]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Proxy.php
in "getidforurl" "no update" is now "update"
[friendica.git] / src / Util / Proxy.php
index 0bb7537f78bda42a52edb9535d43a4eea453ab7a..e104073f0331e6f22cd9dfcdce9b829e39bb309a 100644 (file)
@@ -1,16 +1,30 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Util;
 
-use Friendica\BaseModule;
-use Friendica\BaseObject;
-use Friendica\Core\Config;
-use Friendica\Core\System;
-
-require_once 'include/security.php';
+use Friendica\DI;
 
 /**
- * @brief Proxy utilities class
+ * Proxy utilities class
  */
 class Proxy
 {
@@ -43,14 +57,14 @@ class Proxy
        ];
 
        /**
-        * @brief Private constructor
+        * Private constructor
         */
        private function __construct () {
                // No instances from utilities classes
        }
 
        /**
-        * @brief Transform a remote URL into a local one.
+        * Transform a remote URL into a local one.
         *
         * This function only performs the URL replacement on http URL and if the
         * provided URL isn't local, "the isn't deactivated" (sic) and if the config
@@ -61,11 +75,12 @@ class Proxy
         * @param string $size      One of the ProxyUtils::SIZE_* constants
         *
         * @return string The proxyfied URL or relative path
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function proxifyUrl($url, $writemode = false, $size = '')
        {
                // Get application instance
-               $a = BaseObject::getApp();
+               $a = DI::app();
 
                // Trim URL first
                $url = trim($url);
@@ -78,12 +93,12 @@ class Proxy
 
                // Only continue if it isn't a local image and the isn't deactivated
                if (self::isLocalImage($url)) {
-                       $url = str_replace(normalise_link(System::baseUrl()) . '/', System::baseUrl() . '/', $url);
+                       $url = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/', DI::baseUrl() . '/', $url);
                        return $url;
                }
 
                // Is the proxy disabled?
-               if (Config::get('system', 'proxy_disabled')) {
+               if (DI::config()->get('system', 'proxy_disabled')) {
                        return $url;
                }
 
@@ -111,7 +126,7 @@ class Proxy
                        $longpath .= '.' . $extension;
                }
 
-               $proxypath = System::baseUrl() . '/proxy/' . $longpath;
+               $proxypath = DI::baseUrl() . '/proxy/' . $longpath;
 
                if ($size != '') {
                        $size = ':' . $size;
@@ -122,7 +137,7 @@ class Proxy
                if ((strlen($proxypath) > 250) && $writemode) {
                        return $shortpath;
                } elseif (strlen($proxypath) > 250) {
-                       return System::baseUrl() . '/proxy/' . $shortpath . '?url=' . urlencode($url);
+                       return DI::baseUrl() . '/proxy/' . $shortpath . '?url=' . urlencode($url);
                } elseif ($writemode) {
                        return $longpath;
                } else {
@@ -131,7 +146,7 @@ class Proxy
        }
 
        /**
-        * @brief "Proxifies" HTML code's image tags
+        * "Proxifies" HTML code's image tags
         *
         * "Proxifies", means replaces image URLs in given HTML code with those from
         * proxy storage directory.
@@ -139,19 +154,21 @@ class Proxy
         * @param string $html Un-proxified HTML code
         *
         * @return string Proxified HTML code
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function proxifyHtml($html)
        {
-               $html = str_replace(normalise_link(System::baseUrl()) . '/', System::baseUrl() . '/', $html);
+               $html = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/', DI::baseUrl() . '/', $html);
 
                return preg_replace_callback('/(<img [^>]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', 'self::replaceUrl', $html);
        }
 
        /**
-        * @brief Checks if the URL is a local URL.
+        * Checks if the URL is a local URL.
         *
         * @param string $url
         * @return boolean
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        private static function isLocalImage($url)
        {
@@ -164,14 +181,14 @@ class Proxy
                }
 
                // links normalised - bug #431
-               $baseurl = normalise_link(System::baseUrl());
-               $url = normalise_link($url);
+               $baseurl = Strings::normaliseLink(DI::baseUrl());
+               $url = Strings::normaliseLink($url);
 
                return (substr($url, 0, strlen($baseurl)) == $baseurl);
        }
 
        /**
-        * @brief Return the array of query string parameters from a URL
+        * Return the array of query string parameters from a URL
         *
         * @param string $url URL to parse
         * @return array Associative array of query string parameters
@@ -187,10 +204,11 @@ class Proxy
        }
 
        /**
-        * @brief Call-back method to replace the UR
+        * Call-back method to replace the UR
         *
         * @param array $matches Matches from preg_replace_callback()
         * @return string Proxified HTML image tag
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        private static function replaceUrl(array $matches)
        {