use Shaarli\History;
use Shaarli\Legacy\LegacyLinkDB;
use Shaarli\Legacy\LegacyUpdater;
+use Shaarli\Render\PageCacheManager;
use Shaarli\Updater\UpdaterUtils;
/**
/** @var History instance */
protected $history;
+ /** @var PageCacheManager instance */
+ protected $pageCacheManager;
+
/** @var bool true for logged in users. Default value to retrieve private bookmarks. */
protected $isLoggedIn;
+ /** @var bool Allow datastore alteration from not logged in users. */
+ protected $anonymousPermission = false;
+
/**
* @inheritDoc
*/
{
$this->conf = $conf;
$this->history = $history;
+ $this->pageCacheManager = new PageCacheManager($this->conf->get('resource.page_cache'), $isLoggedIn);
$this->bookmarksIO = new BookmarkIO($this->conf);
$this->isLoggedIn = $isLoggedIn;
$this->bookmarks = $this->bookmarksIO->read();
} catch (EmptyDataStoreException $e) {
$this->bookmarks = new BookmarkArray();
- if ($isLoggedIn) {
+ if ($this->isLoggedIn) {
$this->save();
}
}
throw new Exception('Not authorized');
}
- return $bookmark;
+ return $first;
}
/**
*/
public function set($bookmark, $save = true)
{
- if ($this->isLoggedIn !== true) {
+ if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) {
throw new Exception(t('You\'re not authorized to alter the datastore'));
}
if (! $bookmark instanceof Bookmark) {
*/
public function add($bookmark, $save = true)
{
- if ($this->isLoggedIn !== true) {
+ if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) {
throw new Exception(t('You\'re not authorized to alter the datastore'));
}
if (! $bookmark instanceof Bookmark) {
*/
public function addOrSet($bookmark, $save = true)
{
- if ($this->isLoggedIn !== true) {
+ if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) {
throw new Exception(t('You\'re not authorized to alter the datastore'));
}
if (! $bookmark instanceof Bookmark) {
*/
public function remove($bookmark, $save = true)
{
- if ($this->isLoggedIn !== true) {
+ if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) {
throw new Exception(t('You\'re not authorized to alter the datastore'));
}
if (! $bookmark instanceof Bookmark) {
*/
public function save()
{
- if (!$this->isLoggedIn) {
+ if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) {
// TODO: raise an Exception instead
die('You are not authorized to change the database.');
}
+
$this->bookmarks->reorder();
$this->bookmarksIO->write($this->bookmarks);
- invalidateCaches($this->conf->get('resource.page_cache'));
+ $this->pageCacheManager->invalidateCaches();
}
/**
if (empty($tag)
|| (! $this->isLoggedIn && startsWith($tag, '.'))
|| $tag === BookmarkMarkdownFormatter::NO_MD_TAG
+ || in_array($tag, $filteringTags, true)
) {
continue;
}
$initializer->initialize();
}
+ public function enableAnonymousPermission(): void
+ {
+ $this->anonymousPermission = true;
+ }
+
+ public function disableAnonymousPermission(): void
+ {
+ $this->anonymousPermission = false;
+ }
+
/**
* Handles migration to the new database format (BookmarksArray).
*/