-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
151 lines (128 loc) · 4.87 KB
/
index.php
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
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* -----------------------------------------------------------------------------
* @package smartVISU
* @author Martin Gleiß
* @copyright 2012
* @license GPL [http://www.gnu.de]
* -----------------------------------------------------------------------------
*/
/**
* Version of smartVISU
*/
define ('config_version', '2.7');
// get config-variables
require_once 'lib/includes.php';
require_once const_path_system.'functions_twig.php';
// init parameters
$request = array_merge($_GET, $_POST);
// detect page and path
if ($request['page'] == '')
$request['page'] = config_index;
if (is_file(const_path."pages/".config_pages."/".$request['page'].".html")
or is_file(const_path."apps/".$request['page'].".html")
or is_file(const_path."pages/smarthome/".$request['page'].".html")
or is_file(const_path."pages/base/".$request['page'].".html")
)
{
// init template engine
require_once const_path.'vendor/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem(const_path.'apps');
if (is_dir(const_path.'pages/'.config_pages))
$loader->addPath(const_path.'pages/'.config_pages);
if (dirname($request['page']) != '.')
$loader->addPath(const_path.'pages/'.config_pages.'/'.dirname($request['page']));
// add dir if is not directly choosen
if (config_driver == 'smarthome.py' and config_pages != 'smarthome' and is_dir(const_path."pages/smarthome"))
$loader->addPath(const_path.'pages/smarthome');
$loader->addPath(const_path.'pages/base');
$loader->addPath(const_path.'widgets');
// init environment
$twig = new Twig_Environment($loader);
if (config_cache)
$twig->setCache(dirname(__FILE__).'/temp');
foreach ($request as $key => $val)
{
if ($key == "page")
$val = basename(str_replace('.', '_', $val));
$twig->addGlobal($key, $val);
}
$twig->addGlobal('pagepath', dirname($request['page']));
if (config_design == 'ice')
{
$twig->addGlobal('icon1', 'icons/bl/');
$twig->addGlobal('icon0', 'icons/sw/');
}
elseif (config_design == 'greenhornet')
{
$twig->addGlobal('icon1', 'icons/gn/');
$twig->addGlobal('icon0', 'icons/ws/');
}
else
{
$twig->addGlobal('icon1', 'icons/or/');
$twig->addGlobal('icon0', 'icons/ws/');
}
foreach (get_defined_constants() as $key => $val)
{
if (substr($key, 0, 6) == 'config')
$twig->addGlobal($key, $val);
}
$twig->addFilter('_', new Twig_Filter_Function('twig_concat'));
$twig->addFilter('round', new Twig_Filter_Function('twig_round'));
$twig->addFilter('bit', new Twig_Filter_Function('twig_bit'));
$twig->addFilter('substr', new Twig_Filter_Function('twig_substr'));
$twig->addFilter('smartdate', new Twig_Filter_Function('twig_smartdate'));
$twig->addFunction('uid', new Twig_Function_Function('twig_uid'));
$twig->addFunction('once', new Twig_Function_Function('twig_once'));
$twig->addFunction('isfile', new Twig_Function_Function('twig_isfile'));
$twig->addFunction('dir', new Twig_Function_Function('twig_dir'));
$twig->addFunction('docu', new Twig_Function_Function('twig_docu'));
$twig->addFunction('lang', new Twig_Function_Function('twig_lang'));
$twig->addFunction('implode', new Twig_Function_Function('twig_implode', array('is_safe' => array('html'))));
// init lexer comments
$lexer = new Twig_Lexer($twig, array('tag_comment' => array('/**', '*/')));
$twig->setLexer($lexer);
// load template
try
{
$template = $twig->loadTemplate($request['page'].'.html');
$ret = $template->render(array());
// try to zip the output
if ((strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) && (ini_get('zlib.output_compression') !== false))
{
header("Content-Encoding: gzip");
$ret = "\x1f\x8b\x08\x00\x00\x00\x00\x00".substr(gzcompress($ret, 9), 0, -4).pack("V", crc32($ret)).pack("V", strlen($ret));
}
echo $ret;
}
catch (Exception $e)
{
// header("HTTP/1.0 602 smartVISU Template Error");
echo "<pre>\n";
echo str_repeat(" ", 71)."smartVISU\n";
echo str_repeat(" ", 62).date('H:i, d.m').", v".config_version."\n";
echo str_repeat("-", 80)."\n\n";
echo "Error accoured in twig-template engine!\n\n";
echo "error: <b>".$e->getRawMessage()."</b>\n";
echo "file: ".$e->getTemplateFile()."\n";
echo "line: ".$e->getTemplateLine()."\n\n";
echo str_repeat("-", 80)."\n\n";
echo "\n</pre>";
}
}
else
{
header("HTTP/1.0 404 Not Found");
echo "<pre>\n";
echo str_repeat(" ", 71)."smartVISU\n";
echo str_repeat(" ", 62).date('H:i, d.m').", v".config_version."\n";
echo str_repeat("-", 80)."\n\n";
echo "Error loading Page '<b>".$request['page']."</b>' !\n\n";
echo "Check config.php -> 'config_pages' for correct Pages/Project configuration\n";
echo "or try the <a href='index.php'>index</a> page!\n\n";
echo str_repeat("-", 80)."\n\n";
echo "\n</pre>";
}
?>