2 include_once("include/bbcode.php");
3 include_once("include/contact_selectors.php");
4 include_once("include/Scrape.php");
6 if(! function_exists('notifications_post')) {
7 function notifications_post(&$a) {
13 $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
15 if($request_id === "all")
20 $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
26 $intro_id = $r[0]['id'];
27 $contact_id = $r[0]['contact-id'];
30 notice( t('Invalid request identifier.') . EOL);
34 // If it is a friend suggestion, the contact is not a new friend but an existing friend
35 // that should not be deleted.
39 if($_POST['submit'] == t('Discard')) {
40 $r = q("DELETE FROM `intro` WHERE `id` = %d",
45 // The check for blocked and pending is in case the friendship was already approved
46 // and we just want to get rid of the now pointless notification
48 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1",
53 goaway($a->get_baseurl(true) . '/notifications/intros');
55 if($_POST['submit'] == t('Ignore')) {
56 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
58 goaway($a->get_baseurl(true) . '/notifications/intros');
66 if(! function_exists('notifications_content')) {
67 function notifications_content(&$a) {
70 notice( t('Permission denied.') . EOL);
74 nav_set_selected('notifications');
76 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
82 'label' => t('System'),
83 'url'=>$a->get_baseurl(true) . '/notifications/system',
84 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
88 'label' => t('Network'),
89 'url'=>$a->get_baseurl(true) . '/notifications/network',
90 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
94 'label' => t('Personal'),
95 'url'=>$a->get_baseurl(true) . '/notifications/personal',
96 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
100 'label' => t('Home'),
101 'url' => $a->get_baseurl(true) . '/notifications/home',
102 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
106 'label' => t('Introductions'),
107 'url' => $a->get_baseurl(true) . '/notifications/intros',
108 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
112 'label' => t('Messages'),
113 'url' => $a->get_baseurl(true) . '/message',
115 ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */
121 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
122 nav_set_selected('introductions');
123 if(($a->argc > 2) && ($a->argv[2] == 'all'))
126 $sql_extra = " AND `ignore` = 0 ";
128 $notif_tpl = get_markup_template('notifications.tpl');
130 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
131 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
133 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
134 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
135 intval($_SESSION['uid'])
137 if($r && count($r)) {
138 $a->set_pager_total($r[0]['total']);
139 $a->set_pager_itemspage(20);
142 $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`,
143 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
144 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
145 `gcontact`.`network` AS `gnetwork`
147 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
148 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
149 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
150 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
151 intval($_SESSION['uid']));
153 if(($r !== false) && (count($r))) {
155 $sugg = get_markup_template('suggestions.tpl');
156 $tpl = get_markup_template("intros.tpl");
162 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
164 $notif_content .= replace_macros($sugg, array(
165 '$str_notifytype' => t('Notification type: '),
166 '$notify_type' => t('Friend Suggestion'),
167 '$intro_id' => $rr['intro_id'],
168 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
169 '$contact_id' => $rr['contact-id'],
170 '$photo' => ((x($rr,'fphoto')) ? proxy_url($rr['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
171 '$fullname' => $rr['fname'],
172 '$url' => zrl($rr['furl']),
173 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
174 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
176 '$knowyou' => $knowyou,
177 '$approve' => t('Approve'),
178 '$note' => $rr['note'],
179 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
180 '$ignore' => t('Ignore'),
181 '$discard' => t('Discard'),
188 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
189 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
190 $dfrn_tpl = get_markup_template('netfriend.tpl');
195 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
196 if($rr['network'] === NETWORK_DFRN) {
197 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
198 $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: ');
201 $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: ');
204 $dfrn_text = replace_macros($dfrn_tpl,array(
205 '$intro_id' => $rr['intro_id'],
206 '$friend_selected' => $friend_selected,
207 '$fan_selected' => $fan_selected,
208 '$approve_as' => $helptext,
209 '$as_friend' => t('Friend'),
210 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
214 $header = $rr["name"];
216 $ret = probe_url($rr["url"]);
218 if ($rr['gnetwork'] == "")
219 $rr['gnetwork'] = $ret["network"];
221 if ($ret["addr"] != "")
222 $header .= " <".$ret["addr"].">";
224 $header .= " (".network_to_name($rr['gnetwork'], $rr['url']).")";
226 // Don't show these data until you are connected. Diaspora is doing the same.
227 if($rr['gnetwork'] === NETWORK_DIASPORA) {
228 $rr['glocation'] = "";
233 $notif_content .= replace_macros($tpl, array(
234 '$header' => htmlentities($header),
235 '$str_notifytype' => t('Notification type: '),
236 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
237 '$dfrn_text' => $dfrn_text,
238 '$dfrn_id' => $rr['issued-id'],
239 '$uid' => $_SESSION['uid'],
240 '$intro_id' => $rr['intro_id'],
241 '$contact_id' => $rr['contact-id'],
242 '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
243 '$fullname' => $rr['name'],
244 '$location' => bbcode($rr['glocation'], false, false),
245 '$location_label' => t('Location:'),
246 '$about' => bbcode($rr['gabout'], false, false),
247 '$about_label' => t('About:'),
248 '$keywords' => $rr['gkeywords'],
249 '$keywords_label' => t('Tags:'),
250 '$gender' => $rr['ggender'],
251 '$gender_label' => t('Gender:'),
252 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
253 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
254 '$url' => $rr['url'],
255 '$zrl' => zrl($rr['url']),
256 '$url_label' => t('Profile URL'),
257 '$knowyou' => $knowyou,
258 '$approve' => t('Approve'),
259 '$note' => $rr['note'],
260 '$ignore' => t('Ignore'),
261 '$discard' => t('Discard'),
267 info( t('No introductions.') . EOL);
269 $o .= replace_macros($notif_tpl, array(
270 '$notif_header' => t('Notifications'),
272 '$notif_content' => $notif_content,
278 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
280 $notif_tpl = get_markup_template('notifications.tpl');
282 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
283 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
284 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
285 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
286 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
287 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
291 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
292 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
293 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
294 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
295 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
301 foreach ($r as $it) {
304 $notif_content .= replace_macros($tpl_item_likes,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' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
308 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
309 '$item_when' => relative_date($it['created'])
313 case ACTIVITY_DISLIKE:
314 $notif_content .= replace_macros($tpl_item_dislikes,array(
315 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
316 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
317 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
318 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
319 '$item_when' => relative_date($it['created'])
323 case ACTIVITY_FRIEND:
325 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
326 $obj = parse_xml_string($xmlhead.$it['object']);
327 $it['fname'] = $obj->title;
329 $notif_content .= replace_macros($tpl_item_friends,array(
330 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
331 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
332 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
333 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
334 '$item_when' => relative_date($it['created'])
339 $item_text = (($it['id'] == $it['parent'])
340 ? sprintf( t("%s created a new post"), $it['author-name'])
341 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
342 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
344 $notif_content .= replace_macros($tpl,array(
345 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
346 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
347 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
348 '$item_text' => $item_text,
349 '$item_when' => relative_date($it['created'])
356 $notif_content = t('No more network notifications.');
359 $o .= replace_macros($notif_tpl, array(
360 '$notif_header' => t('Network Notifications'),
362 '$notif_content' => $notif_content,
365 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
367 $notif_tpl = get_markup_template('notifications.tpl');
369 $not_tpl = get_markup_template('notify.tpl');
370 require_once('include/bbcode.php');
372 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
377 foreach ($r as $it) {
378 $notif_content .= replace_macros($not_tpl,array(
379 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
380 '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO),
381 '$item_text' => strip_tags(bbcode($it['msg'])),
382 '$item_when' => relative_date($it['date'])
386 $notif_content .= t('No more system notifications.');
389 $o .= replace_macros($notif_tpl, array(
390 '$notif_header' => t('System Notifications'),
392 '$notif_content' => $notif_content,
395 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
397 $notif_tpl = get_markup_template('notifications.tpl');
399 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
400 $myurl = substr($myurl,strpos($myurl,'://')+3);
401 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
402 $diasp_url = str_replace('/profile/','/u/',$myurl);
403 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
405 dbesc($myurl . '\\]'),
406 dbesc($diasp_url . '\\]')
410 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
411 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
412 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
413 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
414 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
416 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
420 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
421 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
422 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
423 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
424 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
430 foreach ($r as $it) {
433 $notif_content .= replace_macros($tpl_item_likes,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 liked %s's post"), $it['author-name'], $it['pname']),
438 '$item_when' => relative_date($it['created'])
442 case ACTIVITY_DISLIKE:
443 $notif_content .= replace_macros($tpl_item_dislikes,array(
444 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
445 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
446 '$item_image' => $it['author-avatar'],
447 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
448 '$item_when' => relative_date($it['created'])
452 case ACTIVITY_FRIEND:
454 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
455 $obj = parse_xml_string($xmlhead.$it['object']);
456 $it['fname'] = $obj->title;
458 $notif_content .= replace_macros($tpl_item_friends,array(
459 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
460 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
461 '$item_image' => $it['author-avatar'],
462 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
463 '$item_when' => relative_date($it['created'])
468 $item_text = (($it['id'] == $it['parent'])
469 ? sprintf( t("%s created a new post"), $it['author-name'])
470 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
471 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
473 $notif_content .= replace_macros($tpl,array(
474 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
475 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
476 '$item_image' => $it['author-avatar'],
477 '$item_text' => $item_text,
478 '$item_when' => relative_date($it['created'])
485 $notif_content = t('No more personal notifications.');
488 $o .= replace_macros($notif_tpl, array(
489 '$notif_header' => t('Personal Notifications'),
491 '$notif_content' => $notif_content,
499 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
501 $notif_tpl = get_markup_template('notifications.tpl');
503 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
504 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
505 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
506 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
507 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
508 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
512 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
513 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
514 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
515 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
521 foreach ($r as $it) {
524 $notif_content .= replace_macros($tpl_item_likes,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 liked %s's post"), $it['author-name'], $it['pname']),
529 '$item_when' => relative_date($it['created'])
533 case ACTIVITY_DISLIKE:
534 $notif_content .= replace_macros($tpl_item_dislikes,array(
535 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
536 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
537 '$item_image' => $it['author-avatar'],
538 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
539 '$item_when' => relative_date($it['created'])
543 case ACTIVITY_FRIEND:
545 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
546 $obj = parse_xml_string($xmlhead.$it['object']);
547 $it['fname'] = $obj->title;
549 $notif_content .= replace_macros($tpl_item_friends,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 is now friends with %s"), $it['author-name'], $it['fname']),
554 '$item_when' => relative_date($it['created'])
559 $notif_content .= replace_macros($tpl_item_comments,array(
560 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
561 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
562 '$item_image' => $it['author-avatar'],
563 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
564 '$item_when' => relative_date($it['created'])
570 $notif_content = t('No more home notifications.');
573 $o .= replace_macros($notif_tpl, array(
574 '$notif_header' => t('Home Notifications'),
576 '$notif_content' => $notif_content,