X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Frender%2FPageBuilder.php;h=7a7166732392a5726227bd33d769f0dd8abbc96e;hb=a975d97a8da64864c3c49f1c54f571eb4ea5b81a;hp=264cd33b613105fc968bb94d210f4e4390dbe3f1;hpb=ef00f9d2033f6de11e71bf3a909399cae6f73a9f;p=github%2Fshaarli%2FShaarli.git diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index 264cd33b..7a716673 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -3,6 +3,7 @@ namespace Shaarli\Render; use Exception; +use exceptions\MissingBasePathException; use RainTPL; use Shaarli\ApplicationUtils; use Shaarli\Bookmark\BookmarkServiceInterface; @@ -69,6 +70,15 @@ class PageBuilder $this->isLoggedIn = $isLoggedIn; } + /** + * Reset current state of template rendering. + * Mostly useful for error handling. We remove everything, and display the error template. + */ + public function reset(): void + { + $this->tpl = false; + } + /** * Initialize all default tpl tags. */ @@ -143,7 +153,11 @@ class PageBuilder $this->tpl->assign('conf', $this->conf); } - protected function finalize(): void + /** + * Affect variable after controller processing. + * Used for alert messages. + */ + protected function finalize(string $basePath): void { // TODO: use the SessionManager $messageKeys = [ @@ -157,6 +171,14 @@ class PageBuilder unset($_SESSION[$messageKey]); } } + + $this->assign('base_path', $basePath); + $this->assign( + 'asset_path', + $basePath . '/' . + rtrim($this->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' . + $this->conf->get('resource.theme', 'default') + ); } /** @@ -196,23 +218,6 @@ class PageBuilder return true; } - /** - * Render a specific page (using a template file). - * e.g. $pb->renderPage('picwall'); - * - * @param string $page Template filename (without extension). - */ - public function renderPage($page) - { - if ($this->tpl === false) { - $this->initialize(); - } - - $this->finalize(); - - $this->tpl->draw($page); - } - /** * Render a specific page as string (using a template file). * e.g. $pb->render('picwall'); @@ -221,30 +226,14 @@ class PageBuilder * * @return string Processed template content */ - public function render(string $page): string + public function render(string $page, string $basePath): string { if ($this->tpl === false) { $this->initialize(); } - $this->finalize(); + $this->finalize($basePath); return $this->tpl->draw($page, true); } - - /** - * Render a 404 page (uses the template : tpl/404.tpl) - * usage: $PAGE->render404('The link was deleted') - * - * @param string $message A message to display what is not found - */ - public function render404($message = '') - { - if (empty($message)) { - $message = t('The page you are trying to reach does not exist or has been deleted.'); - } - header($_SERVER['SERVER_PROTOCOL'] . ' ' . t('404 Not Found')); - $this->tpl->assign('error_message', $message); - $this->renderPage('404'); - } }