Changeset 297 in t29-www


Ignore:
Timestamp:
Sep 15, 2012, 7:32:28 PM (7 years ago)
Author:
sven
Message:

Verschiedenste Arbeiten im Backend:

  • URL-Catching-System implementiert, per Env-Variable und Mod-Rewrite. Alle Dateien sollen jetzt auch ohne .php-Endung laden bzw. auf eben jene URL-Repräsentation weiterleiten.
  • 404er-System mit Redirect-Mapping implementiert, die alte Geräteseiten auf neue Pendants weiterleitet.

Außerdem in dem Zug das Hostsystem und Loggingsystem umgebastelt. Caching-Fehler müssen noch frühzeitig erkannt werden, um nervige "Cache kann nicht geschrieben werden"-Fehler nicht mehr am Ende der Seite zu haben, sondern an präsenter Stelle oben.

Das Hostsystem kann nun per SERVER_NAME die Hostinstanz wählen, sodass das Seitenbearbeiten auf Heriberts Computer auf diese Weise funktionieren sollte.

Location:
lib
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • lib/404.php

    r295 r297  
    11<?php
     2/**
     3 * t29v6 404er Entry Point
     4 *
     5 * Will be called as ErrorDocument 404 which also catches old
     6 * file.shtml? URLs as well as old URLs which should be remapped
     7 * to new ones.
     8 *
     9 **/
    210
    3 array(
     11// standard arguments
     12$seiten_id = '404';
     13$version = '$Id$';
     14$titel = "404 Seite nicht gefunden";
     15$dynamischer_inhalt = true;
     16
     17$lib = dirname(__FILE__);
     18require "$lib/technikum29.php";
     19
     20#require_once "$lib/link.php";
     21
     22$wanted_page = $_SERVER['REQUEST_URI'];
     23
     24# check if page exists when replacing '.shtml?' => '.php':
     25$phpext_path = $_SERVER['DOCUMENT_ROOT'] . preg_replace('/\.shtml?$/i', '.php', $wanted_page);
     26if(file_exists($phpext_path)) {
     27        $noext_path = preg_replace('/\.shtml?$/i', '', $wanted_page);
     28        header('HTTP/1.1 301 Moved Permanently');
     29        header('Location: '.$noext_path);
     30        exit;
     31}
     32
     33# check that moved pages:
     34$redirects = array(
    435        # Inhaltsseiten
    536        #'/de/suche' => '/de/wir-suchen', # ups, das geht natuerlich
     
    1849        '/de/geraete/univac9400/univac_9300' => '/de/rechnertechnik/univac9200',
    1950        '/en/devices/univac9400/univac_9300' => '/en/computer/univac9200',
    20         '/de/geraete/bull-bs-pr/*' => '/de/rechnertechnik/tabelliermaschine',
     51        '/de/geraete/bull-bs-pr' => '/de/rechnertechnik/tabelliermaschine',
     52);
    2153
    22 );
     54foreach($redirects as $source => $target) {
     55        if(strcasecmp($source, $wanted_page) == 0) {
     56                # we got a match
     57                header('HTTP/1.1 301 Moved Permanently');
     58                header('Location: '.$target);
     59                exit;
     60        }
     61}
     62
     63?>
     64<h2>404 Seite nicht gefunden</h2>
     65
     66<p>Die gewünschte Adresse
     67
     68<address><?=$wanted_page; ?></address>
     69
     70<p>konnte nicht geladen werden. Probieren Sie folgendes... blabla ...
  • lib/cache.php

    r277 r297  
    199199                if($this->debug)
    200200                        print "Will start caching with shutdown: " . $register_shutdown_func . PHP_EOL;
     201                       
     202                // check if output file is writable; for logging and logging output
     203                // purpose.
     204                //if(!is_writable($this->cache_file))
     205                //      print "Cache file not writable: ".$this->cache_file;
     206                //      print "\n";
     207                //exit;
     208
    201209                ob_start();
    202210
  • lib/host.php

    r296 r297  
    1313 **/
    1414
    15 # Lightweight caching system
    16 class t29Host {
     15abstract class t29Host {
    1716        const webroot_host_file = '/host.php'; # relative to webroot
    1817        const webroot_local_host_classname = 't29LocalHost';
     18        const env_hidesuffix_name = "T29HIDESUFFIX";
     19
    1920
    2021        /// Some identifier like a FQDN. Must be overwritten!
    2122        public $hostname = "unknown";
     23
    2224
    2325        /**
     
    2628         * subclass has to be taken.
    2729         **/
    28         static function detect($template_conf) {
     30        static function detect() {
     31                $instance = null;
    2932
    3033                // check if local host file exists
    31                 $hostfile = $template_conf['webroot'].self::webroot_host_file;
     34                $hostfile = dirname(__FILE__) . '/../' . self::webroot_host_file;
    3235                if(file_exists($hostfile)) {
    3336                        include $hostfile;
    3437                        if(class_exists(self::webroot_local_host_classname)) {
    3538                                $x = self::webroot_local_host_classname;
    36                                 return new $x(); // this is php.
     39                                return new $x;
    3740                        }
    3841                }
    3942               
     43                // Quick and Dirty: Load hostname specific instances
     44                switch($_SERVER['SERVER_NAME']) {
     45                        case 'heribert':
     46                        case 'localhost':
     47                                return new t29HeribertHost;
     48                }
    4049               
    41                
    42                 // finally just load the default host
    43                 return new t29PublicHost();
     50                return new t29PublicHost;
    4451        }
     52       
     53        function check_url_rewrite() {
     54                if(isset($_SERVER[self::env_hidesuffix_name])) {
     55                        $path = $_SERVER['REQUEST_URI'];
     56                        $newpath = preg_replace("/\.(php|shtml?)$/i", '', $path);
     57                        if($path != $newpath) {
     58                                header('HTTP/1.1 301 Moved Permanently');
     59                                header('Location: '.$newpath);
     60                                return $newpath;
     61                        }
     62                }
     63                return null;
     64        }
     65
     66        abstract function fillup_template_conf(&$template_conf);
    4567}
    4668
     
    5072         * at www.technikum29.de.
    5173         **/
    52          public $hostname = "public";
     74        public $hostname = "public";
     75        function fillup_template_conf(&$template_conf) {}
    5376}
    5477
     
    6083        public $hostname = "heribert";
    6184
    62         function __construct() {
    63                 include_editor_header();
    64         }
    65 
    66         function include_editor_header() {
    67                 $this->tmplconf['header_prepend'][] =
     85        function fillup_template_conf(&$template_conf) {
     86                $template_conf['header_prepend'][] =
    6887                        '<meta name="t29.localfile" content="'.$_SERVER['SCRIPT_FILENAME'].'" id="localFileSource">';
    6988        }
  • lib/logging.php

    r275 r297  
    11<?php
     2/**
     3 * t29Log is a very lightweight logging system for t29v6.
     4 *
     5 * The logging class is accessible via the Singleton pattern, but should
     6 * be stored in a $GLOBAL["log"] and accessible like that everywhere.
     7 * The contents are printed in t29Template.
     8 *
     9 * Inspired by Klooger for PHP: https://github.com/katzgrau/KLogger/
     10 **/
    211
    3 /**
    4         Inspired by Klooger,
    5         https://github.com/katzgrau/KLogger/
    6 */
     12
    713class t29Log {
    814        const EMERG  = 'emerg';  // Emergency: system is unusable
     
    3238        public $entries = array();
    3339       
    34         function __construct() {
     40        // the one global t29Log instance
     41        private static $instance;
     42       
     43        // singleton access method
     44        public function get() {
     45                if(!isset(self::$instance))
     46                        self::$instance = new t29Log;
     47                return self::$instance;
     48        }
     49       
     50        private function __construct() {
    3551                // we shall be the PHP error handler
    3652                set_error_handler(array($this, 'log_phperror'));
     
    86102        }
    87103
    88        
     104        public function INFO($line, $args = self::NO_ARGUMENTS){
     105                $this->log($line, self::INFO, $args);
     106        }
     107
     108        public function DEBUG($line, $args = self::NO_ARGUMENTS){
     109                $this->log($line, self::INFO, $args);
     110        }
    89111       
    90112} // class
  • lib/technikum29.php

    r295 r297  
    2121        $_GET['rl_debug'] = true;
    2222}
     23
     24require "$lib/host.php";
     25$host = t29Host::detect();
     26
     27// check for url rewriting neccessarity
     28if($host->check_url_rewrite()) exit;
    2329
    2430$cache_dir = "$webroot/shared/cache";
     
    4955        "$lib/menu.php",
    5056        "$lib/messages.php",
     57        "$lib/host.php",
    5158        "$webroot$lang_path/navigation.xml",
    5259        "$webroot$lang_path/news.php",
  • lib/template.php

    r296 r297  
    1414
    1515class t29Template {
    16         public $conf, $menu, $msg, $host;
     16        public $conf, $menu, $msg;
    1717        public $body_classes = array();
    1818        public $javascript_config = array();
     
    2323                $this->conf = $conf_array;
    2424               
    25                 // create a lightweight logging object:
     25                // fetch the lightweight logging object:
    2626                require_once $this->conf['lib'].'/logging.php';
    27                 $this->log = new t29Log();
     27                $this->log = t29Log::get();
    2828
    2929                // create a menu:
     
    3131                $this->menu = new t29Menu($this->conf);
    3232
    33                 // create a host instance:
    34                 require_once $this->conf['lib'].'/host.php';
    35                 $this->host = t29Host::detect($this->conf);
    36 
    3733                // create localisation class:
    3834                require_once $this->conf['lib'].'/messages.php';
     
    4036
    4137                // fill up configuration
    42                 // optional configuration which can be filled by hooks or parts
     38
     39                // optional html headers which can be filled by hooks or parts
    4340                if(!isset($this->conf['header_prepend']))
    4441                        $this->conf['header_prepend'] = array(); // list
     42
     43                // as t29Host for configuration fillup fillup
     44                $this->conf['host']->fillup_template_conf($this->conf);
    4545               
    4646                // Path names in messages
     
    138138  <meta name="description" content="Produziert am 08.01.2012">
    139139  <meta name="author" content="technikum29-Team">
    140   <meta name="generator" content="t29v6">
     140  <meta name="generator" content="t29v6/<?php print $this->conf['host']->hostname; ?>">
    141141  <meta name="t29.cachedate" content="<?php print date('r'); ?>">
    142142  <?php
    143         foreach($this->conf['header_prepend'] as $h) print $h;
     143        foreach($this->conf['header_prepend'] as $h) print $h."\n  ";
    144144 
    145145        if(isset($this->conf['version'])) printf('<meta name="t29.version" content="%s">', $this->conf['version']);
Note: See TracChangeset for help on using the changeset viewer.
© 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