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() . '/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() . '/notifications/intros');
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 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
145 '$activity' => array('activity', t('Post a new friend activity'), 1, t('if applicable')),
147 '$knowyou' => $knowyou,
148 '$approve' => t('Approve'),
149 '$note' => $rr['note'],
150 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
151 '$ignore' => t('Ignore'),
152 '$discard' => t('Discard')
159 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
160 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
161 $dfrn_tpl = get_markup_template('netfriend.tpl');
166 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
167 if($rr['network'] === NETWORK_DFRN)
168 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
171 $dfrn_text = replace_macros($dfrn_tpl,array(
172 '$intro_id' => $rr['intro_id'],
173 '$friend_selected' => $friend_selected,
174 '$fan_selected' => $fan_selected,
175 '$approve_as' => t('Approve as: '),
176 '$as_friend' => t('Friend'),
177 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
181 $notif_content .= replace_macros($tpl,array(
182 '$str_notifytype' => t('Notification type: '),
183 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
184 '$dfrn_text' => $dfrn_text,
185 '$dfrn_id' => $rr['issued-id'],
186 '$uid' => $_SESSION['uid'],
187 '$intro_id' => $rr['intro_id'],
188 '$contact_id' => $rr['contact-id'],
189 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
190 '$fullname' => $rr['name'],
191 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
192 '$activity' => array('activity', t('Post a new friend activity'), 1, t('if applicable')),
193 '$url' => $rr['url'],
194 '$knowyou' => $knowyou,
195 '$approve' => t('Approve'),
196 '$note' => $rr['note'],
197 '$ignore' => t('Ignore'),
198 '$discard' => t('Discard')
204 info( t('No introductions.') . EOL);
206 $o .= replace_macros($notif_tpl,array(
207 '$notif_header' => t('Notifications'),
209 '$notif_content' => $notif_content,
215 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
217 $notif_tpl = get_markup_template('notifications.tpl');
219 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
220 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
221 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
222 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
223 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
224 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
228 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
229 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
230 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
231 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
232 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
238 foreach ($r as $it) {
241 $notif_content .= replace_macros($tpl_item_likes,array(
242 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
243 '$item_image' => $it['author-avatar'],
244 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
245 '$item_when' => relative_date($it['created'])
249 case ACTIVITY_DISLIKE:
250 $notif_content .= replace_macros($tpl_item_dislikes,array(
251 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
252 '$item_image' => $it['author-avatar'],
253 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
254 '$item_when' => relative_date($it['created'])
258 case ACTIVITY_FRIEND:
260 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
261 $obj = parse_xml_string($xmlhead.$it['object']);
262 $it['fname'] = $obj->title;
264 $notif_content .= replace_macros($tpl_item_friends,array(
265 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
266 '$item_image' => $it['author-avatar'],
267 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
268 '$item_when' => relative_date($it['created'])
273 $item_text = (($it['id'] == $it['parent'])
274 ? sprintf( t("%s created a new post"), $it['author-name'])
275 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
276 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
278 $notif_content .= replace_macros($tpl,array(
279 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
280 '$item_image' => $it['author-avatar'],
281 '$item_text' => $item_text,
282 '$item_when' => relative_date($it['created'])
289 $notif_content = t('No more network notifications.');
292 $o .= replace_macros($notif_tpl,array(
293 '$notif_header' => t('Notifications'),
295 '$notif_content' => $notif_content,
298 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
300 $notif_tpl = get_markup_template('notifications.tpl');
302 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
303 $myurl = substr($myurl,strpos($myurl,'://')+3);
304 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
305 $diasp_url = str_replace('/profile/','/u/',$myurl);
306 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
308 dbesc($myurl . '\\]'),
309 dbesc($diasp_url . '\\]')
313 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
314 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
315 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
316 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
317 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
319 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
323 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
324 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
325 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
326 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
327 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
333 foreach ($r as $it) {
336 $notif_content .= replace_macros($tpl_item_likes,array(
337 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
338 '$item_image' => $it['author-avatar'],
339 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
340 '$item_when' => relative_date($it['created'])
344 case ACTIVITY_DISLIKE:
345 $notif_content .= replace_macros($tpl_item_dislikes,array(
346 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
347 '$item_image' => $it['author-avatar'],
348 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
349 '$item_when' => relative_date($it['created'])
353 case ACTIVITY_FRIEND:
355 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
356 $obj = parse_xml_string($xmlhead.$it['object']);
357 $it['fname'] = $obj->title;
359 $notif_content .= replace_macros($tpl_item_friends,array(
360 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
361 '$item_image' => $it['author-avatar'],
362 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
363 '$item_when' => relative_date($it['created'])
368 $item_text = (($it['id'] == $it['parent'])
369 ? sprintf( t("%s created a new post"), $it['author-name'])
370 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
371 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
373 $notif_content .= replace_macros($tpl,array(
374 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
375 '$item_image' => $it['author-avatar'],
376 '$item_text' => $item_text,
377 '$item_when' => relative_date($it['created'])
384 $notif_content = t('No more personal notifications.');
387 $o .= replace_macros($notif_tpl,array(
388 '$notif_header' => t('Notifications'),
390 '$notif_content' => $notif_content,
398 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
400 $notif_tpl = get_markup_template('notifications.tpl');
402 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
403 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
404 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
405 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
406 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
407 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
411 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
412 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
413 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
414 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
420 foreach ($r as $it) {
423 $notif_content .= replace_macros($tpl_item_likes,array(
424 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
425 '$item_image' => $it['author-avatar'],
426 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
427 '$item_when' => relative_date($it['created'])
431 case ACTIVITY_DISLIKE:
432 $notif_content .= replace_macros($tpl_item_dislikes,array(
433 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
434 '$item_image' => $it['author-avatar'],
435 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
436 '$item_when' => relative_date($it['created'])
440 case ACTIVITY_FRIEND:
442 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
443 $obj = parse_xml_string($xmlhead.$it['object']);
444 $it['fname'] = $obj->title;
446 $notif_content .= replace_macros($tpl_item_friends,array(
447 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
448 '$item_image' => $it['author-avatar'],
449 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
450 '$item_when' => relative_date($it['created'])
455 $notif_content .= replace_macros($tpl_item_comments,array(
456 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
457 '$item_image' => $it['author-avatar'],
458 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
459 '$item_when' => relative_date($it['created'])
465 $notif_content = t('No more home notifications.');
468 $o .= replace_macros($notif_tpl,array(
469 '$notif_header' => t('Notifications'),
471 '$notif_content' => $notif_content,