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

Last change on this file since 409 was 390, checked in by sven, 11 years ago
  • Vor/Zurück-Link bei Lernprojekten aktiviert
  • Anzeige fehlender englischer Übersetzungen wieder aktiviert (aufgehübscht; mit Infobox)
  • Property svn:keywords set to Id
File size: 3.7 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// at least the $seiten_id must be defined
13if(!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
24require "$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 /:
29if($file{0} != '/') $file = "/$file";
30
31// exactly define debugging behaviour
32if(isset($_GET['debug'])) {
33        $_GET['purge_cache'] = true;
34        $_GET['rl_debug'] = true;
35}
36
37// check for url rewriting neccessarity
38if($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
48if(isset($title)) $titel = $title;
49elseif(isset($titel)) $title = $titel;
50else $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);
54if(!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// "AJAX" calls are our meaning for pages without chrome
58$ajax = isset($_GET['ajax']);
59if($ajax) {
60        // print only a minimal chrome, no caching.
61        require "$lib/ajax-template.php";
62        $ajax_tmpl = new t29AJAXTemplate($GLOBALS);
63        $ajax_tmpl->print_page();
64        // important: do not execute bottom code
65        return true;
66}
67
68require "$lib/cache.php";
69
70$page_cache = new t29Cache(false, true); // debug, verbose
71$page_cache->set_cache_file($webroot, $file);
72$page_cache->test_files =  array(
73        __FILE__,
74        $_SERVER['SCRIPT_FILENAME'],
75        "$lib/template.php",
76        "$lib/menu.php",
77        "$lib/messages.php",
78        "$lib/host.php",
79        "$webroot$lang_path/navigation.xml",
80        "$webroot$lang_path/news.php",
81);
82
83// dynamical content:
84$static_page = !isset($dynamischer_inhalt);
85
86if(!$static_page) {
87        // Pages with dynamical content: only cache header and footer, seperately.
88        // they depend on same test files, so there is only one is_valid check.
89        $header_cache = $page_cache;
90        $footer_cache = clone $page_cache;
91
92        $header_cache->set_cache_file($webroot, $file.'-header');
93        $footer_cache->set_cache_file($webroot, $file.'-footer');
94}
95
96if($page_cache->shall_use()) {
97        if($static_page)
98                $page_cache->print_cache_and_exit();
99        else {
100                $header_cache->print_cache(true);
101                register_shutdown_function(function() use ($footer_cache) {
102                        $footer_cache->print_cache(true);
103                });
104                // now print your dynamical stuff in your page, the
105                // footer content will be automatically added afterwards.
106        }
107} else {
108        // cache missed, rebuild cache
109        require "$lib/template.php";
110        $tmpl = new t29Template($GLOBALS);
111        if($static_page)
112                // rebuild complete site cache
113                $tmpl->create_cache($page_cache);
114        else
115                // rebuild each header and footer cache
116                $tmpl->create_separate_caches($header_cache, $footer_cache);
117}
118
119
120// 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