3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Notifications;
25 use Friendica\App\Arguments;
26 use Friendica\App\Mode;
27 use Friendica\Content\ContactSelector;
28 use Friendica\Content\Nav;
29 use Friendica\Content\Text\BBCode;
30 use Friendica\Core\L10n;
31 use Friendica\Core\Protocol;
32 use Friendica\Core\Renderer;
33 use Friendica\Model\User;
34 use Friendica\Module\BaseNotifications;
35 use Friendica\Module\Response;
36 use Friendica\Navigation\Notifications\Factory\Introduction as IntroductionFactory;
37 use Friendica\Navigation\Notifications\ValueObject\Introduction;
38 use Friendica\Util\Profiler;
39 use Psr\Log\LoggerInterface;
42 * Prints notifications about introduction
44 class Introductions extends BaseNotifications
46 /** @var IntroductionFactory */
47 protected $notificationIntro;
51 public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Mode $mode, IntroductionFactory $notificationIntro, array $server, array $parameters = [])
53 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
55 $this->notificationIntro = $notificationIntro;
62 public function getNotifications()
64 $id = (int)$this->args->get(2, 0);
65 $all = $this->args->get(2) == 'all';
68 'ident' => 'introductions',
69 'notifications' => $this->notificationIntro->getList($all, $this->firstItemNum, self::ITEMS_PER_PAGE, $id),
73 'header' => $this->t('Notifications'),
74 'notifications' => $notifications,
78 protected function content(array $request = []): string
80 Nav::setSelected('introductions');
82 $all = $this->args->get(2) == 'all';
84 $notificationContent = [];
85 $notificationNoContent = '';
87 $notificationResult = $this->getNotifications();
88 $notifications = $notificationResult['notifications'] ?? [];
89 $notificationHeader = $notificationResult['header'] ?? '';
91 $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
92 $notificationTemplate = Renderer::getMarkupTemplate('notifications/intros.tpl');
94 // The link to switch between ignored and normal connection requests
95 $notificationShowLink = [
96 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
97 'text' => (!$all ? $this->t('Show Ignored Requests') : $this->t('Hide Ignored Requests')),
100 $owner = User::getOwnerDataById(local_user());
102 // Loop through all introduction notifications.This creates an array with the output html for each
104 /** @var Introduction $Introduction */
105 foreach ($notifications['notifications'] as $Introduction) {
107 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
108 // We have to distinguish between these two because they use different data.
109 switch ($Introduction->getLabel()) {
110 case 'friend_suggestion':
111 $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
112 '$type' => $Introduction->getLabel(),
113 '$str_notification_type' => $this->t('Notification type:'),
114 '$str_type' => $Introduction->getType(),
115 '$intro_id' => $Introduction->getIntroId(),
116 '$lbl_madeby' => $this->t('Suggested by:'),
117 '$madeby' => $Introduction->getMadeBy(),
118 '$madeby_url' => $Introduction->getMadeByUrl(),
119 '$madeby_zrl' => $Introduction->getMadeByZrl(),
120 '$madeby_addr' => $Introduction->getMadeByAddr(),
121 '$contact_id' => $Introduction->getContactId(),
122 '$photo' => $Introduction->getPhoto(),
123 '$fullname' => $Introduction->getName(),
124 '$dfrn_url' => $owner['url'],
125 '$url' => $Introduction->getUrl(),
126 '$zrl' => $Introduction->getZrl(),
127 '$lbl_url' => $this->t('Profile URL'),
128 '$addr' => $Introduction->getAddr(),
129 '$action' => 'follow',
130 '$approve' => $this->t('Approve'),
131 '$note' => $Introduction->getNote(),
132 '$ignore' => $this->t('Ignore'),
133 '$discard' => $this->t('Discard'),
134 '$is_mobile' => $this->mode->isMobile(),
138 // Normal connection requests
140 if ($Introduction->getNetwork() === Protocol::DFRN) {
141 $lbl_knowyou = $this->t('Claims to be known to you: ');
142 $knowyou = ($Introduction->getKnowYou() ? $this->t('Yes') : $this->t('No'));
148 $convertedName = BBCode::convert($Introduction->getName());
150 $helptext = $this->t('Shall your connection be bidirectional or not?');
151 $helptext2 = $this->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName);
152 $helptext3 = $this->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $convertedName);
154 $friend = ['duplex', $this->t('Friend'), '1', $helptext2, true];
155 $follower = ['duplex', $this->t('Subscriber'), '0', $helptext3, false];
157 $action = 'follow_confirm';
159 $header = $Introduction->getName();
161 if ($Introduction->getAddr() != '') {
162 $header .= ' <' . $Introduction->getAddr() . '>';
165 $header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')';
167 if ($Introduction->getNetwork() != Protocol::DIASPORA) {
168 $discard = $this->t('Discard');
173 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
174 '$type' => $Introduction->getLabel(),
175 '$header' => $header,
176 '$str_notification_type' => $this->t('Notification type:'),
177 '$str_type' => $Introduction->getType(),
178 '$dfrn_id' => $Introduction->getDfrnId(),
179 '$uid' => $Introduction->getUid(),
180 '$intro_id' => $Introduction->getIntroId(),
181 '$contact_id' => $Introduction->getContactId(),
182 '$photo' => $Introduction->getPhoto(),
183 '$fullname' => $Introduction->getName(),
184 '$location' => $Introduction->getLocation(),
185 '$lbl_location' => $this->t('Location:'),
186 '$about' => $Introduction->getAbout(),
187 '$lbl_about' => $this->t('About:'),
188 '$keywords' => $Introduction->getKeywords(),
189 '$lbl_keywords' => $this->t('Tags:'),
190 '$hidden' => ['hidden', $this->t('Hide this contact from others'), $Introduction->isHidden(), ''],
191 '$lbl_connection_type' => $helptext,
192 '$friend' => $friend,
193 '$follower' => $follower,
194 '$url' => $Introduction->getUrl(),
195 '$zrl' => $Introduction->getZrl(),
196 '$lbl_url' => $this->t('Profile URL'),
197 '$addr' => $Introduction->getAddr(),
198 '$lbl_knowyou' => $lbl_knowyou,
199 '$lbl_network' => $this->t('Network:'),
200 '$network' => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()),
201 '$knowyou' => $knowyou,
202 '$approve' => $this->t('Approve'),
203 '$note' => $Introduction->getNote(),
204 '$ignore' => $this->t('Ignore'),
205 '$discard' => $discard,
206 '$action' => $action,
207 '$is_mobile' => $this->mode->isMobile(),
213 if (count($notifications['notifications']) == 0) {
214 notice($this->t('No introductions.'));
215 $notificationNoContent = $this->t('No more %s notifications.', $notifications['ident']);
218 return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);