2 include_once("include/NotificationsManager.php");
3 include_once("include/bbcode.php");
4 include_once("include/contact_selectors.php");
5 include_once("include/Scrape.php");
7 function notifications_post(&$a) {
13 $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
15 if($request_id === "all")
20 $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
26 $intro_id = $r[0]['id'];
27 $contact_id = $r[0]['contact-id'];
30 notice( t('Invalid request identifier.') . EOL);
34 // If it is a friend suggestion, the contact is not a new friend but an existing friend
35 // that should not be deleted.
39 if($_POST['submit'] == t('Discard')) {
40 $r = q("DELETE FROM `intro` WHERE `id` = %d",
45 // The check for blocked and pending is in case the friendship was already approved
46 // and we just want to get rid of the now pointless notification
48 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1",
53 goaway('notifications/intros');
55 if($_POST['submit'] == t('Ignore')) {
56 $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
58 goaway('notifications/intros');
63 function notifications_content(&$a) {
66 notice( t('Permission denied.') . EOL);
70 $page = (x($_REQUEST,'page') ? $_REQUEST['page'] : 1);
71 $show = (x($_REQUEST,'show') ? $_REQUEST['show'] : 0);
73 nav_set_selected('notifications');
75 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
77 $nm = new NotificationsManager();
80 // get the nav tabs for the notification pages
81 $tabs = $nm->getTabs();
82 $notif_content = array();
84 $startrec = ($page * $perpage) - $perpage;
86 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
87 nav_set_selected('introductions');
89 if(($a->argc > 2) && ($a->argv[2] == 'all'))
92 $sql_extra = " AND `ignore` = 0 ";
94 $notif_header = t('Notifications');
95 $notif_tpl = get_markup_template('notifications.tpl');
98 $notif_show_lnk = array(
99 'href' => ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ),
100 'text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')),
101 'id' => "notifications-show-hide-link",
104 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
105 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
106 intval($_SESSION['uid'])
108 if(dbm::is_result($r)) {
109 $a->set_pager_total($r[0]['total']);
110 $a->set_pager_itemspage($perpage);
113 /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
115 $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`,
116 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
117 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
118 `gcontact`.`network` AS `gnetwork`
120 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
121 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
122 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(dbm::is_result($r)) {
128 $sugg = get_markup_template('suggestions.tpl');
129 $tpl = get_markup_template("intros.tpl");
135 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
137 $notif_content[] = replace_macros($sugg, array(
138 '$str_notifytype' => t('Notification type: '),
139 '$notify_type' => t('Friend Suggestion'),
140 '$intro_id' => $rr['intro_id'],
141 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
142 '$contact_id' => $rr['contact-id'],
143 '$photo' => ((x($rr,'fphoto')) ? proxy_url($rr['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
144 '$fullname' => $rr['fname'],
145 '$url' => zrl($rr['furl']),
146 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
147 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
149 '$knowyou' => $knowyou,
150 '$approve' => t('Approve'),
151 '$note' => $rr['note'],
152 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
153 '$ignore' => t('Ignore'),
154 '$discard' => t('Discard'),
161 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
162 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
163 $dfrn_tpl = get_markup_template('netfriend.tpl');
168 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
169 if($rr['network'] === NETWORK_DFRN) {
170 $lbl_knowyou = t('Claims to be known to you: ');
171 $knowyou = (($rr['knowyou']) ? t('yes') : t('no'));
172 $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Fan/Admirer" means that you allow to read but you do not want to read theirs. Approve as: ');
175 $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Sharer" means that you allow to read but you do not want to read theirs. Approve as: ');
178 $dfrn_text = replace_macros($dfrn_tpl,array(
179 '$intro_id' => $rr['intro_id'],
180 '$friend_selected' => $friend_selected,
181 '$fan_selected' => $fan_selected,
182 '$approve_as' => $helptext,
183 '$as_friend' => t('Friend'),
184 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
188 $header = $rr["name"];
190 $ret = probe_url($rr["url"]);
192 if ($rr['gnetwork'] == "")
193 $rr['gnetwork'] = $ret["network"];
195 if ($ret["addr"] != "")
196 $header .= " <".$ret["addr"].">";
198 $header .= " (".network_to_name($rr['gnetwork'], $rr['url']).")";
200 // Don't show these data until you are connected. Diaspora is doing the same.
201 if($rr['gnetwork'] === NETWORK_DIASPORA) {
202 $rr['glocation'] = "";
207 $notif_content[] = replace_macros($tpl, array(
208 '$header' => htmlentities($header),
209 '$str_notifytype' => t('Notification type: '),
210 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
211 '$dfrn_text' => $dfrn_text,
212 '$dfrn_id' => $rr['issued-id'],
213 '$uid' => $_SESSION['uid'],
214 '$intro_id' => $rr['intro_id'],
215 '$contact_id' => $rr['contact-id'],
216 '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
217 '$fullname' => $rr['name'],
218 '$location' => bbcode($rr['glocation'], false, false),
219 '$location_label' => t('Location:'),
220 '$about' => bbcode($rr['gabout'], false, false),
221 '$about_label' => t('About:'),
222 '$keywords' => $rr['gkeywords'],
223 '$keywords_label' => t('Tags:'),
224 '$gender' => $rr['ggender'],
225 '$gender_label' => t('Gender:'),
226 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
227 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
228 '$url' => $rr['url'],
229 '$zrl' => zrl($rr['url']),
230 '$url_label' => t('Profile URL'),
231 '$addr' => $rr['addr'],
232 '$lbl_knowyou' => $lbl_knowyou,
233 '$lbl_network' => t('Network:'),
234 '$network' => network_to_name($rr['gnetwork'], $rr['url']),
235 '$knowyou' => $knowyou,
236 '$approve' => t('Approve'),
237 '$note' => $rr['note'],
238 '$ignore' => t('Ignore'),
239 '$discard' => t('Discard'),
245 info( t('No introductions.') . EOL);
247 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
249 $notif_header = t('Network Notifications');
250 $notif_tpl = get_markup_template('notifications.tpl');
252 $notifs = $nm->networkNotifs($show, $startrec, $perpage);
254 $notif_show_lnk = array(
255 'href' => ($show ? 'notifications/network' : 'notifications/network?show=all' ),
256 'text' => ($show ? t('Show unread') : t('Show all')),
259 if(!dbm::is_result($notifs)) {
261 $notif_show_lnk = array();
263 $notif_nocontent = t('No more network notifications.');
266 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
268 $notif_header = t('System Notifications');
269 $notif_tpl = get_markup_template('notifications.tpl');
271 $notifs = $nm->systemNotifs($show, $startrec, $perpage);
273 $notif_show_lnk = array(
274 'href' => ($show ? 'notifications/system' : 'notifications/system?show=all' ),
275 'text' => ($show ? t('Show unread') : t('Show all')),
278 if(!dbm::is_result($notifs)) {
280 $notif_show_lnk = array();
282 $notif_nocontent = t('No more system notifications.');
285 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
287 $notif_header = t('Personal Notifications');
288 $notif_tpl = get_markup_template('notifications.tpl');
290 $notifs = $nm->personalNotifs($show, $startrec, $perpage);
292 $notif_show_lnk = array(
293 'href' => ($show ? 'notifications/personal' : 'notifications/personal?show=all' ),
294 'text' => ($show ? t('Show unread') : t('Show all')),
297 if(!dbm::is_result($notifs)) {
299 $notif_show_lnk = array();
301 $notif_nocontent = t('No more personal notifications.');
304 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
306 $notif_header = t('Home Notifications');
307 $notif_tpl = get_markup_template('notifications.tpl');
309 $notifs = $nm->homeNotifs($show, $startrec, $perpage);
311 $notif_show_lnk = array(
312 'href' => ($show ? 'notifications/home' : 'notifications/home?show=all' ),
313 'text' => ($show ? t('Show unread') : t('Show all')),
316 if(!dbm::is_result($notifs)) {
318 $notif_show_lnk = array();
320 $notif_nocontent = t('No more home notifications.');
325 if(count($notifs['notifications']) > 0 ) {
327 $a->set_pager_total($notifs['total']);
328 $a->set_pager_itemspage($perpage);
330 // add additional informations (needed for json output)
331 $notifs['items_page'] = $a->pager['itemspage'];
332 $notifs['page'] = $a->pager['page'];
334 // The template files we need in different cases for formatting the content
335 $tpl_item_like = 'notifications_likes_item.tpl';
336 $tpl_item_dislike = 'notifications_dislikes_item.tpl';
337 $tpl_item_attend = 'notifications_attend_item.tpl';
338 $tpl_item_attendno = 'notifications_attend_item.tpl';
339 $tpl_item_attendmaybe = 'notifications_attend_item.tpl';
340 $tpl_item_friend = 'notifications_friends_item.tpl';
341 $tpl_item_comment = 'notifications_comments_item.tpl';
342 $tpl_item_post = 'notifications_posts_item.tpl';
343 $tpl_item_notify = 'notify.tpl';
345 foreach ($notifs['notifications'] as $it) {
346 $tplname = 'tpl_item_'.$it['label'];
347 $templ = get_markup_template($$tplname);
349 $notif_content[] = replace_macros($templ,array(
350 '$item_label' => $it['label'],
351 '$item_link' => $it['link'],
352 '$item_image' => $it['image'],
353 '$item_text' => $it['text'],
354 '$item_when' => $it['when'],
355 '$item_seen' => $it['seen'],
361 $o .= replace_macros($notif_tpl, array(
362 '$notif_header' => $notif_header,
364 '$notif_content' => $notif_content,
365 '$notif_nocontent' => $notif_nocontent,
366 '$notif_show_lnk' => $notif_show_lnk,
367 '$notif_paginate' => paginate($a)