template.class.php
2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once("libs/Smarty-3.0.9/libs/Smarty.class.php");
Class Template Extends Smarty {
private $layout = 'index';
private $layout_option = 'index';
private $layout_prefix = 'tpl';
private $tpl;
private $tpl_path = 'views';
function __construct($config) {
parent::__construct();
$this->template_dir[] = './views/';
$this->compile_dir = './views/compile/';
$this->setLayout($config->layout);
$this->layout_prefix = $config->layout_prefix;
$this->assign('config',$config);
$this->plugins_dir[] = "./plugins/";
}
private function setNameTpl($name){
return $name . '.' . $this->layout_prefix;
}
public function setLayout($layout){
$this->layout_option = $layout;
}
public function layout(){
if(!$this->layout)return;
$this->display($this->setNameTpl($this->layout));
}
function controllerAction($path,$modules,$controller, $action){
$this->template_dir[] = './'.$path . '/' . $modules .'/' . $this->tpl_path .'/' . $controller . '/';
$this->tpl = './'.$path . '/' . $modules .'/' . $this->tpl_path .'/' . $controller . '/' . $action;
// if(!is_file($this->setNameTpl($this->tpl)))$this->tpl = './'.$path . '/' . $modules .'/' . $this->tpl_path .'/' . "error404" .'/' . 'index';
// $this->tpl404 = '../'.$path . '/' . $modules .'/' . $this->tpl_path .'/error404/index';
//print_r($this->layout_option[$modules][$controller]);
if(isset($this->layout_option[$modules][$controller][$action]))$this->layout = $this->layout_option[$modules][$controller][$action];
elseif(isset($this->layout_option[$modules][$controller])) $this->layout = (isset($this->layout_option[$modules][$controller]['default'])) ? $this->layout_option[$modules][$controller]['default'] : $this->layout_option[$modules]['default'];
elseif(isset($this->layout_option[$modules]))$this->layout = $this->layout_option[$modules]['default'];
else $this->layout = 'default';
$this->assign('controller_action',$controller . '_' . $action);
$this->assign('controller',$controller);
}
public function setAction(){
$tpl = $this->setNameTpl($this->tpl);
// if(!is_file($tpl))$tpl = $this->setNameTpl($this->tpl404);
$this->assign('tpl',$tpl);
}
public function viewLang($lang){
$this->assign('lang',$lang);
}
public function viewLinksLangs($links){
$this->assign('links_lang',$links);
}
public function viewUrl($this_url,$url_lang){
$this->assign('this_url',$this_url);
$this->assign('url_lang',$url_lang);
}
public function viewMeta($meta){
$this->assign('meta',$meta);
}
public function viewNavig($navig){
$this->assign('navig',$navig);
}
public function viewError($error){
$this->assign('error',$error);
}
}
?>