]> git.mxchange.org Git - friendica.git/blob - mod/ping.php
e7f366095d205124774c748b153324d7b40ddb0a
[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         $r = q("SELECT COUNT(*) AS `total` FROM `item` 
12                 WHERE `unseen` = 1 AND `visible` = 1 AND `deleted` = 0 AND `uid` = %d AND `wall` = 0 ",
13                 intval(local_user())
14         );
15         $network = $r[0]['total'];
16
17         $r = q("SELECT COUNT(*) AS `total` FROM `item` 
18                 WHERE `unseen` = 1 AND `visible` = 1 AND `deleted` = 0 AND `uid` = %d AND `wall` = 1 ",
19                 intval(local_user())
20         );
21         $home = $r[0]['total'];
22
23         $intros = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, 
24                 `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` 
25                 FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
26                 WHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 ",
27                 intval(local_user())
28         );
29         $intro = $intros[0]['total'];
30
31         $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
32         $mails = q("SELECT *,  COUNT(*) AS `total` FROM `mail`
33                 WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
34                 intval(local_user()),
35                 dbesc($myurl)
36         );
37         $mail = $mails[0]['total'];
38         
39         
40         
41         header("Content-type: text/xml");
42         echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
43                 <result>
44                         <intro>$intro</intro>
45                         <mail>$mail</mail>
46                         <net>$network</net>
47                         <home>$home</home>
48                         <notif count=\"".($mail+$intro)."\">";
49         if ($intro>0){
50                 foreach ($intros as $i) { 
51                         echo sprintf ('<note href="%s" name="%s" url="%s" photo="%s" date="%s">%s</note>', 
52                                 $a->get_baseurl().'/notification/'.$i['id'], $i['name'], $i['url'], $i['photo'], relative_date($i['datetime']), t("{0} wants to be your friend")
53                         );
54                 };
55         }
56         if ($mail>0){
57                 foreach ($mails as $i) { 
58                         var_dump($i);
59                         echo sprintf ('<note href="%s" name="%s" url="%s" photo="%s" date="%s">%s</note>',
60                                 $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")
61                         );
62                 };
63         }
64
65         echo "  </notif>
66                 </result>
67         ";
68
69         killme();
70 }
71