65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
|
<?php
|
||
|
|
||
|
use EesyPHP\Tpl;
|
||
|
use EesyPHP\Url;
|
||
|
|
||
|
/**
|
||
|
* Redirect to homepage
|
||
|
* @param EesyPHP\UrlRequest $request
|
||
|
* @return void
|
||
|
*/
|
||
|
function handle_redirect_homepage($request) {
|
||
|
Url::redirect("home");
|
||
|
}
|
||
|
Url :: add_url_handler(null, 'handle_redirect_homepage');
|
||
|
|
||
|
/**
|
||
|
* Homepage
|
||
|
* @param EesyPHP\UrlRequest $request
|
||
|
* @return void
|
||
|
*/
|
||
|
function handle_homepage($request) {
|
||
|
Tpl :: display("index.tpl");
|
||
|
}
|
||
|
Url :: add_url_handler("#^home$#", 'handle_homepage');
|
||
|
|
||
|
function _list_static_directory_files($root_dir, $dir, &$result, &$last_updated) {
|
||
|
foreach (array_diff(scandir($dir), array('.','..')) as $file) {
|
||
|
$path = "$dir/$file";
|
||
|
if (is_dir($path)) {
|
||
|
_list_static_directory_files($root_dir, $path, $result, $last_updated);
|
||
|
}
|
||
|
else {
|
||
|
$result[] = Tpl::static_url(substr($path, strlen($root_dir)+1));
|
||
|
$file_last_updated = filemtime($path);
|
||
|
if ($file_last_updated > $last_updated)
|
||
|
$last_updated = $file_last_updated;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Cache manifest file
|
||
|
* @param EesyPHP\UrlRequest $request
|
||
|
* @return void
|
||
|
*/
|
||
|
function handle_cache_manifest($request) {
|
||
|
$cache = ["home"];
|
||
|
$last_updated = filemtime(Tpl::resolve_templates_path("index.tpl"));
|
||
|
foreach (Tpl::static_directories() as $static_directory)
|
||
|
_list_static_directory_files($static_directory, $static_directory, $cache, $last_updated);
|
||
|
Tpl::assign("cache", $cache);
|
||
|
Tpl::assign("last_updated", date("Y/m/d H:i:s", $last_updated));
|
||
|
header("Content-type: text/plain");
|
||
|
$content = Tpl::fetch("cache_manifest.tpl");
|
||
|
$etag = md5($content);
|
||
|
header("Cache-Control: max-age=3000, must-revalidate");
|
||
|
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_updated)." GMT");
|
||
|
header("Etag: $etag");
|
||
|
print($content);
|
||
|
exit();
|
||
|
}
|
||
|
Url :: add_url_handler("#^cache\.manifest$#", 'handle_cache_manifest');
|
||
|
|
||
|
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab
|