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'));
28 $item_id = intval($argv[2]);
37 $recipients = array();
41 $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
46 $uid = $message[0]['uid'];
47 $recipients[] = $message[0]['contact-id'];
54 $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
60 $parent = $r[0]['parent'];
62 $updated = $r[0]['edited'];
64 $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
72 $r = q("SELECT `contact`.*, `user`.`nickname`
73 FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
74 WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
85 require_once('include/group.php');
89 if($parent['type'] == 'remote') {
90 // local followup to remote post
92 $conversant_str = dbesc($parent['contact-id']);
97 $allow_people = expand_acl($parent['allow_cid']);
98 $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
99 $deny_people = expand_acl($parent['deny_cid']);
100 $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
102 $conversants = array();
104 foreach($items as $item) {
105 $recipients[] = $item['contact-id'];
106 $conversants[] = $item['contact-id'];
109 $conversants = array_unique($conversants,SORT_NUMERIC);
112 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
113 $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
114 $recipients = array_diff($recipients,$deny);
116 $conversant_str = dbesc(implode(', ',$conversants));
119 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
126 $tomb_template = file_get_contents('view/atom_tomb.tpl');
127 $item_template = file_get_contents('view/atom_item.tpl');
128 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
131 $feed_template = file_get_contents('view/atom_feed.tpl');
132 $mail_template = file_get_contents('view/atom_mail.tpl');
137 $atom .= replace_macros($feed_template, array(
138 '$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
139 '$feed_title' => xmlify($owner['name']),
140 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , ATOM_TIME)) ,
141 '$name' => xmlify($owner['name']),
142 '$profile_page' => xmlify($owner['url']),
143 '$photo' => xmlify($owner['photo']),
144 '$thumb' => xmlify($owner['thumb']),
145 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
146 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
147 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME))
151 $atom .= replace_macros($mail_template, array(
152 '$name' => xmlify($owner['name']),
153 '$profile_page' => xmlify($owner['url']),
154 '$thumb' => xmlify($owner['thumb']),
155 '$item_id' => xmlify($item['uri']),
156 '$subject' => xmlify($item['title']),
157 '$created' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
158 '$content' => xmlify($item['body']),
159 '$parent_id' => xmlify($item['parent-uri'])
164 require_once('include/items.php');
166 $verb = construct_verb($item);
167 $actobj = construct_activity($item);
171 foreach($items as $item) {
172 if($item['id'] == $item_id) {
173 $atom .= replace_macros($cmnt_template, array(
174 '$name' => xmlify($owner['name']),
175 '$profile_page' => xmlify($owner['url']),
176 '$thumb' => xmlify($owner['thumb']),
177 '$owner_name' => xmlify($item['owner-name']),
178 '$owner_profile_page' => xmlify($item['owner-link']),
179 '$owner_thumb' => xmlify($item['owner-avatar']),
180 '$item_id' => xmlify($item['uri']),
181 '$title' => xmlify($item['title']),
182 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
183 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
184 '$location' => xmlify($item['location']),
186 '$verb' => xmlify($verb),
187 '$actobj' => $actobj,
188 '$content' => xmlify($item['body']),
189 '$parent_id' => xmlify($item['parent-uri']),
190 '$comment_allow' => 0
196 foreach($items as $item) {
197 if($item['deleted']) {
198 $atom .= replace_macros($tomb_template, array(
199 '$id' => xmlify($item['uri']),
200 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME))
204 foreach($contacts as $contact) {
205 if($item['contact-id'] == $contact['id']) {
206 if($item['parent'] == $item['id']) {
207 $atom .= replace_macros($item_template, array(
208 '$name' => xmlify($contact['name']),
209 '$profile_page' => xmlify($contact['url']),
210 '$thumb' => xmlify($contact['thumb']),
211 '$owner_name' => xmlify($item['owner-name']),
212 '$owner_profile_page' => xmlify($item['owner-link']),
213 '$owner_thumb' => xmlify($item['owner-avatar']),
214 '$item_id' => xmlify($item['uri']),
215 '$title' => xmlify($item['title']),
216 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
217 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
218 '$location' => xmlify($item['location']),
220 '$verb' => xmlify($verb),
221 '$actobj' => $actobj,
222 '$content' => xmlify($item['body']),
223 '$comment_allow' => (($item['last-child'] && ($contact['rel']) && ($contact['rel'] != REL_FAN)) ? 1 : 0)
227 $atom .= replace_macros($cmnt_template, array(
228 '$name' => xmlify($contact['name']),
229 '$profile_page' => xmlify($contact['url']),
230 '$thumb' => xmlify($contact['thumb']),
231 '$item_id' => xmlify($item['uri']),
232 '$title' => xmlify($item['title']),
233 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
234 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
235 '$content' => xmlify($item['body']),
236 '$location' => xmlify($item['location']),
238 '$verb' => xmlify($verb),
239 '$actobj' => $actobj,
240 '$parent_id' => xmlify($item['parent-uri']),
241 '$comment_allow' => (($item['last-child']) ? 1 : 0)
250 $atom .= "</feed>\r\n";
255 // create a clone of this feed but with comments disabled to send to those who can't respond.
257 $atom_nowrite = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
261 $recip_str = $parent['contact-id'];
263 $recip_str = implode(', ', $recipients);
266 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
278 if((! strlen($rr['dfrn-id'])) && (! $rr['duplex']))
281 $idtosend = (($rr['dfrn-id']) ? $rr['dfrn-id'] : $rr['issued-id']);
283 $url = $rr['notify'] . '?dfrn_id=' . $idtosend;
285 $xml = fetch_url($url);
293 $res = simplexml_load_string($xml);
295 if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
300 $sent_dfrn_id = hex2bin($res->dfrn_id);
301 $challenge = hex2bin($res->challenge);
305 if($rr['duplex'] && strlen($rr['prvkey'])) {
306 openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$rr['prvkey']);
307 openssl_private_decrypt($challenge,$postvars['challenge'],$rr['prvkey']);
310 openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$rr['pubkey']);
311 openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']);
314 $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
315 if($final_dfrn_id != $idtosend) {
316 // did not decode properly - cannot trust this site
320 $postvars['dfrn_id'] = $idtosend;
322 if(($rr['rel']) && ($rr['rel'] != REL_FAN) && (! $rr['blocked']) && (! $rr['readonly'])) {
323 $postvars['data'] = $atom;
326 $postvars['data'] = $atom_nowrite;
329 $xml = post_url($rr['notify'],$postvars);
334 $res = simplexml_load_string($xml);
336 // Currently there is no retry attempt for failed mail delivery.
337 // We need to handle this in the UI, report the non-deliverables and try again
339 if(($cmd == 'mail') && (intval($res->status) == 0)) {
341 $r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",