diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-23 20:06:32 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-01-26 11:34:14 +0100 |
commit | 0498b209b551cad5595312583e5d6fb1bc3303a5 (patch) | |
tree | a7b176fc39788bc7f5eef1ddcd18877d2defdfd9 /application/front/controllers | |
parent | 9e4cc28e2957e1f7df713d52a03e350d728dc58e (diff) | |
download | Shaarli-0498b209b551cad5595312583e5d6fb1bc3303a5.tar.gz Shaarli-0498b209b551cad5595312583e5d6fb1bc3303a5.tar.zst Shaarli-0498b209b551cad5595312583e5d6fb1bc3303a5.zip |
Execute common plugin hooks before rendering login page
Diffstat (limited to 'application/front/controllers')
-rw-r--r-- | application/front/controllers/LoginController.php | 2 | ||||
-rw-r--r-- | application/front/controllers/ShaarliController.php | 38 |
2 files changed, 39 insertions, 1 deletions
diff --git a/application/front/controllers/LoginController.php b/application/front/controllers/LoginController.php index 47fa3ee3..23efb592 100644 --- a/application/front/controllers/LoginController.php +++ b/application/front/controllers/LoginController.php | |||
@@ -41,6 +41,6 @@ class LoginController extends ShaarliController | |||
41 | ->assignView('pagetitle', t('Login') .' - '. $this->ci->conf->get('general.title', 'Shaarli')) | 41 | ->assignView('pagetitle', t('Login') .' - '. $this->ci->conf->get('general.title', 'Shaarli')) |
42 | ; | 42 | ; |
43 | 43 | ||
44 | return $response->write($this->ci->pageBuilder->render('loginform')); | 44 | return $response->write($this->render('loginform')); |
45 | } | 45 | } |
46 | } | 46 | } |
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); | |||
4 | 4 | ||
5 | namespace Shaarli\Front\Controller; | 5 | namespace Shaarli\Front\Controller; |
6 | 6 | ||
7 | use Shaarli\Bookmark\BookmarkFilter; | ||
7 | use Shaarli\Container\ShaarliContainer; | 8 | use Shaarli\Container\ShaarliContainer; |
8 | 9 | ||
9 | abstract class ShaarliController | 10 | abstract class ShaarliController |
@@ -28,4 +29,41 @@ abstract class ShaarliController | |||
28 | 29 | ||
29 | return $this; | 30 | return $this; |
30 | } | 31 | } |
32 | |||
33 | protected function render(string $template): string | ||
34 | { | ||
35 | $this->assignView('linkcount', $this->ci->bookmarkService->count(BookmarkFilter::$ALL)); | ||
36 | $this->assignView('privateLinkcount', $this->ci->bookmarkService->count(BookmarkFilter::$PRIVATE)); | ||
37 | $this->assignView('plugin_errors', $this->ci->pluginManager->getErrors()); | ||
38 | |||
39 | $this->executeDefaultHooks($template); | ||
40 | |||
41 | return $this->ci->pageBuilder->render($template); | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * Call plugin hooks for header, footer and includes, specifying which page will be rendered. | ||
46 | * Then assign generated data to RainTPL. | ||
47 | */ | ||
48 | protected function executeDefaultHooks(string $template): void | ||
49 | { | ||
50 | $common_hooks = [ | ||
51 | 'includes', | ||
52 | 'header', | ||
53 | 'footer', | ||
54 | ]; | ||
55 | |||
56 | foreach ($common_hooks as $name) { | ||
57 | $plugin_data = []; | ||
58 | $this->ci->pluginManager->executeHooks( | ||
59 | 'render_' . $name, | ||
60 | $plugin_data, | ||
61 | [ | ||
62 | 'target' => $template, | ||
63 | 'loggedin' => $this->ci->loginManager->isLoggedIn() | ||
64 | ] | ||
65 | ); | ||
66 | $this->assignView('plugins_' . $name, $plugin_data); | ||
67 | } | ||
68 | } | ||
31 | } | 69 | } |