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