From 520d29578c57e476ece3bdd20c286d196b7b61b4 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 9 Feb 2019 13:52:12 +0100 Subject: Remove the redirector setting Fixes #1239 --- application/api/ApiMiddleware.php | 4 +--- application/bookmark/LinkDB.php | 41 ++++++------------------------------ application/bookmark/LinkUtils.php | 24 ++++----------------- application/config/ConfigManager.php | 4 ---- application/feed/FeedBuilder.php | 2 +- application/updater/Updater.php | 11 +++++++++- 6 files changed, 22 insertions(+), 64 deletions(-) (limited to 'application') 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 $linkDb = new \Shaarli\Bookmark\LinkDB( $conf->get('resource.datastore'), true, - $conf->get('privacy.hide_public_links'), - $conf->get('redirector.url'), - $conf->get('redirector.encode_url') + $conf->get('privacy.hide_public_links') ); $this->container['db'] = $linkDb; } diff --git a/application/bookmark/LinkDB.php b/application/bookmark/LinkDB.php index c13a1141..266632e3 100644 --- a/application/bookmark/LinkDB.php +++ b/application/bookmark/LinkDB.php @@ -29,10 +29,10 @@ use Shaarli\FileUtils; * - private: Is this link private? 0=no, other value=yes * - tags: tags attached to this entry (separated by spaces) * - title Title of the link - * - url URL of the link. Used for displayable links (no redirector, relative, etc.). - * Can be absolute or relative. - * Relative URLs are permalinks (e.g.'?m-ukcw') - * - real_url Absolute processed URL. + * - url URL of the link. Used for displayable links. + * Can be absolute or relative in the database but the relative links + * will be converted to absolute ones in templates. + * - real_url Raw URL in stored in the DB (absolute or relative). * - shorturl Permalink smallhash * * Implements 3 interfaces: @@ -88,19 +88,6 @@ class LinkDB implements Iterator, Countable, ArrayAccess // Hide public links private $hidePublicLinks; - // link redirector set in user settings. - private $redirector; - - /** - * Set this to `true` to urlencode link behind redirector link, `false` to leave it untouched. - * - * Example: - * anonym.to needs clean URL while dereferer.org needs urlencoded URL. - * - * @var boolean $redirectorEncode parameter: true or false - */ - private $redirectorEncode; - /** * Creates a new LinkDB * @@ -109,22 +96,16 @@ class LinkDB implements Iterator, Countable, ArrayAccess * @param string $datastore datastore file path. * @param boolean $isLoggedIn is the user logged in? * @param boolean $hidePublicLinks if true all links are private. - * @param string $redirector link redirector set in user settings. - * @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true). */ public function __construct( $datastore, $isLoggedIn, - $hidePublicLinks, - $redirector = '', - $redirectorEncode = true + $hidePublicLinks ) { $this->datastore = $datastore; $this->loggedIn = $isLoggedIn; $this->hidePublicLinks = $hidePublicLinks; - $this->redirector = $redirector; - $this->redirectorEncode = $redirectorEncode === true; $this->check(); $this->read(); } @@ -323,17 +304,7 @@ You use the community supported version of the original Shaarli project, by Seba $link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']); } - // Do not use the redirector for internal links (Shaarli note URL starting with a '?'). - if (!empty($this->redirector) && !startsWith($link['url'], '?')) { - $link['real_url'] = $this->redirector; - if ($this->redirectorEncode) { - $link['real_url'] .= urlencode(unescape($link['url'])); - } else { - $link['real_url'] .= $link['url']; - } - } else { - $link['real_url'] = $link['url']; - } + $link['real_url'] = $link['url']; // To be able to load links before running the update, and prepare the update if (!isset($link['created'])) { diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php index de5b61cb..988970bd 100644 --- a/application/bookmark/LinkUtils.php +++ b/application/bookmark/LinkUtils.php @@ -133,29 +133,15 @@ function count_private($links) * In a string, converts URLs to clickable links. * * @param string $text input string. - * @param string $redirector if a redirector is set, use it to gerenate links. - * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not. * * @return string returns $text with all links converted to HTML links. * * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722 */ -function text2clickable($text, $redirector = '', $urlEncode = true) +function text2clickable($text) { $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si'; - - if (empty($redirector)) { - return preg_replace($regex, '$1', $text); - } - // Redirector is set, urlencode the final URL. - return preg_replace_callback( - $regex, - function ($matches) use ($redirector, $urlEncode) { - $url = $urlEncode ? urlencode($matches[1]) : $matches[1]; - return ''. $matches[1] .''; - }, - $text - ); + return preg_replace($regex, '$1', $text); } /** @@ -197,15 +183,13 @@ function space2nbsp($text) * Format Shaarli's description * * @param string $description shaare's description. - * @param string $redirector if a redirector is set, use it to gerenate links. - * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not. * @param string $indexUrl URL to Shaarli's index. * @return string formatted description. */ -function format_description($description, $redirector = '', $urlEncode = true, $indexUrl = '') +function format_description($description, $indexUrl = '') { - return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector, $urlEncode), $indexUrl))); + return nl2br(space2nbsp(hashtag_autolink(text2clickable($description), $indexUrl))); } /** 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 'general.title', 'general.header_link', 'privacy.default_private_links', - 'redirector.url', ); // Only logged in user can alter config. @@ -381,9 +380,6 @@ class ConfigManager // default state of the 'remember me' checkbox of the login form $this->setEmpty('privacy.remember_user_default', true); - $this->setEmpty('redirector.url', ''); - $this->setEmpty('redirector.encode_url', true); - $this->setEmpty('thumbnails.width', '125'); $this->setEmpty('thumbnails.height', '90'); diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php index b66f2f91..e23b3452 100644 --- a/application/feed/FeedBuilder.php +++ b/application/feed/FeedBuilder.php @@ -156,7 +156,7 @@ class FeedBuilder } else { $permalink = '' . t('Permalink') . ''; } - $link['description'] = format_description($link['description'], '', false, $pageaddr); + $link['description'] = format_description($link['description'], $pageaddr); $link['description'] .= PHP_EOL . '
— ' . $permalink; $pubDate = $link['created']; 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 try { $this->conf->set('general.title', escape($this->conf->get('general.title'))); $this->conf->set('general.header_link', escape($this->conf->get('general.header_link'))); - $this->conf->set('redirector.url', escape($this->conf->get('redirector.url'))); $this->conf->write($this->isLoggedIn); } catch (Exception $e) { error_log($e->getMessage()); @@ -550,4 +549,14 @@ class Updater return true; } + + /** + * Remove redirector settings. + */ + public function updateMethodRemoveRedirector() + { + $this->conf->remove('redirector'); + $this->conf->write(true); + return true; + } } -- cgit v1.2.3