aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/bookmark/LinkDB.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/bookmark/LinkDB.php')
-rw-r--r--application/bookmark/LinkDB.php47
1 files changed, 11 insertions, 36 deletions
diff --git a/application/bookmark/LinkDB.php b/application/bookmark/LinkDB.php
index c13a1141..efde8468 100644
--- a/application/bookmark/LinkDB.php
+++ b/application/bookmark/LinkDB.php
@@ -29,10 +29,10 @@ use Shaarli\FileUtils;
29 * - private: Is this link private? 0=no, other value=yes 29 * - private: Is this link private? 0=no, other value=yes
30 * - tags: tags attached to this entry (separated by spaces) 30 * - tags: tags attached to this entry (separated by spaces)
31 * - title Title of the link 31 * - title Title of the link
32 * - url URL of the link. Used for displayable links (no redirector, relative, etc.). 32 * - url URL of the link. Used for displayable links.
33 * Can be absolute or relative. 33 * Can be absolute or relative in the database but the relative links
34 * Relative URLs are permalinks (e.g.'?m-ukcw') 34 * will be converted to absolute ones in templates.
35 * - real_url Absolute processed URL. 35 * - real_url Raw URL in stored in the DB (absolute or relative).
36 * - shorturl Permalink smallhash 36 * - shorturl Permalink smallhash
37 * 37 *
38 * Implements 3 interfaces: 38 * Implements 3 interfaces:
@@ -88,19 +88,6 @@ class LinkDB implements Iterator, Countable, ArrayAccess
88 // Hide public links 88 // Hide public links
89 private $hidePublicLinks; 89 private $hidePublicLinks;
90 90
91 // link redirector set in user settings.
92 private $redirector;
93
94 /**
95 * Set this to `true` to urlencode link behind redirector link, `false` to leave it untouched.
96 *
97 * Example:
98 * anonym.to needs clean URL while dereferer.org needs urlencoded URL.
99 *
100 * @var boolean $redirectorEncode parameter: true or false
101 */
102 private $redirectorEncode;
103
104 /** 91 /**
105 * Creates a new LinkDB 92 * Creates a new LinkDB
106 * 93 *
@@ -109,22 +96,16 @@ class LinkDB implements Iterator, Countable, ArrayAccess
109 * @param string $datastore datastore file path. 96 * @param string $datastore datastore file path.
110 * @param boolean $isLoggedIn is the user logged in? 97 * @param boolean $isLoggedIn is the user logged in?
111 * @param boolean $hidePublicLinks if true all links are private. 98 * @param boolean $hidePublicLinks if true all links are private.
112 * @param string $redirector link redirector set in user settings.
113 * @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true).
114 */ 99 */
115 public function __construct( 100 public function __construct(
116 $datastore, 101 $datastore,
117 $isLoggedIn, 102 $isLoggedIn,
118 $hidePublicLinks, 103 $hidePublicLinks
119 $redirector = '',
120 $redirectorEncode = true
121 ) { 104 ) {
122 105
123 $this->datastore = $datastore; 106 $this->datastore = $datastore;
124 $this->loggedIn = $isLoggedIn; 107 $this->loggedIn = $isLoggedIn;
125 $this->hidePublicLinks = $hidePublicLinks; 108 $this->hidePublicLinks = $hidePublicLinks;
126 $this->redirector = $redirector;
127 $this->redirectorEncode = $redirectorEncode === true;
128 $this->check(); 109 $this->check();
129 $this->read(); 110 $this->read();
130 } 111 }
@@ -271,7 +252,8 @@ You use the community supported version of the original Shaarli project, by Seba
271 ), 252 ),
272 'private' => 0, 253 'private' => 0,
273 'created' => new DateTime(), 254 'created' => new DateTime(),
274 'tags' => 'opensource software' 255 'tags' => 'opensource software',
256 'sticky' => false,
275 ); 257 );
276 $link['shorturl'] = link_small_hash($link['created'], $link['id']); 258 $link['shorturl'] = link_small_hash($link['created'], $link['id']);
277 $this->links[1] = $link; 259 $this->links[1] = $link;
@@ -284,6 +266,7 @@ You use the community supported version of the original Shaarli project, by Seba
284 'private' => 1, 266 'private' => 1,
285 'created' => new DateTime('1 minute ago'), 267 'created' => new DateTime('1 minute ago'),
286 'tags' => 'secretstuff', 268 'tags' => 'secretstuff',
269 'sticky' => false,
287 ); 270 );
288 $link['shorturl'] = link_small_hash($link['created'], $link['id']); 271 $link['shorturl'] = link_small_hash($link['created'], $link['id']);
289 $this->links[0] = $link; 272 $this->links[0] = $link;
@@ -323,17 +306,9 @@ You use the community supported version of the original Shaarli project, by Seba
323 $link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']); 306 $link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']);
324 } 307 }
325 308
326 // Do not use the redirector for internal links (Shaarli note URL starting with a '?'). 309 $link['real_url'] = $link['url'];
327 if (!empty($this->redirector) && !startsWith($link['url'], '?')) { 310
328 $link['real_url'] = $this->redirector; 311 $link['sticky'] = isset($link['sticky']) ? $link['sticky'] : false;
329 if ($this->redirectorEncode) {
330 $link['real_url'] .= urlencode(unescape($link['url']));
331 } else {
332 $link['real_url'] .= $link['url'];
333 }
334 } else {
335 $link['real_url'] = $link['url'];
336 }
337 312
338 // To be able to load links before running the update, and prepare the update 313 // To be able to load links before running the update, and prepare the update
339 if (!isset($link['created'])) { 314 if (!isset($link['created'])) {