]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File.php
Merge mmn's 'nightly' changes
[quix0rs-gnu-social.git] / classes / File.php
index b834036405aba6a3b85c21c5028ac19d924db243..210e758419570c8044bba27429f0ca5ecdb1dde8 100644 (file)
@@ -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;
-
-        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));
-            }
+        foreach (array('title', 'url', 'date', 'modified', 'size', 'mimetype') as $key) {
+            $enclosure->$key = $this->$key;
+        }
+
+        $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;
@@ -550,4 +541,11 @@ class File extends Managed_DataObject
         // And finally remove the entry from the database
         return parent::delete($useWhere);
     }
+
+    public function getTitle()
+    {
+        $title = $this->title ?: $this->filename;
+
+        return $title ?: null;
+    }
 }