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');
62 function notifications_content(&$a) {
65 notice( t('Permission denied.') . EOL);
69 nav_set_selected('notifications');
71 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
75 // get the nav tabs for the notification pages
76 $tabs = notifications_tabs($a);
77 $notif_content = array();
79 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
80 nav_set_selected('introductions');
82 if(($a->argc > 2) && ($a->argv[2] == 'all'))
85 $sql_extra = " AND `ignore` = 0 ";
87 $notif_header = t('Notifications');
88 $notif_tpl = get_markup_template('notifications.tpl');
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";
93 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
94 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
95 intval($_SESSION['uid'])
98 $a->set_pager_total($r[0]['total']);
99 $a->set_pager_itemspage(20);
102 /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
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`
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']));
115 if(($r !== false) && (count($r))) {
117 $sugg = get_markup_template('suggestions.tpl');
118 $tpl = get_markup_template("intros.tpl");
124 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
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')),
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'),
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');
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: ');
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: ');
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'))
177 $header = $rr["name"];
179 $ret = probe_url($rr["url"]);
181 if ($rr['gnetwork'] == "")
182 $rr['gnetwork'] = $ret["network"];
184 if ($ret["addr"] != "")
185 $header .= " <".$ret["addr"].">";
187 $header .= " (".network_to_name($rr['gnetwork'], $rr['url']).")";
189 // Don't show these data until you are connected. Diaspora is doing the same.
190 if($rr['gnetwork'] === NETWORK_DIASPORA) {
191 $rr['glocation'] = "";
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 '$lbl_location' => t('Location:'),
209 '$about' => bbcode($rr['gabout'], false, false),
210 '$lbl_about' => t('About:'),
211 '$keywords' => $rr['gkeywords'],
212 '$lbl_keywords' => t('Tags:'),
213 '$gender' => $rr['ggender'],
214 '$lbl_gender' => 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 '$lbl_url' => 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'),
234 info( t('No introductions.') . EOL);
236 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
238 $notif_header = t('Network Notifications');
239 $notif_tpl = get_markup_template('notifications.tpl');
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" ,
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');
258 foreach ($r as $it) {
261 $notif_content[] = replace_macros($tpl_item_likes,array(
262 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
263 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
264 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
265 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
266 '$item_when' => relative_date($it['created'])
270 case ACTIVITY_DISLIKE:
271 $notif_content[] = replace_macros($tpl_item_dislikes,array(
272 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
273 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
274 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
275 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
276 '$item_when' => relative_date($it['created'])
280 case ACTIVITY_FRIEND:
282 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
283 $obj = parse_xml_string($xmlhead.$it['object']);
284 $it['fname'] = $obj->title;
286 $notif_content[] = replace_macros($tpl_item_friends,array(
287 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
288 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
289 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
290 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
291 '$item_when' => relative_date($it['created'])
296 $item_text = (($it['id'] == $it['parent'])
297 ? sprintf( t("%s created a new post"), $it['author-name'])
298 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
299 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
301 $notif_content[] = replace_macros($tpl,array(
302 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
303 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
304 '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
305 '$item_text' => $item_text,
306 '$item_when' => relative_date($it['created'])
313 $notif_nocontent = t('No more network notifications.');
316 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
318 $notif_header = t('System Notifications');
319 $notif_tpl = get_markup_template('notifications.tpl');
321 $not_tpl = get_markup_template('notify.tpl');
322 require_once('include/bbcode.php');
324 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
329 foreach ($r as $it) {
330 $notif_content[] = replace_macros($not_tpl,array(
331 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
332 '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO),
333 '$item_text' => strip_tags(bbcode($it['msg'])),
334 '$item_when' => relative_date($it['date'])
338 $notif_nocontent = t('No more system notifications.');
341 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
343 $notif_header = t('Personal Notifications');
344 $notif_tpl = get_markup_template('notifications.tpl');
346 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
347 $myurl = substr($myurl,strpos($myurl,'://')+3);
348 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
349 $diasp_url = str_replace('/profile/','/u/',$myurl);
350 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
352 dbesc($myurl . '\\]'),
353 dbesc($diasp_url . '\\]')
357 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
358 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
359 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
360 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
361 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
363 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
367 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
368 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
369 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
370 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
371 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
375 foreach ($r as $it) {
378 $notif_content[] = replace_macros($tpl_item_likes,array(
379 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
380 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
381 '$item_image' => $it['author-avatar'],
382 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
383 '$item_when' => relative_date($it['created'])
387 case ACTIVITY_DISLIKE:
388 $notif_content[] = replace_macros($tpl_item_dislikes,array(
389 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
390 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
391 '$item_image' => $it['author-avatar'],
392 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
393 '$item_when' => relative_date($it['created'])
397 case ACTIVITY_FRIEND:
399 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
400 $obj = parse_xml_string($xmlhead.$it['object']);
401 $it['fname'] = $obj->title;
403 $notif_content[] = replace_macros($tpl_item_friends,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 is now friends with %s"), $it['author-name'], $it['fname']),
408 '$item_when' => relative_date($it['created'])
413 $item_text = (($it['id'] == $it['parent'])
414 ? sprintf( t("%s created a new post"), $it['author-name'])
415 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
416 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
418 $notif_content[] = replace_macros($tpl,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' => $item_text,
423 '$item_when' => relative_date($it['created'])
430 $notif_nocontent = t('No more personal notifications.');
433 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
435 $notif_header = t('Home Notifications');
436 $notif_tpl = get_markup_template('notifications.tpl');
438 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
439 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
440 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
441 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
442 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
443 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
447 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
448 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
449 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
450 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
454 foreach ($r as $it) {
457 $notif_content[] = replace_macros($tpl_item_likes,array(
458 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
459 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
460 '$item_image' => $it['author-avatar'],
461 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
462 '$item_when' => relative_date($it['created'])
466 case ACTIVITY_DISLIKE:
467 $notif_content[] = replace_macros($tpl_item_dislikes,array(
468 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
469 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
470 '$item_image' => $it['author-avatar'],
471 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
472 '$item_when' => relative_date($it['created'])
476 case ACTIVITY_FRIEND:
478 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
479 $obj = parse_xml_string($xmlhead.$it['object']);
480 $it['fname'] = $obj->title;
482 $notif_content[] = replace_macros($tpl_item_friends,array(
483 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
484 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
485 '$item_image' => $it['author-avatar'],
486 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
487 '$item_when' => relative_date($it['created'])
492 $notif_content[] = replace_macros($tpl_item_comments,array(
493 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
494 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
495 '$item_image' => $it['author-avatar'],
496 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
497 '$item_when' => relative_date($it['created'])
503 $notif_nocontent = t('No more home notifications.');
508 $o .= replace_macros($notif_tpl, array(
509 '$notif_header' => $notif_header,
511 '$notif_content' => $notif_content,
512 '$notif_nocontent' => $notif_nocontent,
513 '$notif_ignored_lnk' => $notif_ignored_lnk,
519 * @brief List of pages for the Notifications TabBar
522 * @return array with with notifications TabBar data
524 function notifications_tabs($a) {
527 'label' => t('System'),
528 'url'=>'notifications/system',
529 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
533 'label' => t('Network'),
534 'url'=>'notifications/network',
535 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
539 'label' => t('Personal'),
540 'url'=>'notifications/personal',
541 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
545 'label' => t('Home'),
546 'url' => 'notifications/home',
547 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
551 'label' => t('Introductions'),
552 'url' => 'notifications/intros',
553 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
557 'label' => t('Messages'),
560 ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */