示例#1
0
function render_template($template_name, $assign_vars = array())
{
    // Initialize the template object.
    $tpl = new Template_Lite();
    // template directory
    $tpl->template_dir = TEMPLATE_PATH;
    // compile directory
    $tpl->compile_dir = COMPILED_TEMPLATE_PATH;
    // loop over the vars, assigning each.
    foreach ($assign_vars as $lname => $lvalue) {
        $tpl->assign($lname, $lvalue);
    }
    // call the template
    $rendered = $tpl->fetch($template_name);
    return $rendered;
}
示例#2
0
 /**
  * Call Template_lite display/fetch method (depends on @param $display)
  *
  * @param string $resource_name
  * @param string $theme - null - define by the current controller,
  * 								 what theme will be load (admin or user)
  * 						  'user' - load template from $this->user_theme
  * 						  'admin' - load template from $this->admin_theme
  * @param mixed (boolean/string) $module
  * 						  true - search for the template file in the module views
  * 						  false - search for the template file in the general views
  * 						  string - module name
  * @param integer $cache_id cache identifier
  * @param boolean $display output to browser
  * @return string
  */
 public function view($resource_name, $theme_type = null, $module = true, $cache_id = null, $display = true, $system_messages = true)
 {
     if (!isset($this->CI)) {
         $this->CI =& get_instance();
     }
     ///// preview mode
     if (!empty($_SESSION['change_color_scheme'])) {
         $preview_theme = $_SESSION["preview_theme"];
         $preview_scheme = $_SESSION["preview_scheme"];
     } else {
         $preview_theme = '';
         $preview_scheme = '';
     }
     $module_name = $module === true ? $this->CI->router->class : $module;
     $theme_data = $this->CI->pg_theme->format_theme_settings($module_name, $theme_type, $preview_theme, $preview_scheme);
     if (strpos($resource_name, '.') === false) {
         $resource_name .= '.tpl';
     }
     $img_folder_old = isset($this->_vars['img_folder']) ? $this->_vars['img_folder'] : '';
     $css_folder_old = isset($this->_vars['css_folder']) ? $this->_vars['css_folder'] : '';
     $logo_settings_old = isset($this->_vars['logo_settings']) ? $this->_vars['logo_settings'] : '';
     $this->assign("color_scheme", $preview_scheme ?: $theme_data["scheme"]);
     $this->assign("img_folder", $theme_data["img_path"]);
     $this->assign("css_folder", $theme_data["css_path"]);
     $this->assign("logo_settings", $theme_data["logo"]);
     $this->assign("mini_logo_settings", $theme_data["mini_logo"]);
     $this->assign("js_folder", APPLICATION_FOLDER . 'js/');
     //// language
     if (INSTALL_MODULE_DONE) {
         $language_data = $this->CI->pg_language->get_lang_by_id($this->CI->pg_language->current_lang_id);
         $this->assign("_LANG", $language_data);
         // Direction mark (&rtm; | &ltm;)
         $this->assign("DM", DM);
         $this->assign("DEMO_MODE", DEMO_MODE);
         if (DEMO_MODE) {
             $this->CI->config->load('demo_data', TRUE);
             $login_settings = $this->CI->config->item('login_settings', 'demo_data');
             $this->assign("demo_login_settings", $login_settings);
             $demo_user_type = $this->CI->session->userdata("demo_user_type");
             if (!$demo_user_type) {
                 $demo_user_type = "user";
             }
             $this->assign("demo_user_type", $demo_user_type);
             $this->assign("demo_user_type_login_settings", $login_settings[$demo_user_type]);
             $copyright = $this->CI->config->item('copyright', 'demo_data');
             $this->assign("demo_copyright", $copyright);
         }
         $this->assign("auth_type", $this->CI->session->userdata("auth_type"));
     }
     if ($system_messages) {
         $predefined["error"] = $this->CI->system_messages->get_messages('error');
         $predefined["info"] = $this->CI->system_messages->get_messages('info');
         $predefined["success"] = $this->CI->system_messages->get_messages('success');
         $predefined["header"] = $this->CI->system_messages->get_data('header');
         $predefined["subheader"] = $this->CI->system_messages->get_data('subheader');
         $predefined["help"] = $this->CI->system_messages->get_data('help');
         $predefined["back_link"] = $this->CI->system_messages->get_data('back_link');
         $this->assign("_PREDEFINED", $predefined);
     }
     if ($module !== false) {
         static $modules = array();
         if (isset($modules[$module . '_' . $resource_name])) {
             $resource_name = $modules[$module . '_' . $resource_name];
         } else {
             $resource_key = $resource_name;
             if (!empty($language_data)) {
                 $module_lang_css = $theme_data["css_module_path"] . "style-" . $language_data["rtl"] . ".css";
                 if (file_exists(SITE_PHYSICAL_PATH . $module_lang_css)) {
                     $this->CI->pg_theme->add_css($module_lang_css);
                 }
             }
             $module_css = $theme_data["css_module_path"] . "style.css";
             if (file_exists(SITE_PHYSICAL_PATH . $module_css)) {
                 $this->CI->pg_theme->add_css($module_css);
             }
             $this->assign("module_tpl_path_relative", base_url() . $theme_data["theme_module_path"]);
             $this->assign("module_path_relative", site_url() . ($this->CI->router->is_admin_class ? 'admin/' : '') . ($module === true ? $this->CI->router->class : $module) . '/');
             if (file_exists(SITE_PHYSICAL_PATH . $theme_data["theme_module_path"] . $resource_name)) {
                 $resource_name = SITE_PHYSICAL_PATH . $theme_data["theme_module_path"] . $resource_name;
             } elseif (file_exists(SITE_PHYSICAL_PATH . $theme_data["theme_path"] . $resource_name)) {
                 $resource_name = SITE_PHYSICAL_PATH . $theme_data["theme_path"] . $resource_name;
             } elseif (file_exists($this->template_dir . $resource_name)) {
                 $resource_name = $this->template_dir . $resource_name;
             } else {
                 log_message('error', 'File "' . $resource_name . '" does not exist');
                 return false;
             }
             $modules[$module . '_' . $resource_key] = $resource_name;
         }
     } else {
         $resource_name = SITE_PHYSICAL_PATH . $theme_data["theme_path"] . $resource_name;
     }
     if (!$display) {
         $content = parent::fetch($resource_name, $cache_id, $display);
         if ($img_folder_old) {
             $this->assign("img_folder", $img_folder_old);
         }
         if ($css_folder_old) {
             $this->assign("css_folder", $css_folder_old);
         }
         if ($logo_settings_old) {
             $this->assign("logo_settings", $logo_settings_old);
         }
         return $content;
     } else {
         if ($img_folder_old) {
             $this->assign("img_folder", $img_folder_old);
         }
         if ($css_folder_old) {
             $this->assign("css_folder", $css_folder_old);
         }
         if ($logo_settings_old) {
             $this->assign("logo_settings", $logo_settings_old);
         }
         parent::fetch($resource_name, $cache_id, $display);
     }
 }