aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/Router.php6
-rw-r--r--application/Thumbnailer.php2
-rw-r--r--application/api/ApiMiddleware.php4
-rw-r--r--application/api/ApiUtils.php2
-rw-r--r--application/bookmark/LinkDB.php47
-rw-r--r--application/bookmark/LinkUtils.php37
-rw-r--r--application/config/ConfigManager.php4
-rw-r--r--application/feed/FeedBuilder.php6
-rw-r--r--application/netscape/NetscapeBookmarkUtils.php2
-rw-r--r--application/render/PageBuilder.php2
-rw-r--r--application/updater/Updater.php11
11 files changed, 53 insertions, 70 deletions
diff --git a/application/Router.php b/application/Router.php
index 05877acd..d7187487 100644
--- a/application/Router.php
+++ b/application/Router.php
@@ -38,6 +38,8 @@ class Router
38 38
39 public static $PAGE_DELETELINK = 'delete_link'; 39 public static $PAGE_DELETELINK = 'delete_link';
40 40
41 public static $PAGE_CHANGE_VISIBILITY = 'change_visibility';
42
41 public static $PAGE_PINLINK = 'pin'; 43 public static $PAGE_PINLINK = 'pin';
42 44
43 public static $PAGE_EXPORT = 'export'; 45 public static $PAGE_EXPORT = 'export';
@@ -149,6 +151,10 @@ class Router
149 return self::$PAGE_DELETELINK; 151 return self::$PAGE_DELETELINK;
150 } 152 }
151 153
154 if (isset($get[self::$PAGE_CHANGE_VISIBILITY])) {
155 return self::$PAGE_CHANGE_VISIBILITY;
156 }
157
152 if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) { 158 if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
153 return self::$PAGE_PINLINK; 159 return self::$PAGE_PINLINK;
154 } 160 }
diff --git a/application/Thumbnailer.php b/application/Thumbnailer.php
index a23f98e9..d5f5ac28 100644
--- a/application/Thumbnailer.php
+++ b/application/Thumbnailer.php
@@ -55,7 +55,7 @@ class Thumbnailer
55 $this->conf = $conf; 55 $this->conf = $conf;
56 56
57 if (! $this->checkRequirements()) { 57 if (! $this->checkRequirements()) {
58 $this->conf->set('thumbnails.enabled', false); 58 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_NONE);
59 $this->conf->write(true); 59 $this->conf->write(true);
60 // TODO: create a proper error handling system able to catch exceptions... 60 // TODO: create a proper error handling system able to catch exceptions...
61 die(t( 61 die(t(
diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php
index 5ffb8c6d..2d55bda6 100644
--- a/application/api/ApiMiddleware.php
+++ b/application/api/ApiMiddleware.php
@@ -129,9 +129,7 @@ class ApiMiddleware
129 $linkDb = new \Shaarli\Bookmark\LinkDB( 129 $linkDb = new \Shaarli\Bookmark\LinkDB(
130 $conf->get('resource.datastore'), 130 $conf->get('resource.datastore'),
131 true, 131 true,
132 $conf->get('privacy.hide_public_links'), 132 $conf->get('privacy.hide_public_links')
133 $conf->get('redirector.url'),
134 $conf->get('redirector.encode_url')
135 ); 133 );
136 $this->container['db'] = $linkDb; 134 $this->container['db'] = $linkDb;
137 } 135 }
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php
index 1824b5d0..1e3ac02e 100644
--- a/application/api/ApiUtils.php
+++ b/application/api/ApiUtils.php
@@ -59,7 +59,7 @@ class ApiUtils
59 { 59 {
60 $out['id'] = $link['id']; 60 $out['id'] = $link['id'];
61 // Not an internal link 61 // Not an internal link
62 if ($link['url'][0] != '?') { 62 if (! is_note($link['url'])) {
63 $out['url'] = $link['url']; 63 $out['url'] = $link['url'];
64 } else { 64 } else {
65 $out['url'] = $indexUrl . $link['url']; 65 $out['url'] = $indexUrl . $link['url'];
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'])) {
diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php
index de5b61cb..35a5b290 100644
--- a/application/bookmark/LinkUtils.php
+++ b/application/bookmark/LinkUtils.php
@@ -133,29 +133,15 @@ function count_private($links)
133 * In a string, converts URLs to clickable links. 133 * In a string, converts URLs to clickable links.
134 * 134 *
135 * @param string $text input string. 135 * @param string $text input string.
136 * @param string $redirector if a redirector is set, use it to gerenate links.
137 * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not.
138 * 136 *
139 * @return string returns $text with all links converted to HTML links. 137 * @return string returns $text with all links converted to HTML links.
140 * 138 *
141 * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722 139 * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722
142 */ 140 */
143function text2clickable($text, $redirector = '', $urlEncode = true) 141function text2clickable($text)
144{ 142{
145 $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si'; 143 $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si';
146 144 return preg_replace($regex, '<a href="$1">$1</a>', $text);
147 if (empty($redirector)) {
148 return preg_replace($regex, '<a href="$1">$1</a>', $text);
149 }
150 // Redirector is set, urlencode the final URL.
151 return preg_replace_callback(
152 $regex,
153 function ($matches) use ($redirector, $urlEncode) {
154 $url = $urlEncode ? urlencode($matches[1]) : $matches[1];
155 return '<a href="' . $redirector . $url .'">'. $matches[1] .'</a>';
156 },
157 $text
158 );
159} 145}
160 146
161/** 147/**
@@ -197,15 +183,13 @@ function space2nbsp($text)
197 * Format Shaarli's description 183 * Format Shaarli's description
198 * 184 *
199 * @param string $description shaare's description. 185 * @param string $description shaare's description.
200 * @param string $redirector if a redirector is set, use it to gerenate links.
201 * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not.
202 * @param string $indexUrl URL to Shaarli's index. 186 * @param string $indexUrl URL to Shaarli's index.
203 187
204 * @return string formatted description. 188 * @return string formatted description.
205 */ 189 */
206function format_description($description, $redirector = '', $urlEncode = true, $indexUrl = '') 190function format_description($description, $indexUrl = '')
207{ 191{
208 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector, $urlEncode), $indexUrl))); 192 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description), $indexUrl)));
209} 193}
210 194
211/** 195/**
@@ -220,3 +204,16 @@ function link_small_hash($date, $id)
220{ 204{
221 return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id); 205 return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id);
222} 206}
207
208/**
209 * Returns whether or not the link is an internal note.
210 * Its URL starts by `?` because it's actually a permalink.
211 *
212 * @param string $linkUrl
213 *
214 * @return bool true if internal note, false otherwise.
215 */
216function is_note($linkUrl)
217{
218 return isset($linkUrl[0]) && $linkUrl[0] === '?';
219}
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php
index e6c35073..30993928 100644
--- a/application/config/ConfigManager.php
+++ b/application/config/ConfigManager.php
@@ -221,7 +221,6 @@ class ConfigManager
221 'general.title', 221 'general.title',
222 'general.header_link', 222 'general.header_link',
223 'privacy.default_private_links', 223 'privacy.default_private_links',
224 'redirector.url',
225 ); 224 );
226 225
227 // Only logged in user can alter config. 226 // Only logged in user can alter config.
@@ -381,9 +380,6 @@ class ConfigManager
381 // default state of the 'remember me' checkbox of the login form 380 // default state of the 'remember me' checkbox of the login form
382 $this->setEmpty('privacy.remember_user_default', true); 381 $this->setEmpty('privacy.remember_user_default', true);
383 382
384 $this->setEmpty('redirector.url', '');
385 $this->setEmpty('redirector.encode_url', true);
386
387 $this->setEmpty('thumbnails.width', '125'); 383 $this->setEmpty('thumbnails.width', '125');
388 $this->setEmpty('thumbnails.height', '90'); 384 $this->setEmpty('thumbnails.height', '90');
389 385
diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php
index b66f2f91..7c859474 100644
--- a/application/feed/FeedBuilder.php
+++ b/application/feed/FeedBuilder.php
@@ -147,8 +147,8 @@ class FeedBuilder
147 protected function buildItem($link, $pageaddr) 147 protected function buildItem($link, $pageaddr)
148 { 148 {
149 $link['guid'] = $pageaddr . '?' . $link['shorturl']; 149 $link['guid'] = $pageaddr . '?' . $link['shorturl'];
150 // Check for both signs of a note: starting with ? and 7 chars long. 150 // Prepend the root URL for notes
151 if ($link['url'][0] === '?' && strlen($link['url']) === 7) { 151 if (is_note($link['url'])) {
152 $link['url'] = $pageaddr . $link['url']; 152 $link['url'] = $pageaddr . $link['url'];
153 } 153 }
154 if ($this->usePermalinks === true) { 154 if ($this->usePermalinks === true) {
@@ -156,7 +156,7 @@ class FeedBuilder
156 } else { 156 } else {
157 $permalink = '<a href="' . $link['guid'] . '" title="' . t('Permalink') . '">' . t('Permalink') . '</a>'; 157 $permalink = '<a href="' . $link['guid'] . '" title="' . t('Permalink') . '">' . t('Permalink') . '</a>';
158 } 158 }
159 $link['description'] = format_description($link['description'], '', false, $pageaddr); 159 $link['description'] = format_description($link['description'], $pageaddr);
160 $link['description'] .= PHP_EOL . '<br>&#8212; ' . $permalink; 160 $link['description'] .= PHP_EOL . '<br>&#8212; ' . $permalink;
161 161
162 $pubDate = $link['created']; 162 $pubDate = $link['created'];
diff --git a/application/netscape/NetscapeBookmarkUtils.php b/application/netscape/NetscapeBookmarkUtils.php
index 2fb1a4a6..28665941 100644
--- a/application/netscape/NetscapeBookmarkUtils.php
+++ b/application/netscape/NetscapeBookmarkUtils.php
@@ -54,7 +54,7 @@ class NetscapeBookmarkUtils
54 $link['timestamp'] = $date->getTimestamp(); 54 $link['timestamp'] = $date->getTimestamp();
55 $link['taglist'] = str_replace(' ', ',', $link['tags']); 55 $link['taglist'] = str_replace(' ', ',', $link['tags']);
56 56
57 if (startsWith($link['url'], '?') && $prependNoteUrl) { 57 if (is_note($link['url']) && $prependNoteUrl) {
58 $link['url'] = $indexUrl . $link['url']; 58 $link['url'] = $indexUrl . $link['url'];
59 } 59 }
60 60
diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php
index 0569b67f..3f86fc26 100644
--- a/application/render/PageBuilder.php
+++ b/application/render/PageBuilder.php
@@ -123,6 +123,8 @@ class PageBuilder
123 $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); 123 $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
124 $this->tpl->assign('token', $this->token); 124 $this->tpl->assign('token', $this->token);
125 125
126 $this->tpl->assign('language', $this->conf->get('translation.language'));
127
126 if ($this->linkDB !== null) { 128 if ($this->linkDB !== null) {
127 $this->tpl->assign('tags', $this->linkDB->linksCountPerTag()); 129 $this->tpl->assign('tags', $this->linkDB->linksCountPerTag());
128 } 130 }
diff --git a/application/updater/Updater.php b/application/updater/Updater.php
index f12e3516..beb9ea9b 100644
--- a/application/updater/Updater.php
+++ b/application/updater/Updater.php
@@ -218,7 +218,6 @@ class Updater
218 try { 218 try {
219 $this->conf->set('general.title', escape($this->conf->get('general.title'))); 219 $this->conf->set('general.title', escape($this->conf->get('general.title')));
220 $this->conf->set('general.header_link', escape($this->conf->get('general.header_link'))); 220 $this->conf->set('general.header_link', escape($this->conf->get('general.header_link')));
221 $this->conf->set('redirector.url', escape($this->conf->get('redirector.url')));
222 $this->conf->write($this->isLoggedIn); 221 $this->conf->write($this->isLoggedIn);
223 } catch (Exception $e) { 222 } catch (Exception $e) {
224 error_log($e->getMessage()); 223 error_log($e->getMessage());
@@ -550,4 +549,14 @@ class Updater
550 549
551 return true; 550 return true;
552 } 551 }
552
553 /**
554 * Remove redirector settings.
555 */
556 public function updateMethodRemoveRedirector()
557 {
558 $this->conf->remove('redirector');
559 $this->conf->write(true);
560 return true;
561 }
553} 562}