]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
File::processNew can return -1 which was not true for empty()
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 1 Jun 2014 23:26:23 +0000 (01:26 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 1 Jun 2014 23:46:09 +0000 (01:46 +0200)
Also, File->getEnclosure() now throws exception if not enough metadata.

classes/File.php
lib/apiaction.php
lib/rssaction.php
lib/util.php
plugins/FacebookBridge/lib/facebookclient.php

index 6db1c7b806c79a5f6219d7dcbdacb10db5d885e8..5acf6a7b50bbacfff11dd4e96a96f578eceaaa34 100644 (file)
@@ -364,16 +364,13 @@ class File extends Managed_DataObject
                 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!
+            throw new ServerException('Unknown enclosure mimetype, not enough metadata');
+        }
         return $enclosure;
     }
 
-    // quick back-compat hack, since there's still code using this
-    function isEnclosure()
-    {
-        $enclosure = $this->getEnclosure();
-        return !empty($enclosure);
-    }
-
     /**
      * Get the attachment's thumbnail record, if any.
      * Make sure you supply proper 'int' typed variables (or null).
index 9f26b3b304135dec609a0794e39c778b45f3ccb3..55860efa554286d900191ff25076916f6261771d 100644 (file)
@@ -384,13 +384,15 @@ class ApiAction extends Action
             $twitter_status['attachments'] = array();
 
             foreach ($attachments as $attachment) {
-                $enclosure_o=$attachment->getEnclosure();
-                if ($enclosure_o) {
+                try {
+                    $enclosure_o = $attachment->getEnclosure();
                     $enclosure = array();
                     $enclosure['url'] = $enclosure_o->url;
                     $enclosure['mimetype'] = $enclosure_o->mimetype;
                     $enclosure['size'] = $enclosure_o->size;
                     $twitter_status['attachments'][] = $enclosure;
+                } catch (ServerException $e) {
+                    // There was not enough metadata available
                 }
             }
         }
@@ -510,13 +512,15 @@ class ApiAction extends Action
             $enclosures = array();
 
             foreach ($attachments as $attachment) {
-                $enclosure_o=$attachment->getEnclosure();
-                if ($enclosure_o) {
+                try {
+                    $enclosure_o = $attachment->getEnclosure();
                     $enclosure = array();
                     $enclosure['url'] = $enclosure_o->url;
                     $enclosure['mimetype'] = $enclosure_o->mimetype;
                     $enclosure['size'] = $enclosure_o->size;
                     $enclosures[] = $enclosure;
+                } catch (ServerException $e) {
+                    // There was not enough metadata available
                 }
             }
 
index dac7fa4606e8d4fa5563f4229b10fc8a22b5a275..684ecd6d8c1f1370e088e83e3f60d03bbc377882 100644 (file)
@@ -278,8 +278,8 @@ class Rss10Action extends Action
         $attachments = $notice->attachments();
         if($attachments){
             foreach($attachments as $attachment){
-                $enclosure=$attachment->getEnclosure();
-                if ($enclosure) {
+                try {
+                    $enclosure = $attachment->getEnclosure();
                     $attribs = array('rdf:resource' => $enclosure->url);
                     if ($enclosure->title) {
                         $attribs['dc:title'] = $enclosure->title;
@@ -294,6 +294,8 @@ class Rss10Action extends Action
                         $attribs['enc:type'] = $enclosure->mimetype;
                     }
                     $this->element('enc:enclosure', $attribs);
+                } catch (ServerException $e) {
+                    // There was not enough metadata available
                 }
                 $this->element('sioc:links_to', array('rdf:resource'=>$attachment->url));
             }
index c76f7b276268615467bc208e8c9314184f7330d2..97c0a5aa57517c75752241224324a067d1f17f5b 100644 (file)
@@ -989,22 +989,23 @@ function common_linkify($url) {
 
     $f = File::getKV('url', $longurl);
 
-    if (empty($f)) {
+    if (!$f instanceof File) {
         if (common_config('attachments', 'process_links')) {
             // XXX: this writes to the database. :<
             $f = File::processNew($longurl);
         }
     }
 
-    if (!empty($f)) {
-        if ($f->getEnclosure()) {
+    if ($f instanceof File) {
+        try {
+            $enclosure = $f->getEnclosure();
             $is_attachment = true;
             $attachment_id = $f->id;
 
             $thumb = File_thumbnail::getKV('file_id', $f->id);
-            if (!empty($thumb)) {
-                $has_thumb = true;
-            }
+            $has_thumb = ($thumb instanceof File_thumbnail);
+        } catch (ServerException $e) {
+            // There was not enough metadata available
         }
     }
 
index deb92e93131a57041e47223cfea0cc9824eea769..5b512dfdff6cb5ca70ea660601cb38582dab08ac 100644 (file)
@@ -651,9 +651,10 @@ class Facebookclient
 
         foreach($attachments as $attachment)
         {
-            if($enclosure = $attachment->getEnclosure()){
+            try {
+                $enclosure = $attachment->getEnclosure();
                 $fbmedia = $this->getFacebookMedia($enclosure);
-            }else{
+            } catch (ServerException $e) {
                 $fbmedia = $this->getFacebookMedia($attachment);
             }
             if($fbmedia){