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