2 include_once("include/NotificationsManager.php");
3 include_once("include/bbcode.php");
4 include_once("include/contact_selectors.php");
5 include_once("include/Scrape.php");
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('notifications/intros');
55 if($_POST['submit'] == t('Ignore')) {
56 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
58 goaway('notifications/intros');
63 function notifications_content(&$a) {
66 notice( t('Permission denied.') . EOL);
70 nav_set_selected('notifications');
72 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
74 $nm = new NotificationsManager();
77 // get the nav tabs for the notification pages
78 $tabs = $nm->getTabs();
79 $notif_content = array();
81 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
82 nav_set_selected('introductions');
84 if(($a->argc > 2) && ($a->argv[2] == 'all'))
87 $sql_extra = " AND `ignore` = 0 ";
89 $notif_header = t('Notifications');
90 $notif_tpl = get_markup_template('notifications.tpl');
92 $notif_ignored_lnk .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
93 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
95 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
96 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
97 intval($_SESSION['uid'])
100 $a->set_pager_total($r[0]['total']);
101 $a->set_pager_itemspage(20);
104 /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
106 $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`,
107 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
108 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
109 `gcontact`.`network` AS `gnetwork`
111 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
112 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
113 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
114 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
115 intval($_SESSION['uid']));
117 if(($r !== false) && (count($r))) {
119 $sugg = get_markup_template('suggestions.tpl');
120 $tpl = get_markup_template("intros.tpl");
126 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
128 $notif_content[] = replace_macros($sugg, array(
129 '$str_notifytype' => t('Notification type: '),
130 '$notify_type' => t('Friend Suggestion'),
131 '$intro_id' => $rr['intro_id'],
132 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
133 '$contact_id' => $rr['contact-id'],
134 '$photo' => ((x($rr,'fphoto')) ? proxy_url($rr['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
135 '$fullname' => $rr['fname'],
136 '$url' => zrl($rr['furl']),
137 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
138 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
140 '$knowyou' => $knowyou,
141 '$approve' => t('Approve'),
142 '$note' => $rr['note'],
143 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
144 '$ignore' => t('Ignore'),
145 '$discard' => t('Discard'),
152 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
153 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
154 $dfrn_tpl = get_markup_template('netfriend.tpl');
159 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
160 if($rr['network'] === NETWORK_DFRN) {
161 $lbl_knowyou = t('Claims to be known to you: ');
162 $knowyou = (($rr['knowyou']) ? t('yes') : t('no'));
163 $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: ');
166 $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: ');
169 $dfrn_text = replace_macros($dfrn_tpl,array(
170 '$intro_id' => $rr['intro_id'],
171 '$friend_selected' => $friend_selected,
172 '$fan_selected' => $fan_selected,
173 '$approve_as' => $helptext,
174 '$as_friend' => t('Friend'),
175 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
179 $header = $rr["name"];
181 $ret = probe_url($rr["url"]);
183 if ($rr['gnetwork'] == "")
184 $rr['gnetwork'] = $ret["network"];
186 if ($ret["addr"] != "")
187 $header .= " <".$ret["addr"].">";
189 $header .= " (".network_to_name($rr['gnetwork'], $rr['url']).")";
191 // Don't show these data until you are connected. Diaspora is doing the same.
192 if($rr['gnetwork'] === NETWORK_DIASPORA) {
193 $rr['glocation'] = "";
198 $notif_content[] = replace_macros($tpl, array(
199 '$header' => htmlentities($header),
200 '$str_notifytype' => t('Notification type: '),
201 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
202 '$dfrn_text' => $dfrn_text,
203 '$dfrn_id' => $rr['issued-id'],
204 '$uid' => $_SESSION['uid'],
205 '$intro_id' => $rr['intro_id'],
206 '$contact_id' => $rr['contact-id'],
207 '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
208 '$fullname' => $rr['name'],
209 '$location' => bbcode($rr['glocation'], false, false),
210 '$location_label' => t('Location:'),
211 '$about' => bbcode($rr['gabout'], false, false),
212 '$about_label' => t('About:'),
213 '$keywords' => $rr['gkeywords'],
214 '$keywords_label' => t('Tags:'),
215 '$gender' => $rr['ggender'],
216 '$gender_label' => t('Gender:'),
217 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
218 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
219 '$url' => $rr['url'],
220 '$zrl' => zrl($rr['url']),
221 '$url_label' => t('Profile URL'),
222 '$addr' => $rr['addr'],
223 '$lbl_knowyou' => $lbl_knowyou,
224 '$lbl_network' => t('Network:'),
225 '$network' => network_to_name($rr['gnetwork'], $rr['url']),
226 '$knowyou' => $knowyou,
227 '$approve' => t('Approve'),
228 '$note' => $rr['note'],
229 '$ignore' => t('Ignore'),
230 '$discard' => t('Discard'),
236 info( t('No introductions.') . EOL);
238 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
240 $notif_header = t('Network Notifications');
241 $notif_tpl = get_markup_template('notifications.tpl');
243 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
244 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
245 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
246 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
247 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
248 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
252 // $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
253 // $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
254 // $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
255 // $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
256 // $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
261 'notifications' => $r,
262 'ident' => 'network',
265 // foreach ($r as $it) {
266 // switch($it['verb']){
267 // case ACTIVITY_LIKE:
268 // $notif_content[] = replace_macros($tpl_item_likes,array(
269 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
270 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
271 // '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
272 // '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
273 // '$item_when' => relative_date($it['created'])
277 // case ACTIVITY_DISLIKE:
278 // $notif_content[] = replace_macros($tpl_item_dislikes,array(
279 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
280 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
281 // '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
282 // '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
283 // '$item_when' => relative_date($it['created'])
287 // case ACTIVITY_FRIEND:
289 // $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
290 // $obj = parse_xml_string($xmlhead.$it['object']);
291 // $it['fname'] = $obj->title;
293 // $notif_content[] = replace_macros($tpl_item_friends,array(
294 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
295 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
296 // '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
297 // '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
298 // '$item_when' => relative_date($it['created'])
303 // $item_text = (($it['id'] == $it['parent'])
304 // ? sprintf( t("%s created a new post"), $it['author-name'])
305 // : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
306 // $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
308 // $notif_content[] = replace_macros($tpl,array(
309 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
310 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
311 // '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
312 // '$item_text' => $item_text,
313 // '$item_when' => relative_date($it['created'])
320 $notif_nocontent = t('No more network notifications.');
323 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
325 $notif_header = t('System Notifications');
326 $notif_tpl = get_markup_template('notifications.tpl');
328 $not_tpl = get_markup_template('notify.tpl');
329 require_once('include/bbcode.php');
331 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
336 // foreach ($r as $it) {
337 // $notif_content[] = replace_macros($not_tpl,array(
338 // '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
339 // '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO),
340 // '$item_text' => strip_tags(bbcode($it['msg'])),
341 // '$item_when' => relative_date($it['date'])
345 'notifications' => $r,
350 $notif_nocontent = t('No more system notifications.');
353 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
355 $notif_header = t('Personal Notifications');
356 $notif_tpl = get_markup_template('notifications.tpl');
358 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
359 $myurl = substr($myurl,strpos($myurl,'://')+3);
360 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
361 $diasp_url = str_replace('/profile/','/u/',$myurl);
362 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
364 dbesc($myurl . '\\]'),
365 dbesc($diasp_url . '\\]')
369 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
370 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
371 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
372 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
373 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
375 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
379 // $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
380 // $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
381 // $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
382 // $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
383 // $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
387 'notifications' => $r,
388 'ident' => 'personal'
392 // foreach ($r as $it) {
393 // switch($it['verb']){
394 // case ACTIVITY_LIKE:
395 // $notif_content[] = replace_macros($tpl_item_likes,array(
396 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
397 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
398 // '$item_image' => $it['author-avatar'],
399 // '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
400 // '$item_when' => relative_date($it['created'])
404 // case ACTIVITY_DISLIKE:
405 // $notif_content[] = replace_macros($tpl_item_dislikes,array(
406 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
407 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
408 // '$item_image' => $it['author-avatar'],
409 // '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
410 // '$item_when' => relative_date($it['created'])
414 // case ACTIVITY_FRIEND:
416 // $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
417 // $obj = parse_xml_string($xmlhead.$it['object']);
418 // $it['fname'] = $obj->title;
420 // $notif_content[] = replace_macros($tpl_item_friends,array(
421 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
422 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
423 // '$item_image' => $it['author-avatar'],
424 // '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
425 // '$item_when' => relative_date($it['created'])
430 // $item_text = (($it['id'] == $it['parent'])
431 // ? sprintf( t("%s created a new post"), $it['author-name'])
432 // : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
433 // $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
435 // $notif_content[] = replace_macros($tpl,array(
436 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
437 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
438 // '$item_image' => $it['author-avatar'],
439 // '$item_text' => $item_text,
440 // '$item_when' => relative_date($it['created'])
447 $notif_nocontent = t('No more personal notifications.');
450 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
452 $notif_header = t('Home Notifications');
453 $notif_tpl = get_markup_template('notifications.tpl');
455 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
456 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
457 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
458 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
459 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
460 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
464 // $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
465 // $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
466 // $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
467 // $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
472 'notifications' => $r,
476 // foreach ($r as $it) {
477 // switch($it['verb']){
478 // case ACTIVITY_LIKE:
479 // $notif_content[] = replace_macros($tpl_item_likes,array(
480 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
481 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
482 // '$item_image' => $it['author-avatar'],
483 // '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
484 // '$item_when' => relative_date($it['created'])
488 // case ACTIVITY_DISLIKE:
489 // $notif_content[] = replace_macros($tpl_item_dislikes,array(
490 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
491 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
492 // '$item_image' => $it['author-avatar'],
493 // '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
494 // '$item_when' => relative_date($it['created'])
498 // case ACTIVITY_FRIEND:
500 // $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
501 // $obj = parse_xml_string($xmlhead.$it['object']);
502 // $it['fname'] = $obj->title;
504 // $notif_content[] = replace_macros($tpl_item_friends,array(
505 // //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
506 // '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
507 // '$item_image' => $it['author-avatar'],
508 // '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
509 // '$item_when' => relative_date($it['created'])
514 // $notif_content[] = replace_macros($tpl_item_comments,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 commented on %s's post"), $it['author-name'], $it['pname']),
519 // '$item_when' => relative_date($it['created'])
525 $notif_nocontent = t('No more home notifications.');
530 if(count($notifs['notifications']) > 0 )
531 $notif_content =$nm->format ($notifs);
533 $o .= replace_macros($notif_tpl, array(
534 '$notif_header' => $notif_header,
536 '$notif_content' => $notif_content,
537 '$notif_nocontent' => $notif_nocontent,
538 '$notif_ignored_lnk' => $notif_ignored_lnk,