friendica/include/items.php

1930 lines
62 KiB
PHP
Raw Normal View History

2010-07-18 15:02:55 +02:00
<?php
2010-09-17 12:10:19 +02:00
require_once('bbcode.php');
require_once('oembed.php');
require_once('include/salmon.php');
2010-07-18 15:02:55 +02:00
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
2010-09-09 05:14:17 +02:00
2010-07-18 15:02:55 +02:00
// default permissions - anonymous user
2011-02-08 02:06:04 +01:00
if(! strlen($owner_nick))
killme();
$sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
2010-07-19 05:49:10 +02:00
2011-02-08 02:06:04 +01:00
$r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone`
FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE `contact`.`self` = 1 AND `user`.`nickname` = '%s' LIMIT 1",
dbesc($owner_nick)
2010-07-18 15:02:55 +02:00
);
2011-02-08 02:06:04 +01:00
if(! count($r))
2010-07-18 15:02:55 +02:00
killme();
2011-02-08 02:06:04 +01:00
$owner = $r[0];
$owner_id = $owner['user_uid'];
$owner_nick = $owner['nickname'];
$birthday = feed_birthday($owner_id,$owner['timezone']);
2011-02-08 02:06:04 +01:00
if(strlen($dfrn_id)) {
2010-09-17 12:10:19 +02:00
$sql_extra = '';
switch($direction) {
case (-1):
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id));
$my_id = $dfrn_id;
break;
case 0:
$sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
$my_id = '1:' . $dfrn_id;
break;
case 1:
$sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
$my_id = '0:' . $dfrn_id;
break;
default:
return false;
break; // NOTREACHED
}
2010-07-18 15:02:55 +02:00
2010-09-17 12:10:19 +02:00
$r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `contact`.`uid` = %d $sql_extra LIMIT 1",
2010-09-10 04:48:08 +02:00
intval($owner_id)
2010-07-18 15:02:55 +02:00
);
2010-09-17 12:10:19 +02:00
2010-07-18 15:02:55 +02:00
if(! count($r))
2011-02-08 02:06:04 +01:00
killme();
2010-07-18 15:02:55 +02:00
$contact = $r[0];
$groups = init_groups_visitor($contact['id']);
if(count($groups)) {
2010-08-03 04:06:36 +02:00
for($x = 0; $x < count($groups); $x ++)
$groups[$x] = '<' . intval($groups[$x]) . '>' ;
$gs = implode('|', $groups);
}
else
$gs = '<<>>' ; // Impossible to match
2010-09-09 05:14:17 +02:00
$sql_extra = sprintf("
AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s')
",
2010-07-19 05:49:10 +02:00
intval($contact['id']),
intval($contact['id']),
2010-07-18 15:02:55 +02:00
dbesc($gs),
dbesc($gs)
);
}
2010-09-27 02:24:20 +02:00
if($dfrn_id === '' || $dfrn_id === '*')
2010-09-10 10:45:58 +02:00
$sort = 'DESC';
else
$sort = 'ASC';
2010-07-18 15:02:55 +02:00
if(! strlen($last_update))
2010-11-02 01:56:36 +01:00
$last_update = 'now -30 days';
2010-07-18 15:02:55 +02:00
$check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`,
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
2010-07-18 15:02:55 +02:00
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
2011-02-06 11:33:02 +01:00
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`parent` != 0
2010-09-17 12:10:19 +02:00
AND `item`.`wall` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
2010-08-23 05:57:20 +02:00
AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
2010-07-18 15:02:55 +02:00
$sql_extra
2010-09-10 10:45:58 +02:00
ORDER BY `parent` %s, `created` ASC LIMIT 0, 300",
2010-07-18 15:02:55 +02:00
intval($owner_id),
2010-08-23 05:57:20 +02:00
dbesc($check_date),
2010-09-10 10:45:58 +02:00
dbesc($check_date),
dbesc($sort)
2010-07-18 15:02:55 +02:00
);
// Will check further below if this actually returned results.
2011-02-08 02:06:04 +01:00
// We will provide an empty feed if that is the case.
2010-07-18 15:02:55 +02:00
$items = $r;
2011-05-11 13:37:13 +02:00
$feed_template = get_markup_template('atom_feed.tpl');
2010-07-18 15:02:55 +02:00
$atom = '';
2011-02-08 02:06:04 +01:00
$hubxml = feed_hublinks();
2011-02-08 02:06:04 +01:00
$salmon = feed_salmonlinks($owner_nick);
2010-07-18 15:02:55 +02:00
$atom .= replace_macros($feed_template, array(
2011-01-14 11:04:09 +01:00
'$version' => xmlify(FRIENDIKA_VERSION),
2010-10-02 12:38:53 +02:00
'$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner_nick),
'$feed_title' => xmlify($owner['name']),
2010-11-01 00:38:22 +01:00
'$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now' , ATOM_TIME)) ,
2010-10-02 12:38:53 +02:00
'$hub' => $hubxml,
2010-10-07 04:46:44 +02:00
'$salmon' => $salmon,
2010-10-02 12:38:53 +02:00
'$name' => xmlify($owner['name']),
'$profile_page' => xmlify($owner['url']),
'$photo' => xmlify($owner['photo']),
'$thumb' => xmlify($owner['thumb']),
'$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
'$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
'$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME)) ,
'$birthday' => ((strlen($birthday)) ? '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>' : '')
2010-07-18 15:02:55 +02:00
));
2010-12-25 03:32:23 +01:00
call_hooks('atom_feed', $atom);
if(! count($items)) {
2010-12-25 03:32:23 +01:00
call_hooks('atom_feed_end', $atom);
$atom .= '</feed>' . "\r\n";
return $atom;
}
2010-07-18 15:02:55 +02:00
foreach($items as $item) {
2010-09-09 05:14:17 +02:00
// public feeds get html, our own nodes use bbcode
2011-02-08 02:06:04 +01:00
if($dfrn_id === '') {
2010-09-09 05:14:17 +02:00
$type = 'html';
}
else {
$type = 'text';
}
2010-11-02 01:56:36 +01:00
$atom .= atom_entry($item,$type,null,$owner,true);
2010-07-18 15:02:55 +02:00
}
2010-12-25 03:32:23 +01:00
call_hooks('atom_feed_end', $atom);
$atom .= '</feed>' . "\r\n";
2010-07-18 15:02:55 +02:00
return $atom;
2010-09-09 05:14:17 +02:00
}
function construct_verb($item) {
if($item['verb'])
return $item['verb'];
return ACTIVITY_POST;
}
function construct_activity_object($item) {
2010-09-09 05:14:17 +02:00
2010-09-17 12:10:19 +02:00
if($item['object']) {
$o = '<as:object>' . "\r\n";
$r = parse_xml_string($item['object'],false);
if(! $r)
return '';
2010-09-17 12:10:19 +02:00
if($r->type)
$o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
2010-09-17 12:10:19 +02:00
if($r->id)
$o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
2010-11-05 04:47:44 +01:00
if($r->title)
$o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
if($r->link) {
if(substr($r->link,0,1) === '<') {
// patch up some facebook "like" activity objects that got stored incorrectly
// for a couple of months prior to 9-Jun-2011 and generated bad XML.
// we can probably remove this hack here and in the following function in a few months time.
if(strstr($r->link,'&') && (! strstr($r->link,'&amp;')))
$r->link = str_replace('&','&amp;', $r->link);
$r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link);
2010-11-05 04:47:44 +01:00
$o .= $r->link;
}
else
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
}
2010-09-17 12:10:19 +02:00
if($r->content)
$o .= '<content type="html" >' . xmlify(bbcode($r->content)) . '</content>' . "\r\n";
2010-09-17 12:10:19 +02:00
$o .= '</as:object>' . "\r\n";
return $o;
2010-09-09 05:14:17 +02:00
}
2010-09-17 12:10:19 +02:00
2010-09-09 05:14:17 +02:00
return '';
2010-07-19 05:49:10 +02:00
}
function construct_activity_target($item) {
if($item['target']) {
$o = '<as:target>' . "\r\n";
$r = parse_xml_string($item['target'],false);
if(! $r)
return '';
if($r->type)
$o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
if($r->id)
$o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
2010-11-05 04:47:44 +01:00
if($r->title)
$o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
if($r->link) {
if(substr($r->link,0,1) === '<') {
if(strstr($r->link,'&') && (! strstr($r->link,'&amp;')))
$r->link = str_replace('&','&amp;', $r->link);
$r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link);
2010-11-05 04:47:44 +01:00
$o .= $r->link;
}
else
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
}
if($r->content)
$o .= '<content type="html" >' . xmlify(bbcode($r->content)) . '</content>' . "\r\n";
$o .= '</as:target>' . "\r\n";
return $o;
}
return '';
}
2010-07-19 05:49:10 +02:00
function get_atom_elements($feed,$item) {
2010-07-19 05:49:10 +02:00
2010-09-09 05:14:17 +02:00
require_once('library/HTMLPurifier.auto.php');
require_once('include/html2bbcode.php');
$best_photo = array();
2010-07-19 05:49:10 +02:00
$res = array();
2010-09-09 05:14:17 +02:00
2010-07-19 05:49:10 +02:00
$author = $item->get_author();
2011-04-05 04:36:18 +02:00
if($author) {
$res['author-name'] = unxmlify($author->get_name());
$res['author-link'] = unxmlify($author->get_link());
}
else {
$res['author-name'] = unxmlify($feed->get_title());
$res['author-link'] = unxmlify($feed->get_permalink());
}
2010-07-19 08:23:18 +02:00
$res['uri'] = unxmlify($item->get_id());
2010-07-19 05:49:10 +02:00
$res['title'] = unxmlify($item->get_title());
$res['body'] = unxmlify($item->get_content());
$res['plink'] = unxmlify($item->get_link(0));
// look for a photo. We should check media size and find the best one,
// but for now let's just find any author photo
$rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author');
if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
$base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
foreach($base as $link) {
if(! $res['author-avatar']) {
if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
}
$rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor');
if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'],ACTIVITY_OBJ_PERSON)) {
$base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
if($base && count($base)) {
foreach($base as $link) {
if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
$res['author-link'] = unxmlify($link['attribs']['']['href']);
if(! $res['author-avatar']) {
if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo')
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
}
}
// No photo/profile-link on the item - look at the feed level
2010-11-10 05:38:24 +01:00
if((! (x($res,'author-link'))) || (! (x($res,'author-avatar')))) {
$rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author');
if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
$base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
foreach($base as $link) {
if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
$res['author-link'] = unxmlify($link['attribs']['']['href']);
if(! $res['author-avatar']) {
if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
}
$rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject');
if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'],ACTIVITY_OBJ_PERSON)) {
$base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
if($base && count($base)) {
foreach($base as $link) {
if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
$res['author-link'] = unxmlify($link['attribs']['']['href']);
2010-11-10 05:38:24 +01:00
if(! (x($res,'author-avatar'))) {
if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo')
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
}
}
}
2011-06-21 04:08:40 +02:00
$apps = $item->get_item_tags(NAMESPACE_STATUSNET,'notice_info');
if($apps && $apps[0]['attribs']['']['source']) {
2011-06-24 00:58:43 +02:00
$res['app'] = strip_tags(unxmlify($apps[0]['attribs']['']['source']));
2011-06-21 04:08:40 +02:00
if($res['app'] === 'web')
$res['app'] = 'OStatus';
}
/**
* If there's a copy of the body content which is guaranteed to have survived mangling in transit, use it.
*/
$have_real_body = false;
$rawenv = $item->get_item_tags(NAMESPACE_DFRN, 'env');
if($rawenv) {
$have_real_body = true;
$res['body'] = $rawenv[0]['data'];
$res['body'] = str_replace(array(' ',"\t","\r","\n"), array('','','',''),$res['body']);
2011-02-02 02:50:49 +01:00
// make sure nobody is trying to sneak some html tags by us
$res['body'] = notags(base64url_decode($res['body']));
}
2010-07-19 05:49:10 +02:00
$maxlen = get_max_import_size();
if($maxlen && (strlen($res['body']) > $maxlen))
$res['body'] = substr($res['body'],0, $maxlen);
2010-09-09 05:14:17 +02:00
// It isn't certain at this point whether our content is plaintext or html and we'd be foolish to trust
// the content type. Our own network only emits text normally, though it might have been converted to
2011-01-18 04:50:18 +01:00
// html if we used a pubsubhubbub transport. But if we see even one html tag in our text, we will
2010-09-09 05:14:17 +02:00
// have to assume it is all html and needs to be purified.
// It doesn't matter all that much security wise - because before this content is used anywhere, we are
// going to escape any tags we find regardless, but this lets us import a limited subset of html from
// the wild, by sanitising it and converting supported tags to bbcode before we rip out any remaining
// html.
if((strpos($res['body'],'<') !== false) || (strpos($res['body'],'>') !== false)) {
2010-09-09 05:14:17 +02:00
$res['body'] = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $res['body']);
2010-09-09 05:14:17 +02:00
2011-05-21 10:17:07 +02:00
$res['body'] = preg_replace('#<iframe[^>].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?</iframe>#s',
'[youtube]$1[/youtube]', $res['body']);
$res['body'] = oembed_html2bbcode($res['body']);
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
2010-09-09 05:14:17 +02:00
// we shouldn't need a whitelist, because the bbcode converter
// will strip out any unsupported tags.
// $config->set('HTML.Allowed', 'p,b,a[href],i');
2010-09-09 05:14:17 +02:00
$purifier = new HTMLPurifier($config);
$res['body'] = $purifier->purify($res['body']);
2010-09-09 11:00:54 +02:00
$res['body'] = html2bbcode($res['body']);
2011-01-18 04:50:18 +01:00
}
2010-08-03 04:06:36 +02:00
$allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
2010-07-19 05:49:10 +02:00
if($allow && $allow[0]['data'] == 1)
$res['last-child'] = 1;
else
$res['last-child'] = 0;
$private = $item->get_item_tags(NAMESPACE_DFRN,'private');
if($private && $private[0]['data'] == 1)
$res['private'] = 1;
else
$res['private'] = 0;
$extid = $item->get_item_tags(NAMESPACE_DFRN,'extid');
if($extid && $extid[0]['data'])
$res['extid'] = $extid[0]['data'];
2010-07-19 05:49:10 +02:00
$rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location');
2010-08-20 23:33:15 +02:00
if($rawlocation)
$res['location'] = unxmlify($rawlocation[0]['data']);
$rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
if($rawcreated)
$res['created'] = unxmlify($rawcreated[0]['data']);
2010-07-19 05:49:10 +02:00
$rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
if($rawedited)
$res['edited'] = unxmlify($rawedited[0]['data']);
2010-07-19 05:49:10 +02:00
if((x($res,'edited')) && (! (x($res,'created'))))
2011-02-02 02:05:17 +01:00
$res['created'] = $res['edited'];
if(! $res['created'])
$res['created'] = $item->get_date('c');
if(! $res['edited'])
$res['edited'] = $item->get_date('c');
// Disallow time travelling posts
$d1 = strtotime($res['created']);
$d2 = strtotime($res['edited']);
$d3 = strtotime('now');
if($d1 > $d3)
$res['created'] = datetime_convert();
if($d2 > $d3)
$res['edited'] = datetime_convert();
2010-08-03 04:06:36 +02:00
$rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
2010-09-09 05:14:17 +02:00
if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
$res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']);
elseif($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data'])
2010-08-03 04:06:36 +02:00
$res['owner-name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']);
2010-09-09 05:14:17 +02:00
if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])
$res['owner-link'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']);
elseif($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data'])
2010-08-03 04:06:36 +02:00
$res['owner-link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']);
2010-09-09 05:14:17 +02:00
if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
$base = $rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
foreach($base as $link) {
if(! $res['owner-avatar']) {
if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
$res['owner-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
}
2010-07-19 05:49:10 +02:00
2010-10-20 05:52:05 +02:00
$rawgeo = $item->get_item_tags(NAMESPACE_GEORSS,'point');
if($rawgeo)
$res['coord'] = unxmlify($rawgeo[0]['data']);
2010-09-09 05:14:17 +02:00
$rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb');
2010-09-09 05:14:17 +02:00
// select between supported verbs
if($rawverb) {
2010-09-09 05:14:17 +02:00
$res['verb'] = unxmlify($rawverb[0]['data']);
}
// translate OStatus unfollow to activity streams if it happened to get selected
if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow'))
$res['verb'] = ACTIVITY_UNFOLLOW;
2011-04-06 02:41:02 +02:00
$cats = $item->get_categories();
if($cats) {
$tag_arr = array();
foreach($cats as $cat) {
$term = $cat->get_term();
if(! $term)
$term = $cat->get_label();
$scheme = $cat->get_scheme();
if($scheme && $term && stristr($scheme,'X-DFRN:'))
$tag_arr[] = substr($scheme,7,1) . '[url=' . unxmlify(substr($scheme,9)) . ']' . unxmlify($term) . '[/url]';
elseif($term)
$tag_arr[] = notags(trim($term));
2011-04-06 02:41:02 +02:00
}
$res['tag'] = implode(',', $tag_arr);
}
2010-09-09 05:14:17 +02:00
$attach = $item->get_enclosures();
if($attach) {
$att_arr = array();
foreach($attach as $att) {
2011-04-13 10:53:40 +02:00
$len = intval($att->get_length());
$link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_link()))));
$title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_title()))));
$type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_type()))));
if(strpos($type,';'))
$type = substr($type,0,strpos($type,';'));
if((! $link) || (strpos($link,'http') !== 0))
continue;
if(! $title)
$title = ' ';
if(! $type)
$type = 'application/octet-stream';
2011-08-04 04:18:58 +02:00
$att_arr[] = '[attach]href="' . $link . '" length="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]';
}
$res['attach'] = implode(',', $att_arr);
}
2010-09-09 05:14:17 +02:00
$rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
2010-09-17 12:10:19 +02:00
2010-09-09 05:14:17 +02:00
if($rawobj) {
2010-09-17 12:10:19 +02:00
$res['object'] = '<object>' . "\n";
if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
$res['object-type'] = $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'];
$res['object'] .= '<type>' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n";
}
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'])
$res['object'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'])
$res['object'] .= '<link>' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n";
2010-09-17 12:10:19 +02:00
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'])
$res['object'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) {
$body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data'];
if(! $body)
$body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
// preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
$res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) {
2010-09-17 12:10:19 +02:00
$body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $body);
2011-05-21 10:17:07 +02:00
$res['body'] = preg_replace('#<iframe[^>].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?</iframe>#s',
'[youtube]$1[/youtube]', $res['body']);
2010-09-17 12:10:19 +02:00
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
2010-09-17 12:10:19 +02:00
$purifier = new HTMLPurifier($config);
$body = $purifier->purify($body);
2011-01-18 04:50:18 +01:00
$body = html2bbcode($body);
2010-09-17 12:10:19 +02:00
}
$res['object'] .= '<content>' . $body . '</content>' . "\n";
}
$res['object'] .= '</object>' . "\n";
2010-09-09 05:14:17 +02:00
}
$rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'target');
if($rawobj) {
$res['target'] = '<target>' . "\n";
if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
$res['target'] .= '<type>' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n";
}
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'])
$res['target'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'])
$res['target'] .= '<link>' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'])
$res['target'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) {
$body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data'];
if(! $body)
$body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
// preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
$res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) {
$body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $body);
2011-05-21 10:17:07 +02:00
$res['body'] = preg_replace('#<iframe[^>].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?</iframe>#s',
'[youtube]$1[/youtube]', $res['body']);
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
$purifier = new HTMLPurifier($config);
$body = $purifier->purify($body);
2011-01-18 04:50:18 +01:00
$body = html2bbcode($body);
}
$res['target'] .= '<content>' . $body . '</content>' . "\n";
}
$res['target'] .= '</target>' . "\n";
}
2010-12-26 00:01:02 +01:00
$arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
call_hooks('parse_atom', $arr);
2010-12-25 03:32:23 +01:00
2010-07-19 05:49:10 +02:00
return $res;
}
function encode_rel_links($links) {
$o = '';
if(! ((is_array($links)) && (count($links))))
return $o;
foreach($links as $link) {
$o .= '<link ';
if($link['attribs']['']['rel'])
$o .= 'rel="' . $link['attribs']['']['rel'] . '" ';
if($link['attribs']['']['type'])
$o .= 'type="' . $link['attribs']['']['type'] . '" ';
if($link['attribs']['']['href'])
$o .= 'href="' . $link['attribs']['']['href'] . '" ';
2010-11-04 08:37:29 +01:00
if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['width'])
$o .= 'media:width="' . $link['attribs'][NAMESPACE_MEDIA]['width'] . '" ';
2010-11-04 08:37:29 +01:00
if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['height'])
$o .= 'media:height="' . $link['attribs'][NAMESPACE_MEDIA]['height'] . '" ';
$o .= ' />' . "\n" ;
}
return xmlify($o);
}
function item_store($arr,$force_parent = false) {
2010-07-19 05:49:10 +02:00
2010-09-10 07:02:28 +02:00
if($arr['gravity'])
2010-09-10 09:42:53 +02:00
$arr['gravity'] = intval($arr['gravity']);
2010-09-10 07:02:28 +02:00
elseif($arr['parent-uri'] == $arr['uri'])
$arr['gravity'] = 0;
elseif(activity_match($arr['verb'],ACTIVITY_POST))
2010-09-10 07:02:28 +02:00
$arr['gravity'] = 6;
2010-11-10 05:38:24 +01:00
else
$arr['gravity'] = 6; // extensible catchall
2010-09-10 07:02:28 +02:00
2010-07-19 05:49:10 +02:00
if(! x($arr,'type'))
2010-11-10 05:38:24 +01:00
$arr['type'] = 'remote';
// Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin.
if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false))
$arr['body'] = strip_tags($arr['body']);
2010-11-10 05:38:24 +01:00
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
$arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
$arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : '');
2010-11-10 05:38:24 +01:00
$arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : '');
$arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
$arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : '');
$arr['owner-name'] = ((x($arr,'owner-name')) ? notags(trim($arr['owner-name'])) : '');
$arr['owner-link'] = ((x($arr,'owner-link')) ? notags(trim($arr['owner-link'])) : '');
$arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
$arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
$arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
$arr['received'] = datetime_convert();
2010-11-10 05:38:24 +01:00
$arr['changed'] = datetime_convert();
$arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
$arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
$arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : '');
$arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
$arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
$arr['deleted'] = 0;
$arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : '');
$arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : '');
$arr['object-type'] = ((x($arr,'object-type')) ? notags(trim($arr['object-type'])) : '');
$arr['object'] = ((x($arr,'object')) ? trim($arr['object']) : '');
$arr['target-type'] = ((x($arr,'target-type')) ? notags(trim($arr['target-type'])) : '');
$arr['target'] = ((x($arr,'target')) ? trim($arr['target']) : '');
$arr['plink'] = ((x($arr,'plink')) ? notags(trim($arr['plink'])) : '');
$arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : '');
$arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : '');
$arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : '');
$arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
$arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0 );
$arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : '');
2011-04-06 02:41:02 +02:00
$arr['tag'] = ((x($arr,'tag')) ? notags(trim($arr['tag'])) : '');
2011-04-07 06:59:07 +02:00
$arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : '');
2011-06-21 04:08:40 +02:00
$arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : '');