From 6728a11ee38e890a0ce9b8b6d96dba98a7238129 Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 6 Apr 2011 19:41:16 -0700 Subject: support feed attachments/enclosures, and fix for bug #30 --- include/items.php | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index b17eadba2..501f2f944 100644 --- a/include/items.php +++ b/include/items.php @@ -468,11 +468,34 @@ function get_atom_elements($feed,$item) { 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[] = $term; + $tag_arr[] = notags(trim($term)); } $res['tag'] = implode(',', $tag_arr); } + $attach = $item->get_enclosures(); + if($attach) { + $att_arr = array(); + foreach($attach as $att) { + $len = intval($att->get_length()); + $link = str_replace(',','%2D', notags(trim($att->get_link()))); + $title = str_replace(',','%2D',notags(trim($att->get_title()))); + $type = notags(trim($att->get_type())); + if((! $link) || (strpos($link,'http') !== 0)) + continue; + + if(! $title) + $title = ' '; + if(! $type) + $type = 'application/octet-stream'; + + // this isn't legal html - there is no size in an 'a' tag, remember to strip it before display + + $att_arr[] = '' . $title . ''; + } + $res['attach'] = implode(',', $att_arr); + } + $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); if($rawobj) { @@ -1526,6 +1549,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { } } + $o .= item_getfeedattach($item); + $mentioned = get_mentions($item); if($mentioned) $o .= $mentioned; @@ -1558,6 +1583,26 @@ function item_getfeedtags($item) { return $ret; } +function item_getfeedattach($item) { + $ret = array(); + $arr = explode(',',$item['attach']); + if(count($arr)) { + foreach($arr as $r) { + $matches = false; + $cnt = preg_match('|\(.+?)|',$item['attach'],$matches); + if($cnt) { + $ret .= '