00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
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;
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
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 }