From ec6b351dc45b9a03ec29625618bc6927213b2812 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 4 Jun 2014 18:55:21 +0200 Subject: Add token in Render class, instead of passing it to its methods explicitly all over the place --- inc/render.inc.php | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'inc/render.inc.php') diff --git a/inc/render.inc.php b/inc/render.inc.php index 4fe9d002..6c746c93 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -11,8 +11,10 @@ Mustache_Autoloader::register(); * HTML rendering helper class */ Render::init(); + class Render { + private static $mustache = false; private static $body = ''; private static $header = ''; @@ -22,7 +24,8 @@ class Render public static function init() { - if (self::$mustache !== false) Util::traceError('Called Render::init() twice!'); + if (self::$mustache !== false) + Util::traceError('Called Render::init() twice!'); self::$mustache = new Mustache_Engine; } @@ -33,9 +36,10 @@ class Render { Header('Content-Type: text/html; charset=utf-8'); $zip = isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false); - if ($zip) ob_start(); + if ($zip) + ob_start(); echo - ' + ' ', RENDER_DEFAULT_TITLE, self::$title, ' @@ -51,13 +55,13 @@ class Render ', self::$header , - ' + '
', self::$body , - '
+ ' @@ -95,9 +99,9 @@ class Render */ public static function addTemplate($template, $params = false) { - self::$body .= self::$mustache->render(self::getTemplate($template), $params); + self::$body .= self::parse($template, $params); } - + /** * Add a dialog to the page output. * @@ -111,7 +115,7 @@ class Render self::addTemplate('dialog-generic', array( 'title' => $title, 'next' => $next, - 'body' => self::$mustache->render(self::getTemplate($template), $params) + 'body' => self::parse($template, $params) )); } @@ -128,6 +132,8 @@ class Render */ public static function parse($template, $params = false) { + if (is_array($params)) + $params['token'] = Session::get('token'); return self::$mustache->render(self::getTemplate($template), $params); } @@ -153,9 +159,11 @@ class Render */ public static function closeTag($tag) { - if (empty(self::$tags)) Util::traceError('Tried to close tag ' . $tag . ' when no open tags exist.'); + if (empty(self::$tags)) + Util::traceError('Tried to close tag ' . $tag . ' when no open tags exist.'); $last = array_pop(self::$tags); - if ($last !== $tag) Util::traceError('Tried to close tag ' . $tag . ' when last opened tag was ' . $last); + if ($last !== $tag) + Util::traceError('Tried to close tag ' . $tag . ' when last opened tag was ' . $last); self::$body .= ''; } @@ -169,9 +177,10 @@ class Render } // Load from disk $data = @file_get_contents('templates/' . $template . '.html'); - if ($data === false) $data = 'Non-existent template ' . $template . ' requested!'; - self::$templateCache[$template] =& $data; + if ($data === false) + $data = 'Non-existent template ' . $template . ' requested!'; + self::$templateCache[$template] = & $data; return $data; } -} +} -- cgit v1.2.3-55-g7522