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",
47 if($_POST['submit'] == t('Ignore')) {
48 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
59 function notifications_content(&$a) {
62 notice( t('Permission denied.') . EOL);
66 nav_set_selected('notifications');
71 'label' => t('Network'),
72 'url'=>$a->get_baseurl() . '/notifications/network',
73 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''),
76 'label' => t('Personal'),
77 'url'=>$a->get_baseurl() . '/notifications/personal',
78 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''),
82 'url' => $a->get_baseurl() . '/notifications/home',
83 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
86 'label' => t('Introductions'),
87 'url' => $a->get_baseurl() . '/notifications/intros',
88 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
91 'label' => t('Messages'),
92 'url' => $a->get_baseurl() . '/message',
100 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
101 nav_set_selected('introductions');
102 if(($a->argc > 2) && ($a->argv[2] == 'all'))
105 $sql_extra = " AND `ignore` = 0 ";
107 $notif_tpl = get_markup_template('notifications.tpl');
109 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
110 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
112 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
113 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
114 intval($_SESSION['uid'])
116 if($r && count($r)) {
117 $a->set_pager_total($r[0]['total']);
118 $a->set_pager_itemspage(20);
121 $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`
122 FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
123 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
124 intval($_SESSION['uid']));
126 if(($r !== false) && (count($r))) {
128 $sugg = get_markup_template('suggestions.tpl');
129 $tpl = get_markup_template("intros.tpl");
134 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
135 $notif_content .= replace_macros($sugg,array(
136 '$str_notifytype' => t('Notification type: '),
137 '$notify_type' => t('Friend Suggestion'),
138 '$intro_id' => $rr['intro_id'],
139 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
140 '$contact_id' => $rr['contact-id'],
141 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/default-profile.jpg"),
142 '$fullname' => $rr['fname'],
143 '$url' => $rr['furl'],
144 '$knowyou' => $knowyou,
145 '$approve' => t('Approve'),
146 '$note' => $rr['note'],
147 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
148 '$ignore' => t('Ignore'),
149 '$discard' => t('Discard')
156 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
157 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
158 $dfrn_tpl = get_markup_template('netfriend.tpl');
163 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
164 if($rr['network'] === NETWORK_DFRN)
165 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
168 $dfrn_text = replace_macros($dfrn_tpl,array(
169 '$intro_id' => $rr['intro_id'],
170 '$friend_selected' => $friend_selected,
171 '$fan_selected' => $fan_selected,
172 '$approve_as' => t('Approve as: '),
173 '$as_friend' => t('Friend'),
174 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
178 $notif_content .= replace_macros($tpl,array(
179 '$str_notifytype' => t('Notification type: '),
180 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
181 '$dfrn_text' => $dfrn_text,
182 '$dfrn_id' => $rr['issued-id'],
183 '$uid' => $_SESSION['uid'],
184 '$intro_id' => $rr['intro_id'],
185 '$contact_id' => $rr['contact-id'],
186 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
187 '$fullname' => $rr['name'],
188 '$url' => $rr['url'],
189 '$knowyou' => $knowyou,
190 '$approve' => t('Approve'),
191 '$note' => $rr['note'],
192 '$ignore' => t('Ignore'),
193 '$discard' => t('Discard')
199 info( t('No introductions.') . EOL);
201 $o .= replace_macros($notif_tpl,array(
202 '$notif_header' => t('Notifications'),
204 '$notif_content' => $notif_content,
210 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
212 $notif_tpl = get_markup_template('notifications.tpl');
214 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
215 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
216 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
217 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
218 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
219 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
223 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
224 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
225 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
226 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
227 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
233 foreach ($r as $it) {
236 $notif_content .= replace_macros($tpl_item_likes,array(
237 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
238 '$item_image' => $it['author-avatar'],
239 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
240 '$item_when' => relative_date($it['created'])
244 case ACTIVITY_DISLIKE:
245 $notif_content .= replace_macros($tpl_item_dislikes,array(
246 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
247 '$item_image' => $it['author-avatar'],
248 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
249 '$item_when' => relative_date($it['created'])
253 case ACTIVITY_FRIEND:
255 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
256 $obj = parse_xml_string($xmlhead.$it['object']);
257 $it['fname'] = $obj->title;
259 $notif_content .= replace_macros($tpl_item_friends,array(
260 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
261 '$item_image' => $it['author-avatar'],
262 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
263 '$item_when' => relative_date($it['created'])
268 $item_text = (($it['id'] == $it['parent'])
269 ? sprintf( t("%s created a new post"), $it['author-name'])
270 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
271 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
273 $notif_content .= replace_macros($tpl,array(
274 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
275 '$item_image' => $it['author-avatar'],
276 '$item_text' => $item_text,
277 '$item_when' => relative_date($it['created'])
284 $notif_content = t('No more network notifications.');
287 $o .= replace_macros($notif_tpl,array(
288 '$notif_header' => t('Notifications'),
290 '$notif_content' => $notif_content,
293 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
295 $notif_tpl = get_markup_template('notifications.tpl');
297 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
298 $myurl = substr($myurl,strpos($myurl,'://')+3);
299 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
300 $diasp_url = str_replace('/profile/','/u/',$myurl);
301 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
303 dbesc($myurl . '\\]'),
304 dbesc($diasp_url . '\\]')
308 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
309 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
310 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
311 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
312 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
314 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
318 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
319 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
320 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
321 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
322 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
328 foreach ($r as $it) {
331 $notif_content .= replace_macros($tpl_item_likes,array(
332 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
333 '$item_image' => $it['author-avatar'],
334 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
335 '$item_when' => relative_date($it['created'])
339 case ACTIVITY_DISLIKE:
340 $notif_content .= replace_macros($tpl_item_dislikes,array(
341 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
342 '$item_image' => $it['author-avatar'],
343 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
344 '$item_when' => relative_date($it['created'])
348 case ACTIVITY_FRIEND:
350 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
351 $obj = parse_xml_string($xmlhead.$it['object']);
352 $it['fname'] = $obj->title;
354 $notif_content .= replace_macros($tpl_item_friends,array(
355 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
356 '$item_image' => $it['author-avatar'],
357 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
358 '$item_when' => relative_date($it['created'])
363 $item_text = (($it['id'] == $it['parent'])
364 ? sprintf( t("%s created a new post"), $it['author-name'])
365 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
366 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
368 $notif_content .= replace_macros($tpl,array(
369 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
370 '$item_image' => $it['author-avatar'],
371 '$item_text' => $item_text,
372 '$item_when' => relative_date($it['created'])
379 $notif_content = t('No more personal notifications.');
382 $o .= replace_macros($notif_tpl,array(
383 '$notif_header' => t('Notifications'),
385 '$notif_content' => $notif_content,
393 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
395 $notif_tpl = get_markup_template('notifications.tpl');
397 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
398 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
399 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
400 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
401 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
402 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
406 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
407 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
408 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
409 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
415 foreach ($r as $it) {
418 $notif_content .= replace_macros($tpl_item_likes,array(
419 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
420 '$item_image' => $it['author-avatar'],
421 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
422 '$item_when' => relative_date($it['created'])
426 case ACTIVITY_DISLIKE:
427 $notif_content .= replace_macros($tpl_item_dislikes,array(
428 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
429 '$item_image' => $it['author-avatar'],
430 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
431 '$item_when' => relative_date($it['created'])
435 case ACTIVITY_FRIEND:
437 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
438 $obj = parse_xml_string($xmlhead.$it['object']);
439 $it['fname'] = $obj->title;
441 $notif_content .= replace_macros($tpl_item_friends,array(
442 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
443 '$item_image' => $it['author-avatar'],
444 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
445 '$item_when' => relative_date($it['created'])
450 $notif_content .= replace_macros($tpl_item_comments,array(
451 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
452 '$item_image' => $it['author-avatar'],
453 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
454 '$item_when' => relative_date($it['created'])
460 $notif_content = t('No more home notifications.');
463 $o .= replace_macros($notif_tpl,array(
464 '$notif_header' => t('Notifications'),
466 '$notif_content' => $notif_content,