3 require_once('bbcode.php');
5 function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) {
8 // default permissions - anonymous user
17 if(strlen($owner_id) && ! intval($owner_id)) {
18 $r = q("SELECT `uid`, `nickname` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
22 $owner_id = $r[0]['uid'];
23 $owner_nick = $r[0]['nickname'];
27 $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
32 $owner['nickname'] = $owner_nick;
37 if($dfrn_id && $dfrn_id != '*') {
42 $sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id));
46 $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
47 $my_id = '1:' . $dfrn_id;
50 $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
51 $my_id = '0:' . $dfrn_id;
58 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `contact`.`uid` = %d $sql_extra LIMIT 1",
66 $groups = init_groups_visitor($contact['id']);
69 for($x = 0; $x < count($groups); $x ++)
70 $groups[$x] = '<' . intval($groups[$x]) . '>' ;
71 $gs = implode('|', $groups);
74 $gs = '<<>>' ; // Impossible to match
76 $sql_extra = sprintf("
77 AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
78 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
79 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
80 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s')
82 intval($contact['id']),
83 intval($contact['id']),
89 if($dfrn_id === '' || $dfrn_id === '*')
94 if(! strlen($last_update))
95 $last_update = 'now -30 days';
97 $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
99 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
100 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
101 `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
102 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
103 `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`
104 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
105 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
106 AND `item`.`wall` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
107 AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
109 ORDER BY `parent` %s, `created` ASC LIMIT 0, 300",
116 // Will check further below if this actually returned results.
117 // We will provide an empty feed in any case.
121 $feed_template = load_view_file('view/atom_feed.tpl');
125 $hub = get_config('system','huburl');
129 $hubs = explode(',', $hub);
131 foreach($hubs as $h) {
135 $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
140 $salmon = '<link rel="salmon" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
141 $salmon .= '<link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
142 $salmon .= '<link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify($a->get_baseurl() . '/salmon/' . $owner_nick) . '" />' . "\n" ;
145 $atom .= replace_macros($feed_template, array(
146 '$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner_nick),
147 '$feed_title' => xmlify($owner['name']),
148 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now' , ATOM_TIME)) ,
150 '$salmon' => $salmon,
151 '$name' => xmlify($owner['name']),
152 '$profile_page' => xmlify($owner['url']),
153 '$photo' => xmlify($owner['photo']),
154 '$thumb' => xmlify($owner['thumb']),
155 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
156 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
157 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME))
160 call_hooks('atom_feed', $atom);
162 if(! count($items)) {
164 call_hooks('atom_feed_end', $atom);
166 $atom .= '</feed>' . "\r\n";
170 foreach($items as $item) {
172 // public feeds get html, our own nodes use bbcode
174 if($dfrn_id === '*') {
181 $atom .= atom_entry($item,$type,null,$owner,true);
184 call_hooks('atom_feed_end', $atom);
186 $atom .= '</feed>' . "\r\n";
192 function construct_verb($item) {
194 return $item['verb'];
195 return ACTIVITY_POST;
198 function construct_activity_object($item) {
200 if($item['object']) {
201 $o = '<as:object>' . "\r\n";
202 $r = @simplexml_load_string($item['object']);
204 $o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
206 $o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
208 $o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
210 if(substr($r->link,0,1) === '<')
213 $o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
216 $o .= '<content type="html" >' . xmlify(bbcode($r->content)) . '</content>' . "\r\n";
217 $o .= '</as:object>' . "\r\n";
224 function construct_activity_target($item) {
226 if($item['target']) {
227 $o = '<as:target>' . "\r\n";
228 $r = @simplexml_load_string($item['target']);
230 $o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
232 $o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
234 $o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
236 if(substr($r->link,0,1) === '<')
239 $o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
242 $o .= '<content type="html" >' . xmlify(bbcode($r->content)) . '</content>' . "\r\n";
243 $o .= '</as:target>' . "\r\n";
253 function get_atom_elements($feed,$item) {
255 require_once('library/HTMLPurifier.auto.php');
256 require_once('include/html2bbcode.php');
258 $best_photo = array();
262 $author = $item->get_author();
263 $res['author-name'] = unxmlify($author->get_name());
264 $res['author-link'] = unxmlify($author->get_link());
265 $res['uri'] = unxmlify($item->get_id());
266 $res['title'] = unxmlify($item->get_title());
267 $res['body'] = unxmlify($item->get_content());
270 // look for a photo. We should check media size and find the best one,
271 // but for now let's just find any author photo
273 $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author');
275 if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
276 $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
277 foreach($base as $link) {
278 if(! $res['author-avatar']) {
279 if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
280 $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
285 $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor');
287 if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'],ACTIVITY_OBJ_PERSON)) {
288 $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
289 if($base && count($base)) {
290 foreach($base as $link) {
291 if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
292 $res['author-link'] = unxmlify($link['attribs']['']['href']);
293 if(! $res['author-avatar']) {
294 if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo')
295 $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
301 // No photo/profile-link on the item - look at the feed level
303 if((! (x($res,'author-link'))) || (! (x($res,'author-avatar')))) {
304 $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author');
305 if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
306 $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
307 foreach($base as $link) {
308 if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
309 $res['author-link'] = unxmlify($link['attribs']['']['href']);
310 if(! $res['author-avatar']) {
311 if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
312 $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
317 $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject');
319 if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'],ACTIVITY_OBJ_PERSON)) {
320 $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
322 if($base && count($base)) {
323 foreach($base as $link) {
324 if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
325 $res['author-link'] = unxmlify($link['attribs']['']['href']);
326 if(! (x($res,'author-avatar'))) {
327 if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo')
328 $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
336 $maxlen = get_max_import_size();
337 if($maxlen && (strlen($res['body']) > $maxlen))
338 $res['body'] = substr($res['body'],0, $maxlen);
340 // It isn't certain at this point whether our content is plaintext or html and we'd be foolish to trust
341 // the content type. Our own network only emits text normally, though it might have been converted to
342 // html if we used a pubsubhubbub transport. But if we see even one html open tag in our text, we will
343 // have to assume it is all html and needs to be purified.
345 // It doesn't matter all that much security wise - because before this content is used anywhere, we are
346 // going to escape any tags we find regardless, but this lets us import a limited subset of html from
347 // the wild, by sanitising it and converting supported tags to bbcode before we rip out any remaining
351 if(strpos($res['body'],'<')) {
353 $res['body'] = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
354 '[youtube]$1[/youtube]', $res['body']);
356 $config = HTMLPurifier_Config::createDefault();
357 $config->set('Cache.DefinitionImpl', null);
359 // we shouldn't need a whitelist, because the bbcode converter
360 // will strip out any unsupported tags.
361 // $config->set('HTML.Allowed', 'p,b,a[href],i');
363 $purifier = new HTMLPurifier($config);
364 $res['body'] = $purifier->purify($res['body']);
368 $res['body'] = html2bbcode($res['body']);
371 $allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
372 if($allow && $allow[0]['data'] == 1)
373 $res['last-child'] = 1;
375 $res['last-child'] = 0;
377 $private = $item->get_item_tags(NAMESPACE_DFRN,'private');
378 if($private && $private[0]['data'] == 1)
383 $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
385 $res['created'] = unxmlify($rawcreated[0]['data']);
387 $rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location');
389 $res['location'] = unxmlify($rawlocation[0]['data']);
392 $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
394 $res['edited'] = unxmlify($rawcreated[0]['data']);
396 $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
397 if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
398 $res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']);
399 elseif($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data'])
400 $res['owner-name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']);
401 if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])
402 $res['owner-link'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']);
403 elseif($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data'])
404 $res['owner-link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']);
406 if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
407 $base = $rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
409 foreach($base as $link) {
410 if(! $res['owner-avatar']) {
411 if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
412 $res['owner-avatar'] = unxmlify($link['attribs']['']['href']);
417 $rawgeo = $item->get_item_tags(NAMESPACE_GEORSS,'point');
419 $res['coord'] = unxmlify($rawgeo[0]['data']);
422 $rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb');
424 // select between supported verbs
427 $res['verb'] = unxmlify($rawverb[0]['data']);
430 // translate OStatus unfollow to activity streams if it happened to get selected
432 if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow'))
433 $res['verb'] = ACTIVITY_UNFOLLOW;
437 $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
440 $res['object'] = '<object>' . "\n";
441 if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
442 $res['object-type'] = $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'];
443 $res['object'] .= '<type>' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n";
445 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'])
446 $res['object'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n";
447 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'])
448 $res['object'] .= '<link>' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n";
449 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'])
450 $res['object'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n";
451 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) {
452 $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data'];
454 $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
455 // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
456 $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
457 if(strpos($body,'<')) {
459 $body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
460 '[youtube]$1[/youtube]', $body);
462 $config = HTMLPurifier_Config::createDefault();
463 $config->set('Cache.DefinitionImpl', null);
465 $purifier = new HTMLPurifier($config);
466 $body = $purifier->purify($body);
469 $body = html2bbcode($body);
470 $res['object'] .= '<content>' . $body . '</content>' . "\n";
473 $res['object'] .= '</object>' . "\n";
476 $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'target');
479 $res['target'] = '<target>' . "\n";
480 if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
481 $res['target'] .= '<type>' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n";
483 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'])
484 $res['target'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n";
486 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'])
487 $res['target'] .= '<link>' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n";
488 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'])
489 $res['target'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n";
490 if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) {
491 $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data'];
493 $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
494 // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
495 $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
496 if(strpos($body,'<')) {
498 $body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
499 '[youtube]$1[/youtube]', $body);
501 $config = HTMLPurifier_Config::createDefault();
502 $config->set('Cache.DefinitionImpl', null);
504 $purifier = new HTMLPurifier($config);
505 $body = $purifier->purify($body);
508 $body = html2bbcode($body);
509 $res['target'] .= '<content>' . $body . '</content>' . "\n";
512 $res['target'] .= '</target>' . "\n";
515 $arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
517 call_hooks('parse_atom', $arr);
522 function encode_rel_links($links) {
524 if(! ((is_array($links)) && (count($links))))
526 foreach($links as $link) {
528 if($link['attribs']['']['rel'])
529 $o .= 'rel="' . $link['attribs']['']['rel'] . '" ';
530 if($link['attribs']['']['type'])
531 $o .= 'type="' . $link['attribs']['']['type'] . '" ';
532 if($link['attribs']['']['href'])
533 $o .= 'type="' . $link['attribs']['']['href'] . '" ';
534 if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['width'])
535 $o .= 'media:width="' . $link['attribs'][NAMESPACE_MEDIA]['width'] . '" ';
536 if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['height'])
537 $o .= 'media:height="' . $link['attribs'][NAMESPACE_MEDIA]['height'] . '" ';
543 function item_store($arr) {
546 $arr['gravity'] = intval($arr['gravity']);
547 elseif($arr['parent-uri'] == $arr['uri'])
549 elseif(activity_match($arr['verb'],ACTIVITY_POST))
552 $arr['gravity'] = 6; // extensible catchall
555 $arr['type'] = 'remote';
556 $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
557 $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
558 $arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : '');
559 $arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
560 $arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : '');
561 $arr['owner-name'] = ((x($arr,'owner-name')) ? notags(trim($arr['owner-name'])) : '');
562 $arr['owner-link'] = ((x($arr,'owner-link')) ? notags(trim($arr['owner-link'])) : '');
563 $arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
564 $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
565 $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
566 $arr['changed'] = datetime_convert();
567 $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
568 $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
569 $arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : '');
570 $arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
571 $arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
573 $arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : '');
574 $arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : '');
575 $arr['object-type'] = ((x($arr,'object-type')) ? notags(trim($arr['object-type'])) : '');
576 $arr['object'] = ((x($arr,'object')) ? trim($arr['object']) : '');
577 $arr['target-type'] = ((x($arr,'target-type')) ? notags(trim($arr['target-type'])) : '');
578 $arr['target'] = ((x($arr,'target')) ? trim($arr['target']) : '');
579 $arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : '');
580 $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : '');
581 $arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : '');
582 $arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
583 $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0 );
584 $arr['body'] = ((x($arr,'body')) ? escape_tags(trim($arr['body'])) : '');
586 // The content body has been through a lot of filtering and transport escaping by now.
587 // We don't want to skip any filters, however a side effect of all this filtering
588 // is that ampersands and <> may have been double encoded, depending on which filter chain
589 // they came through.
591 $arr['body'] = str_replace(
592 array('&amp;','&gt;','&lt;'),
593 array('&' ,'>' ,'<'),
599 if($arr['parent-uri'] === $arr['uri']) {
601 $allow_cid = $arr['allow_cid'];
602 $allow_gid = $arr['allow_gid'];
603 $deny_cid = $arr['deny_cid'];
604 $deny_gid = $arr['deny_gid'];
608 // find the parent and snarf the item id and ACL's
610 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
611 dbesc($arr['parent-uri']),
617 // is the new message multi-level threaded?
618 // even though we don't support it now, preserve the info
619 // and re-attach to the conversation parent.
621 if($r[0]['uri'] != $r[0]['parent-uri']) {
622 $arr['thr-parent'] = $arr['parent-uri'];
623 $arr['parent-uri'] = $r[0]['parent-uri'];
626 $parent_id = $r[0]['id'];
627 $allow_cid = $r[0]['allow_cid'];
628 $allow_gid = $r[0]['allow_gid'];
629 $deny_cid = $r[0]['deny_cid'];
630 $deny_gid = $r[0]['deny_gid'];
633 logger('item_store: item parent was not found - ignoring item');
638 call_hooks('post_remote',$arr);
642 logger('item_store: ' . print_r($arr,true), LOGGER_DATA);
644 $r = dbq("INSERT INTO `item` (`"
645 . implode("`, `", array_keys($arr))
647 . implode("', '", array_values($arr))
650 // find the item we just created
652 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
653 $arr['uri'], // already dbesc'd
657 $current_post = $r[0]['id'];
658 logger('item_store: created item ' . $current_post);
661 logger('item_store: could not locate created item');
665 if($arr['parent-uri'] === $arr['uri'])
666 $parent_id = $current_post;
668 if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
671 $private = $arr['private'];
673 // Set parent id - and also make sure to inherit the parent's ACL's.
675 $r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
676 `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d WHERE `id` = %d LIMIT 1",
683 intval($current_post)
686 return $current_post;
689 function get_item_contact($item,$contacts) {
690 if(! count($contacts) || (! is_array($item)))
692 foreach($contacts as $contact) {
693 if($contact['id'] == $item['contact-id']) {
702 function dfrn_deliver($owner,$contact,$atom) {
706 if((! strlen($contact['dfrn-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
709 $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
711 if($contact['duplex'] && $contact['dfrn-id'])
712 $idtosend = '0:' . $orig_id;
713 if($contact['duplex'] && $contact['issued-id'])
714 $idtosend = '1:' . $orig_id;
716 $rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0);
718 $rino_enable = get_config('system','rino_encrypt');
723 $url = $contact['notify'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
725 logger('dfrn_deliver: ' . $url);
727 $xml = fetch_url($url);
729 $curl_stat = $a->get_curl_code();
731 return(-1); // timed out
733 logger('dfrn_deliver: ' . $xml);
738 $res = simplexml_load_string($xml);
740 if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
741 return (($res->status) ? $res->status : 3);
744 $sent_dfrn_id = hex2bin($res->dfrn_id);
745 $challenge = hex2bin($res->challenge);
746 $rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
751 if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
752 openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
753 openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
756 openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
757 openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']);
760 $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
762 if(strpos($final_dfrn_id,':') == 1)
763 $final_dfrn_id = substr($final_dfrn_id,2);
765 if($final_dfrn_id != $orig_id) {
766 logger('dfrn_deliver: wrong dfrn_id.');
767 // did not decode properly - cannot trust this site
771 $postvars['dfrn_id'] = $idtosend;
772 $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
774 if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) {
775 $postvars['data'] = $atom;
777 elseif($owner['page-flags'] == PAGE_COMMUNITY) {
778 $postvars['data'] = $atom;
781 $postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
784 if($rino && $rino_allowed) {
785 $key = substr(random_string(),0,16);
786 $data = bin2hex(aes_encrypt($postvars['data'],$key));
787 $postvars['data'] = $data;
788 logger('rino: sent key = ' . $key);
790 if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
791 openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
794 openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
797 logger('md5 rawkey ' . md5($postvars['key']));
799 $postvars['key'] = bin2hex($postvars['key']);
802 logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA);
804 $xml = post_url($contact['notify'],$postvars);
806 logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA);
808 $curl_stat = $a->get_curl_code();
809 if((! $curl_stat) || (! strlen($xml)))
810 return(-1); // timed out
812 $res = simplexml_load_string($xml);
821 * consume_feed - process atom feed and update anything/everything we might need to update
823 * $xml = the (atom) feed to consume - no RSS spoken here, it might partially work since simplepie
824 * handles both, but we don't claim it will work well, and are reasonably certain it won't.
825 * $importer = the contact_record (joined to user_record) of the local user who owns this relationship.
826 * It is this person's stuff that is going to be updated.
827 * $contact = the person who is sending us stuff. If not set, we MAY be processing a "follow" activity
828 * from an external network and MAY create an appropriate contact record. Otherwise, we MUST
829 * have a contact record.
830 * $hub = should we find a hub declation in the feed, pass it back to our calling process, who might (or
831 * might not) try and subscribe to it.
835 function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) {
837 require_once('simplepie/simplepie.inc');
839 $feed = new SimplePie();
840 $feed->set_raw_data($xml);
842 $feed->enable_order_by_date(true);
844 $feed->enable_order_by_date(false);
847 // Check at the feed level for updated contact name and/or photo
851 $photo_timestamp = '';
855 $hubs = $feed->get_links('hub');
858 $hub = implode(',', $hubs);
860 $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
862 $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
863 if($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) {
864 $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated'];
865 $new_name = $elems['name'][0]['data'];
867 if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo') && ($elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated'])) {
868 $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']);
869 $photo_url = $elems['link'][0]['attribs']['']['href'];
873 if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) {
874 logger('Consume feed: Updating photo for ' . $contact['name']);
875 require_once("Photo.php");
876 $photo_failure = false;
879 $r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1",
880 intval($contact['id']),
881 intval($contact['uid'])
884 $resource_id = $r[0]['resource-id'];
888 $resource_id = photo_new_resource();
891 $img_str = fetch_url($photo_url,true);
892 $img = new Photo($img_str);
893 if($img->is_valid()) {
895 q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `contact-id` = %d AND `uid` = %d",
897 intval($contact['id']),
898 intval($contact['uid'])
902 $img->scaleImageSquare(175);
904 $hash = $resource_id;
905 $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 4);
907 $img->scaleImage(80);
908 $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 5);
910 $img->scaleImage(48);
911 $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 6);
915 q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s'
916 WHERE `uid` = %d AND `id` = %d LIMIT 1",
917 dbesc(datetime_convert()),
918 dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.jpg'),
919 dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.jpg'),
920 dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.jpg'),
921 intval($contact['uid']),
922 intval($contact['id'])
927 if((is_array($contact)) && ($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name-date'])) {
928 q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
929 dbesc(notags(trim($new_name))),
930 dbesc(datetime_convert()),
931 intval($contact['uid']),
932 intval($contact['id'])
936 // Now process the feed
937 if($feed->get_item_quantity()) {
939 // in inverse date order
941 $items = array_reverse($feed->get_items());
943 $items = $feed->get_items();
945 foreach($items as $item) {
949 $rawdelete = $item->get_item_tags( NAMESPACE_TOMB, 'deleted-entry');
950 if(isset($rawdelete[0]['attribs']['']['ref'])) {
951 $uri = $rawthread[0]['attribs']['']['ref'];
953 if(isset($rawdelete[0]['attribs']['']['when'])) {
954 $when = $rawthread[0]['attribs']['']['when'];
955 $when = datetime_convert('UTC','UTC', $when, 'Y-m-d H:i:s');
958 $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
960 if($deleted && is_array($contact)) {
961 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
963 intval($importer['uid']),
964 intval($contact['id'])
968 if($item['uri'] == $item['parent-uri']) {
969 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
970 `body` = '', `title` = ''
971 WHERE `parent-uri` = '%s' AND `uid` = %d",
973 dbesc(datetime_convert()),
975 intval($importer['uid'])
979 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
980 `body` = '', `title` = ''
981 WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
983 dbesc(datetime_convert()),
985 intval($importer['uid'])
987 if($item['last-child']) {
988 // ensure that last-child is set in case the comment that had it just got wiped.
989 $q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
990 dbesc(datetime_convert()),
991 dbesc($item['parent-uri']),
994 // who is the last child now?
995 $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d
996 ORDER BY `created` DESC LIMIT 1",
997 dbesc($item['parent-uri']),
998 intval($importer['uid'])
1001 q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
1013 $item_id = $item->get_id();
1014 $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to');
1015 if(isset($rawthread[0]['attribs']['']['ref'])) {
1017 $parent_uri = $rawthread[0]['attribs']['']['ref'];
1021 if(($is_reply) && is_array($contact)) {
1023 // Have we seen it? If not, import it.
1025 $item_id = $item->get_id();
1027 $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1029 intval($importer['uid'])
1031 // FIXME update content if 'updated' changes
1033 $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
1034 if(($allow) && ($allow[0]['data'] != $r[0]['last-child'])) {
1035 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
1036 dbesc(datetime_convert()),
1038 intval($importer['uid'])
1040 $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1041 intval($allow[0]['data']),
1042 dbesc(datetime_convert()),
1044 intval($importer['uid'])
1049 $datarray = get_atom_elements($feed,$item);
1050 if($contact['network'] === 'stat') {
1051 if(strlen($datarray['title']))
1052 unset($datarray['title']);
1053 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
1054 dbesc(datetime_convert()),
1056 intval($importer['uid'])
1058 $datarray['last-child'] = 1;
1060 $datarray['parent-uri'] = $parent_uri;
1061 $datarray['uid'] = $importer['uid'];
1062 $datarray['contact-id'] = $contact['id'];
1063 if((activity_match($datarray['verb'],ACTIVITY_LIKE)) || (activity_match($datarray['verb'],ACTIVITY_DISLIKE))) {
1064 $datarray['type'] = 'activity';
1065 $datarray['gravity'] = GRAVITY_LIKE;
1068 $r = item_store($datarray);
1073 // Head post of a conversation. Have we seen it? If not, import it.
1075 $item_id = $item->get_id();
1076 $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1078 intval($importer['uid'])
1081 $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
1082 if($allow && $allow[0]['data'] != $r[0]['last-child']) {
1083 $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1084 intval($allow[0]['data']),
1085 dbesc(datetime_convert()),
1087 intval($importer['uid'])
1092 $datarray = get_atom_elements($feed,$item);
1094 if(activity_match($datarray['verb'],ACTIVITY_FOLLOW)) {
1095 logger('consume-feed: New follower');
1096 new_follower($importer,$contact,$datarray,$item);
1099 if(activity_match($datarray['verb'],ACTIVITY_UNFOLLOW)) {
1100 lose_follower($importer,$contact,$datarray,$item);
1103 if(! is_array($contact))
1106 if($contact['network'] === 'stat') {
1107 if(strlen($datarray['title']))
1108 unset($datarray['title']);
1109 $datarray['last-child'] = 1;
1112 $datarray['parent-uri'] = $item_id;
1113 $datarray['uid'] = $importer['uid'];
1114 $datarray['contact-id'] = $contact['id'];
1115 $r = item_store($datarray);
1124 function new_follower($importer,$contact,$datarray,$item) {
1125 $url = notags(trim($datarray['author-link']));
1126 $name = notags(trim($datarray['author-name']));
1127 $photo = notags(trim($datarray['author-avatar']));
1129 $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
1130 if($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'])
1131 $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
1133 if(is_array($contact)) {
1134 if($contact['network'] == 'stat' && $contact['rel'] == REL_FAN) {
1135 $r = q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
1137 intval($contact['id']),
1138 intval($importer['uid'])
1142 // send email notification to owner?
1146 // create contact record - set to readonly
1148 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `photo`, `network`, `rel`,
1149 `blocked`, `readonly`, `pending` )
1150 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1 ) ",
1151 intval($importer['uid']),
1152 dbesc(datetime_convert()),
1160 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 AND `rel` = %d LIMIT 1",
1161 intval($importer['uid']),
1166 $contact_record = $r[0];
1168 // create notification
1169 $hash = random_string();
1171 if(is_array($contact_record)) {
1172 $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `hash`, `datetime`)
1173 VALUES ( %d, %d, 0, 0, '%s', '%s' )",
1174 intval($importer['uid']),
1175 intval($contact_record['id']),
1177 dbesc(datetime_convert())
1180 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
1181 intval($importer['uid'])
1185 if(($r[0]['notify-flags'] & NOTIFY_INTRO) && ($r[0]['page-flags'] == PAGE_NORMAL)) {
1186 $email_tpl = load_view_file('view/follow_notify_eml.tpl');
1187 $email = replace_macros($email_tpl, array(
1188 '$requestor' => ((strlen($name)) ? $name : t('[Name Withheld]')),
1190 '$myname' => $r[0]['username'],
1191 '$siteurl' => $a->get_baseurl(),
1192 '$sitename' => $a->config['sitename']
1194 $res = mail($r[0]['email'],
1195 t("You have a new follower at ") . $a->config['sitename'],
1197 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
1204 function lose_follower($importer,$contact,$datarray,$item) {
1206 if(($contact['rel'] == REL_BUD) || ($contact['rel'] == REL_FAN)) {
1207 q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d LIMIT 1",
1209 intval($contact['id'])
1213 contact_remove($contact['id']);
1218 function subscribe_to_hub($url,$importer,$contact) {
1220 if(is_array($importer)) {
1221 $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
1222 intval($importer['uid'])
1228 $push_url = get_config('system','url') . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
1230 // Use a single verify token, even if multiple hubs
1232 $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
1234 $params= 'hub.mode=subscribe&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
1236 logger('subscribe_to_hub: subscribing ' . $contact['name'] . ' to hub ' . $url . ' with verifier ' . $verify_token);
1238 if(! strlen($contact['hub-verify'])) {
1239 $r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d LIMIT 1",
1240 dbesc($verify_token),
1241 intval($contact['id'])
1245 post_url($url,$params);
1251 function atom_author($tag,$name,$uri,$h,$w,$photo) {
1255 $name = xmlify($name);
1256 $uri = xmlify($uri);
1259 $photo = xmlify($photo);
1263 $o .= "<name>$name</name>\r\n";
1264 $o .= "<uri>$uri</uri>\r\n";
1265 $o .= '<link rel="photo" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
1266 $o .= '<link rel="avatar" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
1268 call_hooks('atom_author', $o);
1270 $o .= "</$tag>\r\n";
1274 function atom_entry($item,$type,$author,$owner,$comment = false) {
1276 if($item['deleted'])
1277 return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '" />' . "\r\n";
1281 $o = "\r\n\r\n<entry>\r\n";
1283 if(is_array($author))
1284 $o .= atom_author('author',$author['name'],$author['url'],80,80,$author['thumb']);
1286 $o .= atom_author('author',$item['name'],$item['url'],80,80,$item['thumb']);
1287 if(strlen($item['owner-name']))
1288 $o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']);
1290 if($item['parent'] != $item['id'])
1291 $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";
1293 $o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n";
1294 $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
1295 $o .= '<published>' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '</published>' . "\r\n";
1296 $o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n";
1297 $o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($item['body']) : $item['body']) . '</content>' . "\r\n";
1298 $o .= '<link rel="alternate" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
1300 $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
1302 if($item['location']) {
1303 $o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n";
1304 $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n";
1308 $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n";
1310 if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid']))
1311 $o .= '<dfrn:private>1</dfrn:private>' . "\r\n";
1313 $verb = construct_verb($item);
1314 $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
1315 $actobj = construct_activity_object($item);
1318 $actarg = construct_activity_target($item);
1322 $mentioned = get_mentions($item);
1326 call_hooks('atom_entry', $o);
1328 $o .= '</entry>' . "\r\n";