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

Last change on this file since 516 was 516, checked in by sven, 5 years ago

Bug #51 gefixt (http://labs.technikum29.de/ticket/51).
Jetzt sollten neue Pagestyles gleich beim Erstellen erkannt werden.

  • 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        $webroot.$host->ressources_get_pagestyle($seiten_id),
82);
83
84// dynamical content:
85$static_page = !isset($dynamischer_inhalt);
86
87if(!$static_page) {
88        // Pages with dynamical content: only cache header and footer, seperately.
89        // they depend on same test files, so there is only one is_valid check.
90        $header_cache = $page_cache;
91        $footer_cache = clone $page_cache;
92
93        $header_cache->set_cache_file($webroot, $file.'-header');
94        $footer_cache->set_cache_file($webroot, $file.'-footer');
95}
96
97if($page_cache->shall_use()) {
98        if($static_page)
99                $page_cache->print_cache_and_exit();
100        else {
101                $header_cache->print_cache(true);
102                register_shutdown_function(function() use ($footer_cache) {
103                        $footer_cache->print_cache(true);
104                });
105                // now print your dynamical stuff in your page, the
106                // footer content will be automatically added afterwards.
107        }
108} else {
109        // cache missed, rebuild cache
110        require "$lib/template.php";
111        $tmpl = new t29Template($GLOBALS);
112        if($static_page)
113                // rebuild complete site cache
114                $tmpl->create_cache($page_cache);
115        else
116                // rebuild each header and footer cache
117                $tmpl->create_separate_caches($header_cache, $footer_cache);
118}
119
120
121// 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