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' : ''),
77 'url' => $a->get_baseurl() . '/notifications/home',
78 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''),
81 'label' => t('Introductions'),
82 'url' => $a->get_baseurl() . '/notifications/intros',
83 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''),
86 'label' => t('Messages'),
87 'url' => $a->get_baseurl() . '/message',
91 $tpl = get_markup_template('common_tabs.tpl');
92 $tab_content = replace_macros($tpl, array('$tabs'=>$tabs));
97 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
98 nav_set_selected('introductions');
99 if(($a->argc > 2) && ($a->argv[2] == 'all'))
102 $sql_extra = " AND `ignore` = 0 ";
104 $notif_tpl = get_markup_template('notifications.tpl');
106 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
107 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
109 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
110 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
111 intval($_SESSION['uid'])
113 if($r && count($r)) {
114 $a->set_pager_total($r[0]['total']);
115 $a->set_pager_itemspage(20);
118 $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`
119 FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
120 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
121 intval($_SESSION['uid']));
123 if(($r !== false) && (count($r))) {
125 $sugg = get_markup_template('suggestions.tpl');
126 $tpl = get_markup_template("intros.tpl");
131 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
132 $notif_content .= replace_macros($sugg,array(
133 '$str_notifytype' => t('Notification type: '),
134 '$notify_type' => t('Friend Suggestion'),
135 '$intro_id' => $rr['intro_id'],
136 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
137 '$contact_id' => $rr['contact-id'],
138 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/default-profile.jpg"),
139 '$fullname' => $rr['fname'],
140 '$url' => $rr['furl'],
141 '$knowyou' => $knowyou,
142 '$approve' => t('Approve'),
143 '$note' => $rr['note'],
144 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
145 '$ignore' => t('Ignore'),
146 '$discard' => t('Discard')
153 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
154 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
155 $dfrn_tpl = get_markup_template('netfriend.tpl');
160 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
161 if($rr['network'] === NETWORK_DFRN)
162 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
165 $dfrn_text = replace_macros($dfrn_tpl,array(
166 '$intro_id' => $rr['intro_id'],
167 '$friend_selected' => $friend_selected,
168 '$fan_selected' => $fan_selected,
169 '$approve_as' => t('Approve as: '),
170 '$as_friend' => t('Friend'),
171 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
175 $notif_content .= replace_macros($tpl,array(
176 '$str_notifytype' => t('Notification type: '),
177 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
178 '$dfrn_text' => $dfrn_text,
179 '$dfrn_id' => $rr['issued-id'],
180 '$uid' => $_SESSION['uid'],
181 '$intro_id' => $rr['intro_id'],
182 '$contact_id' => $rr['contact-id'],
183 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
184 '$fullname' => $rr['name'],
185 '$url' => $rr['url'],
186 '$knowyou' => $knowyou,
187 '$approve' => t('Approve'),
188 '$note' => $rr['note'],
189 '$ignore' => t('Ignore'),
190 '$discard' => t('Discard')
196 info( t('No notifications.') . EOL);
198 $o .= replace_macros($notif_tpl,array(
199 '$notif_header' => t('Notifications'),
200 '$tabs' => $tab_content,
201 '$notif_content' => $notif_content,
202 '$activetab' => 'intros'
208 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
210 $notif_tpl = get_markup_template('notifications.tpl');
212 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
213 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
214 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
215 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
216 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
217 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
221 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
222 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
223 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
224 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
225 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
231 foreach ($r as $it) {
234 $notif_content .= replace_macros($tpl_item_likes,array(
235 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
236 '$item_image' => $it['author-avatar'],
237 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
238 '$item_when' => relative_date($it['created'])
242 case ACTIVITY_DISLIKE:
243 $notif_content .= replace_macros($tpl_item_dislikes,array(
244 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
245 '$item_image' => $it['author-avatar'],
246 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
247 '$item_when' => relative_date($it['created'])
251 case ACTIVITY_FRIEND:
253 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
254 $obj = parse_xml_string($xmlhead.$it['object']);
255 $it['fname'] = $obj->title;
257 $notif_content .= replace_macros($tpl_item_friends,array(
258 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
259 '$item_image' => $it['author-avatar'],
260 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
261 '$item_when' => relative_date($it['created'])
266 $item_text = (($it['id'] == $it['parent'])
267 ? sprintf( t("%s created a new post"), $it['author-name'])
268 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
269 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
271 $notif_content .= replace_macros($tpl,array(
272 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
273 '$item_image' => $it['author-avatar'],
274 '$item_text' => $item_text,
275 '$item_when' => relative_date($it['created'])
282 $notif_content = t('Nothing new!');
285 $o .= replace_macros($notif_tpl,array(
286 '$notif_header' => t('Notifications'),
287 '$tabs' => $tab_content,
288 '$notif_content' => $notif_content,
289 '$activetab' => 'network'
292 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
294 $notif_tpl = get_markup_template('notifications.tpl');
296 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
297 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
298 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
299 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
300 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
301 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
305 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
306 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
307 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
308 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
314 foreach ($r as $it) {
317 $notif_content .= replace_macros($tpl_item_likes,array(
318 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
319 '$item_image' => $it['author-avatar'],
320 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
321 '$item_when' => relative_date($it['created'])
325 case ACTIVITY_DISLIKE:
326 $notif_content .= replace_macros($tpl_item_dislikes,array(
327 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
328 '$item_image' => $it['author-avatar'],
329 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
330 '$item_when' => relative_date($it['created'])
334 case ACTIVITY_FRIEND:
336 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
337 $obj = parse_xml_string($xmlhead.$it['object']);
338 $it['fname'] = $obj->title;
340 $notif_content .= replace_macros($tpl_item_friends,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 is now friends with %s"), $it['author-name'], $it['fname']),
344 '$item_when' => relative_date($it['created'])
349 $notif_content .= replace_macros($tpl_item_comments,array(
350 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
351 '$item_image' => $it['author-avatar'],
352 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
353 '$item_when' => relative_date($it['created'])
359 $notif_content = t('Nothing new!');
362 $o .= replace_macros($notif_tpl,array(
363 '$notif_header' => t('Notifications'),
364 '$tabs' => $tab_content,
365 '$notif_content' => $notif_content,
366 '$activetab' => 'home'