]>
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 */ | |
27ceea2a | 13 | protected $container; |
6c50a6cc | 14 | |
27ceea2a A |
15 | /** @param ShaarliContainer $container Slim container (extended for attribute completion). */ |
16 | public function __construct(ShaarliContainer $container) | |
6c50a6cc | 17 | { |
27ceea2a | 18 | $this->container = $container; |
6c50a6cc A |
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 | { | |
27ceea2a | 28 | $this->container->pageBuilder->assign($name, $value); |
6c50a6cc A |
29 | |
30 | return $this; | |
31 | } | |
0498b209 A |
32 | |
33 | protected function render(string $template): string | |
34 | { | |
27ceea2a A |
35 | $this->assignView('linkcount', $this->container->bookmarkService->count(BookmarkFilter::$ALL)); |
36 | $this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE)); | |
37 | $this->assignView('plugin_errors', $this->container->pluginManager->getErrors()); | |
0498b209 A |
38 | |
39 | $this->executeDefaultHooks($template); | |
40 | ||
27ceea2a | 41 | return $this->container->pageBuilder->render($template); |
0498b209 A |
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 = []; | |
27ceea2a | 58 | $this->container->pluginManager->executeHooks( |
0498b209 A |
59 | 'render_' . $name, |
60 | $plugin_data, | |
61 | [ | |
62 | 'target' => $template, | |
27ceea2a | 63 | 'loggedin' => $this->container->loginManager->isLoggedIn() |
0498b209 A |
64 | ] |
65 | ); | |
66 | $this->assignView('plugins_' . $name, $plugin_data); | |
67 | } | |
68 | } | |
6c50a6cc | 69 | } |