aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkDB.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-03-24 19:40:12 +0100
committerArthurHoaro <arthur@hoa.ro>2016-04-09 16:52:32 +0200
commit043eae70c4c57b0447b56a58b64ce9d102895396 (patch)
tree83a40e1f0096059bd9c7c13efbcfdeaa0ea06b5e /application/LinkDB.php
parent9486a2e92911c726673fe50674a0a408be3c774f (diff)
downloadShaarli-043eae70c4c57b0447b56a58b64ce9d102895396.tar.gz
Shaarli-043eae70c4c57b0447b56a58b64ce9d102895396.tar.zst
Shaarli-043eae70c4c57b0447b56a58b64ce9d102895396.zip
Fixes #480: add an option to urlencode redirector URL
* New config: `$GLOBALS['config']['REDIRECTOR_URLENCODE']` (default `true`). * Parameter added to LinkDB constructor. * Fixes a bug with urlencode and escaped url. * In `index.php`, LinkDB is now instanciate once for `importFile()` and `showDaily()`. * TU
Diffstat (limited to 'application/LinkDB.php')
-rw-r--r--application/LinkDB.php35
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'];