2 include_once("include/bbcode.php");
3 include_once("include/contact_selectors.php");
5 function notifications_post(&$a) {
11 $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
13 if($request_id === "all")
18 $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
24 $intro_id = $r[0]['id'];
25 $contact_id = $r[0]['contact-id'];
28 notice( t('Invalid request identifier.') . EOL);
32 // If it is a friend suggestion, the contact is not a new friend but an existing friend
33 // that should not be deleted.
37 if($_POST['submit'] == t('Discard')) {
38 $r = q("DELETE FROM `intro` WHERE `id` = %d",
43 // The check for blocked and pending is in case the friendship was already approved
44 // and we just want to get rid of the now pointless notification
46 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1",
51 goaway($a->get_baseurl(true) . '/notifications/intros');
53 if($_POST['submit'] == t('Ignore')) {
54 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
56 goaway($a->get_baseurl(true) . '/notifications/intros');
65 function notifications_content(&$a) {
68 notice( t('Permission denied.') . EOL);
72 nav_set_selected('notifications');
74 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
80 'label' => t('System'),
81 'url'=>$a->get_baseurl(true) . '/notifications/system',
82 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
86 'label' => t('Network'),
87 'url'=>$a->get_baseurl(true) . '/notifications/network',
88 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
92 'label' => t('Personal'),
93 'url'=>$a->get_baseurl(true) . '/notifications/personal',
94 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
99 'url' => $a->get_baseurl(true) . '/notifications/home',
100 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
104 'label' => t('Introductions'),
105 'url' => $a->get_baseurl(true) . '/notifications/intros',
106 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
110 'label' => t('Messages'),
111 'url' => $a->get_baseurl(true) . '/message',
113 ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */
119 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
120 nav_set_selected('introductions');
121 if(($a->argc > 2) && ($a->argv[2] == 'all'))
124 $sql_extra = " AND `ignore` = 0 ";
126 $notif_tpl = get_markup_template('notifications.tpl');
128 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
129 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
131 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
132 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
133 intval($_SESSION['uid'])
135 if($r && count($r)) {
136 $a->set_pager_total($r[0]['total']);
137 $a->set_pager_itemspage(20);
140 $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`,
141 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
142 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
143 `gcontact`.`network` AS `gnetwork`
145 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
146 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
147 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
148 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
149 intval($_SESSION['uid']));
151 if(($r !== false) && (count($r))) {
153 $sugg = get_markup_template('suggestions.tpl');
154 $tpl = get_markup_template("intros.tpl");
160 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
162 $notif_content .= replace_macros($sugg, array(
163 '$str_notifytype' => t('Notification type: '),
164 '$notify_type' => t('Friend Suggestion'),
165 '$intro_id' => $rr['intro_id'],
166 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
167 '$contact_id' => $rr['contact-id'],
168 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/person-175.jpg"),
169 '$fullname' => $rr['fname'],
170 '$url' => zrl($rr['furl']),
171 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
172 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
174 '$knowyou' => $knowyou,
175 '$approve' => t('Approve'),
176 '$note' => $rr['note'],
177 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
178 '$ignore' => t('Ignore'),
179 '$discard' => t('Discard'),
186 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
187 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
188 $dfrn_tpl = get_markup_template('netfriend.tpl');
193 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
194 if($rr['network'] === NETWORK_DFRN) {
195 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
196 $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Fan/Admirer" means that you allow to read but you do not want to read theirs. Approve as: ');
199 $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Sharer" means that you allow to read but you do not want to read theirs. Approve as: ');
202 $dfrn_text = replace_macros($dfrn_tpl,array(
203 '$intro_id' => $rr['intro_id'],
204 '$friend_selected' => $friend_selected,
205 '$fan_selected' => $fan_selected,
206 '$approve_as' => $helptext,
207 '$as_friend' => t('Friend'),
208 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
212 $header = $rr["name"];
214 $ret = probe_url($rr["url"]);
216 if ($rr['gnetwork'] == "")
217 $rr['gnetwork'] = $ret["network"];
219 if ($ret["addr"] != "")
220 $header .= " <".$ret["addr"].">";
222 $header .= " (".network_to_name($rr['gnetwork']).")";
224 $notif_content .= replace_macros($tpl, array(
225 '$header' => htmlentities($header),
226 '$str_notifytype' => t('Notification type: '),
227 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
228 '$dfrn_text' => $dfrn_text,
229 '$dfrn_id' => $rr['issued-id'],
230 '$uid' => $_SESSION['uid'],
231 '$intro_id' => $rr['intro_id'],
232 '$contact_id' => $rr['contact-id'],
233 '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo']) : "images/person-175.jpg"),
234 '$fullname' => $rr['name'],
235 '$location' => bbcode($rr['glocation'], false, false),
236 '$location_label' => t('Location:'),
237 '$about' => proxy_parse_html(bbcode($rr['gabout'], false, false)),
238 '$about_label' => t('About:'),
239 '$keywords' => $rr['gkeywords'],
240 '$keywords_label' => t('Tags:'),
241 '$gender' => $rr['ggender'],
242 '$gender_label' => t('Gender:'),
243 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
244 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
245 '$url' => zrl($rr['url']),
246 '$url_label' => t('Profile URL'),
247 '$knowyou' => $knowyou,
248 '$approve' => t('Approve'),
249 '$note' => $rr['note'],
250 '$ignore' => t('Ignore'),
251 '$discard' => t('Discard'),
257 info( t('No introductions.') . EOL);
259 $o .= replace_macros($notif_tpl, array(
260 '$notif_header' => t('Notifications'),
262 '$notif_content' => $notif_content,
268 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
270 $notif_tpl = get_markup_template('notifications.tpl');
272 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
273 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
274 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
275 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
276 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
277 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
281 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
282 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
283 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
284 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
285 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
291 foreach ($r as $it) {
294 $notif_content .= replace_macros($tpl_item_likes,array(
295 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
296 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
297 '$item_image' => $it['author-avatar'],
298 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
299 '$item_when' => relative_date($it['created'])
303 case ACTIVITY_DISLIKE:
304 $notif_content .= replace_macros($tpl_item_dislikes,array(
305 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
306 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
307 '$item_image' => $it['author-avatar'],
308 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
309 '$item_when' => relative_date($it['created'])
313 case ACTIVITY_FRIEND:
315 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
316 $obj = parse_xml_string($xmlhead.$it['object']);
317 $it['fname'] = $obj->title;
319 $notif_content .= replace_macros($tpl_item_friends,array(
320 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
321 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
322 '$item_image' => $it['author-avatar'],
323 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
324 '$item_when' => relative_date($it['created'])
329 $item_text = (($it['id'] == $it['parent'])
330 ? sprintf( t("%s created a new post"), $it['author-name'])
331 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
332 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
334 $notif_content .= replace_macros($tpl,array(
335 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
336 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
337 '$item_image' => $it['author-avatar'],
338 '$item_text' => $item_text,
339 '$item_when' => relative_date($it['created'])
346 $notif_content = t('No more network notifications.');
349 $o .= replace_macros($notif_tpl, array(
350 '$notif_header' => t('Network Notifications'),
352 '$notif_content' => $notif_content,
355 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
357 $notif_tpl = get_markup_template('notifications.tpl');
359 $not_tpl = get_markup_template('notify.tpl');
360 require_once('include/bbcode.php');
362 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
367 foreach ($r as $it) {
368 $notif_content .= replace_macros($not_tpl,array(
369 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
370 '$item_image' => $it['photo'],
371 '$item_text' => strip_tags(bbcode($it['msg'])),
372 '$item_when' => relative_date($it['date'])
376 $notif_content .= t('No more system notifications.');
379 $o .= replace_macros($notif_tpl, array(
380 '$notif_header' => t('System Notifications'),
382 '$notif_content' => $notif_content,
385 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
387 $notif_tpl = get_markup_template('notifications.tpl');
389 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
390 $myurl = substr($myurl,strpos($myurl,'://')+3);
391 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
392 $diasp_url = str_replace('/profile/','/u/',$myurl);
393 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
395 dbesc($myurl . '\\]'),
396 dbesc($diasp_url . '\\]')
400 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
401 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
402 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
403 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
404 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
406 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
410 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
411 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
412 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
413 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
414 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
420 foreach ($r as $it) {
423 $notif_content .= replace_macros($tpl_item_likes,array(
424 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
425 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
426 '$item_image' => $it['author-avatar'],
427 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
428 '$item_when' => relative_date($it['created'])
432 case ACTIVITY_DISLIKE:
433 $notif_content .= replace_macros($tpl_item_dislikes,array(
434 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
435 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
436 '$item_image' => $it['author-avatar'],
437 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
438 '$item_when' => relative_date($it['created'])
442 case ACTIVITY_FRIEND:
444 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
445 $obj = parse_xml_string($xmlhead.$it['object']);
446 $it['fname'] = $obj->title;
448 $notif_content .= replace_macros($tpl_item_friends,array(
449 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
450 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
451 '$item_image' => $it['author-avatar'],
452 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
453 '$item_when' => relative_date($it['created'])
458 $item_text = (($it['id'] == $it['parent'])
459 ? sprintf( t("%s created a new post"), $it['author-name'])
460 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
461 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
463 $notif_content .= replace_macros($tpl,array(
464 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
465 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
466 '$item_image' => $it['author-avatar'],
467 '$item_text' => $item_text,
468 '$item_when' => relative_date($it['created'])
475 $notif_content = t('No more personal notifications.');
478 $o .= replace_macros($notif_tpl, array(
479 '$notif_header' => t('Personal Notifications'),
481 '$notif_content' => $notif_content,
489 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
491 $notif_tpl = get_markup_template('notifications.tpl');
493 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
494 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
495 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
496 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
497 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
498 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
502 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
503 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
504 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
505 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
511 foreach ($r as $it) {
514 $notif_content .= replace_macros($tpl_item_likes,array(
515 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
516 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
517 '$item_image' => $it['author-avatar'],
518 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
519 '$item_when' => relative_date($it['created'])
523 case ACTIVITY_DISLIKE:
524 $notif_content .= replace_macros($tpl_item_dislikes,array(
525 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
526 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
527 '$item_image' => $it['author-avatar'],
528 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
529 '$item_when' => relative_date($it['created'])
533 case ACTIVITY_FRIEND:
535 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
536 $obj = parse_xml_string($xmlhead.$it['object']);
537 $it['fname'] = $obj->title;
539 $notif_content .= replace_macros($tpl_item_friends,array(
540 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
541 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
542 '$item_image' => $it['author-avatar'],
543 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
544 '$item_when' => relative_date($it['created'])
549 $notif_content .= replace_macros($tpl_item_comments,array(
550 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
551 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
552 '$item_image' => $it['author-avatar'],
553 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
554 '$item_when' => relative_date($it['created'])
560 $notif_content = t('No more home notifications.');
563 $o .= replace_macros($notif_tpl, array(
564 '$notif_header' => t('Home Notifications'),
566 '$notif_content' => $notif_content,