]> git.mxchange.org Git - friendica.git/blob - mod/notifications.php
Merge pull request #2170 from fabrixxm/issue_1953
[friendica.git] / mod / notifications.php
1 <?php
2 include_once("include/bbcode.php");
3 include_once("include/contact_selectors.php");
4 include_once("include/Scrape.php");
5
6 function notifications_post(&$a) {
7
8         if(! local_user()) {
9                 goaway(z_root());
10         }
11
12         $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
13
14         if($request_id === "all")
15                 return;
16
17         if($request_id) {
18
19                 $r = q("SELECT * FROM `intro` WHERE `id` = %d  AND `uid` = %d LIMIT 1",
20                         intval($request_id),
21                         intval(local_user())
22                 );
23
24                 if(count($r)) {
25                         $intro_id = $r[0]['id'];
26                         $contact_id = $r[0]['contact-id'];
27                 }
28                 else {
29                         notice( t('Invalid request identifier.') . EOL);
30                         return;
31                 }
32
33                 // If it is a friend suggestion, the contact is not a new friend but an existing friend
34                 // that should not be deleted.
35
36                 $fid = $r[0]['fid'];
37
38                 if($_POST['submit'] == t('Discard')) {
39                         $r = q("DELETE FROM `intro` WHERE `id` = %d",
40                                 intval($intro_id)
41                         );
42                         if(! $fid) {
43
44                                 // The check for blocked and pending is in case the friendship was already approved
45                                 // and we just want to get rid of the now pointless notification
46
47                                 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1",
48                                         intval($contact_id),
49                                         intval(local_user())
50                                 );
51                         }
52                         goaway($a->get_baseurl(true) . '/notifications/intros');
53                 }
54                 if($_POST['submit'] == t('Ignore')) {
55                         $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
56                                 intval($intro_id));
57                         goaway($a->get_baseurl(true) . '/notifications/intros');
58                 }
59         }
60 }
61
62
63
64
65
66 function notifications_content(&$a) {
67
68         if(! local_user()) {
69                 notice( t('Permission denied.') . EOL);
70                 return;
71         }
72
73         nav_set_selected('notifications');
74
75         $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
76
77
78         $o = '';
79         $tabs = array(
80                 array(
81                         'label' => t('System'),
82                         'url'=>$a->get_baseurl(true) . '/notifications/system',
83                         'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
84                         'accesskey' => 'y',
85                 ),
86                 array(
87                         'label' => t('Network'),
88                         'url'=>$a->get_baseurl(true) . '/notifications/network',
89                         'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
90                         'accesskey' => 'w',
91                 ),
92                 array(
93                         'label' => t('Personal'),
94                         'url'=>$a->get_baseurl(true) . '/notifications/personal',
95                         'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
96                         'accesskey' => 'r',
97                 ),
98                 array(
99                         'label' => t('Home'),
100                         'url' => $a->get_baseurl(true) . '/notifications/home',
101                         'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
102                         'accesskey' => 'h',
103                 ),
104                 array(
105                         'label' => t('Introductions'),
106                         'url' => $a->get_baseurl(true) . '/notifications/intros',
107                         'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
108                         'accesskey' => 'i',
109                 ),
110                 /*array(
111                         'label' => t('Messages'),
112                         'url' => $a->get_baseurl(true) . '/message',
113                         'sel'=> '',
114                 ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */
115         );
116
117         $o = "";
118
119
120         if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
121                 nav_set_selected('introductions');
122                 if(($a->argc > 2) && ($a->argv[2] == 'all'))
123                         $sql_extra = '';
124                 else
125                         $sql_extra = " AND `ignore` = 0 ";
126
127                 $notif_tpl = get_markup_template('notifications.tpl');
128
129                 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
130                         . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
131
132                 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
133                         WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
134                                 intval($_SESSION['uid'])
135                 );
136                 if($r && count($r)) {
137                         $a->set_pager_total($r[0]['total']);
138                         $a->set_pager_itemspage(20);
139                 }
140
141                 $r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`,`fcontact`.`url` AS `furl`,`fcontact`.`photo` AS `fphoto`,`fcontact`.`request` AS `frequest`,
142                                 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
143                                 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
144                                 `gcontact`.`network` AS `gnetwork`
145                         FROM `intro`
146                                 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
147                                 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
148                                 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
149                         WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
150                                 intval($_SESSION['uid']));
151
152                 if(($r !== false) && (count($r))) {
153
154                         $sugg = get_markup_template('suggestions.tpl');
155                         $tpl = get_markup_template("intros.tpl");
156
157                         foreach($r as $rr) {
158
159                                 if($rr['fid']) {
160
161                                         $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
162
163                                         $notif_content .= replace_macros($sugg, array(
164                                                 '$str_notifytype' => t('Notification type: '),
165                                                 '$notify_type' => t('Friend Suggestion'),
166                                                 '$intro_id' => $rr['intro_id'],
167                                                 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
168                                                 '$contact_id' => $rr['contact-id'],
169                                                 '$photo' => ((x($rr,'fphoto')) ? proxy_url($rr['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
170                                                 '$fullname' => $rr['fname'],
171                                                 '$url' => zrl($rr['furl']),
172                                                 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
173                                                 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
174
175                                                 '$knowyou' => $knowyou,
176                                                 '$approve' => t('Approve'),
177                                                 '$note' => $rr['note'],
178                                                 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
179                                                 '$ignore' => t('Ignore'),
180                                                 '$discard' => t('Discard'),
181
182                                         ));
183
184                                         continue;
185
186                                 }
187                                 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
188                                 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
189                                 $dfrn_tpl = get_markup_template('netfriend.tpl');
190
191                                 $knowyou   = '';
192                                 $dfrn_text = '';
193
194                                 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
195                                         if($rr['network'] === NETWORK_DFRN) {
196                                                 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
197                                                 $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Fan/Admirer" means that you allow to read but you do not want to read theirs. Approve as: ');
198                                         } else {
199                                                 $knowyou = '';
200                                                 $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Sharer" means that you allow to read but you do not want to read theirs. Approve as: ');
201                                         }
202
203                                         $dfrn_text = replace_macros($dfrn_tpl,array(
204                                                 '$intro_id' => $rr['intro_id'],
205                                                 '$friend_selected' => $friend_selected,
206                                                 '$fan_selected' => $fan_selected,
207                                                 '$approve_as' => $helptext,
208                                                 '$as_friend' => t('Friend'),
209                                                 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
210                                         ));
211                                 }
212
213                                 $header = $rr["name"];
214
215                                 $ret = probe_url($rr["url"]);
216
217                                 if ($rr['gnetwork'] == "")
218                                         $rr['gnetwork'] = $ret["network"];
219
220                                 if ($ret["addr"] != "")
221                                         $header .= " <".$ret["addr"].">";
222
223                                 $header .= " (".network_to_name($rr['gnetwork'], $rr['url']).")";
224
225                                 // Don't show these data until you are connected. Diaspora is doing the same.
226                                 if($rr['gnetwork'] === NETWORK_DIASPORA) {
227                                         $rr['glocation'] = "";
228                                         $rr['gabout'] = "";
229                                         $rr['ggender'] = "";
230                                 }
231
232                                 $notif_content .= replace_macros($tpl, array(
233                                         '$header' => htmlentities($header),
234                                         '$str_notifytype' => t('Notification type: '),
235                                         '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
236                                         '$dfrn_text' => $dfrn_text,
237                                         '$dfrn_id' => $rr['issued-id'],
238                                         '$uid' => $_SESSION['uid'],
239                                         '$intro_id' => $rr['intro_id'],
240                                         '$contact_id' => $rr['contact-id'],
241                                         '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
242                                         '$fullname' => $rr['name'],
243                                         '$location' => bbcode($rr['glocation'], false, false),
244                                         '$location_label' => t('Location:'),
245                                         '$about' => bbcode($rr['gabout'], false, false),
246                                         '$about_label' => t('About:'),
247                                         '$keywords' => $rr['gkeywords'],
248                                         '$keywords_label' => t('Tags:'),
249                                         '$gender' => $rr['ggender'],
250                                         '$gender_label' => t('Gender:'),
251                                         '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
252                                         '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
253                                         '$url' => $rr['url'],
254                                         '$zrl' => zrl($rr['url']),
255                                         '$url_label' => t('Profile URL'),
256                                         '$knowyou' => $knowyou,
257                                         '$approve' => t('Approve'),
258                                         '$note' => $rr['note'],
259                                         '$ignore' => t('Ignore'),
260                                         '$discard' => t('Discard'),
261
262                                 ));
263                         }
264                 }
265                 else
266                         info( t('No introductions.') . EOL);
267
268                 $o .= replace_macros($notif_tpl, array(
269                         '$notif_header' => t('Notifications'),
270                         '$tabs' => $tabs,
271                         '$notif_content' => $notif_content,
272                 ));
273
274                 $o .= paginate($a);
275                 return $o;
276
277         } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
278
279                 $notif_tpl = get_markup_template('notifications.tpl');
280
281                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
282                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
283                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
284                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
285                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
286                                  `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
287                         intval(local_user())
288                 );
289
290                 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
291                 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
292                 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
293                 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
294                 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
295
296                 $notif_content = '';
297
298                 if ($r) {
299
300                         foreach ($r as $it) {
301                                 switch($it['verb']){
302                                         case ACTIVITY_LIKE:
303                                                 $notif_content .= replace_macros($tpl_item_likes,array(
304                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
305                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
306                                                         '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
307                                                         '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
308                                                         '$item_when' => relative_date($it['created'])
309                                                 ));
310                                                 break;
311
312                                         case ACTIVITY_DISLIKE:
313                                                 $notif_content .= replace_macros($tpl_item_dislikes,array(
314                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
315                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
316                                                         '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
317                                                         '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
318                                                         '$item_when' => relative_date($it['created'])
319                                                 ));
320                                                 break;
321
322                                         case ACTIVITY_FRIEND:
323
324                                                 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
325                                                 $obj = parse_xml_string($xmlhead.$it['object']);
326                                                 $it['fname'] = $obj->title;
327
328                                                 $notif_content .= replace_macros($tpl_item_friends,array(
329                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
330                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
331                                                         '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
332                                                         '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
333                                                         '$item_when' => relative_date($it['created'])
334                                                 ));
335                                                 break;
336
337                                         default:
338                                                 $item_text = (($it['id'] == $it['parent'])
339                                                         ? sprintf( t("%s created a new post"), $it['author-name'])
340                                                         : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
341                                                 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
342
343                                                 $notif_content .= replace_macros($tpl,array(
344                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
345                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
346                                                         '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
347                                                         '$item_text' => $item_text,
348                                                         '$item_when' => relative_date($it['created'])
349                                                 ));
350                                 }
351                         }
352
353                 } else {
354
355                         $notif_content = t('No more network notifications.');
356                 }
357
358                 $o .= replace_macros($notif_tpl, array(
359                         '$notif_header' => t('Network Notifications'),
360                         '$tabs' => $tabs,
361                         '$notif_content' => $notif_content,
362                 ));
363
364         } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
365
366                 $notif_tpl = get_markup_template('notifications.tpl');
367
368                 $not_tpl = get_markup_template('notify.tpl');
369                 require_once('include/bbcode.php');
370
371                 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
372                         intval(local_user())
373                 );
374
375                 if (count($r) > 0) {
376                         foreach ($r as $it) {
377                                 $notif_content .= replace_macros($not_tpl,array(
378                                         '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
379                                         '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO),
380                                         '$item_text' => strip_tags(bbcode($it['msg'])),
381                                         '$item_when' => relative_date($it['date'])
382                                 ));
383                         }
384                 } else {
385                         $notif_content .= t('No more system notifications.');
386                 }
387
388                 $o .= replace_macros($notif_tpl, array(
389                         '$notif_header' => t('System Notifications'),
390                         '$tabs' => $tabs,
391                         '$notif_content' => $notif_content,
392                 ));
393
394         } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
395
396                 $notif_tpl = get_markup_template('notifications.tpl');
397
398                 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
399                 $myurl = substr($myurl,strpos($myurl,'://')+3);
400                 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
401                 $diasp_url = str_replace('/profile/','/u/',$myurl);
402                 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
403                         dbesc($myurl . '$'),
404                         dbesc($myurl . '\\]'),
405                         dbesc($diasp_url . '\\]')
406                 );
407
408
409                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
410                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
411                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
412                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
413                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
414                                 $sql_extra
415                                 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
416                         intval(local_user())
417                 );
418
419                 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
420                 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
421                 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
422                 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
423                 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
424
425                 $notif_content = '';
426
427                 if (count($r) > 0) {
428
429                         foreach ($r as $it) {
430                                 switch($it['verb']){
431                                         case ACTIVITY_LIKE:
432                                                 $notif_content .= replace_macros($tpl_item_likes,array(
433                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
434                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
435                                                         '$item_image' => $it['author-avatar'],
436                                                         '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
437                                                         '$item_when' => relative_date($it['created'])
438                                                 ));
439                                                 break;
440
441                                         case ACTIVITY_DISLIKE:
442                                                 $notif_content .= replace_macros($tpl_item_dislikes,array(
443                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
444                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
445                                                         '$item_image' => $it['author-avatar'],
446                                                         '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
447                                                         '$item_when' => relative_date($it['created'])
448                                                 ));
449                                                 break;
450
451                                         case ACTIVITY_FRIEND:
452
453                                                 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
454                                                 $obj = parse_xml_string($xmlhead.$it['object']);
455                                                 $it['fname'] = $obj->title;
456
457                                                 $notif_content .= replace_macros($tpl_item_friends,array(
458                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
459                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
460                                                         '$item_image' => $it['author-avatar'],
461                                                         '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
462                                                         '$item_when' => relative_date($it['created'])
463                                                 ));
464                                                 break;
465
466                                         default:
467                                                 $item_text = (($it['id'] == $it['parent'])
468                                                         ? sprintf( t("%s created a new post"), $it['author-name'])
469                                                         : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
470                                                 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
471
472                                                 $notif_content .= replace_macros($tpl,array(
473                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
474                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
475                                                         '$item_image' => $it['author-avatar'],
476                                                         '$item_text' => $item_text,
477                                                         '$item_when' => relative_date($it['created'])
478                                                 ));
479                                 }
480                         }
481
482                 } else {
483
484                         $notif_content = t('No more personal notifications.');
485                 }
486
487                 $o .= replace_macros($notif_tpl, array(
488                         '$notif_header' => t('Personal Notifications'),
489                         '$tabs' => $tabs,
490                         '$notif_content' => $notif_content,
491                 ));
492
493
494
495
496
497
498         } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
499
500                 $notif_tpl = get_markup_template('notifications.tpl');
501
502                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
503                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
504                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
505                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
506                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
507                                  `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
508                         intval(local_user())
509                 );
510
511                 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
512                 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
513                 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
514                 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
515
516                 $notif_content = '';
517
518                 if (count($r) > 0) {
519
520                         foreach ($r as $it) {
521                                 switch($it['verb']){
522                                         case ACTIVITY_LIKE:
523                                                 $notif_content .= replace_macros($tpl_item_likes,array(
524                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
525                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
526                                                         '$item_image' => $it['author-avatar'],
527                                                         '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
528                                                         '$item_when' => relative_date($it['created'])
529                                                 ));
530
531                                                 break;
532                                         case ACTIVITY_DISLIKE:
533                                                 $notif_content .= replace_macros($tpl_item_dislikes,array(
534                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
535                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
536                                                         '$item_image' => $it['author-avatar'],
537                                                         '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
538                                                         '$item_when' => relative_date($it['created'])
539                                                 ));
540
541                                                 break;
542                                         case ACTIVITY_FRIEND:
543
544                                                 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
545                                                 $obj = parse_xml_string($xmlhead.$it['object']);
546                                                 $it['fname'] = $obj->title;
547
548                                                 $notif_content .= replace_macros($tpl_item_friends,array(
549                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
550                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
551                                                         '$item_image' => $it['author-avatar'],
552                                                         '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
553                                                         '$item_when' => relative_date($it['created'])
554                                                 ));
555
556                                                 break;
557                                         default:
558                                                 $notif_content .= replace_macros($tpl_item_comments,array(
559                                                         //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
560                                                         '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
561                                                         '$item_image' => $it['author-avatar'],
562                                                         '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
563                                                         '$item_when' => relative_date($it['created'])
564                                                 ));
565                                 }
566                         }
567
568                 } else {
569                         $notif_content = t('No more home notifications.');
570                 }
571
572                 $o .= replace_macros($notif_tpl, array(
573                         '$notif_header' => t('Home Notifications'),
574                         '$tabs' => $tabs,
575                         '$notif_content' => $notif_content,
576                 ));
577         }
578
579         $o .= paginate($a);
580         return $o;
581 }