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");
20 $a->set_baseurl($argv[1]);
28 $item_id = intval($argv[3]);
35 $recipients = array();
39 $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
44 $uid = $message[0]['uid'];
45 $recipients[] = $message[0]['contact-id'];
52 $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
58 $parent = $r[0]['parent'];
60 $updated = $r[0]['edited'];
62 $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
70 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
81 require_once('include/group.php');
85 if($parent['type'] == 'remote') {
86 // local followup to remote post
88 $conversant_str = dbesc($parent['contact-id']);
93 $allow_people = expand_acl($parent['allow_cid']);
94 $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
95 $deny_people = expand_acl($parent['deny_cid']);
96 $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
98 $conversants = array();
100 foreach($items as $item) {
101 $recipients[] = $item['contact-id'];
102 $conversants[] = $item['contact-id'];
105 $conversants = array_unique($conversants,SORT_NUMERIC);
108 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
109 $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
110 $recipients = array_diff($recipients,$deny);
112 $conversant_str = dbesc(implode(', ',$conversants));
115 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
122 $tomb_template = file_get_contents('view/atom_tomb.tpl');
123 $item_template = file_get_contents('view/atom_item.tpl');
124 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
127 $feed_template = file_get_contents('view/atom_feed.tpl');
128 $mail_template = file_get_contents('view/atom_mail.tpl');
133 $atom .= replace_macros($feed_template, array(
134 '$feed_id' => xmlify($a->get_baseurl()),
135 '$feed_title' => xmlify($owner['name']),
136 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC',
137 $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
138 '$name' => xmlify($owner['name']),
139 '$profile_page' => xmlify($owner['url']),
140 '$photo' => xmlify($owner['photo'])
144 $atom .= replace_macros($mail_template, array(
145 '$name' => xmlify($owner['name']),
146 '$profile_page' => xmlify($owner['url']),
147 '$thumb' => xmlify($owner['thumb']),
148 '$item_id' => xmlify($item['uri']),
149 '$subject' => xmlify($item['title']),
150 '$created' => xmlify(datetime_convert('UTC', 'UTC',
151 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
152 '$content' =>xmlify($item['body']),
153 '$parent_id' => xmlify($item['parent-uri'])
160 foreach($items as $item) {
161 if($item['id'] == $item_id) {
162 $atom .= replace_macros($cmnt_template, array(
163 '$name' => xmlify($owner['name']),
164 '$profile_page' => xmlify($owner['url']),
165 '$thumb' => xmlify($owner['thumb']),
166 '$item_id' => xmlify($item['uri']),
167 '$title' => xmlify($item['title']),
168 '$published' => xmlify(datetime_convert('UTC', 'UTC',
169 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
170 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
171 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
172 '$content' =>xmlify($item['body']),
173 '$parent_id' => xmlify($item['parent-uri']),
174 '$comment_allow' => 0
180 foreach($items as $item) {
181 if($item['deleted']) {
182 $atom .= replace_macros($tomb_template, array(
183 '$id' => xmlify($item['uri']),
184 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
185 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
189 foreach($contacts as $contact) {
190 if($item['contact-id'] == $contact['id']) {
191 if($item['parent'] == $item['id']) {
192 $atom .= replace_macros($item_template, array(
193 '$name' => xmlify($contact['name']),
194 '$profile_page' => xmlify($contact['url']),
195 '$thumb' => xmlify($contact['thumb']),
196 '$owner_name' => xmlify($item['owner-name']),
197 '$owner_profile_page' => xmlify($item['owner-link']),
198 '$owner_thumb' => xmlify($item['owner-avatar']),
199 '$item_id' => xmlify($item['uri']),
200 '$title' => xmlify($item['title']),
201 '$published' => xmlify(datetime_convert('UTC', 'UTC',
202 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
203 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
204 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
205 '$content' =>xmlify($item['body']),
206 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'])) ? 1 : 0)
210 $atom .= replace_macros($cmnt_template, array(
211 '$name' => xmlify($contact['name']),
212 '$profile_page' => xmlify($contact['url']),
213 '$thumb' => xmlify($contact['thumb']),
214 '$item_id' => xmlify($item['uri']),
215 '$title' => xmlify($item['title']),
216 '$published' => xmlify(datetime_convert('UTC', 'UTC',
217 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
218 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
219 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
220 '$content' =>xmlify($item['body']),
221 '$parent_id' => xmlify($item['parent-uri']),
222 '$comment_allow' => (($item['last-child']) ? 1 : 0)
231 $atom .= "</feed>\r\n";
233 // create a clone of this feed but with comments disabled to send to those who can't respond.
235 $atom_nowrite = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
239 $recip_str = $parent['contact-id'];
241 $recip_str = implode(', ', $recipients);
244 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
256 if(! strlen($rr['dfrn-id']))
261 $url = $rr['notify'] . '?dfrn_id=' . $rr['dfrn-id'];
263 $xml = fetch_url($url);
268 $res = simplexml_load_string($xml);
270 if((intval($res->status) != 0) || (! strlen($res->challenge)) || ($res->dfrn_id != $rr['dfrn-id']))
275 $postvars['dfrn_id'] = $rr['dfrn-id'];
276 $challenge = hex2bin($res->challenge);
278 openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']);
281 $postvars['data'] = $atom;
283 elseif(strlen($rr['dfrn-id']) && (! ($rr['blocked']) || ($rr['readonly']))) {
284 $postvars['data'] = $atom;
287 $postvars['data'] = $atom_nowrite;
290 $xml = post_url($rr['notify'],$postvars);
293 $res = simplexml_load_string($xml);
295 // Currently there is no retry attempt for failed mail delivery.
296 // We need to handle this in the UI, report the non-deliverables and try again
298 if(($cmd == 'mail) && (intval($res->status) == 0)) {
300 $r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",