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