5 require_once("boot.php");
9 @include(".htconfig.php");
10 require_once("dba.php");
11 $db = new dba($db_host, $db_user, $db_pass, $db_data);
12 unset($db_host, $db_user, $db_pass, $db_data);
14 require_once("session.php");
15 require_once("datetime.php");
20 $a->set_baseurl(get_config('system','url'));
23 $a->set_baseurl($argv[1]);
31 $item_id = intval($argv[2]);
40 $recipients = array();
44 $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
49 $uid = $message[0]['uid'];
50 $recipients[] = $message[0]['contact-id'];
57 $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
63 $parent = $r[0]['parent'];
65 $updated = $r[0]['edited'];
67 $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
75 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
86 require_once('include/group.php');
90 if($parent['type'] == 'remote') {
91 // local followup to remote post
93 $conversant_str = dbesc($parent['contact-id']);
98 $allow_people = expand_acl($parent['allow_cid']);
99 $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
100 $deny_people = expand_acl($parent['deny_cid']);
101 $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
103 $conversants = array();
105 foreach($items as $item) {
106 $recipients[] = $item['contact-id'];
107 $conversants[] = $item['contact-id'];
110 $conversants = array_unique($conversants,SORT_NUMERIC);
113 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
114 $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
115 $recipients = array_diff($recipients,$deny);
117 $conversant_str = dbesc(implode(', ',$conversants));
120 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
127 $tomb_template = file_get_contents('view/atom_tomb.tpl');
128 $item_template = file_get_contents('view/atom_item.tpl');
129 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
132 $feed_template = file_get_contents('view/atom_feed.tpl');
133 $mail_template = file_get_contents('view/atom_mail.tpl');
138 $atom .= replace_macros($feed_template, array(
139 '$feed_id' => xmlify($a->get_baseurl()),
140 '$feed_title' => xmlify($owner['name']),
141 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC',
142 $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
143 '$name' => xmlify($owner['name']),
144 '$profile_page' => xmlify($owner['url']),
145 '$photo' => xmlify($owner['photo']),
146 '$thumb' => xmlify($owner['thumb']),
147 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
148 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
149 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
153 $atom .= replace_macros($mail_template, array(
154 '$name' => xmlify($owner['name']),
155 '$profile_page' => xmlify($owner['url']),
156 '$thumb' => xmlify($owner['thumb']),
157 '$item_id' => xmlify($item['uri']),
158 '$subject' => xmlify($item['title']),
159 '$created' => xmlify(datetime_convert('UTC', 'UTC',
160 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
161 '$content' =>xmlify($item['body']),
162 '$parent_id' => xmlify($item['parent-uri'])
169 foreach($items as $item) {
170 if($item['id'] == $item_id) {
171 $atom .= replace_macros($cmnt_template, array(
172 '$name' => xmlify($owner['name']),
173 '$profile_page' => xmlify($owner['url']),
174 '$thumb' => xmlify($owner['thumb']),
175 '$item_id' => xmlify($item['uri']),
176 '$title' => xmlify($item['title']),
177 '$published' => xmlify(datetime_convert('UTC', 'UTC',
178 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
179 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
180 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
181 '$content' => xmlify($item['body']),
182 '$parent_id' => xmlify($item['parent-uri']),
183 '$comment_allow' => 0
189 foreach($items as $item) {
190 if($item['deleted']) {
191 $atom .= replace_macros($tomb_template, array(
192 '$id' => xmlify($item['uri']),
193 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
194 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
198 foreach($contacts as $contact) {
199 if($item['contact-id'] == $contact['id']) {
200 if($item['parent'] == $item['id']) {
201 $atom .= replace_macros($item_template, array(
202 '$name' => xmlify($contact['name']),
203 '$profile_page' => xmlify($contact['url']),
204 '$thumb' => xmlify($contact['thumb']),
205 '$owner_name' => xmlify($item['owner-name']),
206 '$owner_profile_page' => xmlify($item['owner-link']),
207 '$owner_thumb' => xmlify($item['owner-avatar']),
208 '$item_id' => xmlify($item['uri']),
209 '$title' => xmlify($item['title']),
210 '$published' => xmlify(datetime_convert('UTC', 'UTC',
211 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
212 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
213 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
214 '$location' => xmlify($item['location']),
215 '$content' =>xmlify($item['body']),
216 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'])) ? 1 : 0)
220 $atom .= replace_macros($cmnt_template, array(
221 '$name' => xmlify($contact['name']),
222 '$profile_page' => xmlify($contact['url']),
223 '$thumb' => xmlify($contact['thumb']),
224 '$item_id' => xmlify($item['uri']),
225 '$title' => xmlify($item['title']),
226 '$published' => xmlify(datetime_convert('UTC', 'UTC',
227 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
228 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
229 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
230 '$content' =>xmlify($item['body']),
231 '$parent_id' => xmlify($item['parent-uri']),
232 '$comment_allow' => (($item['last-child']) ? 1 : 0)
241 $atom .= "</feed>\r\n";
246 // create a clone of this feed but with comments disabled to send to those who can't respond.
248 $atom_nowrite = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
252 $recip_str = $parent['contact-id'];
254 $recip_str = implode(', ', $recipients);
257 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
269 if((! strlen($rr['dfrn-id'])) || ($rr['duplex'] && ! strlen($rr['issued-id'])))
272 $idtosend = (($rr['duplex']) ? $rr['issued-id'] : $rr['dfrn-id']);
274 $url = $rr['notify'] . '?dfrn_id=' . $idtosend;
276 $xml = fetch_url($url);
284 $res = simplexml_load_string($xml);
286 if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
290 $sent_dfrn_id = hex2bin($res->dfrn_id);
291 $challenge = hex2bin($res->challenge);
295 openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$rr['prvkey']);
296 openssl_private_decrypt($challenge,$postvars['challenge'],$rr['prvkey']);
299 openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$rr['pubkey']);
300 openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']);
303 $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
304 if(($final_dfrn_id != $rr['dfrn-id']) || (($rr['duplex']) && ($final_dfrn_id != $rr['issued-id']))) {
305 // did not decode properly - cannot trust this site
309 $postvars['dfrn_id'] = (($duplex) ? $rr['issued-id'] : $rr['dfrn-id']);
312 $postvars['data'] = $atom;
314 elseif(((strlen($rr['dfrn-id'])) || (($rr['duplex']) && (strlen($rr['issued-id']))))
315 && (! ($rr['blocked']) || ($rr['readonly']))) {
316 $postvars['data'] = $atom;
319 $postvars['data'] = $atom_nowrite;
322 $xml = post_url($rr['notify'],$postvars);
327 $res = simplexml_load_string($xml);
329 // Currently there is no retry attempt for failed mail delivery.
330 // We need to handle this in the UI, report the non-deliverables and try again
332 if(($cmd == 'mail') && (intval($res->status) == 0)) {
334 $r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",