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