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

Last change on this file since 343 was 343, checked in by sven, 11 years ago

Sprachsystem gefixt bei Benutzung von mod_vhost_alias (Bug #32).

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