Annotation of /mambo/branches/4.6/includes/core.classes.php
Parent Directory
|
Revision Log
Revision 1348 - (view) (download)
| 1 : | alwarren | 1331 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo | ||
| 4 : | * @author Mambo Foundation Inc see README.php | ||
| 5 : | * @copyright Mambo Foundation Inc. | ||
| 6 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 7 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see | ||
| 8 : | * LICENSE.php | ||
| 9 : | * Mambo is free software; you can redistribute it and/or | ||
| 10 : | * modify it under the terms of the GNU General Public License | ||
| 11 : | * as published by the Free Software Foundation; version 2 of the | ||
| 12 : | * License. | ||
| 13 : | */ | ||
| 14 : | |||
| 15 : | /** | ||
| 16 : | * Mambo basic error object | ||
| 17 : | */ | ||
| 18 : | define ('_MOS_ERROR_INFORM', 0); | ||
| 19 : | define ('_MOS_ERROR_WARN', 1); | ||
| 20 : | define ('_MOS_ERROR_SEVERE', 2); | ||
| 21 : | define ('_MOS_ERROR_FATAL', 3); | ||
| 22 : | |||
| 23 : | /** | ||
| 24 : | * Enter description here... | ||
| 25 : | * | ||
| 26 : | */ | ||
| 27 : | class mosError { | ||
| 28 : | /** | ||
| 29 : | * Enter description here... | ||
| 30 : | * | ||
| 31 : | * @var unknown_type | ||
| 32 : | */ | ||
| 33 : | var $text = ''; | ||
| 34 : | /** | ||
| 35 : | * Enter description here... | ||
| 36 : | * | ||
| 37 : | * @var unknown_type | ||
| 38 : | */ | ||
| 39 : | var $level = 0; | ||
| 40 : | |||
| 41 : | /** | ||
| 42 : | * Enter description here... | ||
| 43 : | * | ||
| 44 : | * @param unknown_type $text | ||
| 45 : | * @param unknown_type $level | ||
| 46 : | * @return mosError | ||
| 47 : | */ | ||
| 48 : | function mosError ($text='', $level=_MOS_ERROR_INFORM) { | ||
| 49 : | $this->text = $text; | ||
| 50 : | $this->level = $level; | ||
| 51 : | } | ||
| 52 : | } | ||
| 53 : | |||
| 54 : | /** | ||
| 55 : | * Mambo group of errors for some particular operation | ||
| 56 : | */ | ||
| 57 : | class mosErrorSet { | ||
| 58 : | /** | ||
| 59 : | * Enter description here... | ||
| 60 : | * | ||
| 61 : | * @var unknown_type | ||
| 62 : | */ | ||
| 63 : | var $errors = array(); | ||
| 64 : | /** | ||
| 65 : | * Enter description here... | ||
| 66 : | * | ||
| 67 : | * @var unknown_type | ||
| 68 : | */ | ||
| 69 : | var $maxlevel = 0; | ||
| 70 : | |||
| 71 : | // Parameter is an error object | ||
| 72 : | /** | ||
| 73 : | * Enter description here... | ||
| 74 : | * | ||
| 75 : | * @param unknown_type $error | ||
| 76 : | */ | ||
| 77 : | function addError ($error) { | ||
| 78 : | $this->errors[] = $error; | ||
| 79 : | if ($error->level > $this->maxlevel) $this->maxlevel = $error->level; | ||
| 80 : | } | ||
| 81 : | |||
| 82 : | /** | ||
| 83 : | * Enter description here... | ||
| 84 : | * | ||
| 85 : | * @param unknown_type $text | ||
| 86 : | * @param unknown_type $level | ||
| 87 : | */ | ||
| 88 : | function addErrorDetails ($text='', $level=_MOS_ERROR_INFORM) { | ||
| 89 : | $error = new mosError($text, $level); | ||
| 90 : | $this->addError($error); | ||
| 91 : | } | ||
| 92 : | |||
| 93 : | /** | ||
| 94 : | * Enter description here... | ||
| 95 : | * | ||
| 96 : | * @return unknown | ||
| 97 : | */ | ||
| 98 : | function &getErrors () { | ||
| 99 : | return $this->errors; | ||
| 100 : | } | ||
| 101 : | |||
| 102 : | /** | ||
| 103 : | * Enter description here... | ||
| 104 : | * | ||
| 105 : | * @return unknown | ||
| 106 : | */ | ||
| 107 : | function getMaxLevel () { | ||
| 108 : | return $this->maxlevel; | ||
| 109 : | } | ||
| 110 : | |||
| 111 : | /** | ||
| 112 : | * Enter description here... | ||
| 113 : | * | ||
| 114 : | * @return unknown | ||
| 115 : | */ | ||
| 116 : | function getCount () { | ||
| 117 : | return count($this->errors); | ||
| 118 : | } | ||
| 119 : | |||
| 120 : | /** | ||
| 121 : | * Enter description here... | ||
| 122 : | * | ||
| 123 : | * @param unknown_type $errorset | ||
| 124 : | */ | ||
| 125 : | function mergeAnother ($errorset) { | ||
| 126 : | $this->errors = array_merge($this->errors, $errorset->errors); | ||
| 127 : | } | ||
| 128 : | |||
| 129 : | } | ||
| 130 : | |||
| 131 : | |||
| 132 : | /* This is the new error handler to store errors in the database | ||
| 133 : | class mosErrorHandler { | ||
| 134 : | var $types = array ( | ||
| 135 : | E_STRICT => 'Strict check', | ||
| 136 : | E_USER_WARNING => 'User Warning', | ||
| 137 : | E_USER_NOTICE => 'User Notice', | ||
| 138 : | E_WARNING => 'Warning', | ||
| 139 : | E_NOTICE => 'Notice', | ||
| 140 : | E_CORE_WARNING => 'Core Warning', | ||
| 141 : | E_COMPILE_WARNING => 'Compile Warning', | ||
| 142 : | E_USER_ERROR => 'User Error', | ||
| 143 : | E_ERROR => 'Error', | ||
| 144 : | E_PARSE => 'Parse error', | ||
| 145 : | E_CORE_ERROR => 'Core Error', | ||
| 146 : | E_COMPILE_ERROR => 'Compile Error' | ||
| 147 : | ); | ||
| 148 : | |||
| 149 : | function mosErrorHandler () { | ||
| 150 : | set_error_handler(array(&$this, 'handler')); | ||
| 151 : | } | ||
| 152 : | |||
| 153 : | function handler ($errno, $errstr, $errfile, $errline, $errcontext) { | ||
| 154 : | if ($errno = E_STRICT) return; | ||
| 155 : | $string = $this->types[$errno].': '.$errstr.' in '.$errfile.' at '.$errline; | ||
| 156 : | $database =& mamboDatabase::getInstance(); | ||
| 157 : | if (eregi('^(sql)$', $errstr)) { | ||
| 158 : | $extra = $database->getErrorMsg(); | ||
| 159 : | } | ||
| 160 : | if (function_exists('debug_backtrace')) { | ||
| 161 : | foreach(debug_backtrace() as $back) { | ||
| 162 : | if (@$back['file']) { | ||
| 163 : | $extra .= "\n".$back['file'].':'.$back['line']; | ||
| 164 : | } | ||
| 165 : | } | ||
| 166 : | } | ||
| 167 : | $database->setQuery("DELETE FROM #__errors WHERE file=$errfile AND line=$errline AND number=$errno"); | ||
| 168 : | $database->query(); | ||
| 169 : | $database->setQuery("INSERT INTO #__errors VALUES (0, $errno, '$errfile', $errline, '$string', '$extra')"); | ||
| 170 : | $database->query(); | ||
| 171 : | } | ||
| 172 : | } | ||
| 173 : | */ | ||
| 174 : | |||
| 175 : | /** | ||
| 176 : | * Enter description here... | ||
| 177 : | * | ||
| 178 : | */ | ||
| 179 : | class mamboCore { | ||
| 180 : | /** | ||
| 181 : | * Enter description here... | ||
| 182 : | * | ||
| 183 : | * @var unknown_type | ||
| 184 : | */ | ||
| 185 : | var $rootPath = ''; | ||
| 186 : | /** | ||
| 187 : | * Enter description here... | ||
| 188 : | * | ||
| 189 : | * @var unknown_type | ||
| 190 : | */ | ||
| 191 : | var $Itemid = 0; | ||
| 192 : | /** | ||
| 193 : | * Enter description here... | ||
| 194 : | * | ||
| 195 : | * @var unknown_type | ||
| 196 : | */ | ||
| 197 : | var $option = ''; | ||
| 198 : | /** | ||
| 199 : | * Enter description here... | ||
| 200 : | * | ||
| 201 : | * @var unknown_type | ||
| 202 : | */ | ||
| 203 : | var $subdirectory; | ||
| 204 : | /** | ||
| 205 : | * Enter description here... | ||
| 206 : | * | ||
| 207 : | * @var unknown_type | ||
| 208 : | */ | ||
| 209 : | var $current_user = null; | ||
| 210 : | /** | ||
| 211 : | * Enter description here... | ||
| 212 : | * | ||
| 213 : | * @var unknown_type | ||
| 214 : | */ | ||
| 215 : | var $do_gzip_compress = false; | ||
| 216 : | /** | ||
| 217 : | * Enter description here... | ||
| 218 : | * | ||
| 219 : | * @var unknown_type | ||
| 220 : | */ | ||
| 221 : | var $init_errorlevel = 0; | ||
| 222 : | |||
| 223 : | /** | ||
| 224 : | * Enter description here... | ||
| 225 : | * | ||
| 226 : | * @return mamboCore | ||
| 227 : | */ | ||
| 228 : | function mamboCore () { | ||
| 229 : | global $adminside; | ||
| 230 : | $this->init_errorlevel = error_reporting(0); | ||
| 231 : | //$this->rootPath = str_replace('\\', '/', realpath(str_replace('includes', '', dirname(__FILE__)))); | ||
| 232 : | $this->rootPath = str_replace('\\', '/',str_replace('includes', '', dirname(__FILE__))); | ||
| 233 : | $this->checkConfig(); | ||
| 234 : | $this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0); | ||
| 235 : | $this->getConfig(); | ||
| 236 : | $this->fixLanguage(); | ||
| 237 : | @set_magic_quotes_runtime( 0 ); | ||
| 238 : | if (@$this->mosConfig_error_reporting > 0 OR @$this->mosConfig_error_reporting ===0) error_reporting($this->mosConfig_error_reporting); | ||
| 239 : | else error_reporting($this->init_errorlevel); | ||
| 240 : | } | ||
| 241 : | |||
| 242 : | /** | ||
| 243 : | * Enter description here... | ||
| 244 : | * | ||
| 245 : | * @return unknown | ||
| 246 : | */ | ||
| 247 : | function &getMamboCore () { | ||
| 248 : | static $instance; | ||
| 249 : | if (!is_object($instance)) $instance = new mamboCore(); | ||
| 250 : | return $instance; | ||
| 251 : | } | ||
| 252 : | |||
| 253 : | /** | ||
| 254 : | * Enter description here... | ||
| 255 : | * | ||
| 256 : | * @return unknown | ||
| 257 : | */ | ||
| 258 : | function rootPath () { | ||
| 259 : | //if (realpath($this->rootPath) === false) die ('Invalid program load path'); | ||
| 260 : | if (file_exists($this->rootPath) === false) die ('Invalid program load path'); | ||
| 261 : | return $this->rootPath; | ||
| 262 : | } | ||
| 263 : | |||
| 264 : | /** | ||
| 265 : | * Enter description here... | ||
| 266 : | * | ||
| 267 : | * @param unknown_type $property | ||
| 268 : | * @return unknown | ||
| 269 : | */ | ||
| 270 : | function get ($property) { | ||
| 271 : | $config =& mamboCore::getMamboCore(); | ||
| 272 : | if ($property == 'mosConfig_absolute_path') { | ||
| 273 : | //if (realpath($config->mosConfig_absolute_path) === false) die ('Invalid program load path'); | ||
| 274 : | if (file_exists($config->mosConfig_absolute_path) === false) die ('Invalid program load path'); | ||
| 275 : | else return $config->rootPath; | ||
| 276 : | } | ||
| 277 : | if (isset($config->$property)) return $config->$property; | ||
| 278 : | trigger_error("Invalid property ($property) requested from mamboCore"); | ||
| 279 : | return null; | ||
| 280 : | } | ||
| 281 : | |||
| 282 : | /** | ||
| 283 : | * Enter description here... | ||
| 284 : | * | ||
| 285 : | * @param unknown_type $property | ||
| 286 : | * @return unknown | ||
| 287 : | */ | ||
| 288 : | function is_set ($property) { | ||
| 289 : | $config =& mamboCore::getMamboCore(); | ||
| 290 : | return isset($config->$property); | ||
| 291 : | } | ||
| 292 : | |||
| 293 : | /** | ||
| 294 : | * Enter description here... | ||
| 295 : | * | ||
| 296 : | * @param unknown_type $property | ||
| 297 : | * @param unknown_type $value | ||
| 298 : | * @return unknown | ||
| 299 : | */ | ||
| 300 : | function set ($property, $value) { | ||
| 301 : | $config =& mamboCore::getMamboCore(); | ||
| 302 : | $config->$property = $value; | ||
| 303 : | $GLOBALS[$property] = $value; | ||
| 304 : | return $value; | ||
| 305 : | } | ||
| 306 : | |||
| 307 : | /** | ||
| 308 : | * Enter description here... | ||
| 309 : | * | ||
| 310 : | */ | ||
| 311 : | function checkConfig () { | ||
| 312 : | // checks for configuration file, if none found loads installation page | ||
| 313 : | if (!file_exists($this->rootPath.'/configuration.php') OR filesize($this->rootPath.'/configuration.php') < 10 ) { | ||
| 314 : | header( 'Location: installation/index.php' ); | ||
| 315 : | exit(); | ||
| 316 : | } | ||
| 317 : | } | ||
| 318 : | |||
| 319 : | /** | ||
| 320 : | * Enter description here... | ||
| 321 : | * | ||
| 322 : | */ | ||
| 323 : | function getConfig () { | ||
| 324 : | global $adminside; | ||
| 325 : | $code = ''; | ||
| 326 : | $f = @fopen($this->rootPath.'/configuration.php','rb'); | ||
| 327 : | if ($f) { | ||
| 328 : | while ($f AND !feof($f)) { | ||
| 329 : | $line = fgets($f); | ||
| 330 : | $altered = preg_replace('/^\$/', '$this->', $line); | ||
| 331 : | if ($altered != $line) $code .= $altered; | ||
| 332 : | } | ||
| 333 : | } | ||
| 334 : | else { | ||
| 335 : | #header( 'Location: installation/index.php' ); | ||
| 336 : | exit(); | ||
| 337 : | } | ||
| 338 : | fclose($f); | ||
| 339 : | eval($code); | ||
| 340 : | |||
| 341 : | |||
| 342 : | /*if (isset($_SERVER['DOCUMENT_ROOT']) AND strlen($_SERVER['DOCUMENT_ROOT'])) { | ||
| 343 : | $docroot = str_replace('\\', '/', str_replace('\\\\', '\\', $_SERVER['DOCUMENT_ROOT'])); | ||
| 344 : | } | ||
| 345 : | else {*/ | ||
| 346 : | // Find information about where execution started | ||
| 347 : | $origin = array_pop(debug_backtrace()); | ||
| 348 : | // Find the PHP script at the start, with a fix for Windows slashes | ||
| 349 : | $absolutepath = str_replace('\\', '/', $origin['file']); | ||
| 350 : | $localpath = $_SERVER['PHP_SELF']; | ||
| 351 : | $docroot = substr($absolutepath,0,strpos($absolutepath,$localpath)); | ||
| 352 : | /*}*/ | ||
| 353 : | $mamboroot = str_replace('\\', '/', rtrim($this->rootPath, '\/')); | ||
| 354 : | $this->subdirectory = substr($mamboroot, strlen($docroot)); | ||
| 355 : | |||
| 356 : | $scheme = isset($_SERVER['HTTP_SCHEME']) ? $_SERVER['HTTP_SCHEME'] : ((isset($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS'] != 'off')) ? 'https' : 'http'); | ||
| 357 : | if (isset($_SERVER['HTTP_HOST'])) { | ||
| 358 : | $withport = explode(':', $_SERVER['HTTP_HOST']); | ||
| 359 : | $servername = $withport[0]; | ||
| 360 : | if (isset($withport[1])) $port = ':'.$withport[1]; | ||
| 361 : | } | ||
| 362 : | elseif (isset($_SERVER['SERVER_NAME'])) $servername = $_SERVER['SERVER_NAME']; | ||
| 363 : | else trigger_error(T_('Impossible to determine the name of this server'), E_USER_ERROR); | ||
| 364 : | if (!isset($port) AND !empty($_SERVER['SERVER_PORT'])) $port = ':'.$_SERVER['SERVER_PORT']; | ||
| 365 : | if (isset($port)) { | ||
| 366 : | if (($scheme == 'http' AND $port == ':80') OR ($scheme == 'https' AND $port == ':443')) $port = ''; | ||
| 367 : | } | ||
| 368 : | else $port = ''; | ||
| 369 : | $afterscheme = '://'.$servername.$port.$this->subdirectory; | ||
| 370 : | //$this->mosConfig_live_site = $this->mosConfig_secure_site = $scheme.$afterscheme; | ||
| 371 : | $this->mosConfig_unsecure_site = 'http'.$afterscheme; | ||
| 372 : | $this->mosConfig_absolute_path = $this->rootPath; | ||
| 373 : | preg_match_all('/\$this\-\>([A-Za-z_][A-Za-z0-9_]*)/', $code, $matches); | ||
| 374 : | foreach ($matches[1] as $match) $GLOBALS[$match] = $this->$match; | ||
| 375 : | if (!isset($this->mosConfig_register_globals)) { | ||
| 376 : | $this->mosConfig_register_globals = 0; | ||
| 377 : | $GLOBALS['mosConfig_register_globals'] = 0; | ||
| 378 : | } | ||
| 379 : | |||
| 380 : | } | ||
| 381 : | |||
| 382 : | /** | ||
| 383 : | * Enter description here... | ||
| 384 : | * | ||
| 385 : | * @return unknown | ||
| 386 : | */ | ||
| 387 : | function getFavIcon () { | ||
| 388 : | // favourites icon | ||
| 389 : | if (!isset($this->mosConfig_favicon)) $this->mosConfig_favicon = 'favicon.ico'; | ||
| 390 : | if (!file_exists($this->rootPath.'/images/'.$this->mosConfig_favicon)) $this->mosConfig_favicon = 'favicon.ico'; | ||
| 391 : | return $this->mosConfig_live_site.'/images/'.$this->mosConfig_favicon; | ||
| 392 : | } | ||
| 393 : | |||
| 394 : | /** | ||
| 395 : | * Enter description here... | ||
| 396 : | * | ||
| 397 : | * @param unknown_type $user | ||
| 398 : | * @param unknown_type $database | ||
| 399 : | */ | ||
| 400 : | function offlineCheck (&$user, &$database) { | ||
| 401 : | global $adminside; | ||
| 402 : | if (($this->mosConfig_offline && !$adminside) OR file_exists($this->rootPath.'/installation/index.php')) { | ||
| 403 : | require_once($this->rootPath().'/administrator/includes/admin.php'); | ||
| 404 : | session_name(md5($this->mosConfig_live_site)); | ||
| 405 : | session_start(); | ||
| 406 : | $session =& mosSession::getCurrent(); | ||
| 407 : | $my =& new mosUser(); | ||
| 408 : | $my->getSessionData(); | ||
| 409 : | if (mosSession::validate($my)) return; | ||
| 410 : | include("$this->mosConfig_absolute_path/offline.php"); | ||
| 411 : | exit(); | ||
| 412 : | } | ||
| 413 : | } | ||
| 414 : | |||
| 415 : | /** | ||
| 416 : | * Enter description here... | ||
| 417 : | * | ||
| 418 : | */ | ||
| 419 : | function fixLanguage () { | ||
| 420 : | require_once($this->mosConfig_absolute_path.'/includes/phpgettext/phpgettext.class.php'); | ||
| 421 : | require_once($this->mosConfig_absolute_path.'/includes/phpgettext/error.php'); | ||
| 422 : | require_once($this->mosConfig_absolute_path.'/includes/mambofunc.php'); | ||
| 423 : | require_once($this->mosConfig_absolute_path.'/includes/mambolanguage.class.php'); | ||
| 424 : | arpee | 1347 | if (!mosGetParam($_REQUEST, 'lang')); |
| 425 : | else $this->mosConfig_locale = mosGetParam($_REQUEST, 'lang', $this->mosConfig_locale); | ||
| 426 : | alwarren | 1331 | $language =& new mamboLanguage($this->mosConfig_locale, $this->rootPath.'/language/'); |
| 427 : | $languages = $language->getLanguages(); | ||
| 428 : | $charset = $language->get('charset'); | ||
| 429 : | $dateformat = $language->get('dateformat'); | ||
| 430 : | $this->mosConfig_lang = $language->get('lang'); | ||
| 431 : | $this->current_language = $language; | ||
| 432 : | if (!defined('_ISO')) DEFINE('_ISO','charset='.$charset); | ||
| 433 : | header('Content-type: text/html; '._ISO); | ||
| 434 : | if (!defined('_DATE_FORMAT_LC')) DEFINE('_DATE_FORMAT_LC', $dateformat); //Uses PHP's strftime Command Format | ||
| 435 : | if (!defined('_DATE_FORMAT_LC2')) DEFINE('_DATE_FORMAT_LC2', $dateformat); | ||
| 436 : | |||
| 437 : | #error_reporting(E_ALL) ; | ||
| 438 : | ########## DEPRECATED ############ | ||
| 439 : | if (isset($this->mosConfig_lang) AND $this->mosConfig_lang); | ||
| 440 : | else $this->set('mosConfig_lang', 'english'); | ||
| 441 : | $language_file = "$this->mosConfig_absolute_path/language/$this->mosConfig_lang.php"; | ||
| 442 : | if (file_exists($language_file)) require_once ($language_file); | ||
| 443 : | else require_once ("$this->mosConfig_absolute_path/language/english.php"); | ||
| 444 : | ################################### | ||
| 445 : | |||
| 446 : | |||
| 447 : | |||
| 448 : | |||
| 449 : | } | ||
| 450 : | |||
| 451 : | /** | ||
| 452 : | * Enter description here... | ||
| 453 : | * | ||
| 454 : | */ | ||
| 455 : | function handleGlobals () { | ||
| 456 : | $superglobals = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET); | ||
| 457 : | if (isset( $_SESSION )) array_unshift ( $superglobals , $_SESSION ); | ||
| 458 : | |||
| 459 : | // Emulate register_globals on | ||
| 460 : | if (!ini_get('register_globals') && $this->mosConfig_register_globals) { | ||
| 461 : | while(list($key,$value)=each($_GET)) { | ||
| 462 : | if (!isset($GLOBALS[$key])) $GLOBALS[$key]=$value; | ||
| 463 : | } | ||
| 464 : | while(list($key,$value)=each($_POST)) { | ||
| 465 : | if (!isset($GLOBALS[$key])) $GLOBALS[$key]=$value; | ||
| 466 : | } | ||
| 467 : | } | ||
| 468 : | // Emulate register_globals off | ||
| 469 : | elseif (ini_get('register_globals') && !$this->mosConfig_register_globals) { | ||
| 470 : | foreach ( $superglobals as $superglobal ) { | ||
| 471 : | foreach ( $superglobal as $key => $value) { | ||
| 472 : | unset( $GLOBALS[$key]); | ||
| 473 : | unset( $GLOBALS[$key]); | ||
| 474 : | } | ||
| 475 : | } | ||
| 476 : | } | ||
| 477 : | } | ||
| 478 : | |||
| 479 : | /** | ||
| 480 : | * Enter description here... | ||
| 481 : | * | ||
| 482 : | * @return unknown | ||
| 483 : | */ | ||
| 484 : | function determineOptionAndItemid () { | ||
| 485 : | $this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0); | ||
| 486 : | if ($option = strtolower(mosGetParam($_REQUEST, 'option'))); | ||
| 487 : | else { | ||
| 488 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 489 : | $menus =& $menuhandler->getByParentOrder($this->Itemid, 'mainmenu'); | ||
| 490 : | $this->Itemid = $menus[0]->id; | ||
| 491 : | $_REQUEST['Itemid'] = $this->Itemid; | ||
| 492 : | $link = $menus[0]->link; | ||
| 493 : | $pos = strpos( $link, '?' ); | ||
| 494 : | if ($pos !== false) $link = substr( $link, $pos+1 ). '&Itemid='.$this->Itemid; | ||
| 495 : | parse_str( $link, $temp ); | ||
| 496 : | /** this is a patch, need to rework when globals are handled better */ | ||
| 497 : | foreach ($temp as $k=>$v) $_GET[$k] = $_REQUEST[$k] = $v; | ||
| 498 : | if (isset($temp['option'])) $option = $temp['option']; | ||
| 499 : | else return ''; | ||
| 500 : | } | ||
| 501 : | /** patch to lessen the impact on templates */ | ||
| 502 : | if ($option == 'search') $option = 'com_search'; | ||
| 503 : | // checking if we can find the Itemid thru the component | ||
| 504 : | if ($this->Itemid === 0) { | ||
| 505 : | if ( $option == 'com_content') { | ||
| 506 : | require_once($this->rootPath().'/components/com_content/content.class.php'); | ||
| 507 : | $handler =& contentHandler::getInstance(); | ||
| 508 : | $this->Itemid = $handler->getItemid(mosGetParam($_REQUEST, 'id', 0 )); | ||
| 509 : | $_REQUEST['Itemid'] = $this->Itemid; | ||
| 510 : | } | ||
| 511 : | else { | ||
| 512 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 513 : | $this->Itemid = $menuhandler->getIdLikeLink("index.php?option=$option"); | ||
| 514 : | if ($this->Itemid === 0) { | ||
| 515 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 516 : | $menus =& $menuhandler->getByParentOrder($this->Itemid, 'mainmenu'); | ||
| 517 : | } | ||
| 518 : | } | ||
| 519 : | } | ||
| 520 : | return $option; | ||
| 521 : | } | ||
| 522 : | |||
| 523 : | /** | ||
| 524 : | * Enter description here... | ||
| 525 : | * | ||
| 526 : | * @param unknown_type $url | ||
| 527 : | * @param unknown_type $msg | ||
| 528 : | */ | ||
| 529 : | function redirect ($url, $msg='') { | ||
| 530 : | $callcheck = array('InputFilter', 'process'); | ||
| 531 : | if (!is_callable($callcheck)) require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php'); | ||
| 532 : | // specific filters | ||
| 533 : | $iFilter =& new InputFilter(); | ||
| 534 : | $url = $iFilter->process( $url ); | ||
| 535 : | $message = trim($iFilter->process($msg)); | ||
| 536 : | if ($iFilter->badAttributeValue(array('href', $url))) $url = mamboCore::get('mosConfig_live_site'); | ||
| 537 : | if ($message) { | ||
| 538 : | if (strpos($url, '?')) $url .= '&mosmsg='.urlencode($message); | ||
| 539 : | else $url .= '?mosmsg='.urlencode($message); | ||
| 540 : | } | ||
| 541 : | if (headers_sent()) echo "<script>document.location.href='$url';</script>\n"; | ||
| 542 : | else { | ||
| 543 : | @ob_end_clean(); // clear output buffer | ||
| 544 : | header( "Location: $url" ); | ||
| 545 : | } | ||
| 546 : | exit(); | ||
| 547 : | } | ||
| 548 : | |||
| 549 : | /** | ||
| 550 : | * Enter description here... | ||
| 551 : | * | ||
| 552 : | * @param unknown_type $text | ||
| 553 : | */ | ||
| 554 : | function logMessage ($text) { | ||
| 555 : | // JS Popup message | ||
| 556 : | if (mosGetParam( $_POST, 'message', 0 )) { | ||
| 557 : | ?> | ||
| 558 : | <script type="text/javascript"> | ||
| 559 : | <!--// | ||
| 560 : | alert( "<?php echo $text; ?>" ); | ||
| 561 : | //--> | ||
| 562 : | </script> | ||
| 563 : | <?php | ||
| 564 : | } | ||
| 565 : | if ($return = mosGetParam( $_REQUEST, 'return', '' )) { | ||
| 566 : | $this->redirect( $return ); | ||
| 567 : | } | ||
| 568 : | else { | ||
| 569 : | $this->redirect( $this->mosConfig_live_site.'/index.php' ); | ||
| 570 : | } | ||
| 571 : | } | ||
| 572 : | |||
| 573 : | /** | ||
| 574 : | * Enter description here... | ||
| 575 : | * | ||
| 576 : | */ | ||
| 577 : | function handleLogin () { | ||
| 578 : | require_once($this->rootPath().'/includes/authenticator.php'); | ||
| 579 : | $authenticator =& mamboAuthenticator::getInstance(); | ||
| 580 : | $loggedin = $authenticator->loginUser(); | ||
| 581 : | if ($loggedin) $this->logMessage(T_('You have Logged In succesfully')); | ||
| 582 : | else mamboCore::redirect('index.php'); | ||
| 583 : | } | ||
| 584 : | |||
| 585 : | /** | ||
| 586 : | * Enter description here... | ||
| 587 : | * | ||
| 588 : | */ | ||
| 589 : | function handleLogout () { | ||
| 590 : | require_once($this->rootPath().'/includes/authenticator.php'); | ||
| 591 : | $authenticator =& mamboAuthenticator::getInstance(); | ||
| 592 : | $authenticator->logoutUser(); | ||
| 593 : | $this->logMessage(T_('You have Logged Out successfully')); | ||
| 594 : | } | ||
| 595 : | |||
| 596 : | /** | ||
| 597 : | * Enter description here... | ||
| 598 : | * | ||
| 599 : | */ | ||
| 600 : | function standardHeaders () { | ||
| 601 : | header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); | ||
| 602 : | header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); | ||
| 603 : | header( 'Cache-Control: no-store, no-cache, must-revalidate' ); | ||
| 604 : | header( 'Cache-Control: post-check=0, pre-check=0', false ); | ||
| 605 : | header( 'Pragma: no-cache' ); | ||
| 606 : | $mambothandler =& mosMambotHandler::getInstance(); | ||
| 607 : | $mambothandler->loadBotGroup('system'); | ||
| 608 : | $mambothandler->trigger('onHeaders', array($this)); | ||
| 609 : | } | ||
| 610 : | |||
| 611 : | /** | ||
| 612 : | * Enter description here... | ||
| 613 : | * | ||
| 614 : | */ | ||
| 615 : | function initGzip() { | ||
| 616 : | $this->do_gzip_compress = FALSE; | ||
| 617 : | //zlib.output_compression and ob_gzhandler don't get along well so we'll check to make | ||
| 618 : | //that zlib.output_compression is not enable in the php.ini before turning on ob_gzhandler | ||
| 619 : | if ( $this->mosConfig_gzip == 1 AND (int)ini_get('zlib.output_compression') != 1 ) { | ||
| 620 : | $phpver = phpversion(); | ||
| 621 : | $useragent = mosGetParam( $_SERVER, 'HTTP_USER_AGENT', '' ); | ||
| 622 : | $canZip = mosGetParam( $_SERVER, 'HTTP_ACCEPT_ENCODING', '' ); | ||
| 623 : | |||
| 624 : | if ( $phpver >= '4.0.4pl1' AND | ||
| 625 : | ( strpos($useragent,'compatible') !== false || | ||
| 626 : | strpos($useragent,'Gecko') !== false | ||
| 627 : | ) | ||
| 628 : | ) { | ||
| 629 : | if ( extension_loaded('zlib') ) { | ||
| 630 : | ob_start( 'ob_gzhandler' ); | ||
| 631 : | return; | ||
| 632 : | } | ||
| 633 : | } else if ( $phpver > '4.0' ) { | ||
| 634 : | if ( strpos($canZip,'gzip') !== false ) { | ||
| 635 : | if (extension_loaded( 'zlib' )) { | ||
| 636 : | $this->do_gzip_compress = TRUE; | ||
| 637 : | ob_start(); | ||
| 638 : | ob_implicit_flush(0); | ||
| 639 : | |||
| 640 : | header( 'Content-Encoding: gzip' ); | ||
| 641 : | return; | ||
| 642 : | } | ||
| 643 : | } | ||
| 644 : | } | ||
| 645 : | } | ||
| 646 : | ob_start(); | ||
| 647 : | } | ||
| 648 : | |||
| 649 : | /** | ||
| 650 : | * Perform GZIP | ||
| 651 : | */ | ||
| 652 : | function doGzip() { | ||
| 653 : | if ( $this->do_gzip_compress ) { | ||
| 654 : | /** | ||
| 655 : | *Borrowed from php.net! | ||
| 656 : | */ | ||
| 657 : | $gzip_contents = ob_get_contents(); | ||
| 658 : | ob_end_clean(); | ||
| 659 : | |||
| 660 : | $gzip_size = strlen($gzip_contents); | ||
| 661 : | $gzip_crc = crc32($gzip_contents); | ||
| 662 : | |||
| 663 : | $gzip_contents = gzcompress($gzip_contents, 9); | ||
| 664 : | $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4); | ||
| 665 : | |||
| 666 : | echo "\x1f\x8b\x08\x00\x00\x00\x00\x00"; | ||
| 667 : | echo $gzip_contents; | ||
| 668 : | echo pack('V', $gzip_crc); | ||
| 669 : | echo pack('V', $gzip_size); | ||
| 670 : | } else { | ||
| 671 : | ob_end_flush(); | ||
| 672 : | } | ||
| 673 : | } | ||
| 674 : | |||
| 675 : | /** | ||
| 676 : | * Enter description here... | ||
| 677 : | * | ||
| 678 : | * @param unknown_type $separator | ||
| 679 : | * @param unknown_type $field | ||
| 680 : | * @return unknown | ||
| 681 : | */ | ||
| 682 : | function getLastPart ($separator, $field) { | ||
| 683 : | $parts = explode($separator, $field); | ||
| 684 : | return $parts[count($parts)-1]; | ||
| 685 : | } | ||
| 686 : | |||
| 687 : | /** | ||
| 688 : | * Enter description here... | ||
| 689 : | * | ||
| 690 : | * @param unknown_type $separator | ||
| 691 : | * @param unknown_type $field | ||
| 692 : | * @return unknown | ||
| 693 : | */ | ||
| 694 : | function allButLast ($separator, $field) { | ||
| 695 : | $lastSize = strlen(mamboCore::getLastPart($separator,$field)); | ||
| 696 : | return substr($field, 0, strlen($field)-$lastSize); | ||
| 697 : | } | ||
| 698 : | |||
| 699 : | } | ||
| 700 : | |||
| 701 : | |||
| 702 : | /** | ||
| 703 : | * Sorts an Array of objects | ||
| 704 : | */ | ||
| 705 : | class mosObjectSorter { | ||
| 706 : | /** | ||
| 707 : | * Enter description here... | ||
| 708 : | * | ||
| 709 : | * @var unknown_type | ||
| 710 : | */ | ||
| 711 : | var $_keyname = ''; | ||
| 712 : | /** | ||
| 713 : | * Enter description here... | ||
| 714 : | * | ||
| 715 : | * @var unknown_type | ||
| 716 : | */ | ||
| 717 : | var $_direction = 0; | ||
| 718 : | /** | ||
| 719 : | * Enter description here... | ||
| 720 : | * | ||
| 721 : | * @var unknown_type | ||
| 722 : | */ | ||
| 723 : | var $_object_array = array(); | ||
| 724 : | |||
| 725 : | /** | ||
| 726 : | * Enter description here... | ||
| 727 : | * | ||
| 728 : | * @param unknown_type $a | ||
| 729 : | * @param unknown_type $k | ||
| 730 : | * @param unknown_type $sort_direction | ||
| 731 : | * @return mosObjectSorter | ||
| 732 : | */ | ||
| 733 : | function mosObjectSorter (&$a, $k, $sort_direction=1) { | ||
| 734 : | $this->_keyname = $k; | ||
| 735 : | $this->_direction = $sort_direction; | ||
| 736 : | $this->_object_array =& $a; | ||
| 737 : | $this->sort(); | ||
| 738 : | } | ||
| 739 : | |||
| 740 : | /** | ||
| 741 : | * Enter description here... | ||
| 742 : | * | ||
| 743 : | * @param unknown_type $a | ||
| 744 : | * @param unknown_type $b | ||
| 745 : | * @return unknown | ||
| 746 : | */ | ||
| 747 : | function mosObjectCompare (&$a, &$b) { | ||
| 748 : | $key = $this->_keyname; | ||
| 749 : | if ($a->$key > $b->$key) return $this->_direction; | ||
| 750 : | if ($a->$key < $b->$key) return -$this->_direction; | ||
| 751 : | return 0; | ||
| 752 : | } | ||
| 753 : | |||
| 754 : | /** | ||
| 755 : | * Enter description here... | ||
| 756 : | * | ||
| 757 : | */ | ||
| 758 : | function sort () { | ||
| 759 : | usort($this->_object_array, array($this,'mosObjectCompare')); | ||
| 760 : | } | ||
| 761 : | |||
| 762 : | } | ||
| 763 : | |||
| 764 : | /** | ||
| 765 : | * Pathway handler | ||
| 766 : | * @package Mambo | ||
| 767 : | */ | ||
| 768 : | class mosPathway { | ||
| 769 : | /** @var array Names for display in pathway */ | ||
| 770 : | var $_names = null; | ||
| 771 : | /** @var array URLs for links from pathway */ | ||
| 772 : | var $_urls = null; | ||
| 773 : | |||
| 774 : | /** | ||
| 775 : | * Constructor | ||
| 776 : | */ | ||
| 777 : | function mosPathway () { | ||
| 778 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 779 : | $menus =& $menuhandler->getByParentOrder(0,'mainmenu'); | ||
| 780 : | $home = $menus[0]; | ||
| 781 : | $this->_names[] = $home->name; | ||
| 782 : | $this->_urls[] = sefRelToAbs($home->link."&Itemid=$home->id"); | ||
| 783 : | } | ||
| 784 : | |||
| 785 : | /** | ||
| 786 : | * Singleton accessor | ||
| 787 : | */ | ||
| 788 : | function &getInstance () { | ||
| 789 : | static $instance; | ||
| 790 : | if (!is_object($instance)) $instance = new mosPathway(); | ||
| 791 : | return $instance; | ||
| 792 : | } | ||
| 793 : | |||
| 794 : | /** | ||
| 795 : | * Add an item to the pathway | ||
| 796 : | */ | ||
| 797 : | function addItem ($name, $givenurl) { | ||
| 798 : | $last = count($this->_names) - 1; | ||
| 799 : | if (!$name) return; | ||
| 800 : | $url = sefRelToAbs($givenurl); | ||
| 801 : | if ($name == $this->_names[$last] AND $url == $this->_urls[$last]) return; | ||
| 802 : | $this->_names[$last+1] = $name; | ||
| 803 : | $this->_urls[$last+1] = $url; | ||
| 804 : | } | ||
| 805 : | |||
| 806 : | /** | ||
| 807 : | * Enter description here... | ||
| 808 : | * | ||
| 809 : | */ | ||
| 810 : | function reduceToOne () { | ||
| 811 : | for ($i = count($this->_names) - 1; $i > 0; $i--) { | ||
| 812 : | unset($this->_names[$i]); | ||
| 813 : | unset($this->_urls[$i]); | ||
| 814 : | } | ||
| 815 : | } | ||
| 816 : | |||
| 817 : | /** | ||
| 818 : | * Make a pathway string for display | ||
| 819 : | */ | ||
| 820 : | function makePathway () { | ||
| 821 : | $mainframe =& mosMainFrame::getInstance(); | ||
| 822 : | $customs = $mainframe->getCustomPathWay(); | ||
| 823 : | $last = count($this->_names) - 1; | ||
| 824 : | if ($last == 0 AND count($customs == 0)) return ''; | ||
| 825 : | $result = "<span class='pathway'>"; | ||
| 826 : | $config =& mamboCore::getMamboCore(); | ||
| 827 : | $rootpath = $config->rootPath(); | ||
| 828 : | $imgPath = 'templates/'.$mainframe->getTemplate().'/images/arrow.png'; | ||
| 829 : | if (file_exists( "$rootpath/$imgPath" )) $img = "<img src='$config->mosConfig_live_site/$imgPath' border='0' alt='arrow' />"; | ||
| 830 : | else { | ||
| 831 : | $imgPath = '/images/M_images/arrow.png'; | ||
| 832 : | if (file_exists( "$rootpath/$imgPath" )) $img = "<img src='$config->mosConfig_live_site/images/M_images/arrow.png' alt='arrow' />"; | ||
| 833 : | else $img = '>'; | ||
| 834 : | } | ||
| 835 : | foreach ($this->_names as $i=>$name) { | ||
| 836 : | if ($i === $last AND count($customs) == 0) $result .= "$name</span>"; | ||
| 837 : | elseif (strstr($this->_urls[$i], 'view')) $result .= ""; | ||
| 838 : | else { | ||
| 839 : | $sefurl = sefRelToAbs($this->_urls[$i]); | ||
| 840 : | $result .= "<a href='$sefurl' class='pathway'>$name</a>"; | ||
| 841 : | $result .= " $img "; | ||
| 842 : | } | ||
| 843 : | } | ||
| 844 : | foreach ($customs as $custom) $result .= $custom; | ||
| 845 : | if (count($customs)) $result .= '</span>'; | ||
| 846 : | return $result; | ||
| 847 : | } | ||
| 848 : | |||
| 849 : | } | ||
| 850 : | |||
| 851 : | /** | ||
| 852 : | * Module database table class | ||
| 853 : | * @package Mambo | ||
| 854 : | */ | ||
| 855 : | class mosMenu extends mosDBTable { | ||
| 856 : | /** @var int Primary key */ | ||
| 857 : | var $id=null; | ||
| 858 : | /** @var string */ | ||
| 859 : | var $menutype=null; | ||
| 860 : | /** @var string */ | ||
| 861 : | var $name=null; | ||
| 862 : | /** @var string */ | ||
| 863 : | var $link=null; | ||
| 864 : | /** @var int */ | ||
| 865 : | var $type=null; | ||
| 866 : | /** @var int */ | ||
| 867 : | var $published=null; | ||
| 868 : | /** @var int */ | ||
| 869 : | var $componentid=null; | ||
| 870 : | /** @var int */ | ||
| 871 : | var $parent=null; | ||
| 872 : | /** @var int */ | ||
| 873 : | var $sublevel=null; | ||
| 874 : | /** @var int */ | ||
| 875 : | var $ordering=null; | ||
| 876 : | /** @var boolean */ | ||
| 877 : | var $checked_out=null; | ||
| 878 : | /** @var datetime */ | ||
| 879 : | var $checked_out_time=null; | ||
| 880 : | /** @var boolean */ | ||
| 881 : | var $pollid=null; | ||
| 882 : | |||
| 883 : | /** @var string */ | ||
| 884 : | var $browserNav=null; | ||
| 885 : | /** @var int */ | ||
| 886 : | var $access=null; | ||
| 887 : | /** @var int */ | ||
| 888 : | var $utaccess=null; | ||
| 889 : | /** @var string */ | ||
| 890 : | var $params=null; | ||
| 891 : | |||
| 892 : | /** | ||
| 893 : | * @param database A database connector object | ||
| 894 : | */ | ||
| 895 : | function mosMenu() { | ||
| 896 : | $db =& mamboDatabase::getInstance(); | ||
| 897 : | $this->mosDBTable( '#__menu', 'id', $db ); | ||
| 898 : | } | ||
| 899 : | /** | ||
| 900 : | * binds an array/hash to this object | ||
| 901 : | * @param int $oid optional argument, if not specifed then the value of current key is used | ||
| 902 : | * @return any result from the database operation | ||
| 903 : | */ | ||
| 904 : | function load( $oid=null ) { | ||
| 905 : | $k = $this->_tbl_key; | ||
| 906 : | if ($oid !== null) $this->$k = $oid; | ||
| 907 : | if ($this->$k === null) return false; | ||
| 908 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 909 : | $menu =& $menuhandler->getMenuById($this->$k); | ||
| 910 : | if ($menu) { | ||
| 911 : | foreach (get_object_vars($menu) as $key=>$data) $this->$key = $data; | ||
| 912 : | return true; | ||
| 913 : | } | ||
| 914 : | else return false; | ||
| 915 : | } | ||
| 916 : | |||
| 917 : | } | ||
| 918 : | |||
| 919 : | /** | ||
| 920 : | * File Manager including safe mode provision? | ||
| 921 : | * @package Mambo | ||
| 922 : | */ | ||
| 923 : | class mosFileManager { | ||
| 924 : | |||
| 925 : | /** | ||
| 926 : | * Singleton accessor | ||
| 927 : | */ | ||
| 928 : | function &getInstance () { | ||
| 929 : | static $instance; | ||
| 930 : | if (!is_object($instance)) $instance = new mosFileManager(); | ||
| 931 : | return $instance; | ||
| 932 : | } | ||
| 933 : | |||
| 934 : | /** | ||
| 935 : | * Enter description here... | ||
| 936 : | * | ||
| 937 : | * @param unknown_type $file | ||
| 938 : | * @return unknown | ||
| 939 : | */ | ||
| 940 : | function deleteFile ($file) { | ||
| 941 : | if (file_exists($file)) { | ||
| 942 : | @chmod($file, 0644); | ||
| 943 : | return unlink($file); | ||
| 944 : | } | ||
| 945 : | return true; | ||
| 946 : | } | ||
| 947 : | |||
| 948 : | /** | ||
| 949 : | * Enter description here... | ||
| 950 : | * | ||
| 951 : | * @param unknown_type $dir | ||
| 952 : | * @return unknown | ||
| 953 : | */ | ||
| 954 : | function deleteDirectory ($dir) { | ||
| 955 : | if (file_exists($dir)) { | ||
| 956 : | if (is_dir($dir)) { | ||
| 957 : | @chmod($dir, 0755); | ||
| 958 : | return rmdir($dir); | ||
| 959 : | } | ||
| 960 : | return false; | ||
| 961 : | } | ||
| 962 : | return true; | ||
| 963 : | } | ||
| 964 : | |||
| 965 : | /** | ||
| 966 : | * Enter description here... | ||
| 967 : | * | ||
| 968 : | * @param unknown_type $fileSysObject | ||
| 969 : | */ | ||
| 970 : | function setPermissions ($fileSysObject) { | ||
| 971 : | if (file_exists($fileSysObject)) { | ||
| 972 : | if (is_dir($fileSysObject)) $perms = mamboCore::get('mosConfig_dirperms'); | ||
| 973 : | else $perms = mamboCore::get('mosConfig_fileperms'); | ||
| 974 : | if ($perms) { | ||
| 975 : | $origmask = @umask(0); | ||
| 976 : | $mode = octdec($perms); | ||
| 977 : | @chmod($fileSysObject, $mode); | ||
| 978 : | @umask($origmask); | ||
| 979 : | } | ||
| 980 : | } | ||
| 981 : | } | ||
| 982 : | |||
| 983 : | /** | ||
| 984 : | * Enter description here... | ||
| 985 : | * | ||
| 986 : | * @param unknown_type $dir | ||
| 987 : | * @return unknown | ||
| 988 : | */ | ||
| 989 : | function makeDirectory ($dir) { | ||
| 990 : | $perms = mamboCore::get('mosConfig_dirperms'); | ||
| 991 : | $origmask = @umask(0); | ||
| 992 : | if ($perms) $result = @mkdir($dir, octdec($perms)); | ||
| 993 : | else $result = @mkdir($dir, 0755); | ||
| 994 : | if ($result) $this->setPermissions($dir); | ||
| 995 : | @umask($origmask); | ||
| 996 : | return $result; | ||
| 997 : | } | ||
| 998 : | |||
| 999 : | |||
| 1000 : | /** | ||
| 1001 : | * Enter description here... | ||
| 1002 : | * | ||
| 1003 : | * @param unknown_type $dir | ||
| 1004 : | * @param unknown_type $onlyCheck | ||
| 1005 : | * @return unknown | ||
| 1006 : | */ | ||
| 1007 : | function createDirectory ($dir, $onlyCheck=false) { | ||
| 1008 : | if (file_exists($dir)) { | ||
| 1009 : | if (is_dir($dir) AND is_writable($dir)) return true; | ||
| 1010 : | else return false; | ||
| 1011 : | } | ||
| 1012 : | list($upDirectory, $count) = $this->containingDirectory($dir); | ||
| 1013 : | if ($count > 1 AND !file_exists($upDirectory) AND !($result = $this->createDirectory($upDirectory, $onlyCheck))) return false; | ||
| 1014 : | if ($onlyCheck AND isset($result)) return true; | ||
| 1015 : | if (!is_dir($upDirectory) OR !is_writable($upDirectory)) return false; | ||
| 1016 : | if ($onlyCheck) return true; | ||
| 1017 : | else return $this->makeDirectory($dir); | ||
| 1018 : | } | ||
| 1019 : | |||
| 1020 : | /** | ||
| 1021 : | * Enter description here... | ||
| 1022 : | * | ||
| 1023 : | * @param unknown_type $dir | ||
| 1024 : | * @return unknown | ||
| 1025 : | */ | ||
| 1026 : | function containingDirectory ($dir) { | ||
| 1027 : | $dirs = preg_split('*[/|\\\]*', $dir); | ||
| 1028 : | for ($i = count($dirs)-1; $i >= 0; $i--) { | ||
| 1029 : | $text = trim($dirs[$i]); | ||
| 1030 : | unset($dirs[$i]); | ||
| 1031 : | if ($text) break; | ||
| 1032 : | } | ||
| 1033 : | $result2 = count($dirs); | ||
| 1034 : | $result1 = implode('/',$dirs).($result2 > 1 ? '' : '/'); | ||
| 1035 : | return array($result1, $result2); | ||
| 1036 : | } | ||
| 1037 : | |||
| 1038 : | /** | ||
| 1039 : | * Enter description here... | ||
| 1040 : | * | ||
| 1041 : | * @param unknown_type $from | ||
| 1042 : | * @param unknown_type $to | ||
| 1043 : | * @return unknown | ||
| 1044 : | */ | ||
| 1045 : | function simpleCopy ($from, $to) { | ||
| 1046 : | if (@copy($from, $to)) { | ||
| 1047 : | $this->setPermissions($to); | ||
| 1048 : | return true; | ||
| 1049 : | } | ||
| 1050 : | else return false; | ||
| 1051 : | } | ||
| 1052 : | |||
| 1053 : | /** | ||
| 1054 : | * Enter description here... | ||
| 1055 : | * | ||
| 1056 : | * @param unknown_type $from | ||
| 1057 : | * @param unknown_type $to | ||
| 1058 : | * @return unknown | ||
| 1059 : | */ | ||
| 1060 : | function forceCopy ($from, $to) { | ||
| 1061 : | $todir = dirname($to); | ||
| 1062 : | if (!file_exists($todir)) $this->createDirectory($todir); | ||
| 1063 : | if (!file_exists($todir)) return false; | ||
| 1064 : | $name = basename($from); | ||
| 1065 : | $this->deleteFile($to.$name); | ||
| 1066 : | return $this->simpleCopy ($from, $to); | ||
| 1067 : | } | ||
| 1068 : | |||
| 1069 : | /** | ||
| 1070 : | * Enter description here... | ||
| 1071 : | * | ||
| 1072 : | * @param unknown_type $from | ||
| 1073 : | * @param unknown_type $to | ||
| 1074 : | * @return unknown | ||
| 1075 : | */ | ||
| 1076 : | function lightCopy ($from, $to) { | ||
| 1077 : | $name = basename($from); | ||
| 1078 : | if (file_exists($to.$name)) return false; | ||
| 1079 : | $todir = dirname($to); | ||
| 1080 : | if (!file_exists($todir)) $this->createDirectory($todir); | ||
| 1081 : | if (!file_exists($todir)) return false; | ||
| 1082 : | return $this->simpleCopy ($from, $to); | ||
| 1083 : | } | ||
| 1084 : | |||
| 1085 : | /** | ||
| 1086 : | * Enter description here... | ||
| 1087 : | * | ||
| 1088 : | * @param unknown_type $to | ||
| 1089 : | * @return unknown | ||
| 1090 : | */ | ||
| 1091 : | function acceptCopy ($to) { | ||
| 1092 : | $todir = dirname($to); | ||
| 1093 : | return $this->createDirectory($todir, true); | ||
| 1094 : | } | ||
| 1095 : | |||
| 1096 : | |||
| 1097 : | /** | ||
| 1098 : | * Function to strip additional / or \ in a path name | ||
| 1099 : | * @param string The path | ||
| 1100 : | * @param boolean Add trailing slash | ||
| 1101 : | */ | ||
| 1102 : | function mosPathName($p_path, $p_addtrailingslash=true) { | ||
| 1103 : | if (substr(PHP_OS, 0, 3) == 'WIN') { | ||
| 1104 : | $retval = str_replace( '/', '\\', $p_path ); | ||
| 1105 : | if ($p_addtrailingslash AND substr( $retval, -1 ) != '\\') $retval .= '\\'; | ||
| 1106 : | // Remove double \\ | ||
| 1107 : | $retval = str_replace( '\\\\', '\\', $retval ); | ||
| 1108 : | } | ||
| 1109 : | else { | ||
| 1110 : | $retval = str_replace( '\\', '/', $p_path ); | ||
| 1111 : | if ($p_addtrailingslash AND substr( $retval, -1 ) != '/') $retval .= '/'; | ||
| 1112 : | // Remove double // | ||
| 1113 : | $retval = str_replace('//','/',$retval); | ||
| 1114 : | } | ||
| 1115 : | return $retval; | ||
| 1116 : | } | ||
| 1117 : | |||
| 1118 : | /** | ||
| 1119 : | * Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up. | ||
| 1120 : | * @param path The starting file or directory (no trailing slash) | ||
| 1121 : | * @param filemode Integer value to chmod files. NULL = dont chmod files. | ||
| 1122 : | * @param dirmode Integer value to chmod directories. NULL = dont chmod directories. | ||
| 1123 : | * @return TRUE=all succeeded FALSE=one or more chmods failed | ||
| 1124 : | */ | ||
| 1125 : | function mosChmod($path) | ||
| 1126 : | { | ||
| 1127 : | $fileperms = mamboCore::get('mosConfig_fileperms'); | ||
| 1128 : | if ($fileperms != '') $filemode = octdec($fileperms); | ||
| 1129 : | else $filemode = null; | ||
| 1130 : | $dirperms = mamboCore::get('mosConfig_dirperms'); | ||
| 1131 : | if ($dirperms != '') $dirmode = octdec($dirperms); | ||
| 1132 : | else $dirmode = null; | ||
| 1133 : | if (isset($filemode) OR isset($dirmode)) | ||
| 1134 : | return $this->mosChmodRecursive($path, $filemode, $dirmode); | ||
| 1135 : | return true; | ||
| 1136 : | } // mosChmod | ||
| 1137 : | |||
| 1138 : | /** | ||
| 1139 : | * Chmods files and directories recursively to given permissions. Available from 4.5.2 up. | ||
| 1140 : | * @param path The starting file or directory (no trailing slash) | ||
| 1141 : | * @param filemode Integer value to chmod files. NULL = dont chmod files. | ||
| 1142 : | * @param dirmode Integer value to chmod directories. NULL = dont chmod directories. | ||
| 1143 : | * @return TRUE=all succeeded FALSE=one or more chmods failed | ||
| 1144 : | */ | ||
| 1145 : | function mosChmodRecursive($path, $filemode=NULL, $dirmode=NULL) { | ||
| 1146 : | $ret = true; | ||
| 1147 : | if (is_dir($path)) { | ||
| 1148 : | $topdir =& new mosDirectory($path); | ||
| 1149 : | $files =& $topdir->listFiles ('', 'file', true, true); | ||
| 1150 : | $dirs =& $topdir->listFiles ('', 'dir', true, true); | ||
| 1151 : | } | ||
| 1152 : | else { | ||
| 1153 : | $files = array($path); | ||
| 1154 : | $dirs = array(); | ||
| 1155 : | } | ||
| 1156 : | if (isset($filemode)) foreach ($files as $file) $ret = @chmod($file, $filemode) ? $ret : false; | ||
| 1157 : | if (isset($dirmode)) foreach ($dirs as $dir) $ret = @chmod($dir, $dirmode) ? $ret : false; | ||
| 1158 : | return $ret; | ||
| 1159 : | } | ||
| 1160 : | |||
| 1161 : | } | ||
| 1162 : | |||
| 1163 : | /** | ||
| 1164 : | * Enter description here... | ||
| 1165 : | * | ||
| 1166 : | */ | ||
| 1167 : | class mosDirectory { | ||
| 1168 : | /** | ||
| 1169 : | * Enter description here... | ||
| 1170 : | * | ||
| 1171 : | * @var unknown_type | ||
| 1172 : | */ | ||
| 1173 : | var $path = ''; | ||
| 1174 : | |||
| 1175 : | /** | ||
| 1176 : | * Enter description here... | ||
| 1177 : | * | ||
| 1178 : | * @param unknown_type $path | ||
| 1179 : | * @return mosDirectory | ||
| 1180 : | */ | ||
| 1181 : | function mosDirectory ($path) { | ||
| 1182 : | $path = str_replace('\\', '/', $path); | ||
| 1183 : | if (substr($path,-1,1) == '/') $this->path = $path; | ||
| 1184 : | else $this->path = $path.'/'; | ||
| 1185 : | } | ||
| 1186 : | |||
| 1187 : | /** | ||
| 1188 : | * Enter description here... | ||
| 1189 : | * | ||
| 1190 : | * @param unknown_type $type | ||
| 1191 : | * @param unknown_type $recurse | ||
| 1192 : | * @param unknown_type $fullpath | ||
| 1193 : | * @return unknown | ||
| 1194 : | */ | ||
| 1195 : | function &listAll ($type='file', $recurse=false, $fullpath=false) { | ||
| 1196 : | $results = array(); | ||
| 1197 : | if ($dir = @opendir($this->path)) { | ||
| 1198 : | while (false !== ($file = readdir($dir))) { | ||
| 1199 : | if ($file == '.' OR $file == '..') continue; | ||
| 1200 : | if (is_dir($this->path.$file)) { | ||
| 1201 : | if ($recurse) { | ||
| 1202 : | $subdir = new mosDirectory($this->path.$file); | ||
| 1203 : | $results = array_merge($results, $subdir->listAll($type, $recurse, $fullpath)); | ||
| 1204 : | unset($subdir); | ||
| 1205 : | } | ||
| 1206 : | if ($type == 'file') continue; | ||
| 1207 : | } | ||
| 1208 : | elseif ($type == 'dir') continue; | ||
| 1209 : | if ($fullpath) $results[] = $this->path.$file; | ||
| 1210 : | else $results[] = $file; | ||
| 1211 : | } | ||
| 1212 : | closedir($dir); | ||
| 1213 : | arpee | 1348 | } |
| 1214 : | asort($results); | ||
| 1215 : | alwarren | 1331 | return $results; |
| 1216 : | } | ||
| 1217 : | |||
| 1218 : | /** | ||
| 1219 : | * Enter description here... | ||
| 1220 : | * | ||
| 1221 : | * @return unknown | ||
| 1222 : | */ | ||
| 1223 : | function soleDir () { | ||
| 1224 : | $found = ''; | ||
| 1225 : | if ($dir = @opendir($this->path)) { | ||
| 1226 : | while (false !== ($file = readdir($dir))) { | ||
| 1227 : | if ($file == '.' OR $file == '..') continue; | ||
| 1228 : | if (is_dir($this->path.$file)) { | ||
| 1229 : | if ($found) return ''; | ||
| 1230 : | else $found = $file; | ||
| 1231 : | } | ||
| 1232 : | else return ''; | ||
| 1233 : | } | ||
| 1234 : | closedir($dir); | ||
| 1235 : | } | ||
| 1236 : | return $found; | ||
| 1237 : | } | ||
| 1238 : | |||
| 1239 : | /** | ||
| 1240 : | * Enter description here... | ||
| 1241 : | * | ||
| 1242 : | */ | ||
| 1243 : | function deleteAll () { | ||
| 1244 : | if (!file_exists($this->path)) return; | ||
| 1245 : | $subdirs =& $this->listAll ('dir', false, true); | ||
| 1246 : | foreach ($subdirs as $subdir) { | ||
| 1247 : | $subdirectory = new mosDirectory($subdir); | ||
| 1248 : | $subdirectory->deleteAll(); | ||
| 1249 : | unset($subdirectory); | ||
| 1250 : | } | ||
| 1251 : | $filemanager =& mosFileManager::getInstance(); | ||
| 1252 : | $files =& $this->listAll ('file', false, true); | ||
| 1253 : | foreach ($files as $file) $filemanager->deleteFile($file); | ||
| 1254 : | $filemanager->deleteDirectory($this->path); | ||
| 1255 : | } | ||
| 1256 : | |||
| 1257 : | /** | ||
| 1258 : | * Enter description here... | ||
| 1259 : | * | ||
| 1260 : | * @return unknown | ||
| 1261 : | */ | ||
| 1262 : | function createFresh () { | ||
| 1263 : | $this->deleteAll(); | ||
| 1264 : | $filemanager =& mosFileManager::getInstance(); | ||
| 1265 : | $filemanager->createDirectory($this->path); | ||
| 1266 : | return true; | ||
| 1267 : | } | ||
| 1268 : | |||
| 1269 : | /** | ||
| 1270 : | * Enter description here... | ||
| 1271 : | * | ||
| 1272 : | */ | ||
| 1273 : | function createIfNeeded () { | ||
| 1274 : | if (!file_exists($this->path)) { | ||
| 1275 : | $filemanager =& mosFileManager::getInstance(); | ||
| 1276 : | $filemanager->createDirectory($this->path); | ||
| 1277 : | } | ||
| 1278 : | } | ||
| 1279 : | |||
| 1280 : | /** | ||
| 1281 : | * Enter description here... | ||
| 1282 : | * | ||
| 1283 : | * @param unknown_type $pattern | ||
| 1284 : | * @param unknown_type $type | ||
| 1285 : | * @param unknown_type $recurse | ||
| 1286 : | * @param unknown_type $fullpath | ||
| 1287 : | * @return unknown | ||
| 1288 : | */ | ||
| 1289 : | function &listFiles ($pattern='', $type='file', $recurse=false, $fullpath=false) { | ||
| 1290 : | $results = array(); | ||
| 1291 : | $all =& $this->listAll($type, $recurse, $fullpath); | ||
| 1292 : | foreach ($all as $file) { | ||
| 1293 : | $name = basename($file); | ||
| 1294 : | if ($pattern AND !preg_match( "/$pattern/", $name )) continue; | ||
| 1295 : | if (($name != 'index.html') AND ($name[0] != '.')) $results[] = $file; | ||
| 1296 : | } | ||
| 1297 : | return $results; | ||
| 1298 : | } | ||
| 1299 : | |||
| 1300 : | /** | ||
| 1301 : | * Enter description here... | ||
| 1302 : | * | ||
| 1303 : | * @return unknown | ||
| 1304 : | */ | ||
| 1305 : | function getSize () { | ||
| 1306 : | $totalsize = 0; | ||
| 1307 : | $files =& $this->listFiles(); | ||
| 1308 : | foreach ($files as $file) $totalsize += filesize($this->path.$file); | ||
| 1309 : | return $totalsize; | ||
| 1310 : | } | ||
| 1311 : | |||
| 1312 : | } | ||
| 1313 : | |||
| 1314 : | |||
| 1315 : | /** | ||
| 1316 : | * Menu handler | ||
| 1317 : | * @package Mambo | ||
| 1318 : | */ | ||
| 1319 : | class mosMenuHandler { | ||
| 1320 : | /** @var array Menu objects currently available */ | ||
| 1321 : | var $_menus = null; | ||
| 1322 : | /** @var array Counts of menu items by type and published status */ | ||
| 1323 : | var $_counts = null; | ||
| 1324 : | /** @var array Access to stored menu objects by ID */ | ||
| 1325 : | var $_idlinks = null; | ||
| 1326 : | /** @var array Items that may be useful for setting Itemid */ | ||
| 1327 : | var $_byParentOrder = null; | ||
| 1328 : | |||
| 1329 : | /** | ||
| 1330 : | * Constructor | ||
| 1331 : | */ | ||
| 1332 : | function mosMenuHandler() { | ||
| 1333 : | $database =& mamboDatabase::getInstance(); | ||
| 1334 : | $sql = "SELECT * FROM #__menu ORDER BY name"; | ||
| 1335 : | $this->_menus =& $database->doSQLget($sql, 'mosMenu'); | ||
| 1336 : | if (!$this->_menus) $this->_menus = array(); | ||
| 1337 : | foreach ($this->_menus as $key=>$menu) { | ||
| 1338 : | $this->_idlinks[$menu->id] = $key; | ||
| 1339 : | if ($menu->published == 1) $this->_byParentOrder[$menu->parent][$menu->ordering][$menu->menutype] = $key; | ||
| 1340 : | if (isset($this->_counts[$menu->menutype][$menu->published])) $this->_counts[$menu->menutype][$menu->published]++; | ||
| 1341 : | else $this->_counts[$menu->menutype][$menu->published] = 1; | ||
| 1342 : | } | ||
| 1343 : | if ($this->_byParentOrder) { | ||
| 1344 : | foreach ($this->_byParentOrder as $parent=>$outer) ksort($this->_byParentOrder[$parent]); | ||
| 1345 : | ksort($this->_byParentOrder); | ||
| 1346 : | } | ||
| 1347 : | } | ||
| 1348 : | /** | ||
| 1349 : | * Singleton accessor | ||
| 1350 : | */ | ||
| 1351 : | function &getInstance () { | ||
| 1352 : | static $instance; | ||
| 1353 : | if (!is_object($instance)) $instance = new mosMenuHandler(); | ||
| 1354 : | return $instance; | ||
| 1355 : | } | ||
| 1356 : | |||
| 1357 : | /** | ||
| 1358 : | * Enter description here... | ||
| 1359 : | * | ||
| 1360 : | * @param unknown_type $id | ||
| 1361 : | * @return unknown | ||
| 1362 : | */ | ||
| 1363 : | function &getMenuByID ($id) { | ||
| 1364 : | if (isset($this->_idlinks[$id])) { | ||
| 1365 : | $key = $this->_idlinks[$id]; | ||
| 1366 : | $result = $this->_menus[$key]; | ||
| 1367 : | } | ||
| 1368 : | else $result = null; | ||
| 1369 : | return $result; | ||
| 1370 : | } | ||
| 1371 : | |||
| 1372 : | /** | ||
| 1373 : | * Enter description here... | ||
| 1374 : | * | ||
| 1375 : | * @param unknown_type $type | ||
| 1376 : | * @param unknown_type $published | ||
| 1377 : | * @return unknown | ||
| 1378 : | */ | ||
| 1379 : | function getMenuCount ($type, $published) { | ||
| 1380 : | if (isset($this->_counts[$type][$published])) return $this->_counts[$type][$published]; | ||
| 1381 : | else return 0; | ||
| 1382 : | } | ||
| 1383 : | |||
| 1384 : | /** | ||
| 1385 : | * Enter description here... | ||
| 1386 : | * | ||
| 1387 : | * @param unknown_type $types | ||
| 1388 : | * @return unknown | ||
| 1389 : | */ | ||
| 1390 : | function &getMenusByType ($types) { | ||
| 1391 : | $checker = explode(',', $types); | ||
| 1392 : | $result = null; | ||
| 1393 : | foreach ($this->_menus as $menu) { | ||
| 1394 : | if (in_array($menu->menutype, $checker)) $result[] = $menu; | ||
| 1395 : | } | ||
| 1396 : | return $result; | ||
| 1397 : | } | ||
| 1398 : | |||
| 1399 : | /** | ||
| 1400 : | * Enter description here... | ||
| 1401 : | * | ||
| 1402 : | * @return unknown | ||
| 1403 : | */ | ||
| 1404 : | function &getMenuTypes () { | ||
| 1405 : | $types = array(); | ||
| 1406 : | foreach ($this->_menus as $menu) { | ||
| 1407 : | if (!isset($types[$menu->menutype])) $types[$menu->menutype] = 0; | ||
| 1408 : | $types[$menu->menutype]++; | ||
| 1409 : | } | ||
| 1410 : | return $types; | ||
| 1411 : | } | ||
| 1412 : | |||
| 1413 : | /** | ||
| 1414 : | * Enter description here... | ||
| 1415 : | * | ||
| 1416 : | * @param unknown_type $type | ||
| 1417 : | * @param unknown_type $link | ||
| 1418 : | * @return unknown | ||
| 1419 : | */ | ||
| 1420 : | function getIDByTypeLink ($type, $link) { | ||
| 1421 : | foreach ($this->_menus as $menu) { | ||
| 1422 : | if ($menu->published == 1 AND ($type == '*' OR $menu->type == $type) AND $menu->link == $link) return $menu->id; | ||
| 1423 : | } | ||
| 1424 : | return null; | ||
| 1425 : | } | ||
| 1426 : | |||
| 1427 : | /** | ||
| 1428 : | * Enter description here... | ||
| 1429 : | * | ||
| 1430 : | * @param unknown_type $link | ||
| 1431 : | * @return unknown | ||
| 1432 : | */ | ||
| 1433 : | function getIDLikeLink ($link) { | ||
| 1434 : | $exact = $this->getIdByTypeLink('*', $link); | ||
| 1435 : | if ($exact !== null) return $exact; | ||
| 1436 : | foreach ($this->_menus as $menu) { | ||
| 1437 : | if ($menu->published == 1 AND strpos($menu->link,$link) === 0) return $menu->id; | ||
| 1438 : | } | ||
| 1439 : | return 0; | ||
| 1440 : | } | ||
| 1441 : | |||
| 1442 : | /** | ||
| 1443 : | * Enter description here... | ||
| 1444 : | * | ||
| 1445 : | * @param unknown_type $type | ||
| 1446 : | * @param unknown_type $componentid | ||
| 1447 : | * @return unknown | ||
| 1448 : | */ | ||
| 1449 : | function getIDByTypeCid ($type, $componentid) { | ||
| 1450 : | foreach ($this->_menus as $menu) { | ||
| 1451 : | if ($menu->published == 1 AND $menu->type == $type AND $menu->componentid == $componentid) return $menu->id; | ||
| 1452 : | } | ||
| 1453 : | return null; | ||
| 1454 : | } | ||
| 1455 : | |||
| 1456 : | /** | ||
| 1457 : | * Enter description here... | ||
| 1458 : | * | ||
| 1459 : | * @return unknown | ||
| 1460 : | */ | ||
| 1461 : | function getGlobalBlogSectionCount () { | ||
| 1462 : | $count = 0; | ||
| 1463 : | foreach ($this->_menus as $menu) { | ||
| 1464 : | if ($menu->type == 'content_blog_section' AND $menu->published == 1 AND $menu->componentid == 0) $count++; | ||
| 1465 : | } | ||
| 1466 : | return $count; | ||
| 1467 : | } | ||
| 1468 : | |||
| 1469 : | /** | ||
| 1470 : | * Enter description here... | ||
| 1471 : | * | ||
| 1472 : | * @param unknown_type $Itemid | ||
| 1473 : | * @param unknown_type $type | ||
| 1474 : | * @param unknown_type $id | ||
| 1475 : | * @param unknown_type $catid | ||
| 1476 : | * @return unknown | ||
| 1477 : | */ | ||
| 1478 : | function getContentItemid ($Itemid, $type, $id, $catid=0) { | ||
| 1479 : | if ($Itemid) return $Itemid; | ||
| 1480 : | foreach ($this->_menus as $menu) { | ||
| 1481 : | if (strpos($menu->link,'index.php?option=com_content') === false AND strpos($menu->link,'index.php?option=content') === false) continue; | ||
| 1482 : | if (strpos($menu->link, $type) === false) continue; | ||
| 1483 : | if ($catid) { | ||
| 1484 : | if (strpos($menu->link, "&id=$catid") === false) continue; | ||
| 1485 : | if (strpos($menu->link, "§ionid=$id") === false) continue; | ||
| 1486 : | } | ||
| 1487 : | elseif (strpos($menu->link, "&id=$id") === false) continue; | ||
| 1488 : | return $menu->id; | ||
| 1489 : | } | ||
| 1490 : | return 0; | ||
| 1491 : | } | ||
| 1492 : | |||
| 1493 : | /** | ||
| 1494 : | * Enter description here... | ||
| 1495 : | * | ||
| 1496 : | * @return unknown | ||
| 1497 : | */ | ||
| 1498 : | function getBestQueryMatch () { | ||
| 1499 : | parse_str($_SERVER['QUERY_STRING'], $qitems); | ||
| 1500 : | if (!isset($qitems['option'])) return 0; | ||
| 1501 : | $failures = 999; | ||
| 1502 : | $best = 0; | ||
| 1503 : | foreach ($this->_menus as $menu) { | ||
| 1504 : | $split = explode('?', $menu->link); | ||
| 1505 : | if (isset($split[1])) parse_str($split[1], $mitems); | ||
| 1506 : | else continue; | ||
| 1507 : | if (!isset($mitems['option']) OR $mitems['option'] != $qitems['option']) continue; | ||
| 1508 : | $thisfail = 0; | ||
| 1509 : | foreach ($mitems as $key=>$mitem) if (!isset($qitems[$key]) OR $mitem != $qitems[$key]) $thisfail++; | ||
| 1510 : | if ($thisfail < $failures) { | ||
| 1511 : | $best = $menu->id; | ||
| 1512 : | $failures = $thisfail; | ||
| 1513 : | } | ||
| 1514 : | } | ||
| 1515 : | return $best; | ||
| 1516 : | } | ||
| 1517 : | |||
| 1518 : | |||
| 1519 : | /** | ||
| 1520 : | * Enter description here... | ||
| 1521 : | * | ||
| 1522 : | * @param unknown_type $link | ||
| 1523 : | * @return unknown | ||
| 1524 : | */ | ||
| 1525 : | function &maxAccessLink ($link) { | ||
| 1526 : | $selected = null; | ||
| 1527 : | $access = 0; | ||
| 1528 : | foreach ($this->_menus as $key=>$menu) { | ||
| 1529 : | if (strpos($menu->link,$link) === 0 AND $menu->access > $access) { | ||
| 1530 : | $access = $menu->access; | ||
| 1531 : | $selected =& $this->_menus[$key]; | ||
| 1532 : | } | ||
| 1533 : | } | ||
| 1534 : | return $selected; | ||
| 1535 : | } | ||
| 1536 : | |||
| 1537 : | /** | ||
| 1538 : | * Enter description here... | ||
| 1539 : | * | ||
| 1540 : | * @param unknown_type $Itemid | ||
| 1541 : | * @param unknown_type $menutype | ||
| 1542 : | * @param unknown_type $maxaccess | ||
| 1543 : | * @param unknown_type $noparent | ||
| 1544 : | * @return unknown | ||
| 1545 : | */ | ||
| 1546 : | function &getByParentOrder ($Itemid, $menutype, $maxaccess=0, $noparent=false) { | ||
| 1547 : | $result = array(); | ||
| 1548 : | if ($this->_byParentOrder !== null) { | ||
| 1549 : | foreach ($this->_byParentOrder as $parent=>$outer) { | ||
| 1550 : | foreach ($outer as $ordering=>$inner) { | ||
| 1551 : | foreach ($inner as $mtype=>$last) { | ||
| 1552 : | $key = $this->_byParentOrder[$parent][$ordering][$mtype]; | ||
| 1553 : | $menu = $this->_menus[$key]; | ||
| 1554 : | if ($menutype AND $mtype != $menutype) continue; | ||
| 1555 : | if ($Itemid AND $Itemid != $menu->id) continue; | ||
| 1556 : | if ($menu->access > $maxaccess) continue; | ||
| 1557 : | if ($noparent AND $parent != 0) continue; | ||
| 1558 : | $result[] = $this->_menus[$key]; | ||
| 1559 : | } | ||
| 1560 : | } | ||
| 1561 : | } | ||
| 1562 : | } | ||
| 1563 : | andphe | 1321 | if ($Itemid == 0 && !count($result)){ |
| 1564 : | $result[0] = new stdclass; | ||
| 1565 : | $result[0]->id = 1; | ||
| 1566 : | $result[0]->link = 'index.php?option=com_frontpage'; | ||
| 1567 : | $result[0]->parent = 0; | ||
| 1568 : | $result[0]->type = 'components'; | ||
| 1569 : | $result[0]->browserNav = 0; | ||
| 1570 : | $result[0]->name = 'Home'; | ||
| 1571 : | alwarren | 1331 | } |
| 1572 : | return $result; | ||
| 1573 : | } | ||
| 1574 : | |||
| 1575 : | /** | ||
| 1576 : | * Enter description here... | ||
| 1577 : | * | ||
| 1578 : | * @param unknown_type $Itemid | ||
| 1579 : | */ | ||
| 1580 : | function setPathway ($Itemid) { | ||
| 1581 : | if ($Itemid) { | ||
| 1582 : | $menu =& $this->getMenuByID($Itemid); | ||
| 1583 : | if ($menu->parent) $this->setPathway($menu->parent); | ||
| 1584 : | $pathway =& mosPathway::getInstance(); | ||
| 1585 : | $pathway->addItem($menu->name, $menu->link."&Itemid=$Itemid"); | ||
| 1586 : | } | ||
| 1587 : | } | ||
| 1588 : | |||
| 1589 : | /** | ||
| 1590 : | * Checks whether a menu option is within the users access level | ||
| 1591 : | * @param int Item id number | ||
| 1592 : | * @param string The menu option | ||
| 1593 : | * @param int The users group ID number | ||
| 1594 : | * @param database A database connector object | ||
| 1595 : | * @return boolean True if the visitor's group at least equal to the menu access | ||
| 1596 : | */ | ||
| 1597 : | function menuCheck( $Itemid, $menu_option, $task, $gid ) { | ||
| 1598 : | // Construct a link to this component - if no menu for it, assume it is OK | ||
| 1599 : | $dblink="index.php?option=$menu_option"; | ||
| 1600 : | if ($this->getIDLikeLink($dblink) == 0) return true; | ||
| 1601 : | if ($Itemid) { | ||
| 1602 : | $menu =& $this->getMenuByID($Itemid); | ||
| 1603 : | if (strpos($menu->link,$dblink) ===0) { | ||
| 1604 : | $access = $menu->access; | ||
| 1605 : | } elseif ($menu_option == 'com_content' AND $Itemid == 1) { | ||
| 1606 : | return true; | ||
| 1607 : | } | ||
| 1608 : | } | ||
| 1609 : | if (!isset($access)) { | ||
| 1610 : | if ($task!='') $dblink .= "&task=$task"; | ||
| 1611 : | $menu =& $this->maxAccessLink($dblink); | ||
| 1612 : | if (isset($menu)) { | ||
| 1613 : | $access = $menu->access; | ||
| 1614 : | mamboCore::set('Itemid', $menu->id); | ||
| 1615 : | } | ||
| 1616 : | } | ||
| 1617 : | return isset($access) ? $access <= $gid : false; | ||
| 1618 : | } | ||
| 1619 : | |||
| 1620 : | /** | ||
| 1621 : | * Enter description here... | ||
| 1622 : | * | ||
| 1623 : | * @param unknown_type $mitem | ||
| 1624 : | * @param unknown_type $level | ||
| 1625 : | * @param unknown_type $params | ||
| 1626 : | * @param unknown_type $Itemid | ||
| 1627 : | * @return unknown | ||
| 1628 : | */ | ||
| 1629 : | function mosGetMenuLink( &$mitem, $level=0, &$params, $Itemid ) { | ||
| 1630 : | $txt = ''; | ||
| 1631 : | |||
| 1632 : | switch ($mitem->type) { | ||
| 1633 : | case 'separator': | ||
| 1634 : | case 'component_item_link': | ||
| 1635 : | break; | ||
| 1636 : | case 'content_item_link': | ||
| 1637 : | $temp = split("&task=view&id=", $mitem->link); | ||
| 1638 : | if (isset($temp[1])) { | ||
| 1639 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 1640 : | $handler =& contentHandler::getInstance(); | ||
| 1641 : | $mitem->link .= '&Itemid='.$handler->getItemid($temp[1]); | ||
| 1642 : | } | ||
| 1643 : | break; | ||
| 1644 : | case 'url': | ||
| 1645 : | $link = strtolower($mitem->link); | ||
| 1646 : | if (substr($link,0,10) == 'index.php?' AND strpos($link,'itemid=') === false) $mitem->link .= '&Itemid='. $mitem->id; | ||
| 1647 : | break; | ||
| 1648 : | case 'content_typed': | ||
| 1649 : | default: | ||
| 1650 : | $mitem->link .= '&Itemid='.$mitem->id; | ||
| 1651 : | break; | ||
| 1652 : | } | ||
| 1653 : | // Active Menu highlighting | ||
| 1654 : | if ( $Itemid == $mitem->id ) $id = 'id="active_menu'.$params->get( 'class_sfx' ).'"'; | ||
| 1655 : | else $id = ''; | ||
| 1656 : | $mitem->link = ampReplace( $mitem->link ); | ||
| 1657 : | if (strcasecmp(substr($mitem->link,0,4), 'http')) $mitem->link = sefRelToAbs( $mitem->link ); | ||
| 1658 : | if ($level > 0) $menuclass = 'sublevel'; | ||
| 1659 : | else $menuclass = 'mainlevel'; | ||
| 1660 : | $menuclass .= $params->get( 'class_sfx'); | ||
| 1661 : | |||
| 1662 : | switch ($mitem->browserNav) { | ||
| 1663 : | // cases are slightly different | ||
| 1664 : | case 1: | ||
| 1665 : | // open in a new window | ||
| 1666 : | $txt = '<a href="'. $mitem->link .'" target="_blank" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; | ||
| 1667 : | break; | ||
| 1668 : | |||
| 1669 : | case 2: | ||
| 1670 : | // open in a popup window | ||
| 1671 : | $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"; | ||
| 1672 : | break; | ||
| 1673 : | |||
| 1674 : | case 3: | ||
| 1675 : | // don't link it | ||
| 1676 : | $txt = '<span class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</span>'; | ||
| 1677 : | break; | ||
| 1678 : | |||
| 1679 : | default: // formerly case 2 | ||
| 1680 : | // open in parent window | ||
| 1681 : | $txt = '<a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; | ||
| 1682 : | break; | ||
| 1683 : | } | ||
| 1684 : | |||
| 1685 : | if ( $params->get( 'menu_images' ) ) { | ||
| 1686 : | $menu_params =& new mosParameters( $mitem->params ); | ||
| 1687 : | $menu_image = $menu_params->def( 'menu_image', -1 ); | ||
| 1688 : | if ($menu_image AND $menu_image <> '-1') { | ||
| 1689 : | $image = '<img src="'. mamboCore::get('mosConfig_live_site') .'/images/stories/'. $menu_image .'" border="0" alt="'. $mitem->name .'"/>'; | ||
| 1690 : | if ( $params->get('menu_images_align')) $txt = $txt .' '. $image; | ||
| 1691 : | else $txt = $image .' '. $txt; | ||
| 1692 : | } | ||
| 1693 : | } | ||
| 1694 : | return $txt; | ||
| 1695 : | } | ||
| 1696 : | |||
| 1697 : | /** | ||
| 1698 : | * Vertically Indented Menu | ||
| 1699 : | */ | ||
| 1700 : | function mosShowVIMenu( &$params ) { | ||
| 1701 : | global $my, $cur_template, $Itemid; | ||
| 1702 : | if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 0; | ||
| 1703 : | else $maxaccess = $my->gid; | ||
| 1704 : | $rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess); | ||
| 1705 : | foreach ($rows as $i=>$row) $crosslink[$row->id] = $i; | ||
| 1706 : | // indent icons | ||
| 1707 : | $base = mamboCore::get('mosConfig_live_site'); | ||
| 1708 : | switch ( $params->get( 'indent_image' ) ) { | ||
| 1709 : | case '1': | ||
| 1710 : | // Default images | ||
| 1711 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 1712 : | $img[$i] = "<img src=\"$base/images/M_images/indent$i.png\" alt=\"indent$i\" />"; | ||
| 1713 : | } | ||
| 1714 : | break; | ||
| 1715 : | case '2': | ||
| 1716 : | // Use Params | ||
| 1717 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 1718 : | $parm = $params->get('indent_image'. $i); | ||
| 1719 : | if ($parm == '-1' ) $img[$i] = NULL; | ||
| 1720 : | else $img[$i] = "<img src=\"$base/images/M_images/$parm\" alt=\"indent$i\" />"; | ||
| 1721 : | } | ||
| 1722 : | break; | ||
| 1723 : | case '3': | ||
| 1724 : | // None | ||
| 1725 : | for ( $i = 1; $i < 7; $i++ ) $img[$i] = NULL; | ||
| 1726 : | break; | ||
| 1727 : | default: | ||
| 1728 : | // Template | ||
| 1729 : | $imgpath = $base.'/templates/'. $cur_template .'/images'; | ||
| 1730 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 1731 : | $img[$i] = "<img src=\"$base/templates/$cur_template/images/indent$i.png\" alt=\"indent$i\" />"; | ||
| 1732 : | } | ||
| 1733 : | break; | ||
| 1734 : | } | ||
| 1735 : | |||
| 1736 : | $indents = array( | ||
| 1737 : | // block prefix / item prefix / item suffix / block suffix | ||
| 1738 : | array( '<table width="100%" border="0" cellpadding="0" cellspacing="0">', '<tr align="left"><td>' , '</td></tr>', '</table>' ), | ||
| 1739 : | array( '', '<div style="padding-left: 4px">'. $img[1] , '</div>', '' ), | ||
| 1740 : | array( '', '<div style="padding-left: 8px">'. $img[2] , '</div>', '' ), | ||
| 1741 : | array( '', '<div style="padding-left: 12px">'. $img[3] , '</div>', '' ), | ||
| 1742 : | array( '', '<div style="padding-left: 16px">'. $img[4] , '</div>', '' ), | ||
| 1743 : | array( '', '<div style="padding-left: 20px">'. $img[5] , '</div>', '' ), | ||
| 1744 : | array( '', '<div style="padding-left: 24px">'. $img[6] , '</div>', '' ), | ||
| 1745 : | ); | ||
| 1746 : | |||
| 1747 : | // establish the hierarchy of the menu | ||
| 1748 : | $children = array(); | ||
| 1749 : | // first pass - collect children | ||
| 1750 : | foreach ($rows as $v ) $children[$v->parent][] = $v; | ||
| 1751 : | // second pass - collect 'open' menus | ||
| 1752 : | $open = array( $Itemid ); | ||
| 1753 : | for ($i = 0; $i < 20 AND isset($crosslink[$open[$i]]) AND isset($rows[$crosslink[$open[$i]]]); $i++) { | ||
| 1754 : | $next = $rows[$crosslink[$open[$i]]]->parent; | ||
| 1755 : | if ($next) $open[$i+1] = $next; | ||
| 1756 : | else break; | ||
| 1757 : | } | ||
| 1758 : | |||
| 1759 : | $this->mosRecurseVIMenu( 0, 0, $children, $open, $indents, $params ); | ||
| 1760 : | |||
| 1761 : | } | ||
| 1762 : | |||
| 1763 : | /** | ||
| 1764 : | * Utility function to recursively work through a vertically indented | ||
| 1765 : | * hierarchial menu | ||
| 1766 : | */ | ||
| 1767 : | function mosRecurseVIMenu( $id, $level, &$children, &$open, &$indents, &$params ) { | ||
| 1768 : | global $Itemid; | ||
| 1769 : | if (@$children[$id]) { | ||
| 1770 : | $n = min( $level, count($indents )-1); | ||
| 1771 : | echo "\n".$indents[$n][0]; | ||
| 1772 : | foreach ($children[$id] as $row) { | ||
| 1773 : | echo "\n".$indents[$n][1]; | ||
| 1774 : | echo $this->mosGetMenuLink( $row, $level, $params, $Itemid ); | ||
| 1775 : | // show menu with menu expanded - submenus visible | ||
| 1776 : | if ($params->get('expand_menu') OR in_array($row->id, $open)) $this->mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params ); | ||
| 1777 : | echo $indents[$n][2]; | ||
| 1778 : | } | ||
| 1779 : | echo "\n".$indents[$n][3]; | ||
| 1780 : | } | ||
| 1781 : | } | ||
| 1782 : | |||
| 1783 : | /** | ||
| 1784 : | * Draws a horizontal 'flat' style menu (very simple case) | ||
| 1785 : | */ | ||
| 1786 : | function mosShowHFMenu( &$params, $style=0 ) { | ||
| 1787 : | global $my, $cur_template, $Itemid; | ||
| 1788 : | |||
| 1789 : | if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 0; | ||
| 1790 : | else $maxaccess = $my->gid; | ||
| 1791 : | $rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess, true); | ||
| 1792 : | |||
| 1793 : | $links = array(); | ||
| 1794 : | foreach ($rows as $row) $links[] = $this->mosGetMenuLink( $row, 0, $params, $Itemid ); | ||
| 1795 : | $menuclass = 'mainlevel'. $params->get( 'class_sfx' ); | ||
| 1796 : | if (count( $links )) { | ||
| 1797 : | if ($style == 1) { | ||
| 1798 : | echo '<ul id="'. $menuclass .'">'; | ||
| 1799 : | foreach ($links as $link) echo '<li>' . $link . '</li>'; | ||
| 1800 : | echo '</ul>'; | ||
| 1801 : | } | ||
| 1802 : | else { | ||
| 1803 : | echo '<table width="100%" border="0" cellpadding="0" cellspacing="1">'; | ||
| 1804 : | echo '<tr>'; | ||
| 1805 : | echo '<td nowrap="nowrap">'; | ||
| 1806 : | echo '<span class="'. $menuclass .'"> '. $params->get( 'end_spacer' ) .' </span>'; | ||
| 1807 : | echo implode( '<span class="'. $menuclass .'"> '. $params->get( 'spacer' ) .' </span>', $links ); | ||
| 1808 : | echo '<span class="'. $menuclass .'"> '. $params->get( 'end_spacer' ) .' </span>'; | ||
| 1809 : | echo '</td></tr>'; | ||
| 1810 : | echo '</table>'; | ||
| 1811 : | } | ||
| 1812 : | } | ||
| 1813 : | } | ||
| 1814 : | } | ||
| 1815 : | |||
| 1816 : | /** | ||
| 1817 : | * Plugin handler | ||
| 1818 : | * @package Mambo | ||
| 1819 : | */ | ||
| 1820 : | class mosMambotHandler { | ||
| 1821 : | /** @var array An array of functions in event groups */ | ||
| 1822 : | var $_events=null; | ||
| 1823 : | /** @var array An array of lists */ | ||
| 1824 : | var $_lists=null; | ||
| 1825 : | /** @var array An array of mambots */ | ||
| 1826 : | var $_bots=null; | ||
| 1827 : | /** @var array An array of bools showing if corresponding bot is registered */ | ||
| 1828 : | var $_registered=array(); | ||
| 1829 : | /** @var int Index of the mambot being loaded */ | ||
| 1830 : | var $_loading=null; | ||
| 1831 : | |||
| 1832 : | /** | ||
| 1833 : | * Constructor | ||
| 1834 : | */ | ||
| 1835 : | function mosMambotHandler() { | ||
| 1836 : | $my = mamboCore::is_set('currentUser') ? mamboCore::get('currentUser') : null; | ||
| 1837 : | $gid = $my ? $my->gid : 0; | ||
| 1838 : | $this->_events = array(); | ||
| 1839 : | $database =& mamboDatabase::getInstance(); | ||
| 1840 : | $database->setQuery( "SELECT folder, element, published, params, CONCAT_WS('/',folder,element) AS lookup" | ||
| 1841 : | . "\nFROM #__mambots" | ||
| 1842 : | . "\nWHERE published >= 1 AND access <= $gid" | ||
| 1843 : | . "\nORDER BY ordering" | ||
| 1844 : | ); | ||
| 1845 : | $this->_bots = $database->loadObjectList(); | ||
| 1846 : | if (!$this->_bots) $this->_bots = array(); | ||
| 1847 : | } | ||
| 1848 : | /** | ||
| 1849 : | * Singleton accessor | ||
| 1850 : | */ | ||
| 1851 : | function &getInstance () { | ||
| 1852 : | static $instance; | ||
| 1853 : | if (!is_object($instance)) $instance = new mosMambotHandler(); | ||
| 1854 : | return $instance; | ||
| 1855 : | } | ||
| 1856 : | /** | ||
| 1857 : | * Register a class-type mambot, provided it has a perform method | ||
| 1858 : | * - can register for multiple events if desired | ||
| 1859 : | * @param object The mambot object | ||
| 1860 : | * @param mixed string or array of strings - the mambot events to be registered | ||
| 1861 : | * @param int the subscript for use in the main array of mambots | ||
| 1862 : | */ | ||
| 1863 : | function _botRegister (&$botObject, &$selected, $i) { | ||
| 1864 : | $function = array(&$botObject, 'perform'); | ||
| 1865 : | if (!is_callable($function)) return; | ||
| 1866 : | if (is_array($selected)) foreach ($selected as $select) $this->_botRegister($botObject, $select); | ||
| 1867 : | $this->_events[$selected][] = array ($function, $i); | ||
| 1868 : | $this->_registered[$i] = true; | ||
| 1869 : | } | ||
| 1870 : | |||
| 1871 : | /** | ||
| 1872 : | * Loads all the bot files for a particular group | ||
| 1873 : | * @param string The group name, relates to the sub-directory in the mambots directory | ||
| 1874 : | */ | ||
| 1875 : | function loadBotGroup( $group ) { | ||
| 1876 : | global $_MAMBOTS; | ||
| 1877 : | $group = trim( $group ); | ||
| 1878 : | $total = 0; | ||
| 1879 : | $basepath = mamboCore::get('mosConfig_absolute_path'); | ||
| 1880 : | foreach ($this->_bots as $i=>$bot) { | ||
| 1881 : | if ($bot->folder != $group OR isset($this->_registered[$i])) continue; | ||
| 1882 : | $path = "$basepath/mambots/$bot->folder/$bot->element.php"; | ||
| 1883 : | if (file_exists( $path )) { | ||
| 1884 : | $this->_loading = $i; | ||
| 1885 : | require_once( $path ); | ||
| 1886 : | if (!isset($this->_registered[$i])) { | ||
| 1887 : | $botclass = str_replace('.','_',$bot->element); | ||
| 1888 : | if (class_exists($botclass)) { | ||
| 1889 : | $newbot = new $botclass(); | ||
| 1890 : | if (is_callable(array(&$newbot, 'register'))) { | ||
| 1891 : | $selected = $newbot->register(); | ||
| 1892 : | $this->_botRegister($newbot, $selected, $i); | ||
| 1893 : | } | ||
| 1894 : | unset($newbot); | ||
| 1895 : | } | ||
| 1896 : | } | ||
| 1897 : | $total++; | ||
| 1898 : | } | ||
| 1899 : | } | ||
| 1900 : | $this->_loading = null; | ||
| 1901 : | if ($total) return true; | ||
| 1902 : | return false; | ||
| 1903 : | } | ||
| 1904 : | /** | ||
| 1905 : | * Registers a function to a particular event group | ||
| 1906 : | * @param string The event name | ||
| 1907 : | * @param string The function name | ||
| 1908 : | */ | ||
| 1909 : | function registerFunction( $event, $function ) { | ||
| 1910 : | $this->_events[$event][] = array( $function, $this->_loading ); | ||
| 1911 : | $this->_registered[$this->_loading] = true; | ||
| 1912 : | } | ||
| 1913 : | /** | ||
| 1914 : | * Makes a option for a particular list in a group | ||
| 1915 : | * @param string The group name | ||
| 1916 : | * @param string The list name | ||
| 1917 : | * @param string The value for the list option | ||
| 1918 : | * @param string The text for the list option | ||
| 1919 : | */ | ||
| 1920 : | function addListOption( $group, $listName, $value, $text='' ) { | ||
| 1921 : | $this->_lists[$group][$listName][] = mosHTML::makeOption( $value, $text ); | ||
| 1922 : | } | ||
| 1923 : | /** | ||
| 1924 : | * @param string The group name | ||
| 1925 : | * @param string The list name | ||
| 1926 : | * @return array | ||
| 1927 : | */ | ||
| 1928 : | function getList( $group, $listName ) { | ||
| 1929 : | return $this->_lists[$group][$listName]; | ||
| 1930 : | } | ||
| 1931 : | /** | ||
| 1932 : | * Calls all functions according to passed parameters | ||
| 1933 : | * @param string The event name | ||
| 1934 : | * @param array An array of arguments | ||
| 1935 : | * @param boolean True is unpublished bots are to be processed | ||
| 1936 : | * @return array An array of results from each function call | ||
| 1937 : | */ | ||
| 1938 : | function &_runBots ($event, $args, $doUnpublished=false) { | ||
| 1939 : | $result = array(); | ||
| 1940 : | if (isset( $this->_events[$event] )) { | ||
| 1941 : | foreach ($this->_events[$event] as $func) { | ||
| 1942 : | if (is_callable( $func[0] )) { | ||
| 1943 : | $botparams = $this->_bots[$func[1]]->params; | ||
| 1944 : | $args[] = new mosParameters($botparams); | ||
| 1945 : | $args[] = $event; | ||
| 1946 : | if ($doUnpublished) { | ||
| 1947 : | $args[0] = $this->_bots[$func[1]]->published; | ||
| 1948 : | $result[] = call_user_func_array( $func[0], $args ); | ||
| 1949 : | } else if ($this->_bots[$func[1]]->published) { | ||
| 1950 : | $result[] = call_user_func_array( $func[0], $args ); | ||
| 1951 : | } | ||
| 1952 : | } | ||
| 1953 : | } | ||
| 1954 : | } | ||
| 1955 : | return $result; | ||
| 1956 : | } | ||
| 1957 : | /** | ||
| 1958 : | * Calls all functions associated with an event group | ||
| 1959 : | * @param string The event name | ||
| 1960 : | * @param array An array of arguments | ||
| 1961 : | * @param boolean True is unpublished bots are to be processed | ||
| 1962 : | * @return array An array of results from each function call | ||
| 1963 : | */ | ||
| 1964 : | function trigger( $event, $args=null, $doUnpublished=false ) { | ||
| 1965 : | if ($args === null) $args = array(); | ||
| 1966 : | // prepend the published argument | ||
| 1967 : | if ($doUnpublished) array_unshift( $args, null ); | ||
| 1968 : | $result =& $this->_runBots($event, $args, $doUnpublished); | ||
| 1969 : | return $result; | ||
| 1970 : | } | ||
| 1971 : | /** | ||
| 1972 : | * Same as trigger but only returns the first event and | ||
| 1973 : | * allows for a variable argument list | ||
| 1974 : | * @param string The event name | ||
| 1975 : | * @return array The result of the first function call | ||
| 1976 : | */ | ||
| 1977 : | function call( $event ) { | ||
| 1978 : | $args =& func_get_args(); | ||
| 1979 : | array_shift( $args ); | ||
| 1980 : | $result =& $this->_runBots($event, $args); | ||
| 1981 : | if (isset($result[0])) return $result[0]; | ||
| 1982 : | return null; | ||
| 1983 : | } | ||
| 1984 : | |||
| 1985 : | function getBot($element, $folder) { | ||
| 1986 : | $returnBot = ''; | ||
| 1987 : | foreach ($this->_bots as $i=>$bot) { | ||
| 1988 : | if ($bot->folder == $folder && $bot->element == $element){ | ||
| 1989 : | $returnBot = $bot; | ||
| 1990 : | break; | ||
| 1991 : | } | ||
| 1992 : | } | ||
| 1993 : | return $returnBot; | ||
| 1994 : | } | ||
| 1995 : | } | ||
| 1996 : | |||
| 1997 : | /** | ||
| 1998 : | * Users Table Class | ||
| 1999 : | * | ||
| 2000 : | * Provides access to the mos_templates table | ||
| 2001 : | * @package Mambo | ||
| 2002 : | */ | ||
| 2003 : | class mosUser extends mosDBTable { | ||
| 2004 : | /** @var int Unique id*/ | ||
| 2005 : | var $id=null; | ||
| 2006 : | /** @var string The users real name (or nickname)*/ | ||
| 2007 : | var $name=null; | ||
| 2008 : | /** @var string The login name*/ | ||
| 2009 : | var $username=null; | ||
| 2010 : | /** @var string email*/ | ||
| 2011 : | var $email=null; | ||
| 2012 : | /** @var string MD5 encrypted password*/ | ||
| 2013 : | var $password=null; | ||
| 2014 : | /** @var string */ | ||
| 2015 : | var $usertype=null; | ||
| 2016 : | /** @var int */ | ||
| 2017 : | var $block=null; | ||
| 2018 : | /** @var int */ | ||
| 2019 : | var $sendEmail=null; | ||
| 2020 : | /** @var int The group id number */ | ||
| 2021 : | var $gid=null; | ||
| 2022 : | /** @var int Group number from ACL */ | ||
| 2023 : | var $grp=null; | ||
| 2024 : | /** @var datetime */ | ||
| 2025 : | var $registerDate=null; | ||
| 2026 : | /** @var datetime */ | ||
| 2027 : | var $lastvisitDate=null; | ||
| 2028 : | /** @var string activation hash*/ | ||
| 2029 : | var $activation=null; | ||
| 2030 : | /** @var string */ | ||
| 2031 : | var $params=null; | ||
| 2032 : | |||
| 2033 : | /** | ||
| 2034 : | * @param database A database connector object | ||
| 2035 : | */ | ||
| 2036 : | function mosUser() { | ||
| 2037 : | $database =& mamboDatabase::getInstance(); | ||
| 2038 : | $this->mosDBTable( '#__users', 'id', $database ); | ||
| 2039 : | } | ||
| 2040 : | |||
| 2041 : | /** | ||
| 2042 : | * Return true if this user is an administrator, false otherwise | ||
| 2043 : | */ | ||
| 2044 : | function isAdmin() { | ||
| 2045 : | return ( strtolower( $this->usertype ) == 'superadministrator' OR strtolower( $this->usertype ) == 'super administrator' OR (isset($this->grp) AND $this->grp == 16) ) ? true : false; | ||
| 2046 : | } | ||
| 2047 : | |||
| 2048 : | /** | ||
| 2049 : | * Fill a user object with information from the current session | ||
| 2050 : | */ | ||
| 2051 : | function getSessionData() { | ||
| 2052 : | $session =& mosSession::getCurrent(); | ||
| 2053 : | $this->id = intval( $session->userid ); | ||
| 2054 : | $this->username = $session->username; | ||
| 2055 : | $this->usertype = $session->usertype; | ||
| 2056 : | $this->gid = intval ($session->gid); | ||
| 2057 : | } | ||
| 2058 : | |||
| 2059 : | function getSession () { | ||
| 2060 : | $this->id = mosGetParam( $_SESSION, 'session_user_id', 0 ); | ||
| 2061 : | $this->username = mosGetParam( $_SESSION, 'session_username', '' ); | ||
| 2062 : | $this->usertype = mosGetParam( $_SESSION, 'session_usertype', '' ); | ||
| 2063 : | $this->gid = mosGetParam( $_SESSION, 'session_gid', 0 ); | ||
| 2064 : | $this->grp = mosGetParam( $_SESSION, 'session_grp', 0); | ||
| 2065 : | } | ||
| 2066 : | /** | ||
| 2067 : | * Validation and filtering | ||
| 2068 : | * @return boolean True is satisfactory | ||
| 2069 : | */ | ||
| 2070 : | function check() { | ||
| 2071 : | Global $mosConfig_absolute_path; | ||
| 2072 : | //include $mosConfig_absolute_path . ('/language/english.php'); | ||
| 2073 : | $this->_error = ''; | ||
| 2074 : | if ($this->name == '') $this->_error = _REGWARN_NAME; | ||
| 2075 : | elseif ($this->username == '') $this->_error = _REGWARN_UNAME; | ||
| 2076 : | elseif (strlen($this->username) < 3 OR preg_match("/[\\<\\>\\\"\\'\\%\\;\\(\\)\\&\\+\\-]/", $this->username)) $this->_error = sprintf( _VALID_AZ09, _PROMPT_UNAME, 2 ); | ||
| 2077 : | elseif (($this->email == '') OR preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $this->email ) == 0) $this->_error = _REGWARN_MAIL; | ||
| 2078 : | else { | ||
| 2079 : | // check for existing username | ||
| 2080 : | $username = strtolower($this->username); | ||
| 2081 : | $this->_db->setQuery( "SELECT COUNT(id) FROM #__users " | ||
| 2082 : | . "\nWHERE LOWER(username)='$username' AND id!='$this->id'" | ||
| 2083 : | ); | ||
| 2084 : | if ($this->_db->loadResult()) $this->_error = _REGWARN_INUSE; | ||
| 2085 : | elseif (mamboCore::get('mosConfig_uniquemail')) { | ||
| 2086 : | // check for existing email | ||
| 2087 : | $this->_db->setQuery( "SELECT COUNT(id) FROM #__users " | ||
| 2088 : | . "\nWHERE email='$this->email' AND id!='$this->id'" | ||
| 2089 : | ); | ||
| 2090 : | if ($this->_db->loadResult()) $this->_error = _REGWARN_EMAIL_INUSE; | ||
| 2091 : | } | ||
| 2092 : | } | ||
| 2093 : | if ($this->_error) return false; | ||
| 2094 : | return true; | ||
| 2095 : | } | ||
| 2096 : | |||
| 2097 : | function store( $updateNulls=false ) { | ||
| 2098 : | global $acl, $migrate; | ||
| 2099 : | $section_value = 'users'; | ||
| 2100 : | if( $this->id AND !$migrate) { | ||
| 2101 : | // update existing record | ||
| 2102 : | $ret = $this->_db->updateObject( $this->_tbl, $this, 'id', $updateNulls ); | ||
| 2103 : | // syncronise ACL | ||
| 2104 : | // single group handled at the moment | ||
| 2105 : | // trivial to expand to multiple groups | ||
| 2106 : | $groups = $acl->get_object_groups( $section_value, $this->id, 'ARO' ); | ||
| 2107 : | $acl->del_group_object( $groups[0], $section_value, $this->id, 'ARO' ); | ||
| 2108 : | $acl->add_group_object( $this->gid, $section_value, $this->id, 'ARO' ); | ||
| 2109 : | $object_id = $acl->get_object_id( $section_value, $this->id, 'ARO' ); | ||
| 2110 : | $acl->edit_object( $object_id, $section_value, $this->_db->getEscaped( $this->name ), $this->id, 0, 0, 'ARO' ); | ||
| 2111 : | } | ||
| 2112 : | else { | ||
| 2113 : | // new record | ||
| 2114 : | $ret = $this->_db->insertObject( $this->_tbl, $this, 'id' ); | ||
| 2115 : | // syncronise ACL | ||
| 2116 : | $acl->add_object( $section_value, $this->_db->getEscaped( $this->name ), $this->id, null, null, 'ARO' ); | ||
| 2117 : | $acl->add_group_object( $this->gid, $section_value, $this->id, 'ARO' ); | ||
| 2118 : | } | ||
| 2119 : | if ($ret) return true; | ||
| 2120 : | $this->_error = "mosUser::store failed <br />" . $this->_db->getErrorMsg(); | ||
| 2121 : | return false; | ||
| 2122 : | } | ||
| 2123 : | |||
| 2124 : | function delete($oid=null) { | ||
| 2125 : | global $acl; | ||
| 2126 : | $k = $this->_tbl_key; | ||
| 2127 : | if ($oid) $this->id = intval( $oid ); | ||
| 2128 : | $aro_id = $acl->get_object_id( 'users', $this->$k, 'ARO' ); | ||
| 2129 : | $acl->del_object( $aro_id, 'ARO', true ); | ||
| 2130 : | // $authoriser = mosAuthorisationAdmin::getInstance(); | ||
| 2131 : | // $authoriser->dropAccess('mosUser', $this->id); | ||
| 2132 : | $this->_error = ''; | ||
| 2133 : | $this->_db->setQuery( "DELETE FROM $this->_tbl WHERE id = '".$this->id."'" ); | ||
| 2134 : | if ($this->_db->query()) { | ||
| 2135 : | // cleanup related data | ||
| 2136 : | |||
| 2137 : | // :: private messaging | ||
| 2138 : | $this->_db->setQuery( "DELETE FROM #__messages_cfg WHERE user_id='".$this->id."'" ); | ||
| 2139 : | if (!$this->_db->query()) $this->_error = $this->_db->getErrorMsg(); | ||
| 2140 : | else { | ||
| 2141 : | $this->_db->setQuery( "DELETE FROM #__messages WHERE user_id_to='".$this->$k."'" ); | ||
| 2142 : | if (!$this->_db->query()) $this->_error = $this->_db->getErrorMsg(); | ||
| 2143 : | } | ||
| 2144 : | } else $this->_error = $this->_db->getErrorMsg(); | ||
| 2145 : | if ($this->_error) return false; | ||
| 2146 : | return true; | ||
| 2147 : | } | ||
| 2148 : | } | ||
| 2149 : | |||
| 2150 : | /** | ||
| 2151 : | * User login details class | ||
| 2152 : | * @package Mambo | ||
| 2153 : | */ | ||
| 2154 : | class mosLoginDetails { | ||
| 2155 : | var $_user = ''; | ||
| 2156 : | var $_password = ''; | ||
| 2157 : | var $_remember = ''; | ||
| 2158 : | |||
| 2159 : | function mosLoginDetails ($user, $password='', $remember='') { | ||
| 2160 : | $this->_user = $user; | ||
| 2161 : | $this->_password = $password; | ||
| 2162 : | $this->_remember = $remember; | ||
| 2163 : | } | ||
| 2164 : | |||
| 2165 : | function getUser () { | ||
| 2166 : | return $this->_user; | ||
| 2167 : | } | ||
| 2168 : | |||
| 2169 : | function getPassword () { | ||
| 2170 : | return $this->_password; | ||
| 2171 : | } | ||
| 2172 : | |||
| 2173 : | function getRemember () { | ||
| 2174 : | return $this->_remember; | ||
| 2175 : | } | ||
| 2176 : | |||
| 2177 : | } | ||
| 2178 : | /** | ||
| 2179 : | * Mambo Mainframe class | ||
| 2180 : | * | ||
| 2181 : | * Provide many supporting API functions | ||
| 2182 : | * @package Mambo | ||
| 2183 : | */ | ||
| 2184 : | class mosMainFrame { | ||
| 2185 : | /** @var database Internal database class pointer */ | ||
| 2186 : | var $_db=null; | ||
| 2187 : | /** @var object A default option (e.g. component) */ | ||
| 2188 : | var $_option=null; | ||
| 2189 : | /** @var string The current template */ | ||
| 2190 : | var $_template=null; | ||
| 2191 : | /** @var array An array to hold global user state within a session */ | ||
| 2192 : | var $_userstate=null; | ||
| 2193 : | /** @var array An array of page meta information */ | ||
| 2194 : | var $_head=null; | ||
| 2195 : | /** @var string Custom html string to append to the pathway */ | ||
| 2196 : | var $_custom_pathway=array(); | ||
| 2197 : | |||
| 2198 : | /** | ||
| 2199 : | * Class constructor | ||
| 2200 : | * @param database A database connection object | ||
| 2201 : | * @param string The url option | ||
| 2202 : | * @param string The path of the mos directory | ||
| 2203 : | */ | ||
| 2204 : | function mosMainFrame( &$db, $option, $basePath, $isAdmin=false ) { | ||
| 2205 : | $this->_db =& $db; | ||
| 2206 : | // load the configuration values | ||
| 2207 : | //return( $this->loadConfig() ); | ||
| 2208 : | $this->_setTemplate($isAdmin); | ||
| 2209 : | if (substr($option,0,4) != 'com_') $this->_option = "com_$option"; | ||
| 2210 : | else $this->_option = $option; | ||
| 2211 : | if (isset( $_SESSION['session_userstate'] )) $this->_userstate =& $_SESSION['session_userstate']; | ||
| 2212 : | else $this->_userstate = null; | ||
| 2213 : | $this->_head['title'] = $GLOBALS['mosConfig_sitename']; | ||
| 2214 : | $this->_head['meta'] = array(); | ||
| 2215 : | $this->_head['custom'] = array(); | ||
| 2216 : | mosMainFrame::getInstance($this); | ||
| 2217 : | } | ||
| 2218 : | |||
| 2219 : | /** | ||
| 2220 : | * Get the current user - deprecated - use mamboCore instead | ||
| 2221 : | */ | ||
| 2222 : | function getUser() { | ||
| 2223 : | return mamboCore::get('currentUser'); | ||
| 2224 : | } | ||
| 2225 : | /** | ||
| 2226 : | * Logout the current user - deprecated - use the code here directly | ||
| 2227 : | */ | ||
| 2228 : | function logout() { | ||
| 2229 : | require_once(mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php'); | ||
| 2230 : | $authenticator =& mamboAuthenticator::getInstance(); | ||
| 2231 : | $authenticator->logoutUser(); | ||
| 2232 : | } | ||
| 2233 : | /** | ||
| 2234 : | * Login a user given name and password - deprecated - use the code here directly | ||
| 2235 : | */ | ||
| 2236 : | function login ($username=null,$passwd=null) { | ||
| 2237 : | require_once(mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php'); | ||
| 2238 : | $authenticator =& mamboAuthenticator::getInstance(); | ||
| 2239 : | return $authenticator->loginUser($username, $passwd); | ||
| 2240 : | } | ||
| 2241 : | |||
| 2242 : | /** | ||
| 2243 : | * @param object | ||
| 2244 : | */ | ||
| 2245 : | function &getInstance () { | ||
| 2246 : | global $mainframe; | ||
| 2247 : | if (isset($mainframe)) { | ||
| 2248 : | return $mainframe; | ||
| 2249 : | } else { | ||
| 2250 : | $result = null; | ||
| 2251 : | return $result; | ||
| 2252 : | } | ||
| 2253 : | } | ||
| 2254 : | |||
| 2255 : | /** | ||
| 2256 : | * @param string | ||
| 2257 : | */ | ||
| 2258 : | function setPageTitle( $title=null ) { | ||
| 2259 : | if (mamboCore::get('mosConfig_pagetitles')) { | ||
| 2260 : | $title = trim(htmlspecialchars($title)); | ||
| 2261 : | $base = mamboCore::get('mosConfig_sitename'); | ||
| 2262 : | $this->_head['title'] = $title ? $title.' - '.$base : $base; | ||
| 2263 : | } | ||
| 2264 : | } | ||
| 2265 : | /** | ||
| 2266 : | * @return string | ||
| 2267 : | */ | ||
| 2268 : | function getPageTitle() { | ||
| 2269 : | return $this->_head['title']; | ||
| 2270 : | } | ||
| 2271 : | |||
| 2272 : | /** | ||
| 2273 : | * @param string The value of the name attibute | ||
| 2274 : | * @param string The value of the content attibute | ||
| 2275 : | * @param string Text to display before the tag | ||
| 2276 : | * @param string Text to display after the tag | ||
| 2277 : | */ | ||
| 2278 : | function addMetaTag( $name, $content, $prepend='', $append='' ) { | ||
| 2279 : | list($name, $content) = $this->_tidyMetaData($name, $content); | ||
| 2280 : | $prepend = trim($prepend); | ||
| 2281 : | $append = trim($append); | ||
| 2282 : | $this->_head['meta'][$name] = array($content, $prepend, $append); | ||
| 2283 : | } | ||
| 2284 : | /** | ||
| 2285 : | * @param string The value of the name attibute | ||
| 2286 : | */ | ||
| 2287 : | function _getMetaTag ($name) { | ||
| 2288 : | return isset($this->_head['meta'][$name]) ? $this->_head['meta'][$name] : array('', '', ''); | ||
| 2289 : | } | ||
| 2290 : | /** | ||
| 2291 : | * @param string The value of the name attibute | ||
| 2292 : | * @param string The value of the content attibute to append to the existing | ||
| 2293 : | */ | ||
| 2294 : | function _tidyMetaData($name, $content) { | ||
| 2295 : | $result[] = trim(htmlspecialchars($name)); | ||
| 2296 : | $result[] = trim(htmlspecialchars($content)); | ||
| 2297 : | return $result; | ||
| 2298 : | } | ||
| 2299 : | /** | ||
| 2300 : | * @param string The value of the name attibute | ||
| 2301 : | * @param string The value of the content attibute to append to the existing | ||
| 2302 : | * Tags ordered in with Site Keywords and Description first | ||
| 2303 : | */ | ||
| 2304 : | function appendMetaTag( $name, $content, $ifEmpty=false ) { | ||
| 2305 : | list($name, $content) = $this->_tidyMetaData($name, $content); | ||
| 2306 : | $tag = $this->_getMetaTag($name); | ||
| 2307 : | if ($tag[0] AND $ifEmpty) return; | ||
| 2308 : | if ($tag[0] AND $content) $content .= ', '; | ||
| 2309 : | $tag[0] = $content.$tag[0]; | ||
| 2310 : | $this->_head['meta'][$name] = $tag; | ||
| 2311 : | } | ||
| 2312 : | |||
| 2313 : | /** | ||
| 2314 : | * @param string The value of the name attibute | ||
| 2315 : | * @param string The value of the content attibute to append to the existing | ||
| 2316 : | */ | ||
| 2317 : | function prependMetaTag( $name, $content ) { | ||
| 2318 : | list($name, $content) = $this->_tidyMetaData($name, $content); | ||
| 2319 : | $tag = $this->_getMetaTag($name); | ||
| 2320 : | $tag[0] = $content.$tag[0]; | ||
| 2321 : | $this->_head['meta'][$name] = $tag; | ||
| 2322 : | } | ||
| 2323 : | /** | ||
| 2324 : | * Adds a custom html string to the head block | ||
| 2325 : | * @param string The html to add to the head | ||
| 2326 : | */ | ||
| 2327 : | function addCustomHeadTag( $html ) { | ||
| 2328 : | $this->_head['custom'][] = trim( $html ); | ||
| 2329 : | } | ||
| 2330 : | /** | ||
| 2331 : | * @return string | ||
| 2332 : | */ | ||
| 2333 : | function getHead() { | ||
| 2334 : | $head[] = '<title>'.$this->_head['title'].'</title>'; | ||
| 2335 : | foreach ($this->_head['meta'] as $name=>$meta) { | ||
| 2336 : | if ($meta[1]) $head[] = $meta[1]; | ||
| 2337 : | $head[] = '<meta name="' . $name . '" content="' . $meta[0] . '" />'; | ||
| 2338 : | if ($meta[2]) $head[] = $meta[2]; | ||
| 2339 : | } | ||
| 2340 : | foreach ($this->_head['custom'] as $html) $head[] = $html; | ||
| 2341 : | return implode( "\n", $head )."\n"; | ||
| 2342 : | } | ||
| 2343 : | /** | ||
| 2344 : | * @return string | ||
| 2345 : | */ | ||
| 2346 : | function getCustomPathWay() { | ||
| 2347 : | return $this->_custom_pathway; | ||
| 2348 : | } | ||
| 2349 : | |||
| 2350 : | function appendPathWay($html) { | ||
| 2351 : | $this->_custom_pathway[] = $html; | ||
| 2352 : | } | ||
| 2353 : | |||
| 2354 : | /** | ||
| 2355 : | * Gets the value of a user state variable | ||
| 2356 : | * @param string The name of the variable | ||
| 2357 : | */ | ||
| 2358 : | function getUserState( $var_name ) { | ||
| 2359 : | return is_array($this->_userstate) ? mosGetParam($this->_userstate, $var_name, null) : null; | ||
| 2360 : | } | ||
| 2361 : | /** | ||
| 2362 : | * Sets the value of a user state variable | ||
| 2363 : | * @param string The name of the variable | ||
| 2364 : | * @param string The value of the variable | ||
| 2365 : | */ | ||
| 2366 : | function setUserState( $var_name, $var_value ) { | ||
| 2367 : | if (is_array( $this->_userstate )) $this->_userstate[$var_name] = $var_value; | ||
| 2368 : | } | ||
| 2369 : | /** | ||
| 2370 : | * Gets the value of a user state variable | ||
| 2371 : | * @param string The name of the user state variable | ||
| 2372 : | * @param string The name of the variable passed in a request | ||
| 2373 : | * @param string The default value for the variable if not found | ||
| 2374 : | */ | ||
| 2375 : | function getUserStateFromRequest( $var_name, $req_name, $var_default=null ) { | ||
| 2376 : | if (is_array($this->_userstate)) { | ||
| 2377 : | if (isset($_REQUEST[$req_name])) $this->setUserState($var_name, $_REQUEST[$req_name]); | ||
| 2378 : | else if (isset($var_default) AND !isset($this->_userstate[$var_name])) $this->setUserState($var_name, $var_default); | ||
| 2379 : | return $this->_userstate[$var_name]; | ||
| 2380 : | } else { | ||
| 2381 : | return null; | ||
| 2382 : | } | ||
| 2383 : | } | ||
| 2384 : | /** | ||
| 2385 : | * Initialises the user session | ||
| 2386 : | * | ||
| 2387 : | * Old sessions are flushed based on the configuration value for the cookie | ||
| 2388 : | * lifetime. If an existing session, then the last access time is updated. | ||
| 2389 : | * If a new session, a session id is generated and a record is created in | ||
| 2390 : | * the mos_sessions table. | ||
| 2391 : | */ | ||
| 2392 : | function &initSession() { | ||
| 2393 : | $session =& mosSession::getCurrent(); | ||
| 2394 : | return $session; | ||
| 2395 : | } | ||
| 2396 : | |||
| 2397 : | /** | ||
| 2398 : | * @param string The name of the variable (from configuration.php) | ||
| 2399 : | * @return mixed The value of the configuration variable or null if not found | ||
| 2400 : | */ | ||
| 2401 : | function getCfg( $varname ) { | ||
| 2402 : | return mamboCore::get('mosConfig_'.$varname); | ||
| 2403 : | } | ||
| 2404 : | |||
| 2405 : | function _setTemplate( $isAdmin=false ) { | ||
| 2406 : | global $Itemid; | ||
| 2407 : | $cur_template = ''; | ||
| 2408 : | $sql = "SELECT template, client_id, menuid FROM #__templates_menu WHERE (client_id=0 or client_id=1)"; | ||
| 2409 : | if (isset($Itemid) AND $Itemid) $sql .= " AND (menuid=0 OR menuid=$Itemid)"; | ||
| 2410 : | else $sql .= " AND menuid=0"; | ||
| 2411 : | $sql .= " ORDER BY client_id, menuid"; | ||
| 2412 : | $this->_db->setQuery($sql); | ||
| 2413 : | $templates = $this->_db->loadObjectList(); | ||
| 2414 : | foreach ($templates as $template) { | ||
| 2415 : | if ($template->client_id == 1) { | ||
| 2416 : | if ($isAdmin) $cur_template = $template->template; | ||
| 2417 : | } | ||
| 2418 : | else $cur_template = $template->template; | ||
| 2419 : | } | ||
| 2420 : | if ($isAdmin) { | ||
| 2421 : | $path = mamboCore::get('mosConfig_absolute_path')."/administrator/templates/$cur_template/index.php"; | ||
| 2422 : | if (!file_exists( $path )) $cur_template = 'mambo_admin'; | ||
| 2423 : | } | ||
| 2424 : | else { | ||
| 2425 : | // TemplateChooser Start | ||
| 2426 : | $mos_user_template = mosGetParam( $_COOKIE, 'mos_user_template', '' ); | ||
| 2427 : | $mos_change_template = mosGetParam( $_REQUEST, 'mos_change_template', $mos_user_template ); | ||
| 2428 : | if ($mos_change_template) { | ||
| 2429 : | // check that template exists in case it was deleted | ||
| 2430 : | $path = mamboCore::get('mosConfig_absolute_path')."/templates/$mos_change_template/index.php"; | ||
| 2431 : | if (strpos($mos_change_template,'..') == false AND strpos($mos_change_template,':') == false AND file_exists($path)) { | ||
| 2432 : | $lifetime = 60*10; | ||
| 2433 : | $cur_template = $mos_change_template; | ||
| 2434 : | setcookie( "mos_user_template", "$mos_change_template", time()+$lifetime); | ||
| 2435 : | } else setcookie( "mos_user_template", "", time()-3600 ); | ||
| 2436 : | } | ||
| 2437 : | // TemplateChooser End | ||
| 2438 : | } | ||
| 2439 : | $this->_template = $cur_template; | ||
| 2440 : | } | ||
| 2441 : | |||
| 2442 : | function getTemplate() { | ||
| 2443 : | return $this->_template; | ||
| 2444 : | } | ||
| 2445 : | |||
| 2446 : | /** | ||
| 2447 : | * Checks to see if an image exists in the current templates image directory | ||
| 2448 : | * if it does it loads this image. Otherwise the default image is loaded. | ||
| 2449 : | * Also can be used in conjunction with the menulist param to create the chosen image | ||
| 2450 : | * load the default or use no image | ||
| 2451 : | */ | ||
| 2452 : | function ImageCheck( $file, $directory='/images/M_images/', $param=NULL, $param_directory='/images/M_images/', $alt=NULL, $name='image', $type=1, $align='middle' ) { | ||
| 2453 : | $basepath = mamboCore::get('mosConfig_live_site'); | ||
| 2454 : | if ($param) $image = $basepath.$param_directory.$param; | ||
| 2455 : | else { | ||
| 2456 : | $endpath = '/templates/'.$this->getTemplate().'/images/'.$file; | ||
| 2457 : | if (file_exists(mamboCore::get('mosConfig_absolute_path').$endpath)) $image = $basepath.$endpath; | ||
| 2458 : | else $image = $basepath.$directory.$file; // outputs only path to image | ||
| 2459 : | } | ||
| 2460 : | // outputs actual html <img> tag | ||
| 2461 : | if ($type) $image = '<img src="'. $image .'" alt="'. $alt .'" align="'. $align .'" name="'. $name .'" border="0" />'; | ||
| 2462 : | return $image; | ||
| 2463 : | } | ||
| 2464 : | |||
| 2465 : | /** | ||
| 2466 : | * Returns the first to be found of one or more files, or null | ||
| 2467 : | * | ||
| 2468 : | */ | ||
| 2469 : | function tryFiles ($first_choice, $second_choice=null, $third_choice=null) { | ||
| 2470 : | if (file_exists($first_choice)) return $first_choice; | ||
| 2471 : | elseif ($second_choice AND file_exists($second_choice)) return $second_choice; | ||
| 2472 : | elseif ($third_choice AND file_exists($third_choice)) return $third_choice; | ||
| 2473 : | else return null; | ||
| 2474 : | } | ||
| 2475 : | |||
| 2476 : | /** | ||
| 2477 : | * Returns a standard path variable | ||
| 2478 : | * | ||
| 2479 : | */ | ||
| 2480 : | function getPath( $varname, $option='' ) { | ||
| 2481 : | $base = mamboCore::get('mosConfig_absolute_path'); | ||
| 2482 : | $origoption = $option; | ||
| 2483 : | if (!$option) $option = $this->_option; | ||
| 2484 : | $name = substr($option,4); | ||
| 2485 : | $bac_admin = "$base/administrator/components/com_admin/"; | ||
| 2486 : | $baco = "$base/administrator/components/$option/"; | ||
| 2487 : | $bttc = "$base/templates/$this->_template/components/"; | ||
| 2488 : | $bco = "$base/components/$option/"; | ||
| 2489 : | $bai = "$base/administrator/includes/"; | ||
| 2490 : | $bi = "$base/includes/"; | ||
| 2491 : | |||
| 2492 : | switch ($varname) { | ||
| 2493 : | case 'front': return $this->tryFiles ($bco."$name.php"); | ||
| 2494 : | case 'front_html': return $this->tryFiles ($bttc."$name.html.php", $bco."$name.html.php"); | ||
| 2495 : | case 'admin': return $this->tryFiles ($baco."admin.$name.php", $bac_admin.'admin.admin.php'); | ||
| 2496 : | case 'admin_html': return $this->tryFiles ($baco."admin.$name.html.php", $bac_admin.'admin.admin.html.php'); | ||
| 2497 : | case 'toolbar': return $this->tryFiles ($baco."toolbar.$name.php"); | ||
| 2498 : | case 'toolbar_html': return $this->tryFiles ($baco."toolbar.$name.html.php"); | ||
| 2499 : | case 'toolbar_default': return $this->tryFiles ($bai.'toolbar.html.php'); | ||
| 2500 : | case 'class': return $this->tryFiles ($bco."$name.class.php", $baco."$name.class.php", $bi."$name.php"); | ||
| 2501 : | case 'com_xml': return $this->tryFiles ($baco."$name.xml", $bco."$name.xml"); | ||
| 2502 : | case 'mod0_xml': | ||
| 2503 : | if ($origoption) $path = $base."/modules/$option.xml"; | ||
| 2504 : | else $path = $base.'/modules/custom.xml'; | ||
| 2505 : | return $this->tryFiles ($path); | ||
| 2506 : | case 'mod1_xml': | ||
| 2507 : | if ($origoption) $path = $base."/administrator/modules/$option.xml"; | ||
| 2508 : | else $path = $base.'/administrator/modules/custom.xml'; | ||
| 2509 : | return $this->tryFiles ($path); | ||
| 2510 : | case 'bot_xml': return $this->tryFiles ($base."/mambots/$option.xml"); | ||
| 2511 : | case 'menu_xml': return $this->tryFiles ($base."/administrator/components/com_menus/$option/$option.xml"); | ||
| 2512 : | case 'installer_html': return $this->tryFiles($base."/administrator/components/com_installer/$option/$option.html.php"); | ||
| 2513 : | case 'installer_class': return $this->tryFiles($base."/administrator/components/com_installer/$option/$option.class.php"); | ||
| 2514 : | } | ||
| 2515 : | } | ||
| 2516 : | |||
| 2517 : | /** | ||
| 2518 : | * Detects a 'visit' | ||
| 2519 : | * | ||
| 2520 : | * This function updates the agent and domain table hits for a particular | ||
| 2521 : | * visitor. The user agent is recorded/incremented if this is the first visit. | ||
| 2522 : | * A cookie is set to mark the first visit. | ||
| 2523 : | */ | ||
| 2524 : | function detect() { | ||
| 2525 : | if (mamboCore::get('mosConfig_enable_stats') == 1) { | ||
| 2526 : | if (mosGetParam( $_COOKIE, 'mosvisitor', 0 )) return; | ||
| 2527 : | setcookie( "mosvisitor", "1" ); | ||
| 2528 : | |||
| 2529 : | $agent = $_SERVER['HTTP_USER_AGENT']; | ||
| 2530 : | $browser = mosGetBrowser( $agent ); | ||
| 2531 : | $os = mosGetOS( $agent ); | ||
| 2532 : | $domain = gethostbyaddr( $_SERVER['REMOTE_ADDR'] ); | ||
| 2533 : | // tease out the last element of the domain | ||
| 2534 : | $tldomain = split( "\.", $domain ); | ||
| 2535 : | $tldomain = $tldomain[count( $tldomain )-1]; | ||
| 2536 : | if (is_numeric( $tldomain )) { | ||
| 2537 : | $tldomain = "Unknown"; | ||
| 2538 : | } | ||
| 2539 : | |||
| 2540 : | $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"); | ||
| 2541 : | $stats = $this->_db->loadObjectList(); | ||
| 2542 : | $sql['browser'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$browser',0)"; | ||
| 2543 : | $sql['os'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$os',1)"; | ||
| 2544 : | $sql['domain'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$tldomain',2)"; | ||
| 2545 : | if ($stats) foreach ($stats as $stat) { | ||
| 2546 : | if ($stat->type == 0) $sql['browser'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$browser' AND type=0"; | ||
| 2547 : | if ($stat->type == 1) $sql['os'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$os' AND type=1"; | ||
| 2548 : | if ($stat->type == 2) $sql['domain'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$tldomain' AND type=2"; | ||
| 2549 : | } | ||
| 2550 : | $this->_db->setQuery(implode('; ',$sql)); | ||
| 2551 : | $this->_db->query_batch(); | ||
| 2552 : | } | ||
| 2553 : | } | ||
| 2554 : | |||
| 2555 : | /** | ||
| 2556 : | * @return correct Itemid for Content Item | ||
| 2557 : | */ | ||
| 2558 : | function getItemid ($id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1) { | ||
| 2559 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 2560 : | $handler =& contentHandler::getInstance(); | ||
| 2561 : | return $handler->getItemid($id, $typed, $link, $bs, $bc, $gbs); | ||
| 2562 : | } | ||
| 2563 : | |||
| 2564 : | function liveBookMark () { | ||
| 2565 : | // support for Firefox Live Bookmarks ability for site syndication | ||
| 2566 : | $live_bookmark = 0; | ||
| 2567 : | $c_handler =& mosComponentHandler::getInstance(); | ||
| 2568 : | $params =& $c_handler->getParamsByName('Syndicate'); | ||
| 2569 : | if (!is_null($params)){ | ||
| 2570 : | $live_bookmark = $params->get( 'live_bookmark', 0 ); | ||
| 2571 : | } | ||
| 2572 : | |||
| 2573 : | if ($live_bookmark) { | ||
| 2574 : | // custom bookmark file name | ||
| 2575 : | $bookmark_file = $params->get( 'bookmark_file', $live_bookmark ); | ||
| 2576 : | $link_file = mamboCore::get('mosConfig_live_site').'/cache/'. $bookmark_file; | ||
| 2577 : | $filename = mamboCore::get('mosConfig_absolute_path').'/cache/'. $bookmark_file; | ||
| 2578 : | $cache = $params->get( 'cache', 1 ); | ||
| 2579 : | $cache_time = $params->get( 'cache_time', 3600 ); | ||
| 2580 : | $title = $params->def( 'title', mamboCore::get('mosConfig_sitename') ); | ||
| 2581 : | // checks to see if cache file exists, to determine whether to create a new one | ||
| 2582 : | if ( !file_exists( $filename ) || ( ( time() - filemtime( $filename ) ) > $cache_time ) ) { | ||
| 2583 : | $task = 'live_bookmark'; | ||
| 2584 : | // sets bookmark feed type | ||
| 2585 : | $_GET['feed'] = str_replace( '.xml', '', $live_bookmark ); | ||
| 2586 : | // loads rss component to create bookmark file | ||
| 2587 : | require_once( mamboCore::get('mosConfig_absolute_path').'/components/com_rss/rss.php' ); | ||
| 2588 : | } | ||
| 2589 : | // outputs link tag for page | ||
| 2590 : | ?> | ||
| 2591 : | <link rel="alternate" type="application/rss+xml" title="<?php echo $title; ?>" href="<?php echo $link_file; ?>" /> | ||
| 2592 : | <?php | ||
| 2593 : | } | ||
| 2594 : | } | ||
| 2595 : | /** | ||
| 2596 : | * Render head tags | ||
| 2597 : | * tags are assembled into an associative array with the following elements: | ||
| 2598 : | * - title | ||
| 2599 : | * - meta | ||
| 2600 : | * - mambojavascript | ||
| 2601 : | * - custom (custom head tags) | ||
| 2602 : | * - livebookmark | ||
| 2603 : | * - favicon | ||
| 2604 : | * @param unknown keys - array elements to output (null = output all) | ||
| 2605 : | * @param unknown exclude - array elements to exclude in output | ||
| 2606 : | * | ||
| 2607 : | * Usage: mosShowHead() - to render all tags | ||
| 2608 : | * mosShowHead('title') - to render a single tag | ||
| 2609 : | * mosShowHead(array('title', 'meta')) - to selectively render tags (in order) | ||
| 2610 : | * mosShowHead(null, 'custom') - to exclude a single tag | ||
| 2611 : | * mosShowHead(null, array('custom','favicon')) - to exclude multiple tags | ||
| 2612 : | */ | ||
| 2613 : | function mosShowHead($keys='', $exclude='') { | ||
| 2614 : | if (!is_array($keys)) | ||
| 2615 : | if ($keys !== '' && !is_null($keys)) | ||
| 2616 : | $keys = array($keys); | ||
| 2617 : | else $keys = array(); | ||
| 2618 : | if (!is_array($exclude)) | ||
| 2619 : | if ($exclude !== '') | ||
| 2620 : | $exclude = array($exclude); | ||
| 2621 : | else $exclude = array(); | ||
| 2622 : | |||
| 2623 : | $this->_head['output'] = array(); | ||
| 2624 : | |||
| 2625 : | $head = array();; | ||
| 2626 : | $head['title'] = '<title>'.$this->_head['title'].'</title>'; | ||
| 2627 : | |||
| 2628 : | $this->appendMetaTag( 'description', mamboCore::get('mosConfig_MetaDesc'), true ); | ||
| 2629 : | $this->appendMetaTag( 'keywords', mamboCore::get('mosConfig_MetaKeys'), true ); | ||
| 2630 : | $head['meta'] = array(); | ||
| 2631 : | foreach ($this->_head['meta'] as $name=>$meta) { | ||
| 2632 : | if ($meta[1]) $head['meta'][] = $meta[1]; | ||
| 2633 : | $head['meta'][] = '<meta name="' . $name . '" content="' . $meta[0] . '" />'; | ||
| 2634 : | if ($meta[2]) $head['meta'][] = $meta[2]; | ||
| 2635 : | } | ||
| 2636 : | $head['meta'] = implode( "\n", $head['meta'] ); | ||
| 2637 : | |||
| 2638 : | $my = mamboCore::get('currentUser'); | ||
| 2639 : | $head['mambojavascript'] = $my->id ? "<script language=\"JavaScript1.2\" src=".mamboCore::get('mosConfig_live_site')."/includes/js/mambojavascript.js\" type=\"text/javascript\"></script>" : ''; | ||
| 2640 : | |||
| 2641 : | $head['custom'] = array(); | ||
| 2642 : | foreach ($this->_head['custom'] as $html) | ||
| 2643 : | if (trim($html) !== '') | ||
| 2644 : | $head['custom'][] = $html; | ||
| 2645 : | if (count($head['custom']) !== 0) | ||
| 2646 : | $head['custom'] = implode( "\n", $head['custom'] ); | ||
| 2647 : | else | ||
| 2648 : | $head['custom'] = ''; | ||
| 2649 : | |||
| 2650 : | ob_start(); | ||
| 2651 : | $this->liveBookMark(); | ||
| 2652 : | $head['livebookmark'] = ob_get_contents(); | ||
| 2653 : | ob_end_clean(); | ||
| 2654 : | |||
| 2655 : | $configuration =& mamboCore::getMamboCore(); | ||
| 2656 : | $head['favicon'] = "<link rel=\"shortcut icon\" href=\"".$configuration->getFavIcon()."\" />"; | ||
| 2657 : | |||
| 2658 : | foreach($head as $key=>$value) | ||
| 2659 : | $this->_head['output'][$key] = "$value"; | ||
| 2660 : | |||
| 2661 : | $tags = $this->_head['output']; | ||
| 2662 : | if (count($keys) == 0) { | ||
| 2663 : | foreach($tags as $key=>$value) | ||
| 2664 : | if (!in_array($key, $exclude)) | ||
| 2665 : | if ($value !== '') | ||
| 2666 : | echo trim($value)."\n"; | ||
| 2667 : | } else { | ||
| 2668 : | foreach($keys as $key) | ||
| 2669 : | if (isset($tags[$key])) | ||
| 2670 : | if(trim($tags[$key]) !== '') | ||
| 2671 : | echo trim($tags[$key])."\n"; | ||
| 2672 : | } | ||
| 2673 : | } | ||
| 2674 : | |||
| 2675 : | /** | ||
| 2676 : | * retained for backward compatability | ||
| 2677 : | */ | ||
| 2678 : | function getBlogSectionCount() { | ||
| 2679 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 2680 : | $handler =& new contentHandler(); | ||
| 2681 : | return $handler->getBlogSectionCount(); | ||
| 2682 : | } | ||
| 2683 : | |||
| 2684 : | function getBlogCategoryCount() { | ||
| 2685 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 2686 : | $handler =& new contentHandler(); | ||
| 2687 : | return $handler->getBlogCategoryCount(); | ||
| 2688 : | } | ||
| 2689 : | |||
| 2690 : | function getGlobalBlogSectionCount() { | ||
| 2691 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 2692 : | $handler =& new contentHandler(); | ||
| 2693 : | return $handler->getGlobalBlogSectionCount(); | ||
| 2694 : | } | ||
| 2695 : | |||
| 2696 : | function getStaticContentCount() { | ||
| 2697 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 2698 : | $handler =& new contentHandler(); | ||
| 2699 : | return $handler->getStaticContentCount(); | ||
| 2700 : | } | ||
| 2701 : | |||
| 2702 : | function getContentItemLinkCount() { | ||
| 2703 : | require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); | ||
| 2704 : | $handler =& new contentHandler(); | ||
| 2705 : | return $handler->getContentItemLinkCount(); | ||
| 2706 : | } | ||
| 2707 : | /** | ||
| 2708 : | * retained for backward compatability | ||
| 2709 : | */ | ||
| 2710 : | |||
| 2711 : | } | ||
| 2712 : | |||
| 2713 : | /** | ||
| 2714 : | * Class to support function caching | ||
| 2715 : | * @package Mambo | ||
| 2716 : | */ | ||
| 2717 : | class mosCache { | ||
| 2718 : | /** | ||
| 2719 : | * @return object A function cache object | ||
| 2720 : | */ | ||
| 2721 : | function &getCache( $group='' ) { | ||
| 2722 : | $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); | ||
| 2723 : | require_once($mosConfig_absolute_path.'/includes/Cache/Lite/Function.php'); | ||
| 2724 : | $path = mamboCore::get('mosConfig_cachepath'); | ||
| 2725 : | $caching = mamboCore::get('mosConfig_caching'); | ||
| 2726 : | $time = mamboCore::get('mosConfig_cachetime'); | ||
| 2727 : | $options = array( | ||
| 2728 : | 'cacheDir' => "$path/", | ||
| 2729 : | 'caching' => $caching, | ||
| 2730 : | 'defaultGroup' => $group, | ||
| 2731 : | 'lifeTime' => $time | ||
| 2732 : | ); | ||
| 2733 : | $cache =& new Cache_Lite_Function( $options ); | ||
| 2734 : | return $cache; | ||
| 2735 : | } | ||
| 2736 : | /** | ||
| 2737 : | * Cleans the cache | ||
| 2738 : | */ | ||
| 2739 : | function cleanCache ($group=false) { | ||
| 2740 : | if (mamboCore::get('mosConfig_caching')) { | ||
| 2741 : | $cache =& mosCache::getCache( $group ); | ||
| 2742 : | $cache->clean( $group ); | ||
| 2743 : | } | ||
| 2744 : | } | ||
| 2745 : | } | ||
| 2746 : | |||
| 2747 : | /** | ||
| 2748 : | * Session database table class | ||
| 2749 : | * @package Mambo | ||
| 2750 : | */ | ||
| 2751 : | class mosSession extends mosDBTable { | ||
| 2752 : | /** @var int Primary key */ | ||
| 2753 : | var $session_id=null; | ||
| 2754 : | /** @var time */ | ||
| 2755 : | var $time=null; | ||
| 2756 : | /** @var int User ID */ | ||
| 2757 : | var $userid=0; | ||
| 2758 : | /** @var string */ | ||
| 2759 : | var $usertype=null; | ||
| 2760 : | /** @var string */ | ||
| 2761 : | var $username=''; | ||
| 2762 : | /** @var int User group ID */ | ||
| 2763 : | var $gid=0; | ||
| 2764 : | /** @var int */ | ||
| 2765 : | var $guest=1; | ||
| 2766 : | /** @var string */ | ||
| 2767 : | var $_session_cookie=null; | ||
| 2768 : | |||
| 2769 : | /** | ||
| 2770 : | * @param database A database connector object | ||
| 2771 : | */ | ||
| 2772 : | function mosSession() { | ||
| 2773 : | $database =& mamboDatabase::getInstance(); | ||
| 2774 : | $this->mosDBTable( '#__session', 'session_id', $database ); | ||
| 2775 : | $this->time = time(); | ||
| 2776 : | } | ||
| 2777 : | |||
| 2778 : | function validate ($user) { | ||
| 2779 : | // check against db record of session | ||
| 2780 : | $session_id = mosGetParam( $_SESSION, 'session_id', '' ); | ||
| 2781 : | $logintime = mosGetParam( $_SESSION, 'session_logintime', '' ); | ||
| 2782 : | if ($session_id == md5( $user->id.$user->username.$user->usertype.$logintime )) { | ||
| 2783 : | $current_time = time(); | ||
| 2784 : | $database =& mamboDatabase::getInstance(); | ||
| 2785 : | $database->setQuery ("UPDATE #__session" | ||
| 2786 : | . "\nSET time='$current_time', guest=-3-guest" | ||
| 2787 : | . "\nWHERE session_id='$session_id'" | ||
| 2788 : | . " AND username = '" . $database->getEscaped( $user->username ) . "'" | ||
| 2789 : | . " AND userid = " . intval( $user->id ) | ||
| 2790 : | ); | ||
| 2791 : | if (!$result = $database->query()) echo $database->stderr(); | ||
| 2792 : | elseif ($database->getAffectedRows() == 1) return true; | ||
| 2793 : | } | ||
| 2794 : | return false; | ||
| 2795 : | } | ||
| 2796 : | |||
| 2797 : | function &getCurrent () { | ||
| 2798 : | static $currentSession; | ||
| 2799 : | if (!is_object($currentSession)) { | ||
| 2800 : | $currentSession = new mosSession(); | ||
| 2801 : | mosSession::purge(); | ||
| 2802 : | $sessionCookieName = md5('site'.mamboCore::get('mosConfig_live_site')); | ||
| 2803 : | $sessioncookie = mosGetParam($_COOKIE, $sessionCookieName, null); | ||
| 2804 : | $usercookie = mosGetParam($_COOKIE, 'usercookie', null); | ||
| 2805 : | if ($currentSession->load(md5($sessioncookie.$_SERVER['REMOTE_ADDR']))) { | ||
| 2806 : | // Session cookie exists, update time in session table | ||
| 2807 : | $currentSession->time = time(); | ||
| 2808 : | $currentSession->update(); | ||
| 2809 : | } else { | ||
| 2810 : | $currentSession->generateId(); | ||
| 2811 : | if (!$currentSession->insert()) { | ||
| 2812 : | die( $currentSession->getError() ); | ||
| 2813 : | } | ||
| 2814 : | setcookie( $sessionCookieName, $currentSession->getCookie(), time() + 43200, '/' ); | ||
| 2815 : | //$_COOKIE["sessioncookie"] = $session->getCookie(); | ||
| 2816 : | if ($usercookie) { | ||
| 2817 : | // Remember me cookie exists. Login with usercookie info. | ||
| 2818 : | require_once (mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php'); | ||
| 2819 : | $authenticator =& mamboAuthenticator::getInstance(); | ||
| 2820 : | $authenticator->authenticateUser ($message, $usercookie['username'], $usercookie['password'], null, $currentSession); | ||
| 2821 : | } | ||
| 2822 : | } | ||
| 2823 : | } | ||
| 2824 : | return $currentSession; | ||
| 2825 : | } | ||
| 2826 : | |||
| 2827 : | function insert() { | ||
| 2828 : | $ret = $this->_db->insertObject( $this->_tbl, $this ); | ||
| 2829 : | |||
| 2830 : | if( !$ret ) { | ||
| 2831 : | $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->stderr(); | ||
| 2832 : | return false; | ||
| 2833 : | } else { | ||
| 2834 : | return true; | ||
| 2835 : | } | ||
| 2836 : | } | ||
| 2837 : | |||
| 2838 : | function update( $updateNulls=false ) { | ||
| 2839 : | $ret = $this->_db->updateObject( $this->_tbl, $this, 'session_id', $updateNulls ); | ||
| 2840 : | |||
| 2841 : | if( !$ret ) { | ||
| 2842 : | $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->stderr(); | ||
| 2843 : | return false; | ||
| 2844 : | } else { | ||
| 2845 : | return true; | ||
| 2846 : | } | ||
| 2847 : | } | ||
| 2848 : | |||
| 2849 : | function generateId() { | ||
| 2850 : | $failsafe = 20; | ||
| 2851 : | $randnum = 0; | ||
| 2852 : | while ($failsafe--) { | ||
| 2853 : | $randnum = md5( uniqid( microtime(), 1 ) ); | ||
| 2854 : | if ($randnum != "") { | ||
| 2855 : | $cryptrandnum = md5( $randnum ); | ||
| 2856 : | $this->_db->setQuery( "SELECT $this->_tbl_key FROM $this->_tbl WHERE $this->_tbl_key=MD5('$randnum')" ); | ||
| 2857 : | if(!($result = $this->_db->query())) { | ||
| 2858 : | die( $this->_db->stderr( true )); | ||
| 2859 : | // todo: handle gracefully | ||
| 2860 : | } | ||
| 2861 : | if ($this->_db->getNumRows($result) == 0) { | ||
| 2862 : | break; | ||
| 2863 : | } | ||
| 2864 : | } | ||
| 2865 : | } | ||
| 2866 : | $this->_session_cookie = $randnum; | ||
| 2867 : | $this->session_id = md5( $randnum . $_SERVER['REMOTE_ADDR'] ); | ||
| 2868 : | } | ||
| 2869 : | |||
| 2870 : | function getCookie() { | ||
| 2871 : | return $this->_session_cookie; | ||
| 2872 : | } | ||
| 2873 : | |||
| 2874 : | function purge() { | ||
| 2875 : | $past = time() - intval(mamboCore::get('mosConfig_lifetime')); | ||
| 2876 : | $adminpast = time() - 3600; | ||
| 2877 : | $database =& mamboDatabase::getInstance(); | ||
| 2878 : | $database->setQuery("DELETE FROM #__session WHERE (time<$past AND guest>=0) OR (time<$adminpast AND guest<0)"); | ||
| 2879 : | return $database->query(); | ||
| 2880 : | } | ||
| 2881 : | |||
| 2882 : | } | ||
| 2883 : | |||
| 2884 : | /** | ||
| 2885 : | * Parameters handler | ||
| 2886 : | * @package Mambo | ||
| 2887 : | */ | ||
| 2888 : | class mosParameters { | ||
| 2889 : | /** @var object */ | ||
| 2890 : | var $_params = null; | ||
| 2891 : | /** @var string The raw params string */ | ||
| 2892 : | var $_raw = null; | ||
| 2893 : | /** | ||
| 2894 : | * Constructor | ||
| 2895 : | * @param string The raw parms text | ||
| 2896 : | * @param string Path to the xml setup file | ||
| 2897 : | * @var string The type of setup file | ||
| 2898 : | */ | ||
| 2899 : | function mosParameters( $text, $process_sections = false) { | ||
| 2900 : | $this->_params = $this->parse( $text, $process_sections ); | ||
| 2901 : | $this->_raw = $text; | ||
| 2902 : | } | ||
| 2903 : | /** | ||
| 2904 : | * Get the result of parsing the string provided on creation | ||
| 2905 : | * @return string parsed result | ||
| 2906 : | */ | ||
| 2907 : | function getParams () { | ||
| 2908 : | return $this->_params; | ||
| 2909 : | } | ||
| 2910 : | /** | ||
| 2911 : | * @param string The name of the param | ||
| 2912 : | * @param string The value of the parameter | ||
| 2913 : | * @return string The set value | ||
| 2914 : | */ | ||
| 2915 : | function set( $key, $value='' ) { | ||
| 2916 : | $this->_params->$key = $value; | ||
| 2917 : | return $value; | ||
| 2918 : | } | ||
| 2919 : | /** | ||
| 2920 : | * Sets a default value if not alreay assigned | ||
| 2921 : | * @param string The name of the param | ||
| 2922 : | * @param string The value of the parameter | ||
| 2923 : | * @return string The set value | ||
| 2924 : | */ | ||
| 2925 : | function def( $key, $value='' ) { | ||
| 2926 : | return $this->set( $key, $this->get( $key, $value ) ); | ||
| 2927 : | } | ||
| 2928 : | /** | ||
| 2929 : | * @param string The name of the param | ||
| 2930 : | * @param mixed The default value if not found | ||
| 2931 : | * @return string | ||
| 2932 : | */ | ||
| 2933 : | function get( $key, $default='' ) { | ||
| 2934 : | if (isset( $this->_params->$key )) return $this->_params->$key === '' ? $default : $this->_params->$key; | ||
| 2935 : | else return $default; | ||
| 2936 : | } | ||
| 2937 : | /** | ||
| 2938 : | * Look to see if string is bracketed by opener and closer | ||
| 2939 : | * If so, extract and trim the bracketed string | ||
| 2940 : | * Otherwise, return a null string | ||
| 2941 : | **/ | ||
| 2942 : | function getBracketed ($text, $opener, $closer) { | ||
| 2943 : | if (strlen($text) > 1 AND ($text[0] != $opener OR substr($text,-1) != $closer)) return ''; | ||
| 2944 : | else return trim(substr($text,1,-1)); | ||
| 2945 : | } | ||
| 2946 : | /** | ||
| 2947 : | * Parse an .ini string, based on phpDocumentor phpDocumentor_parse_ini_file function | ||
| 2948 : | * @param mixed The ini string or array of lines | ||
| 2949 : | * @param boolean add an associative index for each section [in brackets] | ||
| 2950 : | * @return object | ||
| 2951 : | */ | ||
| 2952 : | function parse( $txt, $process_sections = false ) { | ||
| 2953 : | $result = new stdClass(); | ||
| 2954 : | if (is_string($txt)) $lines = explode( "\n", $txt ); | ||
| 2955 : | elseif (is_array($txt)) $lines = $txt; | ||
| 2956 : | else return $result; | ||
| 2957 : | |||
| 2958 : | $sec_name = ''; | ||
| 2959 : | $unparsed = 0; | ||
| 2960 : | |||
| 2961 : | foreach ($lines as $line) { | ||
| 2962 : | // ignore comments and null lines | ||
| 2963 : | $line = trim($line); | ||
| 2964 : | if (strlen($line) == 0 OR $line[0] == ';') continue; | ||
| 2965 : | |||
| 2966 : | if ($sec_name = $this->getBracketed($line, '[', ']')) { | ||
| 2967 : | if ($process_sections) $result->$sec_name = new stdClass(); | ||
| 2968 : | continue; | ||
| 2969 : | } | ||
| 2970 : | |||
| 2971 : | if (count($propsetter = explode ('=', $line, 2)) == 2) { | ||
| 2972 : | $property = trim($propsetter[0]); | ||
| 2973 : | if ($pquoted = $this->getBracketed($property, '"', '"')) $property = stripcslashes($pquoted); | ||
| 2974 : | $value = trim($propsetter[1]); | ||
| 2975 : | if ($value == 'false') $value = false; | ||
| 2976 : | elseif ($value == 'true') $value = true; | ||
| 2977 : | else if ($vquoted = $this->getBracketed($value, '"', '"')) $value = stripcslashes($vquoted); | ||
| 2978 : | if ($process_sections AND $sec_name) $result->$sec_name->$property = $value; | ||
| 2979 : | else $result->$property = $value; | ||
| 2980 : | } | ||
| 2981 : | else { | ||
| 2982 : | $property = '__invalid' . $unparsed++ . '__'; | ||
| 2983 : | if ($process_sections AND $sec_name) $result->$sec_name->$property = $line; | ||
| 2984 : | else $result->$property = $line; | ||
| 2985 : | } | ||
| 2986 : | } | ||
| 2987 : | return $result; | ||
| 2988 : | } | ||
| 2989 : | /** | ||
| 2990 : | * @param string The name of the control, or the default text area if a setup file is not found | ||
| 2991 : | * @return string HTML | ||
| 2992 : | */ | ||
| 2993 : | function render( $name='params' ) { | ||
| 2994 : | if (is_file($this->_path)) { | ||
| 2995 : | $parser = new mosXMLParams ($this->_path, $this, $name); | ||
| 2996 : | if (count($parser->html)) return implode("\n", $parser->html); | ||
| 2997 : | } | ||
| 2998 : | $raw = $this->_raw; | ||
| 2999 : | return "<textarea name='$name' cols='40' rows='10' class='text_area'>$raw</textarea>"; | ||
| 3000 : | } | ||
| 3001 : | |||
| 3002 : | /** | ||
| 3003 : | * special handling for textarea param | ||
| 3004 : | */ | ||
| 3005 : | function textareaHandling( &$txt ) { | ||
| 3006 : | foreach ($txt as $key=>$value) $txt[$key] = str_replace("\n", '<br />', $value); | ||
| 3007 : | return implode( "\n", $txt ); | ||
| 3008 : | } | ||
| 3009 : | } | ||
| 3010 : | |||
| 3011 : | /** | ||
| 3012 : | * Page generation time | ||
| 3013 : | * @package Mambo | ||
| 3014 : | */ | ||
| 3015 : | class mosProfiler { | ||
| 3016 : | var $start=0; | ||
| 3017 : | var $prefix=''; | ||
| 3018 : | |||
| 3019 : | function mosProfiler( $prefix='' ) { | ||
| 3020 : | $this->start = $this->getmicrotime(); | ||
| 3021 : | $this->prefix = $prefix; | ||
| 3022 : | } | ||
| 3023 : | |||
| 3024 : | function mark( $label ) { | ||
| 3025 : | return sprintf ( "\n<div class=\"profiler\">$this->prefix %.3f $label</div>", $this->getmicrotime() - $this->start ); | ||
| 3026 : | } | ||
| 3027 : | |||
| 3028 : | function getmicrotime(){ | ||
| 3029 : | list($usec, $sec) = explode(" ",microtime()); | ||
| 3030 : | return ((float)$usec + (float)$sec); | ||
| 3031 : | } | ||
| 3032 : | } | ||
| 3033 : | |||
| 3034 : | |||
| 3035 : | /** | ||
| 3036 : | * @author Mikolaj Jedrzejak <mikolajj@op.pl> | ||
| 3037 : | * @copyright Copyright Mikolaj Jedrzejak (c) 2003-2004 | ||
| 3038 : | * @version 1.0 2004-07-27 00:37 | ||
| 3039 : | * @link http://www.unicode.org Unicode Homepage | ||
| 3040 : | * @link http://www.mikkom.pl My Homepage | ||
| 3041 : | * | ||
| 3042 : | **/ | ||
| 3043 : | $PATH_TO_CLASS = dirname(ereg_replace("\\\\","/",__FILE__)) . "/" . "ConvertTables" . "/"; | ||
| 3044 : | @require_once($PATH_TO_CLASS."/charsetmapping.php"); | ||
| 3045 : | define ("CONVERT_TABLES_DIR", $PATH_TO_CLASS); | ||
| 3046 : | define ("DEBUG_MODE", 1); | ||
| 3047 : | |||
| 3048 : | /** | ||
| 3049 : | * -- 1.0 2004-07-28 -- | ||
| 3050 : | * | ||
| 3051 : | * -- The most important thing -- | ||
| 3052 : | * I want to thank all people who helped me fix all bugs, small and big once. | ||
| 3053 : | * I hope that you don't mind that your names are in this file. | ||
| 3054 : | * | ||
| 3055 : | * -- Some Apache issues -- | ||
| 3056 : | * I get info from Lukas Lisa, that in some cases with special apache configuration | ||
| 3057 : | * you have to put header() function with proper encoding to get your result | ||
| 3058 : | * displayed correctly. | ||
| 3059 : | * If you want to see what I mean, go to demo.php and demo1.php | ||
| 3060 : | * | ||
| 3061 : | * -- BETA 1.0 2003-10-21 -- | ||
| 3062 : | * | ||
| 3063 : | * -- You should know about... -- | ||
| 3064 : | * For good understanding this class you shouls read all this stuff first :) but if you are | ||
| 3065 : | * in a hurry just start the demo.php and see what's inside. | ||
| 3066 : | * 1. That I'm not good in english at 03:45 :) - so forgive me all mistakes | ||
| 3067 : | * 2. This class is a BETA version because I haven't tested it enough | ||
| 3068 : | * 3. Feel free to contact me with questions, bug reports and mistakes in PHP and this documentation (email below) | ||
| 3069 : | * | ||
| 3070 : | * -- In a few words... -- | ||
| 3071 : | * Why ConvertCharset class? | ||
| 3072 : | * | ||
| 3073 : | * I have made this class because I had a lot of problems with diferent charsets. First because people | ||
| 3074 : | * from Microsoft wanted to have thair own encoding, second because people from Macromedia didn't | ||
| 3075 : | * thought about other languages, third because sometimes I need to use text written on MAC, and of course | ||
| 3076 : | * it has its own encoding :) | ||
| 3077 : | * | ||
| 3078 : | * Notice & remember: | ||
| 3079 : | * - When I'm saying 1 byte string I mean 1 byte per char. | ||
| 3080 : | * - When I'm saying multibyte string I mean more than one byte per char. | ||
| 3081 : | * | ||
| 3082 : | * So, this are main FEATURES of this class: | ||
| 3083 : | * - conversion between 1 byte charsets | ||
| 3084 : | * - conversion from 1 byte to multi byte charset (utf-8) | ||
| 3085 : | * - conversion from multibyte charset (utf-8) to 1 byte charset | ||
| 3086 : | * - every conversion output can be save with numeric entities (browser charset independent - not a full truth) | ||
| 3087 : | * | ||
| 3088 : | * This is a list of charsets you can operate with, the basic rule is that a char have to be in both charsets, | ||
| 3089 : | * otherwise you'll get an error. | ||
| 3090 : | * | ||
| 3091 : | * - WINDOWS | ||
| 3092 : | * - windows-1250 - Central Europe | ||
| 3093 : | * - windows-1251 - Cyrillic | ||
| 3094 : | * - windows-1252 - Latin I | ||
| 3095 : | * - windows-1253 - Greek | ||
| 3096 : | * - windows-1254 - Turkish | ||
| 3097 : | * - windows-1255 - Hebrew | ||
| 3098 : | * - windows-1256 - Arabic | ||
| 3099 : | * - windows-1257 - Baltic | ||
| 3100 : | * - windows-1258 - Viet Nam | ||
| 3101 : | * - cp874 - Thai - this file is also for DOS | ||
| 3102 : | * | ||
| 3103 : | * - DOS | ||
| 3104 : | * - cp437 - Latin US | ||
| 3105 : | * - cp737 - Greek | ||
| 3106 : | * - cp775 - BaltRim | ||
| 3107 : | * - cp850 - Latin1 | ||
| 3108 : | * - cp852 - Latin2 | ||
| 3109 : | * - cp855 - Cyrylic | ||
| 3110 : | * - cp857 - Turkish | ||
| 3111 : | * - cp860 - Portuguese | ||
| 3112 : | * - cp861 - Iceland | ||
| 3113 : | * - cp862 - Hebrew | ||
| 3114 : | * - cp863 - Canada | ||
| 3115 : | * - cp864 - Arabic | ||
| 3116 : | * - cp865 - Nordic | ||
| 3117 : | * - cp866 - Cyrylic Russian (this is the one, used in IE "Cyrillic (DOS)" ) | ||
| 3118 : | * - cp869 - Greek2 | ||
| 3119 : | * | ||
| 3120 : | * - MAC (Apple) | ||
| 3121 : | * - x-mac-cyrillic | ||
| 3122 : | * - x-mac-greek | ||
| 3123 : | * - x-mac-icelandic | ||
| 3124 : | * - x-mac-ce | ||
| 3125 : | * - x-mac-roman | ||
| 3126 : | * | ||
| 3127 : | * - ISO (Unix/Linux) | ||
| 3128 : | * - iso-8859-1 | ||
| 3129 : | * - iso-8859-2 | ||
| 3130 : | * - iso-8859-3 | ||
| 3131 : | * - iso-8859-4 | ||
| 3132 : | * - iso-8859-5 | ||
| 3133 : | * - iso-8859-6 | ||
| 3134 : | * - iso-8859-7 | ||
| 3135 : | * - iso-8859-8 | ||
| 3136 : | * - iso-8859-9 | ||
| 3137 : | * - iso-8859-10 | ||
| 3138 : | * - iso-8859-11 | ||
| 3139 : | * - iso-8859-12 | ||
| 3140 : | * - iso-8859-13 | ||
| 3141 : | * - iso-8859-14 | ||
| 3142 : | * - iso-8859-15 | ||
| 3143 : | * - iso-8859-16 | ||
| 3144 : | * | ||
| 3145 : | * - MISCELLANEOUS | ||
| 3146 : | * - gsm0338 (ETSI GSM 03.38) | ||
| 3147 : | * - cp037 | ||
| 3148 : | * - cp424 | ||
| 3149 : | * - cp500 | ||
| 3150 : | * - cp856 | ||
| 3151 : | * - cp875 | ||
| 3152 : | * - cp1006 | ||
| 3153 : | * - cp1026 | ||
| 3154 : | * - koi8-r (Cyrillic) | ||
| 3155 : | * - koi8-u (Cyrillic Ukrainian) | ||
| 3156 : | * - nextstep | ||
| 3157 : | * - us-ascii | ||
| 3158 : | * - us-ascii-quotes | ||
| 3159 : | * | ||
| 3160 : | * - DSP implementation for NeXT | ||
| 3161 : | * - stdenc | ||
| 3162 : | * - symbol | ||
| 3163 : | * - zdingbat | ||
| 3164 : | * | ||
| 3165 : | * - And specially for old Polish programs | ||
| 3166 : | * - mazovia | ||
| 3167 : | * | ||
| 3168 : | * -- Now, to the point... -- | ||
| 3169 : | * Here are main variables. | ||
| 3170 : | * | ||
| 3171 : | * DEBUG_MODE | ||
| 3172 : | * | ||
| 3173 : | * You can set this value to: | ||
| 3174 : | * - -1 - No errors or comments | ||
| 3175 : | * - 0 - Only error messages, no comments | ||
| 3176 : | * - 1 - Error messages and comments | ||
| 3177 : | * | ||
| 3178 : | * Default value is 1, and during first steps with class it should be left as is. | ||
| 3179 : | * | ||
| 3180 : | * CONVERT_TABLES_DIR | ||
| 3181 : | * | ||
| 3182 : | * This is a place where you store all files with charset encodings. Filenames should have | ||
| 3183 : | * the same names as encodings. My advise is to keep existing names, because thay | ||
| 3184 : | * were taken from unicode.org (www.unicode.org), and after update to unicode 3.0 or 4.0 | ||
| 3185 : | * the names of files will be the same, so if you want to save your time...uff, leave the | ||
| 3186 : | * names as thay are for future updates. | ||
| 3187 : | * | ||
| 3188 : | * The directory with edings files should be in a class location directory by default, | ||
| 3189 : | * but of course you can change it if you like. | ||
| 3190 : | * | ||
| 3191 : | * @package All about charset... | ||
| 3192 : | * @author Mikolaj Jedrzejak <mikolajj@op.pl> | ||
| 3193 : | * @copyright Copyright Mikolaj Jedrzejak (c) 2003-2004 | ||
| 3194 : | * @version 1.0 2004-07-27 23:11 | ||
| 3195 : | * @access public | ||
| 3196 : | * | ||
| 3197 : | * @link http://www.unicode.org Unicode Homepage | ||
| 3198 : | **/ | ||
| 3199 : | class ConvertCharset { | ||
| 3200 : | var $RecognizedEncoding; //This value keeps information if string contains multibyte chars. | ||
| 3201 : | var $Entities; // This value keeps information if output should be with numeric entities. | ||
| 3202 : | |||
| 3203 : | /** | ||
| 3204 : | * CharsetChange::NumUnicodeEntity() | ||
| 3205 : | * | ||
| 3206 : | * Unicode encoding bytes, bits representation. | ||
| 3207 : | * Each b represents a bit that can be used to store character data. | ||
| 3208 : | * - bytes, bits, binary representation | ||
| 3209 : | * - 1, 7, 0bbbbbbb | ||
| 3210 : | * - 2, 11, 110bbbbb 10bbbbbb | ||
| 3211 : | * - 3, 16, 1110bbbb 10bbbbbb 10bbbbbb | ||
| 3212 : | * - 4, 21, 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb | ||
| 3213 : | * | ||
| 3214 : | * This function is written in a "long" way, for everyone who woluld like to analize | ||
| 3215 : | * the process of unicode encoding and understand it. All other functions like HexToUtf | ||
| 3216 : | * will be written in a "shortest" way I can write tham :) it does'n mean thay are short | ||
| 3217 : | * of course. You can chech it in HexToUtf() (link below) - very similar function. | ||
| 3218 : | * | ||
| 3219 : | * IMPORTANT: Remember that $UnicodeString input CANNOT have single byte upper half | ||
| 3220 : | * extended ASCII codes, why? Because there is a posibility that this function will eat | ||
| 3221 : | * the following char thinking it's miltibyte unicode char. | ||
| 3222 : | * | ||
| 3223 : | * @param string $UnicodeString Input Unicode string (1 char can take more than 1 byte) | ||
| 3224 : | * @return string This is an input string olso with unicode chars, bus saved as entities | ||
| 3225 : | * @see HexToUtf() | ||
| 3226 : | **/ | ||
| 3227 : | function UnicodeEntity ($UnicodeString) | ||
| 3228 : | { | ||
| 3229 : | $OutString = ""; | ||
| 3230 : | $StringLenght = strlen ($UnicodeString); | ||
| 3231 : | for ($CharPosition = 0; $CharPosition < $StringLenght; $CharPosition++) | ||
| 3232 : | { | ||
| 3233 : | $Char = $UnicodeString [$CharPosition]; | ||
| 3234 : | $AsciiChar = ord ($Char); | ||
| 3235 : | |||
| 3236 : | if ($AsciiChar < 128) //1 7 0bbbbbbb (127) | ||
| 3237 : | { | ||
| 3238 : | $OutString .= $Char; | ||
| 3239 : | } | ||
| 3240 : | else if ($AsciiChar >> 5 == 6) //2 11 110bbbbb 10bbbbbb (2047) | ||
| 3241 : | { | ||
| 3242 : | $FirstByte = ($AsciiChar & 31); | ||
| 3243 : | $CharPosition++; | ||
| 3244 : | $Char = $UnicodeString [$CharPosition]; | ||
| 3245 : | $AsciiChar = ord ($Char); | ||
| 3246 : | $SecondByte = ($AsciiChar & 63); | ||
| 3247 : | $AsciiChar = ($FirstByte * 64) + $SecondByte; | ||
| 3248 : | $Entity = sprintf ("&#%d;", $AsciiChar); | ||
| 3249 : | $OutString .= $Entity; | ||
| 3250 : | } | ||
| 3251 : | else if ($AsciiChar >> 4 == 14) //3 16 1110bbbb 10bbbbbb 10bbbbbb | ||
| 3252 : | { | ||
| 3253 : | $FirstByte = ($AsciiChar & 31); | ||
| 3254 : | $CharPosition++; | ||
| 3255 : | $Char = $UnicodeString [$CharPosition]; | ||
| 3256 : | $AsciiChar = ord ($Char); | ||
| 3257 : | $SecondByte = ($AsciiChar & 63); | ||
| 3258 : | $CharPosition++; | ||
| 3259 : | $Char = $UnicodeString [$CharPosition]; | ||
| 3260 : | $AsciiChar = ord ($Char); | ||
| 3261 : | $ThidrByte = ($AsciiChar & 63); | ||
| 3262 : | $AsciiChar = ((($FirstByte * 64) + $SecondByte) * 64) + $ThidrByte; | ||
| 3263 : | |||
| 3264 : | $Entity = sprintf ("&#%d;", $AsciiChar); | ||
| 3265 : | $OutString .= $Entity; | ||
| 3266 : | } | ||
| 3267 : | else if ($AsciiChar >> 3 == 30) //4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb | ||
| 3268 : | { | ||
| 3269 : | $FirstByte = ($AsciiChar & 31); | ||
| 3270 : | $CharPosition++; | ||
| 3271 : | $Char = $UnicodeString [$CharPosition]; | ||
| 3272 : | $AsciiChar = ord ($Char); | ||
| 3273 : | $SecondByte = ($AsciiChar & 63); | ||
| 3274 : | $CharPosition++; | ||
| 3275 : | $Char = $UnicodeString [$CharPosition]; | ||
| 3276 : | $AsciiChar = ord ($Char); | ||
| 3277 : | $ThidrByte = ($AsciiChar & 63); | ||
| 3278 : | $CharPosition++; | ||
| 3279 : | $Char = $UnicodeString [$CharPosition]; | ||
| 3280 : | $AsciiChar = ord ($Char); | ||
| 3281 : | $FourthByte = ($AsciiChar & 63); | ||
| 3282 : | $AsciiChar = ((((($FirstByte * 64) + $SecondByte) * 64) + $ThidrByte) * 64) + $FourthByte; | ||
| 3283 : | |||
| 3284 : | $Entity = sprintf ("&#%d;", $AsciiChar); | ||
| 3285 : | $OutString .= $Entity; | ||
| 3286 : | } | ||
| 3287 : | } | ||
| 3288 : | return $OutString; | ||
| 3289 : | } | ||
| 3290 : | |||
| 3291 : | /** | ||
| 3292 : | * ConvertCharset::HexToUtf() | ||
| 3293 : | * | ||
| 3294 : | * This simple function gets unicode char up to 4 bytes and return it as a regular char. | ||
| 3295 : | * It is very similar to UnicodeEntity function (link below). There is one difference | ||
| 3296 : | * in returned format. This time it's a regular char(s), in most cases it will be one or two chars. | ||
| 3297 : | * | ||
| 3298 : | * @param string $UtfCharInHex Hexadecimal value of a unicode char. | ||
| 3299 : | * @return string Encoded hexadecimal value as a regular char. | ||
| 3300 : | * @see UnicodeEntity() | ||
| 3301 : | **/ | ||
| 3302 : | function HexToUtf ($UtfCharInHex) | ||
| 3303 : | { | ||
| 3304 : | $OutputChar = ""; | ||
| 3305 : | $UtfCharInDec = hexdec($UtfCharInHex); | ||
| 3306 : | if($UtfCharInDec<128) $OutputChar .= chr($UtfCharInDec); | ||
| 3307 : | else if($UtfCharInDec<2048)$OutputChar .= chr(($UtfCharInDec>>6)+192).chr(($UtfCharInDec&63)+128); | ||
| 3308 : | else if($UtfCharInDec<65536)$OutputChar .= chr(($UtfCharInDec>>12)+224).chr((($UtfCharInDec>>6)&63)+128).chr(($UtfCharInDec&63)+128); | ||
| 3309 : | else if($UtfCharInDec<2097152)$OutputChar .= chr($UtfCharInDec>>18+240).chr((($UtfCharInDec>>12)&63)+128).chr(($UtfCharInDec>>6)&63+128). chr($UtfCharInDec&63+128); | ||
| 3310 : | return $OutputChar; | ||
| 3311 : | } | ||
| 3312 : | |||
| 3313 : | |||
| 3314 : | /** | ||
| 3315 : | * CharsetChange::MakeConvertTable() | ||
| 3316 : | * | ||
| 3317 : | * This function creates table with two SBCS (Single Byte Character Set). Every conversion | ||
| 3318 : | * is through this table. | ||
| 3319 : | * | ||
| 3320 : | * - The file with encoding tables have to be save in "Format A" of unicode.org charset table format! This is usualy writen in a header of every charset file. | ||
| 3321 : | * - BOTH charsets MUST be SBCS | ||
| 3322 : | * - The files with encoding tables have to be complet (Non of chars can be missing, unles you are sure you are not going to use it) | ||
| 3323 : | * | ||
| 3324 : | * "Format A" encoding file, if you have to build it by yourself should aplly these rules: | ||
| 3325 : | * - you can comment everything with # | ||
| 3326 : | * - first column contains 1 byte chars in hex starting from 0x.. | ||
| 3327 : | * - second column contains unicode equivalent in hex starting from 0x.... | ||
| 3328 : | * - then every next column is optional, but in "Format A" it should contain unicode char name or/and your own comment | ||
| 3329 : | * - the columns can be splited by "spaces", "tabs", "," or any combination of these | ||
| 3330 : | * - below is an example | ||
| 3331 : | * | ||
| 3332 : | * <code> | ||
| 3333 : | * # | ||
| 3334 : | * # The entries are in ANSI X3.4 order. | ||
| 3335 : | * # | ||
| 3336 : | * 0x00 0x0000 # NULL end extra comment, if needed | ||
| 3337 : | * 0x01 0x0001 # START OF HEADING | ||
| 3338 : | * # Oh, one more thing, you can make comments inside of a rows if you like. | ||
| 3339 : | * 0x02 0x0002 # START OF TEXT | ||
| 3340 : | * 0x03 0x0003 # END OF TEXT | ||
| 3341 : | * next line, and so on... | ||
| 3342 : | * </code> | ||
| 3343 : | * | ||
| 3344 : | * You can get full tables with encodings from http://www.unicode.org | ||
| 3345 : | * | ||
| 3346 : | * @param string $FirstEncoding Name of first encoding and first encoding filename (thay have to be the same) | ||
| 3347 : | * @param string $SecondEncoding Name of second encoding and second encoding filename (thay have to be the same). Optional for building a joined table. | ||
| 3348 : | * @return array Table necessary to change one encoding to another. | ||
| 3349 : | **/ | ||
| 3350 : | function MakeConvertTable ($FirstEncoding, $SecondEncoding = "") | ||
| 3351 : | { | ||
| 3352 : | $ConvertTable = array(); | ||
| 3353 : | for($i = 0; $i < func_num_args(); $i++) | ||
| 3354 : | { | ||
| 3355 : | /** | ||
| 3356 : | * Because func_*** can't be used inside of another function call | ||
| 3357 : | * we have to save it as a separate value. | ||
| 3358 : | **/ | ||
| 3359 : | $FileName = func_get_arg($i); | ||
| 3360 : | if (!is_file(CONVERT_TABLES_DIR . $FileName)) | ||
| 3361 : | { | ||
| 3362 : | print $this->DebugOutput(0, 0, CONVERT_TABLES_DIR . $FileName); //Print an error message | ||
| 3363 : | exit; | ||
| 3364 : | } | ||
| 3365 : | $FileWithEncTabe = fopen(CONVERT_TABLES_DIR . $FileName, "r") or die(); //This die(); is just to make sure... | ||
| 3366 : | while(!feof($FileWithEncTabe)) | ||
| 3367 : | { | ||
| 3368 : | /** | ||
| 3369 : | * We asume that line is not longer | ||
| 3370 : | * than 1024 which is the default value for fgets function | ||
| 3371 : | **/ | ||
| 3372 : | if($OneLine=trim(fgets($FileWithEncTabe, 1024))) | ||
| 3373 : | { | ||
| 3374 : | /** | ||
| 3375 : | * We don't need all comment lines. I check only for "#" sign, because | ||
| 3376 : | * this is a way of making comments by unicode.org in thair encoding files | ||
| 3377 : | * and that's where the files are from :-) | ||
| 3378 : | **/ | ||
| 3379 : | if (substr($OneLine, 0, 1) != "#") | ||
| 3380 : | { | ||
| 3381 : | /** | ||
| 3382 : | * Sometimes inside the charset file the hex walues are separated by | ||
| 3383 : | * "space" and sometimes by "tab", the below preg_split can also be used | ||
| 3384 : | * to split files where separator is a ",", "\r", "\n" and "\f" | ||
| 3385 : | **/ | ||
| 3386 : | $HexValue = preg_split ("/[\s,]+/", $OneLine, 3); //We need only first 2 values | ||
| 3387 : | /** | ||
| 3388 : | * Sometimes char is UNDEFINED, or missing so we can't use it for convertion | ||
| 3389 : | **/ | ||
| 3390 : | if (substr($HexValue[1], 0, 1) != "#") | ||
| 3391 : | { | ||
| 3392 : | $ArrayKey = strtoupper(str_replace(strtolower("0x"), "", $HexValue[1])); | ||
| 3393 : | $ArrayValue = strtoupper(str_replace(strtolower("0x"), "", $HexValue[0])); | ||
| 3394 : | $ConvertTable[func_get_arg($i)][$ArrayKey] = $ArrayValue; | ||
| 3395 : | } | ||
| 3396 : | } //if (substr($OneLine,... | ||
| 3397 : | } //if($OneLine=trim(f... | ||
| 3398 : | } //while(!feof($FirstFileWi... | ||
| 3399 : | } //for($i = 0; $i < func_... | ||
| 3400 : | /** | ||
| 3401 : | * The last thing is to check if by any reason both encoding tables are not the same. | ||
| 3402 : | * For example, it will happen when you save the encoding table file with a wrong name | ||
| 3403 : | * - of another charset. | ||
| 3404 : | **/ | ||
| 3405 : | if ((func_num_args() > 1) && (count($ConvertTable[$FirstEncoding]) == count($ConvertTable[$SecondEncoding])) && (count(array_diff_assoc($ConvertTable[$FirstEncoding], $ConvertTable[$SecondEncoding])) == 0)) | ||
| 3406 : | { | ||
| 3407 : | print $this->DebugOutput(1, 1, "$FirstEncoding, $SecondEncoding"); | ||
| 3408 : | } | ||
| 3409 : | return $ConvertTable; | ||
| 3410 : | } | ||
| 3411 : | |||
| 3412 : | |||
| 3413 : | |||
| 3414 : | /** | ||
| 3415 : | * ConvertCharset::Convert() | ||
| 3416 : | * | ||
| 3417 : | * This is a basic function you are using. I hope that you can figure out this function syntax :-) | ||
| 3418 : | * | ||
| 3419 : | * @param string $StringToChange The string you want to change :) | ||
| 3420 : | * @param string $FromCharset Name of $StringToChange encoding, you have to know it. | ||
| 3421 : | * @param string $ToCharset Name of a charset you want to get for $StringToChange. | ||
| 3422 : | * @param boolean $TurnOnEntities Set to true or 1 if you want to use numeric entities insted of regular chars. | ||
| 3423 : | * @return string Converted string in brand new encoding :) | ||
| 3424 : | * @version 1.0 2004-07-27 01:09 | ||
| 3425 : | **/ | ||
| 3426 : | function Convert ($StringToChange, $FromCharset, $ToCharset, $TurnOnEntities = false) | ||
| 3427 : | { | ||
| 3428 : | /** | ||
| 3429 : | * Check are there all variables | ||
| 3430 : | **/ | ||
| 3431 : | /*if ($StringToChange == "") | ||
| 3432 : | { | ||
| 3433 : | print $this->DebugOutput(0, 3, "\$StringToChange"); | ||
| 3434 : | } | ||
| 3435 : | else*/ | ||
| 3436 : | if ($FromCharset == "") | ||
| 3437 : | { | ||
| 3438 : | print $this->DebugOutput(0, 3, "\$FromCharset"); | ||
| 3439 : | } | ||
| 3440 : | else if ($ToCharset == "") | ||
| 3441 : | { | ||
| 3442 : | print $this->DebugOutput(0, 3, "\$ToCharset"); | ||
| 3443 : | } | ||
| 3444 : | |||
| 3445 : | /** | ||
| 3446 : | * Now a few variables need to be set. | ||
| 3447 : | **/ | ||
| 3448 : | $NewString = ""; | ||
| 3449 : | $this->Entities = $TurnOnEntities; | ||
| 3450 : | |||
| 3451 : | /** | ||
| 3452 : | * For all people who like to use uppercase for charset encoding names :) | ||
| 3453 : | **/ | ||
| 3454 : | $FromCharset = strtolower($FromCharset); | ||
| 3455 : | $ToCharset = strtolower($ToCharset); | ||
| 3456 : | |||
| 3457 : | /** | ||
| 3458 : | * Of course you can make a conversion from one charset to the same one :) | ||
| 3459 : | * but I feel obligate to let you know about it. | ||
| 3460 : | **/ | ||
| 3461 : | if ($FromCharset == $ToCharset) | ||
| 3462 : | { | ||
| 3463 : | print $this->DebugOutput(1, 0, $FromCharset); | ||
| 3464 : | } | ||
| 3465 : | if (($FromCharset == $ToCharset) AND ($FromCharset == "utf-8")) | ||
| 3466 : | { | ||
| 3467 : | print $this->DebugOutput(0, 4, $FromCharset); | ||
| 3468 : | exit; | ||
| 3469 : | } | ||
| 3470 : | |||
| 3471 : | /** | ||
| 3472 : | * This divison was made to prevent errors during convertion to/from utf-8 with | ||
| 3473 : | * "entities" enabled, because we need to use proper destination(to)/source(from) | ||
| 3474 : | * encoding table to write proper entities. | ||
| 3475 : | * | ||
| 3476 : | * This is the first case. We are convertinf from 1byte chars... | ||
| 3477 : | **/ | ||
| 3478 : | if ($FromCharset != "utf-8") | ||
| 3479 : | { | ||
| 3480 : | /** | ||
| 3481 : | * Now build table with both charsets for encoding change. | ||
| 3482 : | **/ | ||
| 3483 : | if ($ToCharset != "utf-8") | ||
| 3484 : | { | ||
| 3485 : | $CharsetTable = $this->MakeConvertTable ($FromCharset, $ToCharset); | ||
| 3486 : | } | ||
| 3487 : | else | ||
| 3488 : | { | ||
| 3489 : | $CharsetTable = $this->MakeConvertTable ($FromCharset); | ||
| 3490 : | } | ||
| 3491 : | /** | ||
| 3492 : | * For each char in a string... | ||
| 3493 : | **/ | ||
| 3494 : | for ($i = 0; $i < strlen($StringToChange); $i++) | ||
| 3495 : | { | ||
| 3496 : | $HexChar = ""; | ||
| 3497 : | $UnicodeHexChar = ""; | ||
| 3498 : | $HexChar = strtoupper(dechex(ord($StringToChange[$i]))); | ||
| 3499 : | // This is fix from Mario Klingemann, it prevents | ||
| 3500 : | // droping chars below 16 because of missing leading 0 [zeros] | ||
| 3501 : | if (strlen($HexChar)==1) $HexChar = "0".$HexChar; | ||
| 3502 : | //end of fix by Mario Klingemann | ||
| 3503 : | // This is quick fix of 10 chars in gsm0338 | ||
| 3504 : | // Thanks goes to Andrea Carpani who pointed on this problem | ||
| 3505 : | // and solve it ;) | ||
| 3506 : | if (($FromCharset == "gsm0338") && ($HexChar == '1B')) { | ||
| 3507 : | $i++; | ||
| 3508 : | $HexChar .= strtoupper(dechex(ord($StringToChange[$i]))); | ||
| 3509 : | } | ||
| 3510 : | // end of workarround on 10 chars from gsm0338 | ||
| 3511 : | if ($ToCharset != "utf-8") | ||
| 3512 : | { | ||
| 3513 : | if (in_array($HexChar, $CharsetTable[$FromCharset])) | ||
| 3514 : | { | ||
| 3515 : | $UnicodeHexChar = array_search($HexChar, $CharsetTable[$FromCharset]); | ||
| 3516 : | $UnicodeHexChars = explode("+",$UnicodeHexChar); | ||
| 3517 : | for($UnicodeHexCharElement = 0; $UnicodeHexCharElement < count($UnicodeHexChars); $UnicodeHexCharElement++) | ||
| 3518 : | { | ||
| 3519 : | if (array_key_exists($UnicodeHexChars[$UnicodeHexCharElement], $CharsetTable[$ToCharset])) | ||
| 3520 : | { | ||
| 3521 : | if ($this->Entities == true) | ||
| 3522 : | { | ||
| 3523 : | $NewString .= $this->UnicodeEntity($this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement])); | ||
| 3524 : | } | ||
| 3525 : | else | ||
| 3526 : | { | ||
| 3527 : | $NewString .= chr(hexdec($CharsetTable[$ToCharset][$UnicodeHexChars[$UnicodeHexCharElement]])); | ||
| 3528 : | } | ||
| 3529 : | } | ||
| 3530 : | else | ||
| 3531 : | { | ||
| 3532 : | print $this->DebugOutput(0, 1, $StringToChange[$i]); | ||
| 3533 : | } | ||
| 3534 : | } //for($UnicodeH... | ||
| 3535 : | } | ||
| 3536 : | else | ||
| 3537 : | { | ||
| 3538 : | print $this->DebugOutput(0, 2,$StringToChange[$i]); | ||
| 3539 : | } | ||
| 3540 : | } | ||
| 3541 : | else | ||
| 3542 : | { | ||
| 3543 : | if (in_array("$HexChar", $CharsetTable[$FromCharset])) | ||
| 3544 : | { | ||
| 3545 : | $UnicodeHexChar = array_search($HexChar, $CharsetTable[$FromCharset]); | ||
| 3546 : | /** | ||
| 3547 : | * Sometimes there are two or more utf-8 chars per one regular char. | ||
| 3548 : | * Extream, example is polish old Mazovia encoding, where one char contains | ||
| 3549 : | * two lettes 007a (z) and 0142 (l slash), we need to figure out how to | ||
| 3550 : | * solve this problem. | ||
| 3551 : | * The letters are merge with "plus" sign, there can be more than two chars. | ||
| 3552 : | * In Mazowia we have 007A+0142, but sometimes it can look like this | ||
| 3553 : | * 0x007A+0x0142+0x2034 (that string means nothing, it just shows the possibility...) | ||
| 3554 : | **/ | ||
| 3555 : | $UnicodeHexChars = explode("+",$UnicodeHexChar); | ||
| 3556 : | for($UnicodeHexCharElement = 0; $UnicodeHexCharElement < count($UnicodeHexChars); $UnicodeHexCharElement++) | ||
| 3557 : | { | ||
| 3558 : | if ($this->Entities == true) | ||
| 3559 : | { | ||
| 3560 : | $NewString .= $this->UnicodeEntity($this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement])); | ||
| 3561 : | } | ||
| 3562 : | else | ||
| 3563 : | { | ||
| 3564 : | $NewString .= $this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement]); | ||
| 3565 : | } | ||
| 3566 : | } // for | ||
| 3567 : | } | ||
| 3568 : | else | ||
| 3569 : | { | ||
| 3570 : | print $this->DebugOutput(0, 2, $StringToChange[$i]); | ||
| 3571 : | } | ||
| 3572 : | } | ||
| 3573 : | } | ||
| 3574 : | } | ||
| 3575 : | /** | ||
| 3576 : | * This is second case. We are encoding from multibyte char string. | ||
| 3577 : | **/ | ||
| 3578 : | else if($FromCharset == "utf-8") | ||
| 3579 : | { | ||
| 3580 : | $HexChar = ""; | ||
| 3581 : | $UnicodeHexChar = ""; | ||
| 3582 : | $CharsetTable = $this->MakeConvertTable ($ToCharset); | ||
| 3583 : | foreach ($CharsetTable[$ToCharset] as $UnicodeHexChar => $HexChar) | ||
| 3584 : | { | ||
| 3585 : | if ($this->Entities == true) { | ||
| 3586 : | $EntitieOrChar = $this->UnicodeEntity($this->HexToUtf($UnicodeHexChar)); | ||
| 3587 : | } | ||
| 3588 : | else | ||
| 3589 : | { | ||
| 3590 : | $EntitieOrChar = chr(hexdec($HexChar)); | ||
| 3591 : | } | ||
| 3592 : | $StringToChange = str_replace($this->HexToUtf($UnicodeHexChar), $EntitieOrChar, $StringToChange); | ||
| 3593 : | } | ||
| 3594 : | $NewString = $StringToChange; | ||
| 3595 : | } | ||
| 3596 : | |||
| 3597 : | return $NewString; | ||
| 3598 : | } | ||
| 3599 : | |||
| 3600 : | /** | ||
| 3601 : | * ConvertCharset::DebugOutput() | ||
| 3602 : | * | ||
| 3603 : | * This function is not really necessary, the debug output could stay inside of | ||
| 3604 : | * source code but like this, it's easier to manage and translate. | ||
| 3605 : | * Besides I couldn't find good coment/debug class :-) Maybe I'll write one someday... | ||
| 3606 : | * | ||
| 3607 : | * All messages depend on DEBUG_MODE level, as I was writing before you can set this value to: | ||
| 3608 : | * - -1 - No errors or notces are shown | ||
| 3609 : | * - 0 - Only error messages are shown, no notices | ||
| 3610 : | * - 1 - Error messages and notices are shown | ||
| 3611 : | * | ||
| 3612 : | * @param int $Group Message groupe: error - 0, notice - 1 | ||
| 3613 : | * @param int $Number Following message number | ||
| 3614 : | * @param mix $Value This walue is whatever you want, usualy it's some parameter value, for better message understanding. | ||
| 3615 : | * @return string String with a proper message. | ||
| 3616 : | **/ | ||
| 3617 : | function DebugOutput ($Group, $Number, $Value = false) | ||
| 3618 : | { | ||
| 3619 : | //$Debug [$Group][$Number] = "Message, can by with $Value"; | ||
| 3620 : | //$Group[0] - Errors | ||
| 3621 : | //$Group[1] - Notice | ||
| 3622 : | $Debug[0][0] = "Error, can NOT read file: " . $Value . "<br />"; | ||
| 3623 : | $Debug[0][1] = "Error, can't find maching char \"". $Value ."\" in destination encoding table!" . "<br />"; | ||
| 3624 : | $Debug[0][2] = "Error, can't find maching char \"". $Value ."\" in source encoding table!" . "<br />"; | ||
| 3625 : | $Debug[0][3] = "Error, you did NOT set variable " . $Value . " in Convert() function." . "<br />"; | ||
| 3626 : | $Debug[0][4] = "You can NOT convert string from " . $Value . " to " . $Value . "!" . "<br />"; | ||
| 3627 : | $Debug[1][0] = "Notice, you are trying to convert string from ". $Value ." to ". $Value .", don't you feel it's strange? ;-)" . "<br />"; | ||
| 3628 : | $Debug[1][1] = "Notice, both charsets " . $Value . " are identical! Check encoding tables files." . "<br />"; | ||
| 3629 : | $Debug[1][2] = "Notice, there is no unicode char in the string you are trying to convert." . "<br />"; | ||
| 3630 : | |||
| 3631 : | if (DEBUG_MODE >= $Group) | ||
| 3632 : | { | ||
| 3633 : | return $Debug[$Group][$Number]; | ||
| 3634 : | } | ||
| 3635 : | } // function DebugOutput | ||
| 3636 : | |||
| 3637 : | } //class ends here | ||
| 3638 : | alwarren | 1341 | |
| 3639 : | class mosHtmlHelper { | ||
| 3640 : | var $_docTypes = array( | ||
| 3641 : | 'xhtml-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', | ||
| 3642 : | 'xhtml-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', | ||
| 3643 : | 'xhtml-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', | ||
| 3644 : | 'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' | ||
| 3645 : | ); | ||
| 3646 : | var $_docTypesText = array( | ||
| 3647 : | 'xhtml-strict' => 'XHTML 1.0 Strict', | ||
| 3648 : | 'xhtml-trans' => 'XHTML 1.0 Transitional', | ||
| 3649 : | 'xhtml-frame' => 'XHTML 1.0 Frameset', | ||
| 3650 : | 'xhtml11' => 'XHTML 1.1' | ||
| 3651 : | ); | ||
| 3652 : | var $doctype = 'xhtml-trans'; | ||
| 3653 : | |||
| 3654 : | /** | ||
| 3655 : | * Singleton accessor | ||
| 3656 : | */ | ||
| 3657 : | function &getInstance () { | ||
| 3658 : | static $instance; | ||
| 3659 : | if (!is_object($instance)) $instance = new mosHtmlHelper(); | ||
| 3660 : | return $instance; | ||
| 3661 : | } | ||
| 3662 : | function __docType($type=null) { | ||
| 3663 : | static $obj; | ||
| 3664 : | if (!is_object($obj)) $obj =& mosHtmlHelper::getInstance(); | ||
| 3665 : | |||
| 3666 : | if (array_key_exists($type, $obj->_docTypes)) return $obj->_docTypes[$type]; | ||
| 3667 : | return $obj->_docTypes[$obj->doctype]; | ||
| 3668 : | } | ||
| 3669 : | function renderDocType($type=null) { | ||
| 3670 : | static $obj; | ||
| 3671 : | if (!is_object($obj)) $obj =& mosHtmlHelper::getInstance(); | ||
| 3672 : | |||
| 3673 : | echo $obj->__docType($type)."\n"; | ||
| 3674 : | } | ||
| 3675 : | function get($var) { | ||
| 3676 : | static $obj; | ||
| 3677 : | if (!is_object($obj)) $obj =& mosHtmlHelper::getInstance(); | ||
| 3678 : | |||
| 3679 : | if(isset($obj->$var)) return $obj->$var; | ||
| 3680 : | return null; | ||
| 3681 : | } | ||
| 3682 : | function set($property, $value) { | ||
| 3683 : | static $obj; | ||
| 3684 : | if (!is_object($obj)) $obj =& mosHtmlHelper::getInstance(); | ||
| 3685 : | |||
| 3686 : | if($property{0} == '_') return; // dont set private properties | ||
| 3687 : | if (isset($obj->$property)) $obj->$property = $value; | ||
| 3688 : | } | ||
| 3689 : | } // end class mosHtmlHelper | ||
| 3690 : | alwarren | 1331 | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

