]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Network.php
This fixes a problem when the URL is too long
[friendica.git] / src / Util / Network.php
index 0ff34f120ad9669f19015984c40f81c1bbd4d9d3..d4e18a8a63bb9177d69c553a5b9699c88931b310 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Network\CurlResult;
+use Friendica\Util\Strings;
 use DOMDocument;
 use DomXPath;
 
@@ -93,7 +94,12 @@ class Network
 
                $stamp1 = microtime(true);
 
-               $a = get_app();
+               $a = \get_app();
+
+               if (strlen($url) > 1000) {
+                       Logger::log('URL is longer than 1000 characters. Callstack: ' . System::callstack(20), Logger::DEBUG);
+                       return CurlResult::createErrorCurl(substr($url, 0, 200));
+               }
 
                $parts = parse_url($url);
                $path_parts = explode('/', defaults($parts, 'path', ''));
@@ -120,7 +126,7 @@ class Network
 
                @curl_setopt($ch, CURLOPT_HEADER, true);
 
-               if (x($opts, "cookiejar")) {
+               if (!empty($opts['cookiejar'])) {
                        curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]);
                        curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]);
                }
@@ -129,7 +135,7 @@ class Network
                //      @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                //      @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
 
-               if (x($opts, 'accept_content')) {
+               if (!empty($opts['accept_content'])) {
                        curl_setopt(
                                $ch,
                                CURLOPT_HTTPHEADER,
@@ -155,15 +161,15 @@ class Network
                /// @todo  We could possibly set this value to "gzip" or something similar
                curl_setopt($ch, CURLOPT_ENCODING, '');
 
-               if (x($opts, 'headers')) {
+               if (!empty($opts['headers'])) {
                        @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
                }
 
-               if (x($opts, 'nobody')) {
+               if (!empty($opts['nobody'])) {
                        @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']);
                }
 
-               if (x($opts, 'timeout')) {
+               if (!empty($opts['timeout'])) {
                        @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
                } else {
                        $curl_time = Config::get('system', 'curl_timeout', 60);
@@ -250,7 +256,7 @@ class Network
                        return CurlResult::createErrorCurl($url);
                }
 
-               $a = get_app();
+               $a = \get_app();
                $ch = curl_init($url);
 
                if (($redirects > 8) || (!$ch)) {
@@ -361,7 +367,7 @@ class Network
                /// @TODO Really suppress function outcomes? Why not find them + debug them?
                $h = @parse_url($url);
 
-               if ((is_array($h)) && (@dns_get_record($h['host'], DNS_A + DNS_CNAME) || filter_var($h['host'], FILTER_VALIDATE_IP) )) {
+               if (!empty($h['host']) && (@dns_get_record($h['host'], DNS_A + DNS_CNAME) || filter_var($h['host'], FILTER_VALIDATE_IP) )) {
                        return $url;
                }
 
@@ -488,7 +494,7 @@ class Network
                }
 
                $str_allowed = Config::get('system', 'allowed_email', '');
-               if (!x($str_allowed)) {
+               if (empty($str_allowed)) {
                        return true;
                }
 
@@ -603,7 +609,7 @@ class Network
         */
        public static function finalUrl($url, $depth = 1, $fetchbody = false)
        {
-               $a = get_app();
+               $a = \get_app();
 
                $url = self::stripTrackingQueryParams($url);
 
@@ -718,8 +724,8 @@ class Network
                        return "";
                }
 
-               $url1 = normalise_link($url1);
-               $url2 = normalise_link($url2);
+               $url1 = Strings::normaliseLink($url1);
+               $url2 = Strings::normaliseLink($url2);
 
                $parts1 = parse_url($url1);
                $parts2 = parse_url($url2);
@@ -790,7 +796,7 @@ class Network
 
                $match .= $path;
 
-               return normalise_link($match);
+               return Strings::normaliseLink($match);
        }
 
        /**