X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fbookmark%2FLinkDB.php;h=f01c7ee6cadaea8422baf7e650ee85e639e84172;hb=7ff3ed1d6377f5db0f63d4228707f69f89653539;hp=6041c0884fec8547d430e38e3f432521083e08f4;hpb=6696729b88e67504fdd333cbaab43a63c3617d86;p=github%2Fshaarli%2FShaarli.git diff --git a/application/bookmark/LinkDB.php b/application/bookmark/LinkDB.php index 6041c088..f01c7ee6 100644 --- a/application/bookmark/LinkDB.php +++ b/application/bookmark/LinkDB.php @@ -6,7 +6,6 @@ use ArrayAccess; use Countable; use DateTime; use Iterator; -use Shaarli\Bookmark\LinkFilter; use Shaarli\Bookmark\Exception\LinkNotFoundException; use Shaarli\Exceptions\IOException; use Shaarli\FileUtils; @@ -30,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: @@ -89,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 * @@ -110,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(); } @@ -272,7 +252,8 @@ You use the community supported version of the original Shaarli project, by Seba ), 'private' => 0, 'created' => new DateTime(), - 'tags' => 'opensource software' + 'tags' => 'opensource software', + 'sticky' => false, ); $link['shorturl'] = link_small_hash($link['created'], $link['id']); $this->links[1] = $link; @@ -285,6 +266,7 @@ You use the community supported version of the original Shaarli project, by Seba 'private' => 1, 'created' => new DateTime('1 minute ago'), 'tags' => 'secretstuff', + 'sticky' => false, ); $link['shorturl'] = link_small_hash($link['created'], $link['id']); $this->links[0] = $link; @@ -324,17 +306,9 @@ 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']; + + $link['sticky'] = isset($link['sticky']) ? $link['sticky'] : false; // To be able to load links before running the update, and prepare the update if (!isset($link['created'])) { @@ -441,7 +415,7 @@ You use the community supported version of the original Shaarli project, by Seba $visibility = 'all', $untaggedonly = false ) { - + // Filter link database according to parameters. $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; @@ -559,6 +533,9 @@ You use the community supported version of the original Shaarli project, by Seba if (isset($a['sticky']) && isset($b['sticky']) && $a['sticky'] !== $b['sticky']) { return $a['sticky'] ? -1 : 1; } + if ($a['created'] == $b['created']) { + return $a['id'] < $b['id'] ? 1 * $order : -1 * $order; + } return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; });