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')) {
209 $notif_tpl = get_markup_template('notifications.tpl');
211 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
212 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
213 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
214 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
215 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
216 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
220 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
221 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
222 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
223 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
224 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
230 foreach ($r as $it) {
233 $notif_content .= replace_macros($tpl_item_likes,array(
234 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
235 '$item_image' => $it['author-avatar'],
236 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
237 '$item_when' => relative_date($it['created'])
241 case ACTIVITY_DISLIKE:
242 $notif_content .= replace_macros($tpl_item_dislikes,array(
243 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
244 '$item_image' => $it['author-avatar'],
245 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
246 '$item_when' => relative_date($it['created'])
250 case ACTIVITY_FRIEND:
252 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
253 $obj = parse_xml_string($xmlhead.$it['object']);
254 $it['fname'] = $obj->title;
256 $notif_content .= replace_macros($tpl_item_friends,array(
257 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
258 '$item_image' => $it['author-avatar'],
259 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
260 '$item_when' => relative_date($it['created'])
265 $item_text = (($it['id'] == $it['parent'])
266 ? sprintf( t("%s created a new post"), $it['author-name'])
267 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
268 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
270 $notif_content .= replace_macros($tpl,array(
271 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
272 '$item_image' => $it['author-avatar'],
273 '$item_text' => $item_text,
274 '$item_when' => relative_date($it['created'])
281 $notif_content = t('Nothing new!');
284 $o .= replace_macros($notif_tpl,array(
285 '$notif_header' => t('Notifications'),
286 '$tabs' => $tab_content,
287 '$notif_content' => $notif_content,
288 '$activetab' => 'network'
291 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
293 $notif_tpl = get_markup_template('notifications.tpl');
295 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
296 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
297 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
298 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
299 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
300 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
304 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
305 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
306 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
307 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
313 foreach ($r as $it) {
316 $notif_content .= replace_macros($tpl_item_likes,array(
317 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
318 '$item_image' => $it['author-avatar'],
319 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
320 '$item_when' => relative_date($it['created'])
324 case ACTIVITY_DISLIKE:
325 $notif_content .= replace_macros($tpl_item_dislikes,array(
326 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
327 '$item_image' => $it['author-avatar'],
328 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
329 '$item_when' => relative_date($it['created'])
333 case ACTIVITY_FRIEND:
335 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
336 $obj = parse_xml_string($xmlhead.$it['object']);
337 $it['fname'] = $obj->title;
339 $notif_content .= replace_macros($tpl_item_friends,array(
340 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
341 '$item_image' => $it['author-avatar'],
342 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
343 '$item_when' => relative_date($it['created'])
348 $notif_content .= replace_macros($tpl_item_comments,array(
349 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
350 '$item_image' => $it['author-avatar'],
351 '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']),
352 '$item_when' => relative_date($it['created'])
358 $notif_content = t('Nothing new!');
361 $o .= replace_macros($notif_tpl,array(
362 '$notif_header' => t('Notifications'),
363 '$tabs' => $tab_content,
364 '$notif_content' => $notif_content,
365 '$activetab' => 'home'