aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkDB.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2015-09-18 13:26:36 +0200
committerArthurHoaro <arthur@hoa.ro>2015-11-26 20:14:38 +0100
commit90e5bd65c9d4a5d3d5cedfeaa1314f2a15df5227 (patch)
tree7a085b9aecaa92aa5076df01df78c39edd2acff5 /application/LinkDB.php
parent986afb752bc57271e76935da9ed2df6ef8713cb7 (diff)
downloadShaarli-90e5bd65c9d4a5d3d5cedfeaa1314f2a15df5227.tar.gz
Shaarli-90e5bd65c9d4a5d3d5cedfeaa1314f2a15df5227.tar.zst
Shaarli-90e5bd65c9d4a5d3d5cedfeaa1314f2a15df5227.zip
URL encode links when a redirector is set.
Fixes #328 - URL encode links when a redirector is set * WARNING - template edit - new variable available : "real_url" Contains the final real url (redirected or any other change on original URL) * Don't redirect shaares link in RSS/Atom. * Affects links shaared in description. * Move text2clickable and keepMultipleSpaces to Utils.php + unit test UPDATE: * keepMultipleSpaces renamed to space2nbsp * space2nbsp improved to handle single space at line beginning * links in text description aren't 'nofollow' anymore
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