X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FNetwork.php;h=e4e9c5af5bb5a75673017425b6cc298057fa74ac;hb=58c8959da0ece9a23966b315310a3962542bc7f4;hp=4e4d329d3dee41515e3202fc67f56993babddff4;hpb=3282ce53894b624893ee2989747a59866ab4b137;p=friendica.git diff --git a/src/Util/Network.php b/src/Util/Network.php index 4e4d329d3d..e4e9c5af5b 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -4,13 +4,13 @@ */ namespace Friendica\Util; +use DOMDocument; +use DomXPath; +use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\System; -use Friendica\Core\Config; use Friendica\Network\CurlResult; -use DOMDocument; -use DomXPath; class Network { @@ -92,8 +92,6 @@ class Network */ public static function curl($url, $binary = false, &$redirects = 0, $opts = []) { - $ret = ['return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => '']; - $stamp1 = microtime(true); $a = \get_app(); @@ -103,6 +101,7 @@ class Network return CurlResult::createErrorCurl(substr($url, 0, 200)); } + $parts2 = []; $parts = parse_url($url); $path_parts = explode('/', defaults($parts, 'path', '')); foreach ($path_parts as $part) { @@ -233,7 +232,7 @@ class Network @curl_close($ch); - $a->saveTimestamp($stamp1, 'network'); + $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack()); return $curlResponse; } @@ -322,7 +321,6 @@ class Network $s = @curl_exec($ch); - $base = $s; $curl_info = curl_getinfo($ch); $curlResponse = new CurlResult($url, $s, $curl_info, curl_errno($ch), curl_error($ch)); @@ -336,7 +334,7 @@ class Network curl_close($ch); - $a->saveTimestamp($stamp1, 'network'); + $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack()); Logger::log('post_url: end ' . $url, Logger::DATA); @@ -461,7 +459,6 @@ class Network * @param string $url The url to check the domain from * * @return boolean - * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function isUrlBlocked($url) { @@ -643,7 +640,7 @@ class Network $http_code = $curl_info['http_code']; curl_close($ch); - $a->saveTimestamp($stamp1, "network"); + $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); if ($http_code == 0) { return $url; @@ -685,7 +682,7 @@ class Network $body = curl_exec($ch); curl_close($ch); - $a->saveTimestamp($stamp1, "network"); + $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); if (trim($body) == "") { return $url; @@ -838,4 +835,28 @@ class Network (strlen($query) ? "?".$query : '') . (strlen($fragment) ? "#".$fragment : ''); } + + + /** + * Switch the scheme of an url between http and https + * + * @param string $url URL + * + * @return string switched URL + */ + public static function switchScheme($url) + { + $scheme = parse_url($url, PHP_URL_SCHEME); + if (empty($scheme)) { + return $url; + } + + if ($scheme === 'http') { + $url = str_replace('http://', 'https://', $url); + } elseif ($scheme === 'https') { + $url = str_replace('https://', 'http://', $url); + } + + return $url; + } }