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 LIMIT 1",
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 LIMIT 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 LIMIT 1",
54 goaway($a->get_baseurl(true) . '/notifications/intros');
63 function notifications_content(&$a) {
66 notice( t('Permission denied.') . EOL);
70 nav_set_selected('notifications');
75 'label' => t('System'),
76 'url'=>$a->get_baseurl(true) . '/notifications/system',
77 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
80 'label' => t('Network'),
81 'url'=>$a->get_baseurl(true) . '/notifications/network',
82 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
85 'label' => t('Personal'),
86 'url'=>$a->get_baseurl(true) . '/notifications/personal',
87 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
91 'url' => $a->get_baseurl(true) . '/notifications/home',
92 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
95 'label' => t('Introductions'),
96 'url' => $a->get_baseurl(true) . '/notifications/intros',
97 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
100 'label' => t('Messages'),
101 'url' => $a->get_baseurl(true) . '/message',
109 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
110 nav_set_selected('introductions');
111 if(($a->argc > 2) && ($a->argv[2] == 'all'))
114 $sql_extra = " AND `ignore` = 0 ";
116 $notif_tpl = get_markup_template('notifications.tpl');
118 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
119 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
121 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
122 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
123 intval($_SESSION['uid'])
125 if($r && count($r)) {
126 $a->set_pager_total($r[0]['total']);
127 $a->set_pager_itemspage(20);
130 $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`
131 FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
132 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
133 intval($_SESSION['uid']));
135 if(($r !== false) && (count($r))) {
137 $sugg = get_markup_template('suggestions.tpl');
138 $tpl = get_markup_template("intros.tpl");
143 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
144 $notif_content .= replace_macros($sugg,array(
145 '$str_notifytype' => t('Notification type: '),
146 '$notify_type' => t('Friend Suggestion'),
147 '$intro_id' => $rr['intro_id'],
148 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
149 '$contact_id' => $rr['contact-id'],
150 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/person-175.jpg"),
151 '$fullname' => $rr['fname'],
152 '$url' => zrl($rr['furl']),
153 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
154 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
156 '$knowyou' => $knowyou,
157 '$approve' => t('Approve'),
158 '$note' => $rr['note'],
159 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
160 '$ignore' => t('Ignore'),
161 '$discard' => t('Discard')
168 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
169 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
170 $dfrn_tpl = get_markup_template('netfriend.tpl');
175 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
176 if($rr['network'] === NETWORK_DFRN)
177 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
180 $dfrn_text = replace_macros($dfrn_tpl,array(
181 '$intro_id' => $rr['intro_id'],
182 '$friend_selected' => $friend_selected,
183 '$fan_selected' => $fan_selected,
184 '$approve_as' => t('Approve as: '),
185 '$as_friend' => t('Friend'),
186 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
190 $notif_content .= replace_macros($tpl,array(
191 '$str_notifytype' => t('Notification type: '),
192 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
193 '$dfrn_text' => $dfrn_text,
194 '$dfrn_id' => $rr['issued-id'],
195 '$uid' => $_SESSION['uid'],
196 '$intro_id' => $rr['intro_id'],
197 '$contact_id' => $rr['contact-id'],
198 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/person-175.jpg"),
199 '$fullname' => $rr['name'],
200 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
201 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
202 '$url' => zrl($rr['url']),
203 '$knowyou' => $knowyou,
204 '$approve' => t('Approve'),
205 '$note' => $rr['note'],
206 '$ignore' => t('Ignore'),
207 '$discard' => t('Discard')
213 info( t('No introductions.') . EOL);
215 $o .= replace_macros($notif_tpl,array(
216 '$notif_header' => t('Notifications'),
218 '$notif_content' => $notif_content,
224 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
226 $notif_tpl = get_markup_template('notifications.tpl');
228 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
229 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
230 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
231 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
232 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
233 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
237 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
238 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
239 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
240 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
241 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
247 foreach ($r as $it) {
250 $notif_content .= replace_macros($tpl_item_likes,array(
251 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
252 '$item_image' => $it['author-avatar'],
253 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
254 '$item_when' => relative_date($it['created'])
258 case ACTIVITY_DISLIKE:
259 $notif_content .= replace_macros($tpl_item_dislikes,array(
260 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
261 '$item_image' => $it['author-avatar'],
262 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
263 '$item_when' => relative_date($it['created'])
267 case ACTIVITY_FRIEND:
269 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
270 $obj = parse_xml_string($xmlhead.$it['object']);
271 $it['fname'] = $obj->title;
273 $notif_content .= replace_macros($tpl_item_friends,array(
274 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
275 '$item_image' => $it['author-avatar'],
276 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
277 '$item_when' => relative_date($it['created'])
282 $item_text = (($it['id'] == $it['parent'])
283 ? sprintf( t("%s created a new post"), $it['author-name'])
284 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
285 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
287 $notif_content .= replace_macros($tpl,array(
288 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
289 '$item_image' => $it['author-avatar'],
290 '$item_text' => $item_text,
291 '$item_when' => relative_date($it['created'])
298 $notif_content = t('No more network notifications.');
301 $o .= replace_macros($notif_tpl,array(
302 '$notif_header' => t('Network Notifications'),
304 '$notif_content' => $notif_content,
307 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
309 $notif_tpl = get_markup_template('notifications.tpl');
311 $not_tpl = get_markup_template('notify.tpl');
312 require_once('include/bbcode.php');
314 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
319 foreach ($r as $it) {
320 $notif_content .= replace_macros($not_tpl,array(
321 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
322 '$item_image' => $it['photo'],
323 '$item_text' => strip_tags(bbcode($it['msg'])),
324 '$item_when' => relative_date($it['date'])
328 $notif_content .= t('No more system notifications.');
331 $o .= replace_macros($notif_tpl,array(
332 '$notif_header' => t('System Notifications'),
334 '$notif_content' => $notif_content,
337 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
339 $notif_tpl = get_markup_template('notifications.tpl');
341 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
342 $myurl = substr($myurl,strpos($myurl,'://')+3);
343 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
344 $diasp_url = str_replace('/profile/','/u/',$myurl);
345 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
347 dbesc($myurl . '\\]'),
348 dbesc($diasp_url . '\\]')
352 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
353 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
354 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
355 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
356 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
358 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
362 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
363 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
364 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
365 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
366 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
372 foreach ($r as $it) {
375 $notif_content .= replace_macros($tpl_item_likes,array(
376 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
377 '$item_image' => $it['author-avatar'],
378 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
379 '$item_when' => relative_date($it['created'])
383 case ACTIVITY_DISLIKE:
384 $notif_content .= replace_macros($tpl_item_dislikes,array(
385 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
386 '$item_image' => $it['author-avatar'],
387 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
388 '$item_when' => relative_date($it['created'])
392 case ACTIVITY_FRIEND:
394 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
395 $obj = parse_xml_string($xmlhead.$it['object']);
396 $it['fname'] = $obj->title;
398 $notif_content .= replace_macros($tpl_item_friends,array(
399 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
400 '$item_image' => $it['author-avatar'],
401 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
402 '$item_when' => relative_date($it['created'])
407 $item_text = (($it['id'] == $it['parent'])
408 ? sprintf( t("%s created a new post"), $it['author-name'])
409 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
410 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
412 $notif_content .= replace_macros($tpl,array(
413 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
414 '$item_image' => $it['author-avatar'],
415 '$item_text' => $item_text,
416 '$item_when' => relative_date($it['created'])
423 $notif_content = t('No more personal notifications.');
426 $o .= replace_macros($notif_tpl,array(
427 '$notif_header' => t('Personal Notifications'),
429 '$notif_content' => $notif_content,
437 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
439 $notif_tpl = get_markup_template('notifications.tpl');
441 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
442 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
443 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
444 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
445 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
446 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
450 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
451 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
452 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
453 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
459 foreach ($r as $it) {
462 $notif_content .= replace_macros($tpl_item_likes,array(
463 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
464 '$item_image' => $it['author-avatar'],
465 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
466 '$item_when' => relative_date($it['created'])
470 case ACTIVITY_DISLIKE:
471 $notif_content .= replace_macros($tpl_item_dislikes,array(
472 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
473 '$item_image' => $it['author-avatar'],
474 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
475 '$item_when' => relative_date($it['created'])
479 case ACTIVITY_FRIEND:
481 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
482 $obj = parse_xml_string($xmlhead.$it['object']);
483 $it['fname'] = $obj->title;
485 $notif_content .= replace_macros($tpl_item_friends,array(
486 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
487 '$item_image' => $it['author-avatar'],
488 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
489 '$item_when' => relative_date($it['created'])
494 $notif_content .= replace_macros($tpl_item_comments,array(
495 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
496 '$item_image' => $it['author-avatar'],
497 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
498 '$item_when' => relative_date($it['created'])
504 $notif_content = t('No more home notifications.');
507 $o .= replace_macros($notif_tpl,array(
508 '$notif_header' => t('Home Notifications'),
510 '$notif_content' => $notif_content,