]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / classes / File.php
index 2390f848de28f420abb06dd211c237ea32467406..dbd9a3bb449f71ae79baf79198c7fa8029eea0d2 100644 (file)
@@ -71,8 +71,20 @@ class File extends Managed_DataObject
         );
     }
 
-    function isProtected($url) {
-        return 'http://www.facebook.com/login.php' === $url;
+    public static function isProtected($url) {
+
+               $protected_urls_exps = array(
+                       'https://www.facebook.com/login.php',
+               common_path('main/login')
+               );
+
+               foreach ($protected_urls_exps as $protected_url_exp) {
+                       if (preg_match('!^'.preg_quote($protected_url_exp).'(.*)$!i', $url) === 1) {
+                               return true;
+                       }
+               }
+
+               return false;
     }
 
     /**
@@ -150,18 +162,6 @@ class File extends Managed_DataObject
         $redir = File_redirection::where($given_url);
         $file = $redir->getFile();
 
-        // If we still don't have a File object, let's create one now!
-        if (empty($file->id)) {
-            if ($redir->url === $given_url || !$followRedirects) {
-                // Save the File object based on our lookup trace
-                $file->saveFile();
-            } else {
-                $file->saveFile();
-                $redir->file_id = $file->id;
-                $redir->insert();
-            }
-        }
-
         if (!$file instanceof File || empty($file->id)) {
             // This should not happen
             throw new ServerException('URL processing failed without new File object');
@@ -264,9 +264,13 @@ class File extends Managed_DataObject
             $ext = common_supported_mime_to_ext($mimetype);
         } catch (Exception $e) {
             // We don't support this mimetype, but let's guess the extension
-            $ext = substr(strrchr($mimetype, '/'), 1);
+            $matches = array();
+            if (!preg_match('/\/([a-z0-9]+)/', mb_strtolower($mimetype), $matches)) {
+                throw new Exception('Malformed mimetype: '.$mimetype);
+            }
+            $ext = $matches[1];
         }
-        return strtolower($ext);
+        return mb_strtolower($ext);
     }
 
     /**
@@ -360,13 +364,14 @@ class File extends Managed_DataObject
 
     function getEnclosure(){
         if (isset(self::$_enclosures[$this->getID()])) {
-            common_debug('Found cached enclosure for file id=='.$this->getID());
             return self::$_enclosures[$this->getID()];
         }
 
         $enclosure = (object) array();
-        foreach (array('title', 'url', 'date', 'modified', 'size', 'mimetype') as $key) {
-            $enclosure->$key = $this->$key;
+        foreach (array('title', 'url', 'date', 'modified', 'size', 'mimetype', 'width', 'height') as $key) {
+            if ($this->$key !== '') {
+                $enclosure->$key = $this->$key;
+            }
         }
 
         $needMoreMetadataMimetypes = array(null, 'application/xhtml+xml', 'text/html');
@@ -411,7 +416,7 @@ class File extends Managed_DataObject
      * @throws UnsupportedMediaException    if, despite trying, we can't understand how to make a thumbnail for this format
      * @throws ServerException              on various other errors
      */
-    public function getThumbnail($width=null, $height=null, $crop=false, $force_still=true)
+    public function getThumbnail($width=null, $height=null, $crop=false, $force_still=true, $upscale=null)
     {
         // Get some more information about this file through our ImageFile class
         $image = ImageFile::fromFileObject($this);
@@ -423,7 +428,11 @@ class File extends Managed_DataObject
             }
         }
 
-        return $image->getFileThumbnail($width, $height, $crop);
+        // Debug log (convert crop to int to have TRUE being displayed as 1 and FALSE as 0)
+        /* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . ']: width=' . $width . ',height=' . $height . ',crop=' . intval($crop) . ',upscale=' . intval($upscale));
+
+        return $image->getFileThumbnail($width, $height, $crop,
+                                        !is_null($upscale) ? $upscale : common_config('thumbnail', 'upscale'));
     }
 
     public function getPath()