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;
24 use Friendica\App\Arguments;
25 use Friendica\App\Mode;
26 use Friendica\Content\ContactSelector;
27 use Friendica\Content\Nav;
28 use Friendica\Content\Text\BBCode;
29 use Friendica\Core\L10n;
30 use Friendica\Core\Protocol;
31 use Friendica\Core\Renderer;
32 use Friendica\Model\User;
33 use Friendica\Module\BaseNotifications;
34 use Friendica\Navigation\Notifications\Factory\Introduction as IntroductionFactory;
35 use Friendica\Navigation\Notifications\ValueObject\Introduction;
38 * Prints notifications about introduction
40 class Introductions extends BaseNotifications
42 /** @var IntroductionFactory */
43 protected $notificationIntro;
47 public function __construct(Mode $mode, IntroductionFactory $notificationIntro, Arguments $args, L10n $l10n, array $parameters = [])
49 parent::__construct($args, $l10n, $parameters);
51 $this->notificationIntro = $notificationIntro;
58 public function getNotifications()
60 $id = (int)$this->args->get(2, 0);
61 $all = $this->args->get(2) == 'all';
64 'ident' => 'introductions',
65 'notifications' => $this->notificationIntro->getList($all, $this->firstItemNum, self::ITEMS_PER_PAGE, $id),
69 'header' => $this->l10n->t('Notifications'),
70 'notifications' => $notifications,
74 public function content(): string
76 Nav::setSelected('introductions');
78 $all = $this->args->get(2) == 'all';
80 $notificationContent = [];
81 $notificationNoContent = '';
83 $notificationResult = $this->getNotifications();
84 $notifications = $notificationResult['notifications'] ?? [];
85 $notificationHeader = $notificationResult['header'] ?? '';
87 $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
88 $notificationTemplate = Renderer::getMarkupTemplate('notifications/intros.tpl');
90 // The link to switch between ignored and normal connection requests
91 $notificationShowLink = [
92 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
93 'text' => (!$all ? $this->l10n->t('Show Ignored Requests') : $this->l10n->t('Hide Ignored Requests')),
96 $owner = User::getOwnerDataById(local_user());
98 // Loop through all introduction notifications.This creates an array with the output html for each
100 /** @var Introduction $Introduction */
101 foreach ($notifications['notifications'] as $Introduction) {
103 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
104 // We have to distinguish between these two because they use different data.
105 switch ($Introduction->getLabel()) {
106 case 'friend_suggestion':
107 $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
108 '$type' => $Introduction->getLabel(),
109 '$str_notification_type' => $this->l10n->t('Notification type:'),
110 '$str_type' => $Introduction->getType(),
111 '$intro_id' => $Introduction->getIntroId(),
112 '$lbl_madeby' => $this->l10n->t('Suggested by:'),
113 '$madeby' => $Introduction->getMadeBy(),
114 '$madeby_url' => $Introduction->getMadeByUrl(),
115 '$madeby_zrl' => $Introduction->getMadeByZrl(),
116 '$madeby_addr' => $Introduction->getMadeByAddr(),
117 '$contact_id' => $Introduction->getContactId(),
118 '$photo' => $Introduction->getPhoto(),
119 '$fullname' => $Introduction->getName(),
120 '$dfrn_url' => $owner['url'],
121 '$url' => $Introduction->getUrl(),
122 '$zrl' => $Introduction->getZrl(),
123 '$lbl_url' => $this->l10n->t('Profile URL'),
124 '$addr' => $Introduction->getAddr(),
125 '$action' => 'follow',
126 '$approve' => $this->l10n->t('Approve'),
127 '$note' => $Introduction->getNote(),
128 '$ignore' => $this->l10n->t('Ignore'),
129 '$discard' => $this->l10n->t('Discard'),
130 '$is_mobile' => $this->mode->isMobile(),
134 // Normal connection requests
136 if ($Introduction->getNetwork() === Protocol::DFRN) {
137 $lbl_knowyou = $this->l10n->t('Claims to be known to you: ');
138 $knowyou = ($Introduction->getKnowYou() ? $this->l10n->t('Yes') : $this->l10n->t('No'));
144 $convertedName = BBCode::convert($Introduction->getName());
146 $helptext = $this->l10n->t('Shall your connection be bidirectional or not?');
147 $helptext2 = $this->l10n->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);
148 $helptext3 = $this->l10n->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);
150 $friend = ['duplex', $this->l10n->t('Friend'), '1', $helptext2, true];
151 $follower = ['duplex', $this->l10n->t('Subscriber'), '0', $helptext3, false];
153 $action = 'follow_confirm';
155 $header = $Introduction->getName();
157 if ($Introduction->getAddr() != '') {
158 $header .= ' <' . $Introduction->getAddr() . '>';
161 $header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')';
163 if ($Introduction->getNetwork() != Protocol::DIASPORA) {
164 $discard = $this->l10n->t('Discard');
169 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
170 '$type' => $Introduction->getLabel(),
171 '$header' => $header,
172 '$str_notification_type' => $this->l10n->t('Notification type:'),
173 '$str_type' => $Introduction->getType(),
174 '$dfrn_id' => $Introduction->getDfrnId(),
175 '$uid' => $Introduction->getUid(),
176 '$intro_id' => $Introduction->getIntroId(),
177 '$contact_id' => $Introduction->getContactId(),
178 '$photo' => $Introduction->getPhoto(),
179 '$fullname' => $Introduction->getName(),
180 '$location' => $Introduction->getLocation(),
181 '$lbl_location' => $this->l10n->t('Location:'),
182 '$about' => $Introduction->getAbout(),
183 '$lbl_about' => $this->l10n->t('About:'),
184 '$keywords' => $Introduction->getKeywords(),
185 '$lbl_keywords' => $this->l10n->t('Tags:'),
186 '$hidden' => ['hidden', $this->l10n->t('Hide this contact from others'), $Introduction->isHidden(), ''],
187 '$lbl_connection_type' => $helptext,
188 '$friend' => $friend,
189 '$follower' => $follower,
190 '$url' => $Introduction->getUrl(),
191 '$zrl' => $Introduction->getZrl(),
192 '$lbl_url' => $this->l10n->t('Profile URL'),
193 '$addr' => $Introduction->getAddr(),
194 '$lbl_knowyou' => $lbl_knowyou,
195 '$lbl_network' => $this->l10n->t('Network:'),
196 '$network' => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()),
197 '$knowyou' => $knowyou,
198 '$approve' => $this->l10n->t('Approve'),
199 '$note' => $Introduction->getNote(),
200 '$ignore' => $this->l10n->t('Ignore'),
201 '$discard' => $discard,
202 '$action' => $action,
203 '$is_mobile' => $this->mode->isMobile(),
209 if (count($notifications['notifications']) == 0) {
210 notice($this->l10n->t('No introductions.'));
211 $notificationNoContent = $this->l10n->t('No more %s notifications.', $notifications['ident']);
214 return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);