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