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