X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FUrl.php;h=a4ac2e73cad2537ab28cd6bb604356bd311d14d7;hb=fc17813bd1888aeace1e74a15c10ba79043a87f8;hp=af43b457961729f3a5c2abc82a407b4a402531ec;hpb=a7921b2445f5a7f13a09290b2a66c5bee82265d2;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Url.php b/application/Url.php index af43b457..a4ac2e73 100644 --- a/application/Url.php +++ b/application/Url.php @@ -51,6 +51,18 @@ function get_url_scheme($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, '/') ? '/' : ''); +} + /** * URL representation and cleanup utilities * @@ -106,7 +118,7 @@ class Url */ public function __construct($url) { - $this->parts = parse_url($url); + $this->parts = parse_url(trim($url)); if (!empty($url) && empty($this->parts['scheme'])) { $this->parts['scheme'] = 'http'; @@ -189,4 +201,13 @@ class Url } return $this->parts['scheme']; } + + /** + * Test if the Url is an HTTP one. + * + * @return true is HTTP, false otherwise. + */ + public function isHttp() { + return strpos(strtolower($this->parts['scheme']), 'http') !== false; + } }