File->getEnclosure improvements (text/html is not an attachment)
This commit is contained in:
parent
33a85ae945
commit
17b9614ff8
@ -352,30 +352,21 @@ class File extends Managed_DataObject
|
||||
|
||||
function getEnclosure(){
|
||||
$enclosure = (object) array();
|
||||
$enclosure->title=$this->title;
|
||||
$enclosure->url=$this->url;
|
||||
$enclosure->title=$this->title;
|
||||
$enclosure->date=$this->date;
|
||||
$enclosure->modified=$this->modified;
|
||||
$enclosure->size=$this->size;
|
||||
$enclosure->mimetype=$this->mimetype;
|
||||
foreach (array('title', 'url', 'date', 'modified', 'size', 'mimetype') as $key) {
|
||||
$enclosure->$key = $this->$key;
|
||||
}
|
||||
|
||||
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)) {
|
||||
$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)) {
|
||||
// This means we don't know what it is, so it can't be an 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');
|
||||
}
|
||||
return $enclosure;
|
||||
|
@ -1820,6 +1820,15 @@ function common_get_mime_media($type)
|
||||
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)
|
||||
{
|
||||
if(array_key_exists($type, $avail)) {
|
||||
|
Loading…
Reference in New Issue
Block a user