]> git.mxchange.org Git - friendica.git/blob - mod/notifications.php
DE translation update
[friendica.git] / mod / notifications.php
1 <?php
2 /**
3  * @file mod/notifications.php
4  * @brief The notifications module
5  */
6
7 use Friendica\App;
8 use Friendica\Content\ContactSelector;
9 use Friendica\Content\Nav;
10 use Friendica\Core\L10n;
11 use Friendica\Core\NotificationsManager;
12 use Friendica\Core\System;
13 use Friendica\Database\DBA;
14
15 function notifications_post(App $a)
16 {
17         if (!local_user()) {
18                 goaway(System::baseUrl());
19         }
20
21         $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
22
23         if ($request_id === "all") {
24                 return;
25         }
26
27         if ($request_id) {
28                 $intro = DBA::selectFirst('intro', ['id', 'contact-id', 'fid'], ['id' => $request_id, 'uid' => local_user()]);
29
30                 if (DBA::isResult($intro)) {
31                         $intro_id = $intro['id'];
32                         $contact_id = $intro['contact-id'];
33                 } else {
34                         notice(L10n::t('Invalid request identifier.') . EOL);
35                         return;
36                 }
37
38                 // If it is a friend suggestion, the contact is not a new friend but an existing friend
39                 // that should not be deleted.
40
41                 $fid = $intro['fid'];
42
43                 if ($_POST['submit'] == L10n::t('Discard')) {
44                         DBA::delete('intro', ['id' => $intro_id]);
45
46                         if (!$fid) {
47                                 // The check for blocked and pending is in case the friendship was already approved
48                                 // and we just want to get rid of the now pointless notification
49                                 $condition = ['id' => $contact_id, 'uid' => local_user(),
50                                         'self' => false, 'blocked' => true, 'pending' => true];
51                                 DBA::delete('contact', $condition);
52                         }
53                         goaway('notifications/intros');
54                 }
55
56                 if ($_POST['submit'] == L10n::t('Ignore')) {
57                         DBA::update('intro', ['ignore' => true], ['id' => $intro_id]);
58                         goaway('notifications/intros');
59                 }
60         }
61 }
62
63 function notifications_content(App $a)
64 {
65         if (!local_user()) {
66                 notice(L10n::t('Permission denied.') . EOL);
67                 return;
68         }
69
70         $page   =       (x($_REQUEST,'page')            ? $_REQUEST['page']             : 1);
71         $show   =       (x($_REQUEST,'show')            ? $_REQUEST['show']             : 0);
72
73         Nav::setSelected('notifications');
74
75         $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
76
77         $nm = new NotificationsManager();
78
79         $o = '';
80         // Get the nav tabs for the notification pages
81         $tabs = $nm->getTabs();
82         $notif_content = [];
83         $notif_nocontent = '';
84
85         // Notification results per page
86         $perpage = 20;
87         $startrec = ($page * $perpage) - $perpage;
88
89         // Get introductions
90         if ((($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
91                 Nav::setSelected('introductions');
92                 $notif_header = L10n::t('Notifications');
93
94                 $all = (($a->argc > 2) && ($a->argv[2] == 'all'));
95
96                 $notifs = $nm->introNotifs($all, $startrec, $perpage);
97
98         // Get the network notifications
99         } elseif (($a->argc > 1) && ($a->argv[1] == 'network')) {
100                 $notif_header = L10n::t('Network Notifications');
101                 $notifs = $nm->networkNotifs($show, $startrec, $perpage);
102
103         // Get the system notifications
104         } elseif (($a->argc > 1) && ($a->argv[1] == 'system')) {
105                 $notif_header = L10n::t('System Notifications');
106                 $notifs = $nm->systemNotifs($show, $startrec, $perpage);
107
108         // Get the personal notifications
109         } elseif (($a->argc > 1) && ($a->argv[1] == 'personal')) {
110                 $notif_header = L10n::t('Personal Notifications');
111                 $notifs = $nm->personalNotifs($show, $startrec, $perpage);
112
113         // Get the home notifications
114         } elseif (($a->argc > 1) && ($a->argv[1] == 'home')) {
115                 $notif_header = L10n::t('Home Notifications');
116                 $notifs = $nm->homeNotifs($show, $startrec, $perpage);
117
118         }
119
120
121         // Set the pager
122         $a->set_pager_itemspage($perpage);
123
124         // Add additional informations (needed for json output)
125         $notifs['items_page'] = $a->pager['itemspage'];
126         $notifs['page'] = $a->pager['page'];
127
128         // Json output
129         if (intval($json) === 1) {
130                 System::jsonExit($notifs);
131         }
132
133         $notif_tpl = get_markup_template('notifications.tpl');
134
135         // Process the data for template creation
136         if ($notifs['ident'] === 'introductions') {
137                 $sugg = get_markup_template('suggestions.tpl');
138                 $tpl = get_markup_template("intros.tpl");
139
140                 // The link to switch between ignored and normal connection requests
141                 $notif_show_lnk = [
142                         'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros' ),
143                         'text' => (!$all ? L10n::t('Show Ignored Requests') : L10n::t('Hide Ignored Requests'))
144                 ];
145
146                 // Loop through all introduction notifications.This creates an array with the output html for each
147                 // introduction
148                 foreach ($notifs['notifications'] as $it) {
149
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 ($it['label']) {
153                                 case 'friend_suggestion':
154                                         $notif_content[] = replace_macros($sugg, [
155                                                 '$type' => $it['label'],
156                                                 '$str_notifytype' => L10n::t('Notification type:'),
157                                                 '$notify_type' => $it['notify_type'],
158                                                 '$intro_id' => $it['intro_id'],
159                                                 '$lbl_madeby' => L10n::t('Suggested by:'),
160                                                 '$madeby' => $it['madeby'],
161                                                 '$madeby_url' => $it['madeby_url'],
162                                                 '$madeby_zrl' => $it['madeby_zrl'],
163                                                 '$madeby_addr' => $it['madeby_addr'],
164                                                 '$contact_id' => $it['contact_id'],
165                                                 '$photo' => $it['photo'],
166                                                 '$fullname' => $it['name'],
167                                                 '$url' => $it['url'],
168                                                 '$zrl' => $it['zrl'],
169                                                 '$lbl_url' => L10n::t('Profile URL'),
170                                                 '$addr' => $it['addr'],
171                                                 '$hidden' => ['hidden', L10n::t('Hide this contact from others'), ($it['hidden'] == 1), ''],
172
173                                                 '$knowyou' => $it['knowyou'],
174                                                 '$approve' => L10n::t('Approve'),
175                                                 '$note' => $it['note'],
176                                                 '$request' => $it['request'],
177                                                 '$ignore' => L10n::t('Ignore'),
178                                                 '$discard' => L10n::t('Discard'),
179                                         ]);
180                                         break;
181
182                                 // Normal connection requests
183                                 default:
184                                         $friend_selected = (($it['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
185                                         $fan_selected = (($it['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
186                                         $dfrn_tpl = get_markup_template('netfriend.tpl');
187
188                                         $knowyou   = '';
189                                         $lbl_knowyou = '';
190                                         $dfrn_text = '';
191                                         $helptext = '';
192                                         $helptext2 = '';
193                                         $helptext3 = '';
194
195                                         if ($it['network'] === NETWORK_DFRN || $it['network'] === NETWORK_DIASPORA) {
196                                                 if ($it['network'] === NETWORK_DFRN) {
197                                                         $lbl_knowyou = L10n::t('Claims to be known to you: ');
198                                                         $knowyou = (($it['knowyou']) ? L10n::t('yes') : L10n::t('no'));
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.', $it['name'], $it['name']);
201                                                         $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.', $it['name']);
202                                                 } else {
203                                                         $knowyou = '';
204                                                         $helptext = L10n::t('Shall your connection be bidirectional or not?');
205                                                         $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.', $it['name'], $it['name']);
206                                                         $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.', $it['name']);
207                                                 }
208                                         }
209
210                                         $dfrn_text = replace_macros($dfrn_tpl,[
211                                                 '$intro_id' => $it['intro_id'],
212                                                 '$friend_selected' => $friend_selected,
213                                                 '$fan_selected' => $fan_selected,
214                                                 '$approve_as1' => $helptext,
215                                                 '$approve_as2' => $helptext2,
216                                                 '$approve_as3' => $helptext3,
217                                                 '$as_friend' => L10n::t('Friend'),
218                                                 '$as_fan' => (($it['network'] == NETWORK_DIASPORA) ? L10n::t('Sharer') : L10n::t('Subscriber'))
219                                         ]);
220
221                                         $header = $it["name"];
222
223                                         if ($it["addr"] != "") {
224                                                 $header .= " <".$it["addr"].">";
225                                         }
226
227                                         $header .= " (".ContactSelector::networkToName($it['network'], $it['url']).")";
228
229                                         if ($it['network'] != NETWORK_DIASPORA) {
230                                                 $discard = L10n::t('Discard');
231                                         } else {
232                                                 $discard = '';
233                                         }
234
235                                         $notif_content[] = replace_macros($tpl, [
236                                                 '$type' => $it['label'],
237                                                 '$header' => htmlentities($header),
238                                                 '$str_notifytype' => L10n::t('Notification type:'),
239                                                 '$notify_type' => $it['notify_type'],
240                                                 '$dfrn_text' => $dfrn_text,
241                                                 '$dfrn_id' => $it['dfrn_id'],
242                                                 '$uid' => $it['uid'],
243                                                 '$intro_id' => $it['intro_id'],
244                                                 '$contact_id' => $it['contact_id'],
245                                                 '$photo' => $it['photo'],
246                                                 '$fullname' => $it['name'],
247                                                 '$location' => $it['location'],
248                                                 '$lbl_location' => L10n::t('Location:'),
249                                                 '$about' => $it['about'],
250                                                 '$lbl_about' => L10n::t('About:'),
251                                                 '$keywords' => $it['keywords'],
252                                                 '$lbl_keywords' => L10n::t('Tags:'),
253                                                 '$gender' => $it['gender'],
254                                                 '$lbl_gender' => L10n::t('Gender:'),
255                                                 '$hidden' => ['hidden', L10n::t('Hide this contact from others'), ($it['hidden'] == 1), ''],
256                                                 '$url' => $it['url'],
257                                                 '$zrl' => $it['zrl'],
258                                                 '$lbl_url' => L10n::t('Profile URL'),
259                                                 '$addr' => $it['addr'],
260                                                 '$lbl_knowyou' => $lbl_knowyou,
261                                                 '$lbl_network' => L10n::t('Network:'),
262                                                 '$network' => ContactSelector::networkToName($it['network'], $it['url']),
263                                                 '$knowyou' => $knowyou,
264                                                 '$approve' => L10n::t('Approve'),
265                                                 '$note' => $it['note'],
266                                                 '$ignore' => L10n::t('Ignore'),
267                                                 '$discard' => $discard,
268
269                                         ]);
270                                         break;
271                         }
272                 }
273
274                 if (count($notifs['notifications']) == 0) {
275                         info(L10n::t('No introductions.') . EOL);
276                 }
277
278         // Normal notifications (no introductions)
279         } else {
280                 // The template files we need in different cases for formatting the content
281                 $tpl_item_like = 'notifications_likes_item.tpl';
282                 $tpl_item_dislike = 'notifications_dislikes_item.tpl';
283                 $tpl_item_attend = 'notifications_attend_item.tpl';
284                 $tpl_item_attendno = 'notifications_attend_item.tpl';
285                 $tpl_item_attendmaybe = 'notifications_attend_item.tpl';
286                 $tpl_item_friend = 'notifications_friends_item.tpl';
287                 $tpl_item_comment = 'notifications_comments_item.tpl';
288                 $tpl_item_post = 'notifications_posts_item.tpl';
289                 $tpl_item_notify = 'notify.tpl';
290
291                 // Loop trough ever notification This creates an array with the output html for each
292                 // notification and apply the correct template according to the notificationtype (label).
293                 foreach ($notifs['notifications'] as $it) {
294
295                         // We use the notification label to get the correct template file
296                         $tpl_var_name = 'tpl_item_'.$it['label'];
297                         $tpl_notif = get_markup_template($$tpl_var_name);
298
299                         $notif_content[] = replace_macros($tpl_notif,[
300                                 '$item_label' => $it['label'],
301                                 '$item_link' => $it['link'],
302                                 '$item_image' => $it['image'],
303                                 '$item_url' => $it['url'],
304                                 '$item_text' => $it['text'],
305                                 '$item_when' => $it['when'],
306                                 '$item_ago' => $it['ago'],
307                                 '$item_seen' => $it['seen'],
308                         ]);
309                 }
310
311                 $notif_show_lnk = [
312                         'href' => ($show ? 'notifications/'.$notifs['ident'] : 'notifications/'.$notifs['ident'].'?show=all' ),
313                         'text' => ($show ? L10n::t('Show unread') : L10n::t('Show all')),
314                 ];
315
316                 // Output if there aren't any notifications available
317                 if (count($notifs['notifications']) == 0) {
318                         $notif_nocontent = L10n::t('No more %s notifications.', $notifs['ident']);
319                 }
320         }
321
322         $o .= replace_macros($notif_tpl, [
323                 '$notif_header' => $notif_header,
324                 '$tabs' => $tabs,
325                 '$notif_content' => $notif_content,
326                 '$notif_nocontent' => $notif_nocontent,
327                 '$notif_show_lnk' => $notif_show_lnk,
328                 '$notif_paginate' => alt_pager($a, count($notif_content))
329         ]);
330
331         return $o;
332 }