3 require_once('bbcode.php');
5 function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
8 // default permissions - anonymous user
17 if(strlen($owner_nick) && ! intval($owner_nick)) {
18 $r = q("SELECT `uid`, `nickname`, `timezone` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
22 $owner_id = $r[0]['uid'];
23 $owner_nick = $r[0]['nickname'];
24 $owner_tz = $r[0]['timezone'];
28 $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
33 $owner['nickname'] = $owner_nick;
40 * Determine the next birthday, but only if the birthday is published
41 * in the default profile. We _could_ also look for a private profile that the
42 * recipient can see, but somebody could get mad at us if they start getting
43 * public birthday greetings when they haven't made this info public.
45 * Assuming we are able to publish this info, we are then going to convert
46 * the start time from the owner's timezone to UTC.
48 * This will potentially solve the problem found with some social networks
49 * where birthdays are converted to the viewer's timezone and salutations from
50 * elsewhere in the world show up on the wrong day. We will convert it to the
51 * viewer's timezone also, but first we are going to convert it from the birthday
52 * person's timezone to GMT - so the viewer may find the birthday starting at
53 * 6:00PM the day before, but that will correspond to midnight to the birthday person.
59 $p = q("SELECT `dob` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
64 $tmp_dob = substr($p[0]['dob'],5);
65 if(intval($tmp_dob)) {
66 $y = datetime_convert($owner_tz,$owner_tz,'now','Y');
67 $bd = $y . '-' . $tmp_dob . ' 00:00';
68 $t_dob = strtotime($bd);
69 $now = strtotime(datetime_convert($owner_tz,$owner_tz,'now'));
71 $bd = $y + 1 . '-' . $tmp_dob . ' 00:00';
72 $birthday = datetime_convert($owner_tz,'UTC',$bd,ATOM_TIME);
76 if($dfrn_id && $dfrn_id != '*') {
81 $sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id));
85 $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
86 $my_id = '1:' . $dfrn_id;
89 $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
90 $my_id = '0:' . $dfrn_id;
97 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `contact`.`uid` = %d $sql_extra LIMIT 1",
105 $groups = init_groups_visitor($contact['id']);
108 for($x = 0; $x < count($groups); $x ++)
109 $groups[$x] = '<' . intval($groups[$x]) . '>' ;
110 $gs = implode('|', $groups);
113 $gs = '<<>>' ; // Impossible to match
115 $sql_extra = sprintf("
116 AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
117 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
118 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
119 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s')
121 intval($contact['id']),
122 intval($contact['id']),
128 if($dfrn_id === '' || $dfrn_id === '*')
133 if(! strlen($last_update))
134 $last_update = 'now -30 days';
136 $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
138 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
139 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
140 `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
141 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
142 `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`
143 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
144 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
145 AND `item`.`wall` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
146 AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
148 ORDER BY `parent` %s, `created` ASC LIMIT 0, 300",
155 // Will check further below if this actually returned results.
156 // We will provide an empty feed in any case.
160 $feed_template = load_view_file('view/atom_feed.tpl');
164 $hub = get_config('system','huburl');
168 $hubs = explode(',', $hub);
170 foreach($hubs as $h) {
174 $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
179 $salmon = '<link rel="salmon" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
180 $salmon .= '<link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
181 $salmon .= '<link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
184 $atom .= replace_macros($feed_template, array(
185 '$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner_nick),
186 '$feed_title' => xmlify($owner['name']),
187 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now' , ATOM_TIME)) ,
189 '$salmon' => $salmon,
190 '$name' => xmlify($owner['name']),
191 '$profile_page' => xmlify($owner['url']),
192 '$photo' => xmlify($owner['photo']),
193 '$thumb' => xmlify($owner['thumb']),
194 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
195 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
196 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME)) ,
197 '$birthday' => ((strlen($birthday)) ? '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>' : '')
200 call_hooks('atom_feed', $atom);
202 if(! count($items)) {
204 call_hooks('atom_feed_end', $atom);
206 $atom .= '</feed>' . "\r\n";
210 foreach($items as $item) {
212 // public feeds get html, our own nodes use bbcode
214 if($dfrn_id === '*') {
221 $atom .= atom_entry($item,$type,null,$owner,true);
224 call_hooks('atom_feed_end', $atom);
226 $atom .= '</feed>' . "\r\n";
232 function construct_verb($item) {
234 return $item['verb'];
235 return ACTIVITY_POST;
238 function construct_activity_object($item) {
240 if($item['object']) {
241 $o = '<as:object>' . "\r\n";
242 $r = @simplexml_load_string($item['object']);
244 $o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
246 $o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
248 $o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
250 if(substr($r->link,0,1) === '<')
253 $o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
256 $o .= '<content type="html" >' . xmlify(bbcode($r->content)) . '</content>' . "\r\n";
257 $o .= '</as:object>' . "\r\n";
264 function construct_activity_target($item) {
266 if($item['target']) {
267 $o = '<as:target>' . "\r\n";
268 $r = @simplexml_load_string($item['target']);
270 $o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
272 $o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
274 $o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
276 if(substr($r->link,0,1) === '<')
279 $o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
282 $o .= '<content type="html" >' . xmlify(bbcode($r->content)) . '</content>' . "\r\n";
283 $o .= '</as:target>' . "\r\n";
293 function get_atom_elements($feed,$item) {
295 require_once('library/HTMLPurifier.auto.php');
296 require_once('include/html2bbcode.php');
298 $best_photo = array();
302 $author = $item->get_author();
303 $res['author-name'] = unxmlify($author->get_name());
304 $res['author-link'] = unxmlify($author->get_link());
305 $res['uri'] = unxmlify($item->get_id());
306 $res['title'] = unxmlify($item->get_title());
307 $res['body'] = unxmlify($item->get_content());
310 // look for a photo. We should check media size and find the best one,
311 // but for now let's just find any author photo
313 $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author');
315 if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
316 $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
317 foreach($base as $link) {
318 if(! $res['author-avatar']) {
319 if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
320 $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
325 $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor');
327 if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'],ACTIVITY_OBJ_PERSON)) {
328 $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
329 if($base && count($base)) {
330 foreach($base as $link) {
331 if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
332 $res['author-link'] = unxmlify($link['attribs']['']['href']);
333 if(! $res['author-avatar']) {
334 if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo')
335 $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
341 // No photo/profile-link on the item - look at the feed level
343 if((! (x($res,'author-link'))) || (! (x($res,'author-avatar')))) {
344 $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author');
345 if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
346 $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
347 foreach($base as $link) {
348 if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
349 $res['author-link'] = unxmlify($link['attribs']['']['href']);
350 if(! $res['author-avatar']) {
351 if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
352 $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
357 $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject');
359 if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'],ACTIVITY_OBJ_PERSON)) {
360 $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
362 if($base && count($base)) {
363 foreach($base as $link) {
364 if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
365 $res['author-link'] = unxmlify($link['attribs']['']['href']);
366 if(! (x($res,'author-avatar'))) {
367 if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo')
368 $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
376 $maxlen = get_max_import_size();
377 if($maxlen && (strlen($res['body']) > $maxlen))
378 $res['body'] = substr($res['body'],0, $maxlen);
380 // It isn't certain at this point whether our content is plaintext or html and we'd be foolish to trust
381 // the content type. Our own network only emits text normally, though it might have been converted to
382 // html if we used a pubsubhubbub transport. But if we see even one html open tag in our text, we will
383 // have to assume it is all html and needs to be purified.
385 // It doesn't matter all that much security wise - because before this content is used anywhere, we are
386 // going to escape any tags we find regardless, but this lets us import a limited subset of html from
387 // the wild, by sanitising it and converting supported tags to bbcode before we rip out any remaining
391 if(strpos($res['body'],'<')) {
393 $res['body'] = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
394 '[youtube]$1[/youtube]', $res['body']);
396 $config = HTMLPurifier_Config::createDefault();
397 $config->set('Cache.DefinitionImpl', null);
399 // we shouldn't need a whitelist, because the bbcode converter
400 // will strip out any unsupported tags.
401 // $config->set('HTML.Allowed', 'p,b,a[href],i');
403 $purifier = new HTMLPurifier($config);
404 $res['body'] = $purifier->purify($res['body']);
408 $res['body'] = html2bbcode($res['body']);
411 $allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
412 if($allow && $allow[0]['data'] == 1)
413 $res['last-child'] = 1;
415 $res['last-child'] = 0;
417 $private = $item->get_item_tags(NAMESPACE_DFRN,'private');
418 if($private && $private[0]['data'] == 1)
423 $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
425 $res['created'] = unxmlify($rawcreated[0]['data']);
427 $rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location');
429 $res['location'] = unxmlify($rawlocation[0]['data']);
432 $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
434 $res['edited'] = unxmlify($rawcreated[0]['data']);
436 $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
437 if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
438 $res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']);
439 elseif($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data'])
440 $res['owner-name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']);
441 if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])
442 $res['owner-link'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']);
443 elseif($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data'])
444 $res['owner-link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']);
446 if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
447 $base = $rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
449 foreach($base as $link) {
450 if(! $res['owner-avatar']) {
451 if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
452 $res['owner-avatar'] = unxmlify($link['attribs']['']['href']);
457 $rawgeo = $item->get_item_tags(NAMESPACE_GEORSS,'point');
459 $res['coord'] = unxmlify($rawgeo[0]['data']);
462 $rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb');
464 // select between supported verbs
467 $res['verb'] = unxmlify($rawverb[0]['data']);
470 // translate OStatus unfollow to activity streams if it happened to get selected
472 if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow'))
473 $res['verb'] = ACTIVITY_UNFOLLOW;
477 $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
480 $res['object'] = '<object>' . "\n";
481 if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
482 $res['object-type'] = $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'];
483 $res['object'] .= '<type>' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n";
485 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'])
486 $res['object'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n";
487 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'])
488 $res['object'] .= '<link>' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n";
489 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'])
490 $res['object'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n";
491 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) {
492 $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data'];
494 $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
495 // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
496 $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
497 if(strpos($body,'<')) {
499 $body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
500 '[youtube]$1[/youtube]', $body);
502 $config = HTMLPurifier_Config::createDefault();
503 $config->set('Cache.DefinitionImpl', null);
505 $purifier = new HTMLPurifier($config);
506 $body = $purifier->purify($body);
509 $body = html2bbcode($body);
510 $res['object'] .= '<content>' . $body . '</content>' . "\n";
513 $res['object'] .= '</object>' . "\n";
516 $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'target');
519 $res['target'] = '<target>' . "\n";
520 if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
521 $res['target'] .= '<type>' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n";
523 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'])
524 $res['target'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n";
526 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'])
527 $res['target'] .= '<link>' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n";
528 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'])
529 $res['target'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n";
530 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) {
531 $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data'];
533 $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
534 // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
535 $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
536 if(strpos($body,'<')) {
538 $body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
539 '[youtube]$1[/youtube]', $body);
541 $config = HTMLPurifier_Config::createDefault();
542 $config->set('Cache.DefinitionImpl', null);
544 $purifier = new HTMLPurifier($config);
545 $body = $purifier->purify($body);
548 $body = html2bbcode($body);
549 $res['target'] .= '<content>' . $body . '</content>' . "\n";
552 $res['target'] .= '</target>' . "\n";
555 $arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
557 call_hooks('parse_atom', $arr);
562 function encode_rel_links($links) {
564 if(! ((is_array($links)) && (count($links))))
566 foreach($links as $link) {
568 if($link['attribs']['']['rel'])
569 $o .= 'rel="' . $link['attribs']['']['rel'] . '" ';
570 if($link['attribs']['']['type'])
571 $o .= 'type="' . $link['attribs']['']['type'] . '" ';
572 if($link['attribs']['']['href'])
573 $o .= 'type="' . $link['attribs']['']['href'] . '" ';
574 if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['width'])
575 $o .= 'media:width="' . $link['attribs'][NAMESPACE_MEDIA]['width'] . '" ';
576 if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['height'])
577 $o .= 'media:height="' . $link['attribs'][NAMESPACE_MEDIA]['height'] . '" ';
583 function item_store($arr) {
586 $arr['gravity'] = intval($arr['gravity']);
587 elseif($arr['parent-uri'] == $arr['uri'])
589 elseif(activity_match($arr['verb'],ACTIVITY_POST))
592 $arr['gravity'] = 6; // extensible catchall
595 $arr['type'] = 'remote';
596 $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
597 $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
598 $arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : '');
599 $arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
600 $arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : '');
601 $arr['owner-name'] = ((x($arr,'owner-name')) ? notags(trim($arr['owner-name'])) : '');
602 $arr['owner-link'] = ((x($arr,'owner-link')) ? notags(trim($arr['owner-link'])) : '');
603 $arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
604 $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
605 $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
606 $arr['changed'] = datetime_convert();
607 $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
608 $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
609 $arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : '');
610 $arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
611 $arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
613 $arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : '');
614 $arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : '');
615 $arr['object-type'] = ((x($arr,'object-type')) ? notags(trim($arr['object-type'])) : '');
616 $arr['object'] = ((x($arr,'object')) ? trim($arr['object']) : '');
617 $arr['target-type'] = ((x($arr,'target-type')) ? notags(trim($arr['target-type'])) : '');
618 $arr['target'] = ((x($arr,'target')) ? trim($arr['target']) : '');
619 $arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : '');
620 $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : '');
621 $arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : '');
622 $arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
623 $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0 );
624 $arr['body'] = ((x($arr,'body')) ? escape_tags(trim($arr['body'])) : '');
626 // The content body has been through a lot of filtering and transport escaping by now.
627 // We don't want to skip any filters, however a side effect of all this filtering
628 // is that ampersands and <> may have been double encoded, depending on which filter chain
629 // they came through.
631 $arr['body'] = str_replace(
632 array('&amp;','&gt;','&lt;'),
633 array('&' ,'>' ,'<'),
639 if($arr['parent-uri'] === $arr['uri']) {
641 $allow_cid = $arr['allow_cid'];
642 $allow_gid = $arr['allow_gid'];
643 $deny_cid = $arr['deny_cid'];
644 $deny_gid = $arr['deny_gid'];
648 // find the parent and snarf the item id and ACL's
650 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
651 dbesc($arr['parent-uri']),
657 // is the new message multi-level threaded?
658 // even though we don't support it now, preserve the info
659 // and re-attach to the conversation parent.
661 if($r[0]['uri'] != $r[0]['parent-uri']) {
662 $arr['thr-parent'] = $arr['parent-uri'];
663 $arr['parent-uri'] = $r[0]['parent-uri'];
666 $parent_id = $r[0]['id'];
667 $allow_cid = $r[0]['allow_cid'];
668 $allow_gid = $r[0]['allow_gid'];
669 $deny_cid = $r[0]['deny_cid'];
670 $deny_gid = $r[0]['deny_gid'];
673 logger('item_store: item parent was not found - ignoring item');
678 call_hooks('post_remote',$arr);
682 logger('item_store: ' . print_r($arr,true), LOGGER_DATA);
684 $r = dbq("INSERT INTO `item` (`"
685 . implode("`, `", array_keys($arr))
687 . implode("', '", array_values($arr))
690 // find the item we just created
692 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
693 $arr['uri'], // already dbesc'd
697 $current_post = $r[0]['id'];
698 logger('item_store: created item ' . $current_post);
701 logger('item_store: could not locate created item');
705 if($arr['parent-uri'] === $arr['uri'])
706 $parent_id = $current_post;
708 if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
711 $private = $arr['private'];
713 // Set parent id - and also make sure to inherit the parent's ACL's.
715 $r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
716 `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d WHERE `id` = %d LIMIT 1",
723 intval($current_post)
726 return $current_post;
729 function get_item_contact($item,$contacts) {
730 if(! count($contacts) || (! is_array($item)))
732 foreach($contacts as $contact) {
733 if($contact['id'] == $item['contact-id']) {
742 function dfrn_deliver($owner,$contact,$atom) {
746 if((! strlen($contact['dfrn-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
749 $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
751 if($contact['duplex'] && $contact['dfrn-id'])
752 $idtosend = '0:' . $orig_id;
753 if($contact['duplex'] && $contact['issued-id'])
754 $idtosend = '1:' . $orig_id;
756 $rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0);
758 $rino_enable = get_config('system','rino_encrypt');
763 $url = $contact['notify'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
765 logger('dfrn_deliver: ' . $url);
767 $xml = fetch_url($url);
769 $curl_stat = $a->get_curl_code();
771 return(-1); // timed out
773 logger('dfrn_deliver: ' . $xml);
778 $res = simplexml_load_string($xml);
780 if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
781 return (($res->status) ? $res->status : 3);
784 $sent_dfrn_id = hex2bin($res->dfrn_id);
785 $challenge = hex2bin($res->challenge);
786 $rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
791 if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
792 openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
793 openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
796 openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
797 openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']);
800 $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
802 if(strpos($final_dfrn_id,':') == 1)
803 $final_dfrn_id = substr($final_dfrn_id,2);
805 if($final_dfrn_id != $orig_id) {
806 logger('dfrn_deliver: wrong dfrn_id.');
807 // did not decode properly - cannot trust this site
811 $postvars['dfrn_id'] = $idtosend;
812 $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
814 if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) {
815 $postvars['data'] = $atom;
817 elseif($owner['page-flags'] == PAGE_COMMUNITY) {
818 $postvars['data'] = $atom;
821 $postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
824 if($rino && $rino_allowed) {
825 $key = substr(random_string(),0,16);
826 $data = bin2hex(aes_encrypt($postvars['data'],$key));
827 $postvars['data'] = $data;
828 logger('rino: sent key = ' . $key);
830 if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
831 openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
834 openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
837 logger('md5 rawkey ' . md5($postvars['key']));
839 $postvars['key'] = bin2hex($postvars['key']);
842 logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA);
844 $xml = post_url($contact['notify'],$postvars);
846 logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA);
848 $curl_stat = $a->get_curl_code();
849 if((! $curl_stat) || (! strlen($xml)))
850 return(-1); // timed out
852 $res = simplexml_load_string($xml);
861 * consume_feed - process atom feed and update anything/everything we might need to update
863 * $xml = the (atom) feed to consume - no RSS spoken here, it might partially work since simplepie
864 * handles both, but we don't claim it will work well, and are reasonably certain it won't.
865 * $importer = the contact_record (joined to user_record) of the local user who owns this relationship.
866 * It is this person's stuff that is going to be updated.
867 * $contact = the person who is sending us stuff. If not set, we MAY be processing a "follow" activity
868 * from an external network and MAY create an appropriate contact record. Otherwise, we MUST
869 * have a contact record.
870 * $hub = should we find a hub declation in the feed, pass it back to our calling process, who might (or
871 * might not) try and subscribe to it.
875 function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) {
877 require_once('simplepie/simplepie.inc');
879 $feed = new SimplePie();
880 $feed->set_raw_data($xml);
882 $feed->enable_order_by_date(true);
884 $feed->enable_order_by_date(false);
887 // Check at the feed level for updated contact name and/or photo
891 $photo_timestamp = '';
895 $hubs = $feed->get_links('hub');
898 $hub = implode(',', $hubs);
900 $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
902 $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
903 if($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) {
904 $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated'];
905 $new_name = $elems['name'][0]['data'];
907 if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo') && ($elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated'])) {
908 $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']);
909 $photo_url = $elems['link'][0]['attribs']['']['href'];
913 if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) {
914 logger('Consume feed: Updating photo for ' . $contact['name']);
915 require_once("Photo.php");
916 $photo_failure = false;
919 $r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1",
920 intval($contact['id']),
921 intval($contact['uid'])
924 $resource_id = $r[0]['resource-id'];
928 $resource_id = photo_new_resource();
931 $img_str = fetch_url($photo_url,true);
932 $img = new Photo($img_str);
933 if($img->is_valid()) {
935 q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `contact-id` = %d AND `uid` = %d",
937 intval($contact['id']),
938 intval($contact['uid'])
942 $img->scaleImageSquare(175);
944 $hash = $resource_id;
945 $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 4);
947 $img->scaleImage(80);
948 $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 5);
950 $img->scaleImage(48);
951 $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 6);
955 q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s'
956 WHERE `uid` = %d AND `id` = %d LIMIT 1",
957 dbesc(datetime_convert()),
958 dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.jpg'),
959 dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.jpg'),
960 dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.jpg'),
961 intval($contact['uid']),
962 intval($contact['id'])
967 if((is_array($contact)) && ($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name-date'])) {
968 q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
969 dbesc(notags(trim($new_name))),
970 dbesc(datetime_convert()),
971 intval($contact['uid']),
972 intval($contact['id'])
976 // Now process the feed
977 if($feed->get_item_quantity()) {
979 // in inverse date order
981 $items = array_reverse($feed->get_items());
983 $items = $feed->get_items();
985 foreach($items as $item) {
989 $rawdelete = $item->get_item_tags( NAMESPACE_TOMB, 'deleted-entry');
990 if(isset($rawdelete[0]['attribs']['']['ref'])) {
991 $uri = $rawthread[0]['attribs']['']['ref'];
993 if(isset($rawdelete[0]['attribs']['']['when'])) {
994 $when = $rawthread[0]['attribs']['']['when'];
995 $when = datetime_convert('UTC','UTC', $when, 'Y-m-d H:i:s');
998 $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
1000 if($deleted && is_array($contact)) {
1001 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
1003 intval($importer['uid']),
1004 intval($contact['id'])
1008 if($item['uri'] == $item['parent-uri']) {
1009 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
1010 `body` = '', `title` = ''
1011 WHERE `parent-uri` = '%s' AND `uid` = %d",
1013 dbesc(datetime_convert()),
1014 dbesc($item['uri']),
1015 intval($importer['uid'])
1019 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
1020 `body` = '', `title` = ''
1021 WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1023 dbesc(datetime_convert()),
1025 intval($importer['uid'])
1027 if($item['last-child']) {
1028 // ensure that last-child is set in case the comment that had it just got wiped.
1029 $q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
1030 dbesc(datetime_convert()),
1031 dbesc($item['parent-uri']),
1032 intval($item['uid'])
1034 // who is the last child now?
1035 $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d
1036 ORDER BY `created` DESC LIMIT 1",
1037 dbesc($item['parent-uri']),
1038 intval($importer['uid'])
1041 q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
1053 $item_id = $item->get_id();
1054 $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to');
1055 if(isset($rawthread[0]['attribs']['']['ref'])) {
1057 $parent_uri = $rawthread[0]['attribs']['']['ref'];
1061 if(($is_reply) && is_array($contact)) {
1063 // Have we seen it? If not, import it.
1065 $item_id = $item->get_id();
1067 $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1069 intval($importer['uid'])
1071 // FIXME update content if 'updated' changes
1073 $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
1074 if(($allow) && ($allow[0]['data'] != $r[0]['last-child'])) {
1075 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
1076 dbesc(datetime_convert()),
1078 intval($importer['uid'])
1080 $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1081 intval($allow[0]['data']),
1082 dbesc(datetime_convert()),
1084 intval($importer['uid'])
1089 $datarray = get_atom_elements($feed,$item);
1090 if($contact['network'] === 'stat') {
1091 if(strlen($datarray['title']))
1092 unset($datarray['title']);
1093 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
1094 dbesc(datetime_convert()),
1096 intval($importer['uid'])
1098 $datarray['last-child'] = 1;
1100 $datarray['parent-uri'] = $parent_uri;
1101 $datarray['uid'] = $importer['uid'];
1102 $datarray['contact-id'] = $contact['id'];
1103 if((activity_match($datarray['verb'],ACTIVITY_LIKE)) || (activity_match($datarray['verb'],ACTIVITY_DISLIKE))) {
1104 $datarray['type'] = 'activity';
1105 $datarray['gravity'] = GRAVITY_LIKE;
1108 $r = item_store($datarray);
1113 // Head post of a conversation. Have we seen it? If not, import it.
1115 $item_id = $item->get_id();
1116 $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1118 intval($importer['uid'])
1121 $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
1122 if($allow && $allow[0]['data'] != $r[0]['last-child']) {
1123 $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1124 intval($allow[0]['data']),
1125 dbesc(datetime_convert()),
1127 intval($importer['uid'])
1132 $datarray = get_atom_elements($feed,$item);
1134 if(activity_match($datarray['verb'],ACTIVITY_FOLLOW)) {
1135 logger('consume-feed: New follower');
1136 new_follower($importer,$contact,$datarray,$item);
1139 if(activity_match($datarray['verb'],ACTIVITY_UNFOLLOW)) {
1140 lose_follower($importer,$contact,$datarray,$item);
1143 if(! is_array($contact))
1146 if($contact['network'] === 'stat') {
1147 if(strlen($datarray['title']))
1148 unset($datarray['title']);
1149 $datarray['last-child'] = 1;
1152 $datarray['parent-uri'] = $item_id;
1153 $datarray['uid'] = $importer['uid'];
1154 $datarray['contact-id'] = $contact['id'];
1155 $r = item_store($datarray);
1164 function new_follower($importer,$contact,$datarray,$item) {
1165 $url = notags(trim($datarray['author-link']));
1166 $name = notags(trim($datarray['author-name']));
1167 $photo = notags(trim($datarray['author-avatar']));
1169 $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
1170 if($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'])
1171 $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
1173 if(is_array($contact)) {
1174 if($contact['network'] == 'stat' && $contact['rel'] == REL_FAN) {
1175 $r = q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
1177 intval($contact['id']),
1178 intval($importer['uid'])
1182 // send email notification to owner?
1186 // create contact record - set to readonly
1188 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `photo`, `network`, `rel`,
1189 `blocked`, `readonly`, `pending` )
1190 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1 ) ",
1191 intval($importer['uid']),
1192 dbesc(datetime_convert()),
1200 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 AND `rel` = %d LIMIT 1",
1201 intval($importer['uid']),
1206 $contact_record = $r[0];
1208 // create notification
1209 $hash = random_string();
1211 if(is_array($contact_record)) {
1212 $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `hash`, `datetime`)
1213 VALUES ( %d, %d, 0, 0, '%s', '%s' )",
1214 intval($importer['uid']),
1215 intval($contact_record['id']),
1217 dbesc(datetime_convert())
1220 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
1221 intval($importer['uid'])
1225 if(($r[0]['notify-flags'] & NOTIFY_INTRO) && ($r[0]['page-flags'] == PAGE_NORMAL)) {
1226 $email_tpl = load_view_file('view/follow_notify_eml.tpl');
1227 $email = replace_macros($email_tpl, array(
1228 '$requestor' => ((strlen($name)) ? $name : t('[Name Withheld]')),
1230 '$myname' => $r[0]['username'],
1231 '$siteurl' => $a->get_baseurl(),
1232 '$sitename' => $a->config['sitename']
1234 $res = mail($r[0]['email'],
1235 t("You have a new follower at ") . $a->config['sitename'],
1237 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
1244 function lose_follower($importer,$contact,$datarray,$item) {
1246 if(($contact['rel'] == REL_BUD) || ($contact['rel'] == REL_FAN)) {
1247 q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d LIMIT 1",
1249 intval($contact['id'])
1253 contact_remove($contact['id']);
1258 function subscribe_to_hub($url,$importer,$contact) {
1260 if(is_array($importer)) {
1261 $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
1262 intval($importer['uid'])
1268 $push_url = get_config('system','url') . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
1270 // Use a single verify token, even if multiple hubs
1272 $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
1274 $params= 'hub.mode=subscribe&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
1276 logger('subscribe_to_hub: subscribing ' . $contact['name'] . ' to hub ' . $url . ' with verifier ' . $verify_token);
1278 if(! strlen($contact['hub-verify'])) {
1279 $r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d LIMIT 1",
1280 dbesc($verify_token),
1281 intval($contact['id'])
1285 post_url($url,$params);
1291 function atom_author($tag,$name,$uri,$h,$w,$photo) {
1295 $name = xmlify($name);
1296 $uri = xmlify($uri);
1299 $photo = xmlify($photo);
1303 $o .= "<name>$name</name>\r\n";
1304 $o .= "<uri>$uri</uri>\r\n";
1305 $o .= '<link rel="photo" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
1306 $o .= '<link rel="avatar" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
1308 call_hooks('atom_author', $o);
1310 $o .= "</$tag>\r\n";
1314 function atom_entry($item,$type,$author,$owner,$comment = false) {
1316 if($item['deleted'])
1317 return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '" />' . "\r\n";
1321 $o = "\r\n\r\n<entry>\r\n";
1323 if(is_array($author))
1324 $o .= atom_author('author',$author['name'],$author['url'],80,80,$author['thumb']);
1326 $o .= atom_author('author',$item['name'],$item['url'],80,80,$item['thumb']);
1327 if(strlen($item['owner-name']))
1328 $o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']);
1330 if($item['parent'] != $item['id'])
1331 $o .= '<thr:in-reply-to ref="' . xmlify($item['parent-uri']) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
1333 $o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n";
1334 $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
1335 $o .= '<published>' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '</published>' . "\r\n";
1336 $o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n";
1337 $o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($item['body']) : $item['body']) . '</content>' . "\r\n";
1338 $o .= '<link rel="alternate" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
1340 $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
1342 if($item['location']) {
1343 $o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n";
1344 $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n";
1348 $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n";
1350 if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid']))
1351 $o .= '<dfrn:private>1</dfrn:private>' . "\r\n";
1353 $verb = construct_verb($item);
1354 $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
1355 $actobj = construct_activity_object($item);
1358 $actarg = construct_activity_target($item);
1362 $mentioned = get_mentions($item);
1366 call_hooks('atom_entry', $o);
1368 $o .= '</entry>' . "\r\n";