2 include_once("include/bbcode.php");
3 include_once("include/contact_selectors.php");
4 include_once("include/Scrape.php");
6 function notifications_post(&$a) {
12 $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
14 if($request_id === "all")
19 $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
25 $intro_id = $r[0]['id'];
26 $contact_id = $r[0]['contact-id'];
29 notice( t('Invalid request identifier.') . EOL);
33 // If it is a friend suggestion, the contact is not a new friend but an existing friend
34 // that should not be deleted.
38 if($_POST['submit'] == t('Discard')) {
39 $r = q("DELETE FROM `intro` WHERE `id` = %d",
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
47 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1",
52 goaway('notifications/intros');
54 if($_POST['submit'] == t('Ignore')) {
55 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
57 goaway('notifications/intros');
66 function notifications_content(&$a) {
69 notice( t('Permission denied.') . EOL);
73 nav_set_selected('notifications');
75 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
81 'label' => t('System'),
82 'url'=>'notifications/system',
83 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
87 'label' => t('Network'),
88 'url'=>'notifications/network',
89 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
93 'label' => t('Personal'),
94 'url'=>'notifications/personal',
95 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
100 'url' => 'notifications/home',
101 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
105 'label' => t('Introductions'),
106 'url' => 'notifications/intros',
107 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
111 'label' => t('Messages'),
114 ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */
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'))
125 $sql_extra = " AND `ignore` = 0 ";
127 $notif_tpl = get_markup_template('notifications.tpl');
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";
132 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
133 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
134 intval($_SESSION['uid'])
136 if($r && count($r)) {
137 $a->set_pager_total($r[0]['total']);
138 $a->set_pager_itemspage(20);
141 /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
143 $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`,
144 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
145 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
146 `gcontact`.`network` AS `gnetwork`
148 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
149 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
150 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
151 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
152 intval($_SESSION['uid']));
154 if(($r !== false) && (count($r))) {
156 $sugg = get_markup_template('suggestions.tpl');
157 $tpl = get_markup_template("intros.tpl");
163 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
165 $notif_content .= replace_macros($sugg, array(
166 '$str_notifytype' => t('Notification type: '),
167 '$notify_type' => t('Friend Suggestion'),
168 '$intro_id' => $rr['intro_id'],
169 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
170 '$contact_id' => $rr['contact-id'],
171 '$photo' => ((x($rr,'fphoto')) ? proxy_url($rr['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
172 '$fullname' => $rr['fname'],
173 '$url' => zrl($rr['furl']),
174 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
175 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
177 '$knowyou' => $knowyou,
178 '$approve' => t('Approve'),
179 '$note' => $rr['note'],
180 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
181 '$ignore' => t('Ignore'),
182 '$discard' => t('Discard'),
189 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
190 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
191 $dfrn_tpl = get_markup_template('netfriend.tpl');
196 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
197 if($rr['network'] === NETWORK_DFRN) {
198 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
199 $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: ');
202 $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: ');
205 $dfrn_text = replace_macros($dfrn_tpl,array(
206 '$intro_id' => $rr['intro_id'],
207 '$friend_selected' => $friend_selected,
208 '$fan_selected' => $fan_selected,
209 '$approve_as' => $helptext,
210 '$as_friend' => t('Friend'),
211 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
215 $header = $rr["name"];
217 $ret = probe_url($rr["url"]);
219 if ($rr['gnetwork'] == "")
220 $rr['gnetwork'] = $ret["network"];
222 if ($ret["addr"] != "")
223 $header .= " <".$ret["addr"].">";
225 $header .= " (".network_to_name($rr['gnetwork'], $rr['url']).")";
227 // Don't show these data until you are connected. Diaspora is doing the same.
228 if($rr['gnetwork'] === NETWORK_DIASPORA) {
229 $rr['glocation'] = "";
234 $notif_content .= replace_macros($tpl, array(
235 '$header' => htmlentities($header),
236 '$str_notifytype' => t('Notification type: '),
237 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
238 '$dfrn_text' => $dfrn_text,
239 '$dfrn_id' => $rr['issued-id'],
240 '$uid' => $_SESSION['uid'],
241 '$intro_id' => $rr['intro_id'],
242 '$contact_id' => $rr['contact-id'],
243 '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
244 '$fullname' => $rr['name'],
245 '$location' => bbcode($rr['glocation'], false, false),
246 '$location_label' => t('Location:'),
247 '$about' => bbcode($rr['gabout'], false, false),
248 '$about_label' => t('About:'),
249 '$keywords' => $rr['gkeywords'],
250 '$keywords_label' => t('Tags:'),
251 '$gender' => $rr['ggender'],
252 '$gender_label' => t('Gender:'),
253 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
254 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
255 '$url' => $rr['url'],
256 '$zrl' => zrl($rr['url']),
257 '$url_label' => t('Profile URL'),
258 '$knowyou' => $knowyou,
259 '$approve' => t('Approve'),
260 '$note' => $rr['note'],
261 '$ignore' => t('Ignore'),
262 '$discard' => t('Discard'),
268 info( t('No introductions.') . EOL);
270 $o .= replace_macros($notif_tpl, array(
271 '$notif_header' => t('Notifications'),
273 '$notif_content' => $notif_content,
279 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
281 $notif_tpl = get_markup_template('notifications.tpl');
283 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
284 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
285 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
286 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
287 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
288 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
292 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
293 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
294 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
295 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
296 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
302 foreach ($r as $it) {
305 $notif_content .= replace_macros($tpl_item_likes,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' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
309 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
310 '$item_when' => relative_date($it['created'])
314 case ACTIVITY_DISLIKE:
315 $notif_content .= replace_macros($tpl_item_dislikes,array(
316 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
317 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
318 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
319 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
320 '$item_when' => relative_date($it['created'])
324 case ACTIVITY_FRIEND:
326 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
327 $obj = parse_xml_string($xmlhead.$it['object']);
328 $it['fname'] = $obj->title;
330 $notif_content .= replace_macros($tpl_item_friends,array(
331 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
332 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
333 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
334 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
335 '$item_when' => relative_date($it['created'])
340 $item_text = (($it['id'] == $it['parent'])
341 ? sprintf( t("%s created a new post"), $it['author-name'])
342 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
343 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
345 $notif_content .= replace_macros($tpl,array(
346 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
347 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
348 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
349 '$item_text' => $item_text,
350 '$item_when' => relative_date($it['created'])
357 $notif_content = t('No more network notifications.');
360 $o .= replace_macros($notif_tpl, array(
361 '$notif_header' => t('Network Notifications'),
363 '$notif_content' => $notif_content,
366 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
368 $notif_tpl = get_markup_template('notifications.tpl');
370 $not_tpl = get_markup_template('notify.tpl');
371 require_once('include/bbcode.php');
373 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
378 foreach ($r as $it) {
379 $notif_content .= replace_macros($not_tpl,array(
380 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
381 '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO),
382 '$item_text' => strip_tags(bbcode($it['msg'])),
383 '$item_when' => relative_date($it['date'])
387 $notif_content .= t('No more system notifications.');
390 $o .= replace_macros($notif_tpl, array(
391 '$notif_header' => t('System Notifications'),
393 '$notif_content' => $notif_content,
396 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
398 $notif_tpl = get_markup_template('notifications.tpl');
400 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
401 $myurl = substr($myurl,strpos($myurl,'://')+3);
402 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
403 $diasp_url = str_replace('/profile/','/u/',$myurl);
404 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
406 dbesc($myurl . '\\]'),
407 dbesc($diasp_url . '\\]')
411 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
412 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
413 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
414 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
415 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
417 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
421 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
422 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
423 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
424 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
425 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
431 foreach ($r as $it) {
434 $notif_content .= replace_macros($tpl_item_likes,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 liked %s's post"), $it['author-name'], $it['pname']),
439 '$item_when' => relative_date($it['created'])
443 case ACTIVITY_DISLIKE:
444 $notif_content .= replace_macros($tpl_item_dislikes,array(
445 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
446 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
447 '$item_image' => $it['author-avatar'],
448 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
449 '$item_when' => relative_date($it['created'])
453 case ACTIVITY_FRIEND:
455 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
456 $obj = parse_xml_string($xmlhead.$it['object']);
457 $it['fname'] = $obj->title;
459 $notif_content .= replace_macros($tpl_item_friends,array(
460 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
461 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
462 '$item_image' => $it['author-avatar'],
463 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
464 '$item_when' => relative_date($it['created'])
469 $item_text = (($it['id'] == $it['parent'])
470 ? sprintf( t("%s created a new post"), $it['author-name'])
471 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
472 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
474 $notif_content .= replace_macros($tpl,array(
475 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
476 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
477 '$item_image' => $it['author-avatar'],
478 '$item_text' => $item_text,
479 '$item_when' => relative_date($it['created'])
486 $notif_content = t('No more personal notifications.');
489 $o .= replace_macros($notif_tpl, array(
490 '$notif_header' => t('Personal Notifications'),
492 '$notif_content' => $notif_content,
500 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
502 $notif_tpl = get_markup_template('notifications.tpl');
504 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
505 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
506 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
507 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
508 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
509 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
513 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
514 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
515 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
516 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
522 foreach ($r as $it) {
525 $notif_content .= replace_macros($tpl_item_likes,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 liked %s's post"), $it['author-name'], $it['pname']),
530 '$item_when' => relative_date($it['created'])
534 case ACTIVITY_DISLIKE:
535 $notif_content .= replace_macros($tpl_item_dislikes,array(
536 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
537 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
538 '$item_image' => $it['author-avatar'],
539 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
540 '$item_when' => relative_date($it['created'])
544 case ACTIVITY_FRIEND:
546 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
547 $obj = parse_xml_string($xmlhead.$it['object']);
548 $it['fname'] = $obj->title;
550 $notif_content .= replace_macros($tpl_item_friends,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 is now friends with %s"), $it['author-name'], $it['fname']),
555 '$item_when' => relative_date($it['created'])
560 $notif_content .= replace_macros($tpl_item_comments,array(
561 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
562 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
563 '$item_image' => $it['author-avatar'],
564 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
565 '$item_when' => relative_date($it['created'])
571 $notif_content = t('No more home notifications.');
574 $o .= replace_macros($notif_tpl, array(
575 '$notif_header' => t('Home Notifications'),
577 '$notif_content' => $notif_content,