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\Navigation\Notifications\Factory\Introduction as IntroductionFactory;
36 use Friendica\Navigation\Notifications\ValueObject\Introduction;
37 use Friendica\Util\Profiler;
38 use Psr\Log\LoggerInterface;
41 * Prints notifications about introduction
43 class Introductions extends BaseNotifications
45 /** @var IntroductionFactory */
46 protected $notificationIntro;
50 public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Mode $mode, IntroductionFactory $notificationIntro, array $server, array $parameters = [])
52 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
54 $this->notificationIntro = $notificationIntro;
61 public function getNotifications()
63 $id = (int)$this->args->get(2, 0);
64 $all = $this->args->get(2) == 'all';
67 'ident' => 'introductions',
68 'notifications' => $this->notificationIntro->getList($all, $this->firstItemNum, self::ITEMS_PER_PAGE, $id),
72 'header' => $this->t('Notifications'),
73 'notifications' => $notifications,
77 protected function content(array $request = []): string
79 Nav::setSelected('introductions');
81 $all = $this->args->get(2) == 'all';
83 $notificationContent = [];
84 $notificationNoContent = '';
86 $notificationResult = $this->getNotifications();
87 $notifications = $notificationResult['notifications'] ?? [];
88 $notificationHeader = $notificationResult['header'] ?? '';
90 $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
91 $notificationTemplate = Renderer::getMarkupTemplate('notifications/intros.tpl');
93 // The link to switch between ignored and normal connection requests
94 $notificationShowLink = [
95 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
96 'text' => (!$all ? $this->t('Show Ignored Requests') : $this->t('Hide Ignored Requests')),
99 $owner = User::getOwnerDataById(local_user());
101 // Loop through all introduction notifications.This creates an array with the output html for each
103 /** @var Introduction $Introduction */
104 foreach ($notifications['notifications'] as $Introduction) {
106 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
107 // We have to distinguish between these two because they use different data.
108 switch ($Introduction->getLabel()) {
109 case 'friend_suggestion':
110 $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
111 '$type' => $Introduction->getLabel(),
112 '$str_notification_type' => $this->t('Notification type:'),
113 '$str_type' => $Introduction->getType(),
114 '$intro_id' => $Introduction->getIntroId(),
115 '$lbl_madeby' => $this->t('Suggested by:'),
116 '$madeby' => $Introduction->getMadeBy(),
117 '$madeby_url' => $Introduction->getMadeByUrl(),
118 '$madeby_zrl' => $Introduction->getMadeByZrl(),
119 '$madeby_addr' => $Introduction->getMadeByAddr(),
120 '$contact_id' => $Introduction->getContactId(),
121 '$photo' => $Introduction->getPhoto(),
122 '$fullname' => $Introduction->getName(),
123 '$dfrn_url' => $owner['url'],
124 '$url' => $Introduction->getUrl(),
125 '$zrl' => $Introduction->getZrl(),
126 '$lbl_url' => $this->t('Profile URL'),
127 '$addr' => $Introduction->getAddr(),
128 '$action' => 'follow',
129 '$approve' => $this->t('Approve'),
130 '$note' => $Introduction->getNote(),
131 '$ignore' => $this->t('Ignore'),
132 '$discard' => $this->t('Discard'),
133 '$is_mobile' => $this->mode->isMobile(),
137 // Normal connection requests
139 if ($Introduction->getNetwork() === Protocol::DFRN) {
140 $lbl_knowyou = $this->t('Claims to be known to you: ');
141 $knowyou = ($Introduction->getKnowYou() ? $this->t('Yes') : $this->t('No'));
147 $convertedName = BBCode::convert($Introduction->getName());
149 $helptext = $this->t('Shall your connection be bidirectional or not?');
150 $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);
151 $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);
153 $friend = ['duplex', $this->t('Friend'), '1', $helptext2, true];
154 $follower = ['duplex', $this->t('Subscriber'), '0', $helptext3, false];
156 $action = 'follow_confirm';
158 $header = $Introduction->getName();
160 if ($Introduction->getAddr() != '') {
161 $header .= ' <' . $Introduction->getAddr() . '>';
164 $header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')';
166 if ($Introduction->getNetwork() != Protocol::DIASPORA) {
167 $discard = $this->t('Discard');
172 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
173 '$type' => $Introduction->getLabel(),
174 '$header' => $header,
175 '$str_notification_type' => $this->t('Notification type:'),
176 '$str_type' => $Introduction->getType(),
177 '$dfrn_id' => $Introduction->getDfrnId(),
178 '$uid' => $Introduction->getUid(),
179 '$intro_id' => $Introduction->getIntroId(),
180 '$contact_id' => $Introduction->getContactId(),
181 '$photo' => $Introduction->getPhoto(),
182 '$fullname' => $Introduction->getName(),
183 '$location' => $Introduction->getLocation(),
184 '$lbl_location' => $this->t('Location:'),
185 '$about' => $Introduction->getAbout(),
186 '$lbl_about' => $this->t('About:'),
187 '$keywords' => $Introduction->getKeywords(),
188 '$lbl_keywords' => $this->t('Tags:'),
189 '$hidden' => ['hidden', $this->t('Hide this contact from others'), $Introduction->isHidden(), ''],
190 '$lbl_connection_type' => $helptext,
191 '$friend' => $friend,
192 '$follower' => $follower,
193 '$url' => $Introduction->getUrl(),
194 '$zrl' => $Introduction->getZrl(),
195 '$lbl_url' => $this->t('Profile URL'),
196 '$addr' => $Introduction->getAddr(),
197 '$lbl_knowyou' => $lbl_knowyou,
198 '$lbl_network' => $this->t('Network:'),
199 '$network' => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()),
200 '$knowyou' => $knowyou,
201 '$approve' => $this->t('Approve'),
202 '$note' => $Introduction->getNote(),
203 '$ignore' => $this->t('Ignore'),
204 '$discard' => $discard,
205 '$action' => $action,
206 '$is_mobile' => $this->mode->isMobile(),
212 if (count($notifications['notifications']) == 0) {
213 notice($this->t('No introductions.'));
214 $notificationNoContent = $this->t('No more %s notifications.', $notifications['ident']);
217 return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);