forked from Talesoft/tale-jade-bootstrap
/
index.php
59 lines (44 loc) · 1.12 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
<?php
namespace MyWebsite;
use Tale\Jade\Renderer;
use Exception;
include 'vendor/autoload.php';
$config = [
'cache' => false,
'pretty' => true,
'url' => 'http://localhost'
];
if (file_exists(__DIR__.'/config.php'))
$config = array_replace_recursive($config, include(__DIR__.'/config.php'));
$renderer = new Renderer([
'compiler' => [
'pretty' => $config['pretty'],
'paths' => [
__DIR__.'/views/'
]
],
'adapter' => 'file',
'adapterOptions' => [
'path' => __DIR__.'/cache',
'lifeTime' => $config['cache'] ? 3600 : 0
]
]);
$page = isset($_GET['page'])
? preg_replace('/[^a-z0-9\-_]/i', '', $_GET['page'])
: 'index';
$action = isset($_GET['action'])
? preg_replace('/[^a-z0-9\-_]/i', '', $_GET['action'])
: 'index';
try {
echo $renderer->render('pages/'.$page, [
'page' => $page,
'action' => $action,
'url' => $config['url']
]);
} catch(Exception $e) {
echo $renderer->render('pages/404', [
'page' => $page,
'action' => $action,
'url' => $config['url']
]);
}