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 $show = (x($_REQUEST,'show') ? $_REQUEST['show'] : 0);
71 nav_set_selected('notifications');
73 $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
75 $nm = new NotificationsManager();
78 // get the nav tabs for the notification pages
79 $tabs = $nm->getTabs();
80 $notif_content = array();
82 if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
83 nav_set_selected('introductions');
85 if(($a->argc > 2) && ($a->argv[2] == 'all'))
88 $sql_extra = " AND `ignore` = 0 ";
90 $notif_header = t('Notifications');
91 $notif_tpl = get_markup_template('notifications.tpl');
93 // $notif_show_lnk .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
94 // . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
96 $notif_show_lnk = array(
97 'href' => ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ),
98 'text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')),
99 'id' => "notifications-show-hide-link",
102 $r = q("SELECT COUNT(*) AS `total` FROM `intro`
103 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
104 intval($_SESSION['uid'])
106 if(dbm::is_result($r)) {
107 $a->set_pager_total($r[0]['total']);
108 $a->set_pager_itemspage(20);
111 /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
113 $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`,
114 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
115 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
116 `gcontact`.`network` AS `gnetwork`
118 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
119 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
120 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
121 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
122 intval($_SESSION['uid']));
124 if(dbm::is_result($r)) {
126 $sugg = get_markup_template('suggestions.tpl');
127 $tpl = get_markup_template("intros.tpl");
133 $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')) ? proxy_url($rr['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
142 '$fullname' => $rr['fname'],
143 '$url' => zrl($rr['furl']),
144 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
145 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
147 '$knowyou' => $knowyou,
148 '$approve' => t('Approve'),
149 '$note' => $rr['note'],
150 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
151 '$ignore' => t('Ignore'),
152 '$discard' => t('Discard'),
159 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
160 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
161 $dfrn_tpl = get_markup_template('netfriend.tpl');
166 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
167 if($rr['network'] === NETWORK_DFRN) {
168 $lbl_knowyou = t('Claims to be known to you: ');
169 $knowyou = (($rr['knowyou']) ? t('yes') : t('no'));
170 $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: ');
173 $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: ');
176 $dfrn_text = replace_macros($dfrn_tpl,array(
177 '$intro_id' => $rr['intro_id'],
178 '$friend_selected' => $friend_selected,
179 '$fan_selected' => $fan_selected,
180 '$approve_as' => $helptext,
181 '$as_friend' => t('Friend'),
182 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
186 $header = $rr["name"];
188 $ret = probe_url($rr["url"]);
190 if ($rr['gnetwork'] == "")
191 $rr['gnetwork'] = $ret["network"];
193 if ($ret["addr"] != "")
194 $header .= " <".$ret["addr"].">";
196 $header .= " (".network_to_name($rr['gnetwork'], $rr['url']).")";
198 // Don't show these data until you are connected. Diaspora is doing the same.
199 if($rr['gnetwork'] === NETWORK_DIASPORA) {
200 $rr['glocation'] = "";
205 $notif_content[] = replace_macros($tpl, array(
206 '$header' => htmlentities($header),
207 '$str_notifytype' => t('Notification type: '),
208 '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
209 '$dfrn_text' => $dfrn_text,
210 '$dfrn_id' => $rr['issued-id'],
211 '$uid' => $_SESSION['uid'],
212 '$intro_id' => $rr['intro_id'],
213 '$contact_id' => $rr['contact-id'],
214 '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
215 '$fullname' => $rr['name'],
216 '$location' => bbcode($rr['glocation'], false, false),
217 '$location_label' => t('Location:'),
218 '$about' => bbcode($rr['gabout'], false, false),
219 '$about_label' => t('About:'),
220 '$keywords' => $rr['gkeywords'],
221 '$keywords_label' => t('Tags:'),
222 '$gender' => $rr['ggender'],
223 '$gender_label' => t('Gender:'),
224 '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''),
225 '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')),
226 '$url' => $rr['url'],
227 '$zrl' => zrl($rr['url']),
228 '$url_label' => t('Profile URL'),
229 '$addr' => $rr['addr'],
230 '$lbl_knowyou' => $lbl_knowyou,
231 '$lbl_network' => t('Network:'),
232 '$network' => network_to_name($rr['gnetwork'], $rr['url']),
233 '$knowyou' => $knowyou,
234 '$approve' => t('Approve'),
235 '$note' => $rr['note'],
236 '$ignore' => t('Ignore'),
237 '$discard' => t('Discard'),
243 info( t('No introductions.') . EOL);
245 } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
247 $notif_header = t('Network Notifications');
248 $notif_tpl = get_markup_template('notifications.tpl');
250 $notifs = $nm->networkNotifs($show);
252 $notif_show_lnk = array(
253 'href' => ($show ? 'notifications/network' : 'notifications/network?show=all' ),
254 'text' => ($show ? t('Show unread') : t('Show all')),
257 if(!dbm::is_result($notifs)) {
259 $notif_show_lnk = array();
261 $notif_nocontent = t('No more network notifications.');
264 } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
266 $notif_header = t('System Notifications');
267 $notif_tpl = get_markup_template('notifications.tpl');
269 $notifs = $nm->systemNotifs($show);
271 $notif_show_lnk = array(
272 'href' => ($show ? 'notifications/system' : 'notifications/system?show=all' ),
273 'text' => ($show ? t('Show unread') : t('Show all')),
276 if(!dbm::is_result($notifs)) {
278 $notif_show_lnk = array();
280 $notif_nocontent = t('No more system notifications.');
283 } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
285 $notif_header = t('Personal Notifications');
286 $notif_tpl = get_markup_template('notifications.tpl');
288 $notifs = $nm->personalNotifs($show);
290 $notif_show_lnk = array(
291 'href' => ($show ? 'notifications/personal' : 'notifications/personal?show=all' ),
292 'text' => ($show ? t('Show unread') : t('Show all')),
295 if(!dbm::is_result($notifs)) {
297 $notif_show_lnk = array();
299 $notif_nocontent = t('No more personal notifications.');
302 } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
304 $notif_header = t('Home Notifications');
305 $notif_tpl = get_markup_template('notifications.tpl');
307 $notifs = $nm->homeNotifs($show);
309 $notif_show_lnk = array(
310 'href' => ($show ? 'notifications/home' : 'notifications/home?show=all' ),
311 'text' => ($show ? t('Show unread') : t('Show all')),
314 if(!dbm::is_result($notifs)) {
316 $notif_show_lnk = array();
318 $notif_nocontent = t('No more home notifications.');
323 if(count($notifs['notifications']) > 0 ) {
324 // The template files we need in different cases for formatting the content
325 $tpl_item_like = 'notifications_likes_item.tpl';
326 $tpl_item_dislike = 'notifications_dislikes_item.tpl';
327 $tpl_item_friend = 'notifications_friends_item.tpl';
328 $tpl_item_comment = 'notifications_comments_item.tpl';
329 $tpl_item_post = 'notifications_posts_item.tpl';
330 $tpl_item_notify = 'notify.tpl';
332 foreach ($notifs['notifications'] as $it) {
333 $tplname = 'tpl_item_'.$it['label'];
334 $templ = get_markup_template($$tplname);
336 $notif_content[] = replace_macros($templ,array(
337 '$item_label' => $it['label'],
338 '$item_link' => $it['link'],
339 '$item_image' => $it['image'],
340 '$item_text' => $it['text'],
341 '$item_when' => $it['when'],
342 '$item_seen' => $it['seen'],
348 $o .= replace_macros($notif_tpl, array(
349 '$notif_header' => $notif_header,
351 '$notif_content' => $notif_content,
352 '$notif_nocontent' => $notif_nocontent,
353 '$notif_show_lnk' => $notif_show_lnk,