File->getEnclosure improvements (text/html is not an attachment)

This commit is contained in:
Mikael Nordfeldth 2014-08-05 10:54:00 +02:00
parent 33a85ae945
commit 17b9614ff8
2 changed files with 23 additions and 23 deletions

View File

@ -352,30 +352,21 @@ class File extends Managed_DataObject
function getEnclosure(){ function getEnclosure(){
$enclosure = (object) array(); $enclosure = (object) array();
$enclosure->title=$this->title; foreach (array('title', 'url', 'date', 'modified', 'size', 'mimetype') as $key) {
$enclosure->url=$this->url; $enclosure->$key = $this->$key;
$enclosure->title=$this->title;
$enclosure->date=$this->date;
$enclosure->modified=$this->modified;
$enclosure->size=$this->size;
$enclosure->mimetype=$this->mimetype;
if (!isset($this->filename)) {
$notEnclosureMimeTypes = array(null,'text/html','application/xhtml+xml');
$mimetype = $this->mimetype;
if($mimetype != null){
$mimetype = strtolower($this->mimetype);
}
$semicolon = strpos($mimetype,';');
if($semicolon){
$mimetype = substr($mimetype,0,$semicolon);
}
if (in_array($mimetype, $notEnclosureMimeTypes)) {
Event::handle('FileEnclosureMetadata', array($this, &$enclosure));
}
} }
if (empty($enclosure->mimetype)) {
// This means we don't know what it is, so it can't be an enclosure! $needMoreMetadataMimetypes = array(null, 'text/html', 'application/xhtml+xml');
if (!isset($this->filename) && in_array(common_bare_mime($enclosure->mimetype), $needMoreMetadataMimetypes)) {
// This fetches enclosure metadata for non-local links with unset/HTML mimetypes,
// which may be enriched through oEmbed or similar (implemented as plugins)
Event::handle('FileEnclosureMetadata', array($this, &$enclosure));
}
if (empty($enclosure->mimetype) || in_array(common_bare_mime($enclosure->mimetype), $needMoreMetadataMimetypes)) {
// This means we either don't know what it is, so it can't
// be shown as an enclosure, or it is an HTML link which
// does not link to a resource with further metadata.
throw new ServerException('Unknown enclosure mimetype, not enough metadata'); throw new ServerException('Unknown enclosure mimetype, not enough metadata');
} }
return $enclosure; return $enclosure;

View File

@ -1820,6 +1820,15 @@ function common_get_mime_media($type)
return strtolower($tmp[0]); return strtolower($tmp[0]);
} }
function common_bare_mime($mimetype)
{
$mimetype = mb_strtolower($mimetype);
if ($semicolon = mb_strpos($mimetype, ';')) {
$mimetype = mb_substr($mimetype, 0, $semicolon);
}
return $mimetype;
}
function common_mime_type_match($type, $avail) function common_mime_type_match($type, $avail)
{ {
if(array_key_exists($type, $avail)) { if(array_key_exists($type, $avail)) {