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 '$knowyou' => $knowyou,
146 '$approve' => t('Approve'),
147 '$note' => $rr['note'],
148 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
149 '$ignore' => t('Ignore'),
150 '$discard' => t('Discard')
157 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
158 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
159 $dfrn_tpl = get_markup_template('netfriend.tpl');
164 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
165 if($rr['network'] === NETWORK_DFRN)
166 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
169 $dfrn_text = replace_macros($dfrn_tpl,array(
170 '$intro_id' => $rr['intro_id'],
171 '$friend_selected' => $friend_selected,
172 '$fan_selected' => $fan_selected,
173 '$approve_as' => t('Approve as: '),
174 '$as_friend' => t('Friend'),
175 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
179 $notif_content .= replace_macros($tpl,array(
180 '$str_notifytype' => t('Notification type: '),
181 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
182 '$dfrn_text' => $dfrn_text,
183 '$dfrn_id' => $rr['issued-id'],
184 '$uid' => $_SESSION['uid'],
185 '$intro_id' => $rr['intro_id'],
186 '$contact_id' => $rr['contact-id'],
187 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
188 '$fullname' => $rr['name'],
189 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
190 '$url' => $rr['url'],
191 '$knowyou' => $knowyou,
192 '$approve' => t('Approve'),
193 '$note' => $rr['note'],
194 '$ignore' => t('Ignore'),
195 '$discard' => t('Discard')
201 info( t('No introductions.') . EOL);
203 $o .= replace_macros($notif_tpl,array(
204 '$notif_header' => t('Notifications'),
206 '$notif_content' => $notif_content,
212 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
214 $notif_tpl = get_markup_template('notifications.tpl');
216 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
217 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
218 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
219 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
220 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
221 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
225 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
226 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
227 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
228 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
229 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
235 foreach ($r as $it) {
238 $notif_content .= replace_macros($tpl_item_likes,array(
239 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
240 '$item_image' => $it['author-avatar'],
241 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
242 '$item_when' => relative_date($it['created'])
246 case ACTIVITY_DISLIKE:
247 $notif_content .= replace_macros($tpl_item_dislikes,array(
248 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
249 '$item_image' => $it['author-avatar'],
250 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
251 '$item_when' => relative_date($it['created'])
255 case ACTIVITY_FRIEND:
257 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
258 $obj = parse_xml_string($xmlhead.$it['object']);
259 $it['fname'] = $obj->title;
261 $notif_content .= replace_macros($tpl_item_friends,array(
262 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
263 '$item_image' => $it['author-avatar'],
264 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
265 '$item_when' => relative_date($it['created'])
270 $item_text = (($it['id'] == $it['parent'])
271 ? sprintf( t("%s created a new post"), $it['author-name'])
272 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
273 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
275 $notif_content .= replace_macros($tpl,array(
276 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
277 '$item_image' => $it['author-avatar'],
278 '$item_text' => $item_text,
279 '$item_when' => relative_date($it['created'])
286 $notif_content = t('No more network notifications.');
289 $o .= replace_macros($notif_tpl,array(
290 '$notif_header' => t('Notifications'),
292 '$notif_content' => $notif_content,
295 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
297 $notif_tpl = get_markup_template('notifications.tpl');
299 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
300 $myurl = substr($myurl,strpos($myurl,'://')+3);
301 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
302 $diasp_url = str_replace('/profile/','/u/',$myurl);
303 $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
305 dbesc($myurl . '\\]'),
306 dbesc($diasp_url . '\\]')
310 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
311 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
312 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
313 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
314 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1
316 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
320 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
321 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
322 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
323 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
324 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
330 foreach ($r as $it) {
333 $notif_content .= replace_macros($tpl_item_likes,array(
334 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
335 '$item_image' => $it['author-avatar'],
336 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
337 '$item_when' => relative_date($it['created'])
341 case ACTIVITY_DISLIKE:
342 $notif_content .= replace_macros($tpl_item_dislikes,array(
343 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
344 '$item_image' => $it['author-avatar'],
345 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
346 '$item_when' => relative_date($it['created'])
350 case ACTIVITY_FRIEND:
352 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
353 $obj = parse_xml_string($xmlhead.$it['object']);
354 $it['fname'] = $obj->title;
356 $notif_content .= replace_macros($tpl_item_friends,array(
357 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
358 '$item_image' => $it['author-avatar'],
359 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
360 '$item_when' => relative_date($it['created'])
365 $item_text = (($it['id'] == $it['parent'])
366 ? sprintf( t("%s created a new post"), $it['author-name'])
367 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
368 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
370 $notif_content .= replace_macros($tpl,array(
371 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
372 '$item_image' => $it['author-avatar'],
373 '$item_text' => $item_text,
374 '$item_when' => relative_date($it['created'])
381 $notif_content = t('No more personal notifications.');
384 $o .= replace_macros($notif_tpl,array(
385 '$notif_header' => t('Notifications'),
387 '$notif_content' => $notif_content,
395 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
397 $notif_tpl = get_markup_template('notifications.tpl');
399 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
400 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
401 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
402 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
403 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
404 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
408 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
409 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
410 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
411 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
417 foreach ($r as $it) {
420 $notif_content .= replace_macros($tpl_item_likes,array(
421 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
422 '$item_image' => $it['author-avatar'],
423 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
424 '$item_when' => relative_date($it['created'])
428 case ACTIVITY_DISLIKE:
429 $notif_content .= replace_macros($tpl_item_dislikes,array(
430 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
431 '$item_image' => $it['author-avatar'],
432 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
433 '$item_when' => relative_date($it['created'])
437 case ACTIVITY_FRIEND:
439 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
440 $obj = parse_xml_string($xmlhead.$it['object']);
441 $it['fname'] = $obj->title;
443 $notif_content .= replace_macros($tpl_item_friends,array(
444 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
445 '$item_image' => $it['author-avatar'],
446 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
447 '$item_when' => relative_date($it['created'])
452 $notif_content .= replace_macros($tpl_item_comments,array(
453 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
454 '$item_image' => $it['author-avatar'],
455 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
456 '$item_when' => relative_date($it['created'])
462 $notif_content = t('No more home notifications.');
465 $o .= replace_macros($notif_tpl,array(
466 '$notif_header' => t('Notifications'),
468 '$notif_content' => $notif_content,