3 namespace Friendica\Module\Notifications;
5 use Friendica\Content\ContactSelector;
6 use Friendica\Content\Nav;
7 use Friendica\Core\Protocol;
8 use Friendica\Core\Renderer;
9 use Friendica\Database\DBA;
11 use Friendica\Module\BaseNotifications;
12 use Friendica\Object\Notification\Introduction;
15 * Prints notifications about introduction
17 class Introductions extends BaseNotifications
22 public static function getNotifications()
24 $id = (int)DI::args()->get(2, 0);
25 $all = DI::args()->get(2) == 'all';
28 'ident' => 'introductions',
29 'notifications' => DI::notificationIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id),
33 'header' => DI::l10n()->t('Notifications'),
34 'notifications' => $notifications,
38 public static function content(array $parameters = [])
40 Nav::setSelected('introductions');
42 $all = DI::args()->get(2) == 'all';
44 $notificationContent = [];
45 $notificationNoContent = '';
47 $notificationResult = self::getNotifications();
48 $notifications = $notificationResult['notifications'] ?? [];
49 $notificationHeader = $notificationResult['header'] ?? '';
51 $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
52 $notificationTemplate = Renderer::getMarkupTemplate('notifications/intros.tpl');
54 // The link to switch between ignored and normal connection requests
55 $notificationShowLink = [
56 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
57 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')),
60 // Loop through all introduction notifications.This creates an array with the output html for each
62 /** @var Introduction $notification */
63 foreach ($notifications['notifications'] as $notification) {
65 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
66 // We have to distinguish between these two because they use different data.
67 switch ($notification->getLabel()) {
68 case 'friend_suggestion':
69 $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
70 '$type' => $notification->getLabel(),
71 '$str_notification_type' => DI::l10n()->t('Notification type:'),
72 '$str_type' => $notification->getType(),
73 '$intro_id' => $notification->getIntroId(),
74 '$lbl_madeby' => DI::l10n()->t('Suggested by:'),
75 '$madeby' => $notification->getMadeBy(),
76 '$madeby_url' => $notification->getMadeByUrl(),
77 '$madeby_zrl' => $notification->getMadeByZrl(),
78 '$madeby_addr' => $notification->getMadeByAddr(),
79 '$contact_id' => $notification->getContactId(),
80 '$photo' => $notification->getPhoto(),
81 '$fullname' => $notification->getName(),
82 '$url' => $notification->getUrl(),
83 '$zrl' => $notification->getZrl(),
84 '$lbl_url' => DI::l10n()->t('Profile URL'),
85 '$addr' => $notification->getAddr(),
86 '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
87 '$knowyou' => $notification->getKnowYou(),
88 '$approve' => DI::l10n()->t('Approve'),
89 '$note' => $notification->getNote(),
90 '$request' => $notification->getRequest(),
91 '$ignore' => DI::l10n()->t('Ignore'),
92 '$discard' => DI::l10n()->t('Discard'),
96 // Normal connection requests
98 if ($notification->getNetwork() === Protocol::DFRN) {
99 $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
100 $knowyou = ($notification->getKnowYou() ? DI::l10n()->t('yes') : DI::l10n()->t('no'));
103 $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
104 $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());
105 $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());
107 $friend = ['duplex', DI::l10n()->t('Friend'), '1', $helptext2, true];
108 $follower = ['duplex', DI::l10n()->t('Subscriber'), '0', $helptext3, false];
110 $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notification->getContactId()]);
112 if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
113 $action = 'follow_confirm';
115 $action = 'dfrn_confirm';
118 $header = $notification->getName();
120 if ($notification->getAddr() != '') {
121 $header .= ' <' . $notification->getAddr() . '>';
124 $header .= ' (' . ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()) . ')';
126 if ($notification->getNetwork() != Protocol::DIASPORA) {
127 $discard = DI::l10n()->t('Discard');
132 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
133 '$type' => $notification->getLabel(),
134 '$header' => $header,
135 '$str_notification_type' => DI::l10n()->t('Notification type:'),
136 '$str_type' => $notification->getType(),
137 '$dfrn_id' => $notification->getDfrnId(),
138 '$uid' => $notification->getUid(),
139 '$intro_id' => $notification->getIntroId(),
140 '$contact_id' => $notification->getContactId(),
141 '$photo' => $notification->getPhoto(),
142 '$fullname' => $notification->getName(),
143 '$location' => $notification->getLocation(),
144 '$lbl_location' => DI::l10n()->t('Location:'),
145 '$about' => $notification->getAbout(),
146 '$lbl_about' => DI::l10n()->t('About:'),
147 '$keywords' => $notification->getKeywords(),
148 '$lbl_keywords' => DI::l10n()->t('Tags:'),
149 '$gender' => $notification->getGender(),
150 '$lbl_gender' => DI::l10n()->t('Gender:'),
151 '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
152 '$lbl_connection_type' => $helptext,
153 '$friend' => $friend,
154 '$follower' => $follower,
155 '$url' => $notification->getUrl(),
156 '$zrl' => $notification->getZrl(),
157 '$lbl_url' => DI::l10n()->t('Profile URL'),
158 '$addr' => $notification->getAddr(),
159 '$lbl_knowyou' => $lbl_knowyou,
160 '$lbl_network' => DI::l10n()->t('Network:'),
161 '$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()),
162 '$knowyou' => $knowyou,
163 '$approve' => DI::l10n()->t('Approve'),
164 '$note' => $notification->getNote(),
165 '$ignore' => DI::l10n()->t('Ignore'),
166 '$discard' => $discard,
167 '$action' => $action,
173 if (count($notifications['notifications']) == 0) {
174 info(DI::l10n()->t('No introductions.') . EOL);
175 $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
178 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);