aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Url.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-03-24 19:01:40 +0100
committerArthurHoaro <arthur@hoa.ro>2016-03-26 16:26:23 +0100
commitc9da01e749e5319d0c0f400cde06e71c0e7312d5 (patch)
tree5150c9af94115efd5908b4e8d7e6f4a3c6a71cc8 /application/Url.php
parentecd051905f0c8aa97590eb453d553dc678125a50 (diff)
downloadShaarli-c9da01e749e5319d0c0f400cde06e71c0e7312d5.tar.gz
Shaarli-c9da01e749e5319d0c0f400cde06e71c0e7312d5.tar.zst
Shaarli-c9da01e749e5319d0c0f400cde06e71c0e7312d5.zip
Refactor and rebase #380: Firefox reader view links
Fixes #366 Closes #380
Diffstat (limited to 'application/Url.php')
-rw-r--r--application/Url.php42
1 files changed, 29 insertions, 13 deletions
diff --git a/application/Url.php b/application/Url.php
index e7c3a4cc..af38c4d9 100644
--- a/application/Url.php
+++ b/application/Url.php
@@ -118,24 +118,41 @@ 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';
125 } 126 }
126 } 127 }
127 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 }
128 141
129 private function removeFirefoxAboutReader($input){ 142 /**
130 $output_array = []; 143 * Remove Firefox Reader prefix if it's present.
131 preg_match("%^about://reader\?url=(.*)%", $input, $output_array); 144 *
132 if(!empty($output_array)){ 145 * @param string $input url
133 $extractedUrl = preg_replace("%^about://reader\?url=(.*)%", "$1", $input); 146 *
134 $url = urldecode($extractedUrl); 147 * @return string cleaned url
135 }else{ 148 */
136 $url = $input; 149 protected static function removeFirefoxAboutReader($input)
137 } 150 {
138 return $url; 151 $firefoxPrefix = 'about://reader?url=';
152 if (startsWith($input, $firefoxPrefix)) {
153 return urldecode(ltrim($input, $firefoxPrefix));
154 }
155 return $input;
139 } 156 }
140 157
141 /** 158 /**
@@ -200,8 +217,7 @@ class Url
200 { 217 {
201 $this->cleanupQuery(); 218 $this->cleanupQuery();
202 $this->cleanupFragment(); 219 $this->cleanupFragment();
203 $url = $this->toString(); 220 return $this->toString();
204 return $this->removeFirefoxAboutReader($url);
205 } 221 }
206 222
207 /** 223 /**