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

Last change on this file since 255 was 255, checked in by sven, 7 years ago

Backend: Class cleanup, multi language support builtin, Message system (with experimental JSON connection). Template is ready to be deployed for multi language.

File size: 1.9 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$lang = "de"; # must be index in $languages
24$lang_path = $languages[$lang][1]; # shorthand, relative to webroot. use "$webroot$lang_path" for local.
25
26# Calling parameters
27$skip_cache = isset($_GET['skip_cache']);
28$purge_cache = isset($_GET['purge_cache']);
29
30# lightweight caching system
31$test_programs = array(
32        __FILE__,
33        $_SERVER['SCRIPT_FILENAME'],
34        "$lib/template.php",
35        "$lib/menu.php",
36        "$lib/messages.php",
37        "$lib/../de-v6/hauptnavigation.xml",
38        "$lib/../de-v6/sidebar.xml",
39        "$lib/../de-v6/news.php",
40);
41
42$cache_file = $cache_dir . $file;
43$last_cache = @filemtime($cache_dir.$file);
44$last_program = array_reduce(array_map(function($x){return @filemtime($x);}, $test_programs), 'max');
45$cache_valid = $last_cache && $last_program < $last_cache;
46
47if(!$cache_valid || $skip_cache || $purge_cache) {
48        // rebuild cache
49        require "$lib/template.php";
50        $tmpl = new t29Template($GLOBALS);
51        $tmpl->create_cache();
52} else {
53        // use cache
54        header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_cache)." GMT");
55        //header("Etag: $etag");
56
57        if(@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_cache) {
58                // client already has page cached locally
59                header("HTTP/1.1 304 Not Modified");
60        } else {
61                readfile($cache_file);
62        }
63        exit;
64}
65
66// 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