2 include_once("include/bbcode.php");
4 function notifications_post(&$a) {
10 $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
12 if($request_id === "all")
17 $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
23 $intro_id = $r[0]['id'];
24 $contact_id = $r[0]['contact-id'];
27 notice( t('Invalid request identifier.') . EOL);
31 // If it is a friend suggestion, the contact is not a new friend but an existing friend
32 // that should not be deleted.
36 if($_POST['submit'] == t('Discard')) {
37 $r = q("DELETE FROM `intro` WHERE `id` = %d",
42 // The check for blocked and pending is in case the friendship was already approved
43 // and we just want to get rid of the now pointless notification
45 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1",
50 goaway($a->get_baseurl(true) . '/notifications/intros');
52 if($_POST['submit'] == t('Ignore')) {
53 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
55 goaway($a->get_baseurl(true) . '/notifications/intros');
64 function notifications_content(&$a) {
67 notice( t('Permission denied.') . EOL);
71 nav_set_selected('notifications');
73 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
79 'label' => t('System'),
80 'url'=>$a->get_baseurl(true) . '/notifications/system',
81 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
85 'label' => t('Network'),
86 'url'=>$a->get_baseurl(true) . '/notifications/network',
87 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
91 'label' => t('Personal'),
92 'url'=>$a->get_baseurl(true) . '/notifications/personal',
93 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
98 'url' => $a->get_baseurl(true) . '/notifications/home',
99 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
103 'label' => t('Introductions'),
104 'url' => $a->get_baseurl(true) . '/notifications/intros',
105 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
109 'label' => t('Messages'),
110 'url' => $a->get_baseurl(true) . '/message',
112 ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */
118 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
119 nav_set_selected('introductions');
120 if(($a->argc > 2) && ($a->argv[2] == 'all'))
123 $sql_extra = " AND `ignore` = 0 ";
125 $notif_tpl = get_markup_template('notifications.tpl');
127 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
128 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
130 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
131 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
132 intval($_SESSION['uid'])
134 if($r && count($r)) {
135 $a->set_pager_total($r[0]['total']);
136 $a->set_pager_itemspage(20);
139 $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`,
140 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
141 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`
143 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
144 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
145 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
146 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
147 intval($_SESSION['uid']));
149 if(($r !== false) && (count($r))) {
151 $sugg = get_markup_template('suggestions.tpl');
152 $tpl = get_markup_template("intros.tpl");
157 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
159 $notif_content .= replace_macros($sugg, array(
160 '$str_notifytype' => t('Notification type: '),
161 '$notify_type' => t('Friend Suggestion'),
162 '$intro_id' => $rr['intro_id'],
163 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
164 '$contact_id' => $rr['contact-id'],
165 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/person-175.jpg"),
166 '$fullname' => $rr['fname'],
167 '$url' => zrl($rr['furl']),
168 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
169 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
171 '$knowyou' => $knowyou,
172 '$approve' => t('Approve'),
173 '$note' => $rr['note'],
174 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
175 '$ignore' => t('Ignore'),
176 '$discard' => t('Discard'),
183 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
184 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
185 $dfrn_tpl = get_markup_template('netfriend.tpl');
190 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
191 if($rr['network'] === NETWORK_DFRN) {
192 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
193 $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: ');
196 $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: ');
199 $dfrn_text = replace_macros($dfrn_tpl,array(
200 '$intro_id' => $rr['intro_id'],
201 '$friend_selected' => $friend_selected,
202 '$fan_selected' => $fan_selected,
203 '$approve_as' => $helptext,
204 '$as_friend' => t('Friend'),
205 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
209 $notif_content .= replace_macros($tpl, array(
210 '$str_notifytype' => t('Notification type: '),
211 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
212 '$dfrn_text' => $dfrn_text,
213 '$dfrn_id' => $rr['issued-id'],
214 '$uid' => $_SESSION['uid'],
215 '$intro_id' => $rr['intro_id'],
216 '$contact_id' => $rr['contact-id'],
217 '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo']) : "images/person-175.jpg"),
218 '$fullname' => $rr['name'],
219 '$location_label' => t('Location:'),
220 '$location' => $rr['glocation'],
221 '$location_label' => t('Location:'),
222 '$about' => proxy_parse_html(bbcode($rr['gabout'], false, false)),
223 '$about_label' => t('About:'),
224 '$keywords' => $rr['gkeywords'],
225 '$keywords_label' => t('Tags:'),
226 '$gender' => $rr['ggender'],
227 '$gender_label' => t('Gender:'),
228 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
229 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
230 '$url' => zrl($rr['url']),
231 '$knowyou' => $knowyou,
232 '$approve' => t('Approve'),
233 '$note' => $rr['note'],
234 '$ignore' => t('Ignore'),
235 '$discard' => t('Discard'),
241 info( t('No introductions.') . EOL);
243 $o .= replace_macros($notif_tpl, array(
244 '$notif_header' => t('Notifications'),
246 '$notif_content' => $notif_content,
252 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
254 $notif_tpl = get_markup_template('notifications.tpl');
256 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
257 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
258 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
259 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
260 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
261 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
265 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
266 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
267 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
268 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
269 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
275 foreach ($r as $it) {
278 $notif_content .= replace_macros($tpl_item_likes,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' => $it['author-avatar'],
282 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
283 '$item_when' => relative_date($it['created'])
287 case ACTIVITY_DISLIKE:
288 $notif_content .= replace_macros($tpl_item_dislikes,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 disliked %s's post"), $it['author-name'], $it['pname']),
293 '$item_when' => relative_date($it['created'])
297 case ACTIVITY_FRIEND:
299 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
300 $obj = parse_xml_string($xmlhead.$it['object']);
301 $it['fname'] = $obj->title;
303 $notif_content .= replace_macros($tpl_item_friends,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' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
308 '$item_when' => relative_date($it['created'])
313 $item_text = (($it['id'] == $it['parent'])
314 ? sprintf( t("%s created a new post"), $it['author-name'])
315 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
316 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
318 $notif_content .= replace_macros($tpl,array(
319 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
320 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
321 '$item_image' => $it['author-avatar'],
322 '$item_text' => $item_text,
323 '$item_when' => relative_date($it['created'])
330 $notif_content = t('No more network notifications.');
333 $o .= replace_macros($notif_tpl, array(
334 '$notif_header' => t('Network Notifications'),
336 '$notif_content' => $notif_content,
339 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
341 $notif_tpl = get_markup_template('notifications.tpl');
343 $not_tpl = get_markup_template('notify.tpl');
344 require_once('include/bbcode.php');
346 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
351 foreach ($r as $it) {
352 $notif_content .= replace_macros($not_tpl,array(
353 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
354 '$item_image' => $it['photo'],
355 '$item_text' => strip_tags(bbcode($it['msg'])),
356 '$item_when' => relative_date($it['date'])
360 $notif_content .= t('No more system notifications.');
363 $o .= replace_macros($notif_tpl, array(
364 '$notif_header' => t('System Notifications'),
366 '$notif_content' => $notif_content,
369 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
371 $notif_tpl = get_markup_template('notifications.tpl');
373 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
374 $myurl = substr($myurl,strpos($myurl,'://')+3);
375 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
376 $diasp_url = str_replace('/profile/','/u/',$myurl);
377 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
379 dbesc($myurl . '\\]'),
380 dbesc($diasp_url . '\\]')
384 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
385 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
386 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
387 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
388 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
390 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
394 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
395 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
396 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
397 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
398 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
404 foreach ($r as $it) {
407 $notif_content .= replace_macros($tpl_item_likes,array(
408 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
409 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
410 '$item_image' => $it['author-avatar'],
411 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
412 '$item_when' => relative_date($it['created'])
416 case ACTIVITY_DISLIKE:
417 $notif_content .= replace_macros($tpl_item_dislikes,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 disliked %s's post"), $it['author-name'], $it['pname']),
422 '$item_when' => relative_date($it['created'])
426 case ACTIVITY_FRIEND:
428 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
429 $obj = parse_xml_string($xmlhead.$it['object']);
430 $it['fname'] = $obj->title;
432 $notif_content .= replace_macros($tpl_item_friends,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' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
437 '$item_when' => relative_date($it['created'])
442 $item_text = (($it['id'] == $it['parent'])
443 ? sprintf( t("%s created a new post"), $it['author-name'])
444 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
445 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
447 $notif_content .= replace_macros($tpl,array(
448 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
449 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
450 '$item_image' => $it['author-avatar'],
451 '$item_text' => $item_text,
452 '$item_when' => relative_date($it['created'])
459 $notif_content = t('No more personal notifications.');
462 $o .= replace_macros($notif_tpl, array(
463 '$notif_header' => t('Personal Notifications'),
465 '$notif_content' => $notif_content,
473 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
475 $notif_tpl = get_markup_template('notifications.tpl');
477 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
478 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
479 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`
480 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
481 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
482 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
486 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
487 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
488 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
489 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
495 foreach ($r as $it) {
498 $notif_content .= replace_macros($tpl_item_likes,array(
499 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
500 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
501 '$item_image' => $it['author-avatar'],
502 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
503 '$item_when' => relative_date($it['created'])
507 case ACTIVITY_DISLIKE:
508 $notif_content .= replace_macros($tpl_item_dislikes,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 disliked %s's post"), $it['author-name'], $it['pname']),
513 '$item_when' => relative_date($it['created'])
517 case ACTIVITY_FRIEND:
519 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
520 $obj = parse_xml_string($xmlhead.$it['object']);
521 $it['fname'] = $obj->title;
523 $notif_content .= replace_macros($tpl_item_friends,array(
524 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
525 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
526 '$item_image' => $it['author-avatar'],
527 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
528 '$item_when' => relative_date($it['created'])
533 $notif_content .= replace_macros($tpl_item_comments,array(
534 //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
535 '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'],
536 '$item_image' => $it['author-avatar'],
537 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
538 '$item_when' => relative_date($it['created'])
544 $notif_content = t('No more home notifications.');
547 $o .= replace_macros($notif_tpl, array(
548 '$notif_header' => t('Home Notifications'),
550 '$notif_content' => $notif_content,