From 6c50a6ccceecf54850e62c312ab2397b84d89ab4 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 18 Jan 2020 17:50:11 +0100 Subject: Render login page through Slim controller --- .../front/controllers/ShaarliController.php | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 application/front/controllers/ShaarliController.php (limited to 'application/front/controllers/ShaarliController.php') diff --git a/application/front/controllers/ShaarliController.php b/application/front/controllers/ShaarliController.php new file mode 100644 index 00000000..2a166c3c --- /dev/null +++ b/application/front/controllers/ShaarliController.php @@ -0,0 +1,31 @@ +ci = $ci; + } + + /** + * Assign variables to RainTPL template through the PageBuilder. + * + * @param mixed $value Value to assign to the template + */ + protected function assignView(string $name, $value): self + { + $this->ci->pageBuilder->assign($name, $value); + + return $this; + } +} -- cgit v1.2.3 From 0498b209b551cad5595312583e5d6fb1bc3303a5 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 23 Jan 2020 20:06:32 +0100 Subject: Execute common plugin hooks before rendering login page --- .../front/controllers/ShaarliController.php | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'application/front/controllers/ShaarliController.php') diff --git a/application/front/controllers/ShaarliController.php b/application/front/controllers/ShaarliController.php index 2a166c3c..99e66d53 100644 --- a/application/front/controllers/ShaarliController.php +++ b/application/front/controllers/ShaarliController.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shaarli\Front\Controller; +use Shaarli\Bookmark\BookmarkFilter; use Shaarli\Container\ShaarliContainer; abstract class ShaarliController @@ -28,4 +29,41 @@ abstract class ShaarliController return $this; } + + protected function render(string $template): string + { + $this->assignView('linkcount', $this->ci->bookmarkService->count(BookmarkFilter::$ALL)); + $this->assignView('privateLinkcount', $this->ci->bookmarkService->count(BookmarkFilter::$PRIVATE)); + $this->assignView('plugin_errors', $this->ci->pluginManager->getErrors()); + + $this->executeDefaultHooks($template); + + return $this->ci->pageBuilder->render($template); + } + + /** + * Call plugin hooks for header, footer and includes, specifying which page will be rendered. + * Then assign generated data to RainTPL. + */ + protected function executeDefaultHooks(string $template): void + { + $common_hooks = [ + 'includes', + 'header', + 'footer', + ]; + + foreach ($common_hooks as $name) { + $plugin_data = []; + $this->ci->pluginManager->executeHooks( + 'render_' . $name, + $plugin_data, + [ + 'target' => $template, + 'loggedin' => $this->ci->loginManager->isLoggedIn() + ] + ); + $this->assignView('plugins_' . $name, $plugin_data); + } + } } -- cgit v1.2.3 From 27ceea2aeeed69b43fef4ebff35ec8004fcc2e45 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 26 Jan 2020 09:06:13 +0100 Subject: Rename ci attribute to container --- .../front/controllers/ShaarliController.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'application/front/controllers/ShaarliController.php') diff --git a/application/front/controllers/ShaarliController.php b/application/front/controllers/ShaarliController.php index 99e66d53..2b828588 100644 --- a/application/front/controllers/ShaarliController.php +++ b/application/front/controllers/ShaarliController.php @@ -10,12 +10,12 @@ use Shaarli\Container\ShaarliContainer; abstract class ShaarliController { /** @var ShaarliContainer */ - protected $ci; + protected $container; - /** @param ShaarliContainer $ci Slim container (extended for attribute completion). */ - public function __construct(ShaarliContainer $ci) + /** @param ShaarliContainer $container Slim container (extended for attribute completion). */ + public function __construct(ShaarliContainer $container) { - $this->ci = $ci; + $this->container = $container; } /** @@ -25,20 +25,20 @@ abstract class ShaarliController */ protected function assignView(string $name, $value): self { - $this->ci->pageBuilder->assign($name, $value); + $this->container->pageBuilder->assign($name, $value); return $this; } protected function render(string $template): string { - $this->assignView('linkcount', $this->ci->bookmarkService->count(BookmarkFilter::$ALL)); - $this->assignView('privateLinkcount', $this->ci->bookmarkService->count(BookmarkFilter::$PRIVATE)); - $this->assignView('plugin_errors', $this->ci->pluginManager->getErrors()); + $this->assignView('linkcount', $this->container->bookmarkService->count(BookmarkFilter::$ALL)); + $this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE)); + $this->assignView('plugin_errors', $this->container->pluginManager->getErrors()); $this->executeDefaultHooks($template); - return $this->ci->pageBuilder->render($template); + return $this->container->pageBuilder->render($template); } /** @@ -55,12 +55,12 @@ abstract class ShaarliController foreach ($common_hooks as $name) { $plugin_data = []; - $this->ci->pluginManager->executeHooks( + $this->container->pluginManager->executeHooks( 'render_' . $name, $plugin_data, [ 'target' => $template, - 'loggedin' => $this->ci->loginManager->isLoggedIn() + 'loggedin' => $this->container->loginManager->isLoggedIn() ] ); $this->assignView('plugins_' . $name, $plugin_data); -- cgit v1.2.3