run.php
3.79 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
session_start();
require_once("config.class.php");
require_once("router.class.php");
require_once("controller_base.class.php");
require_once("block_base.class.php");
require_once("db.class.php");
require_once("template.class.php");
require_once("blocks.php");
require_once("libs/PHPMailer/class.phpmailer.php");
require_once("libs/resize-class.php");
require_once("libs/HTTP/Download.php");
require_once("function.php");
Config::init();
spl_autoload_register('__autoload');
function __autoload($class_name) {
$dir = 'modules';
//print strchr($class_name,'Block',true);
/* if(preg_match("/(.+)Block/i", $class_name, $matches)){
$filename = 'blocks/' . strtolower($matches[1]) . '.block.class.php';
}else */
$filename = 'model/' . strtolower($class_name) . '.class.php';
/* if ($dh = opendir($dir)) {
while (($module = readdir($dh)) !== false) {
if($module!="." && $module!=".."){ */
$file = $dir . '/' . router::$modul . '/' . $filename;
if (file_exists($file) == true)
{
include ($file); return;
}
/* }
}
closedir($dh);
} */
}
Class Run{
private $tpl;
private $error = array();
private $router;
private $blocks;
private $model;
private $url;
private $this_url;
private $navig;
private $meta;
function __construct() {
$this->tpl = new Template(new Config);
$this->router = new router();
$this->router->setPath (Config::get('modules_path'),Config::get('modules_default'),Config::get('modules_controller_path'));
// $this->router->setStart(Config::get('start'));
$this->router->setRule(Config::get('rules'));
$this->router->setLangs(Config::get('langs'),Config::get('lang'));
$this->blocks = new Blocks();
}
public function loader(){
$module = $this->router->loader();
$this->loaderLang($this->router->lang);
$this->view_url(Config::get('url'),Config::get('lang'),$this->router->lang);
$this->setMeta();
$this->setNavig();
$this->router->setParams($this->tpl,$this->error,$this->url,$this->this_url,$this->navig,$this->meta);
$this->router->run();
$this->blocks->setParams($this->tpl,$this->error,$this->router->lang,$this->url,$this->router->getParam,$this->router->postParam);
$this->blocks->loader($module['path'],$module['controller']);
$this->view_lang($this->router->lang);
$this->view_linksLangs(Config::get('url'),Config::get('langs'),Config::get('lang'),$this->router->lang);
$this->view_meta();
$this->view_navig();
$this->layout();
}
private function setMeta(){
$this->meta = Config::get('meta');
}
private function setNavig(){
$this->navig[] = array('url'=>$this->url,'name'=>Config::get('site'));
}
private function view_lang($lang){
$this->tpl->viewLang($lang);
}
private function view_url($url,$default_lang,$lang){
$this->url = $url;
$this->this_url = $this->url . '/' . $_GET['rt'];
if($default_lang!=$lang)$this->url .= '/' . $lang;
$this->tpl->viewUrl($this->this_url,$this->url);
}
private function loaderLang($lang){
$path = "lang/" . $lang . ".php";
if( is_readable($path) ){
include_once $path;
}
}
private function view_linksLangs($url,$langs,$default_lang,$lang){// print $_SERVER['REQUEST_URI'];
$l = array();
$field = strrchr($url, '/');
$REQUEST_URI = str_replace($field,'',$_SERVER['REQUEST_URI']);
$r = explode($lang,$REQUEST_URI);
foreach($langs as $str_lang){
$l[$str_lang] = $url . '/';
if($default_lang!=$str_lang)$l[$str_lang] .= $str_lang . '/';
$l[$str_lang] .= substr($r[count($r)-1],1);
}
$this->tpl->viewLinksLangs($l);
}
private function view_meta(){
$this->tpl->viewMeta($this->meta);
}
private function view_navig(){
$this->tpl->viewNavig($this->navig);
}
private function layout(){
$this->tpl->viewError($this->error);
$this->tpl->layout();
}
}
?>