X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fhttp%2FUrl.php;fp=application%2FUrl.php;h=90444a2f4beaf0ad15df3be06ff36d4431d61811;hb=d9f6275ebca035fec8331652c677981056793ccc;hp=3b7f19c207770679d2fff77a709210529ffa2afa;hpb=38672ba0d1c722e5d6d33a58255ceb55e9410e46;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Url.php b/application/http/Url.php similarity index 63% rename from application/Url.php rename to application/http/Url.php index 3b7f19c2..90444a2f 100644 --- a/application/Url.php +++ b/application/http/Url.php @@ -1,91 +1,6 @@ cleanup(); -} - -/** - * Get URL scheme. - * - * @param string url Url for which the scheme is requested - * - * @return mixed the URL scheme or false if none is provided. - */ -function get_url_scheme($url) -{ - $obj_url = new Url($url); - return $obj_url->getScheme(); -} - -/** - * Adds a trailing slash at the end of URL if necessary. - * - * @param string $url URL to check/edit. - * - * @return string $url URL with a end trailing slash. - */ -function add_trailing_slash($url) -{ - return $url . (!endsWith($url, '/') ? '/' : ''); -} - -/** - * Replace not whitelisted protocols by 'http://' from given URL. - * - * @param string $url URL to clean - * @param array $protocols List of allowed protocols (aside from http(s)). - * - * @return string URL with allowed protocol - */ -function whitelist_protocols($url, $protocols) -{ - if (startsWith($url, '?') || startsWith($url, '/')) { - return $url; - } - $protocols = array_merge(['http', 'https'], $protocols); - $protocol = preg_match('#^(\w+):/?/?#', $url, $match); - // Protocol not allowed: we remove it and replace it with http - if ($protocol === 1 && ! in_array($match[1], $protocols)) { - $url = str_replace($match[0], 'http://', $url); - } elseif ($protocol !== 1) { - $url = 'http://' . $url; - } - return $url; -} +namespace Shaarli\Http; /** * URL representation and cleanup utilities @@ -182,7 +97,7 @@ class Url } return $input; } - + /** * Returns a string representation of this URL */ @@ -196,7 +111,7 @@ class Url */ protected function cleanupQuery() { - if (! isset($this->parts['query'])) { + if (!isset($this->parts['query'])) { return; } @@ -224,7 +139,7 @@ class Url */ protected function cleanupFragment() { - if (! isset($this->parts['fragment'])) { + if (!isset($this->parts['fragment'])) { return; } @@ -257,7 +172,7 @@ class Url public function idnToAscii() { $out = $this->cleanup(); - if (! function_exists('idn_to_ascii') || ! isset($this->parts['host'])) { + if (!function_exists('idn_to_ascii') || !isset($this->parts['host'])) { return $out; } $asciiHost = idn_to_ascii($this->parts['host'], 0, INTL_IDNA_VARIANT_UTS46); @@ -291,7 +206,7 @@ class Url } /** - * Test if the Url is an HTTP one. + * Test if the UrlUtils is an HTTP one. * * @return true is HTTP, false otherwise. */