Annotation of /mambo/branches/4.6/index.php
Parent Directory
|
Revision Log
Revision 419 - (view) (download)
| 1 : | csouza | 129 | <?php |
| 2 : | /** | ||
| 3 : | csouza | 297 | * @package Mambo Open Source |
| 4 : | * @copyright (C) 2005 - 2006 Mambo Foundation Inc. | ||
| 5 : | csouza | 129 | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL |
| 6 : | csouza | 297 | * |
| 7 : | * Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure | ||
| 8 : | * that Mambo remained free Open Source software owned and managed by the community. | ||
| 9 : | csouza | 129 | * Mambo is Free Software |
| 10 : | csouza | 297 | */ |
| 11 : | csouza | 129 | |
| 12 : | /** Set flag that this is a parent file */ | ||
| 13 : | if (!defined('_VALID_MOS')) define( '_VALID_MOS', 1 ); | ||
| 14 : | |||
| 15 : | $protects = array('_REQUEST', '_GET', '_POST', '_COOKIE', '_FILES', '_SERVER', '_ENV', 'GLOBALS', '_SESSION'); | ||
| 16 : | |||
| 17 : | foreach ($protects as $protect) { | ||
| 18 : | csouza | 154 | if ( in_array($protect , array_keys($_REQUEST)) || |
| 19 : | in_array($protect , array_keys($_GET)) || | ||
| 20 : | in_array($protect , array_keys($_POST)) || | ||
| 21 : | in_array($protect , array_keys($_COOKIE)) || | ||
| 22 : | in_array($protect , array_keys($_FILES))) { | ||
| 23 : | die("Invalid Request."); | ||
| 24 : | } | ||
| 25 : | csouza | 129 | } |
| 26 : | |||
| 27 : | /** | ||
| 28 : | * Utility function to return a value from a named array or a specified default | ||
| 29 : | */ | ||
| 30 : | define( "_MOS_NOTRIM", 0x0001 ); | ||
| 31 : | define( "_MOS_ALLOWHTML", 0x0002 ); | ||
| 32 : | define( "_MOS_ALLOWRAW", 0x0004 ); | ||
| 33 : | define( "_MOS_NOMAGIC", 0x0008 ); | ||
| 34 : | function mosGetParam( &$arr, $name, $def=null, $mask=0 ) { | ||
| 35 : | csouza | 154 | if (isset( $arr[$name] )) { |
| 36 : | if (is_array($arr[$name])) foreach ($arr[$name] as $key=>$element) $result[$key] = mosGetParam ($arr[$name], $key, $def, $mask); | ||
| 37 : | else { | ||
| 38 : | $result = $arr[$name]; | ||
| 39 : | if (!($mask&_MOS_NOTRIM)) $result = trim($result); | ||
| 40 : | if (!is_numeric( $result)) { | ||
| 41 : | if (!($mask&_MOS_ALLOWHTML)) $result = strip_tags($result); | ||
| 42 : | if (!($mask&_MOS_ALLOWRAW)) { | ||
| 43 : | if (is_numeric($def)) $result = intval($result); | ||
| 44 : | } | ||
| 45 : | } | ||
| 46 : | } | ||
| 47 : | return $result; | ||
| 48 : | } else { | ||
| 49 : | return $def; | ||
| 50 : | } | ||
| 51 : | csouza | 129 | } |
| 52 : | |||
| 53 : | function sefRelToAbs ($string) { | ||
| 54 : | counterpoi | 238 | t $sef =& mosSEF::getInstance(); |
| 55 : | csouza | 154 | return $sef->sefRelToAbs($string); |
| 56 : | csouza | 129 | } |
| 57 : | |||
| 58 : | class mamboCore { | ||
| 59 : | csouza | 154 | var $rootPath = ''; |
| 60 : | var $Itemid = 0; | ||
| 61 : | var $option = ''; | ||
| 62 : | counterpoi | 222 | t var $subdirectory; |
| 63 : | csouza | 154 | var $current_user = null; |
| 64 : | var $do_gzip_compress = false; | ||
| 65 : | counterpoi | 390 | t var $init_errorlevel = 0; |
| 66 : | csouza | 129 | |
| 67 : | csouza | 154 | function mamboCore () { |
| 68 : | global $adminside; | ||
| 69 : | counterpoi | 390 | t $this->init_errorlevel = error_reporting(0); |
| 70 : | counterpoi | 384 | t $this->rootPath = str_replace('\\', '/', dirname(__FILE__)); |
| 71 : | csouza | 154 | $this->checkConfig(); |
| 72 : | $this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0); | ||
| 73 : | $this->getConfig(); | ||
| 74 : | $this->fixLanguage(); | ||
| 75 : | @set_magic_quotes_runtime( 0 ); | ||
| 76 : | counterpoi | 390 | t if (@$this->mosConfig_error_reporting > 0 OR @$this->mosConfig_error_reporting ===0) error_reporting($this->mosConfig_error_reporting); |
| 77 : | csouza | 403 | else error_reporting($this->init_errorlevel); |
| 78 : | csouza | 154 | } |
| 79 : | csouza | 129 | |
| 80 : | csouza | 154 | function &getMamboCore () { |
| 81 : | static $instance; | ||
| 82 : | if (!is_object($instance)) $instance = new mamboCore(); | ||
| 83 : | return $instance; | ||
| 84 : | } | ||
| 85 : | csouza | 129 | |
| 86 : | csouza | 154 | function rootPath () { |
| 87 : | if (realpath($this->rootPath) === false) die ('Invalid program load path'); | ||
| 88 : | return $this->rootPath; | ||
| 89 : | } | ||
| 90 : | csouza | 129 | |
| 91 : | csouza | 154 | function get ($property) { |
| 92 : | $config =& mamboCore::getMamboCore(); | ||
| 93 : | counterpoi | 206 | t if ($property == 'mosConfig_absolute_path') { |
| 94 : | csouza | 252 | if (realpath($config->mosConfig_absolute_path) === false) die ('Invalid program load path'); |
| 95 : | else return $config->rootPath; | ||
| 96 : | } | ||
| 97 : | csouza | 154 | if (isset($config->$property)) return $config->$property; |
| 98 : | trigger_error("Invalid property ($property) requested from mamboCore"); | ||
| 99 : | return null; | ||
| 100 : | } | ||
| 101 : | csouza | 129 | |
| 102 : | csouza | 154 | function is_set ($property) { |
| 103 : | $config =& mamboCore::getMamboCore(); | ||
| 104 : | return isset($config->$property); | ||
| 105 : | } | ||
| 106 : | csouza | 129 | |
| 107 : | csouza | 154 | function set ($property, $value) { |
| 108 : | $config =& mamboCore::getMamboCore(); | ||
| 109 : | $config->$property = $value; | ||
| 110 : | $GLOBALS[$property] = $value; | ||
| 111 : | return $value; | ||
| 112 : | } | ||
| 113 : | csouza | 129 | |
| 114 : | csouza | 154 | function checkConfig () { |
| 115 : | // checks for configuration file, if none found loads installation page | ||
| 116 : | if (!file_exists($this->rootPath.'/configuration.php') OR filesize($this->rootPath.'/configuration.php') < 10 ) { | ||
| 117 : | header( 'Location: installation/index.php' ); | ||
| 118 : | exit(); | ||
| 119 : | } | ||
| 120 : | } | ||
| 121 : | csouza | 129 | |
| 122 : | counterpoi | 419 | t function getConfig () { |
| 123 : | t global $adminside; | ||
| 124 : | t $code = ''; | ||
| 125 : | t $f = @fopen($this->rootPath.'/configuration.php','rb'); | ||
| 126 : | t if ($f) { | ||
| 127 : | t while ($f AND !feof($f)) { | ||
| 128 : | t $line = fgets($f, 256); | ||
| 129 : | t $altered = str_replace('$', '$this->', $line); | ||
| 130 : | t if ($altered != $line) $code .= $altered; | ||
| 131 : | t } | ||
| 132 : | t } | ||
| 133 : | t else { | ||
| 134 : | t header( 'Location: installation/index.php' ); | ||
| 135 : | t exit(); | ||
| 136 : | t } | ||
| 137 : | t fclose($f); | ||
| 138 : | t eval($code); | ||
| 139 : | t if (isset($_SERVER['DOCUMENT_ROOT']) AND strlen($_SERVER['DOCUMENT_ROOT'])) $docroot = $_SERVER['DOCUMENT_ROOT']; | ||
| 140 : | t else { | ||
| 141 : | t // Find information about where execution started | ||
| 142 : | t $origin = array_pop(debug_backtrace()); | ||
| 143 : | t // Find the PHP script at the start, with a fix for Windows slashes | ||
| 144 : | t $absolutepath = str_replace('\\', '/', $origin['file']); | ||
| 145 : | t $localpath = $_SERVER['PHP_SELF']; | ||
| 146 : | t $docroot = substr($absolutepath,0,strpos($absolutepath,$localpath)); | ||
| 147 : | t } | ||
| 148 : | t $mamboroot = str_replace('\\', '/', dirname(__FILE__)); | ||
| 149 : | t $this->subdirectory = substr($mamboroot, strlen($docroot)); | ||
| 150 : | t $scheme = isset($_SERVER['HTTP_SCHEME']) ? $_SERVER['HTTP_SCHEME'] : ((isset($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS'] != 'off')) ? 'https' : 'http'); | ||
| 151 : | t if (isset($_SERVER['HTTP_HOST'])) { | ||
| 152 : | t $withport = explode(':', $_SERVER['HTTP_HOST']); | ||
| 153 : | t $servername = $withport[0]; | ||
| 154 : | t if (isset($withport[1])) $port = ':'.$withport[1]; | ||
| 155 : | t } | ||
| 156 : | t elseif (isset($_SERVER['SERVER_NAME'])) $servername = $_SERVER['SERVER_NAME']; | ||
| 157 : | t else trigger_error(T_('Impossible to determine the name of this server'), E_USER_ERROR); | ||
| 158 : | t if (!isset($port) AND !empty($_SERVER['SERVER_PORT'])) $port = ':'.$_SERVER['SERVER_PORT']; | ||
| 159 : | t if (isset($port)) { | ||
| 160 : | t if (($scheme == 'http' AND $port == ':80') OR ($scheme == 'https' AND $port == ':443')) $port = ''; | ||
| 161 : | t } | ||
| 162 : | t else $port = ''; | ||
| 163 : | t $afterscheme = '://'.$servername.$port.$this->subdirectory; | ||
| 164 : | t $this->mosConfig_live_site = $this->mosConfig_secure_site = $scheme.$afterscheme; | ||
| 165 : | t $this->mosConfig_unsecure_site = 'http'.$afterscheme; | ||
| 166 : | t $this->mosConfig_absolute_path = $this->rootPath; | ||
| 167 : | t preg_match_all('/\$this\-\>([A-Za-z_][A-Za-z0-9_]*)/', $code, $matches); | ||
| 168 : | t foreach ($matches[1] as $match) $GLOBALS[$match] = $this->$match; | ||
| 169 : | t if (!isset($this->mosConfig_register_globals)) { | ||
| 170 : | t $this->mosConfig_register_globals = 0; | ||
| 171 : | t $GLOBALS['mosConfig_register_globals'] = 0; | ||
| 172 : | t } | ||
| 173 : | t } | ||
| 174 : | csouza | 129 | |
| 175 : | csouza | 154 | function getFavIcon () { |
| 176 : | // favourites icon | ||
| 177 : | if (!isset($this->mosConfig_favicon)) $this->mosConfig_favicon = 'favicon.ico'; | ||
| 178 : | if (!file_exists($this->rootPath.'/images/'.$this->mosConfig_favicon)) $this->mosConfig_favicon = 'favicon.ico'; | ||
| 179 : | return $this->rootPath.'/images/'.$this->mosConfig_favicon; | ||
| 180 : | } | ||
| 181 : | csouza | 129 | |
| 182 : | csouza | 154 | function offlineCheck (&$user, &$database) { |
| 183 : | counterpoi | 384 | t if ($this->mosConfig_offline OR file_exists($this->rootPath.'/installation/index.php')) { |
| 184 : | csouza | 154 | require_once($this->rootPath().'/administrator/includes/admin.php'); |
| 185 : | session_name(md5($this->mosConfig_live_site)); | ||
| 186 : | session_start(); | ||
| 187 : | if ($user =& checkAdminSession($database)) return; | ||
| 188 : | include("$this->mosConfig_absolute_path/offline.php"); | ||
| 189 : | exit(); | ||
| 190 : | } | ||
| 191 : | } | ||
| 192 : | |||
| 193 : | function fixLanguage () { | ||
| 194 : | require_once($this->mosConfig_absolute_path.'/includes/phpgettext/phpgettext.class.php'); | ||
| 195 : | csouza | 403 | require_once($this->mosConfig_absolute_path.'/includes/phpgettext/error.php'); |
| 196 : | require_once($this->mosConfig_absolute_path.'/includes/mambofunc.php'); | ||
| 197 : | require_once($this->mosConfig_absolute_path.'/includes/mambolanguage.class.php'); | ||
| 198 : | error_reporting(E_ALL) ; | ||
| 199 : | csouza | 217 | ########## DEPRECATED ############ |
| 200 : | csouza | 252 | if (isset($this->mosConfig_lang) AND $this->mosConfig_lang); |
| 201 : | else $this->set('mosConfig_lang', 'english'); | ||
| 202 : | $language_file = "$this->mosConfig_absolute_path/language/$this->mosConfig_lang.php"; | ||
| 203 : | if (file_exists($language_file)) require_once ($language_file); | ||
| 204 : | ################################### | ||
| 205 : | |||
| 206 : | csouza | 403 | |
| 207 : | $this->mosConfig_lang = mosGetParam($_POST, 'setLanguage', $this->mosConfig_lang); | ||
| 208 : | csouza | 252 | |
| 209 : | csouza | 403 | |
| 210 : | $language =& mamboLanguage::getInstance($this->mosConfig_lang, $this->rootPath.'/language/'); | ||
| 211 : | $languages = $language->getLanguages(); | ||
| 212 : | $charset = $language->get('charset'); | ||
| 213 : | $dateformat = $language->get('dateformat'); | ||
| 214 : | $this->current_language = $language; | ||
| 215 : | if (!defined('_ISO')) DEFINE('_ISO','charset='.$charset); | ||
| 216 : | if (!defined('_DATE_FORMAT_LC')) DEFINE('_DATE_FORMAT_LC', $dateformat); //Uses PHP's strftime Command Format | ||
| 217 : | if (!defined('_DATE_FORMAT_LC2')) DEFINE('_DATE_FORMAT_LC2', $dateformat); | ||
| 218 : | |||
| 219 : | csouza | 154 | $gettext =& phpgettext(); |
| 220 : | csouza | 302 | $gettext->debug = $this->mosConfig_locale_debug; |
| 221 : | $gettext->has_gettext = $this->mosConfig_locale_use_gettext; | ||
| 222 : | csouza | 403 | $gettext->setlocale($this->mosConfig_lang); |
| 223 : | csouza | 154 | } |
| 224 : | csouza | 129 | |
| 225 : | csouza | 154 | function handleGlobals () { |
| 226 : | $superglobals = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET); | ||
| 227 : | if (isset( $_SESSION )) array_unshift ( $superglobals , $_SESSION ); | ||
| 228 : | csouza | 129 | |
| 229 : | csouza | 154 | // Emulate register_globals on |
| 230 : | if (!ini_get('register_globals') && $this->mosConfig_register_globals) { | ||
| 231 : | while(list($key,$value)=each($_GET)) { | ||
| 232 : | if (!isset($GLOBALS[$key])) $GLOBALS[$key]=$value; | ||
| 233 : | } | ||
| 234 : | } | ||
| 235 : | // Emulate register_globals off | ||
| 236 : | elseif (ini_get('register_globals') && !$this->mosConfig_register_globals) { | ||
| 237 : | foreach ( $superglobals as $superglobal ) { | ||
| 238 : | foreach ( $superglobal as $key => $value) { | ||
| 239 : | unset( $GLOBALS[$key]); | ||
| 240 : | } | ||
| 241 : | } | ||
| 242 : | } | ||
| 243 : | } | ||
| 244 : | csouza | 129 | |
| 245 : | csouza | 154 | function determineOptionAndItemid () { |
| 246 : | $this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0); | ||
| 247 : | if ($option = strtolower(mosGetParam($_REQUEST, 'option'))); | ||
| 248 : | else { | ||
| 249 : | counterpoi | 238 | t $menuhandler =& mosMenuHandler::getInstance(); |
| 250 : | csouza | 154 | $menus =& $menuhandler->getByParentOrder($this->Itemid, 'mainmenu'); |
| 251 : | $this->Itemid = $menus[0]->id; | ||
| 252 : | $_REQUEST['Itemid'] = $this->Itemid; | ||
| 253 : | $link = $menus[0]->link; | ||
| 254 : | $pos = strpos( $link, '?' ); | ||
| 255 : | if ($pos !== false) $link = substr( $link, $pos+1 ). '&Itemid='.$this->Itemid; | ||
| 256 : | parse_str( $link, $temp ); | ||
| 257 : | /** this is a patch, need to rework when globals are handled better */ | ||
| 258 : | foreach ($temp as $k=>$v) $_GET[$k] = $v; | ||
| 259 : | if (isset($temp['option'])) $option = $temp['option']; | ||
| 260 : | else return ''; | ||
| 261 : | } | ||
| 262 : | /** patch to lessen the impact on templates */ | ||
| 263 : | if ($option == 'search') $option = 'com_search'; | ||
| 264 : | // checking if we can find the Itemid thru the component | ||
| 265 : | if ($this->Itemid === 0) { | ||
| 266 : | if ( $option == 'com_content') { | ||
| 267 : | require_once($this->rootPath().'/components/com_content/content.class.php'); | ||
| 268 : | counterpoi | 238 | t $handler =& contentHandler::getInstance(); |
| 269 : | csouza | 154 | $this->Itemid = $handler->getItemid(mosGetParam($_REQUEST, 'id', 0 )); |
| 270 : | $_REQUEST['Itemid'] = $this->Itemid; | ||
| 271 : | } | ||
| 272 : | else { | ||
| 273 : | counterpoi | 238 | t $menuhandler =& mosMenuHandler::getInstance(); |
| 274 : | csouza | 154 | $this->Itemid = $menuhandler->getIdLikeLink("index.php?option=$option"); |
| 275 : | if ($this->Itemid === 0) { | ||
| 276 : | counterpoi | 238 | t $menuhandler =& mosMenuHandler::getInstance(); |
| 277 : | csouza | 154 | $menus =& $menuhandler->getByParentOrder($this->Itemid, 'mainmenu'); |
| 278 : | } | ||
| 279 : | } | ||
| 280 : | } | ||
| 281 : | return $option; | ||
| 282 : | } | ||
| 283 : | csouza | 129 | |
| 284 : | csouza | 154 | function redirect ($url, $msg='') { |
| 285 : | $callcheck = array('InputFilter', 'process'); | ||
| 286 : | cauld | 229 | if (!is_callable($callcheck)) require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php'); |
| 287 : | csouza | 154 | // specific filters |
| 288 : | $iFilter =& new InputFilter(); | ||
| 289 : | $url = $iFilter->process( $url ); | ||
| 290 : | $message = trim($iFilter->process($msg)); | ||
| 291 : | counterpoi | 206 | t if ($iFilter->badAttributeValue(array('href', $url))) $url = mamboCore::get('mosConfig_live_site'); |
| 292 : | csouza | 154 | if ($message) { |
| 293 : | if (strpos($url, '?')) $url .= '&mosmsg='.urlencode($message); | ||
| 294 : | else $url .= '?mosmsg='.urlencode($message); | ||
| 295 : | } | ||
| 296 : | if (headers_sent()) echo "<script>document.location.href='$url';</script>\n"; | ||
| 297 : | else { | ||
| 298 : | @ob_end_clean(); // clear output buffer | ||
| 299 : | header( "Location: $url" ); | ||
| 300 : | } | ||
| 301 : | exit(); | ||
| 302 : | } | ||
| 303 : | csouza | 129 | |
| 304 : | csouza | 154 | function logMessage ($text) { |
| 305 : | // JS Popup message | ||
| 306 : | if (mosGetParam( $_POST, 'message', 0 )) { | ||
| 307 : | csouza | 129 | ?> |
| 308 : | <script type="text/javascript"> | ||
| 309 : | <!--// | ||
| 310 : | alert( "<?php echo $text; ?>" ); | ||
| 311 : | //--> | ||
| 312 : | </script> | ||
| 313 : | <?php | ||
| 314 : | csouza | 154 | } |
| 315 : | if ($return = mosGetParam( $_REQUEST, 'return', '' )) { | ||
| 316 : | $this->redirect( $return ); | ||
| 317 : | } | ||
| 318 : | else { | ||
| 319 : | $this->redirect( $this->mosConfig_live_site.'/index.php' ); | ||
| 320 : | } | ||
| 321 : | } | ||
| 322 : | csouza | 129 | |
| 323 : | counterpoi | 223 | t function handleLogin () { |
| 324 : | csouza | 154 | require_once($this->rootPath().'/includes/authenticator.php'); |
| 325 : | counterpoi | 238 | t $authenticator =& mamboAuthenticator::getInstance(); |
| 326 : | counterpoi | 223 | t $loggedin = $authenticator->loginUser(); |
| 327 : | t if ($loggedin) $this->logMessage(_LOGIN_SUCCESS); | ||
| 328 : | t else mamboCore::redirect('index.php'); | ||
| 329 : | csouza | 154 | } |
| 330 : | csouza | 129 | |
| 331 : | counterpoi | 223 | t function handleLogout () { |
| 332 : | csouza | 154 | require_once($this->rootPath().'/includes/authenticator.php'); |
| 333 : | counterpoi | 238 | t $authenticator =& mamboAuthenticator::getInstance(); |
| 334 : | csouza | 154 | $authenticator->logoutUser(); |
| 335 : | $this->logMessage(_LOGOUT_SUCCESS); | ||
| 336 : | } | ||
| 337 : | csouza | 129 | |
| 338 : | csouza | 154 | function standardHeaders () { |
| 339 : | header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); | ||
| 340 : | header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); | ||
| 341 : | header( 'Cache-Control: no-store, no-cache, must-revalidate' ); | ||
| 342 : | header( 'Cache-Control: post-check=0, pre-check=0', false ); | ||
| 343 : | header( 'Pragma: no-cache' ); | ||
| 344 : | counterpoi | 238 | t $mambothandler =& mosMambotHandler::getInstance(); |
| 345 : | csouza | 154 | $mambothandler->loadBotGroup('system'); |
| 346 : | $mambothandler->trigger('onHeaders', array($this)); | ||
| 347 : | } | ||
| 348 : | csouza | 129 | |
| 349 : | csouza | 154 | function initGzip() { |
| 350 : | $this->do_gzip_compress = FALSE; | ||
| 351 : | //zlib.output_compression and ob_gzhandler don't get along well so we'll check to make | ||
| 352 : | //that zlib.output_compression is not enable in the php.ini before turning on ob_gzhandler | ||
| 353 : | counterpoi | 238 | t if ( $this->mosConfig_gzip == 1 AND (int)ini_get('zlib.output_compression') != 1 ) { |
| 354 : | csouza | 154 | $phpver = phpversion(); |
| 355 : | $useragent = mosGetParam( $_SERVER, 'HTTP_USER_AGENT', '' ); | ||
| 356 : | $canZip = mosGetParam( $_SERVER, 'HTTP_ACCEPT_ENCODING', '' ); | ||
| 357 : | csouza | 129 | |
| 358 : | counterpoi | 238 | t if ( $phpver >= '4.0.4pl1' AND |
| 359 : | csouza | 154 | ( strpos($useragent,'compatible') !== false || |
| 360 : | strpos($useragent,'Gecko') !== false | ||
| 361 : | ) | ||
| 362 : | ) { | ||
| 363 : | if ( extension_loaded('zlib') ) { | ||
| 364 : | ob_start( 'ob_gzhandler' ); | ||
| 365 : | return; | ||
| 366 : | } | ||
| 367 : | } else if ( $phpver > '4.0' ) { | ||
| 368 : | if ( strpos($canZip,'gzip') !== false ) { | ||
| 369 : | if (extension_loaded( 'zlib' )) { | ||
| 370 : | $this->do_gzip_compress = TRUE; | ||
| 371 : | ob_start(); | ||
| 372 : | ob_implicit_flush(0); | ||
| 373 : | csouza | 129 | |
| 374 : | csouza | 154 | header( 'Content-Encoding: gzip' ); |
| 375 : | return; | ||
| 376 : | } | ||
| 377 : | } | ||
| 378 : | } | ||
| 379 : | } | ||
| 380 : | ob_start(); | ||
| 381 : | } | ||
| 382 : | csouza | 129 | |
| 383 : | csouza | 154 | /** |
| 384 : | csouza | 129 | * Perform GZIP |
| 385 : | */ | ||
| 386 : | csouza | 154 | function doGzip() { |
| 387 : | if ( $this->do_gzip_compress ) { | ||
| 388 : | /** | ||
| 389 : | csouza | 129 | *Borrowed from php.net! |
| 390 : | */ | ||
| 391 : | csouza | 154 | $gzip_contents = ob_get_contents(); |
| 392 : | ob_end_clean(); | ||
| 393 : | csouza | 129 | |
| 394 : | csouza | 154 | $gzip_size = strlen($gzip_contents); |
| 395 : | $gzip_crc = crc32($gzip_contents); | ||
| 396 : | csouza | 129 | |
| 397 : | csouza | 154 | $gzip_contents = gzcompress($gzip_contents, 9); |
| 398 : | $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4); | ||
| 399 : | csouza | 129 | |
| 400 : | csouza | 154 | echo "\x1f\x8b\x08\x00\x00\x00\x00\x00"; |
| 401 : | echo $gzip_contents; | ||
| 402 : | echo pack('V', $gzip_crc); | ||
| 403 : | echo pack('V', $gzip_size); | ||
| 404 : | } else { | ||
| 405 : | ob_end_flush(); | ||
| 406 : | } | ||
| 407 : | } | ||
| 408 : | csouza | 129 | |
| 409 : | csouza | 154 | function getLastPart ($separator, $field) { |
| 410 : | $parts = explode($separator, $field); | ||
| 411 : | return $parts[count($parts)-1]; | ||
| 412 : | } | ||
| 413 : | csouza | 129 | |
| 414 : | csouza | 154 | function allButLast ($separator, $field) { |
| 415 : | $lastSize = strlen(mamboCore::getLastPart($separator,$field)); | ||
| 416 : | return substr($field, 0, strlen($field)-$lastSize); | ||
| 417 : | } | ||
| 418 : | csouza | 129 | |
| 419 : | } | ||
| 420 : | |||
| 421 : | counterpoi | 371 | t /* This is the new error handler to store errors in the database |
| 422 : | t class mosErrorHandler { | ||
| 423 : | csouza | 403 | var $types = array ( |
| 424 : | E_STRICT => 'Strict check', | ||
| 425 : | E_USER_WARNING => 'User Warning', | ||
| 426 : | E_USER_NOTICE => 'User Notice', | ||
| 427 : | E_WARNING => 'Warning', | ||
| 428 : | E_NOTICE => 'Notice', | ||
| 429 : | E_CORE_WARNING => 'Core Warning', | ||
| 430 : | E_COMPILE_WARNING => 'Compile Warning', | ||
| 431 : | E_USER_ERROR => 'User Error', | ||
| 432 : | E_ERROR => 'Error', | ||
| 433 : | E_PARSE => 'Parse error', | ||
| 434 : | E_CORE_ERROR => 'Core Error', | ||
| 435 : | E_COMPILE_ERROR => 'Compile Error' | ||
| 436 : | ); | ||
| 437 : | counterpoi | 371 | t |
| 438 : | csouza | 403 | function mosErrorHandler () { |
| 439 : | set_error_handler(array(&$this, 'handler')); | ||
| 440 : | } | ||
| 441 : | counterpoi | 371 | t |
| 442 : | csouza | 403 | function handler ($errno, $errstr, $errfile, $errline, $errcontext) { |
| 443 : | if ($errno = E_STRICT) return; | ||
| 444 : | $string = $this->types[$errno].': '.$errstr.' in '.$errfile.' at '.$errline; | ||
| 445 : | $database = mamboDatabase::getInstance(); | ||
| 446 : | if (eregi('^(sql)$', $errstr)) { | ||
| 447 : | $extra = $database->getErrorMsg(); | ||
| 448 : | counterpoi | 371 | t } |
| 449 : | csouza | 403 | if (function_exists('debug_backtrace')) { |
| 450 : | foreach(debug_backtrace() as $back) { | ||
| 451 : | if (@$back['file']) { | ||
| 452 : | $extra .= "\n".$back['file'].':'.$back['line']; | ||
| 453 : | } | ||
| 454 : | } | ||
| 455 : | } | ||
| 456 : | $database->setQuery("DELETE FROM #__errors WHERE file=$errfile AND line=$errline AND number=$errno"); | ||
| 457 : | $database->query(); | ||
| 458 : | $database->setQuery("INSERT INTO #__errors VALUES (0, $errno, '$errfile', $errline, '$string', '$extra')"); | ||
| 459 : | $database->query(); | ||
| 460 : | } | ||
| 461 : | } | ||
| 462 : | counterpoi | 371 | t */ |
| 463 : | t | ||
| 464 : | mambo | 157 | if (!isset($adminside)) $adminside = 0; |
| 465 : | if (!isset($indextype)) $indextype = 1; | ||
| 466 : | csouza | 129 | |
| 467 : | mambo | 157 | $configuration =& mamboCore::getMamboCore(); |
| 468 : | $configuration->handleGlobals(); | ||
| 469 : | |||
| 470 : | require_once ($configuration->rootPath().'/includes/database.php'); | ||
| 471 : | counterpoi | 371 | t //new mosErrorHandler(); |
| 472 : | mambo | 157 | |
| 473 : | csouza | 129 | /** |
| 474 : | counterpoi | 206 | t * Mambo basic error object |
| 475 : | t */ | ||
| 476 : | t define ('_MOS_ERROR_INFORM', 0); | ||
| 477 : | t define ('_MOS_ERROR_WARN', 1); | ||
| 478 : | t define ('_MOS_ERROR_SEVERE', 2); | ||
| 479 : | t define ('_MOS_ERROR_FATAL', 3); | ||
| 480 : | t | ||
| 481 : | t class mosError { | ||
| 482 : | csouza | 252 | var $text = ''; |
| 483 : | var $level = 0; | ||
| 484 : | counterpoi | 206 | t |
| 485 : | csouza | 252 | function mosError ($text='', $level=_MOS_ERROR_INFORM) { |
| 486 : | $this->text = $text; | ||
| 487 : | $this->level = $level; | ||
| 488 : | } | ||
| 489 : | counterpoi | 206 | t } |
| 490 : | t | ||
| 491 : | t /** | ||
| 492 : | t * Mambo group of errors for some particular operation | ||
| 493 : | t */ | ||
| 494 : | t class mosErrorSet { | ||
| 495 : | csouza | 252 | var $errors = array(); |
| 496 : | var $maxlevel = 0; | ||
| 497 : | |||
| 498 : | // Parameter is an error object | ||
| 499 : | function addError ($error) { | ||
| 500 : | $this->errors[] = $error; | ||
| 501 : | if ($error->level > $this->maxlevel) $this->maxlevel = $error->level; | ||
| 502 : | } | ||
| 503 : | |||
| 504 : | function addErrorDetails ($text='', $level=_MOS_ERROR_INFORM) { | ||
| 505 : | $error = new mosError($text, $level); | ||
| 506 : | $this->addError($error); | ||
| 507 : | } | ||
| 508 : | |||
| 509 : | function &getErrors () { | ||
| 510 : | return $this->errors; | ||
| 511 : | } | ||
| 512 : | |||
| 513 : | function getMaxLevel () { | ||
| 514 : | return $this->maxlevel; | ||
| 515 : | } | ||
| 516 : | |||
| 517 : | function getCount () { | ||
| 518 : | return count($this->errors); | ||
| 519 : | } | ||
| 520 : | |||
| 521 : | function mergeAnother ($errorset) { | ||
| 522 : | $this->errors = array_merge($this->errors, $errorset->errors); | ||
| 523 : | } | ||
| 524 : | |||
| 525 : | counterpoi | 206 | t } |
| 526 : | csouza | 252 | |
| 527 : | counterpoi | 206 | t /** |
| 528 : | csouza | 129 | * Sorts an Array of objects |
| 529 : | */ | ||
| 530 : | class mosObjectSorter { | ||
| 531 : | csouza | 154 | var $_keyname = ''; |
| 532 : | var $_direction = 0; | ||
| 533 : | var $_object_array = array(); | ||
| 534 : | |||
| 535 : | function mosObjectSorter (&$a, $k, $sort_direction=1) { | ||
| 536 : | $this->_keyname = $k; | ||
| 537 : | $this->_direction = $sort_direction; | ||
| 538 : | $this->_object_array =& $a; | ||
| 539 : | $this->sort(); | ||
| 540 : | } | ||
| 541 : | |||
| 542 : | function mosObjectCompare (&$a, &$b) { | ||
| 543 : | $key = $this->_keyname; | ||
| 544 : | if ($a->$key > $b->$key) return $this->_direction; | ||
| 545 : | if ($a->$key < $b->$key) return -$this->_direction; | ||
| 546 : | return 0; | ||
| 547 : | } | ||
| 548 : | |||
| 549 : | function sort () { | ||
| 550 : | usort($this->_object_array, array($this,'mosObjectCompare')); | ||
| 551 : | } | ||
| 552 : | |||
| 553 : | csouza | 129 | } |
| 554 : | |||
| 555 : | /** | ||
| 556 : | * Pathway handler | ||
| 557 : | * @package Mambo | ||
| 558 : | */ | ||
| 559 : | class mosPathway { | ||
| 560 : | csouza | 154 | /** @var array Names for display in pathway */ |
| 561 : | var $_names = null; | ||
| 562 : | /** @var array URLs for links from pathway */ | ||
| 563 : | var $_urls = null; | ||
| 564 : | csouza | 129 | |
| 565 : | csouza | 154 | /** |
| 566 : | csouza | 129 | * Constructor |
| 567 : | */ | ||
| 568 : | csouza | 154 | function mosPathway () { |
| 569 : | counterpoi | 238 | t $menuhandler =& mosMenuHandler::getInstance(); |
| 570 : | csouza | 154 | $menus =& $menuhandler->getByParentOrder(0,'mainmenu'); |
| 571 : | $home = $menus[0]; | ||
| 572 : | $this->_names[] = $home->name; | ||
| 573 : | $this->_urls[] = sefRelToAbs($home->link."&Itemid=$home->id"); | ||
| 574 : | } | ||
| 575 : | |||
| 576 : | /** | ||
| 577 : | csouza | 129 | * Singleton accessor |
| 578 : | */ | ||
| 579 : | csouza | 154 | function &getInstance () { |
| 580 : | static $instance; | ||
| 581 : | if (!is_object($instance)) $instance = new mosPathway(); | ||
| 582 : | return $instance; | ||
| 583 : | } | ||
| 584 : | |||
| 585 : | /** | ||
| 586 : | csouza | 129 | * Add an item to the pathway |
| 587 : | */ | ||
| 588 : | csouza | 154 | function addItem ($name, $givenurl) { |
| 589 : | $last = count($this->_names) - 1; | ||
| 590 : | if (!$name) return; | ||
| 591 : | $url = sefRelToAbs($givenurl); | ||
| 592 : | if ($name == $this->_names[$last] AND $url == $this->_urls[$last]) return; | ||
| 593 : | $this->_names[$last+1] = $name; | ||
| 594 : | $this->_urls[$last+1] = $url; | ||
| 595 : | } | ||
| 596 : | |||
| 597 : | function reduceToOne () { | ||
| 598 : | for ($i = count($this->_names) - 1; $i > 0; $i--) { | ||
| 599 : | unset($this->_names[$i]); | ||
| 600 : | unset($this->_urls[$i]); | ||
| 601 : | } | ||
| 602 : | } | ||
| 603 : | |||
| 604 : | /** | ||
| 605 : | csouza | 129 | * Make a pathway string for display |
| 606 : | */ | ||
| 607 : | csouza | 154 | function makePathway () { |
| 608 : | counterpoi | 186 | t $last = count($this->_names) - 1; |
| 609 : | t if ($last == 0) return ''; | ||
| 610 : | counterpoi | 238 | t $mainframe =& mosMainFrame::getInstance(); |
| 611 : | csouza | 154 | $result = "<span class='pathway'>"; |
| 612 : | counterpoi | 238 | t $config =& mamboCore::getMamboCore(); |
| 613 : | csouza | 154 | $rootpath = $config->rootPath(); |
| 614 : | $imgPath = 'templates/'.$mainframe->getTemplate().'/images/arrow.png'; | ||
| 615 : | if (file_exists( "$rootpath/$imgPath" )) $img = "<img src='$config->mosConfig_live_site/$imgPath' border='0' alt='arrow' />"; | ||
| 616 : | else { | ||
| 617 : | $imgPath = '/images/M_images/arrow.png'; | ||
| 618 : | if (file_exists( "$rootpath/$imgPath" )) $img = "<img src='$config->mosConfig_live_site/images/M_images/arrow.png' alt='arrow' />"; | ||
| 619 : | else $img = '>'; | ||
| 620 : | } | ||
| 621 : | foreach ($this->_names as $i=>$name) { | ||
| 622 : | csouza | 403 | if ($i === $last) $result .= "$name</span>"; |
| 623 : | csouza | 154 | else { |
| 624 : | $sefurl = sefRelToAbs($this->_urls[$i]); | ||
| 625 : | $result .= "<a href='$sefurl' class='pathway'>$name</a>"; | ||
| 626 : | $result .= " $img "; | ||
| 627 : | } | ||
| 628 : | } | ||
| 629 : | $customs = $mainframe->getCustomPathWay(); | ||
| 630 : | foreach ($customs as $custom) $result .= $custom; | ||
| 631 : | counterpoi | 186 | t $result .= '</span>'; |
| 632 : | csouza | 154 | return $result; |
| 633 : | } | ||
| 634 : | csouza | 129 | |
| 635 : | } | ||
| 636 : | |||
| 637 : | /** | ||
| 638 : | * Module database table class | ||
| 639 : | * @package Mambo | ||
| 640 : | */ | ||
| 641 : | class mosMenu extends mosDBTable { | ||
| 642 : | csouza | 154 | /** @var int Primary key */ |
| 643 : | var $id=null; | ||
| 644 : | /** @var string */ | ||
| 645 : | var $menutype=null; | ||
| 646 : | /** @var string */ | ||
| 647 : | var $name=null; | ||
| 648 : | /** @var string */ | ||
| 649 : | var $link=null; | ||
| 650 : | /** @var int */ | ||
| 651 : | var $type=null; | ||
| 652 : | /** @var int */ | ||
| 653 : | var $published=null; | ||
| 654 : | /** @var int */ | ||
| 655 : | var $componentid=null; | ||
| 656 : | /** @var int */ | ||
| 657 : | var $parent=null; | ||
| 658 : | /** @var int */ | ||
| 659 : | var $sublevel=null; | ||
| 660 : | /** @var int */ | ||
| 661 : | var $ordering=null; | ||
| 662 : | /** @var boolean */ | ||
| 663 : | var $checked_out=null; | ||
| 664 : | /** @var datetime */ | ||
| 665 : | var $checked_out_time=null; | ||
| 666 : | /** @var boolean */ | ||
| 667 : | var $pollid=null; | ||
| 668 : | csouza | 129 | |
| 669 : | csouza | 154 | /** @var string */ |
| 670 : | var $browserNav=null; | ||
| 671 : | /** @var int */ | ||
| 672 : | var $access=null; | ||
| 673 : | /** @var int */ | ||
| 674 : | var $utaccess=null; | ||
| 675 : | /** @var string */ | ||
| 676 : | var $params=null; | ||
| 677 : | csouza | 129 | |
| 678 : | csouza | 154 | /** |
| 679 : | csouza | 129 | * @param database A database connector object |
| 680 : | */ | ||
| 681 : | counterpoi | 319 | t function mosMenu() { |
| 682 : | counterpoi | 238 | t $db =& mamboDatabase::getInstance(); |
| 683 : | csouza | 154 | $this->mosDBTable( '#__menu', 'id', $db ); |
| 684 : | } | ||
| 685 : | /** | ||
| 686 : | csouza | 129 | * binds an array/hash to this object |
| 687 : | * @param int $oid optional argument, if not specifed then the value of current key is used | ||
| 688 : | * @return any result from the database operation | ||
| 689 : | */ | ||
| 690 : | csouza | 154 | function load( $oid=null ) { |
| 691 : | $k = $this->_tbl_key; | ||
| 692 : | if ($oid !== null) $this->$k = $oid; | ||
| 693 : | if ($this->$k === null) return false; | ||
| 694 : | counterpoi | 238 | t $menuhandler =& mosMenuHandler::getInstance(); |
| 695 : | t $menu =& $menuhandler->getMenuById($this->$k); | ||
| 696 : | csouza | 154 | if ($menu) { |
| 697 : | foreach (get_object_vars($menu) as $key=>$data) $this->$key = $data; | ||
| 698 : | return true; | ||
| 699 : | } | ||
| 700 : | else return false; | ||
| 701 : | } | ||
| 702 : | |||
| 703 : | csouza | 129 | } |
| 704 : | |||
| 705 : | /** | ||
| 706 : | * File Manager including safe mode provision? | ||
| 707 : | * @package Mambo | ||
| 708 : | */ | ||
| 709 : | class mosFileManager { | ||
| 710 : | |||
| 711 : | csouza | 154 | /** |
| 712 : | csouza | 129 | * Singleton accessor |
| 713 : | */ | ||
| 714 : | csouza | 154 | function &getInstance () { |
| 715 : | static $instance; | ||
| 716 : | if (!is_object($instance)) $instance = new mosFileManager(); | ||
| 717 : | return $instance; | ||
| 718 : | } | ||
| 719 : | csouza | 129 | |
| 720 : | csouza | 154 | function deleteFile ($file) { |
| 721 : | counterpoi | 222 | t if (file_exists($file)) { |
| 722 : | csouza | 252 | @chmod($file, 0644); |
| 723 : | return unlink($file); | ||
| 724 : | } | ||
| 725 : | return true; | ||
| 726 : | csouza | 154 | } |
| 727 : | |||
| 728 : | function deleteDirectory ($dir) { | ||
| 729 : | csouza | 252 | if (file_exists($dir)) { |
| 730 : | if (is_dir($dir)) { | ||
| 731 : | @chmod($dir, 0755); | ||
| 732 : | return rmdir($dir); | ||
| 733 : | } | ||
| 734 : | return false; | ||
| 735 : | } | ||
| 736 : | return true; | ||
| 737 : | csouza | 154 | } |
| 738 : | |||
| 739 : | function createDirectory ($dir) { | ||
| 740 : | csouza | 403 | if (file_exists($dir)) { |
| 741 : | if (is_dir($dir)) return true; | ||
| 742 : | else return false; | ||
| 743 : | } | ||
| 744 : | list($upDirectory, $count) = $this->containingDirectory($dir); | ||
| 745 : | if ($count > 1 AND !file_exists($upDirectory)) if (!$this->createDirectory($upDirectory)) return false; | ||
| 746 : | if (!is_dir($upDirectory)) return false; | ||
| 747 : | $dirperms = mamboCore::get('mosConfig_dirperms'); | ||
| 748 : | if ($dirperms) { | ||
| 749 : | $origmask = @umask(0); | ||
| 750 : | $mode = octdec($dirperms); | ||
| 751 : | } | ||
| 752 : | else $mode = 0755; | ||
| 753 : | counterpoi | 222 | t if (!@mkdir($dir, $mode )) $result = false; |
| 754 : | t else { | ||
| 755 : | csouza | 252 | $result = true; |
| 756 : | @chmod ($dir, $mode); | ||
| 757 : | } | ||
| 758 : | if (isset($origmask)) @umask($origmask); | ||
| 759 : | counterpoi | 222 | t return $result; |
| 760 : | csouza | 154 | } |
| 761 : | counterpoi | 222 | t |
| 762 : | counterpoi | 199 | t function containingDirectory ($dir) { |
| 763 : | csouza | 252 | $dirs = preg_split('*[/|\\\]*', $dir); |
| 764 : | for ($i = count($dirs)-1; $i >= 0; $i--) { | ||
| 765 : | $text = trim($dirs[$i]); | ||
| 766 : | unset($dirs[$i]); | ||
| 767 : | if ($text) break; | ||
| 768 : | } | ||
| 769 : | return array(implode('/',$dirs), count($dirs)); | ||
| 770 : | counterpoi | 199 | t } |
| 771 : | csouza | 154 | |
| 772 : | counterpoi | 222 | t |
| 773 : | csouza | 154 | function forceCopy ($from, $to) { |
| 774 : | $todir = dirname($to); | ||
| 775 : | if (!file_exists($todir)) $this->createDirectory($todir); | ||
| 776 : | counterpoi | 199 | t if (!file_exists($todir)) return false; |
| 777 : | t $name = basename($from); | ||
| 778 : | csouza | 154 | $this->deleteFile($to.$name); |
| 779 : | counterpoi | 199 | t return @copy($from, $to); |
| 780 : | csouza | 154 | } |
| 781 : | counterpoi | 222 | t |
| 782 : | counterpoi | 199 | t function lightCopy ($from, $to) { |
| 783 : | t $name = basename($from); | ||
| 784 : | csouza | 252 | if (file_exists($to.$name)) return false; |
| 785 : | counterpoi | 199 | t $todir = dirname($to); |
| 786 : | t if (!file_exists($todir)) $this->createDirectory($todir); | ||
| 787 : | t if (!file_exists($todir)) return false; | ||
| 788 : | csouza | 252 | return @copy($from, $to); |
| 789 : | counterpoi | 199 | t } |
| 790 : | csouza | 154 | |
| 791 : | |||
| 792 : | /** | ||
| 793 : | csouza | 129 | * Function to strip additional / or \ in a path name |
| 794 : | * @param string The path | ||
| 795 : | * @param boolean Add trailing slash | ||
| 796 : | */ | ||
| 797 : | csouza | 154 | function mosPathName($p_path, $p_addtrailingslash=true) { |
| 798 : | if (substr(PHP_OS, 0, 3) == 'WIN') { | ||
| 799 : | $retval = str_replace( '/', '\\', $p_path ); | ||
| 800 : | if ($p_addtrailingslash AND substr( $retval, -1 ) != '\\') $retval .= '\\'; | ||
| 801 : | // Remove double \\ | ||
| 802 : | $retval = str_replace( '\\\\', '\\', $retval ); | ||
| 803 : | } | ||
| 804 : | else { | ||
| 805 : | $retval = str_replace( '\\', '/', $p_path ); | ||
| 806 : | if ($p_addtrailingslash AND substr( $retval, -1 ) != '/') $retval .= '/'; | ||
| 807 : | // Remove double // | ||
| 808 : | $retval = str_replace('//','/',$retval); | ||
| 809 : | } | ||
| 810 : | return $retval; | ||
| 811 : | } | ||
| 812 : | csouza | 129 | |
| 813 : | csouza | 154 | /** |
| 814 : | csouza | 129 | * Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up. |
| 815 : | * @param path The starting file or directory (no trailing slash) | ||
| 816 : | * @param filemode Integer value to chmod files. NULL = dont chmod files. | ||
| 817 : | * @param dirmode Integer value to chmod directories. NULL = dont chmod directories. | ||
| 818 : | * @return TRUE=all succeeded FALSE=one or more chmods failed | ||
| 819 : | */ | ||
| 820 : | csouza | 154 | function mosChmod($path) |
| 821 : | { | ||
| 822 : | $fileperms = mamboCore::get('mosConfig_fileperms'); | ||
| 823 : | if ($fileperms != '') $filemode = octdec($fileperms); | ||
| 824 : | else $filemode = null; | ||
| 825 : | counterpoi | 222 | t $dirperms = mamboCore::get('mosConfig_dirperms'); |
| 826 : | csouza | 154 | if ($dirperms != '') $dirmode = octdec($dirperms); |
| 827 : | else $dirmode = null; | ||
| 828 : | if (isset($filemode) OR isset($dirmode)) | ||
| 829 : | return $this->mosChmodRecursive($path, $filemode, $dirmode); | ||
| 830 : | return true; | ||
| 831 : | } // mosChmod | ||
| 832 : | csouza | 129 | |
| 833 : | csouza | 154 | /** |
| 834 : | csouza | 129 | * Chmods files and directories recursively to given permissions. Available from 4.5.2 up. |
| 835 : | * @param path The starting file or directory (no trailing slash) | ||
| 836 : | * @param filemode Integer value to chmod files. NULL = dont chmod files. | ||
| 837 : | * @param dirmode Integer value to chmod directories. NULL = dont chmod directories. | ||
| 838 : | * @return TRUE=all succeeded FALSE=one or more chmods failed | ||
| 839 : | */ | ||
| 840 : | csouza | 154 | function mosChmodRecursive($path, $filemode=NULL, $dirmode=NULL) { |
| 841 : | $ret = true; | ||
| 842 : | if (is_dir($path)) { | ||
| 843 : | $topdir =& new mosDirectory($path); | ||
| 844 : | counterpoi | 371 | t $files =& $topdir->listFiles ('', 'file', true, true); |
| 845 : | t $dirs =& $topdir->listFiles ('', 'dir', true, true); | ||
| 846 : | csouza | 154 | } |
| 847 : | else { | ||
| 848 : | $files = array($path); | ||
| 849 : | $dirs = array(); | ||
| 850 : | } | ||
| 851 : | if (isset($filemode)) foreach ($files as $file) $ret = @chmod($file, $filemode) ? $ret : false; | ||
| 852 : | if (isset($dirmode)) foreach ($dirs as $dir) $ret = @chmod($dir, $dirmode) ? $ret : false; | ||
| 853 : | return $ret; | ||
| 854 : | } | ||
| 855 : | csouza | 129 | |
| 856 : | } | ||
| 857 : | |||
| 858 : | class mosDirectory { | ||
| 859 : | csouza | 154 | var $path = ''; |
| 860 : | csouza | 129 | |
| 861 : | csouza | 154 | function mosDirectory ($path) { |
| 862 : | $path = str_replace('\\', '/', $path); | ||
| 863 : | if (substr($path,-1,1) == '/') $this->path = $path; | ||
| 864 : | else $this->path = $path.'/'; | ||
| 865 : | } | ||
| 866 : | csouza | 129 | |
| 867 : | csouza | 154 | function &listAll ($type='file', $recurse=false, $fullpath=false) { |
| 868 : | $results = array(); | ||
| 869 : | if ($dir = @opendir($this->path)) { | ||
| 870 : | while ($file = readdir($dir)) { | ||
| 871 : | if ($file == '.' OR $file == '..') continue; | ||
| 872 : | if (is_dir($this->path.$file)) { | ||
| 873 : | if ($recurse) { | ||
| 874 : | $subdir = new mosDirectory($this->path.$file); | ||
| 875 : | $results = array_merge($results, $subdir->listAll($type, $recurse, $fullpath)); | ||
| 876 : | unset($subdir); | ||
| 877 : | } | ||
| 878 : | if ($type == 'file') continue; | ||
| 879 : | } | ||
| 880 : | elseif ($type == 'dir') continue; | ||
| 881 : | if ($fullpath) $results[] = $this->path.$file; | ||
| 882 : | else $results[] = $file; | ||
| 883 : | } | ||
| 884 : | closedir($dir); | ||
| 885 : | } | ||
| 886 : | return $results; | ||
| 887 : | } | ||
| 888 : | csouza | 151 | |
| 889 : | csouza | 154 | function soleDir () { |
| 890 : | $found = ''; | ||
| 891 : | if ($dir = @opendir($this->path)) { | ||
| 892 : | while ($file = readdir($dir)) { | ||
| 893 : | if ($file == '.' OR $file == '..') continue; | ||
| 894 : | if (is_dir($this->path.$file)) { | ||
| 895 : | if ($found) return ''; | ||
| 896 : | else $found = $file; | ||
| 897 : | } | ||
| 898 : | else return ''; | ||
| 899 : | } | ||
| 900 : | closedir($dir); | ||
| 901 : | } | ||
| 902 : | return $found; | ||
| 903 : | } | ||
| 904 : | csouza | 129 | |
| 905 : | csouza | 154 | function deleteAll () { |
| 906 : | if (!file_exists($this->path)) return; | ||
| 907 : | $subdirs =& $this->listAll ('dir', false, true); | ||
| 908 : | foreach ($subdirs as $subdir) { | ||
| 909 : | $subdirectory = new mosDirectory($subdir); | ||
| 910 : | $subdirectory->deleteAll(); | ||
| 911 : | unset($subdirectory); | ||
| 912 : | } | ||
| 913 : | counterpoi | 238 | t $filemanager =& mosFileManager::getInstance(); |
| 914 : | csouza | 154 | $files =& $this->listAll ('file', false, true); |
| 915 : | foreach ($files as $file) $filemanager->deleteFile($file); | ||
| 916 : | $filemanager->deleteDirectory($this->path); | ||
| 917 : | } | ||
| 918 : | |||
| 919 : | function createFresh () { | ||
| 920 : | $this->deleteAll(); | ||
| 921 : | counterpoi | 238 | t $filemanager =& mosFileManager::getInstance(); |
| 922 : | csouza | 154 | $filemanager->createDirectory($this->path); |
| 923 : | return true; | ||
| 924 : | } | ||
| 925 : | |||
| 926 : | function createIfNeeded () { | ||
| 927 : | if (!file_exists($this->path)) { | ||
| 928 : | counterpoi | 238 | t $filemanager =& mosFileManager::getInstance(); |
| 929 : | csouza | 154 | $filemanager->createDirectory($this->path); |
| 930 : | } | ||
| 931 : | } | ||
| 932 : | |||
| 933 : | function &listFiles ($pattern='', $type='file', $recurse=false, $fullpath=false) { | ||
| 934 : | $results = array(); | ||
| 935 : | $all =& $this->listAll($type, $recurse, $fullpath); | ||
| 936 : | foreach ($all as $file) { | ||
| 937 : | $name = basename($file); | ||
| 938 : | if ($pattern AND !preg_match( "/$pattern/", $name )) continue; | ||
| 939 : | if (($name != 'index.html') AND ($name[0] != '.')) $results[] = $file; | ||
| 940 : | } | ||
| 941 : | return $results; | ||
| 942 : | } | ||
| 943 : | |||
| 944 : | function getSize () { | ||
| 945 : | $totalsize = 0; | ||
| 946 : | counterpoi | 238 | t $files =& $this->listFiles(); |
| 947 : | csouza | 154 | foreach ($files as $file) $totalsize += filesize($this->path.$file); |
| 948 : | return $totalsize; | ||
| 949 : | } | ||
| 950 : | |||
| 951 : | csouza | 129 | } |
| 952 : | |||
| 953 : | /** | ||
| 954 : | * Menu handler | ||
| 955 : | * @package Mambo | ||
| 956 : | */ | ||
| 957 : | class mosMenuHandler { | ||
| 958 : | csouza | 154 | /** @var array Menu objects currently available */ |
| 959 : | var $_menus = null; | ||
| 960 : | /** @var array Counts of menu items by type and published status */ | ||
| 961 : | var $_counts = null; | ||
| 962 : | /** @var array Access to stored menu objects by ID */ | ||
| 963 : | var $_idlinks = null; | ||
| 964 : | /** @var array Items that may be useful for setting Itemid */ | ||
| 965 : | var $_byParentOrder = null; | ||
| 966 : | csouza | 129 | |
| 967 : | csouza | 154 | /** |
| 968 : | csouza | 129 | * Constructor |
| 969 : | */ | ||
| 970 : | csouza | 154 | function mosMenuHandler() { |
| 971 : | global $my; | ||
| 972 : | counterpoi | 238 | t $database =& mamboDatabase::getInstance(); |
| 973 : | csouza | 154 | $sql = "SELECT * FROM #__menu ORDER BY name"; |
| 974 : | $this->_menus =& $database->doSQLget($sql, 'mosMenu'); | ||
| 975 : | if (!$this->_menus) $this->_menus = array(); | ||
| 976 : | foreach ($this->_menus as $key=>$menu) { | ||
| 977 : | $this->_idlinks[$menu->id] = $key; | ||
| 978 : | if ($menu->published == 1) $this->_byParentOrder[$menu->parent][$menu->ordering][$menu->menutype] = $key; | ||
| 979 : | if (isset($this->_counts[$menu->menutype][$menu->published])) $this->_counts[$menu->menutype][$menu->published]++; | ||
| 980 : | else $this->_counts[$menu->menutype][$menu->published] = 1; | ||
| 981 : | } | ||
| 982 : | if ($this->_byParentOrder) { | ||
| 983 : | foreach ($this->_byParentOrder as $parent=>$outer) ksort($this->_byParentOrder[$parent]); | ||
| 984 : | ksort($this->_byParentOrder); | ||
| 985 : | } | ||
| 986 : | } | ||
| 987 : | /** | ||
| 988 : | csouza | 129 | * Singleton accessor |
| 989 : | */ | ||
| 990 : | csouza | 154 | function &getInstance () { |
| 991 : | static $instance; | ||
| 992 : | if (!is_object($instance)) $instance = new mosMenuHandler(); | ||
| 993 : | return $instance; | ||
| 994 : | } | ||
| 995 : | csouza | 129 | |
| 996 : | csouza | 154 | function &getMenuByID ($id) { |
| 997 : | if (isset($this->_idlinks[$id])) { | ||
| 998 : | $key = $this->_idlinks[$id]; | ||
| 999 : | counterpoi | 288 | t $result = $this->_menus[$key]; |
| 1000 : | csouza | 154 | } |
| 1001 : | counterpoi | 288 | t else $result = null; |
| 1002 : | csouza | 154 | return $result; |
| 1003 : | } | ||
| 1004 : | csouza | 129 | |
| 1005 : | csouza | 154 | function getMenuCount ($type, $published) { |
| 1006 : | if (isset($this->_counts[$type][$published])) return $this->_counts[$type][$published]; | ||
| 1007 : | else return 0; | ||
| 1008 : | } | ||
| 1009 : | csouza | 129 | |
| 1010 : | csouza | 154 | function &getMenusByType ($types) { |
| 1011 : | $checker = explode(',', $types); | ||
| 1012 : | $result = null; | ||
| 1013 : | foreach ($this->_menus as $menu) { | ||
| 1014 : | if (in_array($menu->menutype, $checker)) $result[] = $menu; | ||
| 1015 : | } | ||
| 1016 : | return $result; | ||
| 1017 : | } | ||
| 1018 : | counterpoi | 419 | t |
| 1019 : | t function &getMenuTypes () { | ||
| 1020 : | t $types = array(); | ||
| 1021 : | t foreach ($this->_menus as $menu) { | ||
| 1022 : | t if (!in_array($menu->menutype, $types)) $types[] = $menu->menutype; | ||
| 1023 : | t } | ||
| 1024 : | t return $types; | ||
| 1025 : | t } | ||
| 1026 : | csouza | 129 | |
| 1027 : | csouza | 154 | function getIDByTypeLink ($type, $link) { |
| 1028 : | foreach ($this->_menus as $menu) { | ||
| 1029 : | if ($menu->published == 1 AND ($type == '*' OR $menu->type == $type) AND $menu->link == $link) return $menu->id; | ||
| 1030 : | } | ||
| 1031 : | return null; | ||
| 1032 : | } | ||
| 1033 : | csouza | 129 | |
| 1034 : | csouza | 154 | function getIDLikeLink ($link) { |
| 1035 : | $exact = $this->getIdByTypeLink('*', $link); | ||
| 1036 : | if ($exact !== null) return $exact; | ||
| 1037 : | foreach ($this->_menus as $menu) { | ||
| 1038 : | if ($menu->published == 1 AND strpos($menu->link,$link) === 0) return $menu->id; | ||
| 1039 : | } | ||
| 1040 : | return 0; | ||
| 1041 : | } | ||
| 1042 : | csouza | 129 | |
| 1043 : | csouza | 154 | function getIDByTypeCid ($type, $componentid) { |
| 1044 : | foreach ($this->_menus as $menu) { | ||
| 1045 : | if ($menu->published == 1 AND $menu->type == $type AND $menu->componentid == $componentid) return $menu->id; | ||
| 1046 : | } | ||
| 1047 : | return null; | ||
| 1048 : | } | ||
| 1049 : | csouza | 129 | |
| 1050 : | csouza | 154 | function getGlobalBlogSectionCount () { |
| 1051 : | $count = 0; | ||
| 1052 : | foreach ($this->_menus as $menu) { | ||
| 1053 : | if ($menu->type == 'content_blog_section' AND $menu->published == 1 AND $menu->componentid == 0) $count++; | ||
| 1054 : | } | ||
| 1055 : | return $count; | ||
| 1056 : | } | ||
| 1057 : | csouza | 129 | |
| 1058 : | csouza | 154 | function getContentItemid ($Itemid, $type, $id, $catid=0) { |
| 1059 : | if ($Itemid) return $Itemid; | ||
| 1060 : | foreach ($this->_menus as $menu) { | ||
| 1061 : | if (strpos($menu->link,'index.php?option=com_content') === false AND strpos($menu->link,'index.php?option=content') === false) continue; | ||
| 1062 : | if (strpos($menu->link, $type) === false) continue; | ||
| 1063 : | if ($catid) { | ||
| 1064 : | if (strpos($menu->link, "&id=$catid") === false) continue; | ||
| 1065 : | if (strpos($menu->link, "§ionid=$id") === false) continue; | ||
| 1066 : | } | ||
| 1067 : | elseif (strpos($menu->link, "&id=$id") === false) continue; | ||
| 1068 : | return $menu->id; | ||
| 1069 : | } | ||
| 1070 : | return 0; | ||
| 1071 : | } | ||
| 1072 : | csouza | 129 | |
| 1073 : | csouza | 154 | function getBestQueryMatch () { |
| 1074 : | parse_str($_SERVER['QUERY_STRING'], $qitems); | ||
| 1075 : | if (!isset($qitems['option'])) return 0; | ||
| 1076 : | $failures = 999; | ||
| 1077 : | $best = 0; | ||
| 1078 : | foreach ($this->_menus as $menu) { | ||
| 1079 : | $split = explode('?', $menu->link); | ||
| 1080 : | if (isset($split[1])) parse_str($split[1], $mitems); | ||
| 1081 : | else continue; | ||
| 1082 : | if (!isset($mitems['option']) OR $mitems['option'] != $qitems['option']) continue; | ||
| 1083 : | $thisfail = 0; | ||
| 1084 : | foreach ($mitems as $key=>$mitem) if (!isset($qitems[$key]) OR $mitem != $qitems[$key]) $thisfail++; | ||
| 1085 : | if ($thisfail < $failures) { | ||
| 1086 : | $best = $menu->id; | ||
| 1087 : | $failures = $thisfail; | ||
| 1088 : | } | ||
| 1089 : | } | ||
| 1090 : | return $best; | ||
| 1091 : | } | ||
| 1092 : | |||
| 1093 : | |||
| 1094 : | function &maxAccessLink ($link) { | ||
| 1095 : | $selected = null; | ||
| 1096 : | $access = 0; | ||
| 1097 : | foreach ($this->_menus as $key=>$menu) { | ||
| 1098 : | if (strpos($menu->link,$link) === 0 AND $menu->access > $access) { | ||
| 1099 : | $access = $menu->access; | ||
| 1100 : | $selected =& $this->_menus[$key]; | ||
| 1101 : | } | ||
| 1102 : | } | ||
| 1103 : | return $selected; | ||
| 1104 : | } | ||
| 1105 : | |||
| 1106 : | function &getByParentOrder ($Itemid, $menutype, $maxaccess=0, $noparent=false) { | ||
| 1107 : | $result = array(); | ||
| 1108 : | if ($this->_byParentOrder !== null) { | ||
| 1109 : | foreach ($this->_byParentOrder as $parent=>$outer) { | ||
| 1110 : | foreach ($outer as $ordering=>$inner) { | ||
| 1111 : | foreach ($inner as $mtype=>$last) { | ||
| 1112 : | $key = $this->_byParentOrder[$parent][$ordering][$mtype]; | ||
| 1113 : | $menu = $this->_menus[$key]; | ||
| 1114 : | if ($menutype AND $mtype != $menutype) continue; | ||
| 1115 : | if ($Itemid AND $Itemid != $menu->id) continue; | ||
| 1116 : | counterpoi | 286 | t if ($menu->access > $maxaccess) continue; |
| 1117 : | csouza | 154 | if ($noparent AND $parent != 0) continue; |
| 1118 : | $result[] = $this->_menus[$key]; | ||
| 1119 : | } | ||
| 1120 : | } | ||
| 1121 : | } | ||
| 1122 : | } | ||
| 1123 : | return $result; | ||
| 1124 : | } | ||
| 1125 : | |||
| 1126 : | function setPathway ($Itemid) { | ||
| 1127 : | if ($Itemid) { | ||
| 1128 : | counterpoi | 238 | t $menu =& $this->getMenuByID($Itemid); |
| 1129 : | csouza | 154 | if ($menu->parent) $this->setPathway($menu->parent); |
| 1130 : | counterpoi | 238 | t $pathway =& mosPathway::getInstance(); |
| 1131 : | csouza | 154 | $pathway->addItem($menu->name, $menu->link."&Itemid=$Itemid"); |
| 1132 : | } | ||
| 1133 : | } | ||
| 1134 : | |||
| 1135 : | /** | ||
| 1136 : | csouza | 129 | * Checks whether a menu option is within the users access level |
| 1137 : | * @param int Item id number | ||
| 1138 : | * @param string The menu option | ||
| 1139 : | * @param int The users group ID number | ||
| 1140 : | * @param database A database connector object | ||
| 1141 : | * @return boolean True if the visitor's group at least equal to the menu access | ||
| 1142 : | */ | ||
| 1143 : | csouza | 154 | function menuCheck( $Itemid, $menu_option, $task, $gid ) { |
| 1144 : | $exceptions = array ('com_banner', 'com_poll', 'com_registration', 'com_rss'); | ||
| 1145 : | if (in_array($menu_option, $exceptions)) return true; | ||
| 1146 : | $dblink="index.php?option=$menu_option"; | ||
| 1147 : | if ($Itemid) { | ||
| 1148 : | counterpoi | 238 | t $menu =& $this->getMenuByID($Itemid); |
| 1149 : | csouza | 154 | if (strpos($menu->link,$dblink) ===0) $access = $menu->access; |
| 1150 : | } | ||
| 1151 : | if (!isset($access)) { | ||
| 1152 : | if ($task!='') $dblink .= "&task=$task"; | ||
| 1153 : | counterpoi | 238 | t $menu =& $this->maxAccessLink($dblink); |
| 1154 : | csouza | 154 | if (isset($menu)) { |
| 1155 : | $access = $menu->access; | ||
| 1156 : | mamboCore::set('Itemid', $menu->id); | ||
| 1157 : | } | ||
| 1158 : | } | ||
| 1159 : | return isset($access) ? $access <= $gid : false; | ||
| 1160 : | } | ||
| 1161 : | csouza | 129 | |
| 1162 : | csouza | 154 | function mosGetMenuLink( &$mitem, $level=0, &$params, $Itemid ) { |
| 1163 : | $txt = ''; | ||
| 1164 : | csouza | 129 | |
| 1165 : | csouza | 154 | switch ($mitem->type) { |
| 1166 : | case 'separator': | ||
| 1167 : | case 'component_item_link': | ||
| 1168 : | break; | ||
| 1169 : | case 'content_item_link': | ||
| 1170 : | $temp = split("&task=view&id=", $mitem->link); | ||
| 1171 : | if (isset($temp[1])) { | ||
| 1172 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 1173 : | counterpoi | 238 | t $handler =& contentHandler::getInstance(); |
| 1174 : | csouza | 154 | $mitem->link .= '&Itemid='.$handler->getItemid($temp[1]); |
| 1175 : | } | ||
| 1176 : | break; | ||
| 1177 : | case 'url': | ||
| 1178 : | $link = strtolower($mitem->link); | ||
| 1179 : | if (substr($link,0,10) == 'index.php?' AND strpos($link,'itemid=') === false) $mitem->link .= '&Itemid='. $mitem->id; | ||
| 1180 : | break; | ||
| 1181 : | case 'content_typed': | ||
| 1182 : | default: | ||
| 1183 : | $mitem->link .= '&Itemid='.$mitem->id; | ||
| 1184 : | break; | ||
| 1185 : | } | ||
| 1186 : | // Active Menu highlighting | ||
| 1187 : | if ( $Itemid == $mitem->id ) $id = 'id="active_menu'.$params->get( 'class_sfx' ).'"'; | ||
| 1188 : | else $id = ''; | ||
| 1189 : | $mitem->link = ampReplace( $mitem->link ); | ||
| 1190 : | if (strcasecmp(substr($mitem->link,0,4), 'http')) $mitem->link = sefRelToAbs( $mitem->link ); | ||
| 1191 : | if ($level > 0) $menuclass = 'sublevel'; | ||
| 1192 : | else $menuclass = 'mainlevel'; | ||
| 1193 : | $menuclass .= $params->get( 'class_sfx'); | ||
| 1194 : | csouza | 129 | |
| 1195 : | csouza | 154 | switch ($mitem->browserNav) { |
| 1196 : | // cases are slightly different | ||
| 1197 : | case 1: | ||
| 1198 : | // open in a new window | ||
| 1199 : | $txt = '<a href="'. $mitem->link .'" target="_blank" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; | ||
| 1200 : | break; | ||
| 1201 : | csouza | 129 | |
| 1202 : | csouza | 154 | case 2: |
| 1203 : | // open in a popup window | ||
| 1204 : | $txt = "<a href=\"#\" onclick=\"javascript: window.open('". $mitem->link ."', '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'); return false\" class=\"$menuclass\" ". $id .">". $mitem->name ."</a>\n"; | ||
| 1205 : | break; | ||
| 1206 : | csouza | 129 | |
| 1207 : | csouza | 154 | case 3: |
| 1208 : | // don't link it | ||
| 1209 : | $txt = '<span class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</span>'; | ||
| 1210 : | break; | ||
| 1211 : | csouza | 129 | |
| 1212 : | csouza | 154 | default: // formerly case 2 |
| 1213 : | // open in parent window | ||
| 1214 : | $txt = '<a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; | ||
| 1215 : | break; | ||
| 1216 : | } | ||
| 1217 : | csouza | 129 | |
| 1218 : | csouza | 154 | if ( $params->get( 'menu_images' ) ) { |
| 1219 : | $menu_params =& new mosParameters( $mitem->params ); | ||
| 1220 : | $menu_image = $menu_params->def( 'menu_image', -1 ); | ||
| 1221 : | if ($menu_image AND $menu_image <> '-1') { | ||
| 1222 : | $image = '<img src="'. mamboCore::get('mosConfig_live_site') .'/images/stories/'. $menu_image .'" border="0" alt="'. $mitem->name .'"/>'; | ||
| 1223 : | if ( $params->get('menu_images_align')) $txt = $txt .' '. $image; | ||
| 1224 : | else $txt = $image .' '. $txt; | ||
| 1225 : | } | ||
| 1226 : | } | ||
| 1227 : | return $txt; | ||
| 1228 : | } | ||
| 1229 : | csouza | 129 | |
| 1230 : | csouza | 154 | /** |
| 1231 : | csouza | 129 | * Vertically Indented Menu |
| 1232 : | */ | ||
| 1233 : | csouza | 154 | function mosShowVIMenu( &$params ) { |
| 1234 : | global $my, $cur_template, $Itemid; | ||
| 1235 : | csouza | 129 | |
| 1236 : | csouza | 154 | if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 0; |
| 1237 : | else $maxaccess = $my->gid; | ||
| 1238 : | $rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess); | ||
| 1239 : | foreach ($rows as $i=>$row) $crosslink[$row->id] = $i; | ||
| 1240 : | // indent icons | ||
| 1241 : | $base = mamboCore::get('mosConfig_live_site'); | ||
| 1242 : | switch ( $params->get( 'indent_image' ) ) { | ||
| 1243 : | case '1': | ||
| 1244 : | // Default images | ||
| 1245 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 1246 : | $img[$i] = "<img src=\"$base/images/M_images/indent$i.png\" alt=\"indent$i\" />"; | ||
| 1247 : | } | ||
| 1248 : | break; | ||
| 1249 : | case '2': | ||
| 1250 : | // Use Params | ||
| 1251 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 1252 : | $parm = $params->get('indent_image'. $i); | ||
| 1253 : | if ($parm == '-1' ) $img[$i] = NULL; | ||
| 1254 : | else $img[$i] = "<img src=\"$base/images/M_images/$parm\" alt=\"indent$i\" />"; | ||
| 1255 : | } | ||
| 1256 : | break; | ||
| 1257 : | case '3': | ||
| 1258 : | // None | ||
| 1259 : | for ( $i = 1; $i < 7; $i++ ) $img[$i] = NULL; | ||
| 1260 : | break; | ||
| 1261 : | default: | ||
| 1262 : | // Template | ||
| 1263 : | $imgpath = $base.'/templates/'. $cur_template .'/images'; | ||
| 1264 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 1265 : | $img[$i] = "<img src=\"$base/templates/$cur_template/images/indent$i.png\" alt=\"indent$i\" />"; | ||
| 1266 : | } | ||
| 1267 : | break; | ||
| 1268 : | } | ||
| 1269 : | csouza | 129 | |
| 1270 : | csouza | 154 | $indents = array( |
| 1271 : | // block prefix / item prefix / item suffix / block suffix | ||
| 1272 : | array( '<table width="100%" border="0" cellpadding="0" cellspacing="0">', '<tr align="left"><td>' , '</td></tr>', '</table>' ), | ||
| 1273 : | array( '', '<div style="padding-left: 4px">'. $img[1] , '</div>', '' ), | ||
| 1274 : | array( '', '<div style="padding-left: 8px">'. $img[2] , '</div>', '' ), | ||
| 1275 : | array( '', '<div style="padding-left: 12px">'. $img[3] , '</div>', '' ), | ||
| 1276 : | array( '', '<div style="padding-left: 16px">'. $img[4] , '</div>', '' ), | ||
| 1277 : | array( '', '<div style="padding-left: 20px">'. $img[5] , '</div>', '' ), | ||
| 1278 : | array( '', '<div style="padding-left: 24px">'. $img[6] , '</div>', '' ), | ||
| 1279 : | ); | ||
| 1280 : | csouza | 129 | |
| 1281 : | csouza | 154 | // establish the hierarchy of the menu |
| 1282 : | $children = array(); | ||
| 1283 : | // first pass - collect children | ||
| 1284 : | foreach ($rows as $v ) $children[$v->parent][] = $v; | ||
| 1285 : | // second pass - collect 'open' menus | ||
| 1286 : | $open = array( $Itemid ); | ||
| 1287 : | for ($i = 0; $i < 20 AND isset($crosslink[$open[$i]]) AND isset($rows[$crosslink[$open[$i]]]); $i++) { | ||
| 1288 : | $next = $rows[$crosslink[$open[$i]]]->parent; | ||
| 1289 : | if ($next) $open[$i+1] = $next; | ||
| 1290 : | else break; | ||
| 1291 : | } | ||
| 1292 : | csouza | 129 | |
| 1293 : | csouza | 154 | $this->mosRecurseVIMenu( 0, 0, $children, $open, $indents, $params ); |
| 1294 : | csouza | 129 | |
| 1295 : | csouza | 154 | } |
| 1296 : | csouza | 129 | |
| 1297 : | csouza | 154 | /** |
| 1298 : | csouza | 129 | * Utility function to recursively work through a vertically indented |
| 1299 : | * hierarchial menu | ||
| 1300 : | */ | ||
| 1301 : | csouza | 154 | function mosRecurseVIMenu( $id, $level, &$children, &$open, &$indents, &$params ) { |
| 1302 : | global $Itemid; | ||
| 1303 : | if (@$children[$id]) { | ||
| 1304 : | $n = min( $level, count($indents )-1); | ||
| 1305 : | echo "\n".$indents[$n][0]; | ||
| 1306 : | foreach ($children[$id] as $row) { | ||
| 1307 : | echo "\n".$indents[$n][1]; | ||
| 1308 : | echo $this->mosGetMenuLink( $row, $level, $params, $Itemid ); | ||
| 1309 : | // show menu with menu expanded - submenus visible | ||
| 1310 : | if ($params->get('expand_menu') OR in_array($row->id, $open)) $this->mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params ); | ||
| 1311 : | echo $indents[$n][2]; | ||
| 1312 : | } | ||
| 1313 : | echo "\n".$indents[$n][3]; | ||
| 1314 : | } | ||
| 1315 : | } | ||
| 1316 : | csouza | 129 | |
| 1317 : | csouza | 154 | /** |
| 1318 : | csouza | 129 | * Draws a horizontal 'flat' style menu (very simple case) |
| 1319 : | */ | ||
| 1320 : | csouza | 154 | function mosShowHFMenu( &$params, $style=0 ) { |
| 1321 : | global $my, $cur_template, $Itemid; | ||
| 1322 : | csouza | 129 | |
| 1323 : | csouza | 154 | if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 0; |
| 1324 : | else $maxaccess = $my->gid; | ||
| 1325 : | $rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess, true); | ||
| 1326 : | csouza | 129 | |
| 1327 : | csouza | 154 | $links = array(); |
| 1328 : | foreach ($rows as $row) $links[] = $this->mosGetMenuLink( $row, 0, $params, $Itemid ); | ||
| 1329 : | $menuclass = 'mainlevel'. $params->get( 'class_sfx' ); | ||
| 1330 : | if (count( $links )) { | ||
| 1331 : | if ($style == 1) { | ||
| 1332 : | echo '<ul id="'. $menuclass .'">'; | ||
| 1333 : | foreach ($links as $link) echo '<li>' . $link . '</li>'; | ||
| 1334 : | echo '</ul>'; | ||
| 1335 : | } | ||
| 1336 : | else { | ||
| 1337 : | echo '<table width="100%" border="0" cellpadding="0" cellspacing="1">'; | ||
| 1338 : | echo '<tr>'; | ||
| 1339 : | echo '<td nowrap="nowrap">'; | ||
| 1340 : | echo '<span class="'. $menuclass .'"> '. $params->get( 'end_spacer' ) .' </span>'; | ||
| 1341 : | echo implode( '<span class="'. $menuclass .'"> '. $params->get( 'spacer' ) .' </span>', $links ); | ||
| 1342 : | echo '<span class="'. $menuclass .'"> '. $params->get( 'end_spacer' ) .' </span>'; | ||
| 1343 : | echo '</td></tr>'; | ||
| 1344 : | echo '</table>'; | ||
| 1345 : | } | ||
| 1346 : | } | ||
| 1347 : | } | ||
| 1348 : | csouza | 129 | } |
| 1349 : | |||
| 1350 : | /** | ||
| 1351 : | * Plugin handler | ||
| 1352 : | * @package Mambo | ||
| 1353 : | */ | ||
| 1354 : | class mosMambotHandler { | ||
| 1355 : | csouza | 154 | /** @var array An array of functions in event groups */ |
| 1356 : | var $_events=null; | ||
| 1357 : | /** @var array An array of lists */ | ||
| 1358 : | var $_lists=null; | ||
| 1359 : | /** @var array An array of mambots */ | ||
| 1360 : | var $_bots=null; | ||
| 1361 : | /** @var array An array of bools showing if corresponding bot is registered */ | ||
| 1362 : | var $_registered=array(); | ||
| 1363 : | /** @var int Index of the mambot being loaded */ | ||
| 1364 : | var $_loading=null; | ||
| 1365 : | csouza | 129 | |
| 1366 : | csouza | 154 | /** |
| 1367 : | csouza | 129 | * Constructor |
| 1368 : | */ | ||
| 1369 : | csouza | 154 | function mosMambotHandler() { |
| 1370 : | $my = mamboCore::is_set('currentUser') ? mamboCore::get('currentUser') : null; | ||
| 1371 : | $gid = $my ? $my->gid : 0; | ||
| 1372 : | $this->_events = array(); | ||
| 1373 : | counterpoi | 238 | t $database =& mamboDatabase::getInstance(); |
| 1374 : | csouza | 154 | $database->setQuery( "SELECT folder, element, published, params, CONCAT_WS('/',folder,element) AS lookup" |
| 1375 : | . "\nFROM #__mambots" | ||
| 1376 : | . "\nWHERE published >= 1 AND access <= $gid" | ||
| 1377 : | . "\nORDER BY ordering" | ||
| 1378 : | ); | ||
| 1379 : | $this->_bots = $database->loadObjectList(); | ||
| 1380 : | if (!$this->_bots) $this->_bots = array(); | ||
| 1381 : | } | ||
| 1382 : | /** | ||
| 1383 : | csouza | 129 | * Singleton accessor |
| 1384 : | */ | ||
| 1385 : | csouza | 154 | function &getInstance () { |
| 1386 : | static $instance; | ||
| 1387 : | if (!is_object($instance)) $instance = new mosMambotHandler(); | ||
| 1388 : | return $instance; | ||
| 1389 : | } | ||
| 1390 : | /** | ||
| 1391 : | counterpoi | 245 | t * Register a class-type mambot, provided it has a perform method |
| 1392 : | t * - can register for multiple events if desired | ||
| 1393 : | t * @param object The mambot object | ||
| 1394 : | t * @param mixed string or array of strings - the mambot events to be registered | ||
| 1395 : | t * @param int the subscript for use in the main array of mambots | ||
| 1396 : | t */ | ||
| 1397 : | t function _botRegister (&$botObject, &$selected, $i) { | ||
| 1398 : | counterpoi | 286 | t $function = array(&$botObject, 'perform'); |
| 1399 : | counterpoi | 245 | t if (!is_callable($function)) return; |
| 1400 : | t if (is_array($selected)) foreach ($selected as $select) $this->_botRegister($botObject, $select); | ||
| 1401 : | t $this->_events[$selected][] = array ($function, $i); | ||
| 1402 : | t $this->_registered[$i] = true; | ||
| 1403 : | csouza | 403 | } |
| 1404 : | counterpoi | 245 | t |
| 1405 : | t /** | ||
| 1406 : | csouza | 129 | * Loads all the bot files for a particular group |
| 1407 : | * @param string The group name, relates to the sub-directory in the mambots directory | ||
| 1408 : | */ | ||
| 1409 : | csouza | 154 | function loadBotGroup( $group ) { |
| 1410 : | global $_MAMBOTS; | ||
| 1411 : | $group = trim( $group ); | ||
| 1412 : | $total = 0; | ||
| 1413 : | $basepath = mamboCore::get('mosConfig_absolute_path'); | ||
| 1414 : | foreach ($this->_bots as $i=>$bot) { | ||
| 1415 : | if ($bot->folder != $group OR isset($this->_registered[$i])) continue; | ||
| 1416 : | $path = "$basepath/mambots/$bot->folder/$bot->element.php"; | ||
| 1417 : | if (file_exists( $path )) { | ||
| 1418 : | $this->_loading = $i; | ||
| 1419 : | require_once( $path ); | ||
| 1420 : | if (!isset($this->_registered[$i])) { | ||
| 1421 : | $botclass = str_replace('.','_',$bot->element); | ||
| 1422 : | counterpoi | 245 | t if (class_exists($botclass)) { |
| 1423 : | csouza | 403 | $newbot = new $botclass(); |
| 1424 : | if (is_callable(array(&$newbot, 'register'))) { | ||
| 1425 : | $selected = $newbot->register(); | ||
| 1426 : | $this->_botRegister($newbot, $selected, $i); | ||
| 1427 : | } | ||
| 1428 : | } | ||
| 1429 : | csouza | 154 | } |
| 1430 : | $total++; | ||
| 1431 : | } | ||
| 1432 : | } | ||
| 1433 : | $this->_loading = null; | ||
| 1434 : | if ($total) return true; | ||
| 1435 : | return false; | ||
| 1436 : | } | ||
| 1437 : | /** | ||
| 1438 : | csouza | 129 | * Registers a function to a particular event group |
| 1439 : | * @param string The event name | ||
| 1440 : | * @param string The function name | ||
| 1441 : | */ | ||
| 1442 : | csouza | 154 | function registerFunction( $event, $function ) { |
| 1443 : | $this->_events[$event][] = array( $function, $this->_loading ); | ||
| 1444 : | $this->_registered[$this->_loading] = true; | ||
| 1445 : | } | ||
| 1446 : | /** | ||
| 1447 : | csouza | 129 | * Makes a option for a particular list in a group |
| 1448 : | * @param string The group name | ||
| 1449 : | * @param string The list name | ||
| 1450 : | * @param string The value for the list option | ||
| 1451 : | * @param string The text for the list option | ||
| 1452 : | */ | ||
| 1453 : | csouza | 154 | function addListOption( $group, $listName, $value, $text='' ) { |
| 1454 : | $this->_lists[$group][$listName][] = mosHTML::makeOption( $value, $text ); | ||
| 1455 : | } | ||
| 1456 : | /** | ||
| 1457 : | csouza | 129 | * @param string The group name |
| 1458 : | * @param string The list name | ||
| 1459 : | * @return array | ||
| 1460 : | */ | ||
| 1461 : | csouza | 154 | function getList( $group, $listName ) { |
| 1462 : | return $this->_lists[$group][$listName]; | ||
| 1463 : | } | ||
| 1464 : | /** | ||
| 1465 : | csouza | 129 | * Calls all functions according to passed parameters |
| 1466 : | * @param string The event name | ||
| 1467 : | * @param array An array of arguments | ||
| 1468 : | * @param boolean True is unpublished bots are to be processed | ||
| 1469 : | * @return array An array of results from each function call | ||
| 1470 : | */ | ||
| 1471 : | csouza | 154 | function &_runBots ($event, $args, $doUnpublished=false) { |
| 1472 : | $result = array(); | ||
| 1473 : | if (isset( $this->_events[$event] )) { | ||
| 1474 : | foreach ($this->_events[$event] as $func) { | ||
| 1475 : | if (is_callable( $func[0] )) { | ||
| 1476 : | $botparams = $this->_bots[$func[1]]->params; | ||
| 1477 : | counterpoi | 213 | t $args[] = new mosParameters($botparams); |
| 1478 : | t $args[] = $event; | ||
| 1479 : | csouza | 154 | if ($doUnpublished) { |
| 1480 : | $args[0] = $this->_bots[$func[1]]->published; | ||
| 1481 : | $result[] = call_user_func_array( $func[0], $args ); | ||
| 1482 : | } else if ($this->_bots[$func[1]]->published) { | ||
| 1483 : | $result[] = call_user_func_array( $func[0], $args ); | ||
| 1484 : | } | ||
| 1485 : | } | ||
| 1486 : | } | ||
| 1487 : | } | ||
| 1488 : | return $result; | ||
| 1489 : | } | ||
| 1490 : | /** | ||
| 1491 : | csouza | 129 | * Calls all functions associated with an event group |
| 1492 : | * @param string The event name | ||
| 1493 : | * @param array An array of arguments | ||
| 1494 : | * @param boolean True is unpublished bots are to be processed | ||
| 1495 : | * @return array An array of results from each function call | ||
| 1496 : | */ | ||
| 1497 : | csouza | 154 | function trigger( $event, $args=null, $doUnpublished=false ) { |
| 1498 : | if ($args === null) $args = array(); | ||
| 1499 : | // prepend the published argument | ||
| 1500 : | if ($doUnpublished) array_unshift( $args, null ); | ||
| 1501 : | $result =& $this->_runBots($event, $args, $doUnpublished); | ||
| 1502 : | return $result; | ||
| 1503 : | } | ||
| 1504 : | /** | ||
| 1505 : | csouza | 129 | * Same as trigger but only returns the first event and |
| 1506 : | * allows for a variable argument list | ||
| 1507 : | * @param string The event name | ||
| 1508 : | * @return array The result of the first function call | ||
| 1509 : | */ | ||
| 1510 : | csouza | 154 | function call( $event ) { |
| 1511 : | $args =& func_get_args(); | ||
| 1512 : | array_shift( $args ); | ||
| 1513 : | $result =& $this->_runBots($event, $args); | ||
| 1514 : | if (isset($result[0])) return $result[0]; | ||
| 1515 : | return null; | ||
| 1516 : | } | ||
| 1517 : | csouza | 129 | } |
| 1518 : | |||
| 1519 : | /** | ||
| 1520 : | * Users Table Class | ||
| 1521 : | * | ||
| 1522 : | * Provides access to the mos_templates table | ||
| 1523 : | * @package Mambo | ||
| 1524 : | */ | ||
| 1525 : | class mosUser extends mosDBTable { | ||
| 1526 : | csouza | 154 | /** @var int Unique id*/ |
| 1527 : | var $id=null; | ||
| 1528 : | /** @var string The users real name (or nickname)*/ | ||
| 1529 : | var $name=null; | ||
| 1530 : | /** @var string The login name*/ | ||
| 1531 : | var $username=null; | ||
| 1532 : | /** @var string email*/ | ||
| 1533 : | var $email=null; | ||
| 1534 : | /** @var string MD5 encrypted password*/ | ||
| 1535 : | var $password=null; | ||
| 1536 : | /** @var string */ | ||
| 1537 : | var $usertype=null; | ||
| 1538 : | /** @var int */ | ||
| 1539 : | var $block=null; | ||
| 1540 : | /** @var int */ | ||
| 1541 : | var $sendEmail=null; | ||
| 1542 : | /** @var int The group id number */ | ||
| 1543 : | var $gid=null; | ||
| 1544 : | counterpoi | 419 | t /** @var int Group number from ACL */ |
| 1545 : | t var $grp=null; | ||
| 1546 : | csouza | 154 | /** @var datetime */ |
| 1547 : | var $registerDate=null; | ||
| 1548 : | /** @var datetime */ | ||
| 1549 : | var $lastvisitDate=null; | ||
| 1550 : | /** @var string activation hash*/ | ||
| 1551 : | var $activation=null; | ||
| 1552 : | /** @var string */ | ||
| 1553 : | var $params=null; | ||
| 1554 : | csouza | 129 | |
| 1555 : | csouza | 154 | /** |
| 1556 : | csouza | 129 | * @param database A database connector object |
| 1557 : | */ | ||
| 1558 : | counterpoi | 319 | t function mosUser() { |
| 1559 : | counterpoi | 238 | t $database =& mamboDatabase::getInstance(); |
| 1560 : | csouza | 154 | $this->mosDBTable( '#__users', 'id', $database ); |
| 1561 : | } | ||
| 1562 : | csouza | 129 | |
| 1563 : | csouza | 154 | /** |
| 1564 : | counterpoi | 419 | t * Return true if this user is an administrator, false otherwise |
| 1565 : | t */ | ||
| 1566 : | t function isAdmin() { | ||
| 1567 : | t return ( strtolower( $this->usertype ) == 'superadministrator' || strtolower( $this->usertype ) == 'super administrator' || $this->grp == 16 ) ? true : false; | ||
| 1568 : | t } | ||
| 1569 : | t | ||
| 1570 : | t /** | ||
| 1571 : | csouza | 129 | * Fill a user object with information from the current session |
| 1572 : | */ | ||
| 1573 : | csouza | 154 | function getSessionData() { |
| 1574 : | counterpoi | 238 | t $session =& mosSession::getCurrent(); |
| 1575 : | csouza | 154 | $this->id = intval( $session->userid ); |
| 1576 : | $this->username = $session->username; | ||
| 1577 : | $this->usertype = $session->usertype; | ||
| 1578 : | counterpoi | 419 | t $this->gid = intval ($session->gid); |
| 1579 : | csouza | 154 | } |
| 1580 : | counterpoi | 419 | t |
| 1581 : | t function getSession () { | ||
| 1582 : | t $this->id = mosGetParam( $_SESSION, 'session_user_id', 0 ); | ||
| 1583 : | t $this->username = mosGetParam( $_SESSION, 'session_username', '' ); | ||
| 1584 : | t $this->usertype = mosGetParam( $_SESSION, 'session_usertype', '' ); | ||
| 1585 : | t $this->gid = mosGetParam( $_SESSION, 'session_gid', 0 ); | ||
| 1586 : | t $this->grp = mosGetParam( $_SESSION, 'session_grp', 0); | ||
| 1587 : | t } | ||
| 1588 : | csouza | 154 | /** |
| 1589 : | csouza | 129 | * Validation and filtering |
| 1590 : | * @return boolean True is satisfactory | ||
| 1591 : | */ | ||
| 1592 : | csouza | 154 | function check() { |
| 1593 : | $this->_error = ''; | ||
| 1594 : | counterpoi | 199 | t if ($this->name == '') $this->_error = _REGWARN_NAME; |
| 1595 : | t elseif ($this->username == '') $this->_error = _REGWARN_UNAME; | ||
| 1596 : | t elseif (strlen($this->username) < 3 OR preg_match("/[\\<\\>\\\"\\'\\%\\;\\(\\)\\&\\+\\-]/", $this->username)) $this->_error = sprintf( _VALID_AZ09, _PROMPT_UNAME, 2 ); | ||
| 1597 : | t elseif (($this->email == '') OR preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $this->email ) == 0) $this->_error = _REGWARN_MAIL; | ||
| 1598 : | csouza | 154 | else { |
| 1599 : | // check for existing username | ||
| 1600 : | counterpoi | 191 | t $username = strtolower($this->username); |
| 1601 : | csouza | 154 | $this->_db->setQuery( "SELECT COUNT(id) FROM #__users " |
| 1602 : | counterpoi | 191 | t . "\nWHERE LOWER(username)='$username' AND id!='$this->id'" |
| 1603 : | csouza | 154 | ); |
| 1604 : | counterpoi | 199 | t if ($this->_db->loadResult()) $this->_error = _REGWARN_INUSE; |
| 1605 : | csouza | 154 | elseif (mamboCore::get('mosConfig_uniquemail')) { |
| 1606 : | // check for existing email | ||
| 1607 : | $this->_db->setQuery( "SELECT COUNT(id) FROM #__users " | ||
| 1608 : | . "\nWHERE email='$this->email' AND id!='$this->id'" | ||
| 1609 : | ); | ||
| 1610 : | counterpoi | 199 | t if ($this->_db->loadResult()) $this->_error = _REGWARN_EMAIL_INUSE; |
| 1611 : | csouza | 154 | } |
| 1612 : | } | ||
| 1613 : | if ($this->_error) return false; | ||
| 1614 : | return true; | ||
| 1615 : | } | ||
| 1616 : | csouza | 129 | |
| 1617 : | csouza | 154 | function store( $updateNulls=false ) { |
| 1618 : | counterpoi | 192 | t global $acl, $migrate; |
| 1619 : | csouza | 252 | $section_value = 'users'; |
| 1620 : | counterpoi | 192 | t if( $this->id AND !$migrate) { |
| 1621 : | csouza | 252 | // update existing record |
| 1622 : | $ret = $this->_db->updateObject( $this->_tbl, $this, 'id', $updateNulls ); | ||
| 1623 : | // syncronise ACL | ||
| 1624 : | // single group handled at the moment | ||
| 1625 : | // trivial to expand to multiple groups | ||
| 1626 : | $groups = $acl->get_object_groups( $section_value, $this->id, 'ARO' ); | ||
| 1627 : | $acl->del_group_object( $groups[0], $section_value, $this->id, 'ARO' ); | ||
| 1628 : | $acl->add_group_object( $this->gid, $section_value, $this->id, 'ARO' ); | ||
| 1629 : | $object_id = $acl->get_object_id( $section_value, $this->id, 'ARO' ); | ||
| 1630 : | $acl->edit_object( $object_id, $section_value, $this->_db->getEscaped( $this->name ), $this->id, 0, 0, 'ARO' ); | ||
| 1631 : | } | ||
| 1632 : | counterpoi | 192 | t else { |
| 1633 : | csouza | 252 | // new record |
| 1634 : | $ret = $this->_db->insertObject( $this->_tbl, $this, 'id' ); | ||
| 1635 : | // syncronise ACL | ||
| 1636 : | $acl->add_object( $section_value, $this->_db->getEscaped( $this->name ), $this->id, null, null, 'ARO' ); | ||
| 1637 : | $acl->add_group_object( $this->gid, $section_value, $this->id, 'ARO' ); | ||
| 1638 : | } | ||
| 1639 : | csouza | 154 | if ($ret) return true; |
| 1640 : | $this->_error = "mosUser::store failed <br />" . $this->_db->getErrorMsg(); | ||
| 1641 : | return false; | ||
| 1642 : | } | ||
| 1643 : | csouza | 129 | |
| 1644 : | csouza | 154 | function delete($oid=null) { |
| 1645 : | csouza | 403 | global $acl; |
| 1646 : | $k = $this->_tbl_key; | ||
| 1647 : | csouza | 154 | if ($oid) $this->id = intval( $oid ); |
| 1648 : | $aro_id = $acl->get_object_id( 'users', $this->$k, 'ARO' ); | ||
| 1649 : | $acl->del_object( $aro_id, 'ARO', true ); | ||
| 1650 : | // $authoriser = mosAuthorisationAdmin::getInstance(); | ||
| 1651 : | // $authoriser->dropAccess('mosUser', $this->id); | ||
| 1652 : | $this->_error = ''; | ||
| 1653 : | $this->_db->setQuery( "DELETE FROM $this->_tbl WHERE id = '".$this->id."'" ); | ||
| 1654 : | if ($this->_db->query()) { | ||
| 1655 : | // cleanup related data | ||
| 1656 : | csouza | 129 | |
| 1657 : | csouza | 154 | // :: private messaging |
| 1658 : | $this->_db->setQuery( "DELETE FROM #__messages_cfg WHERE user_id='".$this->id."'" ); | ||
| 1659 : | if (!$this->_db->query()) $this->_error = $this->_db->getErrorMsg(); | ||
| 1660 : | else { | ||
| 1661 : | $this->_db->setQuery( "DELETE FROM #__messages WHERE user_id_to='".$this->$k."'" ); | ||
| 1662 : | if (!$this->_db->query()) $this->_error = $this->_db->getErrorMsg(); | ||
| 1663 : | } | ||
| 1664 : | } else $this->_error = $this->_db->getErrorMsg(); | ||
| 1665 : | if ($this->_error) return false; | ||
| 1666 : | return true; | ||
| 1667 : | } | ||
| 1668 : | csouza | 129 | } |
| 1669 : | |||
| 1670 : | /** | ||
| 1671 : | counterpoi | 209 | t * User login details class |
| 1672 : | t * @package Mambo | ||
| 1673 : | t */ | ||
| 1674 : | t class mosLoginDetails { | ||
| 1675 : | csouza | 252 | var $_user = ''; |
| 1676 : | var $_password = ''; | ||
| 1677 : | var $_remember = ''; | ||
| 1678 : | counterpoi | 209 | t |
| 1679 : | csouza | 252 | function mosLoginDetails ($user, $password='', $remember='') { |
| 1680 : | $this->_user = $user; | ||
| 1681 : | $this->_password = $password; | ||
| 1682 : | $this->_remember = $remember; | ||
| 1683 : | } | ||
| 1684 : | counterpoi | 209 | t |
| 1685 : | csouza | 252 | function getUser () { |
| 1686 : | return $this->_user; | ||
| 1687 : | } | ||
| 1688 : | counterpoi | 209 | t |
| 1689 : | csouza | 252 | function getPassword () { |
| 1690 : | return $this->_password; | ||
| 1691 : | } | ||
| 1692 : | counterpoi | 209 | t |
| 1693 : | csouza | 252 | function getRemember () { |
| 1694 : | return $this->_remember; | ||
| 1695 : | } | ||
| 1696 : | counterpoi | 209 | t |
| 1697 : | t } | ||
| 1698 : | t /** | ||
| 1699 : | csouza | 129 | * Mambo Mainframe class |
| 1700 : | * | ||
| 1701 : | * Provide many supporting API functions | ||
| 1702 : | * @package Mambo | ||
| 1703 : | */ | ||
| 1704 : | class mosMainFrame { | ||
| 1705 : | csouza | 154 | /** @var database Internal database class pointer */ |
| 1706 : | var $_db=null; | ||
| 1707 : | /** @var object A default option (e.g. component) */ | ||
| 1708 : | var $_option=null; | ||
| 1709 : | /** @var string The current template */ | ||
| 1710 : | var $_template=null; | ||
| 1711 : | /** @var array An array to hold global user state within a session */ | ||
| 1712 : | var $_userstate=null; | ||
| 1713 : | /** @var array An array of page meta information */ | ||
| 1714 : | var $_head=null; | ||
| 1715 : | /** @var string Custom html string to append to the pathway */ | ||
| 1716 : | var $_custom_pathway=array(); | ||
| 1717 : | csouza | 129 | |
| 1718 : | csouza | 154 | /** |
| 1719 : | csouza | 129 | * Class constructor |
| 1720 : | * @param database A database connection object | ||
| 1721 : | * @param string The url option | ||
| 1722 : | * @param string The path of the mos directory | ||
| 1723 : | */ | ||
| 1724 : | csouza | 154 | function mosMainFrame( &$db, $option, $basePath, $isAdmin=false ) { |
| 1725 : | $this->_db =& $db; | ||
| 1726 : | // load the configuration values | ||
| 1727 : | //return( $this->loadConfig() ); | ||
| 1728 : | $this->_setTemplate($isAdmin); | ||
| 1729 : | if (substr($option,0,4) != 'com_') $this->_option = "com_$option"; | ||
| 1730 : | else $this->_option = $option; | ||
| 1731 : | if (isset( $_SESSION['session_userstate'] )) $this->_userstate =& $_SESSION['session_userstate']; | ||
| 1732 : | else $this->_userstate = null; | ||
| 1733 : | $this->_head['title'] = $GLOBALS['mosConfig_sitename']; | ||
| 1734 : | $this->_head['meta'] = array(); | ||
| 1735 : | $this->_head['custom'] = array(); | ||
| 1736 : | mosMainFrame::getInstance($this); | ||
| 1737 : | } | ||
| 1738 : | csouza | 252 | |
| 1739 : | counterpoi | 218 | t /** |
| 1740 : | t * Get the current user - deprecated - use mamboCore instead | ||
| 1741 : | t */ | ||
| 1742 : | t function getUser() { | ||
| 1743 : | csouza | 252 | return mamboCore::get('currentUser'); |
| 1744 : | counterpoi | 218 | t } |
| 1745 : | counterpoi | 223 | t /** |
| 1746 : | t * Logout the current user - deprecated - use the code here directly | ||
| 1747 : | t */ | ||
| 1748 : | t function logout() { | ||
| 1749 : | t require_once(mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php'); | ||
| 1750 : | counterpoi | 238 | t $authenticator =& mamboAuthenticator::getInstance(); |
| 1751 : | counterpoi | 223 | t $authenticator->logoutUser(); |
| 1752 : | t } | ||
| 1753 : | t /** | ||
| 1754 : | t * Login a user given name and password - deprecated - use the code here directly | ||
| 1755 : | t */ | ||
| 1756 : | t function login ($username=null,$passwd=null) { | ||
| 1757 : | t require_once(mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php'); | ||
| 1758 : | counterpoi | 238 | t $authenticator =& mamboAuthenticator::getInstance(); |
| 1759 : | counterpoi | 223 | t return $authenticator->loginUser($username, $passwd); |
| 1760 : | t } | ||
| 1761 : | csouza | 129 | |
| 1762 : | csouza | 154 | /** |
| 1763 : | csouza | 129 | * Singleton get instance |
| 1764 : | * @param object the mainframe instance (if called internally) | ||
| 1765 : | * Note that because of the need for creation parameters, this cannot | ||
| 1766 : | * be called successfully unless the mainframe object is already created | ||
| 1767 : | */ | ||
| 1768 : | csouza | 154 | function &getInstance () { |
| 1769 : | static $mainframe; | ||
| 1770 : | if (func_num_args()) { | ||
| 1771 : | $args = func_get_args(); | ||
| 1772 : | $mainframe = $args[0]; | ||
| 1773 : | } | ||
| 1774 : | if (isset($mainframe)) $result =& $mainframe; | ||
| 1775 : | else $result = null; | ||
| 1776 : | return $result; | ||
| 1777 : | } | ||
| 1778 : | /** | ||
| 1779 : | csouza | 129 | * @param string |
| 1780 : | */ | ||
| 1781 : | csouza | 154 | function setPageTitle( $title=null ) { |
| 1782 : | if (mamboCore::get('mosConfig_pagetitles')) { | ||
| 1783 : | $title = trim(htmlspecialchars($title)); | ||
| 1784 : | $base = mamboCore::get('mosConfig_sitename'); | ||
| 1785 : | $this->_head['title'] = $title ? $title.' - '.$base : $base; | ||
| 1786 : | } | ||
| 1787 : | } | ||
| 1788 : | /** | ||
| 1789 : | csouza | 129 | * @return string |
| 1790 : | */ | ||
| 1791 : | csouza | 154 | function getPageTitle() { |
| 1792 : | return $this->_head['title']; | ||
| 1793 : | } | ||
| 1794 : | csouza | 129 | |
| 1795 : | csouza | 154 | /** |
| 1796 : | csouza | 129 | * @param string The value of the name attibute |
| 1797 : | * @param string The value of the content attibute | ||
| 1798 : | * @param string Text to display before the tag | ||
| 1799 : | * @param string Text to display after the tag | ||
| 1800 : | */ | ||
| 1801 : | csouza | 154 | function addMetaTag( $name, $content, $prepend='', $append='' ) { |
| 1802 : | list($name, $content) = $this->_tidyMetaData($name, $content); | ||
| 1803 : | $prepend = trim($prepend); | ||
| 1804 : | $append = trim($append); | ||
| 1805 : | $this->_head['meta'][$name] = array($content, $prepend, $append); | ||
| 1806 : | } | ||
| 1807 : | /** | ||
| 1808 : | csouza | 129 | * @param string The value of the name attibute |
| 1809 : | */ | ||
| 1810 : | csouza | 154 | function _getMetaTag ($name) { |
| 1811 : | return isset($this->_head['meta'][$name]) ? $this->_head['meta'][$name] : array('', '', ''); | ||
| 1812 : | } | ||
| 1813 : | /** | ||
| 1814 : | csouza | 129 | * @param string The value of the name attibute |
| 1815 : | * @param string The value of the content attibute to append to the existing | ||
| 1816 : | */ | ||
| 1817 : | csouza | 154 | function _tidyMetaData($name, $content) { |
| 1818 : | $result[] = trim(htmlspecialchars($name)); | ||
| 1819 : | $result[] = trim(htmlspecialchars($content)); | ||
| 1820 : | return $result; | ||
| 1821 : | } | ||
| 1822 : | /** | ||
| 1823 : | csouza | 129 | * @param string The value of the name attibute |
| 1824 : | * @param string The value of the content attibute to append to the existing | ||
| 1825 : | * Tags ordered in with Site Keywords and Description first | ||
| 1826 : | */ | ||
| 1827 : | counterpoi | 243 | t function appendMetaTag( $name, $content, $ifEmpty=false ) { |
| 1828 : | csouza | 154 | list($name, $content) = $this->_tidyMetaData($name, $content); |
| 1829 : | $tag = $this->_getMetaTag($name); | ||
| 1830 : | counterpoi | 243 | t if ($tag[0] AND $ifEmpty) return; |
| 1831 : | csouza | 154 | if ($tag[0] AND $content) $content .= ', '; |
| 1832 : | $tag[0] = $content.$tag[0]; | ||
| 1833 : | $this->_head['meta'][$name] = $tag; | ||
| 1834 : | } | ||
| 1835 : | csouza | 129 | |
| 1836 : | csouza | 154 | /** |
| 1837 : | csouza | 129 | * @param string The value of the name attibute |
| 1838 : | * @param string The value of the content attibute to append to the existing | ||
| 1839 : | */ | ||
| 1840 : | csouza | 154 | function prependMetaTag( $name, $content ) { |
| 1841 : | list($name, $content) = $this->_tidyMetaData($name, $content); | ||
| 1842 : | $tag = $this->_getMetaTag($name); | ||
| 1843 : | $tag[0] = $content.$tag[0]; | ||
| 1844 : | $this->_head['meta'][$name] = $tag; | ||
| 1845 : | } | ||
| 1846 : | /** | ||
| 1847 : | csouza | 129 | * Adds a custom html string to the head block |
| 1848 : | * @param string The html to add to the head | ||
| 1849 : | */ | ||
| 1850 : | csouza | 154 | function addCustomHeadTag( $html ) { |
| 1851 : | $this->_head['custom'][] = trim( $html ); | ||
| 1852 : | } | ||
| 1853 : | /** | ||
| 1854 : | csouza | 129 | * @return string |
| 1855 : | */ | ||
| 1856 : | csouza | 154 | function getHead() { |
| 1857 : | $head[] = '<title>'.$this->_head['title'].'</title>'; | ||
| 1858 : | foreach ($this->_head['meta'] as $name=>$meta) { | ||
| 1859 : | if ($meta[1]) $head[] = $meta[1]; | ||
| 1860 : | $head[] = '<meta name="' . $name . '" content="' . $meta[0] . '" />'; | ||
| 1861 : | if ($meta[2]) $head[] = $meta[2]; | ||
| 1862 : | } | ||
| 1863 : | foreach ($this->_head['custom'] as $html) $head[] = $html; | ||
| 1864 : | return implode( "\n", $head )."\n"; | ||
| 1865 : | } | ||
| 1866 : | /** | ||
| 1867 : | csouza | 129 | * @return string |
| 1868 : | */ | ||
| 1869 : | csouza | 154 | function getCustomPathWay() { |
| 1870 : | return $this->_custom_pathway; | ||
| 1871 : | } | ||
| 1872 : | csouza | 129 | |
| 1873 : | csouza | 154 | function appendPathWay($html) { |
| 1874 : | $this->_custom_pathway[] = $html; | ||
| 1875 : | } | ||
| 1876 : | csouza | 129 | |
| 1877 : | csouza | 154 | /** |
| 1878 : | csouza | 129 | * Gets the value of a user state variable |
| 1879 : | * @param string The name of the variable | ||
| 1880 : | */ | ||
| 1881 : | csouza | 154 | function getUserState( $var_name ) { |
| 1882 : | return is_array($this->_userstate) ? mosGetParam($this->_userstate, $var_name, null) : null; | ||
| 1883 : | } | ||
| 1884 : | /** | ||
| 1885 : | csouza | 129 | * Sets the value of a user state variable |
| 1886 : | * @param string The name of the variable | ||
| 1887 : | * @param string The value of the variable | ||
| 1888 : | */ | ||
| 1889 : | csouza | 154 | function setUserState( $var_name, $var_value ) { |
| 1890 : | if (is_array( $this->_userstate )) $this->_userstate[$var_name] = $var_value; | ||
| 1891 : | } | ||
| 1892 : | /** | ||
| 1893 : | csouza | 129 | * Gets the value of a user state variable |
| 1894 : | * @param string The name of the user state variable | ||
| 1895 : | * @param string The name of the variable passed in a request | ||
| 1896 : | * @param string The default value for the variable if not found | ||
| 1897 : | */ | ||
| 1898 : | csouza | 154 | function getUserStateFromRequest( $var_name, $req_name, $var_default=null ) { |
| 1899 : | if (isset($_REQUEST[$req_name])) $this->setUserState($var_name, $_REQUEST[$req_name]); | ||
| 1900 : | elseif (isset($var_default) AND !isset($this->userstate[$var_name])) $this->setUserState($var_name, $var_default); | ||
| 1901 : | return $this->getUserState($var_name); | ||
| 1902 : | } | ||
| 1903 : | /** | ||
| 1904 : | csouza | 129 | * Initialises the user session |
| 1905 : | * | ||
| 1906 : | * Old sessions are flushed based on the configuration value for the cookie | ||
| 1907 : | * lifetime. If an existing session, then the last access time is updated. | ||
| 1908 : | * If a new session, a session id is generated and a record is created in | ||
| 1909 : | * the mos_sessions table. | ||
| 1910 : | */ | ||
| 1911 : | csouza | 154 | function &initSession() { |
| 1912 : | $session =& mosSession::getCurrent(); | ||
| 1913 : | return $session; | ||
| 1914 : | } | ||
| 1915 : | csouza | 129 | |
| 1916 : | csouza | 154 | /** |
| 1917 : | csouza | 129 | * @param string The name of the variable (from configuration.php) |
| 1918 : | * @return mixed The value of the configuration variable or null if not found | ||
| 1919 : | */ | ||
| 1920 : | csouza | 154 | function getCfg( $varname ) { |
| 1921 : | return mamboCore::get('mosConfig_'.$varname); | ||
| 1922 : | } | ||
| 1923 : | csouza | 129 | |
| 1924 : | csouza | 154 | function _setTemplate( $isAdmin=false ) { |
| 1925 : | global $Itemid; | ||
| 1926 : | $cur_template = ''; | ||
| 1927 : | $sql = "SELECT template, client_id, menuid FROM #__templates_menu WHERE (client_id=0 or client_id=1)"; | ||
| 1928 : | if (isset($Itemid) AND $Itemid) $sql .= " AND (menuid=0 OR menuid=$Itemid)"; | ||
| 1929 : | else $sql .= " AND menuid=0"; | ||
| 1930 : | $sql .= " ORDER BY client_id, menuid"; | ||
| 1931 : | $this->_db->setQuery($sql); | ||
| 1932 : | $templates = $this->_db->loadObjectList(); | ||
| 1933 : | foreach ($templates as $template) { | ||
| 1934 : | if ($template->client_id == 1) { | ||
| 1935 : | if ($isAdmin) $cur_template = $template->template; | ||
| 1936 : | } | ||
| 1937 : | else $cur_template = $template->template; | ||
| 1938 : | } | ||
| 1939 : | if ($isAdmin) { | ||
| 1940 : | $path = mamboCore::get('mosConfig_absolute_path')."/administrator/templates/$cur_template/index.php"; | ||
| 1941 : | if (!file_exists( $path )) $cur_template = 'mambo_admin'; | ||
| 1942 : | } | ||
| 1943 : | else { | ||
| 1944 : | // TemplateChooser Start | ||
| 1945 : | $mos_user_template = mosGetParam( $_COOKIE, 'mos_user_template', '' ); | ||
| 1946 : | $mos_change_template = mosGetParam( $_REQUEST, 'mos_change_template', $mos_user_template ); | ||
| 1947 : | if ($mos_change_template) { | ||
| 1948 : | // check that template exists in case it was deleted | ||
| 1949 : | $path = mamboCore::get('mosConfig_absolute_path')."/templates/$mos_change_template/index.php"; | ||
| 1950 : | counterpoi | 234 | t if (strpos($mos_change_template,'..') == false AND strpos($mos_change_template,':') == false AND file_exists($path)) { |
| 1951 : | csouza | 154 | $lifetime = 60*10; |
| 1952 : | $cur_template = $mos_change_template; | ||
| 1953 : | setcookie( "mos_user_template", "$mos_change_template", time()+$lifetime); | ||
| 1954 : | } else setcookie( "mos_user_template", "", time()-3600 ); | ||
| 1955 : | } | ||
| 1956 : | // TemplateChooser End | ||
| 1957 : | } | ||
| 1958 : | $this->_template = $cur_template; | ||
| 1959 : | } | ||
| 1960 : | csouza | 129 | |
| 1961 : | csouza | 154 | function getTemplate() { |
| 1962 : | return $this->_template; | ||
| 1963 : | } | ||
| 1964 : | csouza | 129 | |
| 1965 : | csouza | 154 | /** |
| 1966 : | csouza | 129 | * Checks to see if an image exists in the current templates image directory |
| 1967 : | * if it does it loads this image. Otherwise the default image is loaded. | ||
| 1968 : | * Also can be used in conjunction with the menulist param to create the chosen image | ||
| 1969 : | * load the default or use no image | ||
| 1970 : | */ | ||
| 1971 : | csouza | 154 | function ImageCheck( $file, $directory='/images/M_images/', $param=NULL, $param_directory='/images/M_images/', $alt=NULL, $name='image', $type=1, $align='middle' ) { |
| 1972 : | $basepath = mamboCore::get('mosConfig_live_site'); | ||
| 1973 : | if ($param) $image = $basepath.$param_directory.$param; | ||
| 1974 : | else { | ||
| 1975 : | $endpath = '/templates/'.$this->getTemplate().'/images/'.$file; | ||
| 1976 : | if (file_exists(mamboCore::get('mosConfig_absolute_path').$endpath)) $image = $basepath.$endpath; | ||
| 1977 : | else $image = $basepath.$directory.$file; // outputs only path to image | ||
| 1978 : | } | ||
| 1979 : | // outputs actual html <img> tag | ||
| 1980 : | if ($type) $image = '<img src="'. $image .'" alt="'. $alt .'" align="'. $align .'" name="'. $name .'" border="0" />'; | ||
| 1981 : | return $image; | ||
| 1982 : | } | ||
| 1983 : | csouza | 129 | |
| 1984 : | csouza | 154 | /** |
| 1985 : | csouza | 129 | * Returns the first to be found of one or more files, or null |
| 1986 : | * | ||
| 1987 : | */ | ||
| 1988 : | csouza | 154 | function tryFiles ($first_choice, $second_choice=null, $third_choice=null) { |
| 1989 : | csouza | 129 | if (file_exists($first_choice)) return $first_choice; |
| 1990 : | elseif ($second_choice AND file_exists($second_choice)) return $second_choice; | ||
| 1991 : | elseif ($third_choice AND file_exists($third_choice)) return $third_choice; | ||
| 1992 : | else return null; | ||
| 1993 : | csouza | 154 | } |
| 1994 : | csouza | 129 | |
| 1995 : | csouza | 154 | /** |
| 1996 : | csouza | 129 | * Returns a standard path variable |
| 1997 : | * | ||
| 1998 : | */ | ||
| 1999 : | csouza | 154 | function getPath( $varname, $option='' ) { |
| 2000 : | $base = mamboCore::get('mosConfig_absolute_path'); | ||
| 2001 : | $origoption = $option; | ||
| 2002 : | if (!$option) $option = $this->_option; | ||
| 2003 : | $name = substr($option,4); | ||
| 2004 : | $bac_admin = "$base/administrator/components/com_admin/"; | ||
| 2005 : | $baco = "$base/administrator/components/$option/"; | ||
| 2006 : | $bttc = "$base/templates/$this->_template/components/"; | ||
| 2007 : | $bco = "$base/components/$option/"; | ||
| 2008 : | $bai = "$base/administrator/includes/"; | ||
| 2009 : | $bi = "$base/includes/"; | ||
| 2010 : | csouza | 129 | |
| 2011 : | csouza | 154 | switch ($varname) { |
| 2012 : | case 'front': return $this->tryFiles ($bco."$name.php"); | ||
| 2013 : | case 'front_html': return $this->tryFiles ($bttc."$name.html.php", $bco."$name.html.php"); | ||
| 2014 : | case 'admin': return $this->tryFiles ($baco."admin.$name.php", $bac_admin.'admin.admin.php'); | ||
| 2015 : | case 'admin_html': return $this->tryFiles ($baco."admin.$name.html.php", $bac_admin.'admin.admin.html.php'); | ||
| 2016 : | case 'toolbar': return $this->tryFiles ($baco."toolbar.$name.php"); | ||
| 2017 : | case 'toolbar_html': return $this->tryFiles ($baco."toolbar.$name.html.php"); | ||
| 2018 : | case 'toolbar_default': return $this->tryFiles ($bai.'toolbar.html.php'); | ||
| 2019 : | case 'class': return $this->tryFiles ($bco."$name.class.php", $baco."$name.class.php", $bi."$name.php"); | ||
| 2020 : | case 'com_xml': return $this->tryFiles ($baco."$name.xml", $bco."$name.xml"); | ||
| 2021 : | case 'mod0_xml': | ||
| 2022 : | if ($origoption) $path = $base."/modules/$option.xml"; | ||
| 2023 : | else $path = $base.'/modules/custom.xml'; | ||
| 2024 : | return $this->tryFiles ($path); | ||
| 2025 : | case 'mod1_xml': | ||
| 2026 : | if ($origoption) $path = $base."/administrator/modules/$option.xml"; | ||
| 2027 : | else $path = $base.'/administrator/modules/custom.xml'; | ||
| 2028 : | return $this->tryFiles ($path); | ||
| 2029 : | case 'bot_xml': return $this->tryFiles ($base."/mambots/$option.xml"); | ||
| 2030 : | case 'menu_xml': return $this->tryFiles ($base."/administrator/components/com_menus/$option/$option.xml"); | ||
| 2031 : | case 'installer_html': return $this->tryFiles($base."/administrator/components/com_installer/$option/$option.html.php"); | ||
| 2032 : | case 'installer_class': return $this->tryFiles($base."/administrator/components/com_installer/$option/$option.class.php"); | ||
| 2033 : | } | ||
| 2034 : | } | ||
| 2035 : | csouza | 129 | |
| 2036 : | csouza | 154 | /** |
| 2037 : | csouza | 129 | * Detects a 'visit' |
| 2038 : | * | ||
| 2039 : | * This function updates the agent and domain table hits for a particular | ||
| 2040 : | * visitor. The user agent is recorded/incremented if this is the first visit. | ||
| 2041 : | * A cookie is set to mark the first visit. | ||
| 2042 : | */ | ||
| 2043 : | csouza | 154 | function detect() { |
| 2044 : | if (mamboCore::get('mosConfig_enable_stats') == 1) { | ||
| 2045 : | if (mosGetParam( $_COOKIE, 'mosvisitor', 0 )) return; | ||
| 2046 : | setcookie( "mosvisitor", "1" ); | ||
| 2047 : | csouza | 129 | |
| 2048 : | csouza | 154 | $agent = $_SERVER['HTTP_USER_AGENT']; |
| 2049 : | $browser = mosGetBrowser( $agent ); | ||
| 2050 : | $os = mosGetOS( $agent ); | ||
| 2051 : | $domain = gethostbyaddr( $_SERVER['REMOTE_ADDR'] ); | ||
| 2052 : | // tease out the last element of the domain | ||
| 2053 : | $tldomain = split( "\.", $domain ); | ||
| 2054 : | $tldomain = $tldomain[count( $tldomain )-1]; | ||
| 2055 : | if (is_numeric( $tldomain )) { | ||
| 2056 : | $tldomain = "Unknown"; | ||
| 2057 : | } | ||
| 2058 : | csouza | 129 | |
| 2059 : | csouza | 154 | $this->_db->setQuery( "SELECT count(*), type FROM #__stats_agents WHERE (agent='$browser' AND type=0) OR (agent='$os' AND type=1) OR (agent='$tldomain' AND type=2) GROUP BY type"); |
| 2060 : | $stats = $this->_db->loadObjectList(); | ||
| 2061 : | $sql['browser'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$browser',0)"; | ||
| 2062 : | $sql['os'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$os',1)"; | ||
| 2063 : | $sql['domain'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$tldomain',2)"; | ||
| 2064 : | if ($stats) foreach ($stats as $stat) { | ||
| 2065 : | if ($stat->type == 0) $sql['agents'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$browser' AND type=0"; | ||
| 2066 : | if ($stat->type == 1) $sql['os'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$os' AND type=1"; | ||
| 2067 : | if ($stat->type == 2) $sql['domain'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$tldomain' AND type=2"; | ||
| 2068 : | } | ||
| 2069 : | $this->_db->setQuery(implode('; ',$sql)); | ||
| 2070 : | $this->_db->query_batch(); | ||
| 2071 : | } | ||
| 2072 : | } | ||
| 2073 : | csouza | 129 | |
| 2074 : | csouza | 154 | /** |
| 2075 : | csouza | 129 | * @return correct Itemid for Content Item |
| 2076 : | */ | ||
| 2077 : | csouza | 154 | function getItemid ($id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1) { |
| 2078 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 2079 : | counterpoi | 238 | t $handler =& contentHandler::getInstance(); |
| 2080 : | csouza | 154 | return $handler->getItemid($id, $typed, $link, $bs, $bc, $gbs); |
| 2081 : | } | ||
| 2082 : | csouza | 129 | |
| 2083 : | csouza | 154 | function liveBookMark () { |
| 2084 : | // support for Firefox Live Bookmarks ability for site syndication | ||
| 2085 : | counterpoi | 238 | t $c_handler =& mosComponentHandler::getInstance(); |
| 2086 : | csouza | 154 | $params = $c_handler->getParamsByName('Syndicate'); |
| 2087 : | $live_bookmark = $params->get( 'live_bookmark', 0 ); | ||
| 2088 : | if ($live_bookmark) { | ||
| 2089 : | // custom bookmark file name | ||
| 2090 : | $bookmark_file = $params->get( 'bookmark_file', $live_bookmark ); | ||
| 2091 : | $link_file = mamboCore::get('mosConfig_live_site').'/cache/'. $bookmark_file; | ||
| 2092 : | $filename = mamboCore::get('mosConfig_absolute_path').'/cache/'. $bookmark_file; | ||
| 2093 : | $cache = $params->get( 'cache', 1 ); | ||
| 2094 : | $cache_time = $params->get( 'cache_time', 3600 ); | ||
| 2095 : | $title = $params->def( 'title', mamboCore::get('mosConfig_sitename') ); | ||
| 2096 : | // checks to see if cache file exists, to determine whether to create a new one | ||
| 2097 : | if ( !file_exists( $filename ) || ( ( time() - filemtime( $filename ) ) > $cache_time ) ) { | ||
| 2098 : | $task = 'live_bookmark'; | ||
| 2099 : | // sets bookmark feed type | ||
| 2100 : | $_GET['feed'] = str_replace( '.xml', '', $live_bookmark ); | ||
| 2101 : | // loads rss component to create bookmark file | ||
| 2102 : | require_once( mamboCore::get('mosConfig_absolute_path').'/components/com_rss/rss.php' ); | ||
| 2103 : | } | ||
| 2104 : | // outputs link tag for page | ||
| 2105 : | csouza | 129 | ?> |
| 2106 : | <link rel="alternate" type="application/rss+xml" title="<?php echo $title; ?>" href="<?php echo $link_file; ?>" /> | ||
| 2107 : | <?php | ||
| 2108 : | csouza | 154 | } |
| 2109 : | } | ||
| 2110 : | |||
| 2111 : | function mosShowHead () { | ||
| 2112 : | global $_VERSION; | ||
| 2113 : | $mosConfig_live_site = mamboCore::get('mosConfig_live_site'); | ||
| 2114 : | counterpoi | 243 | t $this->appendMetaTag( 'description', mamboCore::get('mosConfig_MetaDesc'), true ); |
| 2115 : | t $this->appendMetaTag( 'keywords', mamboCore::get('mosConfig_MetaKeys'), true ); | ||
| 2116 : | csouza | 154 | echo $this->getHead(); |
| 2117 : | if (mamboCore::get('mosConfig_sef')) { | ||
| 2118 : | echo "<base href=\"$mosConfig_live_site/\" />\r\n"; | ||
| 2119 : | } | ||
| 2120 : | $my = mamboCore::get('currentUser'); | ||
| 2121 : | if ( $my->id ) { | ||
| 2122 : | csouza | 129 | ?> |
| 2123 : | <script language="JavaScript1.2" src="<?php echo $mosConfig_live_site;?>/includes/js/mambojavascript.js" type="text/javascript"></script> | ||
| 2124 : | <?php | ||
| 2125 : | csouza | 154 | } |
| 2126 : | $this->liveBookMark(); | ||
| 2127 : | // outputs link tag for page | ||
| 2128 : | counterpoi | 238 | t $configuration =& mamboCore::getMamboCore(); |
| 2129 : | csouza | 129 | ?> |
| 2130 : | <link rel="shortcut icon" href="<?php echo $configuration->getFavIcon();?>" /> | ||
| 2131 : | <?php | ||
| 2132 : | csouza | 154 | } |
| 2133 : | |||
| 2134 : | csouza | 129 | } |
| 2135 : | |||
| 2136 : | /** | ||
| 2137 : | * Class to support function caching | ||
| 2138 : | * @package Mambo | ||
| 2139 : | */ | ||
| 2140 : | class mosCache { | ||
| 2141 : | csouza | 154 | /** |
| 2142 : | csouza | 129 | * @return object A function cache object |
| 2143 : | */ | ||
| 2144 : | csouza | 154 | function &getCache( $group='' ) { |
| 2145 : | $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); | ||
| 2146 : | require_once($mosConfig_absolute_path.'/includes/Cache/Lite/Function.php'); | ||
| 2147 : | $path = mamboCore::get('mosConfig_cachepath'); | ||
| 2148 : | $caching = mamboCore::get('mosConfig_caching'); | ||
| 2149 : | $time = mamboCore::get('mosConfig_cachetime'); | ||
| 2150 : | $options = array( | ||
| 2151 : | 'cacheDir' => "$path/", | ||
| 2152 : | 'caching' => $caching, | ||
| 2153 : | 'defaultGroup' => $group, | ||
| 2154 : | 'lifeTime' => $time | ||
| 2155 : | ); | ||
| 2156 : | $cache =& new Cache_Lite_Function( $options ); | ||
| 2157 : | return $cache; | ||
| 2158 : | } | ||
| 2159 : | /** | ||
| 2160 : | csouza | 129 | * Cleans the cache |
| 2161 : | */ | ||
| 2162 : | csouza | 154 | function cleanCache ($group=false) { |
| 2163 : | if (mamboCore::get('mosConfig_caching')) { | ||
| 2164 : | $cache =& mosCache::getCache( $group ); | ||
| 2165 : | $cache->clean( $group ); | ||
| 2166 : | } | ||
| 2167 : | } | ||
| 2168 : | csouza | 129 | } |
| 2169 : | |||
| 2170 : | /** | ||
| 2171 : | * Session database table class | ||
| 2172 : | * @package Mambo | ||
| 2173 : | */ | ||
| 2174 : | class mosSession extends mosDBTable { | ||
| 2175 : | csouza | 154 | /** @var int Primary key */ |
| 2176 : | var $session_id=null; | ||
| 2177 : | counterpoi | 419 | t /** @var time */ |
| 2178 : | csouza | 154 | var $time=null; |
| 2179 : | counterpoi | 419 | t /** @var int User ID */ |
| 2180 : | csouza | 154 | var $userid=0; |
| 2181 : | /** @var string */ | ||
| 2182 : | var $usertype=null; | ||
| 2183 : | /** @var string */ | ||
| 2184 : | var $username=''; | ||
| 2185 : | counterpoi | 419 | t /** @var int User group ID */ |
| 2186 : | csouza | 154 | var $gid=0; |
| 2187 : | /** @var int */ | ||
| 2188 : | var $guest=1; | ||
| 2189 : | /** @var string */ | ||
| 2190 : | var $_session_cookie=null; | ||
| 2191 : | csouza | 129 | |
| 2192 : | csouza | 154 | /** |
| 2193 : | csouza | 129 | * @param database A database connector object |
| 2194 : | */ | ||
| 2195 : | counterpoi | 319 | t function mosSession() { |
| 2196 : | counterpoi | 238 | t $database =& mamboDatabase::getInstance(); |
| 2197 : | csouza | 154 | $this->mosDBTable( '#__session', 'session_id', $database ); |
| 2198 : | $this->time = time(); | ||
| 2199 : | } | ||
| 2200 : | counterpoi | 419 | t |
| 2201 : | t function validate ($user) { | ||
| 2202 : | t // check against db record of session | ||
| 2203 : | t $session_id = mosGetParam( $_SESSION, 'session_id', '' ); | ||
| 2204 : | t $logintime = mosGetParam( $_SESSION, 'session_logintime', '' ); | ||
| 2205 : | t if ($session_id == md5( $user->id.$user->username.$user->usertype.$logintime )) { | ||
| 2206 : | t $current_time = time(); | ||
| 2207 : | t $database = mamboDatabase::getInstance(); | ||
| 2208 : | t $database->setQuery ("UPDATE #__session" | ||
| 2209 : | t . "\nSET time='$current_time'" | ||
| 2210 : | t . "\nWHERE session_id='$session_id'" | ||
| 2211 : | t . " AND username = '" . $database->getEscaped( $user->username ) . "'" | ||
| 2212 : | t . " AND userid = " . intval( $user->id ) | ||
| 2213 : | t ); | ||
| 2214 : | t if (!$result = $database->query()) echo $database->stderr(); | ||
| 2215 : | t elseif ($database->getAffectedRows() == 1) return true; | ||
| 2216 : | t } | ||
| 2217 : | t return false; | ||
| 2218 : | t } | ||
| 2219 : | csouza | 129 | |
| 2220 : | csouza | 154 | function &getCurrent () { |
| 2221 : | static $currentSession; | ||
| 2222 : | if (!is_object($currentSession)) { | ||
| 2223 : | counterpoi | 319 | t $currentSession = new mosSession(); |
| 2224 : | counterpoi | 320 | t mosSession::purge(); |
| 2225 : | csouza | 154 | $sessionCookieName = md5('site'.mamboCore::get('mosConfig_live_site')); |
| 2226 : | $sessioncookie = mosGetParam($_COOKIE, $sessionCookieName, null); | ||
| 2227 : | $usercookie = mosGetParam($_COOKIE, 'usercookie', null); | ||
| 2228 : | if ($currentSession->load(md5($sessioncookie.$_SERVER['REMOTE_ADDR']))) { | ||
| 2229 : | // Session cookie exists, update time in session table | ||
| 2230 : | $currentSession->time = time(); | ||
| 2231 : | $currentSession->update(); | ||
| 2232 : | } else { | ||
| 2233 : | $currentSession->generateId(); | ||
| 2234 : | if (!$currentSession->insert()) { | ||
| 2235 : | die( $currentSession->getError() ); | ||
| 2236 : | } | ||
| 2237 : | setcookie( $sessionCookieName, $currentSession->getCookie(), time() + 43200, '/' ); | ||
| 2238 : | //$_COOKIE["sessioncookie"] = $session->getCookie(); | ||
| 2239 : | if ($usercookie) { | ||
| 2240 : | // Remember me cookie exists. Login with usercookie info. | ||
| 2241 : | counterpoi | 207 | t require_once (mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php'); |
| 2242 : | counterpoi | 238 | t $authenticator =& mamboAuthenticator::getInstance(); |
| 2243 : | csouza | 154 | $authenticator->authenticateUser ($message, $usercookie['username'], $usercookie['password'], null, $currentSession); |
| 2244 : | } | ||
| 2245 : | } | ||
| 2246 : | } | ||
| 2247 : | return $currentSession; | ||
| 2248 : | } | ||
| 2249 : | csouza | 129 | |
| 2250 : | csouza | 154 | function insert() { |
| 2251 : | $ret = $this->_db->insertObject( $this->_tbl, $this ); | ||
| 2252 : | csouza | 129 | |
| 2253 : | csouza | 154 | if( !$ret ) { |
| 2254 : | $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->stderr(); | ||
| 2255 : | return false; | ||
| 2256 : | } else { | ||
| 2257 : | return true; | ||
| 2258 : | } | ||
| 2259 : | } | ||
| 2260 : | csouza | 129 | |
| 2261 : | csouza | 154 | function update( $updateNulls=false ) { |
| 2262 : | $ret = $this->_db->updateObject( $this->_tbl, $this, 'session_id', $updateNulls ); | ||
| 2263 : | csouza | 129 | |
| 2264 : | csouza | 154 | if( !$ret ) { |
| 2265 : | $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->stderr(); | ||
| 2266 : | return false; | ||
| 2267 : | } else { | ||
| 2268 : | return true; | ||
| 2269 : | } | ||
| 2270 : | } | ||
| 2271 : | csouza | 129 | |
| 2272 : | csouza | 154 | function generateId() { |
| 2273 : | $failsafe = 20; | ||
| 2274 : | $randnum = 0; | ||
| 2275 : | while ($failsafe--) { | ||
| 2276 : | $randnum = md5( uniqid( microtime(), 1 ) ); | ||
| 2277 : | if ($randnum != "") { | ||
| 2278 : | $cryptrandnum = md5( $randnum ); | ||
| 2279 : | $this->_db->setQuery( "SELECT $this->_tbl_key FROM $this->_tbl WHERE $this->_tbl_key=MD5('$randnum')" ); | ||
| 2280 : | counterpoi | 319 | t if(!($result = $this->_db->query())) { |
| 2281 : | csouza | 154 | die( $this->_db->stderr( true )); |
| 2282 : | // todo: handle gracefully | ||
| 2283 : | } | ||
| 2284 : | if ($this->_db->getNumRows($result) == 0) { | ||
| 2285 : | break; | ||
| 2286 : | } | ||
| 2287 : | } | ||
| 2288 : | } | ||
| 2289 : | $this->_session_cookie = $randnum; | ||
| 2290 : | $this->session_id = md5( $randnum . $_SERVER['REMOTE_ADDR'] ); | ||
| 2291 : | } | ||
| 2292 : | csouza | 129 | |
| 2293 : | csouza | 154 | function getCookie() { |
| 2294 : | return $this->_session_cookie; | ||
| 2295 : | } | ||
| 2296 : | csouza | 129 | |
| 2297 : | counterpoi | 320 | t function purge () { |
| 2298 : | t $past = time() - intval(mamboCore::get('mosConfig_lifetime')); | ||
| 2299 : | csouza | 403 | $adminpast = time() - 3600; |
| 2300 : | counterpoi | 320 | t $database = mamboDatabase::getInstance(); |
| 2301 : | counterpoi | 321 | t $database->setQuery("DELETE FROM #__session WHERE (time<$past AND guest>=0) OR (time<$adminpast AND guest<0)"); |
| 2302 : | counterpoi | 320 | t return $database->query(); |
| 2303 : | t } | ||
| 2304 : | csouza | 129 | |
| 2305 : | } | ||
| 2306 : | |||
| 2307 : | /** | ||
| 2308 : | * Parameters handler | ||
| 2309 : | * @package Mambo | ||
| 2310 : | */ | ||
| 2311 : | class mosParameters { | ||
| 2312 : | csouza | 154 | /** @var object */ |
| 2313 : | var $_params = null; | ||
| 2314 : | /** @var string The raw params string */ | ||
| 2315 : | var $_raw = null; | ||
| 2316 : | /** | ||
| 2317 : | csouza | 129 | * Constructor |
| 2318 : | * @param string The raw parms text | ||
| 2319 : | * @param string Path to the xml setup file | ||
| 2320 : | * @var string The type of setup file | ||
| 2321 : | */ | ||
| 2322 : | csouza | 154 | function mosParameters( $text, $process_sections = false) { |
| 2323 : | $this->_params = $this->parse( $text, $process_sections ); | ||
| 2324 : | $this->_raw = $text; | ||
| 2325 : | } | ||
| 2326 : | /** | ||
| 2327 : | csouza | 138 | * Get the result of parsing the string provided on creation |
| 2328 : | * @return string parsed result | ||
| 2329 : | */ | ||
| 2330 : | csouza | 154 | function getParams () { |
| 2331 : | return $this->_params; | ||
| 2332 : | } | ||
| 2333 : | /** | ||
| 2334 : | csouza | 129 | * @param string The name of the param |
| 2335 : | * @param string The value of the parameter | ||
| 2336 : | * @return string The set value | ||
| 2337 : | */ | ||
| 2338 : | csouza | 154 | function set( $key, $value='' ) { |
| 2339 : | $this->_params->$key = $value; | ||
| 2340 : | return $value; | ||
| 2341 : | } | ||
| 2342 : | /** | ||
| 2343 : | csouza | 129 | * Sets a default value if not alreay assigned |
| 2344 : | * @param string The name of the param | ||
| 2345 : | * @param string The value of the parameter | ||
| 2346 : | * @return string The set value | ||
| 2347 : | */ | ||
| 2348 : | csouza | 154 | function def( $key, $value='' ) { |
| 2349 : | return $this->set( $key, $this->get( $key, $value ) ); | ||
| 2350 : | } | ||
| 2351 : | /** | ||
| 2352 : | csouza | 129 | * @param string The name of the param |
| 2353 : | * @param mixed The default value if not found | ||
| 2354 : | * @return string | ||
| 2355 : | */ | ||
| 2356 : | csouza | 154 | function get( $key, $default='' ) { |
| 2357 : | if (isset( $this->_params->$key )) return $this->_params->$key === '' ? $default : $this->_params->$key; | ||
| 2358 : | else return $default; | ||
| 2359 : | } | ||
| 2360 : | /** | ||
| 2361 : | csouza | 138 | * Look to see if string is bracketed by opener and closer |
| 2362 : | * If so, extract and trim the bracketed string | ||
| 2363 : | * Otherwise, return a null string | ||
| 2364 : | **/ | ||
| 2365 : | csouza | 154 | function getBracketed ($text, $opener, $closer) { |
| 2366 : | if (strlen($text) > 1 AND ($text[0] != $opener OR substr($text,-1) != $closer)) return ''; | ||
| 2367 : | else return trim(substr($text,1,-1)); | ||
| 2368 : | } | ||
| 2369 : | /** | ||
| 2370 : | csouza | 129 | * Parse an .ini string, based on phpDocumentor phpDocumentor_parse_ini_file function |
| 2371 : | * @param mixed The ini string or array of lines | ||
| 2372 : | * @param boolean add an associative index for each section [in brackets] | ||
| 2373 : | * @return object | ||
| 2374 : | */ | ||
| 2375 : | csouza | 154 | function parse( $txt, $process_sections = false ) { |
| 2376 : | $result = new stdClass(); | ||
| 2377 : | if (is_string($txt)) $lines = explode( "\n", $txt ); | ||
| 2378 : | elseif (is_array($txt)) $lines = $txt; | ||
| 2379 : | else return $result; | ||
| 2380 : | csouza | 129 | |
| 2381 : | csouza | 154 | $sec_name = ''; |
| 2382 : | $unparsed = 0; | ||
| 2383 : | csouza | 138 | |
| 2384 : | csouza | 154 | foreach ($lines as $line) { |
| 2385 : | // ignore comments and null lines | ||
| 2386 : | $line = trim($line); | ||
| 2387 : | if (strlen($line) == 0 OR $line[0] == ';') continue; | ||
| 2388 : | |||
| 2389 : | if ($sec_name = $this->getBracketed($line, '[', ']')) { | ||
| 2390 : | if ($process_sections) $result->$sec_name = new stdClass(); | ||
| 2391 : | continue; | ||
| 2392 : | } | ||
| 2393 : | |||
| 2394 : | if (count($propsetter = explode ('=', $line, 2)) == 2) { | ||
| 2395 : | $property = trim($propsetter[0]); | ||
| 2396 : | if ($pquoted = $this->getBracketed($property, '"', '"')) $property = stripcslashes($pquoted); | ||
| 2397 : | $value = trim($propsetter[1]); | ||
| 2398 : | if ($value == 'false') $value = false; | ||
| 2399 : | elseif ($value == 'true') $value = true; | ||
| 2400 : | else if ($vquoted = $this->getBracketed($value, '"', '"')) $value = stripcslashes($vquoted); | ||
| 2401 : | if ($process_sections AND $sec_name) $result->$sec_name->$property = $value; | ||
| 2402 : | else $result->$property = $value; | ||
| 2403 : | } | ||
| 2404 : | else { | ||
| 2405 : | $property = '__invalid' . $unparsed++ . '__'; | ||
| 2406 : | if ($process_sections AND $sec_name) $result->$sec_name->$property = $line; | ||
| 2407 : | else $result->$property = $line; | ||
| 2408 : | } | ||
| 2409 : | } | ||
| 2410 : | return $result; | ||
| 2411 : | } | ||
| 2412 : | csouza | 403 | /** |
| 2413 : | counterpoi | 244 | t * @param string The name of the control, or the default text area if a setup file is not found |
| 2414 : | t * @return string HTML | ||
| 2415 : | t */ | ||
| 2416 : | csouza | 403 | function render( $name='params' ) { |
| 2417 : | if (is_file($this->_path)) { | ||
| 2418 : | $parser = new mosXMLParams ($this->_path, $this, $name); | ||
| 2419 : | if (count($parser->html)) return implode("\n", $parser->html); | ||
| 2420 : | } | ||
| 2421 : | $raw = $this->_raw; | ||
| 2422 : | return "<textarea name='$name' cols='40' rows='10' class='text_area'$raw</textarea>"; | ||
| 2423 : | } | ||
| 2424 : | counterpoi | 244 | t |
| 2425 : | csouza | 154 | /** |
| 2426 : | csouza | 129 | * special handling for textarea param |
| 2427 : | */ | ||
| 2428 : | csouza | 154 | function textareaHandling( &$txt ) { |
| 2429 : | foreach ($txt as $key=>$value) $txt[$key] = str_replace("\n", '<br />', $value); | ||
| 2430 : | return implode( "\n", $txt ); | ||
| 2431 : | } | ||
| 2432 : | csouza | 129 | } |
| 2433 : | |||
| 2434 : | /** | ||
| 2435 : | * Page generation time | ||
| 2436 : | * @package Mambo | ||
| 2437 : | */ | ||
| 2438 : | class mosProfiler { | ||
| 2439 : | csouza | 154 | var $start=0; |
| 2440 : | var $prefix=''; | ||
| 2441 : | csouza | 129 | |
| 2442 : | csouza | 154 | function mosProfiler( $prefix='' ) { |
| 2443 : | $this->start = $this->getmicrotime(); | ||
| 2444 : | $this->prefix = $prefix; | ||
| 2445 : | } | ||
| 2446 : | csouza | 129 | |
| 2447 : | csouza | 154 | function mark( $label ) { |
| 2448 : | return sprintf ( "\n<div class=\"profiler\">$this->prefix %.3f $label</div>", $this->getmicrotime() - $this->start ); | ||
| 2449 : | } | ||
| 2450 : | csouza | 129 | |
| 2451 : | csouza | 154 | function getmicrotime(){ |
| 2452 : | list($usec, $sec) = explode(" ",microtime()); | ||
| 2453 : | return ((float)$usec + (float)$sec); | ||
| 2454 : | } | ||
| 2455 : | csouza | 129 | } |
| 2456 : | |||
| 2457 : | counterpoi | 419 | t |
| 2458 : | csouza | 129 | require($configuration->rootPath().'/includes/version.php'); |
| 2459 : | $_VERSION =& new version(); | ||
| 2460 : | |||
| 2461 : | $version = $_VERSION->PRODUCT .' '. $_VERSION->RELEASE .'.'. $_VERSION->DEV_LEVEL .' ' | ||
| 2462 : | . $_VERSION->DEV_STATUS | ||
| 2463 : | .' [ '.$_VERSION->CODENAME .' ] '. $_VERSION->RELDATE .' ' | ||
| 2464 : | . $_VERSION->RELTIME .' '. $_VERSION->RELTZ; | ||
| 2465 : | |||
| 2466 : | if (phpversion() < '4.2.0') require_once( $configuration->rootPath() . '/includes/compat.php41x.php' ); | ||
| 2467 : | if (phpversion() < '4.3.0') require_once( $configuration->rootPath() . '/includes/compat.php42x.php' ); | ||
| 2468 : | |||
| 2469 : | $local_backup_path = $configuration->rootPath().'/administrator/backups'; | ||
| 2470 : | $media_path = $configuration->rootPath().'/media/'; | ||
| 2471 : | $image_path = $configuration->rootPath().'/images/stories'; | ||
| 2472 : | csouza | 252 | $lang_path = $configuration->rootPath().'/language'; |
| 2473 : | csouza | 129 | $image_size = 100; |
| 2474 : | |||
| 2475 : | counterpoi | 238 | t $database =& mamboDatabase::getInstance(); |
| 2476 : | csouza | 129 | $database->debug(mamboCore::get('mosConfig_debug')); |
| 2477 : | |||
| 2478 : | csouza | 252 | // |
| 2479 : | |||
| 2480 : | $gettext =& phpgettext(); | ||
| 2481 : | $gettext->bindtextdomain('common', $configuration->rootPath().'/language'); | ||
| 2482 : | $gettext->textdomain('common'); | ||
| 2483 : | //dump($gettext->textdomain(substr($option, 3))); | ||
| 2484 : | //$gettext->bindtextdomain('frontend', $lang_path); | ||
| 2485 : | //$gettext->textdomain('frontend'); | ||
| 2486 : | |||
| 2487 : | csouza | 129 | if (!$adminside) { |
| 2488 : | csouza | 154 | $sefcode = $configuration->rootPath().'/components/com_sef/sef.php'; |
| 2489 : | if (file_exists($sefcode)) require_once($sefcode); | ||
| 2490 : | else require_once($configuration->rootPath().'/includes/sef.php'); | ||
| 2491 : | $urlerror = 0; | ||
| 2492 : | if (mamboCore::get('mosConfig_sef') AND $indextype == 3) { | ||
| 2493 : | counterpoi | 238 | t $sef =& mosSEF::getInstance(); |
| 2494 : | csouza | 154 | $urlerror = $sef->sefRetrieval(mamboCore::get('mosConfig_register_globals')); |
| 2495 : | $indextype = 1; | ||
| 2496 : | } | ||
| 2497 : | csouza | 129 | } |
| 2498 : | |||
| 2499 : | /** retrieve some possible request string (or form) arguments */ | ||
| 2500 : | $type = mosGetParam($_REQUEST, 'type', 1); | ||
| 2501 : | $act = mosGetParam( $_REQUEST, 'act', '' ); | ||
| 2502 : | $do_pdf = mosGetParam( $_REQUEST, 'do_pdf', 0 ); | ||
| 2503 : | $id = mosGetParam( $_REQUEST, 'id', 0 ); | ||
| 2504 : | $task = mosGetParam($_REQUEST, 'task', ''); | ||
| 2505 : | $act = strtolower(mosGetParam($_REQUEST, 'act', '')); | ||
| 2506 : | $section = mosGetParam($_REQUEST, 'section', ''); | ||
| 2507 : | $no_html = strtolower(mosGetParam($_REQUEST, 'no_html', '')); | ||
| 2508 : | |||
| 2509 : | if ($adminside) { | ||
| 2510 : | csouza | 154 | // Start ACL |
| 2511 : | require_once($configuration->rootPath().'/includes/gacl.class.php' ); | ||
| 2512 : | require_once($configuration->rootPath().'/includes/gacl_api.class.php' ); | ||
| 2513 : | $acl = new gacl_api(); | ||
| 2514 : | // Handle special admin side options | ||
| 2515 : | $option = strtolower(mosGetParam($_REQUEST,'option','com_admin')); | ||
| 2516 : | csouza | 252 | |
| 2517 : | $domain = substr($option, 4); | ||
| 2518 : | $gettext->bindtextdomain('administrator', $lang_path); | ||
| 2519 : | $gettext->bindtextdomain($domain, $lang_path); | ||
| 2520 : | csouza | 403 | $admindomain = $gettext->textdomain(); |
| 2521 : | csouza | 252 | $gettext->textdomain('administrator'); |
| 2522 : | csouza | 154 | // Login will, if it succeeds, start a new session and set $my |
| 2523 : | if ($option == 'login') { | ||
| 2524 : | require_once($configuration->rootPath().'/includes/authenticator.php'); | ||
| 2525 : | counterpoi | 238 | t $authenticator =& mamboAuthenticator::getInstance(); |
| 2526 : | csouza | 154 | $my = $authenticator->loginAdmin($acl); |
| 2527 : | } | ||
| 2528 : | // If this is not login, we should already have a valid admin session | ||
| 2529 : | else { | ||
| 2530 : | counterpoi | 319 | t ini_set('session.use_trans_sid', 0); |
| 2531 : | t ini_set('session.use_cookies', 1); | ||
| 2532 : | t ini_set('session.use_only_cookies', 1); | ||
| 2533 : | csouza | 154 | session_name(md5(mamboCore::get('mosConfig_live_site'))); |
| 2534 : | session_start(); | ||
| 2535 : | // Handle the remaining special options | ||
| 2536 : | if ($option == 'logout') { | ||
| 2537 : | require($configuration->rootPath().'/administrator/logout.php'); | ||
| 2538 : | exit(); | ||
| 2539 : | } | ||
| 2540 : | if ($option == 'simple_mode') $admin_mode = 'on'; | ||
| 2541 : | elseif ($option == 'advanced_mode') $admin_mode = 'off'; | ||
| 2542 : | else $admin_mode = mosGetParam($_SESSION, 'simple_editing', ''); | ||
| 2543 : | $_SESSION['simple_editing'] = mosGetParam($_POST, 'simple_editing', $admin_mode); | ||
| 2544 : | // Include admin side functions, check that we have a valid admin side session | ||
| 2545 : | require_once($configuration->rootPath().'/administrator/includes/admin.php'); | ||
| 2546 : | counterpoi | 419 | t // restore some session variables |
| 2547 : | t $my = new mosUser(); | ||
| 2548 : | t $my->getSession(); | ||
| 2549 : | t if (mosSession::validate($my)) mosSession::purge(); | ||
| 2550 : | t else $my = null; | ||
| 2551 : | csouza | 154 | } |
| 2552 : | // We can now create the mainframe object | ||
| 2553 : | $mainframe =& new mosMainFrame($database, $option, '..', true); | ||
| 2554 : | // Provided $my is set, we have a valid admin side session and can include remaining code | ||
| 2555 : | csouza | 252 | |
| 2556 : | csouza | 154 | if ($my) { |
| 2557 : | mamboCore::set('currentUser', $my); | ||
| 2558 : | require_once( $configuration->rootPath().'/includes/mambo.php' ); | ||
| 2559 : | require_once ($configuration->rootPath().'/includes/mambofunc.php'); | ||
| 2560 : | require_once ($configuration->rootPath().'/includes/mamboHTML.php'); | ||
| 2561 : | require_once( $configuration->rootPath().'/administrator/includes/mosAdminMenus.php'); | ||
| 2562 : | require_once($configuration->rootPath().'/administrator/includes/admin.php'); | ||
| 2563 : | require_once( $configuration->rootPath() . '/includes/cmtclasses.php' ); | ||
| 2564 : | csouza | 403 | require_once( $configuration->rootPath() . '/components/com_content/content.class.php' ); |
| 2565 : | counterpoi | 238 | t $_MAMBOTS =& mosMambotHandler::getInstance(); |
| 2566 : | csouza | 252 | |
| 2567 : | csouza | 403 | |
| 2568 : | csouza | 154 | // If no_html is set, we avoid starting the template, and go straight to the component |
| 2569 : | if ($no_html) { | ||
| 2570 : | if ($path = $mainframe->getPath( "admin" )) require $path; | ||
| 2571 : | exit(); | ||
| 2572 : | } | ||
| 2573 : | $configuration->initGzip(); | ||
| 2574 : | // When adminside = 3 we assume that HTML is being explicitly written and do nothing more | ||
| 2575 : | if ($adminside != 3) { | ||
| 2576 : | $path = $configuration->rootPath().'/administrator/templates/'.$mainframe->getTemplate().'/index.php'; | ||
| 2577 : | require_once($path); | ||
| 2578 : | $configuration->doGzip(); | ||
| 2579 : | } | ||
| 2580 : | else { | ||
| 2581 : | csouza | 302 | if (!isset($popup)) { |
| 2582 : | csouza | 252 | $pop = mosGetParam($_REQUEST, 'pop', ''); |
| 2583 : | counterpoi | 419 | t if ($pop) require($configuration->rootPath()."/administrator/popups/$pop"); |
| 2584 : | t else require($configuration->rootPath()."/administrator/popups/index3pop.php"); | ||
| 2585 : | csouza | 252 | $configuration->doGzip(); |
| 2586 : | } | ||
| 2587 : | csouza | 154 | } |
| 2588 : | } | ||
| 2589 : | // If $my was not set, the only possibility is to ask for an admin side login | ||
| 2590 : | else { | ||
| 2591 : | $configuration->initGzip(); | ||
| 2592 : | $path = $configuration->rootPath().'/administrator/templates/'.$mainframe->getTemplate().'/login.php'; | ||
| 2593 : | require_once( $path ); | ||
| 2594 : | $configuration->doGzip(); | ||
| 2595 : | } | ||
| 2596 : | csouza | 129 | } |
| 2597 : | // Finished admin side; the rest is user side code: | ||
| 2598 : | else { | ||
| 2599 : | csouza | 154 | $option = $configuration->determineOptionAndItemid(); |
| 2600 : | $configuration->handleGlobals(); | ||
| 2601 : | $Itemid = $configuration->get('Itemid'); | ||
| 2602 : | csouza | 129 | |
| 2603 : | csouza | 252 | // load frontend language file |
| 2604 : | $gettext->bindtextdomain(substr($option, 4), $configuration->rootPath().'/language'); | ||
| 2605 : | $gettext->bindtextdomain('frontend', $configuration->rootPath().'/language'); | ||
| 2606 : | $frontdomain = $gettext->textdomain(); | ||
| 2607 : | $gettext->textdomain('frontend'); | ||
| 2608 : | |||
| 2609 : | csouza | 403 | |
| 2610 : | csouza | 154 | $mainframe =& new mosMainFrame($database, $option, '.'); |
| 2611 : | counterpoi | 223 | t if ($option == 'login') $configuration->handleLogin(); |
| 2612 : | t elseif ($option == 'logout') $configuration->handleLogout(); | ||
| 2613 : | t | ||
| 2614 : | counterpoi | 238 | t $session =& mosSession::getCurrent(); |
| 2615 : | counterpoi | 419 | t $my =& new mosUser(); |
| 2616 : | csouza | 154 | $my->getSessionData(); |
| 2617 : | mamboCore::set('currentUser',$my); | ||
| 2618 : | $configuration->offlineCheck($my, $database); | ||
| 2619 : | $gid = intval( $my->gid ); | ||
| 2620 : | // gets template for page | ||
| 2621 : | $cur_template = $mainframe->getTemplate(); | ||
| 2622 : | csouza | 129 | |
| 2623 : | csouza | 154 | require_once( $configuration->rootPath().'/includes/frontend.php' ); |
| 2624 : | require_once( $configuration->rootPath().'/includes/mambo.php' ); | ||
| 2625 : | require_once ($configuration->rootPath().'/includes/mambofunc.php'); | ||
| 2626 : | require_once ($configuration->rootPath().'/includes/mamboHTML.php'); | ||
| 2627 : | csouza | 129 | |
| 2628 : | csouza | 154 | if ($indextype == 2 AND $do_pdf == 1 ) { |
| 2629 : | include_once('includes/pdf.php'); | ||
| 2630 : | exit(); | ||
| 2631 : | } | ||
| 2632 : | csouza | 129 | |
| 2633 : | csouza | 154 | /** detect first visit */ |
| 2634 : | $mainframe->detect(); | ||
| 2635 : | csouza | 129 | |
| 2636 : | csouza | 154 | /** @global mosPlugin $_MAMBOTS */ |
| 2637 : | counterpoi | 238 | t $_MAMBOTS =& mosMambotHandler::getInstance(); |
| 2638 : | csouza | 154 | require_once( $configuration->rootPath().'/editor/editor.php' ); |
| 2639 : | require_once( $configuration->rootPath() . '/includes/gacl.class.php' ); | ||
| 2640 : | require_once( $configuration->rootPath() . '/includes/gacl_api.class.php' ); | ||
| 2641 : | counterpoi | 270 | t require_once( $configuration->rootPath() . '/components/com_content/content.class.php' ); |
| 2642 : | csouza | 154 | $acl = new gacl_api(); |
| 2643 : | csouza | 403 | |
| 2644 : | csouza | 154 | /** Get the component handler */ |
| 2645 : | require_once( $configuration->rootPath() . '/includes/cmtclasses.php' ); | ||
| 2646 : | csouza | 236 | $c_handler =& mosComponentHandler::getInstance(); |
| 2647 : | csouza | 154 | $c_handler->startBuffer(); |
| 2648 : | csouza | 129 | |
| 2649 : | csouza | 154 | if (!$urlerror AND $path = $mainframe->getPath( 'front' )) { |
| 2650 : | counterpoi | 238 | t $menuhandler =& mosMenuHandler::getInstance(); |
| 2651 : | csouza | 154 | $ret = $menuhandler->menuCheck($Itemid, $option, $task, $gid); |
| 2652 : | $menuhandler->setPathway($Itemid); | ||
| 2653 : | csouza | 252 | if ($ret) { |
| 2654 : | $gettext->textdomain(substr($option, 4)); // get the component lang file | ||
| 2655 : | counterpoi | 390 | t require ($path); |
| 2656 : | t $gettext->textdomain($frontdomain); | ||
| 2657 : | csouza | 252 | } |
| 2658 : | csouza | 154 | else mosNotAuth(); |
| 2659 : | } | ||
| 2660 : | else { | ||
| 2661 : | header ('HTTP/1.1 404 Not Found'); | ||
| 2662 : | csouza | 183 | $mainframe->setPageTitle(T_('404 Error - page not found')); |
| 2663 : | csouza | 154 | include ($configuration->rootPath().'/page404.php'); |
| 2664 : | } | ||
| 2665 : | csouza | 129 | |
| 2666 : | csouza | 154 | $c_handler->endBuffer(); |
| 2667 : | csouza | 129 | |
| 2668 : | csouza | 154 | $configuration->initGzip(); |
| 2669 : | csouza | 129 | |
| 2670 : | csouza | 154 | $configuration->standardHeaders(); |
| 2671 : | counterpoi | 270 | t if (mosGetParam($_GET, 'syndstyle', '') == 'yes') mosMainBody(); |
| 2672 : | t elseif ($indextype == 1) { | ||
| 2673 : | csouza | 154 | // loads template file |
| 2674 : | if ( !file_exists( 'templates/'. $cur_template .'/index.php' ) ) { | ||
| 2675 : | csouza | 183 | echo '<font color=\"red\"><b>'.T_('Template File Not Found! Looking for template').'</b></font>'.$cur_template; |
| 2676 : | csouza | 154 | } else { |
| 2677 : | require_once( 'templates/'. $cur_template .'/index.php' ); | ||
| 2678 : | counterpoi | 238 | t $mambothandler =& mosMambotHandler::getInstance(); |
| 2679 : | csouza | 154 | $mambothandler->loadBotGroup('system'); |
| 2680 : | $mambothandler->trigger('afterTemplate', array($configuration)); | ||
| 2681 : | echo "<!-- ".time()." -->"; | ||
| 2682 : | } | ||
| 2683 : | } | ||
| 2684 : | elseif ($indextype == 2) { | ||
| 2685 : | if ( $no_html == 0 ) { | ||
| 2686 : | // needed to seperate the ISO number from the language file constant _ISO | ||
| 2687 : | $iso = split( '=', _ISO ); | ||
| 2688 : | // xml prolog | ||
| 2689 : | echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>'; | ||
| 2690 : | csouza | 129 | ?> |
| 2691 : | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
| 2692 : | <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| 2693 : | <head> | ||
| 2694 : | <link rel="stylesheet" href="templates/<?php echo $cur_template;?>/css/template_css.css" type="text/css" /> | ||
| 2695 : | <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?>" /> | ||
| 2696 : | <meta name="robots" content="noindex, nofollow"> | ||
| 2697 : | </head> | ||
| 2698 : | <body class="contentpane"> | ||
| 2699 : | <?php mosMainBody(); ?> | ||
| 2700 : | </body> | ||
| 2701 : | </html> | ||
| 2702 : | <?php | ||
| 2703 : | csouza | 154 | } else { |
| 2704 : | mosMainBody(); | ||
| 2705 : | } | ||
| 2706 : | } | ||
| 2707 : | csouza | 129 | |
| 2708 : | csouza | 154 | $configuration->doGzip(); |
| 2709 : | csouza | 129 | } |
| 2710 : | // displays queries performed for page | ||
| 2711 : | counterpoi | 419 | t if ($configuration->get('mosConfig_debug') AND $adminside != 3) $database->displayLogged(); |
| 2712 : | csouza | 129 | |
| 2713 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

