]> git.mxchange.org Git - friendica.git/blob - mod/ping.php
7380ff7d051e915c25b2450663bdad36827849ca
[friendica.git] / mod / ping.php
1 <?php
2 require_once("include/datetime.php");
3
4
5 function ping_init(&$a) {
6
7         header("Content-type: text/xml");
8         
9         echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
10                 <result>";
11
12         $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
13         if(local_user()){
14
15                 $firehose = intval(get_pconfig(local_user(),'system','notify_full'));
16
17                 $z = q("select * from notify where uid = %d
18                         order by seen asc, date desc limit 0, 50",
19                         intval(local_user())
20                 );
21
22
23                 $tags = array();
24                 $comments = array();
25                 $likes = array();
26                 $dislikes = array();
27                 $friends = array();
28                 $posts = array();
29                 $home = 0;
30                 $network = 0;
31
32                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`, 
33                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, 
34                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
35                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
36                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
37                                  `item`.`deleted` = 0 AND `item`.`uid` = %d 
38                                 ORDER BY `item`.`created` DESC",
39                         intval(local_user())
40                 );
41
42                 if(count($r)) {         
43
44                         foreach ($r as $it) {
45
46                                 if($it['wall'])
47                                         $home ++;
48                                 else
49                                         $network ++;
50
51                                 switch($it['verb']){
52                                         case ACTIVITY_TAG:
53                                                 $obj = parse_xml_string($xmlhead.$it['object']);
54                                                 $it['tname'] = $obj->content;
55                                                 $tags[] = $it;
56                                                 break;
57                                         case ACTIVITY_LIKE:
58                                                 $likes[] = $it;
59                                                 break;
60                                         case ACTIVITY_DISLIKE:
61                                                 $dislikes[] = $it;
62                                                 break;
63                                         case ACTIVITY_FRIEND:
64                                                 $obj = parse_xml_string($xmlhead.$it['object']);
65                                                 $it['fname'] = $obj->title;                     
66                                                 $friends[] = $it;
67                                                 break;
68                                         default:
69                                                 if ($it['parent']!=$it['id']) { 
70                                                         $comments[] = $it;
71                                                 } else {
72                                                         if(! $it['wall'])
73                                                                 $posts[] = $it;
74                                                 }
75                                 }
76                         }
77                 }
78
79                 $intros1 = q("SELECT  `intro`.`id`, `intro`.`datetime`, 
80                         `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` 
81                         FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
82                         WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0",
83                         intval(local_user())
84                 );
85                 $intros2 = q("SELECT `intro`.`id`, `intro`.`datetime`, 
86                         `contact`.`name`, `contact`.`url`, `contact`.`photo` 
87                         FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
88                         WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0",
89                         intval(local_user())
90                 );
91                 
92                 $intro = count($intros1) + count($intros2);
93                 $intros = $intros1+$intros2;
94
95
96
97                 $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
98                 $mails = q("SELECT *,  COUNT(*) AS `total` FROM `mail`
99                         WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
100                         intval(local_user()),
101                         dbesc($myurl)
102                 );
103                 if($mails)
104                         $mail = $mails[0]['total'];
105                 
106                 if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()){
107                         $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");
108                         if($regs)
109                                 $register = $regs[0]['total'];
110                 } else {
111                         $register = "0";
112                 }
113
114
115                 function xmlize($href, $name, $url, $photo, $date, $seen, $message){
116                         $notsxml = '<note href="%s" name="%s" url="%s" photo="%s" date="%s" seen="%s" >%s</note>';
117                         return sprintf ( $notsxml,
118                                 xmlify($href), xmlify($name), xmlify($url), xmlify($photo), xmlify($date), xmlify($seen), xmlify($message)
119                         );
120                 }
121                 
122                 echo "<intro>$intro</intro>
123                                 <mail>$mail</mail>
124                                 <net>$network</net>
125                                 <home>$home</home>";
126                 if ($register!=0) echo "<register>$register</register>";
127                 
128                 $tot = $mail+$intro+$register+count($comments)+count($likes)+count($dislikes)+count($friends)+count($posts)+count($tags);
129
130                 require_once('include/bbcode.php');
131                 $sysnotify = 0;
132
133                 if($firehose) {
134                         echo '  <notif count="'.$tot.'">';
135                 }
136                 else {
137                         if(count($z)) {
138                                 foreach($z as $zz) {
139                                         if($zz['seen'] == 0)
140                                                 $sysnotify ++;
141                                 }
142                         }                                               
143
144                         echo '  <notif count="'. $sysnotify .'">';
145                         if(count($z)) {
146                                 foreach($z as $zz) {
147                                         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'] ? '' : '&rarr; ') .strip_tags(bbcode($zz['msg'])));
148                                 }
149                         }
150                 }
151
152                 if($firehose) {
153                         if ($intro>0){
154                                 foreach ($intros as $i) { 
155                                         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") );
156                                 };
157                         }
158                         if ($mail>0){
159                                 foreach ($mails as $i) { 
160                                         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") );
161                                 };
162                         }
163                         if ($register>0){
164                                 foreach ($regs as $i) { 
165                                         echo xmlize( $a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), 'notify-unseen',t("{0} requested registration") );
166                                 };
167                         }
168
169                         if (count($comments)){
170                                 foreach ($comments as $i) {
171                                         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'] ) );
172                                 };
173                         }
174                         if (count($likes)){
175                                 foreach ($likes as $i) {
176                                         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'] ) );
177                                 };
178                         }
179                         if (count($dislikes)){
180                                 foreach ($dislikes as $i) {
181                                         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'] ) );
182                                 };
183                         }
184                         if (count($friends)){
185                                 foreach ($friends as $i) {
186                                         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'] ) );
187                                 };
188                         }
189                         if (count($posts)){
190                                 foreach ($posts as $i) {
191                                         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") ) );
192                                 };
193                         }
194                         if (count($tags)){
195                                 foreach ($tags as $i) {
196                                         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'] ) );
197                                 };
198                         }
199
200                         if (count($cit)){
201                                 foreach ($cit as $i) {
202                                         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") );
203                                 };
204                         }
205                 }
206
207                 echo "  </notif>";
208         }
209         echo " <sysmsgs>";
210
211         if(x($_SESSION,'sysmsg')){
212                 foreach ($_SESSION['sysmsg'] as $m){
213                         echo "<notice>".xmlify($m)."</notice>";
214                 }
215                 unset($_SESSION['sysmsg']);
216         }
217         if(x($_SESSION,'sysmsg_info')){
218                 foreach ($_SESSION['sysmsg_info'] as $m){
219                         echo "<info>".xmlify($m)."</info>";
220                 }
221                 unset($_SESSION['sysmsg_info']);
222         }
223         
224         echo " </sysmsgs>";
225         echo"</result>
226         ";
227
228         killme();
229 }
230