4 require_once("boot.php");
8 @include(".htconfig.php");
9 require_once("dba.php");
10 $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
11 unset($db_host, $db_user, $db_pass, $db_data);
13 require_once("session.php");
14 require_once("datetime.php");
19 $baseurl = trim(hex2bin($argv[1]));
26 $item_id = intval($argv[3]);
33 $recipients = array();
37 $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
43 $parent = $r[0]['parent'];
45 $updated = $r[0]['edited'];
47 $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
54 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
64 require_once('include/group.php');
68 if(strlen($parent['remote-id'])) {
70 $conversant_str = dbesc($parent['contact-id']);
75 $allow_people = expand_acl($parent['allow_cid']);
76 $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
77 $deny_people = expand_acl($parent['deny_cid']);
78 $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
80 $conversants = array();
82 foreach($items as $item) {
83 $recipients[] = $item['contact-id'];
84 $conversants[] = $item['contact-id'];
87 $conversants = array_unique($conversants,SORT_NUMERIC);
90 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
91 $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
92 $recipients = array_diff($recipients,$deny);
94 $conversant_str = dbesc(implode(', ',$conversants));
97 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) ");
105 $feed_template = file_get_contents('view/atom_feed.tpl');
106 $tomb_template = file_get_contents('view/atom_tomb.tpl');
107 $item_template = file_get_contents('view/atom_item.tpl');
108 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
113 $atom .= replace_macros($feed_template, array(
114 '$feed_id' => xmlify($baseurl),
115 '$feed_title' => xmlify($owner['name']),
116 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
117 '$name' => xmlify($owner['name']),
118 '$profile_page' => xmlify($owner['url']),
119 '$photo' => xmlify($owner['photo'])
123 foreach($items as $item) {
124 if($item['id'] == $item_id) {
125 $atom .= replace_macros($cmnt_template, array(
126 '$name' => xmlify($owner['name']),
127 '$profile_page' => xmlify($owner['url']),
128 '$thumb' => xmlify($owner['thumb']),
129 '$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"),
130 '$title' => xmlify($item['title']),
131 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
132 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
133 '$content' =>xmlify($item['body']),
134 '$parent_id' => xmlify("{$items[0]['remote-id']}"),
135 '$comment_allow' => 0
141 foreach($items as $item) {
142 if($item['deleted']) {
143 $atom .= replace_macros($tomb_template, array(
144 '$id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"),
145 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
149 foreach($contacts as $contact) {
150 if($item['contact-id'] == $contact['id']) {
151 if($item['parent'] == $item['id']) {
152 $atom .= replace_macros($item_template, array(
153 '$name' => xmlify($contact['name']),
154 '$profile_page' => xmlify($contact['url']),
155 '$thumb' => xmlify($contact['thumb']),
156 '$owner_name' => xmlify($item['owner-name']),
157 '$owner_profile_page' => xmlify($item['owner-link']),
158 '$owner_thumb' => xmlify($item['owner-avatar']),
159 '$item_id' => xmlify(((strlen($item['remote-id'])) ? $item['remote-id'] : "urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}")),
160 '$title' => xmlify($contact['name']),
161 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
162 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
163 '$content' =>xmlify($item['body']),
164 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'] && (! $contact['blocked']))) ? 1 : 0)
168 $atom .= replace_macros($cmnt_template, array(
169 '$name' => xmlify($contact['name']),
170 '$profile_page' => xmlify($contact['url']),
171 '$thumb' => xmlify($contact['thumb']),
172 '$item_id' => xmlify(((strlen($item['remote-id'])) ? $item['remote-id'] : "urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}")),
173 '$title' => xmlify($item['title']),
174 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
175 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
176 '$content' =>xmlify($item['body']),
177 '$parent_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$items[0]['hash']}"),
178 '$comment_allow' => (($item['last-child']) ? 1 : 0)
186 $atom .= "</feed>\r\n";
188 // create a clone of this feed but with comments disabled to send to those who can't respond.
190 $atom_nowrite = str_replace('<dfrn:comment-allow>1</dfrn:comment-allow>','<dfrn:comment-allow>0</dfrn:comment-allow>',$atom);
194 $recip_str = $parent['contact-id'];
196 $recip_str = implode(', ', $recipients);
199 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
209 echo "In delivery loop:";
213 if(! strlen($rr['dfrn-id']))
215 $url = $rr['notify'] . '?dfrn_id=' . $rr['dfrn-id'];
217 $xml = fetch_url($url);
222 $res = simplexml_load_string($xml);
224 if((intval($res->status) != 0) || (! strlen($res->challenge)) || ($res->dfrn_id != $rr['dfrn-id']))
229 $postvars['dfrn_id'] = $rr['dfrn-id'];
230 $challenge = hex2bin($res->challenge);
232 openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']);
234 if(strlen($rr['dfrn-id']) && (! $rr['blocked']))
235 $postvars['data'] = $atom;
237 $postvars['data'] = $atom_nowrite;
239 echo "POSTVARS:" . print_r($postvars);
241 $xml = post_url($url,$postvars);
242 echo "XML response:" . $xml;