/** * workhorse of the website, it loads the template and shows it or returns th html. * it uses smarty to load the $template, but before displaying the template it will pass the $vars to smarty. Also based on your language settings a matching * array of words & sentences for that page will be loaded. In case the $returnHTML parameter is set to true, it will return the html instead of displaying the template. * * @param $template the name of the template(page) that we want to load. * @param $vars an array of variables that should be loaded by smarty before displaying or returning the html. * @param $returnHTML (default=false) if set to true, the html that should have been displayed, will be returned. * @return in case $returnHTML=true, it returns the html of the template being loaded. */ public static function loadTemplate($template, $vars = array(), $returnHTML = false) { //error_log(print_r($_GET,true)); //error_log(print_r($_POST,true)); global $AMS_LIB; global $SITEBASE; global $AMS_TRANS; global $INGAME_LAYOUT; global $AMS_CACHEDIR; global $AMS_PLUGINS; // define('SMARTY_SPL_AUTOLOAD',1); require_once $AMS_LIB . '/smarty/libs/Smarty.class.php'; spl_autoload_register('__autoload'); $smarty = new Smarty(); $smarty->setCompileDir($SITEBASE . '/templates_c/'); $smarty->setCacheDir($AMS_CACHEDIR); $smarty->setConfigDir($SITEBASE . '/configs/'); // turn smarty debugging on/off $smarty->debugging = false; // caching must be disabled for multi-language support $smarty->caching = false; $smarty->cache_lifetime = 300; $smarty->addPluginsDir($AMS_PLUGINS); if (function_exists('apc_cache_info')) { // production //$smarty->caching = true; //$smarty->setCachingType("apc"); //$smarty->compile_check = false; } // needed by smarty. helpers::create_folders(); global $FORCE_INGAME; // if ingame, then use the ingame templates if (helpers::check_if_game_client() or $FORCE_INGAME) { $smarty->template_dir = $AMS_LIB . '/ingame_templates/'; $smarty->setConfigDir($AMS_LIB . '/configs'); $variables = parse_ini_file($AMS_LIB . '/configs/ingame_layout.ini', true); foreach ($variables[$INGAME_LAYOUT] as $key => $value) { $smarty->assign($key, $value); } } else { $smarty->template_dir = $SITEBASE . '/templates/'; $smarty->setConfigDir($SITEBASE . '/configs'); } foreach ($vars as $key => $value) { $smarty->assign($key, $value); } // load page specific variables that are language dependent $variables = Helpers::handle_language(); if ($template != 'layout_plugin') { foreach ($variables[$template] as $key => $value) { $smarty->assign($key, $value); } } // load ams content variables that are language dependent foreach ($variables['ams_content'] as $key => $value) { $smarty->assign($key, $value); } //load ams content variables that are language dependent foreach ($variables['ams_content'] as $key => $value) { $smarty->assign($key, $value); } $id = session_id(); $smarty->assign("sessionid", $id); $dbl = new DBLayer("lib"); $statement = $dbl->executeWithoutParams("SELECT * FROM settings"); $rows = $statement->fetchAll(); foreach ($rows as &$value) { $smarty->assign($value['Setting'], $value['Value']); } // smarty inheritance for loading the matching wrapper layout (with the matching menu bar) if (isset($vars['permission']) && $vars['permission'] == 3) { $inherited = "extends:layout_admin.tpl|"; } else { if (isset($vars['permission']) && $vars['permission'] == 2) { $inherited = "extends:layout_mod.tpl|"; } else { if (isset($vars['permission']) && $vars['permission'] == 1) { $inherited = "extends:layout_user.tpl|"; } else { $inherited = ""; } } } // if $returnHTML is set to true, return the html by fetching the template else display the template. if ($returnHTML == true) { return $smarty->fetch($inherited . $template . '.tpl'); } else { $smarty->display($inherited . $template . '.tpl'); } }