source: t29-www/lib/host.php @ 299

Last change on this file since 299 was 298, checked in by sven, 12 years ago
  • Host: Tippfehler in ENV-Variable, die abgegriffen wird (T29URLHIDEPREFIX)
  • Menu: Extraseiten serverseitig wieder ausgebunden
File size: 2.5 KB
Line 
1<?php
2/**
3 * t29v6 new Hostinfo and Hosthook system.
4 *
5 * Local host.php files in the webroot can hook into t29* php
6 * and js classes without interfering the code. This can be usually
7 * be used for extra svn information.
8 * Hostinfos can also be appended in this file and therefore be
9 * managed centrally.
10 *
11 * webroot/host.php muss have a t29LocalHost extends t29Host class.
12 *
13 **/
14
15abstract class t29Host {
16        const webroot_host_file = '/host.php'; # relative to webroot
17        const webroot_local_host_classname = 't29LocalHost';
18        const env_hidesuffix_name = "T29URLHIDESUFFIX";
19
20
21        /// Some identifier like a FQDN. Must be overwritten!
22        public $hostname = "unknown";
23
24
25        /**
26         * Factory for creating a t29Host instance automatically
27         * from the current host. This method will decide which
28         * subclass has to be taken.
29         **/
30        static function detect() {
31                $instance = null;
32
33                // check if local host file exists
34                $hostfile = dirname(__FILE__) . '/../' . self::webroot_host_file;
35                if(file_exists($hostfile)) {
36                        include $hostfile;
37                        if(class_exists(self::webroot_local_host_classname)) {
38                                $x = self::webroot_local_host_classname;
39                                return new $x;
40                        }
41                }
42               
43                // Quick and Dirty: Load hostname specific instances
44                switch($_SERVER['SERVER_NAME']) {
45                        case 'heribert':
46                        case 'localhost':
47                                return new t29HeribertHost;
48                }
49               
50                return new t29PublicHost;
51        }
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);
67}
68
69class t29PublicHost extends t29Host {
70        /**
71         * This is actually the default public host which should be loaded
72         * at www.technikum29.de.
73         **/
74        public $hostname = "public";
75        function fillup_template_conf(&$template_conf) {}
76}
77
78/**
79 * Host auf heriberts Rechner; dort wird ein weiterer Metatag mit id eingefuehrt,
80 * mit dem seine Firefox Editthispage-Extension die Seite bearbeiten kann.
81 **/
82class t29HeribertHost extends t29Host {
83        public $hostname = "heribert";
84
85        function fillup_template_conf(&$template_conf) {
86                $template_conf['header_prepend'][] = 
87                        '<meta name="t29.localfile" content="'.$_SERVER['SCRIPT_FILENAME'].'" id="localFileSource">';
88        }
89}
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