aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Url.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-04-06 22:00:52 +0200
committerArthurHoaro <arthur@hoa.ro>2016-05-03 19:51:29 +0200
commitce7b0b6480aa854ee6893f5c889277b0e3b13efc (patch)
tree8d8beb4ea5568d9989a5ebf52e2adc542e17f74e /application/Url.php
parent11609d9fd8ba53f049e6c913d8e3affab6cfc9ce (diff)
downloadShaarli-ce7b0b6480aa854ee6893f5c889277b0e3b13efc.tar.gz
Shaarli-ce7b0b6480aa854ee6893f5c889277b0e3b13efc.tar.zst
Shaarli-ce7b0b6480aa854ee6893f5c889277b0e3b13efc.zip
Fixes #531 - Title retrieving is failing with multiple use case
see https://github.com/shaarli/Shaarli/issues/531 for details
Diffstat (limited to 'application/Url.php')
-rw-r--r--application/Url.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/application/Url.php b/application/Url.php
index af38c4d9..61a30a78 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 *
@@ -221,6 +235,22 @@ class Url
221 } 235 }
222 236
223 /** 237 /**
238 * Converts an URL with an International Domain Name host to a ASCII one.
239 * This requires PHP-intl. If it's not available, just returns this->cleanup().
240 *
241 * @return string converted cleaned up URL.
242 */
243 public function indToAscii()
244 {
245 $out = $this->cleanup();
246 if (! function_exists('idn_to_ascii') || ! isset($this->parts['host'])) {
247 return $out;
248 }
249 $asciiHost = idn_to_ascii($this->parts['host']);
250 return str_replace($this->parts['host'], $asciiHost, $out);
251 }
252
253 /**
224 * Get URL scheme. 254 * Get URL scheme.
225 * 255 *
226 * @return string the URL scheme or false if none is provided. 256 * @return string the URL scheme or false if none is provided.
@@ -233,6 +263,18 @@ class Url
233 } 263 }
234 264
235 /** 265 /**
266 * Get URL host.
267 *
268 * @return string the URL host or false if none is provided.
269 */
270 public function getHost() {
271 if (empty($this->parts['host'])) {
272 return false;
273 }
274 return $this->parts['host'];
275 }
276
277 /**
236 * Test if the Url is an HTTP one. 278 * Test if the Url is an HTTP one.
237 * 279 *
238 * @return true is HTTP, false otherwise. 280 * @return true is HTTP, false otherwise.