2024-10-22 12:26:08 +02:00
|
|
|
<?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;
|
|
|
|
|
|
|
|
$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) {
|
2024-12-06 11:34:32 +01:00
|
|
|
if (Cache::isCache($match['params']) && Cache::isValidPage($match['params'], $config['theme']) && Cache::isValidConfig() && $config['useCache'] === true) {
|
2024-10-22 12:26:08 +02:00
|
|
|
$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;
|
|
|
|
}
|