diff options
author | Arthur <arthur@hoa.ro> | 2016-04-09 16:55:39 +0200 |
---|---|---|
committer | Arthur <arthur@hoa.ro> | 2016-04-09 16:55:39 +0200 |
commit | 9ad2950debf1d9e4528700854cf7c02daac9636d (patch) | |
tree | 83a40e1f0096059bd9c7c13efbcfdeaa0ea06b5e /application | |
parent | 9486a2e92911c726673fe50674a0a408be3c774f (diff) | |
parent | 043eae70c4c57b0447b56a58b64ce9d102895396 (diff) | |
download | Shaarli-9ad2950debf1d9e4528700854cf7c02daac9636d.tar.gz Shaarli-9ad2950debf1d9e4528700854cf7c02daac9636d.tar.zst Shaarli-9ad2950debf1d9e4528700854cf7c02daac9636d.zip |
Merge pull request #524 from ArthurHoaro/hotfix/redirectorurl
Fixes #480: add an option to urlencode redirector URL
Diffstat (limited to 'application')
-rw-r--r-- | application/LinkDB.php | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php index a62341fc..1cb70de0 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -66,21 +66,39 @@ class LinkDB implements Iterator, Countable, ArrayAccess | |||
66 | private $_redirector; | 66 | private $_redirector; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Set this to `true` to urlencode link behind redirector link, `false` to leave it untouched. | ||
70 | * | ||
71 | * Example: | ||
72 | * anonym.to needs clean URL while dereferer.org needs urlencoded URL. | ||
73 | * | ||
74 | * @var boolean $redirectorEncode parameter: true or false | ||
75 | */ | ||
76 | private $redirectorEncode; | ||
77 | |||
78 | /** | ||
69 | * Creates a new LinkDB | 79 | * Creates a new LinkDB |
70 | * | 80 | * |
71 | * Checks if the datastore exists; else, attempts to create a dummy one. | 81 | * Checks if the datastore exists; else, attempts to create a dummy one. |
72 | * | 82 | * |
73 | * @param string $datastore datastore file path. | 83 | * @param string $datastore datastore file path. |
74 | * @param boolean $isLoggedIn is the user logged in? | 84 | * @param boolean $isLoggedIn is the user logged in? |
75 | * @param boolean $hidePublicLinks if true all links are private. | 85 | * @param boolean $hidePublicLinks if true all links are private. |
76 | * @param string $redirector link redirector set in user settings. | 86 | * @param string $redirector link redirector set in user settings. |
87 | * @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true). | ||
77 | */ | 88 | */ |
78 | function __construct($datastore, $isLoggedIn, $hidePublicLinks, $redirector = '') | 89 | function __construct( |
90 | $datastore, | ||
91 | $isLoggedIn, | ||
92 | $hidePublicLinks, | ||
93 | $redirector = '', | ||
94 | $redirectorEncode = true | ||
95 | ) | ||
79 | { | 96 | { |
80 | $this->_datastore = $datastore; | 97 | $this->_datastore = $datastore; |
81 | $this->_loggedIn = $isLoggedIn; | 98 | $this->_loggedIn = $isLoggedIn; |
82 | $this->_hidePublicLinks = $hidePublicLinks; | 99 | $this->_hidePublicLinks = $hidePublicLinks; |
83 | $this->_redirector = $redirector; | 100 | $this->_redirector = $redirector; |
101 | $this->redirectorEncode = $redirectorEncode === true; | ||
84 | $this->_checkDB(); | 102 | $this->_checkDB(); |
85 | $this->_readDB(); | 103 | $this->_readDB(); |
86 | } | 104 | } |
@@ -278,7 +296,12 @@ You use the community supported version of the original Shaarli project, by Seba | |||
278 | 296 | ||
279 | // Do not use the redirector for internal links (Shaarli note URL starting with a '?'). | 297 | // Do not use the redirector for internal links (Shaarli note URL starting with a '?'). |
280 | if (!empty($this->_redirector) && !startsWith($link['url'], '?')) { | 298 | if (!empty($this->_redirector) && !startsWith($link['url'], '?')) { |
281 | $link['real_url'] = $this->_redirector . urlencode($link['url']); | 299 | $link['real_url'] = $this->_redirector; |
300 | if ($this->redirectorEncode) { | ||
301 | $link['real_url'] .= urlencode(unescape($link['url'])); | ||
302 | } else { | ||
303 | $link['real_url'] .= $link['url']; | ||
304 | } | ||
282 | } | 305 | } |
283 | else { | 306 | else { |
284 | $link['real_url'] = $link['url']; | 307 | $link['real_url'] = $link['url']; |