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

