]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/render/PageBuilder.php
Process password change controller through Slim
[github/shaarli/Shaarli.git] / application / render / PageBuilder.php
index 65e85aaf4918c1f29c85af30f9560dd596184cef..264cd33b613105fc968bb94d210f4e4390dbe3f1 100644 (file)
@@ -7,6 +7,7 @@ use RainTPL;
 use Shaarli\ApplicationUtils;
 use Shaarli\Bookmark\BookmarkServiceInterface;
 use Shaarli\Config\ConfigManager;
+use Shaarli\Security\SessionManager;
 use Shaarli\Thumbnailer;
 
 /**
@@ -136,17 +137,28 @@ class PageBuilder
         $this->tpl->assign('thumbnails_width', $this->conf->get('thumbnails.width'));
         $this->tpl->assign('thumbnails_height', $this->conf->get('thumbnails.height'));
 
-        if (!empty($_SESSION['warnings'])) {
-            $this->tpl->assign('global_warnings', $_SESSION['warnings']);
-            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);
     }
 
+    protected function finalize(): void
+    {
+        // TODO: use the SessionManager
+        $messageKeys = [
+            SessionManager::KEY_SUCCESS_MESSAGES,
+            SessionManager::KEY_WARNING_MESSAGES,
+            SessionManager::KEY_ERROR_MESSAGES
+        ];
+        foreach ($messageKeys as $messageKey) {
+            if (!empty($_SESSION[$messageKey])) {
+                $this->tpl->assign('global_' . $messageKey, $_SESSION[$messageKey]);
+                unset($_SESSION[$messageKey]);
+            }
+        }
+    }
+
     /**
      * The following assign() method is basically the same as RainTPL (except lazy loading)
      *
@@ -196,9 +208,30 @@ class PageBuilder
             $this->initialize();
         }
 
+        $this->finalize();
+
         $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();
+        }
+
+        $this->finalize();
+
+        return $this->tpl->draw($page, true);
+    }
+
     /**
      * Render a 404 page (uses the template : tpl/404.tpl)
      * usage: $PAGE->render404('The link was deleted')