2 require_once("include/datetime.php");
5 function ping_init(&$a) {
7 header("Content-type: text/xml");
9 echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
12 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
16 // Different login session than the page that is calling us.
18 if(intval($_GET['uid']) && intval($_GET['uid']) != local_user()) {
19 echo '<invalid>1</invalid></result>';
23 $firehose = intval(get_pconfig(local_user(),'system','notify_full'));
25 $t = q("select count(*) as total from notify where uid = %d and seen = 0",
28 if($t && intval($t[0]['total']) > 49) {
29 $z = q("select * from notify where uid = %d
30 and seen = 0 order by date desc limit 0, 50",
33 $sysnotify = $t[0]['total'];
36 $z1 = q("select * from notify where uid = %d
37 and seen = 0 order by date desc limit 0, 50",
41 $z2 = q("select * from notify where uid = %d
42 and seen = 1 order by date desc limit 0, %d",
44 intval(50 - intval($t[0]['total']))
46 $z = array_merge($z1,$z2);
47 $sysnotify = 0; // we will update this in a moment
61 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,
62 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`,
63 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`
64 FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`
65 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
66 `item`.`deleted` = 0 AND `item`.`uid` = %d
67 ORDER BY `item`.`created` DESC",
82 $obj = parse_xml_string($xmlhead.$it['object']);
83 $it['tname'] = $obj->content;
89 case ACTIVITY_DISLIKE:
93 $obj = parse_xml_string($xmlhead.$it['object']);
94 $it['fname'] = $obj->title;
98 if ($it['parent']!=$it['id']) {
108 $intros1 = q("SELECT `intro`.`id`, `intro`.`datetime`,
109 `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo`
110 FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
111 WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0",
114 $intros2 = q("SELECT `intro`.`id`, `intro`.`datetime`,
115 `contact`.`name`, `contact`.`url`, `contact`.`photo`
116 FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
117 WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0",
121 $intro = count($intros1) + count($intros2);
122 $intros = $intros1+$intros2;
126 $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
127 $mails = q("SELECT *, COUNT(*) AS `total` FROM `mail`
128 WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
129 intval(local_user()),
133 $mail = $mails[0]['total'];
135 if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()){
136 $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");
138 $register = $regs[0]['total'];
144 function xmlize($href, $name, $url, $photo, $date, $seen, $message){
145 $data = array('href' => &$href, 'name' => &$name, 'url'=>&$url, 'photo'=>&$photo, 'date'=>&$date, 'seen'=>&$seen, 'messsage'=>&$message);
146 call_hooks('ping_xmlize', $data);
147 $notsxml = '<note href="%s" name="%s" url="%s" photo="%s" date="%s" seen="%s" >%s</note>';
148 return sprintf ( $notsxml,
149 xmlify($href), xmlify($name), xmlify($url), xmlify($photo), xmlify($date), xmlify($seen), xmlify($message)
153 echo "<intro>$intro</intro>
157 if ($register!=0) echo "<register>$register</register>";
159 $tot = $mail+$intro+$register+count($comments)+count($likes)+count($dislikes)+count($friends)+count($posts)+count($tags);
161 require_once('include/bbcode.php');
164 echo ' <notif count="'.$tot.'">';
167 if(count($z) && (! $sysnotify)) {
174 echo ' <notif count="'. $sysnotify .'">';
177 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'])));
184 foreach ($intros as $i) {
185 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") );
189 foreach ($mails as $i) {
190 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") );
194 foreach ($regs as $i) {
195 echo xmlize( $a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), 'notify-unseen',t("{0} requested registration") );
199 if (count($comments)){
200 foreach ($comments as $i) {
201 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'] ) );
205 foreach ($likes as $i) {
206 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'] ) );
209 if (count($dislikes)){
210 foreach ($dislikes as $i) {
211 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'] ) );
214 if (count($friends)){
215 foreach ($friends as $i) {
216 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'] ) );
220 foreach ($posts as $i) {
221 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") ) );
225 foreach ($tags as $i) {
226 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'] ) );
231 foreach ($cit as $i) {
232 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") );
241 if(x($_SESSION,'sysmsg')){
242 foreach ($_SESSION['sysmsg'] as $m){
243 echo "<notice>".xmlify($m)."</notice>";
245 unset($_SESSION['sysmsg']);
247 if(x($_SESSION,'sysmsg_info')){
248 foreach ($_SESSION['sysmsg_info'] as $m){
249 echo "<info>".xmlify($m)."</info>";
251 unset($_SESSION['sysmsg_info']);