]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/front/controllers/ShaarliController.php
Execute common plugin hooks before rendering login page
[github/shaarli/Shaarli.git] / application / front / controllers / ShaarliController.php
index 2a166c3c4db56907207ae9adaf7f643df6d9cda9..99e66d53665d2a17794c244ff8592ce83c208e76 100644 (file)
@@ -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);
+        }
+    }
 }