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",
40 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
45 goaway($a->get_baseurl(true) . '/notifications/intros');
47 if($_POST['submit'] == t('Ignore')) {
48 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
50 goaway($a->get_baseurl(true) . '/notifications/intros');
59 function notifications_content(&$a) {
62 notice( t('Permission denied.') . EOL);
66 nav_set_selected('notifications');
71 'label' => t('System'),
72 'url'=>$a->get_baseurl(true) . '/notifications/system',
73 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''),
76 'label' => t('Network'),
77 'url'=>$a->get_baseurl(true) . '/notifications/network',
78 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
81 'label' => t('Personal'),
82 'url'=>$a->get_baseurl(true) . '/notifications/personal',
83 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
87 'url' => $a->get_baseurl(true) . '/notifications/home',
88 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
91 'label' => t('Introductions'),
92 'url' => $a->get_baseurl(true) . '/notifications/intros',
93 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
96 'label' => t('Messages'),
97 'url' => $a->get_baseurl(true) . '/message',
105 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
106 nav_set_selected('introductions');
107 if(($a->argc > 2) && ($a->argv[2] == 'all'))
110 $sql_extra = " AND `ignore` = 0 ";
112 $notif_tpl = get_markup_template('notifications.tpl');
114 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
115 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
117 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
118 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
119 intval($_SESSION['uid'])
121 if($r && count($r)) {
122 $a->set_pager_total($r[0]['total']);
123 $a->set_pager_itemspage(20);
126 $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`
127 FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
128 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
129 intval($_SESSION['uid']));
131 if(($r !== false) && (count($r))) {
133 $sugg = get_markup_template('suggestions.tpl');
134 $tpl = get_markup_template("intros.tpl");
139 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
140 $notif_content .= replace_macros($sugg,array(
141 '$str_notifytype' => t('Notification type: '),
142 '$notify_type' => t('Friend Suggestion'),
143 '$intro_id' => $rr['intro_id'],
144 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
145 '$contact_id' => $rr['contact-id'],
146 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/person-175.jpg"),
147 '$fullname' => $rr['fname'],
148 '$url' => $rr['furl'],
149 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
150 '$activity' => array('activity', t('Post a new friend activity'), 1, t('if applicable')),
152 '$knowyou' => $knowyou,
153 '$approve' => t('Approve'),
154 '$note' => $rr['note'],
155 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
156 '$ignore' => t('Ignore'),
157 '$discard' => t('Discard')
164 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
165 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
166 $dfrn_tpl = get_markup_template('netfriend.tpl');
171 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
172 if($rr['network'] === NETWORK_DFRN)
173 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
176 $dfrn_text = replace_macros($dfrn_tpl,array(
177 '$intro_id' => $rr['intro_id'],
178 '$friend_selected' => $friend_selected,
179 '$fan_selected' => $fan_selected,
180 '$approve_as' => t('Approve as: '),
181 '$as_friend' => t('Friend'),
182 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
186 $notif_content .= replace_macros($tpl,array(
187 '$str_notifytype' => t('Notification type: '),
188 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
189 '$dfrn_text' => $dfrn_text,
190 '$dfrn_id' => $rr['issued-id'],
191 '$uid' => $_SESSION['uid'],
192 '$intro_id' => $rr['intro_id'],
193 '$contact_id' => $rr['contact-id'],
194 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/person-175.jpg"),
195 '$fullname' => $rr['name'],
196 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
197 '$activity' => array('activity', t('Post a new friend activity'), 1, t('if applicable')),
198 '$url' => $rr['url'],
199 '$knowyou' => $knowyou,
200 '$approve' => t('Approve'),
201 '$note' => $rr['note'],
202 '$ignore' => t('Ignore'),
203 '$discard' => t('Discard')
209 info( t('No introductions.') . EOL);
211 $o .= replace_macros($notif_tpl,array(
212 '$notif_header' => t('Notifications'),
214 '$notif_content' => $notif_content,
220 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
222 $notif_tpl = get_markup_template('notifications.tpl');
224 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
225 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
226 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
227 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
228 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
229 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
233 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
234 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
235 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
236 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
237 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
243 foreach ($r as $it) {
246 $notif_content .= replace_macros($tpl_item_likes,array(
247 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
248 '$item_image' => $it['author-avatar'],
249 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
250 '$item_when' => relative_date($it['created'])
254 case ACTIVITY_DISLIKE:
255 $notif_content .= replace_macros($tpl_item_dislikes,array(
256 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
257 '$item_image' => $it['author-avatar'],
258 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
259 '$item_when' => relative_date($it['created'])
263 case ACTIVITY_FRIEND:
265 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
266 $obj = parse_xml_string($xmlhead.$it['object']);
267 $it['fname'] = $obj->title;
269 $notif_content .= replace_macros($tpl_item_friends,array(
270 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
271 '$item_image' => $it['author-avatar'],
272 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
273 '$item_when' => relative_date($it['created'])
278 $item_text = (($it['id'] == $it['parent'])
279 ? sprintf( t("%s created a new post"), $it['author-name'])
280 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
281 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
283 $notif_content .= replace_macros($tpl,array(
284 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
285 '$item_image' => $it['author-avatar'],
286 '$item_text' => $item_text,
287 '$item_when' => relative_date($it['created'])
294 $notif_content = t('No more network notifications.');
297 $o .= replace_macros($notif_tpl,array(
298 '$notif_header' => t('Network Notifications'),
300 '$notif_content' => $notif_content,
303 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
305 $notif_tpl = get_markup_template('notifications.tpl');
307 $not_tpl = get_markup_template('notify.tpl');
308 require_once('include/bbcode.php');
310 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
315 foreach ($r as $it) {
316 $notif_content .= replace_macros($not_tpl,array(
317 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
318 '$item_image' => $it['photo'],
319 '$item_text' => strip_tags(bbcode($it['msg'])),
320 '$item_when' => relative_date($it['date'])
324 $notif_content .= t('No more system notifications.');
327 $o .= replace_macros($notif_tpl,array(
328 '$notif_header' => t('System Notifications'),
330 '$notif_content' => $notif_content,
333 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
335 $notif_tpl = get_markup_template('notifications.tpl');
337 $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname'];
338 $myurl = substr($myurl,strpos($myurl,'://')+3);
339 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
340 $diasp_url = str_replace('/profile/','/u/',$myurl);
341 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
343 dbesc($myurl . '\\]'),
344 dbesc($diasp_url . '\\]')
348 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
349 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
350 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
351 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
352 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
354 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
358 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
359 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
360 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
361 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
362 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
368 foreach ($r as $it) {
371 $notif_content .= replace_macros($tpl_item_likes,array(
372 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
373 '$item_image' => $it['author-avatar'],
374 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
375 '$item_when' => relative_date($it['created'])
379 case ACTIVITY_DISLIKE:
380 $notif_content .= replace_macros($tpl_item_dislikes,array(
381 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
382 '$item_image' => $it['author-avatar'],
383 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
384 '$item_when' => relative_date($it['created'])
388 case ACTIVITY_FRIEND:
390 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
391 $obj = parse_xml_string($xmlhead.$it['object']);
392 $it['fname'] = $obj->title;
394 $notif_content .= replace_macros($tpl_item_friends,array(
395 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
396 '$item_image' => $it['author-avatar'],
397 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
398 '$item_when' => relative_date($it['created'])
403 $item_text = (($it['id'] == $it['parent'])
404 ? sprintf( t("%s created a new post"), $it['author-name'])
405 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
406 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
408 $notif_content .= replace_macros($tpl,array(
409 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
410 '$item_image' => $it['author-avatar'],
411 '$item_text' => $item_text,
412 '$item_when' => relative_date($it['created'])
419 $notif_content = t('No more personal notifications.');
422 $o .= replace_macros($notif_tpl,array(
423 '$notif_header' => t('Personal Notifications'),
425 '$notif_content' => $notif_content,
433 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
435 $notif_tpl = get_markup_template('notifications.tpl');
437 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
438 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
439 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
440 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
441 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
442 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
446 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
447 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
448 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
449 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
455 foreach ($r as $it) {
458 $notif_content .= replace_macros($tpl_item_likes,array(
459 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
460 '$item_image' => $it['author-avatar'],
461 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
462 '$item_when' => relative_date($it['created'])
466 case ACTIVITY_DISLIKE:
467 $notif_content .= replace_macros($tpl_item_dislikes,array(
468 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
469 '$item_image' => $it['author-avatar'],
470 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
471 '$item_when' => relative_date($it['created'])
475 case ACTIVITY_FRIEND:
477 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
478 $obj = parse_xml_string($xmlhead.$it['object']);
479 $it['fname'] = $obj->title;
481 $notif_content .= replace_macros($tpl_item_friends,array(
482 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
483 '$item_image' => $it['author-avatar'],
484 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
485 '$item_when' => relative_date($it['created'])
490 $notif_content .= replace_macros($tpl_item_comments,array(
491 '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
492 '$item_image' => $it['author-avatar'],
493 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
494 '$item_when' => relative_date($it['created'])
500 $notif_content = t('No more home notifications.');
503 $o .= replace_macros($notif_tpl,array(
504 '$notif_header' => t('Home Notifications'),
506 '$notif_content' => $notif_content,