3 * @file mod/notifications.php
4 * The notifications module
8 use Friendica\Content\ContactSelector;
9 use Friendica\Content\Nav;
10 use Friendica\Content\Pager;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\Renderer;
13 use Friendica\Core\System;
14 use Friendica\Database\DBA;
16 use Friendica\Module\Security\Login;
18 function notifications_post(App $a)
21 DI::baseUrl()->redirect();
24 $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
26 if ($request_id === 'all') {
31 $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
33 switch ($_POST['submit']) {
34 case DI::l10n()->t('Discard'):
37 case DI::l10n()->t('Ignore'):
42 DI::baseUrl()->redirect('notifications/intros');
46 function notifications_content(App $a)
49 notice(DI::l10n()->t('Permission denied.') . EOL);
53 $page = ($_REQUEST['page'] ?? 0) ?: 1;
54 $show = ($_REQUEST['show'] ?? '') === 'all';
56 Nav::setSelected('notifications');
58 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
63 // Get the nav tabs for the notification pages
64 $tabs = $nm->getTabs();
66 $notif_nocontent = '';
68 // Notification results per page
70 $startrec = ($page * $perpage) - $perpage;
72 $notif_header = DI::l10n()->t('Notifications');
77 if ((($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
78 Nav::setSelected('introductions');
81 if (!empty($a->argv[2]) && intval($a->argv[2]) != 0) {
82 $id = (int)$a->argv[2];
85 $all = (($a->argc > 2) && ($a->argv[2] == 'all'));
87 $notifs = $nm->getIntroList($all, $startrec, $perpage, $id);
89 // Get the network notifications
90 } elseif (($a->argc > 1) && ($a->argv[1] == 'network')) {
91 $notif_header = DI::l10n()->t('Network Notifications');
92 $notifs = $nm->getNetworkList($show, $startrec, $perpage);
94 // Get the system notifications
95 } elseif (($a->argc > 1) && ($a->argv[1] == 'system')) {
96 $notif_header = DI::l10n()->t('System Notifications');
97 $notifs = $nm->getSystemList($show, $startrec, $perpage);
99 // Get the personal notifications
100 } elseif (($a->argc > 1) && ($a->argv[1] == 'personal')) {
101 $notif_header = DI::l10n()->t('Personal Notifications');
102 $notifs = $nm->getPersonalList($show, $startrec, $perpage);
104 // Get the home notifications
105 } elseif (($a->argc > 1) && ($a->argv[1] == 'home')) {
106 $notif_header = DI::l10n()->t('Home Notifications');
107 $notifs = $nm->getHomeList($show, $startrec, $perpage);
108 // fallback - redirect to main page
110 DI::baseUrl()->redirect('notifications');
114 $pager = new Pager(DI::args()->getQueryString(), $perpage);
116 // Add additional informations (needed for json output)
117 $notifs['items_page'] = $pager->getItemsPerPage();
118 $notifs['page'] = $pager->getPage();
121 if (intval($json) === 1) {
122 System::jsonExit($notifs);
125 $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl');
128 'href' => ($show ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all' ),
129 'text' => ($show ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
132 // Process the data for template creation
133 if (($notifs['ident'] ?? '') == 'introductions') {
134 $sugg = Renderer::getMarkupTemplate('suggestions.tpl');
135 $tpl = Renderer::getMarkupTemplate('intros.tpl');
137 // The link to switch between ignored and normal connection requests
139 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros' ),
140 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests'))
143 // Loop through all introduction notifications.This creates an array with the output html for each
145 foreach ($notifs['notifications'] as $notif) {
147 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
148 // We have to distinguish between these two because they use different data.
149 switch ($notif['label']) {
150 case 'friend_suggestion':
151 $notif_content[] = Renderer::replaceMacros($sugg, [
152 '$type' => $notif['label'],
153 '$str_notifytype' => DI::l10n()->t('Notification type:'),
154 '$notify_type'=> $notif['notify_type'],
155 '$intro_id' => $notif['intro_id'],
156 '$lbl_madeby' => DI::l10n()->t('Suggested by:'),
157 '$madeby' => $notif['madeby'],
158 '$madeby_url' => $notif['madeby_url'],
159 '$madeby_zrl' => $notif['madeby_zrl'],
160 '$madeby_addr'=> $notif['madeby_addr'],
161 '$contact_id' => $notif['contact_id'],
162 '$photo' => $notif['photo'],
163 '$fullname' => $notif['name'],
164 '$url' => $notif['url'],
165 '$zrl' => $notif['zrl'],
166 '$lbl_url' => DI::l10n()->t('Profile URL'),
167 '$addr' => $notif['addr'],
168 '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''],
169 '$knowyou' => $notif['knowyou'],
170 '$approve' => DI::l10n()->t('Approve'),
171 '$note' => $notif['note'],
172 '$request' => $notif['request'],
173 '$ignore' => DI::l10n()->t('Ignore'),
174 '$discard' => DI::l10n()->t('Discard'),
178 // Normal connection requests
180 $friend_selected = (($notif['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled ');
181 $fan_selected = (($notif['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : '');
189 if ($notif['network'] === Protocol::DFRN) {
190 $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
191 $knowyou = (($notif['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no'));
192 $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
193 $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']);
194 $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']);
195 } elseif ($notif['network'] === Protocol::DIASPORA) {
196 $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
197 $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']);
198 $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']);
201 $dfrn_tpl = Renderer::getMarkupTemplate('netfriend.tpl');
202 $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [
203 '$intro_id' => $notif['intro_id'],
204 '$friend_selected' => $friend_selected,
205 '$fan_selected'=> $fan_selected,
206 '$approve_as1' => $helptext,
207 '$approve_as2' => $helptext2,
208 '$approve_as3' => $helptext3,
209 '$as_friend' => DI::l10n()->t('Friend'),
210 '$as_fan' => (($notif['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber'))
213 $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notif['contact_id']]);
215 if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
216 $action = 'follow_confirm';
218 $action = 'dfrn_confirm';
221 $header = $notif['name'];
223 if ($notif['addr'] != '') {
224 $header .= ' <' . $notif['addr'] . '>';
227 $header .= ' (' . ContactSelector::networkToName($notif['network'], $notif['url']) . ')';
229 if ($notif['network'] != Protocol::DIASPORA) {
230 $discard = DI::l10n()->t('Discard');
235 $notif_content[] = Renderer::replaceMacros($tpl, [
236 '$type' => $notif['label'],
237 '$header' => $header,
238 '$str_notifytype' => DI::l10n()->t('Notification type:'),
239 '$notify_type' => $notif['notify_type'],
240 '$dfrn_text' => $dfrn_text,
241 '$dfrn_id' => $notif['dfrn_id'],
242 '$uid' => $notif['uid'],
243 '$intro_id' => $notif['intro_id'],
244 '$contact_id' => $notif['contact_id'],
245 '$photo' => $notif['photo'],
246 '$fullname' => $notif['name'],
247 '$location' => $notif['location'],
248 '$lbl_location'=> DI::l10n()->t('Location:'),
249 '$about' => $notif['about'],
250 '$lbl_about' => DI::l10n()->t('About:'),
251 '$keywords' => $notif['keywords'],
252 '$lbl_keywords'=> DI::l10n()->t('Tags:'),
253 '$gender' => $notif['gender'],
254 '$lbl_gender' => DI::l10n()->t('Gender:'),
255 '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''],
256 '$url' => $notif['url'],
257 '$zrl' => $notif['zrl'],
258 '$lbl_url' => DI::l10n()->t('Profile URL'),
259 '$addr' => $notif['addr'],
260 '$lbl_knowyou' => $lbl_knowyou,
261 '$lbl_network' => DI::l10n()->t('Network:'),
262 '$network' => ContactSelector::networkToName($notif['network'], $notif['url']),
263 '$knowyou' => $knowyou,
264 '$approve' => DI::l10n()->t('Approve'),
265 '$note' => $notif['note'],
266 '$ignore' => DI::l10n()->t('Ignore'),
267 '$discard' => $discard,
268 '$action' => $action,
274 if (count($notifs['notifications']) == 0) {
275 info(DI::l10n()->t('No introductions.') . EOL);
278 // Normal notifications (no introductions)
279 } elseif (!empty($notifs['notifications'])) {
280 // Loop trough ever notification This creates an array with the output html for each
281 // notification and apply the correct template according to the notificationtype (label).
282 foreach ($notifs['notifications'] as $notif) {
283 $notification_templates = [
284 'like' => 'notifications_likes_item.tpl',
285 'dislike' => 'notifications_dislikes_item.tpl',
286 'attend' => 'notifications_attend_item.tpl',
287 'attendno' => 'notifications_attend_item.tpl',
288 'attendmaybe' => 'notifications_attend_item.tpl',
289 'friend' => 'notifications_friends_item.tpl',
290 'comment' => 'notifications_comments_item.tpl',
291 'post' => 'notifications_posts_item.tpl',
292 'notify' => 'notify.tpl',
295 $tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]);
297 $notif_content[] = Renderer::replaceMacros($tpl_notif, [
298 '$item_label' => $notif['label'],
299 '$item_link' => $notif['link'],
300 '$item_image' => $notif['image'],
301 '$item_url' => $notif['url'],
302 '$item_text' => $notif['text'],
303 '$item_when' => $notif['when'],
304 '$item_ago' => $notif['ago'],
305 '$item_seen' => $notif['seen'],
309 $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']);
312 $o .= Renderer::replaceMacros($notif_tpl, [
313 '$notif_header' => $notif_header,
315 '$notif_content' => $notif_content,
316 '$notif_nocontent' => $notif_nocontent,
317 '$notif_show_lnk' => $notif_show_lnk,
318 '$notif_paginate' => $pager->renderMinimal(count($notif_content))