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