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