]> git.mxchange.org Git - friendica.git/blob - mod/ping.php
ping: show tags
[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                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, 
22                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, 
23                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
24                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
25                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
26                                  `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC",
27                         intval(local_user())
28                 );
29                 
30                 $network = count($r);
31                 foreach ($r as $it) {
32                         switch($it['verb']){
33                                 case ACTIVITY_TAG:
34                                         $obj = parse_xml_string($xmlhead.$it['object']);
35                                         $it['tname'] = $obj->content;
36                                         $tags[] = $it;
37                                         break;
38                                 case ACTIVITY_LIKE:
39                                         $likes[] = $it;
40                                         break;
41                                 case ACTIVITY_DISLIKE:
42                                         $dislikes[] = $it;
43                                         break;
44                                 case ACTIVITY_FRIEND:
45                                         $obj = parse_xml_string($xmlhead.$it['object']);
46                                         $it['fname'] = $obj->title;                     
47                                         $friends[] = $it;
48                                         break;
49                                 default:
50                                         if ($it['parent']!=$it['id']) { 
51                                                 $comments[] = $it;
52                                         } else {
53                                                 $posts[] = $it;
54                                         }
55                         }
56                 }
57
58                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, 
59                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, 
60                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
61                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
62                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
63                                  `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1",
64                         intval(local_user())
65                 );      
66                 $home = count($r);
67                 foreach ($r as $it) {
68                         switch($it['verb']){
69                                 case ACTIVITY_TAG:
70                                         $obj = parse_xml_string($xmlhead.$it['object']);
71                                         $it['tname'] = $obj->content;                           
72                                         $tags[] = $it;
73                                         break;
74                                 case ACTIVITY_LIKE:
75                                         $likes[] = $it;
76                                         break;
77                                 case ACTIVITY_DISLIKE:
78                                         $dislikes[] = $it;
79                                         break;
80                                 case ACTIVITY_FRIEND:
81                                         $obj = parse_xml_string($xmlhead.$it['object']);
82                                         $it['fname'] = $obj->title;
83                                         $friends[] = $it;
84                                         break;
85                                 default:
86                                         if ($it['parent']!=$it['id']) $comments[] = $it;
87                         }
88                 }
89
90
91                 $intros1 = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, 
92                         `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` 
93                         FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
94                         WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0",
95                         intval(local_user())
96                 );
97                 $intros2 = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, 
98                         `contact`.`name`, `contact`.`url`, `contact`.`photo` 
99                         FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
100                         WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0",
101                         intval(local_user())
102                 );
103                 
104                 $intro = $intros1[0]['total'] + $intros2[0]['total'];
105                 if ($intros1[0]['total']==0) $intros1=Array();
106                 if ($intros2[0]['total']==0) $intros2=Array();
107                 $intros = $intros1+$intros2;
108
109
110
111                 $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
112                 $mails = q("SELECT *,  COUNT(*) AS `total` FROM `mail`
113                         WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
114                         intval(local_user()),
115                         dbesc($myurl)
116                 );
117                 $mail = $mails[0]['total'];
118                 
119                 if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()){
120                         $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");
121                         $register = $regs[0]['total'];
122                 } else {
123                         $register = "0";
124                 }
125
126
127                 function xmlize($href, $name, $url, $photo, $date, $message){
128                         $notsxml = '<note href="%s" name="%s" url="%s" photo="%s" date="%s">%s</note>';
129                         return sprintf ( $notsxml,
130                                         xmlify($href), xmlify($name), xmlify($url), xmlify($photo), xmlify($date), xmlify($message)
131                                 );
132                 }
133                 
134
135                 echo "<intro>$intro</intro>
136                                 <mail>$mail</mail>
137                                 <net>$network</net>
138                                 <home>$home</home>";
139                 if ($register!=0) echo "<register>$register</register>";
140                 
141                 $tot = $mail+$intro+$register+count($comments)+count($likes)+count($dislikes)+count($friends)+count($posts)+count($tags);
142                 
143                 echo '  <notif count="'.$tot.'">';
144                 if ($intro>0){
145                         foreach ($intros as $i) { 
146                                 echo xmlize( $a->get_baseurl().'/notifications/'.$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                 echo "  </notif>";
192         }
193         echo " <sysmsgs>";
194
195                 if(x($_SESSION,'sysmsg')){
196                         foreach ($_SESSION['sysmsg'] as $m){
197                                 echo "<notice>".xmlify($m)."</notice>";
198                         }
199                         unset($_SESSION['sysmsg']);
200                 }
201                 if(x($_SESSION,'sysmsg_info')){
202                         foreach ($_SESSION['sysmsg_info'] as $m){
203                                 echo "<info>".xmlify($m)."</info>";
204                         }
205                         unset($_SESSION['sysmsg_info']);
206                 }
207         
208         echo " </sysmsgs>";
209         echo"</result>
210         ";
211
212         killme();
213 }
214