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