3 * @file mod/notifications.php
4 * @brief The notifications module
8 use Friendica\Content\ContactSelector;
9 use Friendica\Content\Nav;
10 use Friendica\Content\Pager;
11 use Friendica\Core\L10n;
12 use Friendica\Core\Protocol;
13 use Friendica\Core\Renderer;
14 use Friendica\Core\System;
15 use Friendica\Database\DBA;
17 use Friendica\Module\Security\Login;
18 use Friendica\Model\Contact;
19 use Friendica\Model\Introduction;
21 function notifications_post(App $a)
24 DI::baseUrl()->redirect();
27 $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
29 if ($request_id === 'all') {
34 $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
36 switch ($_POST['submit']) {
37 case L10n::t('Discard'):
40 case L10n::t('Ignore'):
45 DI::baseUrl()->redirect('notifications/intros');
49 function notifications_content(App $a)
52 notice(L10n::t('Permission denied.') . EOL);
56 $page = ($_REQUEST['page'] ?? 0) ?: 1;
57 $show = ($_REQUEST['show'] ?? '') === 'all';
59 Nav::setSelected('notifications');
61 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
66 // Get the nav tabs for the notification pages
67 $tabs = $nm->getTabs();
69 $notif_nocontent = '';
71 // Notification results per page
73 $startrec = ($page * $perpage) - $perpage;
75 $notif_header = L10n::t('Notifications');
80 if ((($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
81 Nav::setSelected('introductions');
84 if (!empty($a->argv[2]) && intval($a->argv[2]) != 0) {
85 $id = (int)$a->argv[2];
88 $all = (($a->argc > 2) && ($a->argv[2] == 'all'));
90 $notifs = $nm->getIntroList($all, $startrec, $perpage, $id);
92 // Get the network notifications
93 } elseif (($a->argc > 1) && ($a->argv[1] == 'network')) {
94 $notif_header = L10n::t('Network Notifications');
95 $notifs = $nm->getNetworkList($show, $startrec, $perpage);
97 // Get the system notifications
98 } elseif (($a->argc > 1) && ($a->argv[1] == 'system')) {
99 $notif_header = L10n::t('System Notifications');
100 $notifs = $nm->getSystemList($show, $startrec, $perpage);
102 // Get the personal notifications
103 } elseif (($a->argc > 1) && ($a->argv[1] == 'personal')) {
104 $notif_header = L10n::t('Personal Notifications');
105 $notifs = $nm->getPersonalList($show, $startrec, $perpage);
107 // Get the home notifications
108 } elseif (($a->argc > 1) && ($a->argv[1] == 'home')) {
109 $notif_header = L10n::t('Home Notifications');
110 $notifs = $nm->getHomeList($show, $startrec, $perpage);
111 // fallback - redirect to main page
113 DI::baseUrl()->redirect('notifications');
117 $pager = new Pager(DI::args()->getQueryString(), $perpage);
119 // Add additional informations (needed for json output)
120 $notifs['items_page'] = $pager->getItemsPerPage();
121 $notifs['page'] = $pager->getPage();
124 if (intval($json) === 1) {
125 System::jsonExit($notifs);
128 $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl');
131 'href' => ($show ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all' ),
132 'text' => ($show ? L10n::t('Show unread') : L10n::t('Show all')),
135 // Process the data for template creation
136 if (($notifs['ident'] ?? '') == 'introductions') {
137 $sugg = Renderer::getMarkupTemplate('suggestions.tpl');
138 $tpl = Renderer::getMarkupTemplate('intros.tpl');
140 // The link to switch between ignored and normal connection requests
142 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros' ),
143 'text' => (!$all ? L10n::t('Show Ignored Requests') : L10n::t('Hide Ignored Requests'))
146 // Loop through all introduction notifications.This creates an array with the output html for each
148 foreach ($notifs['notifications'] as $notif) {
150 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
151 // We have to distinguish between these two because they use different data.
152 switch ($notif['label']) {
153 case 'friend_suggestion':
154 $notif_content[] = Renderer::replaceMacros($sugg, [
155 '$type' => $notif['label'],
156 '$str_notifytype' => L10n::t('Notification type:'),
157 '$notify_type'=> $notif['notify_type'],
158 '$intro_id' => $notif['intro_id'],
159 '$lbl_madeby' => L10n::t('Suggested by:'),
160 '$madeby' => $notif['madeby'],
161 '$madeby_url' => $notif['madeby_url'],
162 '$madeby_zrl' => $notif['madeby_zrl'],
163 '$madeby_addr'=> $notif['madeby_addr'],
164 '$contact_id' => $notif['contact_id'],
165 '$photo' => $notif['photo'],
166 '$fullname' => $notif['name'],
167 '$url' => $notif['url'],
168 '$zrl' => $notif['zrl'],
169 '$lbl_url' => L10n::t('Profile URL'),
170 '$addr' => $notif['addr'],
171 '$hidden' => ['hidden', L10n::t('Hide this contact from others'), ($notif['hidden'] == 1), ''],
172 '$knowyou' => $notif['knowyou'],
173 '$approve' => L10n::t('Approve'),
174 '$note' => $notif['note'],
175 '$request' => $notif['request'],
176 '$ignore' => L10n::t('Ignore'),
177 '$discard' => L10n::t('Discard'),
181 // Normal connection requests
183 $friend_selected = (($notif['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled ');
184 $fan_selected = (($notif['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : '');
192 if ($notif['network'] === Protocol::DFRN) {
193 $lbl_knowyou = L10n::t('Claims to be known to you: ');
194 $knowyou = (($notif['knowyou']) ? L10n::t('yes') : L10n::t('no'));
195 $helptext = L10n::t('Shall your connection be bidirectional or not?');
196 $helptext2 = 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']);
197 $helptext3 = 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']);
198 } elseif ($notif['network'] === Protocol::DIASPORA) {
199 $helptext = L10n::t('Shall your connection be bidirectional or not?');
200 $helptext2 = 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']);
201 $helptext3 = 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']);
204 $dfrn_tpl = Renderer::getMarkupTemplate('netfriend.tpl');
205 $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [
206 '$intro_id' => $notif['intro_id'],
207 '$friend_selected' => $friend_selected,
208 '$fan_selected'=> $fan_selected,
209 '$approve_as1' => $helptext,
210 '$approve_as2' => $helptext2,
211 '$approve_as3' => $helptext3,
212 '$as_friend' => L10n::t('Friend'),
213 '$as_fan' => (($notif['network'] == Protocol::DIASPORA) ? L10n::t('Sharer') : L10n::t('Subscriber'))
216 $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notif['contact_id']]);
218 if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
219 $action = 'follow_confirm';
221 $action = 'dfrn_confirm';
224 $header = $notif['name'];
226 if ($notif['addr'] != '') {
227 $header .= ' <' . $notif['addr'] . '>';
230 $header .= ' (' . ContactSelector::networkToName($notif['network'], $notif['url']) . ')';
232 if ($notif['network'] != Protocol::DIASPORA) {
233 $discard = L10n::t('Discard');
238 $notif_content[] = Renderer::replaceMacros($tpl, [
239 '$type' => $notif['label'],
240 '$header' => $header,
241 '$str_notifytype' => L10n::t('Notification type:'),
242 '$notify_type' => $notif['notify_type'],
243 '$dfrn_text' => $dfrn_text,
244 '$dfrn_id' => $notif['dfrn_id'],
245 '$uid' => $notif['uid'],
246 '$intro_id' => $notif['intro_id'],
247 '$contact_id' => $notif['contact_id'],
248 '$photo' => $notif['photo'],
249 '$fullname' => $notif['name'],
250 '$location' => $notif['location'],
251 '$lbl_location'=> L10n::t('Location:'),
252 '$about' => $notif['about'],
253 '$lbl_about' => L10n::t('About:'),
254 '$keywords' => $notif['keywords'],
255 '$lbl_keywords'=> L10n::t('Tags:'),
256 '$gender' => $notif['gender'],
257 '$lbl_gender' => L10n::t('Gender:'),
258 '$hidden' => ['hidden', L10n::t('Hide this contact from others'), ($notif['hidden'] == 1), ''],
259 '$url' => $notif['url'],
260 '$zrl' => $notif['zrl'],
261 '$lbl_url' => L10n::t('Profile URL'),
262 '$addr' => $notif['addr'],
263 '$lbl_knowyou' => $lbl_knowyou,
264 '$lbl_network' => L10n::t('Network:'),
265 '$network' => ContactSelector::networkToName($notif['network'], $notif['url']),
266 '$knowyou' => $knowyou,
267 '$approve' => L10n::t('Approve'),
268 '$note' => $notif['note'],
269 '$ignore' => L10n::t('Ignore'),
270 '$discard' => $discard,
271 '$action' => $action,
277 if (count($notifs['notifications']) == 0) {
278 info(L10n::t('No introductions.') . EOL);
281 // Normal notifications (no introductions)
282 } elseif (!empty($notifs['notifications'])) {
283 // Loop trough ever notification This creates an array with the output html for each
284 // notification and apply the correct template according to the notificationtype (label).
285 foreach ($notifs['notifications'] as $notif) {
286 $notification_templates = [
287 'like' => 'notifications_likes_item.tpl',
288 'dislike' => 'notifications_dislikes_item.tpl',
289 'attend' => 'notifications_attend_item.tpl',
290 'attendno' => 'notifications_attend_item.tpl',
291 'attendmaybe' => 'notifications_attend_item.tpl',
292 'friend' => 'notifications_friends_item.tpl',
293 'comment' => 'notifications_comments_item.tpl',
294 'post' => 'notifications_posts_item.tpl',
295 'notify' => 'notify.tpl',
298 $tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]);
300 $notif_content[] = Renderer::replaceMacros($tpl_notif, [
301 '$item_label' => $notif['label'],
302 '$item_link' => $notif['link'],
303 '$item_image' => $notif['image'],
304 '$item_url' => $notif['url'],
305 '$item_text' => $notif['text'],
306 '$item_when' => $notif['when'],
307 '$item_ago' => $notif['ago'],
308 '$item_seen' => $notif['seen'],
312 $notif_nocontent = L10n::t('No more %s notifications.', $notifs['ident']);
315 $o .= Renderer::replaceMacros($notif_tpl, [
316 '$notif_header' => $notif_header,
318 '$notif_content' => $notif_content,
319 '$notif_nocontent' => $notif_nocontent,
320 '$notif_show_lnk' => $notif_show_lnk,
321 '$notif_paginate' => $pager->renderMinimal(count($notif_content))