71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
|
<?php
|
||
|
|
||
|
$time_start = microtime(true);
|
||
|
|
||
|
date_default_timezone_set('Europe/Paris');
|
||
|
require_once '../vendor/autoload.php';
|
||
|
|
||
|
use App\Router;
|
||
|
use App\Cache;
|
||
|
use App\Utils\Config;
|
||
|
use App\Utils\Debug;
|
||
|
|
||
|
|
||
|
$config = Config::loadConfig();
|
||
|
|
||
|
$router = new Router;
|
||
|
|
||
|
$router->map('GET', '/', 'App\Controllers\Home');
|
||
|
$router->map('GET', '/posts/{page}', 'App\Controllers\Posts');
|
||
|
$router->map('GET', '/posts', 'App\Controllers\Posts');
|
||
|
$router->map('GET', '/post/{slug}', 'App\Controllers\Post');
|
||
|
$router->map('GET', '/about', 'App\Controllers\Page');
|
||
|
$router->map('GET', '/now', 'App\Controllers\Page');
|
||
|
$router->map('GET', '/favs', 'App\Controllers\Page');
|
||
|
$router->map('GET', '/blogroll', 'App\Controllers\Page');
|
||
|
$router->map('GET', '/slashes', 'App\Controllers\Page');
|
||
|
$router->map('GET', '/use', 'App\Controllers\Page');
|
||
|
$router->map('GET', '/contact', 'App\Controllers\Page'); // use special page
|
||
|
$router->map('GET', '/colophon', 'App\Controllers\Page');
|
||
|
if ($config['debug'] === true) {
|
||
|
$router->map('GET', '/dev', 'App\Controllers\Dev');
|
||
|
}
|
||
|
|
||
|
$match = $router->match($config);
|
||
|
|
||
|
if ($config['useCache'] === false) {
|
||
|
Cache::clearCache('page');
|
||
|
Cache::clearCache('feed');
|
||
|
Cache::clearCache('post');
|
||
|
Cache::clearCache('posts');
|
||
|
}
|
||
|
/*
|
||
|
@todo
|
||
|
add system for live preview whitout regen cache*/
|
||
|
if (isset($match['params']['extraParams']['live']) && $match['params']['extraParams']['live'] == 1 && $match['params']['config']['debug'] == true) {
|
||
|
$match['params']['config']['useCache'] = $config['useCache'] = false;
|
||
|
}
|
||
|
|
||
|
|
||
|
if ($match) {
|
||
|
if (Cache::isCache($match['params']) && Cache::isValidPage($match['params']) && Cache::isValidConfig() && $config['useCache'] === true) {
|
||
|
$gen = Cache::getCache($match['params']['cacheName'], $match['params']['type']);
|
||
|
$genType = 'Serve from cache in : ';
|
||
|
} else {
|
||
|
$gen = $router->render();
|
||
|
if ($config['useCache'] === true) {
|
||
|
Cache::setCache($match['params']['cacheName'], $gen, $match['params']['type']);
|
||
|
}
|
||
|
$genType = 'Build in : ';
|
||
|
}
|
||
|
|
||
|
$time_end = microtime(true);
|
||
|
$executionTime = round(($time_end - $time_start), 5);
|
||
|
$gen = preg_replace("/<% buildTime %>/", $genType . $executionTime . 's', $gen);
|
||
|
echo $gen;
|
||
|
exit;
|
||
|
} else {
|
||
|
header("Location: /");
|
||
|
exit;
|
||
|
}
|