index.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*******************************************************************************
00004  * Aliro - the modern, accessible content management system
00005  *
00006  * Aliro is open source software, free to use, and licensed under GPL.
00007  * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL
00008  *
00009  * The author freely draws attention to the fact that Aliro derives from Mambo,
00010  * software that is controlled by the Mambo Foundation.  However, this section
00011  * of code is totally new.  If it should contain any fragments that are similar
00012  * to Mambo, please bear in mind (1) there are only so many ways to do things
00013  * and (2) the author of Aliro is also the author and copyright owner for large
00014  * parts of Mambo 4.6.
00015  *
00016  * Tribute should be paid to all the developers who took Mambo to the stage
00017  * it had reached at the time Aliro was created.  It is a feature rich system
00018  * that contains a good deal of innovation.
00019  *
00020  * Your attention is also drawn to the fact that Aliro relies on other items of
00021  * open source software, which is very much in the spirit of open source.  Aliro
00022  * wishes to give credit to those items of code.  Please refer to
00023  * http://aliro.org/credits for details.  The credits are not included within
00024  * the Aliro package simply to avoid providing a marker that allows hackers to
00025  * identify the system.
00026  *
00027  * Copyright in this code is strictly reserved by its author, Martin Brampton.
00028  * If it seems appropriate, the copyright will be vested in the Aliro Organisation
00029  * at a suitable time.
00030  *
00031  * Copyright (c) 2007 Martin Brampton
00032  *
00033  * http://aliro.org
00034  *
00035  * counterpoint@aliro.org
00036  *
00037  * This is the starting point for all user interactions with Aliro, the index.php
00038  * file for the user side.  It contains a minimum of code.
00039  *
00040  * The criticalInfo class is a very simple class to obtain basic directory
00041  * information in a way that should be resistant to hacking.  There is a slightly
00042  * different version of this class in the admin side index.php.
00043  *
00044  * __autoload is one of a tiny number of functions outside classes.  It is a special
00045  * PHP5 name and is invoked whenever there is a reference to an unknown class.
00046  * The smart class mapper is used to try to locate the class, in which case it is
00047  * loaded.  There are very few uses of "require" or "include" in the core of Aliro
00048  * and this is one of the few.  It is important that they be resistant to hacker
00049  * attempts to load external code.
00050  *
00051  * The startup function exists so that the amount of code executing in a global
00052  * context is minimal.  It checks for attempts to inject values into global data.
00053  * Then it loads essential classes using robust file paths, and invokes the user
00054  * side logic of the class aliroRequest.
00055  *
00056  * The code initially executed simply buffers all output so that any diagnostic
00057  * output (deliberate or accidental) during core processing and the running of
00058  * components, modules and mambots is trapped until after headers have been sent.
00059  * Or indefinitely for any component that wishes to send a file to the browser,
00060  * or similar.
00061  *
00062  */
00063 
00065 define( '_VALID_MOS', 1 );
00066 
00067 class criticalInfo {
00068     private static $instance = __CLASS__;
00069     public $absolute_path;
00070     public $class_base;
00071     public $isAdmin = false;
00072 
00073     private function __construct() {
00074         $this->absolute_path = str_replace('\\', '/', dirname(__FILE__));
00075         define('_ALIRO_ABSOLUTE_PATH', $this->absolute_path);
00076         define('_ALIRO_CURRENT_PATH', $this->absolute_path);
00077         if (!defined('_ALIRO_CLASS_BASE')) define ('_ALIRO_CLASS_BASE', $this->absolute_path);
00078         $this->class_base = _ALIRO_CLASS_BASE;
00079         define ('_ALIRO_IS_ADMIN', 0);
00080         define ('_ALIRO_ADMIN_PATH', '');
00081         define ('_ALIRO_ADMIN_DIR', '');
00082     }
00083 
00084     public static function getInstance () {
00085         return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance);
00086     }
00087 
00088 }
00089 
00090 class aliro {
00091     private static $instance = __CLASS__;
00092     private $timer = null;
00093     public $installed = false;
00094     
00095     public static function getInstance () {
00096         if (!is_object(self::$instance)) {
00097             self::$instance = new self::$instance();
00098             $critical = criticalInfo::getInstance();
00099         }
00100         return self::$instance;
00101     }
00102     
00103     public function classExists ($classname) {
00104         return smartClassMapper::getInstance()->classExists($classname);
00105     }
00106     
00107     public function requireClass ($classname) {
00108         smartClassMapper::getInstance()->requireClass($classname);
00109     }
00110 
00111     public function startup () {
00112 
00113         $protects = array('_REQUEST', '_GET', '_POST', '_COOKIE', '_FILES', '_SERVER', '_ENV', 'GLOBALS', '_SESSION');
00114 
00115         foreach ($protects as $protect) {
00116             if ( in_array($protect , array_keys($_REQUEST)) ||
00117             in_array($protect , array_keys($_GET)) ||
00118             in_array($protect , array_keys($_POST)) ||
00119             in_array($protect , array_keys($_COOKIE)) ||
00120             in_array($protect , array_keys($_FILES))) {
00121                 die('Invalid Request.');
00122             }
00123         }
00124         if (false !== strpos($_SERVER['REQUEST_URI'], 'mosConfig_absolute_path')) die ('Invalid Request.');
00125 
00126         require_once (dirname(__FILE__).'/definitions.php');
00127 
00128         $filepath = _ALIRO_CLASS_BASE.'/configs/'.md5(_ALIRO_ABSOLUTE_PATH.'/configuration.php').'.php';
00129         if (file_exists($filepath) AND filesize($filepath) > 10 ) $this->installed = true;
00130     
00131         require_once (_ALIRO_CLASS_BASE.'/objectcache.php');
00132         $this->timer = new aliroProfiler();
00133         require_once (_ALIRO_CLASS_BASE.'/classloader.php');
00134         smartClassMapper::getInstance();
00135         $this->classLoader = smartClassMapper::getInstance();
00136 
00137         $controller = aliroRequest::getInstance();
00138 
00139         $errorhandler = aliroErrorRecorder::getInstance();
00140         set_error_handler(array($errorhandler, 'PHPerror'));
00141         $controller->doControl();
00142     }
00143 
00144     public function getElapsed () {
00145         return $this->timer->getElapsed();
00146     }
00147     
00148     public function getTimeMessage () {
00149         return sprintf(T_('Time to generate page %s seconds'), $this->getElapsed());
00150     }
00151 
00152 }
00153 
00154 ob_start();
00155 ob_implicit_flush(0);
00156 aliro::getInstance()->startup();

Generated on Thu Apr 17 13:03:27 2008 for ALIRO by  doxygen 1.5.5