3 function notifications_post(&$a) {
9 $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
11 if($request_id === "all")
16 $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
22 $intro_id = $r[0]['id'];
23 $contact_id = $r[0]['contact-id'];
26 notice( t('Invalid request identifier.') . EOL);
30 // If it is a friend suggestion, the contact is not a new friend but an existing friend
31 // that should not be deleted.
35 if($_POST['submit'] == t('Discard')) {
36 $r = q("DELETE FROM `intro` WHERE `id` = %d",
41 // The check for blocked and pending is in case the friendship was already approved
42 // and we just want to get rid of the now pointless notification
44 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1",
49 goaway($a->get_baseurl(true) . '/notifications/intros');
51 if($_POST['submit'] == t('Ignore')) {
52 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
54 goaway($a->get_baseurl(true) . '/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);
78 'label' => t('System'),
79 'url'=>$a->get_baseurl(true) . '/notifications/system',
80 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
83 'label' => t('Network'),
84 'url'=>$a->get_baseurl(true) . '/notifications/network',
85 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
88 'label' => t('Personal'),
89 'url'=>$a->get_baseurl(true) . '/notifications/personal',
90 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
94 'url' => $a->get_baseurl(true) . '/notifications/home',
95 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
98 'label' => t('Introductions'),
99 'url' => $a->get_baseurl(true) . '/notifications/intros',
100 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
103 'label' => t('Messages'),
104 'url' => $a->get_baseurl(true) . '/message',
106 ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */
112 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
113 nav_set_selected('introductions');
114 if(($a->argc > 2) && ($a->argv[2] == 'all'))
117 $sql_extra = " AND `ignore` = 0 ";
119 $notif_tpl = get_markup_template('notifications.tpl');
121 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
122 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
124 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
125 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
126 intval($_SESSION['uid'])
128 if($r && count($r)) {
129 $a->set_pager_total($r[0]['total']);
130 $a->set_pager_itemspage(20);
133 $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`
134 FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
135 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
136 intval($_SESSION['uid']));
138 if(($r !== false) && (count($r))) {
140 $sugg = get_markup_template('suggestions.tpl');
141 $tpl = get_markup_template("intros.tpl");
146 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
148 $notif_content .= replace_macros($sugg, array(
149 '$str_notifytype' => t('Notification type: '),
150 '$notify_type' => t('Friend Suggestion'),
151 '$intro_id' => $rr['intro_id'],
152 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
153 '$contact_id' => $rr['contact-id'],
154 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/person-175.jpg"),
155 '$fullname' => $rr['fname'],
156 '$url' => zrl($rr['furl']),
157 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
158 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
160 '$knowyou' => $knowyou,
161 '$approve' => t('Approve'),
162 '$note' => $rr['note'],
163 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
164 '$ignore' => t('Ignore'),
165 '$discard' => t('Discard'),
172 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
173 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
174 $dfrn_tpl = get_markup_template('netfriend.tpl');
179 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
180 if($rr['network'] === NETWORK_DFRN)
181 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
184 $dfrn_text = replace_macros($dfrn_tpl,array(
185 '$intro_id' => $rr['intro_id'],
186 '$friend_selected' => $friend_selected,
187 '$fan_selected' => $fan_selected,
188 '$approve_as' => t('Approve as: '),
189 '$as_friend' => t('Friend'),
190 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
194 $notif_content .= replace_macros($tpl, array(
195 '$str_notifytype' => t('Notification type: '),
196 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
197 '$dfrn_text' => $dfrn_text,
198 '$dfrn_id' => $rr['issued-id'],
199 '$uid' => $_SESSION['uid'],
200 '$intro_id' => $rr['intro_id'],
201 '$contact_id' => $rr['contact-id'],
202 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/person-175.jpg"),
203 '$fullname' => $rr['name'],
204 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
205 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
206 '$url' => zrl($rr['url']),
207 '$knowyou' => $knowyou,
208 '$approve' => t('Approve'),
209 '$note' => $rr['note'],
210 '$ignore' => t('Ignore'),
211 '$discard' => t('Discard'),
217 info( t('No introductions.') . EOL);
219 $o .= replace_macros($notif_tpl, array(
220 '$notif_header' => t('Notifications'),
222 '$notif_content' => $notif_content,
228 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
230 $notif_tpl = get_markup_template('notifications.tpl');
232 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
233 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
234 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
235 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
236 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
237 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
241 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
242 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
243 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
244 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
245 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
251 foreach ($r as $it) {
254 $notif_content .= replace_macros($tpl_item_likes,array(
255 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
256 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
257 '$item_image' => $it['author-avatar'],
258 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
259 '$item_when' => relative_date($it['created'])
263 case ACTIVITY_DISLIKE:
264 $notif_content .= replace_macros($tpl_item_dislikes,array(
265 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
266 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
267 '$item_image' => $it['author-avatar'],
268 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
269 '$item_when' => relative_date($it['created'])
273 case ACTIVITY_FRIEND:
275 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
276 $obj = parse_xml_string($xmlhead.$it['object']);
277 $it['fname'] = $obj->title;
279 $notif_content .= replace_macros($tpl_item_friends,array(
280 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
281 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
282 '$item_image' => $it['author-avatar'],
283 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
284 '$item_when' => relative_date($it['created'])
289 $item_text = (($it['id'] == $it['parent'])
290 ? sprintf( t("%s created a new post"), $it['author-name'])
291 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
292 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
294 $notif_content .= replace_macros($tpl,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' => $item_text,
299 '$item_when' => relative_date($it['created'])
306 $notif_content = t('No more network notifications.');
309 $o .= replace_macros($notif_tpl, array(
310 '$notif_header' => t('Network Notifications'),
312 '$notif_content' => $notif_content,
315 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
317 $notif_tpl = get_markup_template('notifications.tpl');
319 $not_tpl = get_markup_template('notify.tpl');
320 require_once('include/bbcode.php');
322 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
327 foreach ($r as $it) {
328 $notif_content .= replace_macros($not_tpl,array(
329 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
330 '$item_image' => $it['photo'],
331 '$item_text' => strip_tags(bbcode($it['msg'])),
332 '$item_when' => relative_date($it['date'])
336 $notif_content .= t('No more system notifications.');
339 $o .= replace_macros($notif_tpl, array(
340 '$notif_header' => t('System Notifications'),
342 '$notif_content' => $notif_content,
345 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
347 $notif_tpl = get_markup_template('notifications.tpl');
349 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
350 $myurl = substr($myurl,strpos($myurl,'://')+3);
351 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
352 $diasp_url = str_replace('/profile/','/u/',$myurl);
353 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
355 dbesc($myurl . '\\]'),
356 dbesc($diasp_url . '\\]')
360 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
361 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
362 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
363 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
364 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
366 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
370 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
371 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
372 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
373 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
374 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
380 foreach ($r as $it) {
383 $notif_content .= replace_macros($tpl_item_likes,array(
384 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
385 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
386 '$item_image' => $it['author-avatar'],
387 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
388 '$item_when' => relative_date($it['created'])
392 case ACTIVITY_DISLIKE:
393 $notif_content .= replace_macros($tpl_item_dislikes,array(
394 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
395 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
396 '$item_image' => $it['author-avatar'],
397 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
398 '$item_when' => relative_date($it['created'])
402 case ACTIVITY_FRIEND:
404 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
405 $obj = parse_xml_string($xmlhead.$it['object']);
406 $it['fname'] = $obj->title;
408 $notif_content .= replace_macros($tpl_item_friends,array(
409 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
410 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
411 '$item_image' => $it['author-avatar'],
412 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
413 '$item_when' => relative_date($it['created'])
418 $item_text = (($it['id'] == $it['parent'])
419 ? sprintf( t("%s created a new post"), $it['author-name'])
420 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
421 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
423 $notif_content .= replace_macros($tpl,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' => $item_text,
428 '$item_when' => relative_date($it['created'])
435 $notif_content = t('No more personal notifications.');
438 $o .= replace_macros($notif_tpl, array(
439 '$notif_header' => t('Personal Notifications'),
441 '$notif_content' => $notif_content,
449 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
451 $notif_tpl = get_markup_template('notifications.tpl');
453 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
454 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
455 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
456 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
457 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
458 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
462 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
463 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
464 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
465 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
471 foreach ($r as $it) {
474 $notif_content .= replace_macros($tpl_item_likes,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' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
479 '$item_when' => relative_date($it['created'])
483 case ACTIVITY_DISLIKE:
484 $notif_content .= replace_macros($tpl_item_dislikes,array(
485 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
486 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
487 '$item_image' => $it['author-avatar'],
488 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
489 '$item_when' => relative_date($it['created'])
493 case ACTIVITY_FRIEND:
495 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
496 $obj = parse_xml_string($xmlhead.$it['object']);
497 $it['fname'] = $obj->title;
499 $notif_content .= replace_macros($tpl_item_friends,array(
500 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
501 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
502 '$item_image' => $it['author-avatar'],
503 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
504 '$item_when' => relative_date($it['created'])
509 $notif_content .= replace_macros($tpl_item_comments,array(
510 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
511 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
512 '$item_image' => $it['author-avatar'],
513 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
514 '$item_when' => relative_date($it['created'])
520 $notif_content = t('No more home notifications.');
523 $o .= replace_macros($notif_tpl, array(
524 '$notif_header' => t('Home Notifications'),
526 '$notif_content' => $notif_content,