]> git.mxchange.org Git - friendica.git/blob - mod/ping.php
malformed xml in ping
[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         echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
9                 <result>";
10
11         if(local_user()){
12
13                 
14                 $comments = array();
15                 $likes = array();
16                 $dislikes = array();
17                 $friends = array();
18                 
19                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, 
20                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, 
21                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
22                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
23                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
24                                  `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0",
25                         intval(local_user())
26                 );
27                 
28                 $network = count($r);
29                 foreach ($r as $it) {
30                         switch($it['verb']){
31                                 case ACTIVITY_LIKE:
32                                         $likes[] = $it;
33                                         break;
34                                 case ACTIVITY_DISLIKE:
35                                         $dislikes[] = $it;
36                                         break;
37                                 case ACTIVITY_FRIEND:
38                                         $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
39                                         $obj = parse_xml_string($xmlhead.$it['object']);
40                                         $it['fname'] = $obj->title;                     
41                                         $friends[] = $it;
42                                         break;
43                                 default:
44                                         if ($it['parent']!=$it['id']) $comments[] = $it;
45                         }
46                 }
47
48
49                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, 
50                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, 
51                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
52                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
53                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
54                                  `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1",
55                         intval(local_user())
56                 );      
57                 $home = count($r);
58                 foreach ($r as $it) {
59                         switch($it['verb']){
60                                 case ACTIVITY_LIKE:
61                                         $likes[] = $it;
62                                         break;
63                                 case ACTIVITY_DISLIKE:
64                                         $dislikes[] = $it;
65                                         break;
66                                 case ACTIVITY_FRIEND:
67                                         $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
68                                         $obj = parse_xml_string($xmlhead.$it['object']);
69                                         $it['fname'] = $obj->title;
70                                         $friends[] = $it;
71                                         break;
72                                 default:
73                                         if ($it['parent']!=$it['id']) $comments[] = $it;
74                         }
75                 }
76
77
78                 $intros1 = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, 
79                         `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` 
80                         FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
81                         WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0",
82                         intval(local_user())
83                 );
84                 $intros2 = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, 
85                         `contact`.`name`, `contact`.`url`, `contact`.`photo` 
86                         FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
87                         WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0",
88                         intval(local_user())
89                 );
90                 
91                 $intro = $intros1[0]['total'] + $intros2[0]['total'];
92                 if ($intros1[0]['total']==0) $intros1=Array();
93                 if ($intros2[0]['total']==0) $intros2=Array();
94                 $intros = $intros1+$intros2;
95
96
97
98                 $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
99                 $mails = q("SELECT *,  COUNT(*) AS `total` FROM `mail`
100                         WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
101                         intval(local_user()),
102                         dbesc($myurl)
103                 );
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                         $register = $regs[0]['total'];
109                 } else {
110                         $register = "0";
111                 }
112
113
114                 function xmlize($href, $name, $url, $photo, $date, $message){
115                         $notsxml = '<note href="%s" name="%s" url="%s" photo="%s" date="%s">%s</note>';
116                         return sprintf ( $notsxml,
117                                         xmlify($href), xmlify($name), xmlify($url), xmlify($photo), xmlify($date), xmlify($message)
118                                 );
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);
129                 
130                 echo '  <notif count="'.$tot.'">';
131                 if ($intro>0){
132                         foreach ($intros as $i) { 
133                                 echo xmlize( $a->get_baseurl().'/notifications/'.$i['id'], $i['name'], $i['url'], $i['photo'], relative_date($i['datetime']), t("{0} wants to be your friend") );
134                         };
135                 }
136                 if ($mail>0){
137                         foreach ($mails as $i) { 
138                                 echo xmlize( $a->get_baseurl().'/message/'.$i['id'], $i['from-name'], $i['from-url'], $i['from-photo'], relative_date($i['created']), t("{0} sent you a message") );
139                         };
140                 }
141                 if ($register>0){
142                         foreach ($regs as $i) { 
143                                 echo xmlize( $a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), t("{0} requested registration") );
144                         };
145                 }
146
147                 if (count($comments)){
148                         foreach ($comments as $i) {
149                                 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), sprintf( t("{0} commented %s's post"), $i['pname'] ) );
150                         };
151                 }
152                 if (count($likes)){
153                         foreach ($likes as $i) {
154                                 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), sprintf( t("{0} like %s's post"), $i['pname'] ) );
155                         };
156                 }
157                 if (count($dislikes)){
158                         foreach ($dislikes as $i) {
159                                 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), sprintf( t("{0} dislike %s's post"), $i['pname'] ) );
160                         };
161                 }
162                 if (count($friends)){
163                         foreach ($friends as $i) {
164                                 echo xmlize( $a->get_baseurl().'/display/'.$a->user['nickname']."/".$i['parent'], $i['author-name'], $i['author-link'], $i['author-avatar'], relative_date($i['created']), sprintf( t("{0} is now friend with %s"), $i['fname'] ) );
165                         };
166                 }
167
168
169                 echo "  </notif>";
170         }
171         echo " <sysmsgs>";
172
173                 if(x($_SESSION,'sysmsg')){
174                         foreach ($_SESSION['sysmsg'] as $m){
175                                 echo "<notice>".($m)."</notice>";
176                         }
177                         //$_SESSION['sysmsg']=array();
178                         unset($_SESSION['sysmsg']);
179                 }
180                 if(x($_SESSION,'sysmsg_info')){
181                         foreach ($_SESSION['sysmsg_info'] as $m){
182                                 echo "<info>".($m)."</info>";
183                         }
184                         //$_SESSION['sysmsg_info']=array();
185                         unset($_SESSION['sysmsg_info']);
186                 }
187         
188         echo " </sysmsgs>";
189         echo"</result>
190         ";
191
192         killme();
193 }
194