[251] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * technikum29v6 - PHP Subsystem. |
---|
| 4 | * Haupteinstiegspunkt ("WebStart.php"), welches |
---|
| 5 | * ohne weiteren Funktionsaufruf alles macht. |
---|
| 6 | * |
---|
| 7 | **/ |
---|
[254] | 8 | |
---|
| 9 | if(defined('T29')) return false; // no nesting |
---|
| 10 | define('T29', true); |
---|
| 11 | |
---|
[560] | 12 | // is it an external call? |
---|
| 13 | $external = isset($external); |
---|
| 14 | |
---|
[354] | 15 | // at least the $seiten_id must be defined |
---|
| 16 | if(!isset($seiten_id)) { |
---|
| 17 | print "<html><pre>The t29v6 WebStart file\n"; |
---|
| 18 | print 'technikum29.php is the main include, but requires at least global <tt>$seiten_id</tt> to be defined.'; |
---|
| 19 | print "\n<a href='https://labs.technikum29.de/browser/technikum29%20Website/lib/technikum29.php'>Read my sourcecode</a>"; |
---|
| 20 | return false; |
---|
| 21 | } |
---|
| 22 | |
---|
[251] | 23 | $lib = dirname(__FILE__); |
---|
[255] | 24 | $webroot = realpath("$lib/../"); # file path to root of t29 web installation |
---|
[343] | 25 | |
---|
| 26 | // early import host specific settings for making low level corrections like Bugfix #32 |
---|
| 27 | require "$lib/host.php"; |
---|
[561] | 28 | $host = $external ? t29Host::create('t29ExternalHost') : t29Host::detect(); |
---|
[343] | 29 | |
---|
[357] | 30 | $file = $host->script_filename; # e.g.: "/de/page.php" |
---|
[295] | 31 | # Bug when DOCUMENT_ROOT ends with trailing slash: make sure $file begins with /: |
---|
| 32 | if($file{0} != '/') $file = "/$file"; |
---|
[251] | 33 | |
---|
[277] | 34 | // exactly define debugging behaviour |
---|
| 35 | if(isset($_GET['debug'])) { |
---|
| 36 | $_GET['purge_cache'] = true; |
---|
| 37 | $_GET['rl_debug'] = true; |
---|
| 38 | } |
---|
| 39 | |
---|
[560] | 40 | // check for url rewriting neccessarity (skip at external calls) |
---|
[297] | 41 | if($host->check_url_rewrite()) exit; |
---|
| 42 | |
---|
[255] | 43 | $cache_dir = "$webroot/shared/cache"; |
---|
| 44 | $languages = array( |
---|
| 45 | // shorthand => array(full name in page, path from webroot) |
---|
[285] | 46 | "de" => array("Deutsch", "/de"), |
---|
[288] | 47 | "en" => array("English", "/en"), |
---|
[255] | 48 | ); |
---|
| 49 | |
---|
[275] | 50 | // make sure we have a page title |
---|
| 51 | if(isset($title)) $titel = $title; |
---|
| 52 | elseif(isset($titel)) $title = $titel; |
---|
| 53 | else $titel = $title = false; // to be determined by navigation seiten_id. |
---|
| 54 | |
---|
[259] | 55 | // try to determine the language from the file path |
---|
[560] | 56 | if(!isset($lang)) $lang = substr($file, 1, 2); |
---|
[259] | 57 | if(!in_array($lang, array_keys($languages))) $lang = "de"; # check if language exists |
---|
[255] | 58 | $lang_path = $languages[$lang][1]; # shorthand, relative to webroot. use "$webroot$lang_path" for local. |
---|
| 59 | |
---|
[390] | 60 | // "AJAX" calls are our meaning for pages without chrome |
---|
| 61 | $ajax = isset($_GET['ajax']); |
---|
[560] | 62 | if(!$external && $ajax) { |
---|
[390] | 63 | // print only a minimal chrome, no caching. |
---|
| 64 | require "$lib/ajax-template.php"; |
---|
| 65 | $ajax_tmpl = new t29AJAXTemplate($GLOBALS); |
---|
| 66 | $ajax_tmpl->print_page(); |
---|
[560] | 67 | // important: do not execute code further down (Templating stuff) |
---|
[390] | 68 | return true; |
---|
| 69 | } |
---|
| 70 | |
---|
[264] | 71 | require "$lib/cache.php"; |
---|
[251] | 72 | |
---|
[560] | 73 | // "External" pages which are not part of the t29 website |
---|
| 74 | if($external) { |
---|
| 75 | // skip caching stuff. External pages don't get in touch with |
---|
| 76 | // any navigation.xml or news.php etc. |
---|
| 77 | require "$lib/template.php"; |
---|
| 78 | $header_cache = new t29Cache(/*debug*/false, /*verbose*/true, /*skip=memory only*/true); |
---|
| 79 | $footer_cache = new t29Cache(/*debug*/false, /*verbose*/true, /*skip=memory only*/true); |
---|
| 80 | $tmpl = new t29Template($GLOBALS); |
---|
| 81 | $tmpl->create_separate_caches($header_cache, $footer_cache); |
---|
| 82 | // important: do not execute caching stuff below |
---|
| 83 | return true; |
---|
| 84 | } |
---|
| 85 | |
---|
[264] | 86 | $page_cache = new t29Cache(false, true); // debug, verbose |
---|
| 87 | $page_cache->set_cache_file($webroot, $file); |
---|
[273] | 88 | $page_cache->test_files = array( |
---|
[254] | 89 | __FILE__, |
---|
| 90 | $_SERVER['SCRIPT_FILENAME'], |
---|
| 91 | "$lib/template.php", |
---|
| 92 | "$lib/menu.php", |
---|
[255] | 93 | "$lib/messages.php", |
---|
[297] | 94 | "$lib/host.php", |
---|
[260] | 95 | "$webroot$lang_path/navigation.xml", |
---|
| 96 | "$webroot$lang_path/news.php", |
---|
[516] | 97 | $webroot.$host->ressources_get_pagestyle($seiten_id), |
---|
[254] | 98 | ); |
---|
[251] | 99 | |
---|
[273] | 100 | // dynamical content: |
---|
| 101 | $static_page = !isset($dynamischer_inhalt); |
---|
[251] | 102 | |
---|
[273] | 103 | if(!$static_page) { |
---|
| 104 | // Pages with dynamical content: only cache header and footer, seperately. |
---|
| 105 | // they depend on same test files, so there is only one is_valid check. |
---|
| 106 | $header_cache = $page_cache; |
---|
| 107 | $footer_cache = clone $page_cache; |
---|
[251] | 108 | |
---|
[273] | 109 | $header_cache->set_cache_file($webroot, $file.'-header'); |
---|
| 110 | $footer_cache->set_cache_file($webroot, $file.'-footer'); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | if($page_cache->shall_use()) { |
---|
| 114 | if($static_page) |
---|
| 115 | $page_cache->print_cache_and_exit(); |
---|
| 116 | else { |
---|
| 117 | $header_cache->print_cache(true); |
---|
| 118 | register_shutdown_function(function() use ($footer_cache) { |
---|
| 119 | $footer_cache->print_cache(true); |
---|
| 120 | }); |
---|
| 121 | // now print your dynamical stuff in your page, the |
---|
| 122 | // footer content will be automatically added afterwards. |
---|
| 123 | } |
---|
| 124 | } else { |
---|
| 125 | // cache missed, rebuild cache |
---|
| 126 | require "$lib/template.php"; |
---|
| 127 | $tmpl = new t29Template($GLOBALS); |
---|
| 128 | if($static_page) |
---|
| 129 | // rebuild complete site cache |
---|
| 130 | $tmpl->create_cache($page_cache); |
---|
| 131 | else |
---|
| 132 | // rebuild each header and footer cache |
---|
| 133 | $tmpl->create_separate_caches($header_cache, $footer_cache); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
[343] | 137 | // end of technikum29.php |
---|