3 require_once("boot.php");
7 @include(".htconfig.php");
8 require_once("dba.php");
9 $db = new dba($db_host, $db_user, $db_pass, $db_data);
10 unset($db_host, $db_user, $db_pass, $db_data);
13 $debugging = get_config('system','debugging');
15 require_once("session.php");
16 require_once("datetime.php");
17 require_once('include/items.php');
23 $a->set_baseurl(get_config('system','url'));
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_id = $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 `contact`.*, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags`
76 FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
77 WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
86 $hub = get_config('system','huburl');
87 // If this is a public conversation, notify the feed hub
90 // fill this in with a salmon slap if applicable
95 require_once('include/group.php');
99 if($parent['type'] === 'remote') {
100 // local followup to remote post
102 $notify_hub = false; // not public
103 $conversant_str = dbesc($parent['contact-id']);
108 if((strlen($parent['allow_cid']))
109 || (strlen($parent['allow_gid']))
110 || (strlen($parent['deny_cid']))
111 || (strlen($parent['deny_gid'])))
112 $notify_hub = false; // private recipients, not public
114 $allow_people = expand_acl($parent['allow_cid']);
115 $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
116 $deny_people = expand_acl($parent['deny_cid']);
117 $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
119 $conversants = array();
121 foreach($items as $item) {
122 $recipients[] = $item['contact-id'];
123 $conversants[] = $item['contact-id'];
126 $conversants = array_unique($conversants,SORT_NUMERIC);
129 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
130 $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
131 $recipients = array_diff($recipients,$deny);
133 $conversant_str = dbesc(implode(', ',$conversants));
136 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
143 $tomb_template = load_view_file('view/atom_tomb.tpl');
144 $item_template = load_view_file('view/atom_item.tpl');
145 $cmnt_template = load_view_file('view/atom_cmnt.tpl');
148 $feed_template = load_view_file('view/atom_feed.tpl');
149 $mail_template = load_view_file('view/atom_mail.tpl');
155 $hubs = explode(',', $hub);
157 foreach($hubs as $h) {
161 $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
166 $atom .= replace_macros($feed_template, array(
167 '$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
168 '$feed_title' => xmlify($owner['name']),
169 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , ATOM_TIME)) ,
171 '$salmon' => '', // private feed, we don't use salmon here
172 '$name' => xmlify($owner['name']),
173 '$profile_page' => xmlify($owner['url']),
174 '$photo' => xmlify($owner['photo']),
175 '$thumb' => xmlify($owner['thumb']),
176 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
177 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
178 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME))
181 if($cmd === 'mail') {
182 $notify_hub = false; // mail is not public
183 $atom .= replace_macros($mail_template, array(
184 '$name' => xmlify($owner['name']),
185 '$profile_page' => xmlify($owner['url']),
186 '$thumb' => xmlify($owner['thumb']),
187 '$item_id' => xmlify($item['uri']),
188 '$subject' => xmlify($item['title']),
189 '$created' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
190 '$content' => xmlify($item['body']),
191 '$parent_id' => xmlify($item['parent-uri'])
197 foreach($items as $item) { // there is only one item
199 $verb = construct_verb($item);
200 $actobj = construct_activity($item);
202 if($item['id'] == $item_id) {
203 $slap = replace_macros($cmnt_template, array(
204 '$name' => xmlify($owner['name']),
205 '$profile_page' => xmlify($owner['url']),
206 '$thumb' => xmlify($owner['thumb']),
207 '$owner_name' => xmlify($item['owner-name']),
208 '$owner_profile_page' => xmlify($item['owner-link']),
209 '$owner_thumb' => xmlify($item['owner-avatar']),
210 '$item_id' => xmlify($item['uri']),
211 '$title' => xmlify($item['title']),
212 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
213 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
214 '$location' => xmlify($item['location']),
215 '$coord' => xmlify($item['coord']),
217 '$verb' => xmlify($verb),
218 '$actobj' => $actobj,
219 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
220 '$content' => xmlify($item['body']),
221 '$parent_id' => xmlify($item['parent-uri']),
222 '$comment_allow' => 0
229 foreach($items as $item) {
230 if($item['deleted']) {
231 $atom .= replace_macros($tomb_template, array(
232 '$id' => xmlify($item['uri']),
233 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME))
237 $contact = get_item_contact($item,$contacts);
241 $verb = construct_verb($item);
242 $actobj = construct_activity($item);
244 if($item['parent'] == $item['id']) {
245 $atom .= replace_macros($item_template, array(
246 '$name' => xmlify($contact['name']),
247 '$profile_page' => xmlify($contact['url']),
248 '$thumb' => xmlify($contact['thumb']),
249 '$owner_name' => xmlify($item['owner-name']),
250 '$owner_profile_page' => xmlify($item['owner-link']),
251 '$owner_thumb' => xmlify($item['owner-avatar']),
252 '$item_id' => xmlify($item['uri']),
253 '$title' => xmlify($item['title']),
254 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
255 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
256 '$location' => xmlify($item['location']),
257 '$coord' => xmlify($item['coord']),
259 '$verb' => xmlify($verb),
260 '$actobj' => $actobj,
261 '$content' => xmlify($item['body']),
262 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
263 '$comment_allow' => (($item['last-child']) ? 1 : 0)
267 $atom .= replace_macros($cmnt_template, array(
268 '$name' => xmlify($contact['name']),
269 '$profile_page' => xmlify($contact['url']),
270 '$thumb' => xmlify($contact['thumb']),
271 '$item_id' => xmlify($item['uri']),
272 '$title' => xmlify($item['title']),
273 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
274 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
275 '$content' => xmlify($item['body']),
276 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
277 '$location' => xmlify($item['location']),
278 '$coord' => xmlify($item['coord']),
280 '$verb' => xmlify($verb),
281 '$actobj' => $actobj,
282 '$parent_id' => xmlify($item['parent-uri']),
283 '$comment_allow' => (($item['last-child']) ? 1 : 0)
290 $atom .= '</feed>' . "\r\n";
297 $recip_str = $parent['contact-id'];
299 $recip_str = implode(', ', $recipients);
302 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
312 foreach($r as $contact) {
318 switch($contact['network']) {
320 $deliver_status = dfrn_deliver($owner,$contact,$atom,$debugging);
324 require_once('include/salmon.php');
325 slapper($owner,$contact,$slap);
330 if(($cmd === 'mail') && ($deliver_status == 0)) {
331 $r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",
337 if((strlen($hub)) && ($notify_hub)) {
338 $hubs = explode(',', $hub);
340 foreach($hubs as $h) {
344 $params = 'hub.mode=publish&hub.url=' . urlencode($a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
345 post_url($h,$params);
347 file_put_contents('pubsub.out', "\n\n" . "Pinged hub " . $h . ' at '
348 . datetime_convert() . "\n" . "Hub returned " . $a->get_curl_code() . "\n\n" , FILE_APPEND);
351 sleep(7); // try and avoid multiple hubs responding at precisely the same time