From dbc0d9614421e064cc62aacf116ebb783c83f2f3 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 1 Apr 2016 16:50:13 +0200 Subject: [merge] merging c3sl / fr - initial commit --- inc/render.inc.php | 86 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 10 deletions(-) (limited to 'inc/render.inc.php') diff --git a/inc/render.inc.php b/inc/render.inc.php index 6de00eee..10d18514 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -18,6 +18,7 @@ class Render private static $mustache = false; private static $body = ''; private static $header = ''; + private static $dashboard = ''; private static $footer = ''; private static $title = ''; private static $templateCache = array(); @@ -39,6 +40,9 @@ class Render $zip = isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false); if ($zip) ob_start(); + $page = strtolower($_GET['do']); + if(User::isLoggedIn()) + self::createDashboard($page); echo ' @@ -50,6 +54,9 @@ class Render + + + @@ -58,11 +65,15 @@ class Render , ' -
+
+
', + self::$dashboard + , self::$body , '
+
@@ -129,9 +140,9 @@ class Render /** * Add the given template to the output, using the given params for placeholders in the template */ - public static function addTemplate($template, $params = false) + public static function addTemplate($template, $params = false, $module = false) { - self::$body .= self::parse($template, $params); + self::$body .= self::parse($template, $params, $module); } /** @@ -148,7 +159,7 @@ class Render 'title' => $title, 'next' => $next, 'body' => self::parse($template, $params) - )); + ), 'main'); } /** @@ -164,15 +175,19 @@ class Render * @param string $template name of template, relative to templates/, without .html extension * @return string Rendered template */ - public static function parse($template, $params = false) + public static function parse($template, $params = false, $module = false) { // Load html snippet - $html = self::getTemplate($template); + $html = self::getTemplate($template,$module); if ($html === false) { return '

Template ' . htmlspecialchars($template) . '

' . nl2br(htmlspecialchars(print_r($params, true))) . '
'; } // Get all translated strings for this template - $dictionary = Dictionary::getArrayTemplate($template); + if($module === false){ + $module = strtolower(empty($_REQUEST['do']) ? 'main' : $_REQUEST['do']); + } + $dictionary = Dictionary::getArrayTemplate($template, $module); + // Now find all language tags in this array preg_match_all('/{{(lang_.+?)}}/', $html, $out); foreach ($out[1] as $tag) { @@ -183,7 +198,7 @@ class Render // Always add token to parameter list if (is_array($params) || $params === false || is_null($params)) $params['token'] = Session::get('token'); - // Likewise, add currently selected language (its two letter code) to params + // Likewise, add currently selected language ( its two letter code) to params $params['current_lang'] = LANG; // Add desired password field type $params['password_type'] = Property::getPasswordFieldType(); @@ -224,15 +239,66 @@ class Render /** * Private helper: Load the given template and return it */ - private static function getTemplate($template) + private static function getTemplate($template, $module = false) { if (isset(self::$templateCache[$template])) { return self::$templateCache[$template]; } + // Select current module + if(!$module){ + $module = strtolower(empty($_REQUEST['do']) ? 'Main' : $_REQUEST['do']); + } // Load from disk - $data = @file_get_contents('templates/' . $template . '.html'); + $data = @file_get_contents('modules/' . $module . '/templates/' . $template . '.html'); + if ($data === false) + $data = 'Non-existent template ' . $template . ' requested!'; self::$templateCache[$template] = & $data; return $data; } + /** + * Create the dashboard menu + */ + private static function createDashboard($page) + { + // Check all required modules + $requiredModules = array('adduser','main','session','translation','usermanagement'); + $notFound = ''; + foreach ($requiredModules as $module) { + if(!is_dir('modules/' . $module . '/')){ + $notFound .= '\'' . $module . '\' '; + } + } + if(strlen($notFound) > 0){ + Util::traceError('At least one required module was not found: ' . $notFound); + }else{ + $modules = array_diff(scandir('modules/'), array('..', '.')); + $categories = array(); + foreach ($modules as $module) { + $json = json_decode(file_get_contents("modules/" . $module . "/config.json"),true); + $categories[$json['category']][] = $module; + } + unset($categories['hidden']); + self::$dashboard = '
'; + } + } + + /** + * get categories glyph icons + */ + private static function getGlyphicon($category){ + return json_decode(file_get_contents("style/categories.json"),true)[$category]; + } + } -- cgit v1.2.3-55-g7522