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

Last change on this file since 260 was 260, checked in by sven, 12 years ago

JavaScripts fuer v6

Alle Scripte aus v5 in einzelne Dateien rueberkopiert, kompatibel zum neuen System gemacht. Mit einem RessourceLoader-aehnlichen Konzept werden nun alle Javascripts serverseitig gebuendelt und komprimiert, dabei werden auch die Messages von PHP ueber JSON zur Ladezeit mitgegeben. Seitenspezifische Conf wird ueber das Template injektziert.

Bugfixes

  • navigation.xml (en/de): Tote Links zu Navigationszwecken brauchbar gemacht, mit "#DUMME-VERLINKUNG" als Anker um auf inkonsistentes Navigationskonzept hinzuweisen
  • de/news.php: Exemplarische Deeplinks angepasst, funktionieren jetzt
  • de-v6/rechnertechnik/ic-technik.php: Kleiner Designfix (uralte Klasse "h-ul" durch Inlinecode ersetzt wie in en)
  • lib/menu.php: Bugfix
  • lib/messages.php: Neue Nachrichten, vom JS-System
  • etc.
File size: 2.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$file = substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])); # e.g.: "/de/page.php"
15
16$cache_dir = "$webroot/shared/cache";
17$languages = array(
18// shorthand => array(full name in page, path from webroot)
19        "de" => array("Deutsch",  "/de-v6"),
20        "en" => array("English", "/en-v6"),
21);
22
23// try to determine the language from the file path
24$lang = substr($file, 1, 2);
25if(!in_array($lang, array_keys($languages))) $lang = "de"; # check if language exists
26$lang_path = $languages[$lang][1]; # shorthand, relative to webroot. use "$webroot$lang_path" for local.
27
28# Calling parameters
29$skip_cache = isset($_GET['skip_cache']);
30$purge_cache = isset($_GET['purge_cache']);
31
32# lightweight caching system
33$test_programs = array(
34        __FILE__,
35        $_SERVER['SCRIPT_FILENAME'],
36        "$lib/template.php",
37        "$lib/menu.php",
38        "$lib/messages.php",
39        "$webroot$lang_path/navigation.xml",
40        "$webroot$lang_path/news.php",
41);
42
43$cache_file = $cache_dir . $file;
44$last_cache = @filemtime($cache_dir.$file);
45$last_program = array_reduce(array_map(function($x){return @filemtime($x);}, $test_programs), 'max');
46$cache_valid = $last_cache && $last_program < $last_cache;
47
48if(!$cache_valid || $skip_cache || $purge_cache) {
49        // rebuild cache
50        require "$lib/template.php";
51        $tmpl = new t29Template($GLOBALS);
52        $tmpl->create_cache();
53} else {
54        // use cache
55        header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_cache)." GMT");
56        //header("Etag: $etag");
57
58        if(@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_cache) {
59                // client already has page cached locally
60                header("HTTP/1.1 304 Not Modified");
61        } else {
62                readfile($cache_file);
63        }
64        exit;
65}
66
67// 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