]> git.mxchange.org Git - friendica.git/commitdiff
Simplyfying code
authorMichael <heluecht@pirati.ca>
Mon, 5 Jul 2021 04:16:02 +0000 (04:16 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 5 Jul 2021 04:16:02 +0000 (04:16 +0000)
src/Module/Proxy.php
src/Util/Proxy.php

index 6ccc38f60d7000829bafe7307378aeb72eb485f7..b1683e8f5b4082e4c76e129c9e63fa0747ddc4bc 100644 (file)
@@ -40,10 +40,7 @@ class Proxy extends BaseModule
 {
 
        /**
-        * Initializer method for this class.
-        *
-        * Sets application instance and checks if /proxy/ path is writable.
-        *
+        * Fetch remote image content
         */
        public static function rawContent(array $parameters = [])
        {
@@ -81,8 +78,7 @@ class Proxy extends BaseModule
                $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['timeout' => 10]);
                $img_str = $fetchResult->getBody();
 
-               // If there is an error then return an error
-               if ((substr($fetchResult->getReturnCode(), 0, 1) == '4') || empty($img_str)) {
+               if (!$fetchResult->isSuccess() || empty($img_str)) {
                        Logger::info('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]);
                        self::responseError();
                        // stop.
index 839442797ef8ed3b7a29bb3df63874266952fe7e..16e3e221ff5c0da7dab239eb27e089b3aa80bb05 100644 (file)
@@ -87,21 +87,11 @@ class Proxy
         */
        public static function proxifyUrl($url, $size = '')
        {
-               // Get application instance
-               $a = DI::app();
-
                // Trim URL first
                $url = trim($url);
 
-               // Is no http in front of it?
-               /// @TODO To weak test for being a valid URL
-               if (substr($url, 0, 4) !== 'http') {
-                       return $url;
-               }
-
-               // Only continue if it isn't a local image and the isn't deactivated
-               if (self::isLocalImage($url)) {
-                       $url = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/', DI::baseUrl() . '/', $url);
+               // Quit if not an HTTP/HTTPS link or if local
+               if (!in_array(parse_url($url, PHP_URL_SCHEME), ['http', 'https']) || self::isLocalImage($url)) {
                        return $url;
                }
 
@@ -175,11 +165,7 @@ class Proxy
                        return true;
                }
 
-               // links normalised - bug #431
-               $baseurl = Strings::normaliseLink(DI::baseUrl());
-               $url = Strings::normaliseLink($url);
-
-               return (substr($url, 0, strlen($baseurl)) == $baseurl);
+               return Network::isLocalLink($url);
        }
 
        /**