1 | <?php |
---|
2 | /** |
---|
3 | * technikum29v6 - PHP Subsystem. |
---|
4 | * Haupteinstiegspunkt ("WebStart.php"), welches |
---|
5 | * ohne weiteren Funktionsaufruf alles macht. |
---|
6 | * |
---|
7 | **/ |
---|
8 | |
---|
9 | if(defined('T29')) return false; // no nesting |
---|
10 | define('T29', true); |
---|
11 | |
---|
12 | $lib = dirname(__FILE__); |
---|
13 | $webroot = realpath("$lib/../"); # file path to root of t29 web installation |
---|
14 | $file = substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])); # e.g.: "/de/page.php" |
---|
15 | |
---|
16 | $cache_dir = "$webroot/shared/cache"; |
---|
17 | $languages = array( |
---|
18 | // shorthand => array(full name in page, path from webroot) |
---|
19 | "de" => array("Deutsch", "/de-v6"), |
---|
20 | "en" => array("English", "/en-v6"), |
---|
21 | ); |
---|
22 | |
---|
23 | // try to determine the language from the file path |
---|
24 | $lang = substr($file, 1, 2); |
---|
25 | if(!in_array($lang, array_keys($languages))) $lang = "de"; # check if language exists |
---|
26 | $lang_path = $languages[$lang][1]; # shorthand, relative to webroot. use "$webroot$lang_path" for local. |
---|
27 | |
---|
28 | # Calling parameters |
---|
29 | $skip_cache = isset($_GET['skip_cache']); |
---|
30 | $purge_cache = isset($_GET['purge_cache']); |
---|
31 | |
---|
32 | # lightweight caching system |
---|
33 | $test_programs = array( |
---|
34 | __FILE__, |
---|
35 | $_SERVER['SCRIPT_FILENAME'], |
---|
36 | "$lib/template.php", |
---|
37 | "$lib/menu.php", |
---|
38 | "$lib/messages.php", |
---|
39 | "$webroot$lang_path/navigation.xml", |
---|
40 | "$webroot$lang_path/news.php", |
---|
41 | ); |
---|
42 | |
---|
43 | $cache_file = $cache_dir . $file; |
---|
44 | $last_cache = @filemtime($cache_dir.$file); |
---|
45 | $last_program = array_reduce(array_map(function($x){return @filemtime($x);}, $test_programs), 'max'); |
---|
46 | $cache_valid = $last_cache && $last_program < $last_cache; |
---|
47 | |
---|
48 | if(!$cache_valid || $skip_cache || $purge_cache) { |
---|
49 | // rebuild cache |
---|
50 | require "$lib/template.php"; |
---|
51 | $tmpl = new t29Template($GLOBALS); |
---|
52 | $tmpl->create_cache(); |
---|
53 | } else { |
---|
54 | // use cache |
---|
55 | header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_cache)." GMT"); |
---|
56 | //header("Etag: $etag"); |
---|
57 | |
---|
58 | if(@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_cache) { |
---|
59 | // client already has page cached locally |
---|
60 | header("HTTP/1.1 304 Not Modified"); |
---|
61 | } else { |
---|
62 | readfile($cache_file); |
---|
63 | } |
---|
64 | exit; |
---|
65 | } |
---|
66 | |
---|
67 | // end of technikum29.php |
---|