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);
68 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
70 if(($a->argc > 2) && ($a->argv[2] == 'all'))
73 $sql_extra = " AND `ignore` = 0 ";
75 $notif_tpl = get_markup_template('notifications.tpl');
77 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
78 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
80 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
81 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
82 intval($_SESSION['uid'])
85 $a->set_pager_total($r[0]['total']);
86 $a->set_pager_itemspage(20);
89 $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`
90 FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
91 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
92 intval($_SESSION['uid']));
94 if(($r !== false) && (count($r))) {
96 $sugg = get_markup_template('suggestions.tpl');
97 $tpl = get_markup_template("intros.tpl");
102 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
103 $notif_content .= replace_macros($sugg,array(
104 '$str_notifytype' => t('Notification type: '),
105 '$notify_type' => t('Friend Suggestion'),
106 '$intro_id' => $rr['intro_id'],
107 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
108 '$contact_id' => $rr['contact-id'],
109 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/default-profile.jpg"),
110 '$fullname' => $rr['fname'],
111 '$url' => $rr['furl'],
112 '$knowyou' => $knowyou,
113 '$approve' => t('Approve'),
114 '$note' => $rr['note'],
115 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
116 '$ignore' => t('Ignore'),
117 '$discard' => t('Discard')
124 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
125 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
126 $dfrn_tpl = get_markup_template('netfriend.tpl');
131 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
132 if($rr['network'] === NETWORK_DFRN)
133 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
136 $dfrn_text = replace_macros($dfrn_tpl,array(
137 '$intro_id' => $rr['intro_id'],
138 '$friend_selected' => $friend_selected,
139 '$fan_selected' => $fan_selected,
140 '$approve_as' => t('Approve as: '),
141 '$as_friend' => t('Friend'),
142 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
146 $notif_content .= replace_macros($tpl,array(
147 '$str_notifytype' => t('Notification type: '),
148 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
149 '$dfrn_text' => $dfrn_text,
150 '$dfrn_id' => $rr['issued-id'],
151 '$uid' => $_SESSION['uid'],
152 '$intro_id' => $rr['intro_id'],
153 '$contact_id' => $rr['contact-id'],
154 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
155 '$fullname' => $rr['name'],
156 '$url' => $rr['url'],
157 '$knowyou' => $knowyou,
158 '$approve' => t('Approve'),
159 '$note' => $rr['note'],
160 '$ignore' => t('Ignore'),
161 '$discard' => t('Discard')
167 info( t('No notifications.') . EOL);
169 $o .= replace_macros($notif_tpl,array(
170 '$notif_content' => $notif_content,
171 '$activetab' => 'intros'
177 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
179 $notif_tpl = get_markup_template('notifications.tpl');
181 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
182 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
183 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
184 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
185 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
186 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
190 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
191 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
192 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
193 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
194 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
200 foreach ($r as $it) {
203 $notif_content .= replace_macros($tpl_item_likes,array(
204 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
205 '$item_image' => $it['author-avatar'],
206 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
207 '$item_when' => relative_date($it['created'])
211 case ACTIVITY_DISLIKE:
212 $notif_content .= replace_macros($tpl_item_dislikes,array(
213 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
214 '$item_image' => $it['author-avatar'],
215 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
216 '$item_when' => relative_date($it['created'])
220 case ACTIVITY_FRIEND:
222 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
223 $obj = parse_xml_string($xmlhead.$it['object']);
224 $it['fname'] = $obj->title;
226 $notif_content .= replace_macros($tpl_item_friends,array(
227 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
228 '$item_image' => $it['author-avatar'],
229 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
230 '$item_when' => relative_date($it['created'])
235 $item_text = (($it['id'] == $it['parent'])
236 ? sprintf( t("%s created a new post"), $it['author-name'])
237 : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']));
238 $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments);
240 $notif_content .= replace_macros($tpl,array(
241 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
242 '$item_image' => $it['author-avatar'],
243 '$item_text' => $item_text,
244 '$item_when' => relative_date($it['created'])
251 $notif_content = 'Nothing new!';
254 $o .= replace_macros($notif_tpl,array(
255 '$notif_content' => $notif_content,
256 '$activetab' => 'network'
259 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
261 $notif_tpl = get_markup_template('notifications.tpl');
263 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,
264 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,
265 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
266 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
267 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
268 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
272 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
273 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
274 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
275 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
281 foreach ($r as $it) {
284 $notif_content .= replace_macros($tpl_item_likes,array(
285 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
286 '$item_image' => $it['author-avatar'],
287 '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
288 '$item_when' => relative_date($it['created'])
292 case ACTIVITY_DISLIKE:
293 $notif_content .= replace_macros($tpl_item_dislikes,array(
294 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
295 '$item_image' => $it['author-avatar'],
296 '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
297 '$item_when' => relative_date($it['created'])
301 case ACTIVITY_FRIEND:
303 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
304 $obj = parse_xml_string($xmlhead.$it['object']);
305 $it['fname'] = $obj->title;
307 $notif_content .= replace_macros($tpl_item_friends,array(
308 '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
309 '$item_image' => $it['author-avatar'],
310 '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
311 '$item_when' => relative_date($it['created'])
316 $notif_content .= replace_macros($tpl_item_comments,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 commented on %s's post"), $it['author-name'], $it['pname']),
320 '$item_when' => relative_date($it['created'])
326 $notif_content = 'Nothing new!';
329 $o .= replace_macros($notif_tpl,array(
330 '$notif_content' => $notif_content,
331 '$activetab' => 'home'