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' : ''),
84 'label' => t('Network'),
85 'url'=>$a->get_baseurl(true) . '/notifications/network',
86 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
90 'label' => t('Personal'),
91 'url'=>$a->get_baseurl(true) . '/notifications/personal',
92 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
97 'url' => $a->get_baseurl(true) . '/notifications/home',
98 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
102 'label' => t('Introductions'),
103 'url' => $a->get_baseurl(true) . '/notifications/intros',
104 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
108 'label' => t('Messages'),
109 'url' => $a->get_baseurl(true) . '/message',
111 ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */
117 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
118 nav_set_selected('introductions');
119 if(($a->argc > 2) && ($a->argv[2] == 'all'))
122 $sql_extra = " AND `ignore` = 0 ";
124 $notif_tpl = get_markup_template('notifications.tpl');
126 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
127 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
129 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
130 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
131 intval($_SESSION['uid'])
133 if($r && count($r)) {
134 $a->set_pager_total($r[0]['total']);
135 $a->set_pager_itemspage(20);
138 $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`
139 FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
140 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
141 intval($_SESSION['uid']));
143 if(($r !== false) && (count($r))) {
145 $sugg = get_markup_template('suggestions.tpl');
146 $tpl = get_markup_template("intros.tpl");
151 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
153 $notif_content .= replace_macros($sugg, array(
154 '$str_notifytype' => t('Notification type: '),
155 '$notify_type' => t('Friend Suggestion'),
156 '$intro_id' => $rr['intro_id'],
157 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
158 '$contact_id' => $rr['contact-id'],
159 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/person-175.jpg"),
160 '$fullname' => $rr['fname'],
161 '$url' => zrl($rr['furl']),
162 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
163 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
165 '$knowyou' => $knowyou,
166 '$approve' => t('Approve'),
167 '$note' => $rr['note'],
168 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
169 '$ignore' => t('Ignore'),
170 '$discard' => t('Discard'),
177 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
178 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
179 $dfrn_tpl = get_markup_template('netfriend.tpl');
184 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
185 if($rr['network'] === NETWORK_DFRN) {
186 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
187 $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: ');
190 $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: ');
193 $dfrn_text = replace_macros($dfrn_tpl,array(
194 '$intro_id' => $rr['intro_id'],
195 '$friend_selected' => $friend_selected,
196 '$fan_selected' => $fan_selected,
197 '$approve_as' => $helptext,
198 '$as_friend' => t('Friend'),
199 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
203 $notif_content .= replace_macros($tpl, array(
204 '$str_notifytype' => t('Notification type: '),
205 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
206 '$dfrn_text' => $dfrn_text,
207 '$dfrn_id' => $rr['issued-id'],
208 '$uid' => $_SESSION['uid'],
209 '$intro_id' => $rr['intro_id'],
210 '$contact_id' => $rr['contact-id'],
211 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/person-175.jpg"),
212 '$fullname' => $rr['name'],
213 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
214 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
215 '$url' => zrl($rr['url']),
216 '$knowyou' => $knowyou,
217 '$approve' => t('Approve'),
218 '$note' => $rr['note'],
219 '$ignore' => t('Ignore'),
220 '$discard' => t('Discard'),
226 info( t('No introductions.') . EOL);
228 $o .= replace_macros($notif_tpl, array(
229 '$notif_header' => t('Notifications'),
231 '$notif_content' => $notif_content,
237 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
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');
260 foreach ($r as $it) {
263 $notif_content .= replace_macros($tpl_item_likes,array(
264 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
265 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
266 '$item_image' => $it['author-avatar'],
267 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
268 '$item_when' => relative_date($it['created'])
272 case ACTIVITY_DISLIKE:
273 $notif_content .= replace_macros($tpl_item_dislikes,array(
274 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
275 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
276 '$item_image' => $it['author-avatar'],
277 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
278 '$item_when' => relative_date($it['created'])
282 case ACTIVITY_FRIEND:
284 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
285 $obj = parse_xml_string($xmlhead.$it['object']);
286 $it['fname'] = $obj->title;
288 $notif_content .= replace_macros($tpl_item_friends,array(
289 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
290 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
291 '$item_image' => $it['author-avatar'],
292 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
293 '$item_when' => relative_date($it['created'])
298 $item_text = (($it['id'] == $it['parent'])
299 ? sprintf( t("%s created a new post"), $it['author-name'])
300 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
301 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
303 $notif_content .= replace_macros($tpl,array(
304 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
305 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
306 '$item_image' => $it['author-avatar'],
307 '$item_text' => $item_text,
308 '$item_when' => relative_date($it['created'])
315 $notif_content = t('No more network notifications.');
318 $o .= replace_macros($notif_tpl, array(
319 '$notif_header' => t('Network Notifications'),
321 '$notif_content' => $notif_content,
324 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
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' => $it['photo'],
340 '$item_text' => strip_tags(bbcode($it['msg'])),
341 '$item_when' => relative_date($it['date'])
345 $notif_content .= t('No more system notifications.');
348 $o .= replace_macros($notif_tpl, array(
349 '$notif_header' => t('System Notifications'),
351 '$notif_content' => $notif_content,
354 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
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');
389 foreach ($r as $it) {
392 $notif_content .= replace_macros($tpl_item_likes,array(
393 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
394 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
395 '$item_image' => $it['author-avatar'],
396 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
397 '$item_when' => relative_date($it['created'])
401 case ACTIVITY_DISLIKE:
402 $notif_content .= replace_macros($tpl_item_dislikes,array(
403 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
404 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
405 '$item_image' => $it['author-avatar'],
406 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
407 '$item_when' => relative_date($it['created'])
411 case ACTIVITY_FRIEND:
413 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
414 $obj = parse_xml_string($xmlhead.$it['object']);
415 $it['fname'] = $obj->title;
417 $notif_content .= replace_macros($tpl_item_friends,array(
418 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
419 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
420 '$item_image' => $it['author-avatar'],
421 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
422 '$item_when' => relative_date($it['created'])
427 $item_text = (($it['id'] == $it['parent'])
428 ? sprintf( t("%s created a new post"), $it['author-name'])
429 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
430 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
432 $notif_content .= replace_macros($tpl,array(
433 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
434 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
435 '$item_image' => $it['author-avatar'],
436 '$item_text' => $item_text,
437 '$item_when' => relative_date($it['created'])
444 $notif_content = t('No more personal notifications.');
447 $o .= replace_macros($notif_tpl, array(
448 '$notif_header' => t('Personal Notifications'),
450 '$notif_content' => $notif_content,
458 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
460 $notif_tpl = get_markup_template('notifications.tpl');
462 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
463 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
464 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
465 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
466 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
467 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
471 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
472 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
473 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
474 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
480 foreach ($r as $it) {
483 $notif_content .= replace_macros($tpl_item_likes,array(
484 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
485 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
486 '$item_image' => $it['author-avatar'],
487 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
488 '$item_when' => relative_date($it['created'])
492 case ACTIVITY_DISLIKE:
493 $notif_content .= replace_macros($tpl_item_dislikes,array(
494 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
495 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
496 '$item_image' => $it['author-avatar'],
497 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
498 '$item_when' => relative_date($it['created'])
502 case ACTIVITY_FRIEND:
504 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
505 $obj = parse_xml_string($xmlhead.$it['object']);
506 $it['fname'] = $obj->title;
508 $notif_content .= replace_macros($tpl_item_friends,array(
509 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
510 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
511 '$item_image' => $it['author-avatar'],
512 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
513 '$item_when' => relative_date($it['created'])
518 $notif_content .= replace_macros($tpl_item_comments,array(
519 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
520 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
521 '$item_image' => $it['author-avatar'],
522 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
523 '$item_when' => relative_date($it['created'])
529 $notif_content = t('No more home notifications.');
532 $o .= replace_macros($notif_tpl, array(
533 '$notif_header' => t('Home Notifications'),
535 '$notif_content' => $notif_content,