diff options
author | VirtualTam <virtualtam@flibidi.net> | 2016-03-30 19:31:19 +0200 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2016-03-30 19:31:19 +0200 |
commit | 11609d9fd8ba53f049e6c913d8e3affab6cfc9ce (patch) | |
tree | 027fb21385bdda3b177d6c2f1f1ea109bc869c02 /application | |
parent | 5f143b72eaafeda533fcb997ecca73d38258546e (diff) | |
parent | c9da01e749e5319d0c0f400cde06e71c0e7312d5 (diff) | |
download | Shaarli-11609d9fd8ba53f049e6c913d8e3affab6cfc9ce.tar.gz Shaarli-11609d9fd8ba53f049e6c913d8e3affab6cfc9ce.tar.zst Shaarli-11609d9fd8ba53f049e6c913d8e3affab6cfc9ce.zip |
Merge pull request #522 from ArthurHoaro/hotfix/readershaare
Refactor and rebase #380: Firefox reader view links
Diffstat (limited to 'application')
-rw-r--r-- | application/Url.php | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/application/Url.php b/application/Url.php index a4ac2e73..af38c4d9 100644 --- a/application/Url.php +++ b/application/Url.php | |||
@@ -118,7 +118,8 @@ class Url | |||
118 | */ | 118 | */ |
119 | public function __construct($url) | 119 | public function __construct($url) |
120 | { | 120 | { |
121 | $this->parts = parse_url(trim($url)); | 121 | $url = self::cleanupUnparsedUrl(trim($url)); |
122 | $this->parts = parse_url($url); | ||
122 | 123 | ||
123 | if (!empty($url) && empty($this->parts['scheme'])) { | 124 | if (!empty($url) && empty($this->parts['scheme'])) { |
124 | $this->parts['scheme'] = 'http'; | 125 | $this->parts['scheme'] = 'http'; |
@@ -126,6 +127,35 @@ class Url | |||
126 | } | 127 | } |
127 | 128 | ||
128 | /** | 129 | /** |
130 | * Clean up URL before it's parsed. | ||
131 | * ie. handle urlencode, url prefixes, etc. | ||
132 | * | ||
133 | * @param string $url URL to clean. | ||
134 | * | ||
135 | * @return string cleaned URL. | ||
136 | */ | ||
137 | protected static function cleanupUnparsedUrl($url) | ||
138 | { | ||
139 | return self::removeFirefoxAboutReader($url); | ||
140 | } | ||
141 | |||
142 | /** | ||
143 | * Remove Firefox Reader prefix if it's present. | ||
144 | * | ||
145 | * @param string $input url | ||
146 | * | ||
147 | * @return string cleaned url | ||
148 | */ | ||
149 | protected static function removeFirefoxAboutReader($input) | ||
150 | { | ||
151 | $firefoxPrefix = 'about://reader?url='; | ||
152 | if (startsWith($input, $firefoxPrefix)) { | ||
153 | return urldecode(ltrim($input, $firefoxPrefix)); | ||
154 | } | ||
155 | return $input; | ||
156 | } | ||
157 | |||
158 | /** | ||
129 | * Returns a string representation of this URL | 159 | * Returns a string representation of this URL |
130 | */ | 160 | */ |
131 | public function toString() | 161 | public function toString() |