aliroCore.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  * aliroCore is the singleton class that holds the basic configuration information
00038  * for the CMS.  It dynamically determines the live site and absolute path, so as
00039  * to be able to adapt to any change in the environment.  However, the overhead is
00040  * reduced by the fact that aliroCore is a cached singleton.  The methods for
00041  * retrieving the configuration data from the file system are also used by database
00042  * classes to obtain their credentials.  The decoding is also used by the aliroParameters
00043  * class.  A variety of retrieval methods is provided, and also a globalization method
00044  * for use with old components that expect configuration variables to be global.
00045  *
00046  */
00047 
00048 class aliroCore {
00049 
00050     private static $instance = __CLASS__;
00051     private $config = array();
00052     private $subdirlength = 0;
00053 
00054     protected function __construct () {
00055         if (aliro::getInstance()->installed) $database = aliroDatabase::getInstance();
00056         $this->config = aliroCore::getConfigData('configuration.php');
00057         error_reporting(E_ALL|E_STRICT);
00058         $subdirectory = dirname($_SERVER['PHP_SELF']);
00059         if (criticalInfo::getInstance()->isAdmin) $subdirectory = dirname($subdirectory);
00060         if ('/' == $subdirectory) $subdirectory = '';
00061         $this->subdirlength = strlen($subdirectory);
00062         $this->findLiveSite($subdirectory);
00063     }
00064 
00065     private function findLiveSite ($subdirectory) {
00066         $_SERVER['HTTP_HOST'] = str_replace('joomla.', '', $_SERVER['HTTP_HOST']);
00067         $_SERVER['SERVER_NAME'] = str_replace('joomla.', '', $_SERVER['SERVER_NAME']);
00068         $scheme = isset($_SERVER['HTTP_SCHEME']) ? $_SERVER['HTTP_SCHEME'] : ((isset($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS'] != 'off')) ? 'https' : 'http');
00069         if (isset($_SERVER['HTTP_HOST'])) {
00070             $withport = explode(':', $_SERVER['HTTP_HOST']);
00071             $servername = $withport[0];
00072             if (isset($withport[1])) $port = ':'.$withport[1];
00073         }
00074         elseif (isset($_SERVER['SERVER_NAME'])) $servername = $_SERVER['SERVER_NAME'];
00075         else trigger_error(T_('Impossible to determine the name of this server'), E_USER_ERROR);
00076         if (!isset($port) AND !empty($_SERVER['SERVER_PORT'])) $port = ':'.$_SERVER['SERVER_PORT'];
00077         if (isset($port)) {
00078             if (($scheme == 'http' AND $port == ':80') OR ($scheme == 'https' AND $port == ':443')) $port = '';
00079         }
00080         else $port = '';
00081         $afterscheme = '://'.$servername.$port.$subdirectory;
00082         $this->config['live_site'] = $this->config['secure_site'] = $_SESSION['aliro_live_site'] = $scheme.$afterscheme;
00083         $this->config['unsecure_site'] = $_SESSION['aliro_unsecure_site'] = 'http'.$afterscheme;
00084     }
00085 
00086     public function setRedirectHere () {
00087         $_SESSION['aliro_redirect_here'] = substr($_SERVER['REQUEST_URI'], $this->subdirlength);
00088     }
00089 
00090     public static function getInstance () {
00091         return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance());
00092     }
00093 
00094     public function fixLanguage () {
00095         $language = aliroLanguage::getInstance();
00096         if (empty($this->config['lang'])) $this->set('mosConfig_lang', 'english');
00097         $language_file = _ALIRO_ABSOLUTE_PATH."/language/$this->mosConfig_lang.php";
00098         if (file_exists($language_file)) require_once ($language_file);
00099         else require_once (criticalInfo::getInstance()->absolute_path.'/language/english.php');
00100     }
00101 
00102     public static function getConfigData ($configname) {
00103         $info = criticalInfo::getInstance();
00104         $filename = md5($info->absolute_path.'/'.$configname).'.php';
00105         if (!file_exists($info->class_base.'/configs/'.$filename)) {
00106             @session_write_close();
00107             $installer = new aliroInstall();
00108             $installer->tellUserNotInstalled();
00109             exit;
00110         }
00111         require ($info->class_base.'/configs/'.$filename);
00112         $results = unserialize ($packed);
00113         foreach ($results as &$item) $item = base64_decode($item);
00114         $results['configfilename'] = $filename; // basename($filepath);
00115         return $results;
00116     }
00117 
00118     public function decodeParams ($rawtext) {
00119         $info = unserialize ($rawtext);
00120         foreach ($info as &$item) $item = base64_decode($item);
00121         return $info;
00122     }
00123 
00124     public function getCfg ($property) {
00125         if (aliro::getInstance()->installed) $info = criticalInfo::getInstance();
00126         else return null;
00127         if ('admin_site' == $property) return $this->config['live_site'].$info->admin_dir;
00128         // For backwards compatibility
00129         if ('allowUserRegistration' == $property) {
00130             $registration = aliroComponentHandler::getInstance()->getComponentByFormalName('com_registration');
00131             return $registration ? 1 : 0;
00132         }
00133         if ('cachepath' == $property) return $this->getCfg('absolute_path').'/cache';
00134         if ('locale' == $property) return isset($this->config['locale']) ? $this->config['locale'] : 'en';
00135         if (in_array($property, array ('absolute_path', 'admin_absolute_path', 'admin_dir'))) {
00136             if (isset($info->$property)) return $info->$property;
00137         }
00138         elseif (isset($this->config[$property])) return $this->config[$property];
00139         $this->propertyError($property);
00140         return null;
00141     }
00142 
00143     public function __get ($property) {
00144         aliroCore::get($property);
00145     }
00146 
00147     private function propertyError ($property) {
00148         $message = sprintf(T_('Invalid property %s requested from aliroCore'), $property);
00149         trigger_error($message, E_USER_WARNING);
00150     }
00151 
00152     public static function get ($property) {
00153         if (aliro::getInstance()->installed) $config = aliroCore::getInstance();
00154         else return null;
00155         if ('mosConfig_' == substr($property, 0, 10)) return $config->getCfg(substr($property,10));
00156         elseif ('Itemid' == $property) return aliroRequest::getInstance()->getItemid();
00157         $config->propertyError($property);
00158         return null;
00159     }
00160 
00161     public static function is_set ($property) {
00162         $config = aliroCore::getInstance();
00163         return ('mosConfig_' == substr($property, 0, 10) AND isset($config->config[substr($property,10)]));
00164     }
00165 
00166     public static function set ($property, $value) {
00167         $config = aliroCore::getInstance();
00168         $config->config[$property] = $value;
00169         return $value;
00170     }
00171 
00172     public function globalizeConfig () {
00173         foreach ($this->config as $key=>$value) $GLOBALS['mosConfig_'.$key] = $value;
00174         $GLOBALS['mosConfig_absolute_path'] = $this->getCfg('absolute_path');
00175     }
00176 
00177     public function getSubLen () {
00178         return $this->subdirlength;
00179     }
00180 
00181 }
00182 
00183 class mamboCore extends aliroCore {
00184 
00185 }

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