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`.`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
92 require_once('include/group.php');
96 if($parent['type'] === 'remote') {
97 // local followup to remote post
99 $notify_hub = false; // not public
100 $conversant_str = dbesc($parent['contact-id']);
105 if((strlen($parent['allow_cid']))
106 || (strlen($parent['allow_gid']))
107 || (strlen($parent['deny_cid']))
108 || (strlen($parent['deny_gid'])))
109 $notify_hub = false; // private recipients, not public
111 $allow_people = expand_acl($parent['allow_cid']);
112 $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
113 $deny_people = expand_acl($parent['deny_cid']);
114 $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
116 $conversants = array();
118 foreach($items as $item) {
119 $recipients[] = $item['contact-id'];
120 $conversants[] = $item['contact-id'];
123 $conversants = array_unique($conversants,SORT_NUMERIC);
126 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
127 $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
128 $recipients = array_diff($recipients,$deny);
130 $conversant_str = dbesc(implode(', ',$conversants));
133 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
140 $tomb_template = load_view_file('view/atom_tomb.tpl');
141 $item_template = load_view_file('view/atom_item.tpl');
142 $cmnt_template = load_view_file('view/atom_cmnt.tpl');
145 $feed_template = load_view_file('view/atom_feed.tpl');
146 $mail_template = load_view_file('view/atom_mail.tpl');
152 $hubs = explode(',', $hub);
154 foreach($hubs as $h) {
158 $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
163 $atom .= replace_macros($feed_template, array(
164 '$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
165 '$feed_title' => xmlify($owner['name']),
166 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , ATOM_TIME)) ,
168 '$salmon' => '', // private feed, we don't use salmon here
169 '$name' => xmlify($owner['name']),
170 '$profile_page' => xmlify($owner['url']),
171 '$photo' => xmlify($owner['photo']),
172 '$thumb' => xmlify($owner['thumb']),
173 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
174 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
175 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME))
178 if($cmd === 'mail') {
179 $notify_hub = false; // mail is not public
180 $atom .= replace_macros($mail_template, array(
181 '$name' => xmlify($owner['name']),
182 '$profile_page' => xmlify($owner['url']),
183 '$thumb' => xmlify($owner['thumb']),
184 '$item_id' => xmlify($item['uri']),
185 '$subject' => xmlify($item['title']),
186 '$created' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
187 '$content' => xmlify($item['body']),
188 '$parent_id' => xmlify($item['parent-uri'])
194 foreach($items as $item) { // there is only one item
196 $verb = construct_verb($item);
197 $actobj = construct_activity($item);
199 if($item['id'] == $item_id) {
200 $atom .= replace_macros($cmnt_template, array(
201 '$name' => xmlify($owner['name']),
202 '$profile_page' => xmlify($owner['url']),
203 '$thumb' => xmlify($owner['thumb']),
204 '$owner_name' => xmlify($item['owner-name']),
205 '$owner_profile_page' => xmlify($item['owner-link']),
206 '$owner_thumb' => xmlify($item['owner-avatar']),
207 '$item_id' => xmlify($item['uri']),
208 '$title' => xmlify($item['title']),
209 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
210 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
211 '$location' => xmlify($item['location']),
213 '$verb' => xmlify($verb),
214 '$actobj' => $actobj,
215 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
216 '$content' => xmlify($item['body']),
217 '$parent_id' => xmlify($item['parent-uri']),
218 '$comment_allow' => 0
224 foreach($items as $item) {
225 if($item['deleted']) {
226 $atom .= replace_macros($tomb_template, array(
227 '$id' => xmlify($item['uri']),
228 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME))
232 $contact = get_item_contact($item,$contacts);
236 $verb = construct_verb($item);
237 $actobj = construct_activity($item);
239 if($item['parent'] == $item['id']) {
240 $atom .= replace_macros($item_template, array(
241 '$name' => xmlify($contact['name']),
242 '$profile_page' => xmlify($contact['url']),
243 '$thumb' => xmlify($contact['thumb']),
244 '$owner_name' => xmlify($item['owner-name']),
245 '$owner_profile_page' => xmlify($item['owner-link']),
246 '$owner_thumb' => xmlify($item['owner-avatar']),
247 '$item_id' => xmlify($item['uri']),
248 '$title' => xmlify($item['title']),
249 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
250 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
251 '$location' => xmlify($item['location']),
253 '$verb' => xmlify($verb),
254 '$actobj' => $actobj,
255 '$content' => xmlify($item['body']),
256 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
257 '$comment_allow' => (($item['last-child']) ? 1 : 0)
261 $atom .= replace_macros($cmnt_template, array(
262 '$name' => xmlify($contact['name']),
263 '$profile_page' => xmlify($contact['url']),
264 '$thumb' => xmlify($contact['thumb']),
265 '$item_id' => xmlify($item['uri']),
266 '$title' => xmlify($item['title']),
267 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
268 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
269 '$content' => xmlify($item['body']),
270 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
271 '$location' => xmlify($item['location']),
273 '$verb' => xmlify($verb),
274 '$actobj' => $actobj,
275 '$parent_id' => xmlify($item['parent-uri']),
276 '$comment_allow' => (($item['last-child']) ? 1 : 0)
283 $atom .= '</feed>' . "\r\n";
290 $recip_str = $parent['contact-id'];
292 $recip_str = implode(', ', $recipients);
295 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
303 foreach($r as $contact) {
309 switch($contact['network']) {
311 $deliver_status = dfrn_deliver($owner,$contact,$atom,$debugging);
317 if(($cmd === 'mail') && ($deliver_status == 0)) {
318 $r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",
324 if((strlen($hub)) && ($notify_hub)) {
325 $hubs = explode(',', $hub);
327 foreach($hubs as $h) {
331 $params = 'hub.mode=publish&hub.url=' . urlencode($a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
332 post_url($h,$params);
334 file_put_contents('pubsub.out', "\n\n" . "Pinged hub " . $h . ' at '
335 . datetime_convert() . "\n" . "Hub returned " . $a->get_curl_code() . "\n\n" , FILE_APPEND);
338 sleep(7); // try and avoid multiple hubs responding at precisely the same time