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 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
140 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`
142 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
143 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
144 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
145 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
146 intval($_SESSION['uid']));
148 if(($r !== false) && (count($r))) {
150 $sugg = get_markup_template('suggestions.tpl');
151 $tpl = get_markup_template("intros.tpl");
156 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
158 $notif_content .= replace_macros($sugg, array(
159 '$str_notifytype' => t('Notification type: '),
160 '$notify_type' => t('Friend Suggestion'),
161 '$intro_id' => $rr['intro_id'],
162 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
163 '$contact_id' => $rr['contact-id'],
164 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/person-175.jpg"),
165 '$fullname' => $rr['fname'],
166 '$url' => zrl($rr['furl']),
167 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
168 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
170 '$knowyou' => $knowyou,
171 '$approve' => t('Approve'),
172 '$note' => $rr['note'],
173 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
174 '$ignore' => t('Ignore'),
175 '$discard' => t('Discard'),
182 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
183 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
184 $dfrn_tpl = get_markup_template('netfriend.tpl');
189 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
190 if($rr['network'] === NETWORK_DFRN) {
191 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
192 $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: ');
195 $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: ');
198 $dfrn_text = replace_macros($dfrn_tpl,array(
199 '$intro_id' => $rr['intro_id'],
200 '$friend_selected' => $friend_selected,
201 '$fan_selected' => $fan_selected,
202 '$approve_as' => $helptext,
203 '$as_friend' => t('Friend'),
204 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
208 $notif_content .= replace_macros($tpl, array(
209 '$str_notifytype' => t('Notification type: '),
210 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
211 '$dfrn_text' => $dfrn_text,
212 '$dfrn_id' => $rr['issued-id'],
213 '$uid' => $_SESSION['uid'],
214 '$intro_id' => $rr['intro_id'],
215 '$contact_id' => $rr['contact-id'],
216 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/person-175.jpg"),
217 '$fullname' => $rr['name'],
218 '$location_label' => t('Location:'),
219 '$location' => $rr['glocation'],
220 '$location_label' => t('Location:'),
221 '$about' => $rr['gabout'],
222 '$about_label' => t('About:'),
223 '$keywords' => $rr['gkeywords'],
224 '$keywords_label' => t('Tags:'),
225 '$gender' => $rr['ggender'],
226 '$gender_label' => t('Gender:'),
227 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
228 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
229 '$url' => zrl($rr['url']),
230 '$knowyou' => $knowyou,
231 '$approve' => t('Approve'),
232 '$note' => $rr['note'],
233 '$ignore' => t('Ignore'),
234 '$discard' => t('Discard'),
240 info( t('No introductions.') . EOL);
242 $o .= replace_macros($notif_tpl, array(
243 '$notif_header' => t('Notifications'),
245 '$notif_content' => $notif_content,
251 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
253 $notif_tpl = get_markup_template('notifications.tpl');
255 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
256 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
257 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
258 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
259 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
260 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
264 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
265 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
266 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
267 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
268 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
274 foreach ($r as $it) {
277 $notif_content .= replace_macros($tpl_item_likes,array(
278 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
279 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
280 '$item_image' => $it['author-avatar'],
281 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
282 '$item_when' => relative_date($it['created'])
286 case ACTIVITY_DISLIKE:
287 $notif_content .= replace_macros($tpl_item_dislikes,array(
288 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
289 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
290 '$item_image' => $it['author-avatar'],
291 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
292 '$item_when' => relative_date($it['created'])
296 case ACTIVITY_FRIEND:
298 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
299 $obj = parse_xml_string($xmlhead.$it['object']);
300 $it['fname'] = $obj->title;
302 $notif_content .= replace_macros($tpl_item_friends,array(
303 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
304 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
305 '$item_image' => $it['author-avatar'],
306 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
307 '$item_when' => relative_date($it['created'])
312 $item_text = (($it['id'] == $it['parent'])
313 ? sprintf( t("%s created a new post"), $it['author-name'])
314 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
315 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
317 $notif_content .= replace_macros($tpl,array(
318 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
319 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
320 '$item_image' => $it['author-avatar'],
321 '$item_text' => $item_text,
322 '$item_when' => relative_date($it['created'])
329 $notif_content = t('No more network notifications.');
332 $o .= replace_macros($notif_tpl, array(
333 '$notif_header' => t('Network Notifications'),
335 '$notif_content' => $notif_content,
338 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
340 $notif_tpl = get_markup_template('notifications.tpl');
342 $not_tpl = get_markup_template('notify.tpl');
343 require_once('include/bbcode.php');
345 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
350 foreach ($r as $it) {
351 $notif_content .= replace_macros($not_tpl,array(
352 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
353 '$item_image' => $it['photo'],
354 '$item_text' => strip_tags(bbcode($it['msg'])),
355 '$item_when' => relative_date($it['date'])
359 $notif_content .= t('No more system notifications.');
362 $o .= replace_macros($notif_tpl, array(
363 '$notif_header' => t('System Notifications'),
365 '$notif_content' => $notif_content,
368 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
370 $notif_tpl = get_markup_template('notifications.tpl');
372 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
373 $myurl = substr($myurl,strpos($myurl,'://')+3);
374 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
375 $diasp_url = str_replace('/profile/','/u/',$myurl);
376 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
378 dbesc($myurl . '\\]'),
379 dbesc($diasp_url . '\\]')
383 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
384 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
385 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
386 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
387 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
389 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
393 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
394 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
395 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
396 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
397 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
403 foreach ($r as $it) {
406 $notif_content .= replace_macros($tpl_item_likes,array(
407 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
408 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
409 '$item_image' => $it['author-avatar'],
410 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
411 '$item_when' => relative_date($it['created'])
415 case ACTIVITY_DISLIKE:
416 $notif_content .= replace_macros($tpl_item_dislikes,array(
417 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
418 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
419 '$item_image' => $it['author-avatar'],
420 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
421 '$item_when' => relative_date($it['created'])
425 case ACTIVITY_FRIEND:
427 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
428 $obj = parse_xml_string($xmlhead.$it['object']);
429 $it['fname'] = $obj->title;
431 $notif_content .= replace_macros($tpl_item_friends,array(
432 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
433 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
434 '$item_image' => $it['author-avatar'],
435 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
436 '$item_when' => relative_date($it['created'])
441 $item_text = (($it['id'] == $it['parent'])
442 ? sprintf( t("%s created a new post"), $it['author-name'])
443 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
444 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
446 $notif_content .= replace_macros($tpl,array(
447 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
448 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
449 '$item_image' => $it['author-avatar'],
450 '$item_text' => $item_text,
451 '$item_when' => relative_date($it['created'])
458 $notif_content = t('No more personal notifications.');
461 $o .= replace_macros($notif_tpl, array(
462 '$notif_header' => t('Personal Notifications'),
464 '$notif_content' => $notif_content,
472 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
474 $notif_tpl = get_markup_template('notifications.tpl');
476 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
477 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
478 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
479 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
480 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
481 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
485 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
486 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
487 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
488 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
494 foreach ($r as $it) {
497 $notif_content .= replace_macros($tpl_item_likes,array(
498 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
499 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
500 '$item_image' => $it['author-avatar'],
501 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
502 '$item_when' => relative_date($it['created'])
506 case ACTIVITY_DISLIKE:
507 $notif_content .= replace_macros($tpl_item_dislikes,array(
508 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
509 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
510 '$item_image' => $it['author-avatar'],
511 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
512 '$item_when' => relative_date($it['created'])
516 case ACTIVITY_FRIEND:
518 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
519 $obj = parse_xml_string($xmlhead.$it['object']);
520 $it['fname'] = $obj->title;
522 $notif_content .= replace_macros($tpl_item_friends,array(
523 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
524 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
525 '$item_image' => $it['author-avatar'],
526 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
527 '$item_when' => relative_date($it['created'])
532 $notif_content .= replace_macros($tpl_item_comments,array(
533 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
534 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
535 '$item_image' => $it['author-avatar'],
536 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
537 '$item_when' => relative_date($it['created'])
543 $notif_content = t('No more home notifications.');
546 $o .= replace_macros($notif_tpl, array(
547 '$notif_header' => t('Home Notifications'),
549 '$notif_content' => $notif_content,