/** * Load a new template by a given name. * If the given name is null or the given template can't be found, use a fallback. * * @fallback use the standard template * * @param null|string $s_template_name the name of the used template * @param bool $b_use_cache A value to define if the template should use * the cache (true) or not(false) * default: true */ public function load_template($s_template_name = null, $b_use_cache = true) { // user standard template if nothing is given if (is_null($s_template_name)) { $s_template_name = $this->s_start_template; } // set the path to the template with following structure: // (DIR)Templatename/templatename.{EXTENSION} relative to the template directory // The {Extension} will be set automatically, not need here directly. $s_template_path = $s_template_name . DIRECTORY_SEPARATOR . $s_template_name; try { //todo: Maybe write a log message which template can't be loaded! $s_path = LOGD::find_file($this->s_template_dir, $s_template_path); if (!$s_path) { //Template not found! Check if the standard one wasn't found, //if yes throw exception if ($s_template_name === $this->s_start_template) { throw new LOGD_Exception('Could not load the standard template "' . $s_template_name . '". Please check if its available in the template directory.', 'TEMPLATE_ERROR'); } else { self::load_template($this->s_start_template); } } else { if ($b_use_cache && Cache::getInstance()->exists('template_' . $s_template_name . '_html') && Cache::getInstance()->exists('template_' . $s_template_name . '_stats')) { $this->s_current_template = Cache::getInstance()->get('template_' . $s_template_name . '_html'); $this->a_stats_html = Cache::getInstance()->get('template_' . $s_template_name . '_stats'); } else { if (!$b_use_cache && Cache::getInstance()->exists('template_' . $s_template_name . '_html') && Cache::getInstance()->exists('template_' . $s_template_name . '_stats')) { Cache::getInstance()->delete_entry('template_' . $s_template_name . '_html'); Cache::getInstance()->delete_entry('template_' . $s_template_name . '_stats'); } //All ok! Load the template and buffer the output $a_global_template_variables = array('template_directory' => MEDIA_URL . $this->s_template_dir . '/' . $s_template_name . '/', 's_base_url' => BASE_URL); extract($a_global_template_variables, EXTR_SKIP); ob_start(); include $s_path; //Trim the buffered output and set it to a variable $s_full_template = trim(ob_get_clean()); //Check if all needed tags are in the template string //todo write a extra method for all needed tags $a_needed_tags = array('title', 'navigation', 'motd', 'mail', 'petition', 'stats', 'stats-head', 'stats-left', 'stats-right', 'game', 'onlineuser', 'copyright', 'pagegen', 'version', 'source'); $a_failed_tags = array(); $i_key = 0; foreach ($a_needed_tags as $tag) { if (!strpos($s_full_template, '{' . $tag . '}')) { $a_failed_tags[$i_key] = $tag; $i_key++; } } if (!is_null($a_failed_tags) && sizeof($a_failed_tags) !== 0) { $s_failed_tags = implode(' , ', $a_failed_tags); throw new LOGD_Exception('Following tags could not be found in your template, but have to be in it: <br><b>' . $s_failed_tags . '</b><br> Please check your template "' . $s_template_name . '"', 'TEMPLATE_TAG_ERROR'); } //extract the special statsbar html of the template. $s_stats_html = substr($s_full_template, strpos($s_full_template, '<!--!stats-->') + 13); $s_stats_html = substr($s_stats_html, 0, strpos($s_stats_html, '<!--end!-->')); $a_stats_html = array(); //replace the statsbar html with nothing! Because we don't need the standard one anymore. $s_full_template = str_replace($s_stats_html, null, $s_full_template); //explode all needed tags in the statsbar html (stats-head, stats-left, stets-right) foreach (explode('</div>', $s_stats_html) as $key => $value) { $value = trim($value); if (is_null($value) || $value === '') { continue; } $value = $value . '</div>'; //added the exploded </div> tag again, to avoid failures. $s_field_value = substr($value, strpos($value, '{') + 1); $s_field_value = substr($s_field_value, 0, strpos($s_field_value, '}')); $a_stats_html[$s_field_value] = $value; } //Set the current html of the template $this->s_current_template = $s_full_template; $this->a_stats_html = $a_stats_html; if ($b_use_cache && !Cache::getInstance()->exists('template_' . $s_template_name . '_html') && !Cache::getInstance()->exists('template_' . $s_template_name . '_stats')) { Cache::getInstance()->set('template_' . $s_template_name . '_html', $s_full_template, 86400); Cache::getInstance()->set('template_' . $s_template_name . '_stats', $a_stats_html, 86400); } } //load also all needed standard css and js. $this->load_standard_css_js(); } } catch (LOGD_Exception $e) { $e->print_error(); } }
* @todo set it later via database */ date_default_timezone_set('Europe/Berlin'); /* * Enable the auto-loader. * it will be accept namespace-based classes and also classes * with underscores. It will replace the underscores as path to the class. */ spl_autoload_register(function ($class) { spl_autoload(str_replace('_', DIRECTORY_SEPARATOR, $class)); }); //Clear complete cache if needed. //Cache::getInstance()->clear(); //die; //Initialize the random number generator mt_srand(LOGD::make_seed()); //Initialize the Session and the Routing Session::get_session(); Routing::init(); //check if the dbconfig.default.php exist, if yes - we have to install the game if (!file_exists(dirname(LOGD_ROOT) . DIRECTORY_SEPARATOR . '.dbconfig' . EXT) && file_exists(dirname(LOGD_ROOT) . DIRECTORY_SEPARATOR . '.dbconfig.default' . EXT)) { //try-catch the installer, if it fails try { new \Install\Installer(); } catch (LOGD_Exception $e) { $e->print_error(); } exit(1); } //Initialize the language Class //todo this is later only a fallback if nothing found in the database