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