aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkDB.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2015-11-26 23:05:58 +0100
committerVirtualTam <virtualtam@flibidi.net>2015-11-26 23:05:58 +0100
commit61873e3ded8dfba397b39aebd2322d0939c82caa (patch)
treea0cb54fb7223f23faa67bd90349a0981b9ef04e6 /application/LinkDB.php
parent657f0e25ba2c6f39775a8386b62d7c662ae709f7 (diff)
parent90e5bd65c9d4a5d3d5cedfeaa1314f2a15df5227 (diff)
downloadShaarli-61873e3ded8dfba397b39aebd2322d0939c82caa.tar.gz
Shaarli-61873e3ded8dfba397b39aebd2322d0939c82caa.tar.zst
Shaarli-61873e3ded8dfba397b39aebd2322d0939c82caa.zip
Merge pull request #355 from ArthurHoaro/redirector-url
URL encode links when a redirector is set
Diffstat (limited to 'application/LinkDB.php')
-rw-r--r--application/LinkDB.php20
1 files changed, 17 insertions, 3 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php
index 15fadbc3..f771ac8b 100644
--- a/application/LinkDB.php
+++ b/application/LinkDB.php
@@ -57,18 +57,25 @@ class LinkDB implements Iterator, Countable, ArrayAccess
57 // Hide public links 57 // Hide public links
58 private $_hidePublicLinks; 58 private $_hidePublicLinks;
59 59
60 // link redirector set in user settings.
61 private $_redirector;
62
60 /** 63 /**
61 * Creates a new LinkDB 64 * Creates a new LinkDB
62 * 65 *
63 * Checks if the datastore exists; else, attempts to create a dummy one. 66 * Checks if the datastore exists; else, attempts to create a dummy one.
64 * 67 *
65 * @param $isLoggedIn is the user logged in? 68 * @param string $datastore datastore file path.
69 * @param boolean $isLoggedIn is the user logged in?
70 * @param boolean $hidePublicLinks if true all links are private.
71 * @param string $redirector link redirector set in user settings.
66 */ 72 */
67 function __construct($datastore, $isLoggedIn, $hidePublicLinks) 73 function __construct($datastore, $isLoggedIn, $hidePublicLinks, $redirector = '')
68 { 74 {
69 $this->_datastore = $datastore; 75 $this->_datastore = $datastore;
70 $this->_loggedIn = $isLoggedIn; 76 $this->_loggedIn = $isLoggedIn;
71 $this->_hidePublicLinks = $hidePublicLinks; 77 $this->_hidePublicLinks = $hidePublicLinks;
78 $this->_redirector = $redirector;
72 $this->_checkDB(); 79 $this->_checkDB();
73 $this->_readDB(); 80 $this->_readDB();
74 } 81 }
@@ -259,7 +266,14 @@ You use the community supported version of the original Shaarli project, by Seba
259 266
260 // Escape links data 267 // Escape links data
261 foreach($this->_links as &$link) { 268 foreach($this->_links as &$link) {
262 sanitizeLink($link); 269 sanitizeLink($link);
270 // Do not use the redirector for internal links (Shaarli note URL starting with a '?').
271 if (!empty($this->_redirector) && !startsWith($link['url'], '?')) {
272 $link['real_url'] = $this->_redirector . urlencode($link['url']);
273 }
274 else {
275 $link['real_url'] = $link['url'];
276 }
263 } 277 }
264 } 278 }
265 279