]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/render/PageBuilder.php
Migrate cache purge function to a proper class
[github/shaarli/Shaarli.git] / application / render / PageBuilder.php
index 9a0fe61a557654f77ceeb5fae9dccec2f59171d2..f4fefda84f448297374fc1b5e47ad159f44c1bae 100644 (file)
@@ -2,10 +2,10 @@
 
 namespace Shaarli\Render;
 
-use ApplicationUtils;
 use Exception;
-use Shaarli\Bookmark\LinkDB;
 use RainTPL;
+use Shaarli\ApplicationUtils;
+use Shaarli\Bookmark\BookmarkServiceInterface;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Thumbnailer;
 
@@ -34,9 +34,9 @@ class PageBuilder
     protected $session;
 
     /**
-     * @var LinkDB $linkDB instance.
+     * @var BookmarkServiceInterface $bookmarkService instance.
      */
-    protected $linkDB;
+    protected $bookmarkService;
 
     /**
      * @var null|string XSRF token
@@ -52,18 +52,18 @@ class PageBuilder
      * PageBuilder constructor.
      * $tpl is initialized at false for lazy loading.
      *
-     * @param ConfigManager $conf       Configuration Manager instance (reference).
-     * @param array         $session    $_SESSION array
-     * @param LinkDB        $linkDB     instance.
-     * @param string        $token      Session token
-     * @param bool          $isLoggedIn
+     * @param ConfigManager            $conf    Configuration Manager instance (reference).
+     * @param array                    $session $_SESSION array
+     * @param BookmarkServiceInterface $linkDB  instance.
+     * @param string                   $token   Session token
+     * @param bool                     $isLoggedIn
      */
     public function __construct(&$conf, $session, $linkDB = null, $token = null, $isLoggedIn = false)
     {
         $this->tpl = false;
         $this->conf = $conf;
         $this->session = $session;
-        $this->linkDB = $linkDB;
+        $this->bookmarkService = $linkDB;
         $this->token = $token;
         $this->isLoggedIn = $isLoggedIn;
     }
@@ -123,8 +123,10 @@ class PageBuilder
         $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
         $this->tpl->assign('token', $this->token);
 
-        if ($this->linkDB !== null) {
-            $this->tpl->assign('tags', $this->linkDB->linksCountPerTag());
+        $this->tpl->assign('language', $this->conf->get('translation.language'));
+
+        if ($this->bookmarkService !== null) {
+            $this->tpl->assign('tags', $this->bookmarkService->bookmarksCountPerTag());
         }
 
         $this->tpl->assign(
@@ -139,6 +141,8 @@ class PageBuilder
             unset($_SESSION['warnings']);
         }
 
+        $this->tpl->assign('formatter', $this->conf->get('formatter', 'default'));
+
         // To be removed with a proper theme configuration.
         $this->tpl->assign('conf', $this->conf);
     }
@@ -195,6 +199,23 @@ class PageBuilder
         $this->tpl->draw($page);
     }
 
+    /**
+     * Render a specific page as string (using a template file).
+     * e.g. $pb->render('picwall');
+     *
+     * @param string $page Template filename (without extension).
+     *
+     * @return string Processed template content
+     */
+    public function render(string $page): string
+    {
+        if ($this->tpl === false) {
+            $this->initialize();
+        }
+
+        return $this->tpl->draw($page, true);
+    }
+
     /**
      * Render a 404 page (uses the template : tpl/404.tpl)
      * usage: $PAGE->render404('The link was deleted')