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