From a985ad4a5407c3cbc0d0a3919e19ddd99bf108af Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 3 Nov 2010 16:48:21 -0700 Subject: add activity target to items, allow multiple link relations --- include/items.php | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 7 deletions(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index da85ed331..b016fa180 100644 --- a/include/items.php +++ b/include/items.php @@ -188,7 +188,7 @@ function construct_verb($item) { return ACTIVITY_POST; } -function construct_activity($item) { +function construct_activity_object($item) { if($item['object']) { $o = '' . "\r\n"; @@ -197,8 +197,12 @@ function construct_activity($item) { $o .= '' . xmlify($r->type) . '' . "\r\n"; if($r->id) $o .= '' . xmlify($r->id) . '' . "\r\n"; - if($r->link) - $o .= '' . "\r\n"; + if($r->link) { + if(substr($r->link,0,1) === '&') + $o .= unxmlify($r->link); + else + $o .= '' . "\r\n"; + } if($r->title) $o .= '' . xmlify($r->title) . '' . "\r\n"; if($r->content) @@ -210,6 +214,32 @@ function construct_activity($item) { return ''; } +function construct_activity_target($item) { + + if($item['target']) { + $o = '' . "\r\n"; + $r = @simplexml_load_string($item['target']); + if($r->type) + $o .= '' . xmlify($r->type) . '' . "\r\n"; + if($r->id) + $o .= '' . xmlify($r->id) . '' . "\r\n"; + if($r->link) { + if(substr($r->link,0,1) === '&') + $o .= unxmlify($r->link); + else + $o .= '' . "\r\n"; + } + if($r->title) + $o .= '' . xmlify($r->title) . '' . "\r\n"; + if($r->content) + $o .= '' . xmlify(bbcode($r->content)) . '' . "\r\n"; + $o .= '' . "\r\n"; + return $o; + } + + return ''; +} + @@ -391,9 +421,8 @@ function get_atom_elements($feed,$item) { } if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; - - if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'][0]['attribs']['']['rel'] === 'alternate') - $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'][0]['attribs']['']['href'] . '' . "\n"; + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) + $res['target'] .= '' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '' . "\n"; if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '' . "\n"; if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { @@ -419,9 +448,67 @@ function get_atom_elements($feed,$item) { $res['object'] .= '' . "\n"; } + $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'target'); + + if($rawobj) { + $res['target'] = '' . "\n"; + if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) { + $res['target'] .= '' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '' . "\n"; + } + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) + $res['target'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; + + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) + $res['target'] .= '' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '' . "\n"; + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) + $res['target'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '' . "\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']; + if(strpos($body,'<')) { + + $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $body); + + $config = HTMLPurifier_Config::createDefault(); + $config->set('Cache.DefinitionImpl', null); + + $purifier = new HTMLPurifier($config); + $body = $purifier->purify($body); + } + + $body = html2bbcode($body); + $res['target'] .= '' . $body . '' . "\n"; + } + + $res['target'] .= '' . "\n"; + } + return $res; } +function encode_rel_links($links) { + $o = ''; + if(! ((is_array($links)) && (count($links)))) + return $o; + foreach($links as $link) { + $o .= '' . "\r\n"; - $actobj = construct_activity($item); + $actobj = construct_activity_object($item); if(strlen($actobj)) $o .= $actobj; + $actarg = construct_activity_target($item); + if(strlen($actarg)) + $o .= $actarg; $mentioned = get_mentions($item); if($mentioned) -- cgit v1.2.3