2 require_once("include/datetime.php");
3 require_once('include/bbcode.php');
6 function ping_init(&$a) {
8 header("Content-type: text/xml");
10 echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
13 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
17 // Different login session than the page that is calling us.
19 if(intval($_GET['uid']) && intval($_GET['uid']) != local_user()) {
20 echo '<invalid>1</invalid></result>';
24 $firehose = intval(get_pconfig(local_user(),'system','notify_full'));
26 $z = ping_get_notifications(local_user());
27 $sysnotify = 0; // we will update this in a moment
39 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,
40 `item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`,
41 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
42 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
43 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
44 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `pitem`.`parent` != 0
45 ORDER BY `item`.`created` DESC",
51 $arr = array('items' => $r);
52 call_hooks('network_ping', $arr);
63 $obj = parse_xml_string($xmlhead.$it['object']);
64 $it['tname'] = $obj->content;
70 case ACTIVITY_DISLIKE:
74 $obj = parse_xml_string($xmlhead.$it['object']);
75 $it['fname'] = $obj->title;
79 if ($it['parent']!=$it['id']) {
89 $intros1 = q("SELECT `intro`.`id`, `intro`.`datetime`,
90 `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo`
91 FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
92 WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0",
95 $intros2 = q("SELECT `intro`.`id`, `intro`.`datetime`,
96 `contact`.`name`, `contact`.`url`, `contact`.`photo`
97 FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
98 WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0",
102 $intro = count($intros1) + count($intros2);
103 $intros = $intros1+$intros2;
107 $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
108 $mails = q("SELECT * FROM `mail`
109 WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
110 intval(local_user()),
113 $mail = count($mails);
115 if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()){
116 $regs = q("SELECT `contact`.`name`, `contact`.`url`, `contact`.`micro`, `register`.`created`, COUNT(*) as `total` FROM `contact` RIGHT JOIN `register` ON `register`.`uid`=`contact`.`uid` WHERE `contact`.`self`=1");
118 $register = $regs[0]['total'];
124 $all_events_today = 0;
128 $birthdays_today = 0;
131 $ev = q("SELECT count(`event`.`id`) as total, type, start, adjust FROM `event`
132 WHERE `event`.`uid` = %d AND `start` < '%s' AND `finish` > '%s' and `ignore` = 0
133 ORDER BY `start` ASC ",
134 intval(local_user()),
135 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
136 dbesc(datetime_convert('UTC','UTC','now'))
139 if($ev && count($ev)) {
140 $all_events = intval($ev[0]['total']);
143 $str_now = datetime_convert('UTC',$a->timezone,'now','Y-m-d');
146 if($x['type'] === 'birthday') {
153 if(datetime_convert('UTC',((intval($x['adjust'])) ? $a->timezone : 'UTC'), $x['start'],'Y-m-d') === $str_now) {
154 $all_events_today ++;
166 function xmlize($href, $name, $url, $photo, $date, $seen, $message){
167 require_once("mod/proxy.php");
168 $photo = proxy_url($photo);
170 // Are the nofications calles from the regular process or via the friendica app?
171 $regularnotifications = (intval($_GET['uid']) AND intval($_GET['_']));
175 if ($a->is_friendica_app() OR !$regularnotifications)
176 $message = str_replace("{0}", $name, $message);
179 $data = array('href' => &$href, 'name' => &$name, 'url'=>&$url, 'photo'=>&$photo, 'date'=>&$date, 'seen'=>&$seen, 'messsage'=>&$message);
180 call_hooks('ping_xmlize', $data);
181 $notsxml = '<note href="%s" name="%s" url="%s" photo="%s" date="%s" seen="%s" >%s</note>';
182 return sprintf ( $notsxml,
183 xmlify($href), xmlify($name), xmlify($url), xmlify($photo), xmlify($date), xmlify($seen), xmlify($message)
187 echo "<intro>$intro</intro>
190 <home>$home</home>\r\n";
191 if ($register!=0) echo "<register>$register</register>";
193 echo "<all-events>$all_events</all-events>
194 <all-events-today>$all_events_today</all-events-today>
195 <events>$events</events>
196 <events-today>$events_today</events-today>
197 <birthdays>$birthdays</birthdays>
198 <birthdays-today>$birthdays_today</birthdays-today>\r\n";
200 $tot = $mail+$intro+$register+count($comments)+count($likes)+count($dislikes)+count($friends)+count($posts)+count($tags);
203 echo ' <notif count="'.$tot.'">';
206 if(count($z) && (! $sysnotify)) {
213 echo ' <notif count="'. ($sysnotify + $intro + $mail + $register) .'">';
216 foreach ($intros as $i) {
217 echo xmlize($a->get_baseurl().'/notifications/intros/'.$i['id'], $i['name'], $i['url'], $i['photo'], relative_date($i['datetime']), 'notify-unseen', "→ ".t("{0} wants to be your friend"));
221 foreach ($mails as $i) {
222 echo xmlize($a->get_baseurl().'/message/'.$i['id'], $i['from-name'], $i['from-url'], $i['from-photo'], relative_date($i['created']), 'notify-unseen',"→ ".t("{0} sent you a message"));
226 foreach ($regs as $i) {
227 echo xmlize($a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), 'notify-unseen', "→ ".t("{0} requested registration"));
233 echo xmlize($a->get_baseurl() . '/notify/view/' . $zz['id'], $zz['name'],$zz['url'],$zz['photo'],relative_date($zz['date']), ($zz['seen'] ? 'notify-seen' : 'notify-unseen'), ($zz['seen'] ? '' : '→ ') .strip_tags(bbcode($zz['msg'])));
240 foreach ($intros as $i) {
241 echo xmlize( $a->get_baseurl().'/notifications/intros/'.$i['id'], $i['name'], $i['url'], $i['photo'], relative_date($i['datetime']), 'notify-unseen',t("{0} wants to be your friend") );
245 foreach ($mails as $i) {
246 echo xmlize( $a->get_baseurl().'/message/'.$i['id'], $i['from-name'], $i['from-url'], $i['from-photo'], relative_date($i['created']), 'notify-unseen',t("{0} sent you a message") );
250 foreach ($regs as $i) {
251 echo xmlize( $a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), 'notify-unseen',t("{0} requested registration") );
255 if (count($comments)){
256 foreach ($comments as $i) {
257 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), 'notify-unseen',sprintf( t("{0} commented %s's post"), $i['pname'] ) );
261 foreach ($likes as $i) {
262 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), 'notify-unseen',sprintf( t("{0} liked %s's post"), $i['pname'] ) );
265 if (count($dislikes)){
266 foreach ($dislikes as $i) {
267 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), 'notify-unseen',sprintf( t("{0} disliked %s's post"), $i['pname'] ) );
270 if (count($friends)){
271 foreach ($friends as $i) {
272 echo xmlize($a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'],$i['author-name'],$i['author-link'], $i['author-avatar'], relative_date($i['created']), 'notify-unseen',sprintf( t("{0} is now friends with %s"), $i['fname'] ) );
276 foreach ($posts as $i) {
277 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), 'notify-unseen',sprintf( t("{0} posted") ) );
281 foreach ($tags as $i) {
282 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), 'notify-unseen',sprintf( t("{0} tagged %s's post with #%s"), $i['pname'], $i['tname'] ) );
287 foreach ($cit as $i) {
288 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), 'notify-unseen',t("{0} mentioned you in a post") );
297 if(x($_SESSION,'sysmsg')){
298 foreach ($_SESSION['sysmsg'] as $m){
299 echo "<notice>".xmlify($m)."</notice>";
301 unset($_SESSION['sysmsg']);
303 if(x($_SESSION,'sysmsg_info')){
304 foreach ($_SESSION['sysmsg_info'] as $m){
305 echo "<info>".xmlify($m)."</info>";
307 unset($_SESSION['sysmsg_info']);
317 function ping_get_notifications($uid) {
329 $r = q("SELECT `notify`.*, `item`.`visible`, `item`.`spam`, `item`.`deleted`
330 FROM `notify` LEFT JOIN `item` ON `item`.`id` = `notify`.`iid`
331 WHERE `notify`.`uid` = %d AND `notify`.`msg` != ''
332 AND NOT (`notify`.`type` IN (%d, %d))
333 AND $seensql `notify`.`seen` ORDER BY `notify`.`date` $order LIMIT %d, 50",
335 intval(NOTIFY_INTRO),
340 if (!$r AND !$seen) {
350 foreach ($r AS $notification) {
351 if (is_null($notification["visible"]))
352 $notification["visible"] = true;
354 if (is_null($notification["spam"]))
355 $notification["spam"] = 0;
357 if (is_null($notification["deleted"]))
358 $notification["deleted"] = 0;
360 $notification["msg"] = strip_tags(bbcode($notification["msg"]));
361 $notification["name"] = strip_tags(bbcode($notification["name"]));
363 // Replace the name with {0} but ensure to make that only once
364 // The {0} is used later and prints the name in bold.
366 $pos = strpos($notification["msg"],$notification['name']);
368 $notification["msg"] = substr_replace($notification["msg"],"{0}",$pos,strlen($notification["name"]));
370 if ($notification["visible"] AND !$notification["spam"] AND
371 !$notification["deleted"] AND !is_array($result[$notification["parent"]]))
372 $result[$notification["parent"]] = $notification;
375 } while ((count($result) < 50) AND !$quit);