root/trunk/midcom/midcom.core/midcom.php

Revision 17903, 6.5 kB (checked in by bergie, 4 days ago)

Some lower debug levels

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * @package midcom
4  * @author The Midgard Project, http://www.midgard-project.org
5  * @version $Id:application.php 3765 2006-07-31 08:51:39 +0000 (Mon, 31 Jul 2006) tarjei $
6  * @copyright The Midgard Project, http://www.midgard-project.org
7  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
8  */
9
10 ////////////////////////////////////////////////////////
11 // First, block all Link prefetching requests as long as
12 // MidCOM isn't bulletproofed against this "feature".
13 // Ultimately, this is also a matter of performance...
14 if (   array_key_exists('HTTP_X_MOZ', $_SERVER)
15     && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
16 {
17     header('Cache-Control: no-cache');
18     header('Pragma: no-cache');
19     header('HTTP/1.0 403 Forbidden');
20     echo '403: Forbidden<br><br>Prefetching not allowed.';
21     exit;
22 }
23
24 /**
25  * Second, make sure the URLs not having query string (or midcom-xxx- -method signature)
26  * have trailing slash or some extension in the "filename".
27  *
28  * This makes life much, much better when making static copies for whatever reason
29  *
30  * 2008-09-26: Now also rewrites urls ending in .html to end with trailing slash.
31  */
32 $redirect_test_uri = (string)$_SERVER['REQUEST_URI'];
33 if (   !isset($_SERVER['MIDCOM_COMPAT_REDIR'])
34     || (bool)$_SERVER['MIDCOM_COMPAT_REDIR'] !== false)
35 {
36     $redirect_test_uri = preg_replace('/\.html$/', '', $redirect_test_uri);
37 }
38 if (   !preg_match('%\?|/$|midcom-.+-|/.+\..+$%', $redirect_test_uri)
39     && (   !isset($_POST)
40         || empty($_POST))
41     )
42 {
43     header('HTTP/1.0 301 Moved Permanently');
44     header("Location: {$redirect_test_uri}/");
45     echo "301: new location <a href='{$redirect_test_uri}/'>{$redirect_test_uri}/</a>";
46     exit();
47 }
48 unset($redirect_test_uri);
49
50 /** */
51
52 // Advertise the fact that this is a Midgard server
53 header('X-Powered-By: Midgard/' . mgd_version());
54
55 ///////////////////////////////////////////////////////////
56 // Ease debugging and make sure the code actually works(tm)
57 error_reporting(E_ALL);
58
59 ///////////////////////////////////
60 // Try to be smart about the paths:
61 // Define default constants
62 if (! defined('MIDCOM_ROOT'))
63 {
64     define('MIDCOM_ROOT', dirname(__FILE__));
65 }
66 if (! defined('MIDCOM_STATIC_ROOT'))
67 {
68     $pos = strrpos(MIDCOM_ROOT, '/');
69     if ($pos === false)
70     {
71         // No slash, this is strange
72         die ('MIDCOM_ROOT did not contain a slash, this should not happen and is most probably the cause of a configuration error.');
73     }
74     define('MIDCOM_STATIC_ROOT', substr(MIDCOM_ROOT,0,$pos) . '/static');
75 }
76 if (! defined('MIDCOM_STATIC_URL'))
77 {
78     define('MIDCOM_STATIC_URL', '/midcom-static');
79 }
80 if (! defined('MIDCOM_CONFIG_FILE_BEFORE'))
81 {
82     define('MIDCOM_CONFIG_FILE_BEFORE', '/etc/midgard/midcom.conf');
83 }
84 if (! defined('MIDCOM_CONFIG_FILE_AFTER'))
85 {
86     define('MIDCOM_CONFIG_FILE_AFTER', '/etc/midgard/midcom-after.conf');
87 }
88
89 ///////////////////////////////////////
90 //Constants, Globals and Configuration
91 require('constants.php');
92 require('globals.php');
93 require('midcom/config/midcom_config.php');
94 ini_set('track_errors', '1');
95
96 //////////////////////////////////////////////////////////////
97 // Set the MIDCOM_XDEBUG constant accordingly, if not yet set.
98
99 if (! defined('MIDCOM_XDEBUG'))
100 {
101     if (function_exists('xdebug_start_profiling'))
102     {
103         define('MIDCOM_XDEBUG', 1);
104     }
105     else if (function_exists('xdebug_break'))
106     {
107         define('MIDCOM_XDEBUG', 2);
108     }
109     else
110     {
111         define('MIDCOM_XDEBUG', 0);
112     }
113 }
114
115 /////////////////////
116 // Start the Debugger
117 require('midcom/debug.php');
118
119 debug_add("Start of MidCOM run: {$_SERVER['REQUEST_URI']}", MIDCOM_LOG_DEBUG);
120
121 /**
122  * Automatically load missing class files
123  *
124  * @param string $class_name Name of a missing PHP class
125  */
126 function midcom_autoload($class_name)
127 {
128     static $autoloaded = 0;
129     
130     if (substr($class_name, 0, 15) == 'midcom_service_')
131     {
132         // Some service classes are named midcom_service_ and not midcom_services_
133         $class_name = str_replace('midcom_service_', 'midcom_services_', $class_name);
134     }
135     
136     $path = MIDCOM_ROOT . '/' . str_replace('_', '/', $class_name) . '.php';
137     $path = str_replace('//', '/_', $path);
138     
139     if (   basename($path) == 'dba.php'
140         || basename($path) == 'db.php')
141     {
142         // DBA object files are named objectname.php
143         //debug_add("Autoloader got '{$path}' which is DBA class, going one above");
144         
145         // Ensure we have the component loaded
146         $_MIDCOM->dbclassloader->load_component_for_class($class_name);
147         if (class_exists($class_name))
148         {
149             return;
150         }
151         
152         $path = dirname($path) . ".php";
153     }
154     
155     if (   basename($path) == 'interface.php'
156         && $class_name != 'midcom_baseclasses_components_interface')
157     {
158         // MidCOM component interfaces are named midcom/interface.php
159         //debug_add("Autoloader got '{$path}' which is component interface class, loading the component instead");
160         $_MIDCOM->dbclassloader->load_component_for_class($class_name);
161         return;
162     }
163     
164     if (!file_exists($path))
165     {
166         $original_path = $path;
167         $path = str_replace('.php', '/main.php', $path);
168         
169         if (!file_exists($path))
170         {
171             debug_add("Autoloader got '{$original_path}' and tried {$path} but neither was not found, aborting");
172             return;
173         }
174     }
175     
176     require($path);
177     $autoloaded++;
178     //debug_add("Autoloader got '{$path}', loading file {$autoloaded}");
179 }
180 // Register autoloader so we get all MidCOM classes loaded automatically
181 spl_autoload_register('midcom_autoload');
182
183 ///////////////////////////////////
184 // Load first-level supporting code
185 // Note that the cache check hit depends on the i18n and auth code.
186 require('midcom/helper/misc.php');
187 require('midcom/helper/formatters.php');
188
189 $auth = new midcom_services_auth();
190 $auth->initialize();
191
192 //////////////////////////////////////
193 // Load and start up the cache system,
194 // this might already end the request
195 // on a content cache hit.
196 require('midcom/services/cache.php');
197 midcom_services_cache_startup();
198
199 ///////////////////////////////////////////////
200 // Load all required MidCOM Framework Libraries
201
202 // Helpers and First-Generation services
203 // Services
204 require('midcom/services/_i18n_l10n.php');
205
206 //mgd_debug_start();
207 /////////////////////////////////////
208 // Instantiate the MidCOM main class
209 require('midcom/application.php');
210
211 $_MIDCOM = new midcom_application();
212 $_MIDCOM->auth = $auth;
213 //$GLOBALS['midcom'] =& $_MIDCOM;
214 $_MIDCOM->initialize();
215
216 if (file_exists(MIDCOM_CONFIG_FILE_AFTER))
217 {
218     include(MIDCOM_CONFIG_FILE_AFTER);
219 }
220 ?>
Note: See TracBrowser for help on using the browser.