theme.php (1830B)
1 <?php 2 class ControllerEventTheme extends Controller { 3 public function index(&$route, &$args, &$template) { 4 // If there is a template file we render 5 if ($template) { 6 // include and register Twig auto-loader 7 include_once(DIR_SYSTEM . 'library/template/Twig/Autoloader.php'); 8 9 Twig_Autoloader::register(); 10 11 // specify where to look for templates 12 $loader = new \Twig_Loader_Filesystem(DIR_TEMPLATE); 13 14 $config = array('autoescape' => false); 15 16 if ($this->config->get('template_cache')) { 17 $config['cache'] = DIR_CACHE; 18 } 19 20 // initialize Twig environment 21 $twig = new \Twig_Environment($loader, $config); 22 23 return $twig->createTemplate($template)->render($args); 24 } 25 } 26 27 public function override(&$route, &$args, &$template) { 28 if (!$this->config->get('theme_' . $this->config->get('config_theme') . '_status')) { 29 exit('Error: A theme has not been assigned to this store!'); 30 } 31 32 // If the default theme is selected we need to know which directory its pointing to 33 if ($this->config->get('config_theme') == 'default') { 34 $theme = $this->config->get('theme_default_directory'); 35 } else { 36 $theme = $this->config->get('config_theme'); 37 } 38 39 // If there is a theme override we should get it 40 $this->load->model('design/theme'); 41 42 $theme_info = $this->model_design_theme->getTheme($route, $theme); 43 44 if ($theme_info) { 45 $template = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8'); 46 } elseif (is_file(DIR_TEMPLATE . $theme . '/template/' . $route . '.twig')) { 47 $this->config->set('template_directory', $theme . '/template/'); 48 } elseif (is_file(DIR_TEMPLATE . 'default/template/' . $route . '.twig')) { 49 $this->config->set('template_directory', 'default/template/'); 50 } 51 } 52 }