]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Slight cleanup in typing and syntax of File and File_* classes
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 10 Nov 2013 13:33:45 +0000 (14:33 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 10 Nov 2013 13:33:45 +0000 (14:33 +0100)
classes/File.php
classes/File_oembed.php
classes/File_redirection.php

index e3300e7e6870981de8684e251edb3f750d33e501..a5914b506e670f414e23a33b5de65a87fdbeebeb 100644 (file)
  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-require_once INSTALLDIR.'/classes/File_redirection.php';
-require_once INSTALLDIR.'/classes/File_oembed.php';
-require_once INSTALLDIR.'/classes/File_thumbnail.php';
-require_once INSTALLDIR.'/classes/File_to_post.php';
-//require_once INSTALLDIR.'/classes/File_redirection.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Table Definition for file
@@ -88,7 +81,7 @@ class File extends Managed_DataObject
 
         $x = File::getKV('url', $given_url);
         
-        if (empty($x)) {
+        if (!$x instanceof File) {
             $x = new File;
             $x->url = $given_url;
             if (!empty($redir_data['protected'])) $x->protected = $redir_data['protected'];
@@ -116,16 +109,21 @@ class File extends Managed_DataObject
     public function saveOembed(array $redir_data, $given_url)
     {
         if (isset($redir_data['type'])
-            && (('text/html' === substr($redir_data['type'], 0, 9) || 'application/xhtml+xml' === substr($redir_data['type'], 0, 21)))
-            && ($oembed_data = File_oembed::_getOembed($given_url))) {
+                && (('text/html' === substr($redir_data['type'], 0, 9)
+                || 'application/xhtml+xml' === substr($redir_data['type'], 0, 21)))) {
+            try {
+                $oembed_data = File_oembed::_getOembed($given_url);
+            } catch (Exception $e) {
+                return false;
+            }
 
             $fo = File_oembed::getKV('file_id', $this->id);
 
-            if (empty($fo)) {
+            if ($fo instanceof File_oembed) {
+                common_log(LOG_WARNING, "Strangely, a File_oembed object exists for new file $file_id", __FILE__);
+            } else {
                 File_oembed::saveNew($oembed_data, $this->id);
                 return true;
-            } else {
-                common_log(LOG_WARNING, "Strangely, a File_oembed object exists for new file $file_id", __FILE__);
             }
         }
         return false;
index a250a1cc3b76009e5b7622c9ffd44e2909650243..460722c7999fa0432c4e03fe079f610442a6fee4 100644 (file)
@@ -98,6 +98,9 @@ class File_oembed extends Managed_DataObject
     function saveNew($data, $file_id) {
         $file_oembed = new File_oembed;
         $file_oembed->file_id = $file_id;
+        if (!isset($data->version)) {
+            common_debug('DEBUGGING oEmbed: data->version undefined in variable $data: '.var_export($data, true));
+        }
         $file_oembed->version = $data->version;
         $file_oembed->type = $data->type;
         if (!empty($data->provider_name)) $file_oembed->provider = $data->provider_name;
@@ -114,7 +117,9 @@ class File_oembed extends Managed_DataObject
             $given_url = File_redirection::_canonUrl($file_oembed->url);
             if (! empty($given_url)){
                 $file = File::getKV('url', $given_url);
-                if (empty($file)) {
+                if ($file instanceof File) {
+                    $file_oembed->mimetype = $file->mimetype;
+                } else {
                     $file_redir = File_redirection::getKV('url', $given_url);
                     if (empty($file_redir)) {
                         $redir_data = File_redirection::where($given_url);
@@ -122,15 +127,13 @@ class File_oembed extends Managed_DataObject
                     } else {
                         $file_id = $file_redir->file_id;
                     }
-                } else {
-                    $file_oembed->mimetype=$file->mimetype;
                 }
             }
         }
         $file_oembed->insert();
         if (!empty($data->thumbnail_url) || ($data->type == 'photo')) {
             $ft = File_thumbnail::getKV('file_id', $file_id);
-            if (!empty($ft)) {
+            if ($ft instanceof File_thumbnail) {
                 common_log(LOG_WARNING, "Strangely, a File_thumbnail object exists for new file $file_id",
                            __FILE__);
             } else {
index 00a5216505a8171df20642e0c3c6b0b86fcb956f..42021668d99684e8123394a2390ae5aaaecdcfd9 100644 (file)
  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-require_once INSTALLDIR.'/classes/File.php';
-require_once INSTALLDIR.'/classes/File_oembed.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Table Definition for file_redirection
@@ -251,7 +247,9 @@ class File_redirection extends Managed_DataObject
             $short_url = (string)$short_url;
             // store it
             $file = File::getKV('url', $long_url);
-            if (empty($file)) {
+            if ($file instanceof File) {
+                $file_id = $file->id;
+            } else {
                 // Check if the target URL is itself a redirect...
                 $redir_data = File_redirection::where($long_url);
                 if (is_array($redir_data)) {
@@ -275,11 +273,9 @@ class File_redirection extends Managed_DataObject
                     }
                     $file_id = $file->id;
                 }
-            } else {
-                $file_id = $file->id;
             }
             $file_redir = File_redirection::getKV('url', $short_url);
-            if (empty($file_redir)) {
+            if (!$file_redir instanceof File_redirection) {
                 $file_redir = new File_redirection;
                 $file_redir->url = $short_url;
                 $file_redir->file_id = $file_id;