]> git.mxchange.org Git - friendica.git/blob - include/notifier.php
e67ef06e3185be46e494ee4a553382a38faa8ad9
[friendica.git] / include / notifier.php
1 <?php
2
3 require_once("boot.php");
4
5 $a = new App;
6
7 @include(".htconfig.php");
8 require_once("dba.php");
9 $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
10         unset($db_host, $db_user, $db_pass, $db_data);
11
12 require_once("session.php");
13 require_once("datetime.php");
14
15 // FIXME - generalise for other content, probably create a notify queue in 
16 // the db with type and recipient list
17
18 if(($argc != 3) || (! intval($argv[2])))
19         exit;
20
21         $baseurl = trim(pack("H*" , $argv[1]));
22
23         $item_id = $argv[2];
24
25         $is_parent = false;
26
27         $recipients = array();
28
29         $r = q("SELECT `item`.*,  `contact`.*,`item`.`id` AS `item_id` FROM `item` LEFT JOIN `contact` ON `item`.`contact-id` = `contact`.`id` 
30                 WHERE `item`.`id` = %d LIMIT 1",
31                 intval($item_id)
32         );
33         if(! count($r))
34                 killme();
35
36         $item = $r[0];
37
38         $recipients[] = $item['contact-id'];
39
40         if($item['parent'] == $item['id']) {
41                 $is_parent = true;
42         }
43         else {
44                 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
45                         intval($item['parent'])
46                 );
47                 if(count($r))
48                         $parent = $r[0];
49         }
50
51         if(is_array($parent))
52                 $recipients[] = $parent['contact-id'];
53
54         $r = q("SELECT `contact-id` FROM `item` WHERE `hash` = '%s' AND `id` != %d AND `id` != %d",
55                 dbesc($item['hash']),
56                 intval($item['id']),
57                 intval($item['parent'])
58         );
59         if(count($r)) {
60                 foreach($r as $rr) {
61                         if($rr['contact-id'] != $item['contact-id'])
62                                 $recipients[] = $rr['contact-id'];
63                 }
64         }
65
66         $tpl = file_get_contents('view/atomic.tpl');
67
68         // FIXME should dump the entire conversation
69
70         $atom = replace_macros($tpl, array(
71                 '$feed_id' => xmlify($baseurl),
72                 '$feed_title' => xmlify('Wall Item'),
73                 '$feed_updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')) ,
74                 '$name' => xmlify($item['name']),
75                 '$profile_page' => xmlify($item['url']),
76                 '$thumb' => xmlify($item['thumb']),
77                 '$item_id' => xmlify($item['hash'] . '-' . $item['id']),
78                 '$title' => xmlify(''),
79                 '$link' => xmlify($baseurl . '/item/' . $item['id']),
80                 '$updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')),
81                 '$summary' => xmlify(''),
82                 '$content' => xmlify($item['body'])
83         ));
84
85 print_r($atom);
86         // atomify
87
88         // expand list of recipients
89
90 dbg(3);
91
92
93         $recipients = array_unique($recipients);
94 print_r($recipients);
95         $recip_str = implode(', ', $recipients);
96
97         $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
98                 dbesc($recip_str)
99         );
100         if(! count($r))
101                 killme();
102
103         // delivery loop
104
105         foreach($r as $rr) {
106                 if($rr['self'])
107                         continue;
108
109                 if(! strlen($rr['dfrn-id']))
110                         continue;
111                 $url = $rr['notify'] . '?dfrn_id=' . $rr['dfrn-id'];
112 print_r($url);
113                 $xml = fetch_url($url);
114 echo $xml;
115
116 print_r($xml);
117                 if(! $xml)
118                         continue;
119
120                 $res = simplexml_load_string($xml);
121 print_r($res);
122 var_dump($res);
123
124                 if((intval($res->status) != 0) || (! strlen($res->challenge)) || ($res->dfrn_id != $rr['dfrn-id']))
125                         continue;
126
127                 $postvars = array();
128
129                 $postvars['dfrn_id'] = $rr['dfrn-id'];
130                 $challenge = hex2bin($res->challenge);
131 echo "dfrn-id:" . $res->dfrn_id . "\r\n";
132 echo "challenge:" . $res->challenge . "\r\n";
133 echo "pubkey:" . $rr['pubkey'] . "\r\n";
134
135                 openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']);
136
137                 $postvars['data'] = $atom;
138
139 print_r($postvars);
140                 $xml = fetch_url($url,$postvars);
141
142                                 
143         }
144
145         killme();
146