]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php
Merge branch 'master' of git.gnu.io:gnu/gnu-social into mmn_fixes
[quix0rs-gnu-social.git] / plugins / StoreRemoteMedia / StoreRemoteMediaPlugin.php
index 36e3544efa4417a4e8829397d325a97052973df8..e171218f79ffc6868abfe82e91f8e1d471c9e147 100644 (file)
@@ -18,6 +18,8 @@ class StoreRemoteMediaPlugin extends Plugin
     public $domain_blacklist = array();
     public $check_blacklist = false;
 
+    public $max_image_bytes = 10485760;  // 10MiB max image size by default
+
     protected $imgData = array();
 
     // these should be declared protected everywhere
@@ -53,7 +55,7 @@ class StoreRemoteMediaPlugin extends Plugin
         switch (common_get_mime_media($file->mimetype)) {
         case 'image':
             // Just to set something for now at least...
-            $file->title = $file->mimetype;
+            //$file->title = $file->mimetype;
             break;
         }
         
@@ -89,7 +91,7 @@ class StoreRemoteMediaPlugin extends Plugin
             $http = new HTTPClient();
             common_debug(sprintf('Performing HEAD request for remote file id==%u to avoid unnecessarily downloading too large files. URL: %s', $file->getID(), $remoteUrl));
             $head = $http->head($remoteUrl);
-            $remoteUrl = $head->effectiveUrl;   // to avoid going through redirects again
+            $remoteUrl = $head->getEffectiveUrl();   // to avoid going through redirects again
             if (!$this->checkBlackList($remoteUrl)) {
                 common_log(LOG_WARN, sprintf('%s: Non-blacklisted URL %s redirected to blacklisted URL %s', __CLASS__, $file->getUrl(), $remoteUrl));
                 return true;
@@ -103,18 +105,22 @@ class StoreRemoteMediaPlugin extends Plugin
                 // file size not specified on remote server
                 common_debug(sprintf('%s: Ignoring remote media because we did not get a content length for file id==%u', __CLASS__, $file->getID()));
                 return true;
+            } elseif ($filesize > $this->max_image_bytes) {
+                //FIXME: When we perhaps start fetching videos etc. we'll need to differentiate max_image_bytes from that...
+                // file too big according to plugin configuration
+                common_debug(sprintf('%s: Skipping remote media because content length (%u) is larger than plugin configured max_image_bytes (%u) for file id==%u', __CLASS__, intval($filesize), $this->max_image_bytes, $file->getID()));
+                return true;
             } elseif ($filesize > common_config('attachments', 'file_quota')) {
-                // file too big
+                // file too big according to site configuration
                 common_debug(sprintf('%s: Skipping remote media because content length (%u) is larger than file_quota (%u) for file id==%u', __CLASS__, intval($filesize), common_config('attachments', 'file_quota'), $file->getID()));
                 return true;
             }
 
-            $http = new HTTPClient();
             // Then we download the file to memory and test whether it's actually an image file
             common_debug(sprintf('Downloading remote file id==%u (should be size %u) with effective URL: %s', $file->getID(), $filesize, _ve($remoteUrl)));
-            $imgData = $http->get($remoteUrl);
+            $imgData = HTTPClient::quickGet($remoteUrl);
         } catch (HTTP_Request2_ConnectionException $e) {
-            common_log(LOG_ERR, __CLASS__.': quickGet on URL: '._ve($file->getUrl()).' threw exception: '.$e->getMessage());
+            common_log(LOG_ERR, __CLASS__.': '._ve(get_class($e)).' on URL: '._ve($file->getUrl()).' threw exception: '.$e->getMessage());
             return true;
         }
         $info = @getimagesizefromstring($imgData);