X-Git-Url: https://git.bts.cx/cx.git/blobdiff_plain/326cc7d316faee2371e3b7d62e61b5158c681649..HEAD:/cx/lib/template.php?ds=sidebyside diff --git a/cx/lib/template.php b/cx/lib/template.php index 6826d16..638c600 100644 --- a/cx/lib/template.php +++ b/cx/lib/template.php @@ -9,10 +9,10 @@ function cx_template_content_path($class, $path) { } function cx_template_has_content($class, $path) { - return file_exists(cx_template_content_path($class, $path)); + return is_file(cx_template_content_path($class, $path)); } -function cx_template_output_content($class, $path) { +function cx_template_output_content($class, $path, $cache_age = 30 * 86400) { $full_path = cx_template_content_path($class, $path); $extension = pathinfo($path, PATHINFO_EXTENSION); @@ -25,8 +25,22 @@ function cx_template_output_content($class, $path) { //finfo_close($finfo); - Deprecated } + $file_size = filesize($full_path); + $file_modified_time = filemtime($full_path); + header('Content-Type: ' . $mime_type); - header('Content-Length: ' . filesize($full_path)); + header('Content-Length: ' . $file_size); + header('Cache-Control: public, max-age=604800'); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $cache_age) . ' GMT'); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file_modified_time) . ' GMT'); + + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { + $request_modification = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']); + if ($request_modification >= $file_modified_time) { + http_response_code(304); + return; + } + } $fp = fopen($full_path, 'rb'); fpassthru($fp);