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