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

Last change on this file since 343 was 343, checked in by sven, 11 years ago

Sprachsystem gefixt bei Benutzung von mod_vhost_alias (Bug #32).

File size: 2.7 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 = "undefined";
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                        } else {
41                                print "Warning: Hostfile $hostfile does not contain class ".self::webroot_local_host_classname."\n";
42                        }
43                }
44               
45                // Quick and Dirty: Load hostname specific instances
46                switch($_SERVER['SERVER_NAME']) {
47                        case 'heribert':
48                        case 'localhost':
49                                return new t29HeribertHost;
50                }
51               
52                return new t29PublicHost;
53        }
54       
55        function check_url_rewrite() {
56                if(isset($_SERVER[self::env_hidesuffix_name])) {
57                        $path = $_SERVER['REQUEST_URI'];
58                        $newpath = preg_replace("/\.(php|shtml?)$/i", '', $path);
59                        if($path != $newpath) {
60                                header('HTTP/1.1 301 Moved Permanently');
61                                header('Location: '.$newpath);
62                                return $newpath;
63                        }
64                }
65                return null;
66        }
67
68        public function __toString() {
69                return 't29v6/host:'.$this->hostname;
70        }
71
72        abstract function fillup_template_conf(&$template_conf);
73}
74
75class t29PublicHost extends t29Host {
76        /**
77         * This is actually the default public host which should be loaded
78         * at www.technikum29.de.
79         **/
80        public $hostname = "public";
81        function fillup_template_conf(&$template_conf) {}
82}
83
84/**
85 * Host auf heriberts Rechner; dort wird ein weiterer Metatag mit id eingefuehrt,
86 * mit dem seine Firefox Editthispage-Extension die Seite bearbeiten kann.
87 **/
88class t29HeribertHost extends t29Host {
89        public $hostname = "heribert";
90
91        function fillup_template_conf(&$template_conf) {
92                $template_conf['header_prepend'][] = 
93                        '<meta name="t29.localfile" content="'.$_SERVER['SCRIPT_FILENAME'].'" id="localFileSource">';
94        }
95}
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