]>
Commit | Line | Data |
---|---|---|
6c50a6cc A |
1 | <?php |
2 | ||
3 | declare(strict_types=1); | |
4 | ||
5 | namespace Shaarli\Front\Controller; | |
6 | ||
0498b209 | 7 | use Shaarli\Bookmark\BookmarkFilter; |
6c50a6cc A |
8 | use Shaarli\Container\ShaarliContainer; |
9 | ||
10 | abstract class ShaarliController | |
11 | { | |
12 | /** @var ShaarliContainer */ | |
13 | protected $ci; | |
14 | ||
15 | /** @param ShaarliContainer $ci Slim container (extended for attribute completion). */ | |
16 | public function __construct(ShaarliContainer $ci) | |
17 | { | |
18 | $this->ci = $ci; | |
19 | } | |
20 | ||
21 | /** | |
22 | * Assign variables to RainTPL template through the PageBuilder. | |
23 | * | |
24 | * @param mixed $value Value to assign to the template | |
25 | */ | |
26 | protected function assignView(string $name, $value): self | |
27 | { | |
28 | $this->ci->pageBuilder->assign($name, $value); | |
29 | ||
30 | return $this; | |
31 | } | |
0498b209 A |
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 | } | |
6c50a6cc | 69 | } |