php session_start require_once Smarty Smarty class php require_once La

 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
<?php
session_start();
require_once 'Smarty/Smarty.class.php';
require_once 'Languages.class.php';
class Controller {
private $sections = [], $config = [], $ipinfo = [];
public static function prepare() {
return new Controller();
}
public function readConfig($filename = 'settings.ini') {
$this->config = parse_ini_file($filename, true);
return $this;
}
public function normalizeURI() {
$query = '';
foreach($_GET as $key => $value)
if(preg_match('/^[A-z0-9]+$/', $key) && (preg_match('/^[A-z0-9]+$/', $value) || empty($value)))
$query .= (!empty($query) ? '&' : '') . $key . (!empty($value) ? '=' . $value : '');
else {
header('Location: /');
exit;
}
$this->sections = explode('|', implode('|', array_filter(explode('/', preg_replace('/\/+/', '/', str_replace('\\', '/', substr($_SERVER['REQUEST_URI'], 0, (strpos($_SERVER['REQUEST_URI'], '?') ? strpos($_SERVER['REQUEST_URI'], '?') : strlen($_SERVER['REQUEST_URI'])))))))));
foreach($this->sections as $key => $value)
if(!preg_match('/^[A-z0-9]+$/', $value) && $value) {
header('Location: /');
exit;
}
$normalize = '/' . (!empty(implode('/', $this->sections)) ? implode('/', $this->sections) . '/' : '') . (!empty($query) ? '?' . $query : '');
if($normalize != $_SERVER['REQUEST_URI']) {
header('Location: ' . $normalize);
exit;
}
return $this;
}
public function run() {
if($this->sections[0] == 'setLanguage' && !empty($this->sections[1]))
Languages::setLanguage($this->sections[1]);
if(!isset($_SESSION['lang']))
Languages::setLanguage();
$_SESSION['template'] = 'wap'; //debug
$tpl = new Smarty();
$tpl->setTemplateDir('templates/' . $_SESSION['template'] . '/data/');
$tpl->setCompileDir('templates/' . $_SESSION['template'] . '/compile/');
// -> switcher();
$tpl->assign('lang', Languages::getLanguage($_SESSION['lang']));
$tpl->display('index.tpl');
}
}