aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Url.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/Url.php')
-rw-r--r--application/Url.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/application/Url.php b/application/Url.php
index af38c4d9..c166ff6e 100644
--- a/application/Url.php
+++ b/application/Url.php
@@ -62,7 +62,21 @@ function add_trailing_slash($url)
62{ 62{
63 return $url . (!endsWith($url, '/') ? '/' : ''); 63 return $url . (!endsWith($url, '/') ? '/' : '');
64} 64}
65/**
66 * Converts an URL with an IDN host to a ASCII one.
67 *
68 * @param string $url Input URL.
69 *
70 * @return string converted URL.
71 */
72function url_with_idn_to_ascii($url)
73{
74 $parts = parse_url($url);
75 $parts['host'] = idn_to_ascii($parts['host']);
65 76
77 $httpUrl = new \http\Url($parts);
78 return $httpUrl->toString();
79}
66/** 80/**
67 * URL representation and cleanup utilities 81 * URL representation and cleanup utilities
68 * 82 *
@@ -85,6 +99,7 @@ class Url
85 'action_type_map=', 99 'action_type_map=',
86 'fb_', 100 'fb_',
87 'fb=', 101 'fb=',
102 'PHPSESSID=',
88 103
89 // Scoop.it 104 // Scoop.it
90 '__scoop', 105 '__scoop',
@@ -221,6 +236,22 @@ class Url
221 } 236 }
222 237
223 /** 238 /**
239 * Converts an URL with an International Domain Name host to a ASCII one.
240 * This requires PHP-intl. If it's not available, just returns this->cleanup().
241 *
242 * @return string converted cleaned up URL.
243 */
244 public function idnToAscii()
245 {
246 $out = $this->cleanup();
247 if (! function_exists('idn_to_ascii') || ! isset($this->parts['host'])) {
248 return $out;
249 }
250 $asciiHost = idn_to_ascii($this->parts['host']);
251 return str_replace($this->parts['host'], $asciiHost, $out);
252 }
253
254 /**
224 * Get URL scheme. 255 * Get URL scheme.
225 * 256 *
226 * @return string the URL scheme or false if none is provided. 257 * @return string the URL scheme or false if none is provided.
@@ -233,6 +264,18 @@ class Url
233 } 264 }
234 265
235 /** 266 /**
267 * Get URL host.
268 *
269 * @return string the URL host or false if none is provided.
270 */
271 public function getHost() {
272 if (empty($this->parts['host'])) {
273 return false;
274 }
275 return $this->parts['host'];
276 }
277
278 /**
236 * Test if the Url is an HTTP one. 279 * Test if the Url is an HTTP one.
237 * 280 *
238 * @return true is HTTP, false otherwise. 281 * @return true is HTTP, false otherwise.