]> git.mxchange.org Git - friendica.git/blob - mod/ping.php
Merge remote-tracking branch 'friendika/master' into newui
[friendica.git] / mod / ping.php
1 <?php
2 require_once("include/datetime.php");
3
4
5 function ping_init(&$a) {
6
7         if(! local_user())
8                 xml_status(0);
9
10         
11         $comments = array();
12         $likes = array();
13         $dislikes = array();
14         $friends = array();
15         
16         $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, 
17                         `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, 
18                         `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
19                         FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
20                         WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
21                          `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0",
22                 intval(local_user())
23         );
24         
25         $network = count($r);
26         foreach ($r as $it) {
27                 switch($it['verb']){
28                         case 'http://activitystrea.ms/schema/1.0/like':
29                                 $likes[] = $it;
30                                 break;
31                         case 'http://activitystrea.ms/schema/1.0/dislike':
32                                 $dislikes[] = $it;
33                                 break;
34                         case 'http://activitystrea.ms/schema/1.0/make-friend':
35                                 $friends[] = $it;
36                                 break;
37                         default:
38                                 if ($it['parent']!=$it['id']) $comments[] = $it;
39                 }
40         }
41
42
43         $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, 
44                         `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, 
45                         `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
46                         FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
47                         WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
48                          `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1",
49                 intval(local_user())
50         );      
51         $home = count($r);
52         foreach ($r as $it) {
53                 switch($it['verb']){
54                         case 'http://activitystrea.ms/schema/1.0/like':
55                                 $likes[] = $it;
56                                 break;
57                         case 'http://activitystrea.ms/schema/1.0/dislike':
58                                 $dislikes[] = $it;
59                                 break;
60                         case 'http://activitystrea.ms/schema/1.0/make-friend':
61                                 $friends[] = $it;
62                                 break;
63                         default:
64                                 if ($it['parent']!=$it['id']) $comments[] = $it;
65                 }
66         }
67
68
69         $intros1 = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, 
70                 `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` 
71                 FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
72                 WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0",
73                 intval(local_user())
74         );
75         $intros2 = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, 
76                 `contact`.`name`, `contact`.`url`, `contact`.`photo` 
77                 FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
78                 WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0",
79                 intval(local_user())
80         );
81         
82         $intro = $intros1[0]['total'] + $intros2[0]['total'];
83         if ($intros1[0]['total']==0) $intros1=Array();
84         if ($intros2[0]['total']==0) $intros2=Array();
85         $intros = $intros1+$intros2;
86
87
88
89         $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
90         $mails = q("SELECT *,  COUNT(*) AS `total` FROM `mail`
91                 WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
92                 intval(local_user()),
93                 dbesc($myurl)
94         );
95         $mail = $mails[0]['total'];
96         
97         if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()){
98                 $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");
99                 $register = $regs[0]['total'];
100         } else {
101                 $register = "0";
102         }
103
104
105         function xmlize($href, $name, $url, $photo, $date, $message){
106                 $notsxml = '<note href="%s" name="%s" url="%s" photo="%s" date="%s">%s</note>';
107                 return sprintf ( $notsxml,
108                                 $href, $name, $url, $photo, $date, $message
109                         );
110         }
111         
112         header("Content-type: text/xml");
113         echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
114                 <result>
115                         <intro>$intro</intro>
116                         <mail>$mail</mail>
117                         <net>$network</net>
118                         <home>$home</home>";
119         if ($register!=0) echo "<register>$register</register>";
120         
121         $tot = $mail+$intro+$register+count($comments)+count($likes)+count($dislikes)+count($friends);
122         
123         echo '  <notif count="'.$tot.'">';
124         if ($intro>0){
125                 foreach ($intros as $i) { 
126                         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") );
127                 };
128         }
129         if ($mail>0){
130                 foreach ($mails as $i) { 
131                         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") );
132                 };
133         }
134         if ($register>0){
135                 foreach ($regs as $i) { 
136                         echo xmlize( $a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), t("{0} requested registration") );
137                 };
138         }
139
140         if (count($comments)){
141                 foreach ($comments as $i) {
142                         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'] ) );
143                 };
144         }
145         if (count($likes)){
146                 foreach ($likes as $i) {
147                         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} like %s's post"), $i['pname'] ) );
148                 };
149         }
150         if (count($dislikes)){
151                 foreach ($dislikes as $i) {
152                         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} dislike %s's post"), $i['pname'] ) );
153                 };
154         }
155         if (count($friends)){
156                 foreach ($friends as $i) {
157                         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 friend with %s"), $i['pname'] ) );
158                 };
159         }
160
161
162         echo "  </notif>
163                 </result>
164         ";
165
166         killme();
167 }
168