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

Last change on this file since 580 was 561, checked in by sven, 10 years ago
  • lib: Weitere Fixes, um externe Einbindungen auch ueber Hostgrenzen zu schaffen
  • de/geraete: Zeichensatzfixes
  • menu.js: Keine Buttons, wenn in der Seitenleiste kein Menü eingeblendet wird
  • preferences.js: Versucht, den Bug anzugehen, dass mehrere Cookies angelegt werden
  • mobile.css: Breite vergrößert, ab der man das Tablet-Design angezeigt bekommt
  • Property svn:keywords set to Id
File size: 4.5 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// is it an external call?
13$external = isset($external);
14
15// at least the $seiten_id must be defined
16if(!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
23$lib = dirname(__FILE__);
24$webroot = realpath("$lib/../");  # file path to root of t29 web installation
25
26// early import host specific settings for making low level corrections like Bugfix #32
27require "$lib/host.php";
28$host = $external ? t29Host::create('t29ExternalHost') : t29Host::detect();
29
30$file = $host->script_filename; # e.g.: "/de/page.php"
31# Bug when DOCUMENT_ROOT ends with trailing slash: make sure $file begins with /:
32if($file{0} != '/') $file = "/$file";
33
34// exactly define debugging behaviour
35if(isset($_GET['debug'])) {
36        $_GET['purge_cache'] = true;
37        $_GET['rl_debug'] = true;
38}
39
40// check for url rewriting neccessarity (skip at external calls)
41if($host->check_url_rewrite()) exit;
42
43$cache_dir = "$webroot/shared/cache";
44$languages = array(
45// shorthand => array(full name in page, path from webroot)
46        "de" => array("Deutsch",  "/de"),
47        "en" => array("English", "/en"),
48);
49
50// make sure we have a page title
51if(isset($title)) $titel = $title;
52elseif(isset($titel)) $title = $titel;
53else $titel = $title = false; // to be determined by navigation seiten_id.
54
55// try to determine the language from the file path
56if(!isset($lang)) $lang = substr($file, 1, 2);
57if(!in_array($lang, array_keys($languages))) $lang = "de"; # check if language exists
58$lang_path = $languages[$lang][1]; # shorthand, relative to webroot. use "$webroot$lang_path" for local.
59
60// "AJAX" calls are our meaning for pages without chrome
61$ajax = isset($_GET['ajax']);
62if(!$external && $ajax) {
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();
67        // important: do not execute code further down (Templating stuff)
68        return true;
69}
70
71require "$lib/cache.php";
72
73// "External" pages which are not part of the t29 website
74if($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
86$page_cache = new t29Cache(false, true); // debug, verbose
87$page_cache->set_cache_file($webroot, $file);
88$page_cache->test_files =  array(
89        __FILE__,
90        $_SERVER['SCRIPT_FILENAME'],
91        "$lib/template.php",
92        "$lib/menu.php",
93        "$lib/messages.php",
94        "$lib/host.php",
95        "$webroot$lang_path/navigation.xml",
96        "$webroot$lang_path/news.php",
97        $webroot.$host->ressources_get_pagestyle($seiten_id),
98);
99
100// dynamical content:
101$static_page = !isset($dynamischer_inhalt);
102
103if(!$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;
108
109        $header_cache->set_cache_file($webroot, $file.'-header');
110        $footer_cache->set_cache_file($webroot, $file.'-footer');
111}
112
113if($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
137// 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