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;
14 * Prints notifications about introduction
16 class Introductions extends BaseNotifications
21 public static function getNotifies()
23 $id = (int)DI::args()->get(2, 0);
24 $all = DI::args()->get(2) == 'all';
26 $notifs = DI::notify()->getIntroList($all, self::$start, self::PER_PAGE, $id);
29 'header' => DI::l10n()->t('Notifications'),
34 public static function content(array $parameters = [])
36 Nav::setSelected('introductions');
38 $all = DI::args()->get(2) == 'all';
41 $notif_nocontent = '';
43 $notif_result = self::getNotifies();
44 $notifs = $notif_result['notifs'] ?? [];
45 $notif_header = $notif_result['header'] ?? '';
47 $sugg = Renderer::getMarkupTemplate('suggestions.tpl');
48 $tpl = Renderer::getMarkupTemplate('intros.tpl');
50 // The link to switch between ignored and normal connection requests
52 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
53 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests'))
56 // Loop through all introduction notifications.This creates an array with the output html for each
58 foreach ($notifs['notifications'] as $notif) {
60 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
61 // We have to distinguish between these two because they use different data.
62 switch ($notif['label']) {
63 case 'friend_suggestion':
64 $notif_content[] = Renderer::replaceMacros($sugg, [
65 '$type' => $notif['label'],
66 '$str_notifytype' => DI::l10n()->t('Notification type:'),
67 '$notify_type' => $notif['notify_type'],
68 '$intro_id' => $notif['intro_id'],
69 '$lbl_madeby' => DI::l10n()->t('Suggested by:'),
70 '$madeby' => $notif['madeby'],
71 '$madeby_url' => $notif['madeby_url'],
72 '$madeby_zrl' => $notif['madeby_zrl'],
73 '$madeby_addr' => $notif['madeby_addr'],
74 '$contact_id' => $notif['contact_id'],
75 '$photo' => $notif['photo'],
76 '$fullname' => $notif['name'],
77 '$url' => $notif['url'],
78 '$zrl' => $notif['zrl'],
79 '$lbl_url' => DI::l10n()->t('Profile URL'),
80 '$addr' => $notif['addr'],
81 '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''],
82 '$knowyou' => $notif['knowyou'],
83 '$approve' => DI::l10n()->t('Approve'),
84 '$note' => $notif['note'],
85 '$request' => $notif['request'],
86 '$ignore' => DI::l10n()->t('Ignore'),
87 '$discard' => DI::l10n()->t('Discard'),
91 // Normal connection requests
93 $friend_selected = (($notif['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled ');
94 $fan_selected = (($notif['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : '');
102 if ($notif['network'] === Protocol::DFRN) {
103 $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
104 $knowyou = (($notif['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no'));
105 $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
106 $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.', $notif['name'], $notif['name']);
107 $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.', $notif['name']);
108 } elseif ($notif['network'] === Protocol::DIASPORA) {
109 $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
110 $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.', $notif['name'], $notif['name']);
111 $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']);
114 $dfrn_tpl = Renderer::getMarkupTemplate('netfriend.tpl');
115 $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [
116 '$intro_id' => $notif['intro_id'],
117 '$friend_selected' => $friend_selected,
118 '$fan_selected' => $fan_selected,
119 '$approve_as1' => $helptext,
120 '$approve_as2' => $helptext2,
121 '$approve_as3' => $helptext3,
122 '$as_friend' => DI::l10n()->t('Friend'),
123 '$as_fan' => (($notif['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber'))
126 $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notif['contact_id']]);
128 if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
129 $action = 'follow_confirm';
131 $action = 'dfrn_confirm';
134 $header = $notif['name'];
136 if ($notif['addr'] != '') {
137 $header .= ' <' . $notif['addr'] . '>';
140 $header .= ' (' . ContactSelector::networkToName($notif['network'], $notif['url']) . ')';
142 if ($notif['network'] != Protocol::DIASPORA) {
143 $discard = DI::l10n()->t('Discard');
148 $notif_content[] = Renderer::replaceMacros($tpl, [
149 '$type' => $notif['label'],
150 '$header' => $header,
151 '$str_notifytype' => DI::l10n()->t('Notification type:'),
152 '$notify_type' => $notif['notify_type'],
153 '$dfrn_text' => $dfrn_text,
154 '$dfrn_id' => $notif['dfrn_id'],
155 '$uid' => $notif['uid'],
156 '$intro_id' => $notif['intro_id'],
157 '$contact_id' => $notif['contact_id'],
158 '$photo' => $notif['photo'],
159 '$fullname' => $notif['name'],
160 '$location' => $notif['location'],
161 '$lbl_location' => DI::l10n()->t('Location:'),
162 '$about' => $notif['about'],
163 '$lbl_about' => DI::l10n()->t('About:'),
164 '$keywords' => $notif['keywords'],
165 '$lbl_keywords' => DI::l10n()->t('Tags:'),
166 '$gender' => $notif['gender'],
167 '$lbl_gender' => DI::l10n()->t('Gender:'),
168 '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''],
169 '$url' => $notif['url'],
170 '$zrl' => $notif['zrl'],
171 '$lbl_url' => DI::l10n()->t('Profile URL'),
172 '$addr' => $notif['addr'],
173 '$lbl_knowyou' => $lbl_knowyou,
174 '$lbl_network' => DI::l10n()->t('Network:'),
175 '$network' => ContactSelector::networkToName($notif['network'], $notif['url']),
176 '$knowyou' => $knowyou,
177 '$approve' => DI::l10n()->t('Approve'),
178 '$note' => $notif['note'],
179 '$ignore' => DI::l10n()->t('Ignore'),
180 '$discard' => $discard,
181 '$action' => $action,
187 if (count($notifs['notifications']) == 0) {
188 info(DI::l10n()->t('No introductions.') . EOL);
189 $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']);
192 return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk);