From b0428aa9b02b058b72c40b6e8dc2298d55bf692f Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 23 Jan 2020 21:13:41 +0100 Subject: Migrate cache purge function to a proper class And update dependencies and tests. Note that SESSION['tags'] has been removed a log ago --- application/render/PageCacheManager.php | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 application/render/PageCacheManager.php (limited to 'application/render') diff --git a/application/render/PageCacheManager.php b/application/render/PageCacheManager.php new file mode 100644 index 00000000..bd91fe0d --- /dev/null +++ b/application/render/PageCacheManager.php @@ -0,0 +1,45 @@ +pageCacheDir = $pageCacheDir; + } + + /** + * Purges all cached pages + * + * @return string|null an error string if the directory is missing + */ + public function purgeCachedPages(): ?string + { + if (!is_dir($this->pageCacheDir)) { + $error = sprintf(t('Cannot purge %s: no directory'), $this->pageCacheDir); + error_log($error); + + return $error; + } + + array_map('unlink', glob($this->pageCacheDir . '/*.cache')); + + return null; + } + + /** + * Invalidates caches when the database is changed or the user logs out. + */ + public function invalidateCaches(): void + { + // Purge page cache shared by sessions. + $this->purgeCachedPages(); + } +} -- cgit v1.2.3 From c4d5be53c2ae503c00da3cfe6b28d0ce9d2ca7f5 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 17 May 2020 14:16:32 +0200 Subject: Process Daily RSS feed through Slim controller The daily RSS template has been entirely rewritten to handle the whole feed through the template engine. --- application/render/PageCacheManager.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'application/render') diff --git a/application/render/PageCacheManager.php b/application/render/PageCacheManager.php index bd91fe0d..97805c35 100644 --- a/application/render/PageCacheManager.php +++ b/application/render/PageCacheManager.php @@ -2,6 +2,8 @@ namespace Shaarli\Render; +use Shaarli\Feed\CachedPage; + /** * Cache utilities */ @@ -10,9 +12,13 @@ class PageCacheManager /** @var string Cache directory */ protected $pageCacheDir; - public function __construct(string $pageCacheDir) + /** @var bool */ + protected $isLoggedIn; + + public function __construct(string $pageCacheDir, bool $isLoggedIn) { $this->pageCacheDir = $pageCacheDir; + $this->isLoggedIn = $isLoggedIn; } /** @@ -42,4 +48,13 @@ class PageCacheManager // Purge page cache shared by sessions. $this->purgeCachedPages(); } + + public function getCachePage(string $pageUrl): CachedPage + { + return new CachedPage( + $this->pageCacheDir, + $pageUrl, + false === $this->isLoggedIn + ); + } } -- cgit v1.2.3 From ef00f9d2033f6de11e71bf3a909399cae6f73a9f Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 27 May 2020 13:35:48 +0200 Subject: Process password change controller through Slim --- application/render/PageBuilder.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'application/render') diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index f4fefda8..264cd33b 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -7,6 +7,7 @@ use RainTPL; use Shaarli\ApplicationUtils; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; +use Shaarli\Security\SessionManager; use Shaarli\Thumbnailer; /** @@ -136,17 +137,28 @@ class PageBuilder $this->tpl->assign('thumbnails_width', $this->conf->get('thumbnails.width')); $this->tpl->assign('thumbnails_height', $this->conf->get('thumbnails.height')); - if (!empty($_SESSION['warnings'])) { - $this->tpl->assign('global_warnings', $_SESSION['warnings']); - unset($_SESSION['warnings']); - } - $this->tpl->assign('formatter', $this->conf->get('formatter', 'default')); // To be removed with a proper theme configuration. $this->tpl->assign('conf', $this->conf); } + protected function finalize(): void + { + // TODO: use the SessionManager + $messageKeys = [ + SessionManager::KEY_SUCCESS_MESSAGES, + SessionManager::KEY_WARNING_MESSAGES, + SessionManager::KEY_ERROR_MESSAGES + ]; + foreach ($messageKeys as $messageKey) { + if (!empty($_SESSION[$messageKey])) { + $this->tpl->assign('global_' . $messageKey, $_SESSION[$messageKey]); + unset($_SESSION[$messageKey]); + } + } + } + /** * The following assign() method is basically the same as RainTPL (except lazy loading) * @@ -196,6 +208,8 @@ class PageBuilder $this->initialize(); } + $this->finalize(); + $this->tpl->draw($page); } @@ -213,6 +227,8 @@ class PageBuilder $this->initialize(); } + $this->finalize(); + return $this->tpl->draw($page, true); } -- cgit v1.2.3 From 66063ed1a18d739b1a60bfb163d8656417a4c529 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 30 May 2020 14:00:06 +0200 Subject: Process configure page through Slim controller --- application/render/PageBuilder.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'application/render') diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index 264cd33b..d90ed58b 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -143,6 +143,10 @@ class PageBuilder $this->tpl->assign('conf', $this->conf); } + /** + * Affect variable after controller processing. + * Used for alert messages. + */ protected function finalize(): void { // TODO: use the SessionManager -- cgit v1.2.3 From 818b3193ffabec57501e3bdfa997206e3c0671ef Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 13 Jun 2020 11:22:14 +0200 Subject: Explicitly define base and asset path in templates With the new routes, all pages are not all at the same folder level anymore (e.g. /shaare and /shaare/123), so we can't just use './' everywhere. The most consistent way to handle this is to prefix all path with the proper variable, and handle the actual path in controllers. --- application/render/PageBuilder.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'application/render') diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index d90ed58b..2779eb90 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -149,6 +149,10 @@ class PageBuilder */ protected function finalize(): void { + //FIXME - DEV _ REMOVE ME + $this->assign('base_path', '/Shaarli'); + $this->assign('asset_path', '/Shaarli/tpl/default'); + // TODO: use the SessionManager $messageKeys = [ SessionManager::KEY_SUCCESS_MESSAGES, -- cgit v1.2.3 From 1a8ac737e52cb25a5c346232ee398f5908cee7d7 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 6 Jul 2020 08:04:35 +0200 Subject: Process main page (linklist) through Slim controller Including a bunch of improvements on the container, and helper used across new controllers. --- application/render/PageBuilder.php | 9 +++++++++ application/render/TemplatePage.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 application/render/TemplatePage.php (limited to 'application/render') diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index 2779eb90..85e1d59d 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -69,6 +69,15 @@ class PageBuilder $this->isLoggedIn = $isLoggedIn; } + /** + * Reset current state of template rendering. + * Mostly useful for error handling. We remove everything, and display the error template. + */ + public function reset(): void + { + $this->tpl = false; + } + /** * Initialize all default tpl tags. */ diff --git a/application/render/TemplatePage.php b/application/render/TemplatePage.php new file mode 100644 index 00000000..8af8228a --- /dev/null +++ b/application/render/TemplatePage.php @@ -0,0 +1,33 @@ + Date: Wed, 22 Jul 2020 18:12:10 +0200 Subject: Move PHP and config init to dedicated file in order to keep index.php as minimal as possible --- application/render/PageBuilder.php | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'application/render') diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index 85e1d59d..471724c0 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -158,10 +158,6 @@ class PageBuilder */ protected function finalize(): void { - //FIXME - DEV _ REMOVE ME - $this->assign('base_path', '/Shaarli'); - $this->assign('asset_path', '/Shaarli/tpl/default'); - // TODO: use the SessionManager $messageKeys = [ SessionManager::KEY_SUCCESS_MESSAGES, @@ -248,20 +244,4 @@ class PageBuilder return $this->tpl->draw($page, true); } - - /** - * Render a 404 page (uses the template : tpl/404.tpl) - * usage: $PAGE->render404('The link was deleted') - * - * @param string $message A message to display what is not found - */ - public function render404($message = '') - { - if (empty($message)) { - $message = t('The page you are trying to reach does not exist or has been deleted.'); - } - header($_SERVER['SERVER_PROTOCOL'] . ' ' . t('404 Not Found')); - $this->tpl->assign('error_message', $message); - $this->renderPage('404'); - } } -- cgit v1.2.3 From 9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 26 Jul 2020 14:43:10 +0200 Subject: New basePath: fix officiel plugin paths and vintage template --- application/render/PageBuilder.php | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'application/render') diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index 471724c0..7a716673 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -3,6 +3,7 @@ namespace Shaarli\Render; use Exception; +use exceptions\MissingBasePathException; use RainTPL; use Shaarli\ApplicationUtils; use Shaarli\Bookmark\BookmarkServiceInterface; @@ -156,7 +157,7 @@ class PageBuilder * Affect variable after controller processing. * Used for alert messages. */ - protected function finalize(): void + protected function finalize(string $basePath): void { // TODO: use the SessionManager $messageKeys = [ @@ -170,6 +171,14 @@ class PageBuilder unset($_SESSION[$messageKey]); } } + + $this->assign('base_path', $basePath); + $this->assign( + 'asset_path', + $basePath . '/' . + rtrim($this->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' . + $this->conf->get('resource.theme', 'default') + ); } /** @@ -209,23 +218,6 @@ class PageBuilder return true; } - /** - * Render a specific page (using a template file). - * e.g. $pb->renderPage('picwall'); - * - * @param string $page Template filename (without extension). - */ - public function renderPage($page) - { - if ($this->tpl === false) { - $this->initialize(); - } - - $this->finalize(); - - $this->tpl->draw($page); - } - /** * Render a specific page as string (using a template file). * e.g. $pb->render('picwall'); @@ -234,13 +226,13 @@ class PageBuilder * * @return string Processed template content */ - public function render(string $page): string + public function render(string $page, string $basePath): string { if ($this->tpl === false) { $this->initialize(); } - $this->finalize(); + $this->finalize($basePath); return $this->tpl->draw($page, true); } -- cgit v1.2.3