forked from nakamuraapp/Rapido
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
92 lines (69 loc) · 2.42 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
<?php
global $site;
$config = include(__DIR__.'/config.php');
// embed cockpit
require_once(__DIR__."/{$config['admin']}/bootstrap.php");
date_default_timezone_set($config['timezone']);
$site = new LimeExtra\App($config);
$site["config"] = $config;
// register global paths
foreach ([
'site' => __DIR__,
'content' => __DIR__.'/content',
'snippets' => __DIR__.'/snippets',
'data' => __DIR__.'/storage/data',
'cache' => __DIR__.'/storage/cache',
'tmp' => __DIR__.'/storage/cache/tmp',
'media' => __DIR__.'/storage/media',
'lib' => __DIR__.'/lib',
'assets' => __DIR__.'/lib/assets',
'modules' => __DIR__.'/lib/modules',
'vendor' => __DIR__.'/lib/vendor',
'themes' => __DIR__.'/themes',
'theme' => __DIR__."/themes/{$config['theme']}",
'cockpit' => __DIR__."/{$config['admin']}",
] as $key => $path) { $site->path($key, $path); }
// nosql storage
$site->service('database', function() use($site) {
$client = new MongoLite\Client($site->path('data:'));
return $client->database;
});
// key-value storage
$site->service('memory', function() use($site) {
$client = new RedisLite(sprintf("%s/site.memory.sqlite", $site->path('data:')));
return $client;
});
// set cache path
$site("cache")->setCachePath("cache:tmp");
// bootstrap theme
if($themebootstrap = $site->path("theme:bootstrap.php")) {
include($themebootstrap);
}
// load extension modules
$site->loadModules(__DIR__.'/lib/modules');
// route to content mapping
$site->bind("/*", function() use($site) {
$view = false;
$route = str_replace('../', '', rtrim($site["route"], '/'));
$path = $site->path("content:".(strlen($route) ? $route : '/'));
if($path && is_file($path)) return false; // prevent direct access to files in the content folder
if ($path && is_dir($path)) {
if(file_exists("{$path}/index.php")) {
$view = "{$path}/index.php";
}
} else {
$view = $site->path("content:{$route}.php");
}
return $view ? $site->module("rapido")->render_page($view) : false;
});
// handle 404, 500
$site->on("after", function() use($site) {
switch ($site->response->status) {
case 500:
case 404:
$site->layout = false;
$site->response->body = $site->view("theme:{$site->response->status}.php");
break;
}
});
$site->trigger('site.init')->run();