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 | // at least the $seiten_id must be defined |
---|
13 | if(!isset($seiten_id)) { |
---|
14 | print "<html><pre>The t29v6 WebStart file\n"; |
---|
15 | print 'technikum29.php is the main include, but requires at least global <tt>$seiten_id</tt> to be defined.'; |
---|
16 | print "\n<a href='https://labs.technikum29.de/browser/technikum29%20Website/lib/technikum29.php'>Read my sourcecode</a>"; |
---|
17 | return false; |
---|
18 | } |
---|
19 | |
---|
20 | $lib = dirname(__FILE__); |
---|
21 | $webroot = realpath("$lib/../"); # file path to root of t29 web installation |
---|
22 | |
---|
23 | // early import host specific settings for making low level corrections like Bugfix #32 |
---|
24 | require "$lib/host.php"; |
---|
25 | $host = t29Host::detect(); |
---|
26 | |
---|
27 | $file = $host->script_filename; # e.g.: "/de/page.php" |
---|
28 | # Bug when DOCUMENT_ROOT ends with trailing slash: make sure $file begins with /: |
---|
29 | if($file{0} != '/') $file = "/$file"; |
---|
30 | |
---|
31 | // exactly define debugging behaviour |
---|
32 | if(isset($_GET['debug'])) { |
---|
33 | $_GET['purge_cache'] = true; |
---|
34 | $_GET['rl_debug'] = true; |
---|
35 | } |
---|
36 | |
---|
37 | // check for url rewriting neccessarity |
---|
38 | if($host->check_url_rewrite()) exit; |
---|
39 | |
---|
40 | $cache_dir = "$webroot/shared/cache"; |
---|
41 | $languages = array( |
---|
42 | // shorthand => array(full name in page, path from webroot) |
---|
43 | "de" => array("Deutsch", "/de"), |
---|
44 | "en" => array("English", "/en"), |
---|
45 | ); |
---|
46 | |
---|
47 | // make sure we have a page title |
---|
48 | if(isset($title)) $titel = $title; |
---|
49 | elseif(isset($titel)) $title = $titel; |
---|
50 | else $titel = $title = false; // to be determined by navigation seiten_id. |
---|
51 | |
---|
52 | // try to determine the language from the file path |
---|
53 | $lang = substr($file, 1, 2); |
---|
54 | if(!in_array($lang, array_keys($languages))) $lang = "de"; # check if language exists |
---|
55 | $lang_path = $languages[$lang][1]; # shorthand, relative to webroot. use "$webroot$lang_path" for local. |
---|
56 | |
---|
57 | require "$lib/cache.php"; |
---|
58 | |
---|
59 | $page_cache = new t29Cache(false, true); // debug, verbose |
---|
60 | $page_cache->set_cache_file($webroot, $file); |
---|
61 | $page_cache->test_files = array( |
---|
62 | __FILE__, |
---|
63 | $_SERVER['SCRIPT_FILENAME'], |
---|
64 | "$lib/template.php", |
---|
65 | "$lib/menu.php", |
---|
66 | "$lib/messages.php", |
---|
67 | "$lib/host.php", |
---|
68 | "$webroot$lang_path/navigation.xml", |
---|
69 | "$webroot$lang_path/news.php", |
---|
70 | ); |
---|
71 | |
---|
72 | // dynamical content: |
---|
73 | $static_page = !isset($dynamischer_inhalt); |
---|
74 | |
---|
75 | if(!$static_page) { |
---|
76 | // Pages with dynamical content: only cache header and footer, seperately. |
---|
77 | // they depend on same test files, so there is only one is_valid check. |
---|
78 | $header_cache = $page_cache; |
---|
79 | $footer_cache = clone $page_cache; |
---|
80 | |
---|
81 | $header_cache->set_cache_file($webroot, $file.'-header'); |
---|
82 | $footer_cache->set_cache_file($webroot, $file.'-footer'); |
---|
83 | } |
---|
84 | |
---|
85 | if($page_cache->shall_use()) { |
---|
86 | if($static_page) |
---|
87 | $page_cache->print_cache_and_exit(); |
---|
88 | else { |
---|
89 | $header_cache->print_cache(true); |
---|
90 | register_shutdown_function(function() use ($footer_cache) { |
---|
91 | $footer_cache->print_cache(true); |
---|
92 | }); |
---|
93 | // now print your dynamical stuff in your page, the |
---|
94 | // footer content will be automatically added afterwards. |
---|
95 | } |
---|
96 | } else { |
---|
97 | // cache missed, rebuild cache |
---|
98 | require "$lib/template.php"; |
---|
99 | $tmpl = new t29Template($GLOBALS); |
---|
100 | if($static_page) |
---|
101 | // rebuild complete site cache |
---|
102 | $tmpl->create_cache($page_cache); |
---|
103 | else |
---|
104 | // rebuild each header and footer cache |
---|
105 | $tmpl->create_separate_caches($header_cache, $footer_cache); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | // end of technikum29.php |
---|