3 * @copyright Copyright (C) 2020, Friendica
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\Content\ContactSelector;
25 use Friendica\Content\Nav;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Database\DBA;
30 use Friendica\Module\BaseNotifications;
31 use Friendica\Object\Notification\Introduction;
34 * Prints notifications about introduction
36 class Introductions extends BaseNotifications
41 public static function getNotifications()
43 $id = (int)DI::args()->get(2, 0);
44 $all = DI::args()->get(2) == 'all';
47 'ident' => 'introductions',
48 'notifications' => DI::notificationIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id),
52 'header' => DI::l10n()->t('Notifications'),
53 'notifications' => $notifications,
57 public static function content(array $parameters = [])
59 Nav::setSelected('introductions');
61 $all = DI::args()->get(2) == 'all';
63 $notificationContent = [];
64 $notificationNoContent = '';
66 $notificationResult = self::getNotifications();
67 $notifications = $notificationResult['notifications'] ?? [];
68 $notificationHeader = $notificationResult['header'] ?? '';
70 $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
71 $notificationTemplate = Renderer::getMarkupTemplate('notifications/intros.tpl');
73 // The link to switch between ignored and normal connection requests
74 $notificationShowLink = [
75 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
76 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')),
79 // Loop through all introduction notifications.This creates an array with the output html for each
81 /** @var Introduction $notification */
82 foreach ($notifications['notifications'] as $notification) {
84 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
85 // We have to distinguish between these two because they use different data.
86 switch ($notification->getLabel()) {
87 case 'friend_suggestion':
88 $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
89 '$type' => $notification->getLabel(),
90 '$str_notification_type' => DI::l10n()->t('Notification type:'),
91 '$str_type' => $notification->getType(),
92 '$intro_id' => $notification->getIntroId(),
93 '$lbl_madeby' => DI::l10n()->t('Suggested by:'),
94 '$madeby' => $notification->getMadeBy(),
95 '$madeby_url' => $notification->getMadeByUrl(),
96 '$madeby_zrl' => $notification->getMadeByZrl(),
97 '$madeby_addr' => $notification->getMadeByAddr(),
98 '$contact_id' => $notification->getContactId(),
99 '$photo' => $notification->getPhoto(),
100 '$fullname' => $notification->getName(),
101 '$url' => $notification->getUrl(),
102 '$zrl' => $notification->getZrl(),
103 '$lbl_url' => DI::l10n()->t('Profile URL'),
104 '$addr' => $notification->getAddr(),
105 '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
106 '$knowyou' => $notification->getKnowYou(),
107 '$approve' => DI::l10n()->t('Approve'),
108 '$note' => $notification->getNote(),
109 '$request' => $notification->getRequest(),
110 '$ignore' => DI::l10n()->t('Ignore'),
111 '$discard' => DI::l10n()->t('Discard'),
115 // Normal connection requests
117 if ($notification->getNetwork() === Protocol::DFRN) {
118 $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
119 $knowyou = ($notification->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No'));
125 $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
126 $helptext2 = DI::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.', $notification->getName(), $notification->getName());
127 $helptext3 = DI::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.', $notification->getName());
129 $friend = ['duplex', DI::l10n()->t('Friend'), '1', $helptext2, true];
130 $follower = ['duplex', DI::l10n()->t('Subscriber'), '0', $helptext3, false];
132 $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notification->getContactId()]);
134 if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
135 $action = 'follow_confirm';
137 $action = 'dfrn_confirm';
140 $header = $notification->getName();
142 if ($notification->getAddr() != '') {
143 $header .= ' <' . $notification->getAddr() . '>';
146 $header .= ' (' . ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()) . ')';
148 if ($notification->getNetwork() != Protocol::DIASPORA) {
149 $discard = DI::l10n()->t('Discard');
154 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
155 '$type' => $notification->getLabel(),
156 '$header' => $header,
157 '$str_notification_type' => DI::l10n()->t('Notification type:'),
158 '$str_type' => $notification->getType(),
159 '$dfrn_id' => $notification->getDfrnId(),
160 '$uid' => $notification->getUid(),
161 '$intro_id' => $notification->getIntroId(),
162 '$contact_id' => $notification->getContactId(),
163 '$photo' => $notification->getPhoto(),
164 '$fullname' => $notification->getName(),
165 '$location' => $notification->getLocation(),
166 '$lbl_location' => DI::l10n()->t('Location:'),
167 '$about' => $notification->getAbout(),
168 '$lbl_about' => DI::l10n()->t('About:'),
169 '$keywords' => $notification->getKeywords(),
170 '$lbl_keywords' => DI::l10n()->t('Tags:'),
171 '$gender' => $notification->getGender(),
172 '$lbl_gender' => DI::l10n()->t('Gender:'),
173 '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
174 '$lbl_connection_type' => $helptext,
175 '$friend' => $friend,
176 '$follower' => $follower,
177 '$url' => $notification->getUrl(),
178 '$zrl' => $notification->getZrl(),
179 '$lbl_url' => DI::l10n()->t('Profile URL'),
180 '$addr' => $notification->getAddr(),
181 '$lbl_knowyou' => $lbl_knowyou,
182 '$lbl_network' => DI::l10n()->t('Network:'),
183 '$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()),
184 '$knowyou' => $knowyou,
185 '$approve' => DI::l10n()->t('Approve'),
186 '$note' => $notification->getNote(),
187 '$ignore' => DI::l10n()->t('Ignore'),
188 '$discard' => $discard,
189 '$action' => $action,
195 if (count($notifications['notifications']) == 0) {
196 info(DI::l10n()->t('No introductions.') . EOL);
197 $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
200 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);