source: t29-www/lib/technikum29.php @ 254

Last change on this file since 254 was 254, checked in by sven, 7 years ago

Weiterarbeit an t29v6 (5 Stunden):

  • News werden dynamisch als YAML aus einem Heredoc aus news.php rausgelesen und in das Menü eingepflegt (String-Ersetzung)
  • Caching-System: Jede generierte Seite wird nun gecacht
  • Objektorientierung: Der Library-Code ist pseudo-OOP
  • PHP 5.3-Abhängigkeit - keine create_function-Aufrufe mehr sondern Closures
File size: 1.5 KB
Line 
1<?php
2/**
3 * technikum29v6 - PHP Subsystem.
4 * Haupteinstiegspunkt ("WebStart.php"), welches
5 * ohne weiteren Funktionsaufruf alles macht.
6 *
7 **/
8
9if(defined('T29')) return false; // no nesting
10define('T29', true);
11
12$lib = dirname(__FILE__);
13$lang = "de-v6";
14$root = "/"; # webroot
15$file = substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT']));
16
17$skip_cache = isset($_GET['skip_cache']);
18$purge_cache = isset($_GET['purge_cache']);
19
20$cache_dir = "$lib/../shared/cache";
21
22# lightweight caching system
23$test_programs = array(
24        __FILE__,
25        $_SERVER['SCRIPT_FILENAME'],
26        "$lib/template.php",
27        "$lib/menu.php",
28        "$lib/../de-v6/hauptnavigation.xml",
29        "$lib/../de-v6/sidebar.xml",
30        "$lib/../de-v6/news.php",
31);
32
33$cache_file = $cache_dir . $file;
34$last_cache = @filemtime($cache_dir.$file);
35$last_program = array_reduce(array_map(function($x){return @filemtime($x);}, $test_programs), 'max');
36$cache_valid = $last_cache && $last_program < $last_cache;
37
38if(!$cache_valid || $skip_cache || $purge_cache) {
39        // rebuild cache
40        require "$lib/template.php";
41        $tmpl = new t29Template($GLOBALS);
42        $tmpl->create_cache();
43} else {
44        // use cache
45        header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_cache)." GMT");
46        //header("Etag: $etag");
47
48        if(@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_cache) {
49                // client already has page cached locally
50                header("HTTP/1.1 304 Not Modified");
51        } else {
52                readfile($cache_file);
53        }
54        exit;
55}
56
57// end of technikum29.php
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License