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