Annotation of /mambo/branches/4.5.4/index.php
Parent Directory
|
Revision Log
Revision 83 - (view) (download)
| 1 : | counterpoi | 4 | t <?php |
| 2 : | t /** | ||
| 3 : | t * @version $Id: index.php,v 1.47 2005/08/26 08:10:43 mambofoundation Exp $ | ||
| 4 : | t * @package Mambo | ||
| 5 : | t * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 6 : | t * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | t * Mambo is Free Software | ||
| 8 : | t */ | ||
| 9 : | t | ||
| 10 : | t /** Set flag that this is a parent file */ | ||
| 11 : | t define( '_VALID_MOS', 1 ); | ||
| 12 : | t | ||
| 13 : | t $protects = array('_REQUEST', '_GET', '_POST', '_COOKIE', '_FILES', '_SERVER', '_ENV', 'GLOBALS', '_SESSION'); | ||
| 14 : | t | ||
| 15 : | t foreach ($protects as $protect) { | ||
| 16 : | t if ( in_array($protect , array_keys($_REQUEST)) || | ||
| 17 : | t in_array($protect , array_keys($_GET)) || | ||
| 18 : | t in_array($protect , array_keys($_POST)) || | ||
| 19 : | t in_array($protect , array_keys($_COOKIE)) || | ||
| 20 : | t in_array($protect , array_keys($_FILES))) { | ||
| 21 : | t die("Invalid Request."); | ||
| 22 : | t } | ||
| 23 : | t } | ||
| 24 : | t | ||
| 25 : | t /** | ||
| 26 : | t * Utility function to return a value from a named array or a specified default | ||
| 27 : | t */ | ||
| 28 : | t define( "_MOS_NOTRIM", 0x0001 ); | ||
| 29 : | t define( "_MOS_ALLOWHTML", 0x0002 ); | ||
| 30 : | t define( "_MOS_ALLOWRAW", 0x0004 ); | ||
| 31 : | t define( "_MOS_NOMAGIC", 0x0008 ); | ||
| 32 : | t function mosGetParam( &$arr, $name, $def=null, $mask=0 ) { | ||
| 33 : | t if (isset( $arr[$name] )) { | ||
| 34 : | counterpoi | 9 | t if (is_array($arr[$name])) foreach ($arr[$name] as $key=>$element) $result[$key] = mosGetParam ($arr[$name], $key, $def, $mask); |
| 35 : | counterpoi | 4 | t else { |
| 36 : | counterpoi | 9 | t $result = $arr[$name]; |
| 37 : | t if (!($mask&_MOS_NOTRIM)) $result = trim($result); | ||
| 38 : | t if (!is_numeric( $result)) { | ||
| 39 : | t if (!($mask&_MOS_ALLOWHTML)) $result = strip_tags($result); | ||
| 40 : | counterpoi | 4 | t if (!($mask&_MOS_ALLOWRAW)) { |
| 41 : | counterpoi | 9 | t if (is_numeric($def)) $result = intval($result); |
| 42 : | counterpoi | 4 | t } |
| 43 : | t } | ||
| 44 : | t } | ||
| 45 : | counterpoi | 9 | t return $result; |
| 46 : | counterpoi | 4 | t } else { |
| 47 : | t return $def; | ||
| 48 : | t } | ||
| 49 : | t } | ||
| 50 : | t | ||
| 51 : | counterpoi | 79 | t function sefRelToAbs ($string) { |
| 52 : | t $sef = mosSEF::getInstance(); | ||
| 53 : | t return $sef->sefRelToAbs($string); | ||
| 54 : | t } | ||
| 55 : | t | ||
| 56 : | t | ||
| 57 : | counterpoi | 4 | t /** |
| 58 : | t * @version $Id: version.php,v 1.6 2005/08/17 04:03:42 eddieajau Exp $ | ||
| 59 : | t * @package Mambo | ||
| 60 : | t * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 61 : | t * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 62 : | t * Mambo is Free Software | ||
| 63 : | t */ | ||
| 64 : | t | ||
| 65 : | t /** Version information */ | ||
| 66 : | t class version { | ||
| 67 : | t /** @var string Product */ | ||
| 68 : | t var $PRODUCT = 'Mambo'; | ||
| 69 : | t /** @var int Main Release Level */ | ||
| 70 : | t var $RELEASE = '4.5'; | ||
| 71 : | t /** @var string Development Status */ | ||
| 72 : | t var $DEV_STATUS = 'Stable'; | ||
| 73 : | t /** @var int Sub Release Level */ | ||
| 74 : | t var $DEV_LEVEL = '4'; | ||
| 75 : | t /** @var string Codename */ | ||
| 76 : | t var $CODENAME = 'Titan'; | ||
| 77 : | t /** @var string Date */ | ||
| 78 : | t var $RELDATE = '17-Aug-2005'; | ||
| 79 : | t /** @var string Time */ | ||
| 80 : | t var $RELTIME = '03:00'; | ||
| 81 : | t /** @var string Timezone */ | ||
| 82 : | t var $RELTZ = 'GMT'; | ||
| 83 : | t /** @var string Copyright Text */ | ||
| 84 : | t var $COPYRIGHT = 'Copyright 2000 - 2005 Miro International Pty Ltd. All rights reserved.'; | ||
| 85 : | t /** @var string URL */ | ||
| 86 : | t var $URL = '<a href="http://www.mamboserver.com">Mambo</a> is Free Software released under the GNU/GPL License.'; | ||
| 87 : | t } | ||
| 88 : | t | ||
| 89 : | t class mamboCore { | ||
| 90 : | t var $rootPath = ''; | ||
| 91 : | t var $Itemid = 0; | ||
| 92 : | t var $option = ''; | ||
| 93 : | t var $_db; | ||
| 94 : | t var $do_gzip_compress = false; | ||
| 95 : | counterpoi | 67 | t var $_section_limit = 250; |
| 96 : | t var $_section_status = 0; | ||
| 97 : | t var $_sections; | ||
| 98 : | counterpoi | 4 | t |
| 99 : | t function mamboCore () { | ||
| 100 : | t global $adminside; | ||
| 101 : | t $this->rootPath = $this->allButLast('/',$_SERVER['SCRIPT_FILENAME']); | ||
| 102 : | t if ($adminside) $this->rootPath = substr($this->rootPath,0,strlen($this->rootPath)-14); | ||
| 103 : | t $this->checkConfig(); | ||
| 104 : | t $this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0); | ||
| 105 : | t $this->getConfig(); | ||
| 106 : | t $this->fixLanguage(); | ||
| 107 : | t $this->secure(); | ||
| 108 : | t } | ||
| 109 : | t | ||
| 110 : | t function &getMamboCore () { | ||
| 111 : | t static $instance; | ||
| 112 : | counterpoi | 16 | t if (!is_object($instance)) $instance = new mamboCore(); |
| 113 : | counterpoi | 4 | t return $instance; |
| 114 : | t } | ||
| 115 : | t | ||
| 116 : | t function rootPath () { | ||
| 117 : | t if (realpath($this->rootPath) === false) die ('Invalid program load path'); | ||
| 118 : | t return $this->rootPath; | ||
| 119 : | t } | ||
| 120 : | t | ||
| 121 : | t function get ($property) { | ||
| 122 : | t $config =& mamboCore::getMamboCore(); | ||
| 123 : | t if ($property == 'mosConfig_absolute_path' AND realpath($config->mosConfig_absolute_path) === false) die ('Invalid program load path'); | ||
| 124 : | t if (isset($config->$property)) return $config->$property; | ||
| 125 : | t trigger_error("Invalid property ($property) requested from mamboCore"); | ||
| 126 : | t return null; | ||
| 127 : | t } | ||
| 128 : | t | ||
| 129 : | t function is_set ($property) { | ||
| 130 : | t $config =& mamboCore::getMamboCore(); | ||
| 131 : | t return isset($config->$property); | ||
| 132 : | t } | ||
| 133 : | t | ||
| 134 : | t function set ($property, $value) { | ||
| 135 : | t $config =& mamboCore::getMamboCore(); | ||
| 136 : | t $config->$property = $value; | ||
| 137 : | t $GLOBALS[$property] = $value; | ||
| 138 : | t return $value; | ||
| 139 : | t } | ||
| 140 : | t | ||
| 141 : | t function checkConfig () { | ||
| 142 : | t // checks for configuration file, if none found loads installation page | ||
| 143 : | t if (!file_exists($this->rootPath.'configuration.php') OR filesize($this->rootPath.'configuration.php') < 10 ) { | ||
| 144 : | t header( 'Location: installation/index.php' ); | ||
| 145 : | t exit(); | ||
| 146 : | t } | ||
| 147 : | t } | ||
| 148 : | t | ||
| 149 : | t function getConfig () { | ||
| 150 : | t $code = ''; | ||
| 151 : | t $f = @fopen($this->rootPath.'configuration.php','rb'); | ||
| 152 : | t if ($f) { | ||
| 153 : | t while ($f AND !feof($f)) { | ||
| 154 : | t $line = fgets($f, 256); | ||
| 155 : | t $altered = str_replace('$', '$this->', $line); | ||
| 156 : | t if ($line != $altered) $code .= $altered; | ||
| 157 : | t } | ||
| 158 : | t } | ||
| 159 : | t else { | ||
| 160 : | t header( 'Location: installation/index.php' ); | ||
| 161 : | t exit(); | ||
| 162 : | t } | ||
| 163 : | t fclose($f); | ||
| 164 : | t eval($code); | ||
| 165 : | t preg_match_all('/\$this\-\>([A-Za-z_][A-Za-z0-9_]*)/', $code, $matches); | ||
| 166 : | t foreach ($matches[1] as $match) $GLOBALS[$match] = $this->$match; | ||
| 167 : | t if (!isset($this->mosConfig_register_globals)) { | ||
| 168 : | t $this->mosConfig_register_globals = 0; | ||
| 169 : | t $GLOBALS['mosConfig_register_globals'] = 0; | ||
| 170 : | t } | ||
| 171 : | t } | ||
| 172 : | t | ||
| 173 : | t function offlineCheck (&$user, &$database) { | ||
| 174 : | t if ($this->mosConfig_offline) { | ||
| 175 : | t require_once($this->rootPath().'/administrator/includes/admin.php'); | ||
| 176 : | t session_name(md5($this->mosConfig_live_site)); | ||
| 177 : | t session_start(); | ||
| 178 : | t if ($user =& checkAdminSession($database)) return; | ||
| 179 : | t include("$this->mosConfig_absolute_path/offline.php"); | ||
| 180 : | t exit(); | ||
| 181 : | t } | ||
| 182 : | t } | ||
| 183 : | t | ||
| 184 : | t function fixLanguage () { | ||
| 185 : | t if (isset($this->mosConfig_lang) AND $this->mosConfig_lang); | ||
| 186 : | t else $this->set('mosConfig_lang', 'english'); | ||
| 187 : | t $language_file = "$this->mosConfig_absolute_path/language/$this->mosConfig_lang.php"; | ||
| 188 : | t if (file_exists($language_file)) require_once ($language_file); | ||
| 189 : | t } | ||
| 190 : | t | ||
| 191 : | t function secure () { | ||
| 192 : | t $this->mosConfig_unsecure_site = $this->mosConfig_live_site; | ||
| 193 : | t if ($_SERVER['SERVER_PORT'] == 443) { | ||
| 194 : | t if (!isset($this->mosConfig_secure_site)) $this->mosConfig_secure_site = str_replace('http://', 'https://', $this->mosConfig_live_site); | ||
| 195 : | t $this->mosConfig_live_site = $this->mosConfig_secure_site; | ||
| 196 : | t } | ||
| 197 : | t } | ||
| 198 : | t | ||
| 199 : | t function handleGlobals () { | ||
| 200 : | t $superglobals = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET); | ||
| 201 : | t if (isset( $_SESSION )) array_unshift ( $superglobals , $_SESSION ); | ||
| 202 : | t | ||
| 203 : | t // Emulate register_globals on | ||
| 204 : | t if (!ini_get('register_globals') && $this->mosConfig_register_globals) { | ||
| 205 : | counterpoi | 13 | t while(list($key,$value)=each($_GET)) { |
| 206 : | t if (!isset($GLOBALS[$key])) $GLOBALS[$key]=$value; | ||
| 207 : | t } | ||
| 208 : | counterpoi | 4 | t } |
| 209 : | t // Emulate register_globals off | ||
| 210 : | t elseif (ini_get('register_globals') && !$this->mosConfig_register_globals) { | ||
| 211 : | t foreach ( $superglobals as $superglobal ) { | ||
| 212 : | t foreach ( $superglobal as $key => $value) { | ||
| 213 : | t unset( $GLOBALS[$key]); | ||
| 214 : | t } | ||
| 215 : | t } | ||
| 216 : | t } | ||
| 217 : | t } | ||
| 218 : | t | ||
| 219 : | t function determineOptionAndItemid () { | ||
| 220 : | t if ($option = strtolower(mosGetParam($_REQUEST, 'option'))); | ||
| 221 : | t else { | ||
| 222 : | t if (!is_object($this->_db)) $this->_db = mamboDatabase::getInstance(); | ||
| 223 : | counterpoi | 13 | t $menuhandler = mosMenuHandler::getInstance(); |
| 224 : | t $menus =& $menuhandler->getByParentOrder($this->Itemid, 'mainmenu'); | ||
| 225 : | t $this->Itemid = $menus[0]->id; | ||
| 226 : | counterpoi | 20 | t $link = $menus[0]->link; |
| 227 : | counterpoi | 4 | t if (($pos = strpos( $link, '?' )) !== false) $link = substr( $link, $pos+1 ). '&Itemid='.$this->Itemid; |
| 228 : | t parse_str( $link, $temp ); | ||
| 229 : | t /** this is a patch, need to rework when globals are handled better */ | ||
| 230 : | t foreach ($temp as $k=>$v) $GLOBALS[$k] = $_REQUEST[$k] = $v; | ||
| 231 : | t if (isset($temp['option'])) $option = $temp['option']; | ||
| 232 : | t else return ''; | ||
| 233 : | t } | ||
| 234 : | t /** patch to lessen the impact on templates */ | ||
| 235 : | t if ($option == 'search') $option = 'com_search'; | ||
| 236 : | t // checking if we can find the Itemid thru the content | ||
| 237 : | t if ( $option == 'com_content' && $this->Itemid === 0 ) $this->Itemid = $this->getItemid(mosGetParam($_REQUEST, 'id', 0 )); | ||
| 238 : | t return $option; | ||
| 239 : | t } | ||
| 240 : | t | ||
| 241 : | t function redirect ($url, $msg='') { | ||
| 242 : | t $callcheck = array('InputFilter', 'process'); | ||
| 243 : | counterpoi | 83 | t if (!is_callable($callcheck)) require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpinputfilter/class.inputfilter.php'); |
| 244 : | counterpoi | 4 | t // specific filters |
| 245 : | counterpoi | 83 | t $iFilter =& new InputFilter(); |
| 246 : | counterpoi | 4 | t $url = $iFilter->process( $url ); |
| 247 : | t $message = trim($iFilter->process($msg)); | ||
| 248 : | t if ($iFilter->badAttributeValue(array('href', $url))) $url = $GLOBALS['mosConfig_live_site']; | ||
| 249 : | t if ($message) { | ||
| 250 : | t if (strpos($url, '?')) $url .= '&mosmsg='.urlencode($message); | ||
| 251 : | t else $url .= '?mosmsg='.urlencode($message); | ||
| 252 : | t } | ||
| 253 : | t if (headers_sent()) echo "<script>document.location.href='$url';</script>\n"; | ||
| 254 : | t else { | ||
| 255 : | t @ob_end_clean(); // clear output buffer | ||
| 256 : | t header( "Location: $url" ); | ||
| 257 : | t } | ||
| 258 : | t exit(); | ||
| 259 : | t } | ||
| 260 : | t | ||
| 261 : | t function logMessage ($text) { | ||
| 262 : | t // JS Popup message | ||
| 263 : | t if (mosGetParam( $_POST, 'message', 0 )) { | ||
| 264 : | t ?> | ||
| 265 : | t <script type="text/javascript"> | ||
| 266 : | t <!--// | ||
| 267 : | t alert( "<?php echo $text; ?>" ); | ||
| 268 : | t //--> | ||
| 269 : | t </script> | ||
| 270 : | t <?php | ||
| 271 : | t } | ||
| 272 : | t if ($return = mosGetParam( $_REQUEST, 'return', '' )) { | ||
| 273 : | t $this->redirect( $return ); | ||
| 274 : | t } | ||
| 275 : | t else { | ||
| 276 : | t $this->redirect( $this->mosConfig_live_site.'/index.php' ); | ||
| 277 : | t } | ||
| 278 : | t } | ||
| 279 : | t | ||
| 280 : | t function handleLogin ($session) { | ||
| 281 : | t require_once($this->rootPath().'/includes/authenticator.php'); | ||
| 282 : | t $authenticator = mamboAuthenticator::getInstance(); | ||
| 283 : | t $authenticator->loginUser(); | ||
| 284 : | t $this->logMessage(_LOGIN_SUCCESS); | ||
| 285 : | t } | ||
| 286 : | t | ||
| 287 : | t function handleLogout ($session) { | ||
| 288 : | t require_once($this->rootPath().'/includes/authenticator.php'); | ||
| 289 : | t $authenticator = mamboAuthenticator::getInstance(); | ||
| 290 : | t $authenticator->logoutUser(); | ||
| 291 : | t @session_destroy(); | ||
| 292 : | t $this->logMessage(_LOGOUT_SUCCESS); | ||
| 293 : | t } | ||
| 294 : | t | ||
| 295 : | t function standardHeaders () { | ||
| 296 : | t header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); | ||
| 297 : | t header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); | ||
| 298 : | t header( 'Cache-Control: no-store, no-cache, must-revalidate' ); | ||
| 299 : | t header( 'Cache-Control: post-check=0, pre-check=0', false ); | ||
| 300 : | t header( 'Pragma: no-cache' ); | ||
| 301 : | t } | ||
| 302 : | t | ||
| 303 : | t function initGzip() { | ||
| 304 : | t $this->do_gzip_compress = FALSE; | ||
| 305 : | t //zlib.output_compression and ob_gzhandler don't get along well so we'll check to make | ||
| 306 : | t //that zlib.output_compression is not enable in the php.ini before turning on ob_gzhandler | ||
| 307 : | t if ( $this->mosConfig_gzip == 1 && (int)ini_get('zlib.output_compression') != 1 ) { | ||
| 308 : | t $phpver = phpversion(); | ||
| 309 : | t $useragent = mosGetParam( $_SERVER, 'HTTP_USER_AGENT', '' ); | ||
| 310 : | t $canZip = mosGetParam( $_SERVER, 'HTTP_ACCEPT_ENCODING', '' ); | ||
| 311 : | t | ||
| 312 : | t if ( $phpver >= '4.0.4pl1' && | ||
| 313 : | t ( strpos($useragent,'compatible') !== false || | ||
| 314 : | t strpos($useragent,'Gecko') !== false | ||
| 315 : | t ) | ||
| 316 : | t ) { | ||
| 317 : | t if ( extension_loaded('zlib') ) { | ||
| 318 : | t ob_start( 'ob_gzhandler' ); | ||
| 319 : | t return; | ||
| 320 : | t } | ||
| 321 : | t } else if ( $phpver > '4.0' ) { | ||
| 322 : | t if ( strpos($canZip,'gzip') !== false ) { | ||
| 323 : | t if (extension_loaded( 'zlib' )) { | ||
| 324 : | t $this->do_gzip_compress = TRUE; | ||
| 325 : | t ob_start(); | ||
| 326 : | t ob_implicit_flush(0); | ||
| 327 : | t | ||
| 328 : | t header( 'Content-Encoding: gzip' ); | ||
| 329 : | t return; | ||
| 330 : | t } | ||
| 331 : | t } | ||
| 332 : | t } | ||
| 333 : | t } | ||
| 334 : | t ob_start(); | ||
| 335 : | t } | ||
| 336 : | t | ||
| 337 : | t /** | ||
| 338 : | t * Perform GZIP | ||
| 339 : | t */ | ||
| 340 : | t function doGzip() { | ||
| 341 : | t if ( $this->do_gzip_compress ) { | ||
| 342 : | t /** | ||
| 343 : | t *Borrowed from php.net! | ||
| 344 : | t */ | ||
| 345 : | t $gzip_contents = ob_get_contents(); | ||
| 346 : | t ob_end_clean(); | ||
| 347 : | t | ||
| 348 : | t $gzip_size = strlen($gzip_contents); | ||
| 349 : | t $gzip_crc = crc32($gzip_contents); | ||
| 350 : | t | ||
| 351 : | t $gzip_contents = gzcompress($gzip_contents, 9); | ||
| 352 : | t $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4); | ||
| 353 : | t | ||
| 354 : | t echo "\x1f\x8b\x08\x00\x00\x00\x00\x00"; | ||
| 355 : | t echo $gzip_contents; | ||
| 356 : | t echo pack('V', $gzip_crc); | ||
| 357 : | t echo pack('V', $gzip_size); | ||
| 358 : | t } else { | ||
| 359 : | t ob_end_flush(); | ||
| 360 : | t } | ||
| 361 : | t } | ||
| 362 : | t | ||
| 363 : | t function getLastPart ($separator, $field) { | ||
| 364 : | t $parts = explode($separator, $field); | ||
| 365 : | t return $parts[count($parts)-1]; | ||
| 366 : | t } | ||
| 367 : | t | ||
| 368 : | t function allButLast ($separator, $field) { | ||
| 369 : | t $lastSize = strlen(mamboCore::getLastPart($separator,$field)); | ||
| 370 : | t return substr($field, 0, strlen($field)-$lastSize); | ||
| 371 : | t } | ||
| 372 : | counterpoi | 67 | t |
| 373 : | t function getSection ($id) { | ||
| 374 : | t $limit = $this->_section_limit; | ||
| 375 : | t if (!$this->_section_status) { | ||
| 376 : | t $this->_db->setQuery("SELECT i.id, i.sectionid FROM #__content AS i, #__sections AS s WHERE i.sectionid=s.id ORDER BY i.id DESC LIMIT $limit"); | ||
| 377 : | t $sections = $this->_db->loadObjectList(); | ||
| 378 : | t if ($sections) { | ||
| 379 : | t foreach ($sections as $section) $this->_sections[$section->id] = $section->sectionid; | ||
| 380 : | t $this->_section_status = count($sections); | ||
| 381 : | t } | ||
| 382 : | t } | ||
| 383 : | t if ($this->_section_status) { | ||
| 384 : | t if (isset($this->_sections[$id])) return $this->_sections[$id]; | ||
| 385 : | t if (count($this->_sections) < $limit) return 0; | ||
| 386 : | t $this->_db->setQuery("SELECT i.sectionid FROM #__content AS i, #__sections AS s WHERE i.sectionid=s.id AND i.id=$id"); | ||
| 387 : | t return $this->_db->loadResult(); | ||
| 388 : | t } | ||
| 389 : | t else return 0; | ||
| 390 : | t } | ||
| 391 : | counterpoi | 4 | t |
| 392 : | t function getItemid ($id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1) { | ||
| 393 : | t if (!is_object($this->_db)) $this->_db = mamboDatabase::getInstance(); | ||
| 394 : | t $_Itemid = null; | ||
| 395 : | counterpoi | 13 | t $menuhandler = mosMenuHandler::getInstance(); |
| 396 : | counterpoi | 4 | t if ($typed) { |
| 397 : | t // Search for typed link | ||
| 398 : | counterpoi | 13 | t $_Itemid = $menuhandler->getIDByTypeLink('content_typed', "index.php?option=com_content&task=view&id=$id"); |
| 399 : | counterpoi | 4 | t } |
| 400 : | t | ||
| 401 : | t if ($_Itemid == null AND $link) { | ||
| 402 : | t // Search for item link | ||
| 403 : | counterpoi | 13 | t $_Itemid = $menuhandler->getIDByTypeLink('content_item_link', "index.php?option=com_content&task=view&id=$id"); |
| 404 : | counterpoi | 4 | t } |
| 405 : | t | ||
| 406 : | counterpoi | 67 | t $sectionid = $this->getSection($id); |
| 407 : | counterpoi | 4 | t if ($_Itemid == null) { |
| 408 : | t // Search in sections | ||
| 409 : | counterpoi | 67 | t $_Itemid = $menuhandler->getIDByTypeCid ('content_section', $sectionid); |
| 410 : | counterpoi | 4 | t } |
| 411 : | counterpoi | 67 | t if ($_Itemid == null) { |
| 412 : | t // Search in sections | ||
| 413 : | t $_Itemid = $menuhandler->getIDByTypeCid ('content_blog_section', $sectionid); | ||
| 414 : | t } | ||
| 415 : | t if ($_Itemid == null) { | ||
| 416 : | t // Search in sections | ||
| 417 : | t $_Itemid = $menuhandler->getIDByTypeCid ('content_blog_category', $sectionid); | ||
| 418 : | t } | ||
| 419 : | counterpoi | 4 | t if ($_Itemid == null AND $gbs) { |
| 420 : | t // Search in global blog section | ||
| 421 : | counterpoi | 13 | t $_Itemid = $menuhandler->getIDByTypeCid('content_blog_section', 0); |
| 422 : | counterpoi | 4 | t } |
| 423 : | t /* | ||
| 424 : | t if ($_Itemid == '') { | ||
| 425 : | t // Search in global blog category | ||
| 426 : | t $this->_db->setQuery( "SELECT id " | ||
| 427 : | t ."\nFROM #__menu " | ||
| 428 : | t ."\nWHERE type='content_blog_category' AND published='1' AND componentid=0" ); | ||
| 429 : | t $_Itemid = $this->_db->loadResult(); | ||
| 430 : | t } | ||
| 431 : | t */ | ||
| 432 : | t if ($_Itemid) $this->Itemid = $_Itemid; | ||
| 433 : | t return $this->Itemid; | ||
| 434 : | t } | ||
| 435 : | t } | ||
| 436 : | t | ||
| 437 : | t /** | ||
| 438 : | counterpoi | 20 | t * Pathway handler |
| 439 : | t * @package Mambo | ||
| 440 : | t */ | ||
| 441 : | t class mosPathway { | ||
| 442 : | t /** @var array Names for display in pathway */ | ||
| 443 : | t var $_names = null; | ||
| 444 : | t /** @var array URLs for links from pathway */ | ||
| 445 : | t var $_urls = null; | ||
| 446 : | t | ||
| 447 : | t /** | ||
| 448 : | t * Constructor | ||
| 449 : | t */ | ||
| 450 : | t function mosPathway () { | ||
| 451 : | t $menuhandler = mosMenuHandler::getInstance(); | ||
| 452 : | t $menus =& $menuhandler->getByParentOrder(0,'mainmenu'); | ||
| 453 : | t $home = $menus[0]; | ||
| 454 : | t $this->_names[] = $home->name; | ||
| 455 : | counterpoi | 67 | t $this->_urls[] = sefRelToAbs($home->link."&Itemid=$home->id"); |
| 456 : | counterpoi | 20 | t } |
| 457 : | t | ||
| 458 : | t /** | ||
| 459 : | t * Singleton accessor | ||
| 460 : | t */ | ||
| 461 : | t function &getInstance () { | ||
| 462 : | t static $instance; | ||
| 463 : | t if (!is_object($instance)) $instance = new mosPathway(); | ||
| 464 : | t return $instance; | ||
| 465 : | t } | ||
| 466 : | t | ||
| 467 : | t /** | ||
| 468 : | t * Add an item to the pathway | ||
| 469 : | t */ | ||
| 470 : | t function addItem ($name, $url) { | ||
| 471 : | counterpoi | 67 | t $last = count($this->_names) - 1; |
| 472 : | t if (!$name) return; | ||
| 473 : | t if ($name == $this->_names[$last] AND $url == $this->_urls[$last]) return; | ||
| 474 : | t $this->_names[$last+1] = $name; | ||
| 475 : | t $this->_urls[$last+1] = $url; | ||
| 476 : | counterpoi | 20 | t } |
| 477 : | t | ||
| 478 : | counterpoi | 67 | t function reduceToOne () { |
| 479 : | t for ($i = count($this->_names) - 1; $i > 0; $i--) { | ||
| 480 : | t unset($this->_names[$i]); | ||
| 481 : | t unset($this->_urls[$i]); | ||
| 482 : | t } | ||
| 483 : | t } | ||
| 484 : | t | ||
| 485 : | counterpoi | 20 | t /** |
| 486 : | t * Make a pathway string for display | ||
| 487 : | t */ | ||
| 488 : | t function makePathway () { | ||
| 489 : | counterpoi | 81 | t $mainframe = mosMainFrame::getInstance(); |
| 490 : | counterpoi | 67 | t $result = "<span class='pathway'>"; |
| 491 : | counterpoi | 20 | t $config = mamboCore::getMamboCore(); |
| 492 : | t $rootpath = $config->rootPath(); | ||
| 493 : | t $imgPath = 'templates/'.$mainframe->getTemplate().'/images/arrow.png'; | ||
| 494 : | t if (file_exists( "$rootpath/$imgPath" )) $img = "<img src='$config->mosConfig_live_site/$imgPath' border='0' alt='arrow' />"; | ||
| 495 : | t else { | ||
| 496 : | t $imgPath = '/images/M_images/arrow.png'; | ||
| 497 : | t if (file_exists( "$rootpath/$imgPath" )) $img = "<img src='$config->mosConfig_live_site/images/M_images/arrow.png' alt='arrow' />"; | ||
| 498 : | t else $img = '>'; | ||
| 499 : | t } | ||
| 500 : | t $last = count($this->_names) - 1; | ||
| 501 : | t foreach ($this->_names as $i=>$name) { | ||
| 502 : | counterpoi | 67 | t if ($i === $last) $result .= "$name</span>"; |
| 503 : | counterpoi | 20 | t else { |
| 504 : | t $sefurl = sefRelToAbs($this->_urls[$i]); | ||
| 505 : | t $result .= "<a href='$sefurl' class='pathway'>$name</a>"; | ||
| 506 : | t $result .= " $img "; | ||
| 507 : | t } | ||
| 508 : | t } | ||
| 509 : | t return $result; | ||
| 510 : | t } | ||
| 511 : | t | ||
| 512 : | t } | ||
| 513 : | t | ||
| 514 : | t /** | ||
| 515 : | counterpoi | 67 | t * Module database table class |
| 516 : | t * @package Mambo | ||
| 517 : | t */ | ||
| 518 : | t class mosMenu extends mosDBTable { | ||
| 519 : | t /** @var int Primary key */ | ||
| 520 : | t var $id=null; | ||
| 521 : | t /** @var string */ | ||
| 522 : | t var $menutype=null; | ||
| 523 : | t /** @var string */ | ||
| 524 : | t var $name=null; | ||
| 525 : | t /** @var string */ | ||
| 526 : | t var $link=null; | ||
| 527 : | t /** @var int */ | ||
| 528 : | t var $type=null; | ||
| 529 : | t /** @var int */ | ||
| 530 : | t var $published=null; | ||
| 531 : | t /** @var int */ | ||
| 532 : | t var $componentid=null; | ||
| 533 : | t /** @var int */ | ||
| 534 : | t var $parent=null; | ||
| 535 : | t /** @var int */ | ||
| 536 : | t var $sublevel=null; | ||
| 537 : | t /** @var int */ | ||
| 538 : | t var $ordering=null; | ||
| 539 : | t /** @var boolean */ | ||
| 540 : | t var $checked_out=null; | ||
| 541 : | t /** @var datetime */ | ||
| 542 : | t var $checked_out_time=null; | ||
| 543 : | t /** @var boolean */ | ||
| 544 : | t var $pollid=null; | ||
| 545 : | t | ||
| 546 : | t /** @var string */ | ||
| 547 : | t var $browserNav=null; | ||
| 548 : | t /** @var int */ | ||
| 549 : | t var $access=null; | ||
| 550 : | t /** @var int */ | ||
| 551 : | t var $utaccess=null; | ||
| 552 : | t /** @var string */ | ||
| 553 : | t var $params=null; | ||
| 554 : | t | ||
| 555 : | t /** | ||
| 556 : | t * @param database A database connector object | ||
| 557 : | t */ | ||
| 558 : | t function mosMenu( $dummy ) { | ||
| 559 : | t $db = mamboDatabase::getInstance(); | ||
| 560 : | t $this->mosDBTable( '#__menu', 'id', $db ); | ||
| 561 : | t } | ||
| 562 : | t /** | ||
| 563 : | t * binds an array/hash to this object | ||
| 564 : | t * @param int $oid optional argument, if not specifed then the value of current key is used | ||
| 565 : | t * @return any result from the database operation | ||
| 566 : | t */ | ||
| 567 : | t function load( $oid=null ) { | ||
| 568 : | t $k = $this->_tbl_key; | ||
| 569 : | t if ($oid !== null) $this->$k = $oid; | ||
| 570 : | t if ($this->$k === null) return false; | ||
| 571 : | t $menuhandler = mosMenuHandler::getInstance(); | ||
| 572 : | t $menu = $menuhandler->getMenuById($this->$k); | ||
| 573 : | t if ($menu) { | ||
| 574 : | t foreach (get_object_vars($menu) as $key=>$data) $this->$key = $data; | ||
| 575 : | t return true; | ||
| 576 : | t } | ||
| 577 : | t else return false; | ||
| 578 : | t } | ||
| 579 : | t } | ||
| 580 : | t | ||
| 581 : | t /** | ||
| 582 : | counterpoi | 13 | t * Menu handler |
| 583 : | t * @package Mambo | ||
| 584 : | t */ | ||
| 585 : | t class mosMenuHandler { | ||
| 586 : | t /** @var array Menu objects currently available */ | ||
| 587 : | t var $_menus = null; | ||
| 588 : | t /** @var array Counts of menu items by type and published status */ | ||
| 589 : | t var $_counts = null; | ||
| 590 : | t /** @var array Access to stored menu objects by ID */ | ||
| 591 : | t var $_idlinks = null; | ||
| 592 : | t /** @var array Items that may be useful for setting Itemid */ | ||
| 593 : | t var $_byParentOrder = null; | ||
| 594 : | t | ||
| 595 : | t /** | ||
| 596 : | t * Constructor | ||
| 597 : | t */ | ||
| 598 : | t function mosMenuHandler() { | ||
| 599 : | t global $my; | ||
| 600 : | t $database = mamboDatabase::getInstance(); | ||
| 601 : | counterpoi | 67 | t $sql = "SELECT * FROM #__menu ORDER BY name"; |
| 602 : | t $this->_menus =& $database->doSQLget($sql, 'mosMenu'); | ||
| 603 : | counterpoi | 13 | t if (!$this->_menus) $this->_menus = array(); |
| 604 : | t foreach ($this->_menus as $key=>$menu) { | ||
| 605 : | t $this->_idlinks[$menu->id] = $key; | ||
| 606 : | t if ($menu->published == 1) $this->_byParentOrder[$menu->parent][$menu->ordering][$menu->menutype] = $key; | ||
| 607 : | t if (isset($this->_counts[$menu->menutype][$menu->published])) $this->_counts[$menu->menutype][$menu->published]++; | ||
| 608 : | t else $this->_counts[$menu->menutype][$menu->published] = 1; | ||
| 609 : | t } | ||
| 610 : | t if ($this->_byParentOrder) { | ||
| 611 : | t foreach ($this->_byParentOrder as $parent=>$outer) ksort($this->_byParentOrder[$parent]); | ||
| 612 : | t ksort($this->_byParentOrder); | ||
| 613 : | t } | ||
| 614 : | t } | ||
| 615 : | t /** | ||
| 616 : | t * Singleton accessor | ||
| 617 : | t */ | ||
| 618 : | t function &getInstance () { | ||
| 619 : | t static $instance; | ||
| 620 : | t if (!is_object($instance)) $instance = new mosMenuHandler(); | ||
| 621 : | t return $instance; | ||
| 622 : | t } | ||
| 623 : | t | ||
| 624 : | t function &getMenuByID ($id) { | ||
| 625 : | t if (isset($this->_idlinks[$id])) { | ||
| 626 : | t $key = $this->_idlinks[$id]; | ||
| 627 : | t return $this->_menus[$key]; | ||
| 628 : | t } | ||
| 629 : | t $result = null; | ||
| 630 : | t return $result; | ||
| 631 : | t } | ||
| 632 : | t | ||
| 633 : | t function getMenuCount ($type, $published) { | ||
| 634 : | t if (isset($this->_counts[$type][$published])) return $this->_counts[$type][$published]; | ||
| 635 : | t else return 0; | ||
| 636 : | t } | ||
| 637 : | t | ||
| 638 : | t function &getMenusByType ($types) { | ||
| 639 : | t $checker = explode(',', $types); | ||
| 640 : | t $result = null; | ||
| 641 : | t foreach ($this->_menus as $menu) { | ||
| 642 : | t if (in_array($menu->menutype, $checker)) $result[] = $menu; | ||
| 643 : | t } | ||
| 644 : | t return $result; | ||
| 645 : | t } | ||
| 646 : | t | ||
| 647 : | t function getIDByTypeLink ($type, $link) { | ||
| 648 : | t foreach ($this->_menus as $menu) { | ||
| 649 : | counterpoi | 79 | t if ($menu->published == 1 AND ($type == '*' OR $menu->type == $type) AND $menu->link == $link) return $menu->id; |
| 650 : | counterpoi | 13 | t } |
| 651 : | t return null; | ||
| 652 : | t } | ||
| 653 : | counterpoi | 79 | t |
| 654 : | t function getIDLikeLink ($link) { | ||
| 655 : | t $exact = $this->getIdByTypeLink('*', $link); | ||
| 656 : | t if ($exact !== null) return $exact; | ||
| 657 : | t foreach ($this->_menus as $menu) { | ||
| 658 : | t if ($menu->published == 1 AND strpos($menu->link,$link) === 0) return $menu->id; | ||
| 659 : | t } | ||
| 660 : | t return null; | ||
| 661 : | t } | ||
| 662 : | counterpoi | 13 | t |
| 663 : | t function getIDByTypeCid ($type, $componentid) { | ||
| 664 : | t foreach ($this->_menus as $menu) { | ||
| 665 : | t if ($menu->published == 1 AND $menu->type == $type AND $menu->componentid == $componentid) return $menu->id; | ||
| 666 : | t } | ||
| 667 : | t return null; | ||
| 668 : | t } | ||
| 669 : | t | ||
| 670 : | t function getGlobalBlogSectionCount () { | ||
| 671 : | t $count = 0; | ||
| 672 : | t foreach ($this->_menus as $menu) { | ||
| 673 : | t if ($menu->type == 'content_blog_section' AND $menu->published == 1 AND $menu->componentid == 0) $count++; | ||
| 674 : | t } | ||
| 675 : | t return $count; | ||
| 676 : | t } | ||
| 677 : | t | ||
| 678 : | counterpoi | 79 | t function getContentItemid ($Itemid, $type, $id, $catid=0) { |
| 679 : | t if ($Itemid) return $Itemid; | ||
| 680 : | t foreach ($this->_menus as $menu) { | ||
| 681 : | t if (strpos($menu->link,'index.php?option=com_content') === false AND strpos($menu->link,'index.php?option=content') === false) continue; | ||
| 682 : | t if (strpos($menu->link, $type) === false) continue; | ||
| 683 : | t if ($catid) { | ||
| 684 : | t if (strpos($menu->link, "&id=$catid") === false) continue; | ||
| 685 : | t if (strpos($menu->link, "§ionid=$id") === false) continue; | ||
| 686 : | t } | ||
| 687 : | t elseif (strpos($menu->link, "&id=$id") === false) continue; | ||
| 688 : | t return $menu->id; | ||
| 689 : | t } | ||
| 690 : | t return 0; | ||
| 691 : | t } | ||
| 692 : | t | ||
| 693 : | counterpoi | 13 | t function maxAccessLink ($link) { |
| 694 : | t $access = 0; | ||
| 695 : | t foreach ($this->_menus as $menu) { | ||
| 696 : | t if (strpos($menu->link,$link) === 0 AND $menu->access > $access) $access = $menu->access; | ||
| 697 : | t } | ||
| 698 : | t return $access; | ||
| 699 : | t } | ||
| 700 : | t | ||
| 701 : | t function &getByParentOrder ($Itemid, $menutype, $maxaccess=0, $noparent=false) { | ||
| 702 : | t $result = array(); | ||
| 703 : | t if ($this->_byParentOrder !== null) { | ||
| 704 : | t foreach ($this->_byParentOrder as $parent=>$outer) { | ||
| 705 : | t foreach ($outer as $ordering=>$inner) { | ||
| 706 : | t foreach ($inner as $mtype=>$last) { | ||
| 707 : | t $key = $this->_byParentOrder[$parent][$ordering][$mtype]; | ||
| 708 : | t $menu = $this->_menus[$key]; | ||
| 709 : | t if ($menutype AND $mtype != $menutype) continue; | ||
| 710 : | t if ($Itemid AND $Itemid != $menu->id) continue; | ||
| 711 : | t if ($maxaccess AND $menu->access > $maxaccess) continue; | ||
| 712 : | t if ($noparent AND $parent != 0) continue; | ||
| 713 : | t $result[] = $this->_menus[$key]; | ||
| 714 : | t } | ||
| 715 : | t } | ||
| 716 : | t } | ||
| 717 : | t } | ||
| 718 : | t return $result; | ||
| 719 : | t } | ||
| 720 : | counterpoi | 67 | t |
| 721 : | t function setPathway ($Itemid) { | ||
| 722 : | t if ($Itemid) { | ||
| 723 : | t $menu = $this->getMenuByID($Itemid); | ||
| 724 : | t if ($menu->parent) $this->setPathway($menu->parent); | ||
| 725 : | t $pathway = mosPathway::getInstance(); | ||
| 726 : | t $pathway->addItem($menu->name, $menu->link."&Itemid=$Itemid"); | ||
| 727 : | t } | ||
| 728 : | t } | ||
| 729 : | counterpoi | 13 | t |
| 730 : | counterpoi | 67 | t /** |
| 731 : | t * Checks whether a menu option is within the users access level | ||
| 732 : | t * @param int Item id number | ||
| 733 : | t * @param string The menu option | ||
| 734 : | t * @param int The users group ID number | ||
| 735 : | t * @param database A database connector object | ||
| 736 : | t * @return boolean True if the visitor's group at least equal to the menu access | ||
| 737 : | t */ | ||
| 738 : | t function menuCheck( $Itemid, $menu_option, $task, $gid ) { | ||
| 739 : | t if ($Itemid) { | ||
| 740 : | t $menu = $this->getMenuByID($Itemid); | ||
| 741 : | t $access = $menu->access; | ||
| 742 : | t } else { | ||
| 743 : | t $dblink="index.php?option=$menu_option"; | ||
| 744 : | t if ($task!='') $dblink .= "&task=$task"; | ||
| 745 : | t $access = $this->maxAccessLink($dblink); | ||
| 746 : | t } | ||
| 747 : | t return ($access <= $gid); | ||
| 748 : | t } | ||
| 749 : | t | ||
| 750 : | t function mosGetMenuLink( &$mitem, $level=0, &$params, $Itemid ) { | ||
| 751 : | t $txt = ''; | ||
| 752 : | t | ||
| 753 : | t switch ($mitem->type) { | ||
| 754 : | t case 'separator': | ||
| 755 : | t case 'component_item_link': | ||
| 756 : | t break; | ||
| 757 : | t case 'content_item_link': | ||
| 758 : | t $temp = split("&task=view&id=", $mitem->link); | ||
| 759 : | t if (isset($temp[1])) { | ||
| 760 : | t $configuration = mamboCore::getMamboCore(); | ||
| 761 : | t $mitem->link .= '&Itemid='.$configuration->getItemid($temp[1]); | ||
| 762 : | t } | ||
| 763 : | t break; | ||
| 764 : | t case 'url': | ||
| 765 : | t $link = strtolower($mitem->link); | ||
| 766 : | t if (substr($link,0,10) == 'index.php?' AND strpos($link,'itemid=') === false) $mitem->link .= '&Itemid='. $mitem->id; | ||
| 767 : | t break; | ||
| 768 : | t case 'content_typed': | ||
| 769 : | t default: | ||
| 770 : | t $mitem->link .= '&Itemid='.$mitem->id; | ||
| 771 : | t break; | ||
| 772 : | t } | ||
| 773 : | t // Active Menu highlighting | ||
| 774 : | t if ( $Itemid == $mitem->id ) $id = 'id="active_menu'.$params->get( 'class_sfx' ).'"'; | ||
| 775 : | t else $id = ''; | ||
| 776 : | t $mitem->link = ampReplace( $mitem->link ); | ||
| 777 : | t if (strcasecmp(substr($mitem->link,0,4), 'http')) $mitem->link = sefRelToAbs( $mitem->link ); | ||
| 778 : | t if ($level > 0) $menuclass = 'sublevel'; | ||
| 779 : | t else $menuclass = 'mainlevel'; | ||
| 780 : | t $menuclass .= $params->get( 'class_sfx'); | ||
| 781 : | t | ||
| 782 : | t switch ($mitem->browserNav) { | ||
| 783 : | t // cases are slightly different | ||
| 784 : | t case 1: | ||
| 785 : | t // open in a new window | ||
| 786 : | t $txt = '<a href="'. $mitem->link .'" target="_blank" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; | ||
| 787 : | t break; | ||
| 788 : | t | ||
| 789 : | t case 2: | ||
| 790 : | t // open in a popup window | ||
| 791 : | t $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"; | ||
| 792 : | t break; | ||
| 793 : | t | ||
| 794 : | t case 3: | ||
| 795 : | t // don't link it | ||
| 796 : | t $txt = '<span class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</span>'; | ||
| 797 : | t break; | ||
| 798 : | t | ||
| 799 : | t default: // formerly case 2 | ||
| 800 : | t // open in parent window | ||
| 801 : | t $txt = '<a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; | ||
| 802 : | t break; | ||
| 803 : | t } | ||
| 804 : | t | ||
| 805 : | t if ( $params->get( 'menu_images' ) ) { | ||
| 806 : | t $menu_params =& new mosParameters( $mitem->params ); | ||
| 807 : | t $menu_image = $menu_params->def( 'menu_image', -1 ); | ||
| 808 : | t if ($menu_image AND $menu_image <> '-1') { | ||
| 809 : | t $image = '<img src="'. mamboCore::get('mosConfig_live_site') .'/images/stories/'. $menu_image .'" border="0" alt="'. $mitem->name .'"/>'; | ||
| 810 : | t if ( $params->get('menu_images_align')) $txt = $txt .' '. $image; | ||
| 811 : | t else $txt = $image .' '. $txt; | ||
| 812 : | t } | ||
| 813 : | t } | ||
| 814 : | t return $txt; | ||
| 815 : | t } | ||
| 816 : | t | ||
| 817 : | t /** | ||
| 818 : | t * Vertically Indented Menu | ||
| 819 : | t */ | ||
| 820 : | t function mosShowVIMenu( &$params ) { | ||
| 821 : | t global $my, $cur_template, $Itemid; | ||
| 822 : | t | ||
| 823 : | t if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 0; | ||
| 824 : | t else $maxaccess = $my->gid; | ||
| 825 : | t $rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess); | ||
| 826 : | t foreach ($rows as $i=>$row) $crosslink[$row->id] = $i; | ||
| 827 : | t // indent icons | ||
| 828 : | t $base = mamboCore::get('mosConfig_live_site'); | ||
| 829 : | t switch ( $params->get( 'indent_image' ) ) { | ||
| 830 : | t case '1': | ||
| 831 : | t // Default images | ||
| 832 : | t for ( $i = 1; $i < 7; $i++ ) { | ||
| 833 : | t $img[$i] = "<img src=\"$base/images/M_images/indent$i.png\" alt=\"indent$i\" />"; | ||
| 834 : | t } | ||
| 835 : | t break; | ||
| 836 : | t case '2': | ||
| 837 : | t // Use Params | ||
| 838 : | t for ( $i = 1; $i < 7; $i++ ) { | ||
| 839 : | t $parm = $params->get('indent_image'. $i); | ||
| 840 : | t if ($parm == '-1' ) $img[$i] = NULL; | ||
| 841 : | t else $img[$i] = "<img src=\"$base/images/M_images/$parm\" alt=\"indent$i\" />"; | ||
| 842 : | t } | ||
| 843 : | t break; | ||
| 844 : | t case '3': | ||
| 845 : | t // None | ||
| 846 : | t for ( $i = 1; $i < 7; $i++ ) $img[$i] = NULL; | ||
| 847 : | t break; | ||
| 848 : | t default: | ||
| 849 : | t // Template | ||
| 850 : | t $imgpath = $base.'/templates/'. $cur_template .'/images'; | ||
| 851 : | t for ( $i = 1; $i < 7; $i++ ) { | ||
| 852 : | t $img[$i] = "<img src=\"$base/templates/$cur_template/images/indent$i.png\" alt=\"indent$i\" />"; | ||
| 853 : | t } | ||
| 854 : | t break; | ||
| 855 : | t } | ||
| 856 : | t | ||
| 857 : | t $indents = array( | ||
| 858 : | t // block prefix / item prefix / item suffix / block suffix | ||
| 859 : | t array( '<table width="100%" border="0" cellpadding="0" cellspacing="0">', '<tr align="left"><td>' , '</td></tr>', '</table>' ), | ||
| 860 : | t array( '', '<div style="padding-left: 4px">'. $img[1] , '</div>', '' ), | ||
| 861 : | t array( '', '<div style="padding-left: 8px">'. $img[2] , '</div>', '' ), | ||
| 862 : | t array( '', '<div style="padding-left: 12px">'. $img[3] , '</div>', '' ), | ||
| 863 : | t array( '', '<div style="padding-left: 16px">'. $img[4] , '</div>', '' ), | ||
| 864 : | t array( '', '<div style="padding-left: 20px">'. $img[5] , '</div>', '' ), | ||
| 865 : | t array( '', '<div style="padding-left: 24px">'. $img[6] , '</div>', '' ), | ||
| 866 : | t ); | ||
| 867 : | t | ||
| 868 : | t // establish the hierarchy of the menu | ||
| 869 : | t $children = array(); | ||
| 870 : | t // first pass - collect children | ||
| 871 : | t foreach ($rows as $v ) $children[$v->parent][] = $v; | ||
| 872 : | t // second pass - collect 'open' menus | ||
| 873 : | t $open = array( $Itemid ); | ||
| 874 : | t for ($i = 0; $i < 20 AND isset($crosslink[$open[$i]]) AND isset($rows[$crosslink[$open[$i]]]); $i++) { | ||
| 875 : | t $next = $rows[$crosslink[$open[$i]]]->parent; | ||
| 876 : | t if ($next) $open[$i+1] = $next; | ||
| 877 : | t else break; | ||
| 878 : | t } | ||
| 879 : | t | ||
| 880 : | t $this->mosRecurseVIMenu( 0, 0, $children, $open, $indents, $params ); | ||
| 881 : | t | ||
| 882 : | t } | ||
| 883 : | t | ||
| 884 : | t /** | ||
| 885 : | t * Utility function to recursively work through a vertically indented | ||
| 886 : | t * hierarchial menu | ||
| 887 : | t */ | ||
| 888 : | t function mosRecurseVIMenu( $id, $level, &$children, &$open, &$indents, &$params ) { | ||
| 889 : | t global $Itemid; | ||
| 890 : | t if (@$children[$id]) { | ||
| 891 : | t $n = min( $level, count($indents )-1); | ||
| 892 : | t echo "\n".$indents[$n][0]; | ||
| 893 : | t foreach ($children[$id] as $row) { | ||
| 894 : | t echo "\n".$indents[$n][1]; | ||
| 895 : | t echo $this->mosGetMenuLink( $row, $level, $params, $Itemid ); | ||
| 896 : | t // show menu with menu expanded - submenus visible | ||
| 897 : | t if ($params->get('expand_menu') OR in_array($row->id, $open)) $this->mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params ); | ||
| 898 : | t echo $indents[$n][2]; | ||
| 899 : | t } | ||
| 900 : | t echo "\n".$indents[$n][3]; | ||
| 901 : | t } | ||
| 902 : | t } | ||
| 903 : | t | ||
| 904 : | t /** | ||
| 905 : | t * Draws a horizontal 'flat' style menu (very simple case) | ||
| 906 : | t */ | ||
| 907 : | t function mosShowHFMenu( &$params, $style=0 ) { | ||
| 908 : | t global $my, $cur_template, $Itemid; | ||
| 909 : | t | ||
| 910 : | t if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 0; | ||
| 911 : | t else $maxaccess = $my->gid; | ||
| 912 : | t $rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess, true); | ||
| 913 : | t | ||
| 914 : | t $links = array(); | ||
| 915 : | t foreach ($rows as $row) $links[] = $this->mosGetMenuLink( $row, 0, $params, $Itemid ); | ||
| 916 : | t $menuclass = 'mainlevel'. $params->get( 'class_sfx' ); | ||
| 917 : | t if (count( $links )) { | ||
| 918 : | t if ($style == 1) { | ||
| 919 : | t echo '<ul id="'. $menuclass .'">'; | ||
| 920 : | t foreach ($links as $link) echo '<li>' . $link . '</li>'; | ||
| 921 : | t echo '</ul>'; | ||
| 922 : | t } | ||
| 923 : | t else { | ||
| 924 : | t echo '<table width="100%" border="0" cellpadding="0" cellspacing="1">'; | ||
| 925 : | t echo '<tr>'; | ||
| 926 : | t echo '<td nowrap="nowrap">'; | ||
| 927 : | t echo '<span class="'. $menuclass .'"> '. $params->get( 'end_spacer' ) .' </span>'; | ||
| 928 : | t echo implode( '<span class="'. $menuclass .'"> '. $params->get( 'spacer' ) .' </span>', $links ); | ||
| 929 : | t echo '<span class="'. $menuclass .'"> '. $params->get( 'end_spacer' ) .' </span>'; | ||
| 930 : | t echo '</td></tr>'; | ||
| 931 : | t echo '</table>'; | ||
| 932 : | t } | ||
| 933 : | t } | ||
| 934 : | t } | ||
| 935 : | counterpoi | 13 | t } |
| 936 : | t | ||
| 937 : | t /** | ||
| 938 : | t * Plugin handler | ||
| 939 : | t * @package Mambo | ||
| 940 : | t */ | ||
| 941 : | t class mosMambotHandler { | ||
| 942 : | t /** @var array An array of functions in event groups */ | ||
| 943 : | t var $_events=null; | ||
| 944 : | t /** @var array An array of lists */ | ||
| 945 : | t var $_lists=null; | ||
| 946 : | t /** @var array An array of mambots */ | ||
| 947 : | t var $_bots=null; | ||
| 948 : | t /** @var int Index of the mambot being loaded */ | ||
| 949 : | t var $_loading=null; | ||
| 950 : | t | ||
| 951 : | t /** | ||
| 952 : | t * Constructor | ||
| 953 : | t */ | ||
| 954 : | t function mosMambotHandler() { | ||
| 955 : | t global $my; | ||
| 956 : | t $this->_events = array(); | ||
| 957 : | t $database = mamboDatabase::getInstance(); | ||
| 958 : | t $database->setQuery( "SELECT folder, element, published, params, CONCAT_WS('/',folder,element) AS lookup" | ||
| 959 : | t . "\nFROM #__mambots" | ||
| 960 : | t . "\nWHERE published >= 1 AND access <= $my->gid" | ||
| 961 : | t . "\nORDER BY ordering" | ||
| 962 : | t ); | ||
| 963 : | t $this->_bots = $database->loadObjectList(); | ||
| 964 : | t if (!$this->_bots) $this->_bots = array(); | ||
| 965 : | t | ||
| 966 : | t } | ||
| 967 : | t /** | ||
| 968 : | t * Singleton accessor | ||
| 969 : | t */ | ||
| 970 : | t function &getInstance () { | ||
| 971 : | t static $instance; | ||
| 972 : | t if (!is_object($instance)) $instance = new mosMambotHandler(); | ||
| 973 : | t return $instance; | ||
| 974 : | t } | ||
| 975 : | t /** | ||
| 976 : | t * Loads all the bot files for a particular group | ||
| 977 : | t * @param string The group name, relates to the sub-directory in the mambots directory | ||
| 978 : | t */ | ||
| 979 : | t function loadBotGroup( $group ) { | ||
| 980 : | t global $_MAMBOTS; | ||
| 981 : | t $group = trim( $group ); | ||
| 982 : | t $total = 0; | ||
| 983 : | t $basepath = mamboCore::get('mosConfig_absolute_path'); | ||
| 984 : | t foreach ($this->_bots as $i=>$bot) { | ||
| 985 : | t if ($bot->folder != $group) continue; | ||
| 986 : | t $path = "$basepath/mambots/$bot->folder/$bot->element.php"; | ||
| 987 : | t if (file_exists( $path )) { | ||
| 988 : | t $this->_loading = $i; | ||
| 989 : | t require_once( $path ); | ||
| 990 : | t $total++; | ||
| 991 : | t } | ||
| 992 : | t } | ||
| 993 : | t $this->_loading = null; | ||
| 994 : | t if ($total) return true; | ||
| 995 : | t return false; | ||
| 996 : | t } | ||
| 997 : | t /** | ||
| 998 : | t * Registers a function to a particular event group | ||
| 999 : | t * @param string The event name | ||
| 1000 : | t * @param string The function name | ||
| 1001 : | t */ | ||
| 1002 : | t function registerFunction( $event, $function ) { | ||
| 1003 : | t $this->_events[$event][] = array( $function, $this->_loading ); | ||
| 1004 : | t } | ||
| 1005 : | t /** | ||
| 1006 : | t * Makes a option for a particular list in a group | ||
| 1007 : | t * @param string The group name | ||
| 1008 : | t * @param string The list name | ||
| 1009 : | t * @param string The value for the list option | ||
| 1010 : | t * @param string The text for the list option | ||
| 1011 : | t */ | ||
| 1012 : | t function addListOption( $group, $listName, $value, $text='' ) { | ||
| 1013 : | t $this->_lists[$group][$listName][] = mosHTML::makeOption( $value, $text ); | ||
| 1014 : | t } | ||
| 1015 : | t /** | ||
| 1016 : | t * @param string The group name | ||
| 1017 : | t * @param string The list name | ||
| 1018 : | t * @return array | ||
| 1019 : | t */ | ||
| 1020 : | t function getList( $group, $listName ) { | ||
| 1021 : | t return $this->_lists[$group][$listName]; | ||
| 1022 : | t } | ||
| 1023 : | t /** | ||
| 1024 : | t * Calls all functions according to passed parameters | ||
| 1025 : | t * @param string The event name | ||
| 1026 : | t * @param array An array of arguments | ||
| 1027 : | t * @param boolean True is unpublished bots are to be processed | ||
| 1028 : | t * @return array An array of results from each function call | ||
| 1029 : | t */ | ||
| 1030 : | t function &_runBots ($event, $args, $doUnpublished=false) { | ||
| 1031 : | t $result = array(); | ||
| 1032 : | t if (isset( $this->_events[$event] )) { | ||
| 1033 : | t foreach ($this->_events[$event] as $func) { | ||
| 1034 : | t if (function_exists( $func[0] )) { | ||
| 1035 : | t $args[] = $this->_bots[$func[1]]->params; | ||
| 1036 : | t if ($doUnpublished) { | ||
| 1037 : | t $args[0] = $this->_bots[$func[1]]->published; | ||
| 1038 : | t $result[] = call_user_func_array( $func[0], $args ); | ||
| 1039 : | t } else if ($this->_bots[$func[1]]->published) { | ||
| 1040 : | t $result[] = call_user_func_array( $func[0], $args ); | ||
| 1041 : | t } | ||
| 1042 : | t } | ||
| 1043 : | t } | ||
| 1044 : | t } | ||
| 1045 : | t return $result; | ||
| 1046 : | t } | ||
| 1047 : | t /** | ||
| 1048 : | t * Calls all functions associated with an event group | ||
| 1049 : | t * @param string The event name | ||
| 1050 : | t * @param array An array of arguments | ||
| 1051 : | t * @param boolean True is unpublished bots are to be processed | ||
| 1052 : | t * @return array An array of results from each function call | ||
| 1053 : | t */ | ||
| 1054 : | t function trigger( $event, $args=null, $doUnpublished=false ) { | ||
| 1055 : | t if ($args === null) $args = array(); | ||
| 1056 : | t // prepend the published argument | ||
| 1057 : | t if ($doUnpublished) array_unshift( $args, null ); | ||
| 1058 : | t $result =& $this->_runBots($event, $args, $doUnpublished); | ||
| 1059 : | t return $result; | ||
| 1060 : | t } | ||
| 1061 : | t /** | ||
| 1062 : | t * Same as trigger but only returns the first event and | ||
| 1063 : | t * allows for a variable argument list | ||
| 1064 : | t * @param string The event name | ||
| 1065 : | t * @return array The result of the first function call | ||
| 1066 : | t */ | ||
| 1067 : | t function call( $event ) { | ||
| 1068 : | t $args =& func_get_args(); | ||
| 1069 : | t array_shift( $args ); | ||
| 1070 : | t $result =& $this->_runBots($event, $args); | ||
| 1071 : | t if (isset($result[0])) return $result[0]; | ||
| 1072 : | t return null; | ||
| 1073 : | t } | ||
| 1074 : | t } | ||
| 1075 : | t | ||
| 1076 : | t /** | ||
| 1077 : | counterpoi | 4 | t * Database connector class |
| 1078 : | t * @subpackage Database | ||
| 1079 : | t * @package Mambo | ||
| 1080 : | t */ | ||
| 1081 : | t class database { | ||
| 1082 : | t /** @var string Internal variable to hold the query sql */ | ||
| 1083 : | t var $_sql=''; | ||
| 1084 : | t /** @var int Internal variable to hold the database error number */ | ||
| 1085 : | t var $_errorNum=0; | ||
| 1086 : | t /** @var string Internal variable to hold the database error message */ | ||
| 1087 : | t var $_errorMsg=''; | ||
| 1088 : | t /** @var string Internal variable to hold the prefix used on all database tables */ | ||
| 1089 : | t var $_table_prefix=''; | ||
| 1090 : | t /** @var Internal variable to hold the connector resource */ | ||
| 1091 : | t var $_resource=''; | ||
| 1092 : | t /** @var Internal variable to hold the last query cursor */ | ||
| 1093 : | t var $_cursor=null; | ||
| 1094 : | t /** @var boolean Debug option */ | ||
| 1095 : | t var $_debug=0; | ||
| 1096 : | t /** @var array A log of queries */ | ||
| 1097 : | t var $_log=array(); | ||
| 1098 : | t | ||
| 1099 : | t /** | ||
| 1100 : | t * Database object constructor | ||
| 1101 : | t * @param string Database host | ||
| 1102 : | t * @param string Database user name | ||
| 1103 : | t * @param string Database user password | ||
| 1104 : | t * @param string Database name | ||
| 1105 : | t * @param string Common prefix for all tables | ||
| 1106 : | t */ | ||
| 1107 : | t function database( $host='localhost', $user, $pass, $db, $table_prefix ) { | ||
| 1108 : | t // perform a number of fatality checks, then die gracefully | ||
| 1109 : | t if (!function_exists( 'mysql_connect' )) $this->forceOffline(1); | ||
| 1110 : | t if (!($this->_resource = @mysql_connect( $host, $user, $pass ))) $this->forceOffline(2); | ||
| 1111 : | t if (!mysql_select_db($db)) $this->forceOffline(3); | ||
| 1112 : | t $this->_table_prefix = $table_prefix; | ||
| 1113 : | t } | ||
| 1114 : | t | ||
| 1115 : | t function forceOffline ($error_number) { | ||
| 1116 : | t $mosSystemError = $error_number; | ||
| 1117 : | t $basePath = dirname( __FILE__ ); | ||
| 1118 : | t include $basePath . '/configuration.php'; | ||
| 1119 : | t include $basePath . '/offline.php'; | ||
| 1120 : | t exit(); | ||
| 1121 : | t } | ||
| 1122 : | t /** | ||
| 1123 : | t * @param int | ||
| 1124 : | t */ | ||
| 1125 : | t function debug( $level ) { | ||
| 1126 : | t $this->_debug = intval( $level ); | ||
| 1127 : | t } | ||
| 1128 : | t | ||
| 1129 : | t function debug_trace () { | ||
| 1130 : | t trigger_error( $this->_errorNum, E_USER_NOTICE ); | ||
| 1131 : | t //echo "<pre>" . $this->_sql . "</pre>\n"; | ||
| 1132 : | t if (function_exists('debug_backtrace')) { | ||
| 1133 : | t foreach(debug_backtrace() as $back) { | ||
| 1134 : | t if (@$back['file']) { | ||
| 1135 : | t echo '<br />'.$back['file'].':'.$back['line']; | ||
| 1136 : | t } | ||
| 1137 : | t } | ||
| 1138 : | t } | ||
| 1139 : | t } | ||
| 1140 : | t /** | ||
| 1141 : | t * @return int The error number for the most recent query | ||
| 1142 : | t */ | ||
| 1143 : | t function getErrorNum() { | ||
| 1144 : | t return $this->_errorNum; | ||
| 1145 : | t } | ||
| 1146 : | t /** | ||
| 1147 : | t * @return string The error message for the most recent query | ||
| 1148 : | t */ | ||
| 1149 : | t function getErrorMsg() { | ||
| 1150 : | t return str_replace( array( "\n", "'" ), array( '\n', "\'" ), $this->_errorMsg ); | ||
| 1151 : | t } | ||
| 1152 : | t /** | ||
| 1153 : | t * Get a database escaped string | ||
| 1154 : | t * @return string | ||
| 1155 : | t */ | ||
| 1156 : | t function getEscaped( $text ) { | ||
| 1157 : | t return mysql_escape_string( $text ); | ||
| 1158 : | t } | ||
| 1159 : | t /** | ||
| 1160 : | t * Get a quoted database escaped string | ||
| 1161 : | t * @return string | ||
| 1162 : | t */ | ||
| 1163 : | t function Quote( $text ) { | ||
| 1164 : | t return '\'' . mysql_escape_string( $text ) . '\''; | ||
| 1165 : | t } | ||
| 1166 : | t /** | ||
| 1167 : | t * Sets the SQL query string for later execution. | ||
| 1168 : | t * | ||
| 1169 : | t * This function replaces a string identifier <var>$prefix</var> with the | ||
| 1170 : | t * string held is the <var>_table_prefix</var> class variable. | ||
| 1171 : | t * | ||
| 1172 : | t * @param string The SQL query | ||
| 1173 : | t * @param string The common table prefix | ||
| 1174 : | t */ | ||
| 1175 : | t function setQuery( $sql, $prefix='#__' ) { | ||
| 1176 : | t $this->_sql = $this->replacePrefix($sql, $prefix); | ||
| 1177 : | t } | ||
| 1178 : | t | ||
| 1179 : | t /** | ||
| 1180 : | t * This function replaces a string identifier <var>$prefix</var> with the | ||
| 1181 : | t * string held is the <var>_table_prefix</var> class variable. | ||
| 1182 : | t * | ||
| 1183 : | t * @param string The SQL query | ||
| 1184 : | t * @param string The common table prefix | ||
| 1185 : | t * @author thede, David McKinnis | ||
| 1186 : | t */ | ||
| 1187 : | t function replacePrefix ($sql, $prefix='#__') { | ||
| 1188 : | t $done = ''; | ||
| 1189 : | t while (strlen($sql)) { | ||
| 1190 : | t if ($double = preg_match('/\"([^\\\"]|\\.)*"/', $sql,$matches_double,PREG_OFFSET_CAPTURE) OR | ||
| 1191 : | t $single = preg_match("/\'([^\\\']|\\.)*'/", $sql,$matches_single,PREG_OFFSET_CAPTURE)) { | ||
| 1192 : | t if ($single == 0 OR ($double AND $matches_double[0][1] < $matches_single[0][1])) { | ||
| 1193 : | t $done .= str_replace($prefix, $this->_table_prefix, substr($sql,0,$matches_double[0][1])).$matches_double[0][0]; | ||
| 1194 : | t $sql = substr($sql,$matches_double[0][1]+strlen($matches_double[0][0])); | ||
| 1195 : | t } | ||
| 1196 : | t else { | ||
| 1197 : | t $done .= str_replace($prefix, $this->_table_prefix, substr($sql,0,$matches_single[0][1])).$matches_single[0][0]; | ||
| 1198 : | t $sql = substr($sql,$matches_single[0][1]+strlen($matches_single[0][0])); | ||
| 1199 : | t } | ||
| 1200 : | t } | ||
| 1201 : | t else return $done.str_replace($prefix, $this->_table_prefix,$sql); | ||
| 1202 : | t } | ||
| 1203 : | t return $done; | ||
| 1204 : | t } | ||
| 1205 : | t /** | ||
| 1206 : | t * @return string The current value of the internal SQL vairable | ||
| 1207 : | t */ | ||
| 1208 : | t function getQuery($sql='') { | ||
| 1209 : | t if ($sql == '') $sql = $this->_sql; | ||
| 1210 : | t return "<pre>" . htmlspecialchars( $sql ) . "</pre>"; | ||
| 1211 : | t } | ||
| 1212 : | t /** | ||
| 1213 : | t * Execute the query | ||
| 1214 : | t * @return mixed A database resource if successful, FALSE if not. | ||
| 1215 : | t */ | ||
| 1216 : | t function query($sql = '') { | ||
| 1217 : | t global $mosConfig_debug; | ||
| 1218 : | t if ($sql == '') $sql = $this->_sql; | ||
| 1219 : | t if ($this->_debug) $this->_log[] = $sql; | ||
| 1220 : | t if ($this->_cursor = mysql_query($sql, $this->_resource)) { | ||
| 1221 : | t $this->_errorNum = 0; | ||
| 1222 : | t $this->_errorMsg = ''; | ||
| 1223 : | t return $this->_cursor; | ||
| 1224 : | t } | ||
| 1225 : | t else { | ||
| 1226 : | t $this->_errorNum = mysql_errno( $this->_resource ); | ||
| 1227 : | t $this->_errorMsg = mysql_error( $this->_resource )." SQL=$sql"; | ||
| 1228 : | t if ($this->_debug) $this->debug_trace(); | ||
| 1229 : | t return false; | ||
| 1230 : | t } | ||
| 1231 : | t } | ||
| 1232 : | t | ||
| 1233 : | t function query_batch( $abort_on_error=true, $p_transaction_safe = false) { | ||
| 1234 : | t $this->_errorNum = 0; | ||
| 1235 : | t $this->_errorMsg = ''; | ||
| 1236 : | t if ($p_transaction_safe) { | ||
| 1237 : | t $si = mysql_get_server_info(); | ||
| 1238 : | t preg_match_all( "/(\d+)\.(\d+)\.(\d+)/i", $si, $m ); | ||
| 1239 : | t $prefix = ''; | ||
| 1240 : | t if ($m[1] >= 4) $prefix = 'START TRANSACTION; '; | ||
| 1241 : | t elseif ($m[2] >= 23) { | ||
| 1242 : | t if ($m[3] >= 19) $prefix = 'BEGIN WORK; '; | ||
| 1243 : | t elseif ($m[3] >= 17) $prefix = 'BEGIN; '; | ||
| 1244 : | t } | ||
| 1245 : | t if ($prefix) $this->_sql = $prefix.$this->_sql.'; COMMIT;'; | ||
| 1246 : | t } | ||
| 1247 : | t $query_split = preg_split ("/[;]+/", $this->_sql); | ||
| 1248 : | t $error = 0; | ||
| 1249 : | t foreach ($query_split as $command_line) { | ||
| 1250 : | t $command_line = trim( $command_line ); | ||
| 1251 : | t if ($command_line != '') { | ||
| 1252 : | t if (!$this->query($command_line)) { | ||
| 1253 : | t $error = 1; echo 'xxx '; | ||
| 1254 : | t if ($abort_on_error) { | ||
| 1255 : | t return $this->_cursor; | ||
| 1256 : | t } | ||
| 1257 : | t } | ||
| 1258 : | t } | ||
| 1259 : | t } | ||
| 1260 : | t return $error ? false : true; | ||
| 1261 : | t } | ||
| 1262 : | t | ||
| 1263 : | t /** | ||
| 1264 : | t * Diagnostic function | ||
| 1265 : | t */ | ||
| 1266 : | t function explain() { | ||
| 1267 : | t if (!($cur = $this->query("EXPLAIN ".$this->_sql))) return null; | ||
| 1268 : | t $headline = $header = $body = ''; | ||
| 1269 : | t $buf = '<table cellspacing="1" cellpadding="2" border="0" bgcolor="#000000" align="center">'; | ||
| 1270 : | t $buf .= $this->getQuery("EXPLAIN ".$this->_sql); | ||
| 1271 : | t while ($row = mysql_fetch_assoc($cur)) { | ||
| 1272 : | t $body .= "<tr>"; | ||
| 1273 : | t foreach ($row as $k=>$v) { | ||
| 1274 : | t if ($headline == '') $header .= "<th bgcolor=\"#ffffff\">$k</th>"; | ||
| 1275 : | t $body .= "<td bgcolor=\"#ffffff\">$v</td>"; | ||
| 1276 : | t } | ||
| 1277 : | t $headline = $header; | ||
| 1278 : | t $body .= "</tr>"; | ||
| 1279 : | t } | ||
| 1280 : | t $buf .= "<tr>$headline</tr>$body</table><br /> "; | ||
| 1281 : | t mysql_free_result( $cur ); | ||
| 1282 : | t return "<div style=\"background-color:#FFFFCC\" align=\"left\">$buf</div>"; | ||
| 1283 : | t } | ||
| 1284 : | t /** | ||
| 1285 : | t * @return int The number of rows returned from the most recent query. | ||
| 1286 : | t */ | ||
| 1287 : | t function getNumRows( $cur=null ) { | ||
| 1288 : | t return mysql_num_rows( $cur ? $cur : $this->_cursor ); | ||
| 1289 : | t } | ||
| 1290 : | t | ||
| 1291 : | t /** | ||
| 1292 : | t * Load an array of retrieved database objects or values | ||
| 1293 : | t * @param int Database cursor | ||
| 1294 : | t * @param string The field name of a primary key | ||
| 1295 : | t * @return array If <var>key</var> is empty as sequential list of returned records. | ||
| 1296 : | t * If <var>key</var> is not empty then the returned array is indexed by the value | ||
| 1297 : | t * the database key. Returns <var>null</var> if the query fails. | ||
| 1298 : | t */ | ||
| 1299 : | t function &retrieveResults ($key='', $max=0, $result_type='row') { | ||
| 1300 : | t $results = array(); | ||
| 1301 : | t $sql_function = 'mysql_fetch_'.$result_type; | ||
| 1302 : | t if ($cur = $this->query()) { | ||
| 1303 : | t while ($row = $sql_function($cur)) { | ||
| 1304 : | t if ($key != '') $results[$row->$key] = $row; | ||
| 1305 : | t else $results[] = $row; | ||
| 1306 : | t if ($max AND count($results) >= $max) break; | ||
| 1307 : | t } | ||
| 1308 : | t mysql_free_result($cur); | ||
| 1309 : | t } | ||
| 1310 : | t return $results; | ||
| 1311 : | t } | ||
| 1312 : | t /** | ||
| 1313 : | t * This method loads the first field of the first row returned by the query. | ||
| 1314 : | t * | ||
| 1315 : | t * @return The value returned in the query or null if the query failed. | ||
| 1316 : | t */ | ||
| 1317 : | t function loadResult() { | ||
| 1318 : | t $results =& $this->retrieveResults('', 1, 'row'); | ||
| 1319 : | t if (count($results)) return $results[0][0]; | ||
| 1320 : | t else return null; | ||
| 1321 : | t } | ||
| 1322 : | t | ||
| 1323 : | t /** | ||
| 1324 : | t * Load an array of single field results into an array | ||
| 1325 : | t */ | ||
| 1326 : | t function loadResultArray($numinarray = 0) { | ||
| 1327 : | t $results =& $this->retrieveResults('', 0, 'row'); | ||
| 1328 : | t $values = array(); | ||
| 1329 : | t foreach ($results as $result) $values[] = $result[$numinarray]; | ||
| 1330 : | t if (count($values)) return $values; | ||
| 1331 : | t else return null; | ||
| 1332 : | t } | ||
| 1333 : | t /** | ||
| 1334 : | t * Load a assoc list of database rows | ||
| 1335 : | t * @param string The field name of a primary key | ||
| 1336 : | t * @return array If <var>key</var> is empty as sequential list of returned records. | ||
| 1337 : | t */ | ||
| 1338 : | t function loadAssocList( $key='' ) { | ||
| 1339 : | t $results =& $this->retrieveResults($key, 0, 'assoc'); | ||
| 1340 : | t if (count($results)) return $results[0][0]; | ||
| 1341 : | t else return null; | ||
| 1342 : | t } | ||
| 1343 : | t /** | ||
| 1344 : | t * Copy the named array content into the object as properties | ||
| 1345 : | t * only existing properties of object are filled. when undefined in hash, properties wont be deleted | ||
| 1346 : | t * @param array the input array | ||
| 1347 : | t * @param obj byref the object to fill of any class | ||
| 1348 : | t * @param string | ||
| 1349 : | t * @param boolean | ||
| 1350 : | t */ | ||
| 1351 : | t function mosBindArrayToObject( $array, &$obj, $ignore='', $prefix=NULL, $checkSlashes=true ) { | ||
| 1352 : | t if (!is_array($array) OR !is_object($obj)) return false; | ||
| 1353 : | t if ($prefix == null) $prefix = ''; | ||
| 1354 : | t foreach (get_object_vars($obj) as $k => $v) { | ||
| 1355 : | t if( substr( $k, 0, 1 ) != '_' AND strpos($ignore, $k) === false) { | ||
| 1356 : | t if (isset($array[$prefix.$k])) { | ||
| 1357 : | t $obj->$k = ($checkSlashes AND get_magic_quotes_gpc()) ? mosStripslashes( $array[$k] ) : $array[$k]; | ||
| 1358 : | t } | ||
| 1359 : | t } | ||
| 1360 : | t } | ||
| 1361 : | t return true; | ||
| 1362 : | t } | ||
| 1363 : | t | ||
| 1364 : | t /** | ||
| 1365 : | t * This global function loads the first row of a query into an object | ||
| 1366 : | t * | ||
| 1367 : | t * If an object is passed to this function, the returned row is bound to the existing elements of <var>object</var>. | ||
| 1368 : | t * If <var>object</var> has a value of null, then all of the returned query fields returned in the object. | ||
| 1369 : | t * @param string The SQL query | ||
| 1370 : | t * @param object The address of variable | ||
| 1371 : | t */ | ||
| 1372 : | t function loadObject( &$object ) { | ||
| 1373 : | t if ($object != null) { | ||
| 1374 : | t $results =& $this->retrieveResults('', 1, 'assoc'); | ||
| 1375 : | t if (count($results)) { | ||
| 1376 : | t $this->mosBindArrayToObject($results[0], $object, null, null, false); | ||
| 1377 : | t return true; | ||
| 1378 : | t } | ||
| 1379 : | t } | ||
| 1380 : | t else { | ||
| 1381 : | t $results =& $this->retrieveResults('', 1, 'object'); | ||
| 1382 : | t if (count($results)) { | ||
| 1383 : | t $object = $results[0]; | ||
| 1384 : | t return true; | ||
| 1385 : | t } | ||
| 1386 : | t else $object = null; | ||
| 1387 : | t } | ||
| 1388 : | t return false; | ||
| 1389 : | t } | ||
| 1390 : | t /** | ||
| 1391 : | t * Load a list of database objects | ||
| 1392 : | t * @param string The field name of a primary key | ||
| 1393 : | t * @return array If <var>key</var> is empty as sequential list of returned records. | ||
| 1394 : | t * If <var>key</var> is not empty then the returned array is indexed by the value | ||
| 1395 : | t * the database key. Returns <var>null</var> if the query fails. | ||
| 1396 : | t */ | ||
| 1397 : | t function loadObjectList( $key='' ) { | ||
| 1398 : | t $results =& $this->retrieveResults($key, 0, 'object'); | ||
| 1399 : | t if (count($results)) return $results; | ||
| 1400 : | t else return null; | ||
| 1401 : | t } | ||
| 1402 : | t /** | ||
| 1403 : | t * @return The first row of the query. | ||
| 1404 : | t */ | ||
| 1405 : | t function loadRow() { | ||
| 1406 : | t $results =& $this->retrieveResults('', 1, 'row'); | ||
| 1407 : | t if (count(results)) return $results[0]; | ||
| 1408 : | t else return null; | ||
| 1409 : | t } | ||
| 1410 : | t /** | ||
| 1411 : | t * Load a list of database rows (numeric column indexing) | ||
| 1412 : | t * @param string The field name of a primary key | ||
| 1413 : | t * @return array If <var>key</var> is empty as sequential list of returned records. | ||
| 1414 : | t * If <var>key</var> is not empty then the returned array is indexed by the value | ||
| 1415 : | t * the database key. Returns <var>null</var> if the query fails. | ||
| 1416 : | t */ | ||
| 1417 : | t function loadRowList( $key='' ) { | ||
| 1418 : | t $results =& $this->retrieveResults('', 0, 'row'); | ||
| 1419 : | t if (count(results)) return $results; | ||
| 1420 : | t else return null; | ||
| 1421 : | t } | ||
| 1422 : | t | ||
| 1423 : | t /** | ||
| 1424 : | t * Document::db_insertObject() | ||
| 1425 : | t * | ||
| 1426 : | t * { Description } | ||
| 1427 : | t * | ||
| 1428 : | t * @param [type] $keyName | ||
| 1429 : | t * @param [type] $verbose | ||
| 1430 : | t */ | ||
| 1431 : | t function insertObject( $table, &$object, $keyName = NULL, $verbose=false ) { | ||
| 1432 : | t $fmtsql = "INSERT INTO $table ( %s ) VALUES ( %s ) "; | ||
| 1433 : | t $fields = array(); | ||
| 1434 : | t foreach (get_object_vars( $object ) as $k => $v) { | ||
| 1435 : | t if (is_array($v) OR is_object($v) OR $v === NULL OR $k[0] == '_') continue; | ||
| 1436 : | t $fields[] = "`$k`"; | ||
| 1437 : | t $values[] = "'" . $this->getEscaped( $v ) . "'"; | ||
| 1438 : | t } | ||
| 1439 : | t if (!isset($fields)) die ('class database method insertObject - no fields'); | ||
| 1440 : | t $this->setQuery( sprintf( $fmtsql, implode( ",", $fields ), implode( ",", $values ) ) ); | ||
| 1441 : | t ($verbose) && print "$sql<br />\n"; | ||
| 1442 : | t if (!$this->query()) return false; | ||
| 1443 : | t $id = mysql_insert_id(); | ||
| 1444 : | t ($verbose) && print "id=[$id]<br />\n"; | ||
| 1445 : | t if ($keyName && $id) $object->$keyName = $id; | ||
| 1446 : | t return true; | ||
| 1447 : | t } | ||
| 1448 : | t | ||
| 1449 : | t /** | ||
| 1450 : | t * Document::db_updateObject() | ||
| 1451 : | t * | ||
| 1452 : | t * { Description } | ||
| 1453 : | t * | ||
| 1454 : | t * @param [type] $updateNulls | ||
| 1455 : | t */ | ||
| 1456 : | t function updateObject( $table, &$object, $keyName, $updateNulls=true ) { | ||
| 1457 : | t $fmtsql = "UPDATE $table SET %s WHERE %s"; | ||
| 1458 : | t $tmp = array(); | ||
| 1459 : | t foreach (get_object_vars( $object ) as $k => $v) { | ||
| 1460 : | t if (is_array($v) OR is_object($v) OR $k[0] == '_' OR ($v === null AND !$updateNulls)) continue; | ||
| 1461 : | t if( $k == $keyName ) { // PK not to be updated | ||
| 1462 : | t $where = "$keyName='" . $this->getEscaped( $v ) . "'"; | ||
| 1463 : | t continue; | ||
| 1464 : | t } | ||
| 1465 : | t if ($v) $v = $this->getEscaped($v); | ||
| 1466 : | t $tmp[] = "`$k`='$v'"; | ||
| 1467 : | t } | ||
| 1468 : | t if (!isset($tmp)) return true; | ||
| 1469 : | t if (!isset($where)) die ('database class updateObject method - no key value'); | ||
| 1470 : | t $this->setQuery( sprintf( $fmtsql, implode( ",", $tmp ) , $where ) ); | ||
| 1471 : | t return $this->query(); | ||
| 1472 : | t } | ||
| 1473 : | t | ||
| 1474 : | t /** | ||
| 1475 : | t * @param boolean If TRUE, displays the last SQL statement sent to the database | ||
| 1476 : | t * @return string A standised error message | ||
| 1477 : | t */ | ||
| 1478 : | t function stderr( $showSQL = false ) { | ||
| 1479 : | t return "DB function failed with error number $this->_errorNum" | ||
| 1480 : | t ."<br /><font color=\"red\">$this->_errorMsg</font>" | ||
| 1481 : | t .($showSQL ? "<br />SQL = <pre>$this->_sql</pre>" : ''); | ||
| 1482 : | t } | ||
| 1483 : | t | ||
| 1484 : | t function insertid() | ||
| 1485 : | t { | ||
| 1486 : | t return mysql_insert_id(); | ||
| 1487 : | t } | ||
| 1488 : | t | ||
| 1489 : | t function getVersion() | ||
| 1490 : | t { | ||
| 1491 : | t return mysql_get_server_info(); | ||
| 1492 : | t } | ||
| 1493 : | t | ||
| 1494 : | t /** | ||
| 1495 : | t * Fudge method for ADOdb compatibility | ||
| 1496 : | t */ | ||
| 1497 : | t function GenID( $foo1=null, $foo2=null ) { | ||
| 1498 : | t return '0'; | ||
| 1499 : | t } | ||
| 1500 : | t /** | ||
| 1501 : | t * @return array A list of all the tables in the database | ||
| 1502 : | t */ | ||
| 1503 : | t function getTableList() { | ||
| 1504 : | t $this->setQuery( 'SHOW tables' ); | ||
| 1505 : | t $this->query(); | ||
| 1506 : | t return $this->loadResultArray(); | ||
| 1507 : | t } | ||
| 1508 : | t /** | ||
| 1509 : | t * @param array A list of table names | ||
| 1510 : | t * @return array A list the create SQL for the tables | ||
| 1511 : | t */ | ||
| 1512 : | t function getTableCreate( $tables ) { | ||
| 1513 : | t $result = array(); | ||
| 1514 : | t | ||
| 1515 : | t foreach ($tables as $tblval) { | ||
| 1516 : | t $this->setQuery( 'SHOW CREATE table ' . $tblval ); | ||
| 1517 : | t $this->query(); | ||
| 1518 : | t $result[$tblval] = $this->loadResultArray( 1 ); | ||
| 1519 : | t } | ||
| 1520 : | t | ||
| 1521 : | t return $result; | ||
| 1522 : | t } | ||
| 1523 : | t /** | ||
| 1524 : | t * @param array A list of table names | ||
| 1525 : | t * @return array An array of fields by table | ||
| 1526 : | t */ | ||
| 1527 : | t function getTableFields( $tables ) { | ||
| 1528 : | t $result = array(); | ||
| 1529 : | t | ||
| 1530 : | t foreach ($tables as $tblval) { | ||
| 1531 : | t $this->setQuery( 'SHOW FIELDS FROM ' . $tblval ); | ||
| 1532 : | t $this->query(); | ||
| 1533 : | t $fields = $this->loadObjectList(); | ||
| 1534 : | t foreach ($fields as $field) { | ||
| 1535 : | t $result[$tblval][$field->Field] = preg_replace("/[(0-9)]/",'', $field->Type ); | ||
| 1536 : | t } | ||
| 1537 : | t } | ||
| 1538 : | t | ||
| 1539 : | t return $result; | ||
| 1540 : | t } | ||
| 1541 : | t | ||
| 1542 : | t function displayLogged () { | ||
| 1543 : | t echo count($this->_log).' queries executed'; | ||
| 1544 : | t echo '<pre>'; | ||
| 1545 : | t foreach ($this->_log as $k=>$sql) { | ||
| 1546 : | t echo $k+1 . "\n" . $sql . '<hr />'; | ||
| 1547 : | t } | ||
| 1548 : | t } | ||
| 1549 : | t | ||
| 1550 : | t /* Helper method - maybe should go into database itself */ | ||
| 1551 : | t function doSQL ($sql) { | ||
| 1552 : | t $this->setQuery($sql); | ||
| 1553 : | t if (!$this->query()) { | ||
| 1554 : | t echo "<script> alert('".$this->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 1555 : | t exit(); | ||
| 1556 : | t } | ||
| 1557 : | t } | ||
| 1558 : | t | ||
| 1559 : | t /* Helper method - maybe could go into database itself */ | ||
| 1560 : | t function &doSQLget ($sql, $classname) { | ||
| 1561 : | t $this->setQuery($sql); | ||
| 1562 : | t $rows = $this->loadObjectList(); | ||
| 1563 : | counterpoi | 67 | t $target = get_class_vars($classname); |
| 1564 : | counterpoi | 4 | t if ($rows) { |
| 1565 : | t foreach ($rows as $row) { | ||
| 1566 : | counterpoi | 67 | t $next =& new $classname(0); |
| 1567 : | t foreach ($target as $field=>$value) { | ||
| 1568 : | t if (isset($row->$field)) $next->$field = $row->$field; | ||
| 1569 : | counterpoi | 4 | t } |
| 1570 : | t $result[] = $next; | ||
| 1571 : | t } | ||
| 1572 : | t } | ||
| 1573 : | t else $result = array(); | ||
| 1574 : | t return $result; | ||
| 1575 : | t } | ||
| 1576 : | t | ||
| 1577 : | t | ||
| 1578 : | t } | ||
| 1579 : | t | ||
| 1580 : | t class mamboDatabase extends database { | ||
| 1581 : | t | ||
| 1582 : | t function mamboDatabase () { | ||
| 1583 : | t $host = mamboCore::get('mosConfig_host'); | ||
| 1584 : | t $user = mamboCore::get('mosConfig_user'); | ||
| 1585 : | t $pw = mamboCore::get('mosConfig_password'); | ||
| 1586 : | t $db = mamboCore::get('mosConfig_db'); | ||
| 1587 : | t $prefix = mamboCore::get('mosConfig_dbprefix'); | ||
| 1588 : | t parent::database($host, $user, $pw, $db, $prefix); | ||
| 1589 : | t } | ||
| 1590 : | t | ||
| 1591 : | t function &getInstance () { | ||
| 1592 : | t static $instance; | ||
| 1593 : | counterpoi | 13 | t if (!is_object($instance)) $instance = new mamboDatabase(); |
| 1594 : | counterpoi | 4 | t return $instance; |
| 1595 : | t } | ||
| 1596 : | t } | ||
| 1597 : | t | ||
| 1598 : | t | ||
| 1599 : | t /** | ||
| 1600 : | t * mosDBTable Abstract Class. | ||
| 1601 : | t * @abstract | ||
| 1602 : | t * @package Mambo | ||
| 1603 : | t * @subpackage Database | ||
| 1604 : | t * | ||
| 1605 : | t * Parent classes to all database derived objects. Customisation will generally | ||
| 1606 : | t * not involve tampering with this object. | ||
| 1607 : | t * @package Mambo | ||
| 1608 : | t * @author Andrew Eddie <eddieajau@users.sourceforge.net | ||
| 1609 : | t */ | ||
| 1610 : | t class mosDBTable { | ||
| 1611 : | t /** @var string Name of the table in the db schema relating to child class */ | ||
| 1612 : | t var $_tbl = ''; | ||
| 1613 : | t /** @var string Name of the primary key field in the table */ | ||
| 1614 : | t var $_tbl_key = ''; | ||
| 1615 : | t /** @var string Error message */ | ||
| 1616 : | t var $_error = ''; | ||
| 1617 : | t /** @var mosDatabase Database connector */ | ||
| 1618 : | t var $_db = null; | ||
| 1619 : | t | ||
| 1620 : | t /** | ||
| 1621 : | t * Object constructor to set table and key field | ||
| 1622 : | t * | ||
| 1623 : | t * Can be overloaded/supplemented by the child class | ||
| 1624 : | t * @param string $table name of the table in the db schema relating to child class | ||
| 1625 : | t * @param string $key name of the primary key field in the table | ||
| 1626 : | t */ | ||
| 1627 : | t function mosDBTable( $table, $key, &$db ) { | ||
| 1628 : | t $this->_tbl = $table; | ||
| 1629 : | t $this->_tbl_key = $key; | ||
| 1630 : | t $this->_db =& $db; | ||
| 1631 : | t } | ||
| 1632 : | t | ||
| 1633 : | t /** | ||
| 1634 : | t * @return bool True if DB query failed. Sets the error message | ||
| 1635 : | t */ | ||
| 1636 : | t function queryTestFailure () { | ||
| 1637 : | t if ($this->_db->query()) return false; | ||
| 1638 : | t $this->_error = $this->_db->getErrorMsg(); | ||
| 1639 : | t return true; | ||
| 1640 : | t } | ||
| 1641 : | t /** | ||
| 1642 : | t * Filters public properties | ||
| 1643 : | t * @access protected | ||
| 1644 : | t * @param array List of fields to ignore | ||
| 1645 : | t */ | ||
| 1646 : | t function filter( $ignoreList=null ) { | ||
| 1647 : | counterpoi | 83 | t $callcheck = array('InputFilter', 'process'); |
| 1648 : | t if (!is_callable($callcheck)) require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpinputfilter/class.inputfilter.php'); | ||
| 1649 : | t // specific filters | ||
| 1650 : | counterpoi | 4 | t $iFilter =& new InputFilter(); |
| 1651 : | t if (is_array($ignoreList)) foreach ($this->getPublicProperties() as $k) { | ||
| 1652 : | t if (!in_array($k, $ignoreList)) $this->$k = $iFilter->process($this->$k); | ||
| 1653 : | t } | ||
| 1654 : | t else foreach ($this->getPublicProperties() as $k) $this->$k = $iFilter->process($this->$k); | ||
| 1655 : | t } | ||
| 1656 : | t /** | ||
| 1657 : | t * @return string Returns the error message | ||
| 1658 : | t */ | ||
| 1659 : | t function getError() { | ||
| 1660 : | t return $this->_error; | ||
| 1661 : | t } | ||
| 1662 : | t /** | ||
| 1663 : | t * Gets the value of the class variable | ||
| 1664 : | t * @param string The name of the class variable | ||
| 1665 : | t * @return mixed The value of the class var (or null if no var of that name exists) | ||
| 1666 : | t */ | ||
| 1667 : | t function get( $_property ) { | ||
| 1668 : | t if(isset( $this->$_property )) return $this->$_property; | ||
| 1669 : | t else return null; | ||
| 1670 : | t } | ||
| 1671 : | t /** | ||
| 1672 : | t * Returns an array of public properties | ||
| 1673 : | t * @return array | ||
| 1674 : | t */ | ||
| 1675 : | t function getPublicProperties() { | ||
| 1676 : | t static $cache = null; | ||
| 1677 : | t if (is_null( $cache )) { | ||
| 1678 : | t $cache = array(); | ||
| 1679 : | t foreach (get_class_vars( get_class( $this ) ) as $key=>$val) { | ||
| 1680 : | t if (substr( $key, 0, 1 ) != '_') { | ||
| 1681 : | t $cache[] = $key; | ||
| 1682 : | t } | ||
| 1683 : | t } | ||
| 1684 : | t } | ||
| 1685 : | t return $cache; | ||
| 1686 : | t } | ||
| 1687 : | t /** | ||
| 1688 : | t * Checks if this object lacks the property given by the parameter | ||
| 1689 : | t * @param string The name of the property | ||
| 1690 : | t * @return bool | ||
| 1691 : | t */ | ||
| 1692 : | t function lacks( $property ) { | ||
| 1693 : | t $thisclass = strtolower(get_class($this)); | ||
| 1694 : | t if (!array_key_exists( $property, get_class_vars($thisclass) )) { | ||
| 1695 : | t $this->_error = "WARNING: $thisclass does not support $property."; | ||
| 1696 : | t return true; | ||
| 1697 : | t } | ||
| 1698 : | t return false; | ||
| 1699 : | t } | ||
| 1700 : | t /** | ||
| 1701 : | t * Set the value of the class variable | ||
| 1702 : | t * @param string The name of the class variable | ||
| 1703 : | t * @param mixed The value to assign to the variable | ||
| 1704 : | t */ | ||
| 1705 : | t function set( $_property, $_value ) { | ||
| 1706 : | t $this->$_property = $_value; | ||
| 1707 : | t } | ||
| 1708 : | t /** | ||
| 1709 : | t * binds a named array/hash to this object | ||
| 1710 : | t * | ||
| 1711 : | t * can be overloaded/supplemented by the child class | ||
| 1712 : | t * @param array $hash named array | ||
| 1713 : | t * @return null|string null is operation was satisfactory, otherwise returns an error | ||
| 1714 : | t */ | ||
| 1715 : | t function bind( $array, $ignore="" ) { | ||
| 1716 : | t if (is_array($array)) return database::mosBindArrayToObject($array, $this, $ignore); | ||
| 1717 : | t $this->_error = strtolower(get_class( $this ))."::bind failed."; | ||
| 1718 : | t return false; | ||
| 1719 : | t } | ||
| 1720 : | t | ||
| 1721 : | t /** | ||
| 1722 : | t * binds an array/hash to this object | ||
| 1723 : | t * @param int $oid optional argument, if not specifed then the value of current key is used | ||
| 1724 : | t * @return any result from the database operation | ||
| 1725 : | t */ | ||
| 1726 : | t function load( $oid=null ) { | ||
| 1727 : | t $k = $this->_tbl_key; | ||
| 1728 : | t if ($oid !== null) $this->$k = $oid; | ||
| 1729 : | t if ($this->$k === null) return false; | ||
| 1730 : | t $this->_db->setQuery("SELECT * FROM $this->_tbl WHERE $this->_tbl_key='".$this->$k."'" ); | ||
| 1731 : | t return $this->_db->loadObject($this); | ||
| 1732 : | t } | ||
| 1733 : | t | ||
| 1734 : | t /** | ||
| 1735 : | t * generic check method | ||
| 1736 : | t * | ||
| 1737 : | t * can be overloaded/supplemented by the child class | ||
| 1738 : | t * @return boolean True if the object is ok | ||
| 1739 : | t */ | ||
| 1740 : | t function check() { | ||
| 1741 : | t return true; | ||
| 1742 : | t } | ||
| 1743 : | t | ||
| 1744 : | t /** | ||
| 1745 : | t * Inserts a new row if id is zero or updates an existing row in the database table | ||
| 1746 : | t * | ||
| 1747 : | t * Can be overloaded/supplemented by the child class | ||
| 1748 : | t * @param boolean If false, null object variables are not updated | ||
| 1749 : | t * @return null|string null if successful otherwise returns and error message | ||
| 1750 : | t */ | ||
| 1751 : | t function store( $updateNulls=false ) { | ||
| 1752 : | t $k = $this->_tbl_key; | ||
| 1753 : | t global $migrate; | ||
| 1754 : | t if( $this->$k && !$migrate) $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls ); | ||
| 1755 : | t else $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key ); | ||
| 1756 : | t if( !$ret ) { | ||
| 1757 : | t $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->getErrorMsg(); | ||
| 1758 : | t return false; | ||
| 1759 : | t } else return true; | ||
| 1760 : | t } | ||
| 1761 : | t | ||
| 1762 : | t /** | ||
| 1763 : | t * Determine from the direction parameter which operator and order to use in SQL | ||
| 1764 : | t */ | ||
| 1765 : | t function orderCodes ($direction) { | ||
| 1766 : | t if ($direction < 0) { | ||
| 1767 : | t $relation = '<'; | ||
| 1768 : | t $ordering = ' ORDER BY ordering DESC'; | ||
| 1769 : | t } | ||
| 1770 : | t elseif ($direction > 0) { | ||
| 1771 : | t $relation = '>'; | ||
| 1772 : | t $ordering = ' ORDER BY ordering ASC'; | ||
| 1773 : | t } | ||
| 1774 : | t else { | ||
| 1775 : | t $relation = '='; | ||
| 1776 : | t $ordering = ''; | ||
| 1777 : | t } | ||
| 1778 : | t return array ($relation, $ordering); | ||
| 1779 : | t } | ||
| 1780 : | t /** | ||
| 1781 : | t */ | ||
| 1782 : | t function move( $direction, $where='' ) { | ||
| 1783 : | t $k = $this->_tbl_key; | ||
| 1784 : | t list ($relation, $ordering) = $this->orderCodes($direction); | ||
| 1785 : | t $sql = "SELECT $this->_tbl_key, ordering FROM $this->_tbl WHERE ordering $relation $this->ordering"; | ||
| 1786 : | t $sql .= ($where ? "\n AND $where" : '').$ordering.' LIMIT 1'; | ||
| 1787 : | t $this->_db->setQuery( $sql ); | ||
| 1788 : | t $row = null; | ||
| 1789 : | t if ($this->_db->loadObject($row)) { | ||
| 1790 : | t $sql = "UPDATE $this->_tbl SET ordering='$row->ordering' WHERE $this->_tbl_key='".$this->$k."'"; | ||
| 1791 : | t $this->_db->doSQL($sql); | ||
| 1792 : | t } | ||
| 1793 : | t $sql = "UPDATE $this->_tbl SET ordering='$this->ordering' WHERE $this->_tbl_key='".$row->$k."'"; | ||
| 1794 : | t if ($row) $this->ordering = $row->ordering; | ||
| 1795 : | t $this->_db->doSQL($sql); | ||
| 1796 : | t } | ||
| 1797 : | t /** | ||
| 1798 : | t * Compacts the ordering sequence of the selected records | ||
| 1799 : | t * @param string Additional where query to limit ordering to a particular subset of records | ||
| 1800 : | t */ | ||
| 1801 : | t function updateOrder( $where='' ) { | ||
| 1802 : | t if ($this->lacks('ordering')) return false; | ||
| 1803 : | t $k = $this->_tbl_key; | ||
| 1804 : | t if ($this->_tbl == "#__content_frontpage") $order2 = ", content_id DESC"; | ||
| 1805 : | t else $order2 = ""; | ||
| 1806 : | t | ||
| 1807 : | t $sql = "SELECT $k, ordering FROM $this->_tbl " | ||
| 1808 : | t . ($where ? "\nWHERE $where" : '') | ||
| 1809 : | t . "\nORDER BY ordering$order2"; | ||
| 1810 : | t $this->_db->setQuery($sql); | ||
| 1811 : | t if (!$rows = $this->_db->loadObjectList()) { | ||
| 1812 : | t $this->_error = $this->_db->getErrorMsg(); | ||
| 1813 : | t return false; | ||
| 1814 : | t } | ||
| 1815 : | t $neworder = max(min($this->ordering, count($rows)), 1); | ||
| 1816 : | t $i = 1; | ||
| 1817 : | t foreach ($rows as $row) { | ||
| 1818 : | t $key = $row->$k; | ||
| 1819 : | t if ($i == $neworder) $i++; | ||
| 1820 : | t if ($key == $this->$k) { | ||
| 1821 : | t $i--; | ||
| 1822 : | t $ordering = $neworder; | ||
| 1823 : | t } | ||
| 1824 : | t else $ordering = $i; | ||
| 1825 : | t $sql = "UPDATE $this->_tbl SET ordering=$ordering WHERE $k = $key "; | ||
| 1826 : | t $this->_db->doSQL($sql); | ||
| 1827 : | t $i++; | ||
| 1828 : | t } | ||
| 1829 : | t return true; | ||
| 1830 : | t } | ||
| 1831 : | t | ||
| 1832 : | t /** | ||
| 1833 : | t * Default delete method | ||
| 1834 : | t * | ||
| 1835 : | t * can be overloaded/supplemented by the child class | ||
| 1836 : | t * @return true if successful otherwise returns and error message | ||
| 1837 : | t */ | ||
| 1838 : | t function delete( $oid=null ) { | ||
| 1839 : | t $k = $this->_tbl_key; | ||
| 1840 : | t if ($oid) $this->$k = intval( $oid ); | ||
| 1841 : | t $this->_db->setQuery( "DELETE FROM $this->_tbl WHERE $this->_tbl_key = '".$this->$k."'" ); | ||
| 1842 : | t if ($this->queryTestFailure()) return false; | ||
| 1843 : | t return true; | ||
| 1844 : | t } | ||
| 1845 : | t | ||
| 1846 : | t function checkout( $who, $oid=null ) { | ||
| 1847 : | t if ($this->lacks('checked_out')) return false; | ||
| 1848 : | t $k = $this->_tbl_key; | ||
| 1849 : | t if ($oid !== null) $this->$k = $oid; | ||
| 1850 : | t $time = date( "%Y-%m-%d H:i:s" ); | ||
| 1851 : | t if (intval( $who )) { | ||
| 1852 : | t // new way of storing editor, by id | ||
| 1853 : | t $this->_db->setQuery( "UPDATE $this->_tbl" | ||
| 1854 : | t . "\nSET checked_out='$who', checked_out_time='$time'" | ||
| 1855 : | t . "\nWHERE $this->_tbl_key='".$this->$k."'" | ||
| 1856 : | t ); | ||
| 1857 : | t } else { | ||
| 1858 : | t // old way of storing editor, by name | ||
| 1859 : | t $this->_db->setQuery( "UPDATE $this->_tbl" | ||
| 1860 : | t . "\nSET checked_out='1', checked_out_time='$time', editor='".$who."' " | ||
| 1861 : | t . "\nWHERE $this->_tbl_key='".$this->$k."'" | ||
| 1862 : | t ); | ||
| 1863 : | t } | ||
| 1864 : | t return $this->_db->query(); | ||
| 1865 : | t } | ||
| 1866 : | t | ||
| 1867 : | t function checkin( $oid=null ) { | ||
| 1868 : | t if ($this->lacks('checked_out')) return false; | ||
| 1869 : | t $k = $this->_tbl_key; | ||
| 1870 : | t if ($oid !== null) $this->$k = $oid; | ||
| 1871 : | t $time = date("H:i:s"); | ||
| 1872 : | t $this->_db->setQuery( "UPDATE $this->_tbl" | ||
| 1873 : | t . "\nSET checked_out='0', checked_out_time='0000-00-00 00:00:00'" | ||
| 1874 : | t . "\nWHERE $this->_tbl_key='".$this->$k."'" | ||
| 1875 : | t ); | ||
| 1876 : | t return $this->_db->query(); | ||
| 1877 : | t } | ||
| 1878 : | t | ||
| 1879 : | t function hit( $oid=null ) { | ||
| 1880 : | t $k = $this->_tbl_key; | ||
| 1881 : | t if ($oid !== null) $this->$k = intval( $oid ); | ||
| 1882 : | t $key = $this->$k; | ||
| 1883 : | t $this->_db->setQuery( "UPDATE $this->_tbl SET hits=(hits+1) WHERE $this->_tbl_key='$key'" ); | ||
| 1884 : | t $this->_db->query(); | ||
| 1885 : | t | ||
| 1886 : | t if (mamboCore::get('mosConfig_enable_log_items')) { | ||
| 1887 : | t $now = date( "Y-m-d" ); | ||
| 1888 : | t $this->_db->setQuery( "SELECT hits" | ||
| 1889 : | t . "\nFROM #__core_log_items" | ||
| 1890 : | t . "\nWHERE time_stamp='$now' AND item_table='$this->_tbl' AND item_id='$key'" | ||
| 1891 : | t ); | ||
| 1892 : | t $hits = intval( $this->_db->loadResult() ); | ||
| 1893 : | t if ($hits) $this->_db->setQuery( "UPDATE #__core_log_items SET hits=(hits+1)" | ||
| 1894 : | t . "\nWHERE time_stamp='$now' AND item_table='$this->_tbl' AND item_id='".$this->$k."'" | ||
| 1895 : | t ); | ||
| 1896 : | t else $this->_db->setQuery( "INSERT INTO #__core_log_items VALUES" | ||
| 1897 : | t . "\n('$now','$this->_tbl','".$this->$k."','1')" | ||
| 1898 : | t ); | ||
| 1899 : | t $this->_db->query(); | ||
| 1900 : | t } | ||
| 1901 : | t } | ||
| 1902 : | t | ||
| 1903 : | t /** | ||
| 1904 : | t * Generic save function | ||
| 1905 : | t * @param array Source array for binding to class vars | ||
| 1906 : | t * @param string Filter for the order updating | ||
| 1907 : | t * @returns TRUE if completely successful, FALSE if partially or not succesful. | ||
| 1908 : | t */ | ||
| 1909 : | t function save( $source, $order_filter ) { | ||
| 1910 : | t if (!$this->bind($_POST) OR !$this->check() OR !$this->store()OR !$this->checkin()) return false; | ||
| 1911 : | t $filter_value = $this->$order_filter; | ||
| 1912 : | t $this->updateOrder( $order_filter ? "`$order_filter`='$filter_value'" : "" ); | ||
| 1913 : | t $this->_error = ''; | ||
| 1914 : | t return true; | ||
| 1915 : | t } | ||
| 1916 : | t | ||
| 1917 : | t /** | ||
| 1918 : | t * Generic Publish/Unpublish function | ||
| 1919 : | t * @param array An array of id numbers | ||
| 1920 : | t * @param integer 0 if unpublishing, 1 if publishing | ||
| 1921 : | t * @param integer The id of the user performnig the operation | ||
| 1922 : | t */ | ||
| 1923 : | t function publish_array( $cid=null, $publish=1, $myid=0 ) { | ||
| 1924 : | t if (!is_array( $cid ) OR count( $cid ) < 1) { | ||
| 1925 : | t $this->_error = "No items selected."; | ||
| 1926 : | t return false; | ||
| 1927 : | t } | ||
| 1928 : | t $cids = implode( ',', $cid ); | ||
| 1929 : | t $this->_db->setQuery( "UPDATE $this->_tbl SET published='$publish'" | ||
| 1930 : | t . "\nWHERE $this->_tbl_key IN ($cids) AND (checked_out=0 OR checked_out='$myid')" | ||
| 1931 : | t ); | ||
| 1932 : | t if ($this->queryTestFailure()) return false; | ||
| 1933 : | t if (count( $cid ) == 1) $this->checkin( $cid[0] ); | ||
| 1934 : | t return true; | ||
| 1935 : | t } | ||
| 1936 : | t | ||
| 1937 : | t /** | ||
| 1938 : | t * Export item list to xml | ||
| 1939 : | t * @param boolean Map foreign keys to text values | ||
| 1940 : | t */ | ||
| 1941 : | t function toXML( $mapKeysToText=false ) { | ||
| 1942 : | t $xml = '<record table="' . $this->_tbl . '"'; | ||
| 1943 : | t if ($mapKeysToText) $xml .= ' mapkeystotext="true"'; | ||
| 1944 : | t $xml .= '>'; | ||
| 1945 : | t foreach (get_object_vars($this) as $k => $v) { | ||
| 1946 : | t if ($v === null OR is_array($v) OR is_object($v)) continue; | ||
| 1947 : | t if ($k[0] == '_') continue; // internal field | ||
| 1948 : | t $xml .= '<' . $k . '><![CDATA[' . $v . ']]></' . $k . '>'; | ||
| 1949 : | t } | ||
| 1950 : | t $xml .= '</record>'; | ||
| 1951 : | t return $xml; | ||
| 1952 : | t } | ||
| 1953 : | t } | ||
| 1954 : | t | ||
| 1955 : | t /** | ||
| 1956 : | t * Abstract class for classes where the objects of the class can be relatively easily | ||
| 1957 : | t * stored in a single database table. Can usually be adapted to more complex cases. | ||
| 1958 : | t * Requires child classes to implement: tableName(), notSQL(). | ||
| 1959 : | t * tableName() must return the name of the database table, using #__ in the usual Mambo way | ||
| 1960 : | t * notSQL() must return an array of strings, where each string is the name of a | ||
| 1961 : | t * variable that is NOT in the database table, or is not written explicitly, | ||
| 1962 : | t * e.g. the auto-increment key. If this is the ONLY non-SQL field, then the | ||
| 1963 : | t * child class need not implement it, as that it is already in the abstract class. | ||
| 1964 : | t * Child classes may implement timeStampField, in which case it must return the name | ||
| 1965 : | t * of a field that will have a timestamp placed in it whenever the DB is written. | ||
| 1966 : | t */ | ||
| 1967 : | t | ||
| 1968 : | t class mosDBTableEntry { | ||
| 1969 : | t /** @var int ID for file record in database */ | ||
| 1970 : | t var $id = 0; | ||
| 1971 : | t var $database = ''; | ||
| 1972 : | t | ||
| 1973 : | t function mosDBTableEntry () { | ||
| 1974 : | t die ('Cannot instantiate mosDBTableEntry'); | ||
| 1975 : | t } | ||
| 1976 : | t | ||
| 1977 : | t function getDatabase () { | ||
| 1978 : | t if (!is_object($this->database)) $this->database = mamboDatabase::getInstance(); | ||
| 1979 : | t return $this->database; | ||
| 1980 : | t } | ||
| 1981 : | t | ||
| 1982 : | t /* Stores all POST data where the name matches an object variable name */ | ||
| 1983 : | t function addPostData () { | ||
| 1984 : | t foreach (get_class_vars(get_class($this)) as $field=>$value) { | ||
| 1985 : | t if ($field!='id' AND isset($_POST[$field])) { | ||
| 1986 : | t $this->$field = trim($_POST[$field]); | ||
| 1987 : | t } | ||
| 1988 : | t } | ||
| 1989 : | t $this->forceBools(); | ||
| 1990 : | t } | ||
| 1991 : | t | ||
| 1992 : | t /* Provided in case child class does not implement it. Can force any values */ | ||
| 1993 : | t /* within some limited range. In particular, can force bools to be 0 or 1 */ | ||
| 1994 : | t function forceBools () { | ||
| 1995 : | t return; | ||
| 1996 : | t } | ||
| 1997 : | t | ||
| 1998 : | t /* Updates an existing DB entry with the object's current values */ | ||
| 1999 : | t function updateObjectDB () { | ||
| 2000 : | t $this->prepareValues(); | ||
| 2001 : | t $database = $this->getDatabase(); | ||
| 2002 : | t $database->doSQL($this->updateSQL()); | ||
| 2003 : | t } | ||
| 2004 : | t | ||
| 2005 : | t /* Deletes the current object from the DB */ | ||
| 2006 : | t function delete () { | ||
| 2007 : | t $table = $this->tableName(); | ||
| 2008 : | t $sql = "DELETE FROM $table WHERE id=$this->id"; | ||
| 2009 : | t $database = $this->getDatabase(); | ||
| 2010 : | t $database->doSQL($sql); | ||
| 2011 : | t } | ||
| 2012 : | t | ||
| 2013 : | t /* Provided in case the child class does not provide a method for timeStampField */ | ||
| 2014 : | t function timeStampField () { | ||
| 2015 : | t return ''; | ||
| 2016 : | t } | ||
| 2017 : | t | ||
| 2018 : | t /* Provides SQL for updating the DB with the contents of the current object */ | ||
| 2019 : | t function updateSQL () { | ||
| 2020 : | t $tabname = $this->tableName(); | ||
| 2021 : | t $sql = "UPDATE $tabname SET %s WHERE id=$this->id"; | ||
| 2022 : | t $exclude = $this->notSQL(); | ||
| 2023 : | t foreach (get_class_vars(get_class($this)) as $field=>$value) { | ||
| 2024 : | t if (!in_array($field,$exclude)) $setter[] = $field."='".$this->$field."'"; | ||
| 2025 : | t } | ||
| 2026 : | t $timestamp = $this->timeStampField(); | ||
| 2027 : | t if ($timestamp) $setter[] = $timestamp."='".date('Y-m-d H:i:s')."'"; | ||
| 2028 : | t return sprintf($sql,implode(',', $setter)); | ||
| 2029 : | t } | ||
| 2030 : | t | ||
| 2031 : | t /* Default method for identifying fields not to be written to the DB */ | ||
| 2032 : | t /* The child classes may override this and return more items in the array */ | ||
| 2033 : | t function notSQL () { | ||
| 2034 : | t return array ('id'); | ||
| 2035 : | t } | ||
| 2036 : | t | ||
| 2037 : | t /* Provides SQL to insert the current object into the DB */ | ||
| 2038 : | t function insertSQL () { | ||
| 2039 : | t $tabname = $this->tableName(); | ||
| 2040 : | t $sql = "INSERT INTO $tabname (%s) VALUES (%s)"; | ||
| 2041 : | t $exclude = $this->notSQL(); | ||
| 2042 : | t foreach (get_class_vars(get_class($this)) as $field=>$value) { | ||
| 2043 : | t if (!in_array($field,$exclude)) { | ||
| 2044 : | t $infields[] = $field; | ||
| 2045 : | t $values[] = "'".$this->$field."'"; | ||
| 2046 : | t } | ||
| 2047 : | t } | ||
| 2048 : | t $timestamp = $this->timeStampField(); | ||
| 2049 : | t if ($timestamp) { | ||
| 2050 : | t $infields[] = $timestamp; | ||
| 2051 : | t $values[] = "'".date('Y-m-d H:i:s')."'"; | ||
| 2052 : | t } | ||
| 2053 : | t return sprintf($sql, implode(',', $infields), implode(',', $values)); | ||
| 2054 : | t } | ||
| 2055 : | t | ||
| 2056 : | t /* Copies any matching fields from some arbitrary object into the current object */ | ||
| 2057 : | t function setValues (&$anObject) { | ||
| 2058 : | t foreach (get_class_vars(get_class($this)) as $field=>$value) { | ||
| 2059 : | t if ($field != 'id' AND isset($anObject->$field)) $this->$field = $anObject->$field; | ||
| 2060 : | t } | ||
| 2061 : | t } | ||
| 2062 : | t | ||
| 2063 : | t /* Ensures values can safely be written to DB; assumes magic quotes forced off */ | ||
| 2064 : | t function prepareValues () { | ||
| 2065 : | t $database = $this->getDatabase(); | ||
| 2066 : | t foreach (get_class_vars(get_class($this)) as $field=>$value) { | ||
| 2067 : | t if (!is_numeric($this->$field)) $this->$field = $database->getEscaped($this->$field); | ||
| 2068 : | t } | ||
| 2069 : | t } | ||
| 2070 : | t | ||
| 2071 : | t /* Takes some arbitrary SELECT type SQL and places the first or only result into the current object */ | ||
| 2072 : | t function readDataBase($sql) { | ||
| 2073 : | t $database = $this->getDatabase(); | ||
| 2074 : | t $database->setQuery( $sql ); | ||
| 2075 : | t if (!$database->loadObject($this)) $this->id = 0; | ||
| 2076 : | t } | ||
| 2077 : | t | ||
| 2078 : | t } | ||
| 2079 : | t | ||
| 2080 : | t | ||
| 2081 : | t /** | ||
| 2082 : | t * Users Table Class | ||
| 2083 : | t * | ||
| 2084 : | t * Provides access to the mos_templates table | ||
| 2085 : | t * @package Mambo | ||
| 2086 : | t */ | ||
| 2087 : | t class mosUser extends mosDBTable { | ||
| 2088 : | t /** @var int Unique id*/ | ||
| 2089 : | t var $id=null; | ||
| 2090 : | t /** @var string The users real name (or nickname)*/ | ||
| 2091 : | t var $name=null; | ||
| 2092 : | t /** @var string The login name*/ | ||
| 2093 : | t var $username=null; | ||
| 2094 : | t /** @var string email*/ | ||
| 2095 : | t var $email=null; | ||
| 2096 : | t /** @var string MD5 encrypted password*/ | ||
| 2097 : | t var $password=null; | ||
| 2098 : | t /** @var string */ | ||
| 2099 : | t var $usertype=null; | ||
| 2100 : | t /** @var int */ | ||
| 2101 : | t var $block=null; | ||
| 2102 : | t /** @var int */ | ||
| 2103 : | t var $sendEmail=null; | ||
| 2104 : | t /** @var int The group id number */ | ||
| 2105 : | t var $gid=null; | ||
| 2106 : | t /** @var datetime */ | ||
| 2107 : | t var $registerDate=null; | ||
| 2108 : | t /** @var datetime */ | ||
| 2109 : | t var $lastvisitDate=null; | ||
| 2110 : | t /** @var string activation hash*/ | ||
| 2111 : | t var $activation=null; | ||
| 2112 : | t /** @var string */ | ||
| 2113 : | t var $params=null; | ||
| 2114 : | t | ||
| 2115 : | t /** | ||
| 2116 : | t * @param database A database connector object | ||
| 2117 : | t */ | ||
| 2118 : | counterpoi | 67 | t function mosUser( $dummy ) { |
| 2119 : | t $database = mamboDatabase::getInstance(); | ||
| 2120 : | counterpoi | 4 | t $this->mosDBTable( '#__users', 'id', $database ); |
| 2121 : | t } | ||
| 2122 : | t | ||
| 2123 : | t /** | ||
| 2124 : | t * Fill a user object with information from the current session | ||
| 2125 : | t */ | ||
| 2126 : | t function getSessionData() { | ||
| 2127 : | t $session = mosSession::getCurrent(); | ||
| 2128 : | t $this->id = intval( $session->userid ); | ||
| 2129 : | t $this->username = $session->username; | ||
| 2130 : | t $this->usertype = $session->usertype; | ||
| 2131 : | t $this->gid = intval( $session->gid ); | ||
| 2132 : | t } | ||
| 2133 : | t /** | ||
| 2134 : | t * Validation and filtering | ||
| 2135 : | t * @return boolean True is satisfactory | ||
| 2136 : | t */ | ||
| 2137 : | t function check() { | ||
| 2138 : | t $this->_error = ''; | ||
| 2139 : | t if ($this->name == '') $this->_error = _REGWARN_NAME; | ||
| 2140 : | t elseif ($this->username == '') $this->_error = _REGWARN_UNAME; | ||
| 2141 : | t elseif (strlen($this->username) < 3 OR preg_match("/[\\<\\>\\\"\\'\\%\\;\\(\\)\\&\\+\\-]/", $this->username)) $this->_error = sprintf( _VALID_AZ09, _PROMPT_UNAME, 2 ); | ||
| 2142 : | t elseif (($this->email == '') OR preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $this->email ) == 0) $this->_error = _REGWARN_MAIL; | ||
| 2143 : | t else { | ||
| 2144 : | t // check for existing username | ||
| 2145 : | t $this->_db->setQuery( "SELECT COUNT(id) FROM #__users " | ||
| 2146 : | t . "\nWHERE LOWER(username)=LOWER('$this->username') AND id!='$this->id'" | ||
| 2147 : | t ); | ||
| 2148 : | t if ($this->_db->loadResult()) $this->_error = _REGWARN_INUSE; | ||
| 2149 : | t elseif (mamboCore::get('mosConfig_uniquemail')) { | ||
| 2150 : | t // check for existing email | ||
| 2151 : | t $this->_db->setQuery( "SELECT COUNT(id) FROM #__users " | ||
| 2152 : | t . "\nWHERE email='$this->email' AND id!='$this->id'" | ||
| 2153 : | t ); | ||
| 2154 : | t if ($this->_db->loadResult()) $this->_error = _REGWARN_EMAIL_INUSE; | ||
| 2155 : | t } | ||
| 2156 : | t } | ||
| 2157 : | t if ($this->_error) return false; | ||
| 2158 : | t return true; | ||
| 2159 : | t } | ||
| 2160 : | t | ||
| 2161 : | t function store( $updateNulls=false ) { | ||
| 2162 : | t global $migrate; | ||
| 2163 : | t if( $this->id AND !$migrate) $ret = $this->_db->updateObject( $this->_tbl, $this, $this->id, $updateNulls ); | ||
| 2164 : | t else $ret = $this->_db->insertObject( $this->_tbl, $this, $this->id ); | ||
| 2165 : | t if ($ret) return true; | ||
| 2166 : | t $this->_error = "mosUser::store failed <br />" . $this->_db->getErrorMsg(); | ||
| 2167 : | t return false; | ||
| 2168 : | t } | ||
| 2169 : | t | ||
| 2170 : | t function delete($oid=null) { | ||
| 2171 : | t | ||
| 2172 : | t if ($oid) $this->id = intval( $oid ); | ||
| 2173 : | counterpoi | 5 | t $aro_id = $acl->get_object_id( 'users', $this->$k, 'ARO' ); |
| 2174 : | t $acl->del_object( $aro_id, 'ARO', true ); | ||
| 2175 : | t // $authoriser = mosAuthorisationAdmin::getInstance(); | ||
| 2176 : | t // $authoriser->dropAccess('mosUser', $this->id); | ||
| 2177 : | counterpoi | 4 | t $this->_error = ''; |
| 2178 : | t $this->_db->setQuery( "DELETE FROM $this->_tbl WHERE id = '".$this->id."'" ); | ||
| 2179 : | t if ($this->_db->query()) { | ||
| 2180 : | t // cleanup related data | ||
| 2181 : | t | ||
| 2182 : | t // :: private messaging | ||
| 2183 : | t $this->_db->setQuery( "DELETE FROM #__messages_cfg WHERE user_id='".$this->id."'" ); | ||
| 2184 : | t if (!$this->_db->query()) $this->_error = $this->_db->getErrorMsg(); | ||
| 2185 : | t else { | ||
| 2186 : | t $this->_db->setQuery( "DELETE FROM #__messages WHERE user_id_to='".$this->$k."'" ); | ||
| 2187 : | t if (!$this->_db->query()) $this->_error = $this->_db->getErrorMsg(); | ||
| 2188 : | t } | ||
| 2189 : | t } else $this->_error = $this->_db->getErrorMsg(); | ||
| 2190 : | t if ($this->_error) return false; | ||
| 2191 : | t return true; | ||
| 2192 : | t } | ||
| 2193 : | t } | ||
| 2194 : | t | ||
| 2195 : | t /** | ||
| 2196 : | t * Mambo Mainframe class | ||
| 2197 : | t * | ||
| 2198 : | t * Provide many supporting API functions | ||
| 2199 : | t * @package Mambo | ||
| 2200 : | t */ | ||
| 2201 : | t class mosMainFrame { | ||
| 2202 : | t /** @var database Internal database class pointer */ | ||
| 2203 : | t var $_db=null; | ||
| 2204 : | t /** @var object A default option (e.g. component) */ | ||
| 2205 : | t var $_option=null; | ||
| 2206 : | t /** @var string The current template */ | ||
| 2207 : | t var $_template=null; | ||
| 2208 : | t /** @var array An array to hold global user state within a session */ | ||
| 2209 : | t var $_userstate=null; | ||
| 2210 : | t /** @var array An array of page meta information */ | ||
| 2211 : | t var $_head=null; | ||
| 2212 : | t /** @var string Custom html string to append to the pathway */ | ||
| 2213 : | t var $_custom_pathway=null; | ||
| 2214 : | t | ||
| 2215 : | t /** | ||
| 2216 : | t * Class constructor | ||
| 2217 : | t * @param database A database connection object | ||
| 2218 : | t * @param string The url option | ||
| 2219 : | t * @param string The path of the mos directory | ||
| 2220 : | t */ | ||
| 2221 : | t function mosMainFrame( &$db, $option, $basePath, $isAdmin=false ) { | ||
| 2222 : | t $this->_db =& $db; | ||
| 2223 : | t // load the configuration values | ||
| 2224 : | t //return( $this->loadConfig() ); | ||
| 2225 : | t $this->_setTemplate($isAdmin); | ||
| 2226 : | t if (substr($option,0,4) != 'com_') $this->_option = "com_$option"; | ||
| 2227 : | t else $this->_option = $option; | ||
| 2228 : | t if (isset( $_SESSION['session_userstate'] )) $this->_userstate =& $_SESSION['session_userstate']; | ||
| 2229 : | t else $this->_userstate = null; | ||
| 2230 : | t $this->_head['title'] = $GLOBALS['mosConfig_sitename']; | ||
| 2231 : | t $this->_head['meta'] = array(); | ||
| 2232 : | t $this->_head['custom'] = array(); | ||
| 2233 : | counterpoi | 81 | t mosMainFrame::getInstance($this); |
| 2234 : | counterpoi | 4 | t } |
| 2235 : | counterpoi | 81 | t |
| 2236 : | counterpoi | 4 | t /** |
| 2237 : | counterpoi | 81 | t * Singleton get instance |
| 2238 : | t * @param object the mainframe instance (if called internally) | ||
| 2239 : | t * Note that because of the need for creation parameters, this cannot | ||
| 2240 : | t * be called successfully unless the mainframe object is already created | ||
| 2241 : | t */ | ||
| 2242 : | t function &getInstance () { | ||
| 2243 : | t static $mainframe; | ||
| 2244 : | t if (func_num_args()) { | ||
| 2245 : | t $args =& func_get_args(); | ||
| 2246 : | t $mainframe = $args[0]; | ||
| 2247 : | t } | ||
| 2248 : | t if (isset($mainframe)) $result =& $mainframe; | ||
| 2249 : | t else $result = null; | ||
| 2250 : | t return $result; | ||
| 2251 : | t } | ||
| 2252 : | t /** | ||
| 2253 : | counterpoi | 4 | t * @param string |
| 2254 : | t */ | ||
| 2255 : | t function setPageTitle( $title=null ) { | ||
| 2256 : | t if (mamboCore::get('mosConfig_pagetitles')) { | ||
| 2257 : | t $title = trim(htmlspecialchars($title)); | ||
| 2258 : | t $base = mamboCore::get('mosConfig_sitename'); | ||
| 2259 : | t $this->_head['title'] = $title ? $title.' - '.$base : $base; | ||
| 2260 : | t } | ||
| 2261 : | t } | ||
| 2262 : | t /** | ||
| 2263 : | t * @return string | ||
| 2264 : | t */ | ||
| 2265 : | t function getPageTitle() { | ||
| 2266 : | t return $this->_head['title']; | ||
| 2267 : | t } | ||
| 2268 : | t | ||
| 2269 : | t /** | ||
| 2270 : | t * @param string The value of the name attibute | ||
| 2271 : | t * @param string The value of the content attibute | ||
| 2272 : | t * @param string Text to display before the tag | ||
| 2273 : | t * @param string Text to display after the tag | ||
| 2274 : | t */ | ||
| 2275 : | t function addMetaTag( $name, $content, $prepend='', $append='' ) { | ||
| 2276 : | t list($name, $content) = $this->_tidyMetaData($name, $content); | ||
| 2277 : | t $prepend = trim($prepend); | ||
| 2278 : | t $append = trim($append); | ||
| 2279 : | t $this->_head['meta'][$name] = array($content, $prepend, $append); | ||
| 2280 : | t } | ||
| 2281 : | t /** | ||
| 2282 : | t * @param string The value of the name attibute | ||
| 2283 : | t */ | ||
| 2284 : | t function _getMetaTag ($name) { | ||
| 2285 : | t return isset($this->_head['meta'][$name]) ? $this->_head['meta'][$name] : array('', '', ''); | ||
| 2286 : | t } | ||
| 2287 : | t /** | ||
| 2288 : | t * @param string The value of the name attibute | ||
| 2289 : | t * @param string The value of the content attibute to append to the existing | ||
| 2290 : | t */ | ||
| 2291 : | t function _tidyMetaData($name, $content) { | ||
| 2292 : | t $result[] = trim(htmlspecialchars($name)); | ||
| 2293 : | t $result[] = trim(htmlspecialchars($content)); | ||
| 2294 : | t return $result; | ||
| 2295 : | t } | ||
| 2296 : | t /** | ||
| 2297 : | t * @param string The value of the name attibute | ||
| 2298 : | t * @param string The value of the content attibute to append to the existing | ||
| 2299 : | t * Tags ordered in with Site Keywords and Description first | ||
| 2300 : | t */ | ||
| 2301 : | t function appendMetaTag( $name, $content ) { | ||
| 2302 : | t list($name, $content) = $this->_tidyMetaData($name, $content); | ||
| 2303 : | t $tag = $this->_getMetaTag($name); | ||
| 2304 : | t if ($tag[0] AND $content) $content .= ', '; | ||
| 2305 : | t $tag[0] = $content.$tag[0]; | ||
| 2306 : | t $this->_head['meta'][$name] = $tag; | ||
| 2307 : | t } | ||
| 2308 : | t | ||
| 2309 : | t /** | ||
| 2310 : | t * @param string The value of the name attibute | ||
| 2311 : | t * @param string The value of the content attibute to append to the existing | ||
| 2312 : | t */ | ||
| 2313 : | t function prependMetaTag( $name, $content ) { | ||
| 2314 : | t list($name, $content) = $this->_tidyMetaData($name, $content); | ||
| 2315 : | t $tag = $this->_getMetaTag($name); | ||
| 2316 : | t $tag[0] = $content.$tag[0]; | ||
| 2317 : | t $this->_head['meta'][$name] = $tag; | ||
| 2318 : | t } | ||
| 2319 : | t /** | ||
| 2320 : | t * Adds a custom html string to the head block | ||
| 2321 : | t * @param string The html to add to the head | ||
| 2322 : | t */ | ||
| 2323 : | t function addCustomHeadTag( $html ) { | ||
| 2324 : | t $this->_head['custom'][] = trim( $html ); | ||
| 2325 : | t } | ||
| 2326 : | t /** | ||
| 2327 : | t * @return string | ||
| 2328 : | t */ | ||
| 2329 : | t function getHead() { | ||
| 2330 : | t $head[] = '<title>'.$this->_head['title'].'</title>'; | ||
| 2331 : | t foreach ($this->_head['meta'] as $name=>$meta) { | ||
| 2332 : | t if ($meta[1]) $head[] = $meta[1]; | ||
| 2333 : | t $head[] = '<meta name="' . $name . '" content="' . $meta[0] . '" />'; | ||
| 2334 : | t if ($meta[2]) $head[] = $meta[2]; | ||
| 2335 : | t } | ||
| 2336 : | t foreach ($this->_head['custom'] as $html) $head[] = $html; | ||
| 2337 : | t return implode( "\n", $head )."\n"; | ||
| 2338 : | t } | ||
| 2339 : | t /** | ||
| 2340 : | t * @return string | ||
| 2341 : | t */ | ||
| 2342 : | t function getCustomPathWay() { | ||
| 2343 : | t return $this->_custom_pathway; | ||
| 2344 : | t } | ||
| 2345 : | t | ||
| 2346 : | t function appendPathWay($html) { | ||
| 2347 : | t $this->_custom_pathway[] = $html; | ||
| 2348 : | t } | ||
| 2349 : | t | ||
| 2350 : | t /** | ||
| 2351 : | t * Gets the value of a user state variable | ||
| 2352 : | t * @param string The name of the variable | ||
| 2353 : | t */ | ||
| 2354 : | t function getUserState( $var_name ) { | ||
| 2355 : | t return is_array($this->_userstate) ? mosGetParam($this->_userstate, $var_name, null) : null; | ||
| 2356 : | t } | ||
| 2357 : | t /** | ||
| 2358 : | t * Sets the value of a user state variable | ||
| 2359 : | t * @param string The name of the variable | ||
| 2360 : | t * @param string The value of the variable | ||
| 2361 : | t */ | ||
| 2362 : | t function setUserState( $var_name, $var_value ) { | ||
| 2363 : | t if (is_array( $this->_userstate )) $this->_userstate[$var_name] = $var_value; | ||
| 2364 : | t } | ||
| 2365 : | t /** | ||
| 2366 : | t * Gets the value of a user state variable | ||
| 2367 : | t * @param string The name of the user state variable | ||
| 2368 : | t * @param string The name of the variable passed in a request | ||
| 2369 : | t * @param string The default value for the variable if not found | ||
| 2370 : | t */ | ||
| 2371 : | t function getUserStateFromRequest( $var_name, $req_name, $var_default=null ) { | ||
| 2372 : | t if (isset($_REQUEST[$req_name])) $this->setUserState($var_name, $_REQUEST[$req_name]); | ||
| 2373 : | t elseif (isset($var_default) AND !isset($this->userstate[$var_name])) $this->setUserState($var_name, $var_default); | ||
| 2374 : | t return $this->getUserState($var_name); | ||
| 2375 : | t } | ||
| 2376 : | t /** | ||
| 2377 : | t * Initialises the user session | ||
| 2378 : | t * | ||
| 2379 : | t * Old sessions are flushed based on the configuration value for the cookie | ||
| 2380 : | t * lifetime. If an existing session, then the last access time is updated. | ||
| 2381 : | t * If a new session, a session id is generated and a record is created in | ||
| 2382 : | t * the mos_sessions table. | ||
| 2383 : | t */ | ||
| 2384 : | t function &initSession() { | ||
| 2385 : | t $session =& mosSession::getCurrent(); | ||
| 2386 : | t return $session; | ||
| 2387 : | t } | ||
| 2388 : | t | ||
| 2389 : | t /** | ||
| 2390 : | t * @param string The name of the variable (from configuration.php) | ||
| 2391 : | t * @return mixed The value of the configuration variable or null if not found | ||
| 2392 : | t */ | ||
| 2393 : | t function getCfg( $varname ) { | ||
| 2394 : | t return mamboCore::get('mosConfig_'.$varname); | ||
| 2395 : | t } | ||
| 2396 : | t | ||
| 2397 : | t function _setTemplate( $isAdmin=false ) { | ||
| 2398 : | t global $Itemid; | ||
| 2399 : | t $cur_template = ''; | ||
| 2400 : | t $sql = "SELECT template, client_id, menuid FROM #__templates_menu WHERE (client_id=0 or client_id=1)"; | ||
| 2401 : | t if (isset($Itemid) AND $Itemid) $sql .= " AND (menuid=0 OR menuid=$Itemid)"; | ||
| 2402 : | t else $sql .= " AND menuid=0"; | ||
| 2403 : | t $sql .= " ORDER BY client_id, menuid"; | ||
| 2404 : | t $this->_db->setQuery($sql); | ||
| 2405 : | t $templates = $this->_db->loadObjectList(); | ||
| 2406 : | t foreach ($templates as $template) { | ||
| 2407 : | t if ($template->client_id == 1) { | ||
| 2408 : | t if ($isAdmin) $cur_template = $template->template; | ||
| 2409 : | t } | ||
| 2410 : | t else $cur_template = $template->template; | ||
| 2411 : | t } | ||
| 2412 : | t if ($isAdmin) { | ||
| 2413 : | t $path = mamboCore::get('mosConfig_absolute_path')."/administrator/templates/$cur_template/index.php"; | ||
| 2414 : | t if (!file_exists( $path )) $cur_template = 'mambo_admin'; | ||
| 2415 : | t } | ||
| 2416 : | t else { | ||
| 2417 : | t // TemplateChooser Start | ||
| 2418 : | t $mos_user_template = mosGetParam( $_COOKIE, 'mos_user_template', '' ); | ||
| 2419 : | t $mos_change_template = mosGetParam( $_REQUEST, 'mos_change_template', $mos_user_template ); | ||
| 2420 : | t if ($mos_change_template) { | ||
| 2421 : | t // check that template exists in case it was deleted | ||
| 2422 : | t $path = mamboCore::get('mosConfig_absolute_path')."/templates/$mos_change_template/index.php"; | ||
| 2423 : | t if (file_exists( $path)) { | ||
| 2424 : | t $lifetime = 60*10; | ||
| 2425 : | t $cur_template = $mos_change_template; | ||
| 2426 : | t setcookie( "mos_user_template", "$mos_change_template", time()+$lifetime); | ||
| 2427 : | t } else setcookie( "mos_user_template", "", time()-3600 ); | ||
| 2428 : | t } | ||
| 2429 : | t // TemplateChooser End | ||
| 2430 : | t } | ||
| 2431 : | t $this->_template = $cur_template; | ||
| 2432 : | t } | ||
| 2433 : | t | ||
| 2434 : | t function getTemplate() { | ||
| 2435 : | t return $this->_template; | ||
| 2436 : | t } | ||
| 2437 : | t | ||
| 2438 : | t /** | ||
| 2439 : | counterpoi | 81 | t * Checks to see if an image exists in the current templates image directory |
| 2440 : | t * if it does it loads this image. Otherwise the default image is loaded. | ||
| 2441 : | t * Also can be used in conjunction with the menulist param to create the chosen image | ||
| 2442 : | t * load the default or use no image | ||
| 2443 : | t */ | ||
| 2444 : | t function ImageCheck( $file, $directory='/images/M_images/', $param=NULL, $param_directory='/images/M_images/', $alt=NULL, $name='image', $type=1, $align='middle' ) { | ||
| 2445 : | t $basepath = mamboCore::get('mosConfig_live_site'); | ||
| 2446 : | t if ($param) $image = $basepath.$param_directory.$param; | ||
| 2447 : | t else { | ||
| 2448 : | t $endpath = '/templates/'.$this->getTemplate().'/images/'.$file; | ||
| 2449 : | t if (file_exists(mamboCore::get('mosConfig_absolute_path').$endpath)) $image = $basepath.$endpath; | ||
| 2450 : | t else $image = $basepath.$directory.$file; // outputs only path to image | ||
| 2451 : | t } | ||
| 2452 : | t // outputs actual html <img> tag | ||
| 2453 : | t if ($type) $image = '<img src="'. $image .'" alt="'. $alt .'" align="'. $align .'" name="'. $name .'" border="0" />'; | ||
| 2454 : | t return $image; | ||
| 2455 : | t } | ||
| 2456 : | t | ||
| 2457 : | t /** | ||
| 2458 : | counterpoi | 4 | t * Returns the first to be found of one or more files, or null |
| 2459 : | t * | ||
| 2460 : | t */ | ||
| 2461 : | t function tryFiles ($first_choice, $second_choice=null, $third_choice=null) { | ||
| 2462 : | t if (file_exists($first_choice)) return $first_choice; | ||
| 2463 : | t elseif ($second_choice AND file_exists($second_choice)) return $second_choice; | ||
| 2464 : | t elseif ($third_choice AND file_exists($third_choice)) return $third_choice; | ||
| 2465 : | t else return null; | ||
| 2466 : | t } | ||
| 2467 : | t | ||
| 2468 : | t /** | ||
| 2469 : | t * Returns a standard path variable | ||
| 2470 : | t * | ||
| 2471 : | t */ | ||
| 2472 : | t function getPath( $varname, $option='' ) { | ||
| 2473 : | t | ||
| 2474 : | t $base = mamboCore::get('mosConfig_absolute_path'); | ||
| 2475 : | t if (!$option) $option = $this->_option; | ||
| 2476 : | t $name = substr($option,4); | ||
| 2477 : | t $bac_admin = "$base/administrator/components/com_admin/"; | ||
| 2478 : | t $baco = "$base/administrator/components/$option/"; | ||
| 2479 : | t $bttc = "$base/templates/$this->_template/components/"; | ||
| 2480 : | t $bco = "$base/components/$option/"; | ||
| 2481 : | t $bai = "$base/administrator/includes/"; | ||
| 2482 : | t $bi = "$base/includes/"; | ||
| 2483 : | t | ||
| 2484 : | t switch ($varname) { | ||
| 2485 : | t case 'front': return $this->tryFiles ($bco."$name.php"); | ||
| 2486 : | t case 'front_html': return $this->tryFiles ($bttc."$name.html.php", $bco."$name.html.php"); | ||
| 2487 : | t case 'admin': return $this->tryFiles ($baco."admin.$name.php", $bac_admin.'admin.admin.php'); | ||
| 2488 : | t case 'admin_html': return $this->tryFiles ($baco."admin.$name.html.php", $bac_admin.'admin.admin.html.php'); | ||
| 2489 : | t case 'toolbar': return $this->tryFiles ($baco."toolbar.$name.php"); | ||
| 2490 : | t case 'toolbar_html': return $this->tryFiles ($baco."toolbar.$name.html.php"); | ||
| 2491 : | t case 'toolbar_default': return $this->tryFiles ($bai.'toolbar.html.php'); | ||
| 2492 : | t case 'class': return $this->tryFiles ($bco."$name.class.php", $baco."$name.class.php", $bi."$name.php"); | ||
| 2493 : | t case 'com_xml': return $this->tryFiles ($baco."$name.xml", $bco."$name.xml"); | ||
| 2494 : | t case 'mod0_xml': | ||
| 2495 : | t if ($option) $path = $base."/modules/$option.xml"; | ||
| 2496 : | t else $path = $base.'/modules/custom.xml'; | ||
| 2497 : | t return $this->tryFiles ($path); | ||
| 2498 : | t case 'mod1_xml': | ||
| 2499 : | t if ($option) $path = $base."/administrator/modules/$option.xml"; | ||
| 2500 : | t else $path = $base.'/administrator/modules/custom.xml'; | ||
| 2501 : | t return $this->tryFiles ($path); | ||
| 2502 : | t case 'bot_xml': return $this->tryFiles ($base."/mambots/$option.xml"); | ||
| 2503 : | t case 'menu_xml': return $this->tryFiles ($base."/administrator/comonents/com_menus/$option/$option.xml"); | ||
| 2504 : | t case 'installer_html': return $this->tryFiles($base."/administrator/components/com_installer/$option/$option.html.php"); | ||
| 2505 : | t case 'installer_class': return $this->tryFiles($base."/administrator/components/com_installer/$option/$option.class.php"); | ||
| 2506 : | t } | ||
| 2507 : | t } | ||
| 2508 : | t | ||
| 2509 : | t /** | ||
| 2510 : | t * Detects a 'visit' | ||
| 2511 : | t * | ||
| 2512 : | t * This function updates the agent and domain table hits for a particular | ||
| 2513 : | t * visitor. The user agent is recorded/incremented if this is the first visit. | ||
| 2514 : | t * A cookie is set to mark the first visit. | ||
| 2515 : | t */ | ||
| 2516 : | t function detect() { | ||
| 2517 : | counterpoi | 67 | t if (mamboCore::get('mosConfig_enable_stats') == 1) { |
| 2518 : | counterpoi | 4 | t if (mosGetParam( $_COOKIE, 'mosvisitor', 0 )) return; |
| 2519 : | t setcookie( "mosvisitor", "1" ); | ||
| 2520 : | t | ||
| 2521 : | t $agent = $_SERVER['HTTP_USER_AGENT']; | ||
| 2522 : | t $browser = mosGetBrowser( $agent ); | ||
| 2523 : | t $os = mosGetOS( $agent ); | ||
| 2524 : | t $domain = gethostbyaddr( $_SERVER['REMOTE_ADDR'] ); | ||
| 2525 : | t // tease out the last element of the domain | ||
| 2526 : | t $tldomain = split( "\.", $domain ); | ||
| 2527 : | t $tldomain = $tldomain[count( $tldomain )-1]; | ||
| 2528 : | t if (is_numeric( $tldomain )) { | ||
| 2529 : | t $tldomain = "Unknown"; | ||
| 2530 : | t } | ||
| 2531 : | t | ||
| 2532 : | t $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"); | ||
| 2533 : | t $stats = $this->_db->loadObjectList(); | ||
| 2534 : | t $sql['browser'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$browser',0)"; | ||
| 2535 : | t $sql['os'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$os',1)"; | ||
| 2536 : | t $sql['domain'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$tldomain',2)"; | ||
| 2537 : | t foreach ($stats as $stat) { | ||
| 2538 : | t if ($stat->type == 0) $sql['agents'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$browser' AND type=0"; | ||
| 2539 : | t if ($stat->type == 1) $sql['os'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$os' AND type=1"; | ||
| 2540 : | t if ($stat->type == 2) $sql['domain'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$tldomain' AND type=2"; | ||
| 2541 : | t } | ||
| 2542 : | t $this->_db->setQuery(implode('; ',$sql)); | ||
| 2543 : | t $this->_db->query(); | ||
| 2544 : | t } | ||
| 2545 : | t } | ||
| 2546 : | t | ||
| 2547 : | t /** | ||
| 2548 : | t * @return correct Itemid for Content Item | ||
| 2549 : | t */ | ||
| 2550 : | t function getItemid ($id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1) { | ||
| 2551 : | t $configuration = mamboCore::getMamboCore(); | ||
| 2552 : | t return $configuration->getItemid($id, $typed, $link, $bs, $bc, $gbs); | ||
| 2553 : | t } | ||
| 2554 : | t | ||
| 2555 : | t /** | ||
| 2556 : | t * @return number of Published Blog Sections | ||
| 2557 : | t */ | ||
| 2558 : | t function getBlogSectionCount( ) { | ||
| 2559 : | counterpoi | 67 | t $menuhandler = mosMenuHandler::getInstance(); |
| 2560 : | t if (count($menuhandler->getMenusByType('content_blog_section'))) { | ||
| 2561 : | t $query = "SELECT COUNT( m.id )" | ||
| 2562 : | t ."\n FROM #__content AS i" | ||
| 2563 : | t ."\n LEFT JOIN #__sections AS s ON i.sectionid=s.id" | ||
| 2564 : | t ."\n LEFT JOIN #__menu AS m ON m.componentid=s.id " | ||
| 2565 : | t ."\n WHERE m.type='content_blog_section'" | ||
| 2566 : | t ."\n AND m.published='1'" | ||
| 2567 : | t ; | ||
| 2568 : | t $this->_db->setQuery( $query ); | ||
| 2569 : | t $count = $this->_db->loadResult(); | ||
| 2570 : | t } | ||
| 2571 : | t else $count = 0; | ||
| 2572 : | counterpoi | 4 | t return $count; |
| 2573 : | t } | ||
| 2574 : | t | ||
| 2575 : | t /** | ||
| 2576 : | t * @return number of Published Blog Categories | ||
| 2577 : | t */ | ||
| 2578 : | t function getBlogCategoryCount( ) { | ||
| 2579 : | counterpoi | 67 | t $menuhandler = mosMenuHandler::getInstance(); |
| 2580 : | t if (count($menuhandler->getMenusByType('content_blog_category'))) { | ||
| 2581 : | t $query = "SELECT COUNT( m.id )" | ||
| 2582 : | t . "\n FROM #__content AS i" | ||
| 2583 : | t . "\n LEFT JOIN #__categories AS c ON i.catid=c.id" | ||
| 2584 : | t . "\n LEFT JOIN #__menu AS m ON m.componentid=c.id " | ||
| 2585 : | t . "\n WHERE m.type='content_blog_category'" | ||
| 2586 : | t . "\n AND m.published='1'" | ||
| 2587 : | t ; | ||
| 2588 : | t $this->_db->setQuery( $query ); | ||
| 2589 : | t $count = $this->_db->loadResult(); | ||
| 2590 : | t } | ||
| 2591 : | t else $count = 0; | ||
| 2592 : | counterpoi | 4 | t return $count; |
| 2593 : | t } | ||
| 2594 : | t | ||
| 2595 : | t /** | ||
| 2596 : | t * @return number of Published Global Blog Sections | ||
| 2597 : | t */ | ||
| 2598 : | t function getGlobalBlogSectionCount( ) { | ||
| 2599 : | counterpoi | 13 | t $menuhandler = mosMenuHandler::getInstance(); |
| 2600 : | t return $menuhandler->getGlobalBlogSectionCount(); | ||
| 2601 : | counterpoi | 4 | t } |
| 2602 : | t | ||
| 2603 : | t /** | ||
| 2604 : | t * @return number of Static Content | ||
| 2605 : | t */ | ||
| 2606 : | t function getStaticContentCount( ) { | ||
| 2607 : | counterpoi | 13 | t $menuhandler = mosMenuHandler::getInstance(); |
| 2608 : | t return $menuhandler->getMenuCount ('content_typed', 1); | ||
| 2609 : | counterpoi | 4 | t } |
| 2610 : | t | ||
| 2611 : | t /** | ||
| 2612 : | t * @return number of Content Item Links | ||
| 2613 : | t */ | ||
| 2614 : | t function getContentItemLinkCount( ) { | ||
| 2615 : | counterpoi | 13 | t $menuhandler = mosMenuHandler::getInstance(); |
| 2616 : | t return $menuhandler->getMenuCount ('content_item_link', 1); | ||
| 2617 : | counterpoi | 4 | t } |
| 2618 : | t } | ||
| 2619 : | t | ||
| 2620 : | t /** | ||
| 2621 : | t * Class to support function caching | ||
| 2622 : | t * @package Mambo | ||
| 2623 : | t */ | ||
| 2624 : | t class mosCache { | ||
| 2625 : | t /** | ||
| 2626 : | t * @return object A function cache object | ||
| 2627 : | t */ | ||
| 2628 : | t function &getCache( $group='' ) { | ||
| 2629 : | t $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); | ||
| 2630 : | t require_once($mosConfig_absolute_path.'/includes/Cache/Lite/Function.php'); | ||
| 2631 : | t $path = mamboCore::get('mosConfig_cachepath'); | ||
| 2632 : | t $caching = mamboCore::get('mosConfig_caching'); | ||
| 2633 : | t $time = mamboCore::get('mosConfig_cachetime'); | ||
| 2634 : | t $options = array( | ||
| 2635 : | t 'cacheDir' => "$path/", | ||
| 2636 : | t 'caching' => $caching, | ||
| 2637 : | t 'defaultGroup' => $group, | ||
| 2638 : | t 'lifeTime' => $time | ||
| 2639 : | t ); | ||
| 2640 : | t $cache =& new Cache_Lite_Function( $options ); | ||
| 2641 : | t return $cache; | ||
| 2642 : | t } | ||
| 2643 : | t /** | ||
| 2644 : | t * Cleans the cache | ||
| 2645 : | t */ | ||
| 2646 : | t function cleanCache ($group=false) { | ||
| 2647 : | t if (mamboCore::get('mosConfig_caching')) { | ||
| 2648 : | t $cache =& mosCache::getCache( $group ); | ||
| 2649 : | t $cache->clean( $group ); | ||
| 2650 : | t } | ||
| 2651 : | t } | ||
| 2652 : | t } | ||
| 2653 : | t | ||
| 2654 : | t /** | ||
| 2655 : | t * Session database table class | ||
| 2656 : | t * @package Mambo | ||
| 2657 : | t */ | ||
| 2658 : | t class mosSession extends mosDBTable { | ||
| 2659 : | t /** @var int Primary key */ | ||
| 2660 : | t var $session_id=null; | ||
| 2661 : | t /** @var string */ | ||
| 2662 : | t var $time=null; | ||
| 2663 : | t /** @var string */ | ||
| 2664 : | t var $userid=0; | ||
| 2665 : | t /** @var string */ | ||
| 2666 : | t var $usertype=null; | ||
| 2667 : | t /** @var string */ | ||
| 2668 : | t var $username=''; | ||
| 2669 : | t /** @var time */ | ||
| 2670 : | t var $gid=0; | ||
| 2671 : | t /** @var int */ | ||
| 2672 : | t var $guest=1; | ||
| 2673 : | t /** @var string */ | ||
| 2674 : | t var $_session_cookie=null; | ||
| 2675 : | t | ||
| 2676 : | t /** | ||
| 2677 : | t * @param database A database connector object | ||
| 2678 : | t */ | ||
| 2679 : | t function mosSession( &$db ) { | ||
| 2680 : | t $database = mamboDatabase::getInstance(); | ||
| 2681 : | t $this->mosDBTable( '#__session', 'session_id', $database ); | ||
| 2682 : | t $this->time = time(); | ||
| 2683 : | t } | ||
| 2684 : | t | ||
| 2685 : | t function &getCurrent () { | ||
| 2686 : | t static $currentSession; | ||
| 2687 : | t if (!is_object($currentSession)) { | ||
| 2688 : | counterpoi | 13 | t $currentSession = new mosSession($dummy); |
| 2689 : | counterpoi | 4 | t $currentSession->purge(intval(mamboCore::get('mosConfig_lifetime'))); |
| 2690 : | t $sessionCookieName = md5('site'.mamboCore::get('mosConfig_live_site')); | ||
| 2691 : | t $sessioncookie = mosGetParam($_COOKIE, $sessionCookieName, null); | ||
| 2692 : | t $usercookie = mosGetParam($_COOKIE, 'usercookie', null); | ||
| 2693 : | t if ($currentSession->load(md5($sessioncookie.$_SERVER['REMOTE_ADDR']))) { | ||
| 2694 : | t // Session cookie exists, update time in session table | ||
| 2695 : | t $currentSession->time = time(); | ||
| 2696 : | t $currentSession->update(); | ||
| 2697 : | t } else { | ||
| 2698 : | t $currentSession->generateId(); | ||
| 2699 : | t if (!$currentSession->insert()) { | ||
| 2700 : | t die( $currentSession->getError() ); | ||
| 2701 : | t } | ||
| 2702 : | t setcookie( $sessionCookieName, $currentSession->getCookie(), time() + 43200, '/' ); | ||
| 2703 : | t //$_COOKIE["sessioncookie"] = $session->getCookie(); | ||
| 2704 : | t if ($usercookie) { | ||
| 2705 : | t // Remember me cookie exists. Login with usercookie info. | ||
| 2706 : | t $authenticator = mamboAuthenticator::getInstance(); | ||
| 2707 : | t $authenticator->authenticateUser ($message, $usercookie['username'], $usercookie['password'], null, $currentSession); | ||
| 2708 : | t } | ||
| 2709 : | t } | ||
| 2710 : | t } | ||
| 2711 : | t return $currentSession; | ||
| 2712 : | t } | ||
| 2713 : | t | ||
| 2714 : | t function insert() { | ||
| 2715 : | t $ret = $this->_db->insertObject( $this->_tbl, $this ); | ||
| 2716 : | t | ||
| 2717 : | t if( !$ret ) { | ||
| 2718 : | t $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->stderr(); | ||
| 2719 : | t return false; | ||
| 2720 : | t } else { | ||
| 2721 : | t return true; | ||
| 2722 : | t } | ||
| 2723 : | t } | ||
| 2724 : | t | ||
| 2725 : | t function update( $updateNulls=false ) { | ||
| 2726 : | t $ret = $this->_db->updateObject( $this->_tbl, $this, 'session_id', $updateNulls ); | ||
| 2727 : | t | ||
| 2728 : | t if( !$ret ) { | ||
| 2729 : | t $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->stderr(); | ||
| 2730 : | t return false; | ||
| 2731 : | t } else { | ||
| 2732 : | t return true; | ||
| 2733 : | t } | ||
| 2734 : | t } | ||
| 2735 : | t | ||
| 2736 : | t function generateId() { | ||
| 2737 : | t $failsafe = 20; | ||
| 2738 : | t $randnum = 0; | ||
| 2739 : | t while ($failsafe--) { | ||
| 2740 : | t $randnum = md5( uniqid( microtime(), 1 ) ); | ||
| 2741 : | t if ($randnum != "") { | ||
| 2742 : | t $cryptrandnum = md5( $randnum ); | ||
| 2743 : | t $this->_db->setQuery( "SELECT $this->_tbl_key FROM $this->_tbl WHERE $this->_tbl_key=MD5('$randnum')" ); | ||
| 2744 : | t if(!$result = $this->_db->query()) { | ||
| 2745 : | t die( $this->_db->stderr( true )); | ||
| 2746 : | t // todo: handle gracefully | ||
| 2747 : | t } | ||
| 2748 : | t if ($this->_db->getNumRows($result) == 0) { | ||
| 2749 : | t break; | ||
| 2750 : | t } | ||
| 2751 : | t } | ||
| 2752 : | t } | ||
| 2753 : | t $this->_session_cookie = $randnum; | ||
| 2754 : | t $this->session_id = md5( $randnum . $_SERVER['REMOTE_ADDR'] ); | ||
| 2755 : | t } | ||
| 2756 : | t | ||
| 2757 : | t function getCookie() { | ||
| 2758 : | t return $this->_session_cookie; | ||
| 2759 : | t } | ||
| 2760 : | t | ||
| 2761 : | t function purge( $inc=1800 ) { | ||
| 2762 : | t $past = time() - $inc; | ||
| 2763 : | t $query = "DELETE FROM $this->_tbl" | ||
| 2764 : | t . "\nWHERE (time < $past)"; | ||
| 2765 : | t $this->_db->setQuery($query); | ||
| 2766 : | t | ||
| 2767 : | t return $this->_db->query(); | ||
| 2768 : | t } | ||
| 2769 : | t } | ||
| 2770 : | t | ||
| 2771 : | t /** | ||
| 2772 : | t * Page generation time | ||
| 2773 : | t * @package Mambo | ||
| 2774 : | t */ | ||
| 2775 : | t class mosProfiler { | ||
| 2776 : | t var $start=0; | ||
| 2777 : | t var $prefix=''; | ||
| 2778 : | t | ||
| 2779 : | t function mosProfiler( $prefix='' ) { | ||
| 2780 : | t $this->start = $this->getmicrotime(); | ||
| 2781 : | t $this->prefix = $prefix; | ||
| 2782 : | t } | ||
| 2783 : | t | ||
| 2784 : | t function mark( $label ) { | ||
| 2785 : | t return sprintf ( "\n<div class=\"profiler\">$this->prefix %.3f $label</div>", $this->getmicrotime() - $this->start ); | ||
| 2786 : | t } | ||
| 2787 : | t | ||
| 2788 : | t function getmicrotime(){ | ||
| 2789 : | t list($usec, $sec) = explode(" ",microtime()); | ||
| 2790 : | t return ((float)$usec + (float)$sec); | ||
| 2791 : | t } | ||
| 2792 : | t } | ||
| 2793 : | t | ||
| 2794 : | t if (!isset($adminside)) $adminside = 0; | ||
| 2795 : | counterpoi | 67 | t if (!isset($indextype)) $indextype = 1; |
| 2796 : | counterpoi | 4 | t |
| 2797 : | t $_VERSION =& new version(); | ||
| 2798 : | t | ||
| 2799 : | t $version = $_VERSION->PRODUCT .' '. $_VERSION->RELEASE .'.'. $_VERSION->DEV_LEVEL .' ' | ||
| 2800 : | t . $_VERSION->DEV_STATUS | ||
| 2801 : | t .' [ '.$_VERSION->CODENAME .' ] '. $_VERSION->RELDATE .' ' | ||
| 2802 : | t . $_VERSION->RELTIME .' '. $_VERSION->RELTZ; | ||
| 2803 : | t | ||
| 2804 : | t $configuration =& mamboCore::getMamboCore(); | ||
| 2805 : | t | ||
| 2806 : | t $configuration->handleGlobals(); | ||
| 2807 : | t | ||
| 2808 : | counterpoi | 82 | t if (phpversion() < '4.2.0') require_once( $configuration->rootPath() . '/includes/compat.php41x.php' ); |
| 2809 : | t if (phpversion() < '4.3.0') require_once( $configuration->rootPath() . '/includes/compat.php42x.php' ); | ||
| 2810 : | t | ||
| 2811 : | t @set_magic_quotes_runtime( 0 ); | ||
| 2812 : | t | ||
| 2813 : | t if (@$mosConfig_error_reporting === 0) error_reporting( 0 ); | ||
| 2814 : | t elseif (@$mosConfig_error_reporting > 0) error_reporting( $mosConfig_error_reporting ); | ||
| 2815 : | t | ||
| 2816 : | t $local_backup_path = $configuration->rootPath().'/administrator/backups'; | ||
| 2817 : | t $media_path = $configuration->rootPath().'/media/'; | ||
| 2818 : | t $image_path = $configuration->rootPath().'/images/stories'; | ||
| 2819 : | t $image_size = 100; | ||
| 2820 : | t | ||
| 2821 : | counterpoi | 4 | t /** retrieve all possible request string (or form) arguments */ |
| 2822 : | t $type = mosGetParam($_REQUEST, 'type', 1); | ||
| 2823 : | t $no_html = mosGetParam( $_REQUEST, 'no_html', 0 ); | ||
| 2824 : | t $act = mosGetParam( $_REQUEST, 'act', '' ); | ||
| 2825 : | t $do_pdf = mosGetParam( $_REQUEST, 'do_pdf', 0 ); | ||
| 2826 : | t $pop = mosGetParam( $_REQUEST, 'pop', 0 ); | ||
| 2827 : | t $id = mosGetParam( $_REQUEST, 'id', 0 ); | ||
| 2828 : | t $task = mosGetParam($_REQUEST, 'task', ''); | ||
| 2829 : | t $act = strtolower(mosGetParam($_REQUEST, 'act', '')); | ||
| 2830 : | t $section = mosGetParam($_REQUEST, 'section', ''); | ||
| 2831 : | t $no_html = strtolower(mosGetParam($_REQUEST, 'no_html', '')); | ||
| 2832 : | t | ||
| 2833 : | t $database = mamboDatabase::getInstance(); | ||
| 2834 : | t $database->debug(mamboCore::get('mosConfig_debug')); | ||
| 2835 : | t | ||
| 2836 : | t if ($adminside) { | ||
| 2837 : | t $option = strtolower(mosGetParam($_REQUEST,'option','com_admin')); | ||
| 2838 : | counterpoi | 82 | t require_once($configuration->rootPath().'/includes/gacl.class.php' ); |
| 2839 : | t require_once($configuration->rootPath().'/includes/gacl_api.class.php' ); | ||
| 2840 : | counterpoi | 8 | t $acl = new gacl_api(); |
| 2841 : | counterpoi | 4 | t if ($option == 'login') { |
| 2842 : | t require_once($configuration->rootPath().'/includes/authenticator.php'); | ||
| 2843 : | t $authenticator = mamboAuthenticator::getInstance(); | ||
| 2844 : | counterpoi | 5 | t $my = $authenticator->loginAdmin($acl); |
| 2845 : | counterpoi | 4 | t } |
| 2846 : | t else { | ||
| 2847 : | t session_name(md5(mamboCore::get('mosConfig_live_site'))); | ||
| 2848 : | t session_start(); | ||
| 2849 : | t if ($option == 'logout') { | ||
| 2850 : | t require($configuration->rootPath().'/administrator/logout.php'); | ||
| 2851 : | t exit(); | ||
| 2852 : | t } | ||
| 2853 : | t else { | ||
| 2854 : | t require_once($configuration->rootPath().'/administrator/includes/admin.php'); | ||
| 2855 : | t $my = checkAdminSession($database); | ||
| 2856 : | t if ($option == 'simple_mode') $admin_mode = 'on'; | ||
| 2857 : | t elseif ($option == 'advanced_mode') $admin_mode = 'off'; | ||
| 2858 : | t else $admin_mode = mosGetParam($_SESSION, 'simple_editing', ''); | ||
| 2859 : | t $_SESSION['simple_editing'] = mosGetParam($_POST, 'simple_editing', $admin_mode); | ||
| 2860 : | t } | ||
| 2861 : | t } | ||
| 2862 : | t $mainframe =& new mosMainFrame($database, $option, '..', true); | ||
| 2863 : | t if ($my) { | ||
| 2864 : | t require_once( $configuration->rootPath().'/includes/mambo.php' ); | ||
| 2865 : | counterpoi | 82 | t require_once ($configuration->rootPath().'/includes/mambofunc.php'); |
| 2866 : | counterpoi | 83 | t require_once ($configuration->rootPath().'/includes/mamboHTML.php'); |
| 2867 : | counterpoi | 81 | t require_once( $configuration->rootPath().'/administrator/includes/mosAdminMenus.php'); |
| 2868 : | t require_once( $configuration->rootPath().'/includes/mamboxml.php' ); | ||
| 2869 : | counterpoi | 4 | t $_MAMBOTS = mosMambotHandler::getInstance(); |
| 2870 : | t // start the html output | ||
| 2871 : | t if ($no_html) { | ||
| 2872 : | t if ($path = $mainframe->getPath( "admin" )) require $path; | ||
| 2873 : | t exit(); | ||
| 2874 : | t } | ||
| 2875 : | t $configuration->initGzip(); | ||
| 2876 : | t require_once($configuration->rootPath().'/administrator/includes/admin.php'); | ||
| 2877 : | t if ($adminside != 3) { | ||
| 2878 : | t $path = $configuration->rootPath().'/administrator/templates/'.$mainframe->getTemplate().'/index.php'; | ||
| 2879 : | t require_once($path); | ||
| 2880 : | t $configuration->doGzip(); | ||
| 2881 : | t } | ||
| 2882 : | t } | ||
| 2883 : | t else { | ||
| 2884 : | t $configuration->initGzip(); | ||
| 2885 : | t $path = $configuration->rootPath().'/administrator/templates/'.$mainframe->getTemplate().'/login.php'; | ||
| 2886 : | t require_once( $path ); | ||
| 2887 : | t $configuration->doGzip(); | ||
| 2888 : | t } | ||
| 2889 : | t } | ||
| 2890 : | t else { | ||
| 2891 : | t $sefcode = $configuration->rootPath().'/components/com_sef/sef.php'; | ||
| 2892 : | t if (file_exists($sefcode)) require_once($sefcode); | ||
| 2893 : | t else require_once($configuration->rootPath().'/includes/sef.php'); | ||
| 2894 : | counterpoi | 79 | t $urlerror = 0; |
| 2895 : | t if (mamboCore::get('mosConfig_sef') AND $indextype == 3) { | ||
| 2896 : | t $sef = mosSEF::getInstance(); | ||
| 2897 : | t $urlerror = $sef->sefRetrieval(mamboCore::get('mosConfig_register_globals')); | ||
| 2898 : | t $indextype = 1; | ||
| 2899 : | t $configuration->handleGlobals(); | ||
| 2900 : | t } | ||
| 2901 : | counterpoi | 4 | t $option = $configuration->determineOptionAndItemid(); |
| 2902 : | t $Itemid = $configuration->get('Itemid'); | ||
| 2903 : | t $mainframe =& new mosMainFrame($database, $option, '.'); | ||
| 2904 : | t $session = mosSession::getCurrent(); | ||
| 2905 : | t | ||
| 2906 : | t if ($option == 'login') $configuration->handleLogin($session); | ||
| 2907 : | t elseif ($option == 'logout') $configuration->handleLogout($session); | ||
| 2908 : | t | ||
| 2909 : | t $my =& new mosUser($database); | ||
| 2910 : | t $my->getSessionData(); | ||
| 2911 : | t $configuration->offlineCheck($my, $database); | ||
| 2912 : | t $gid = intval( $my->gid ); | ||
| 2913 : | t // gets template for page | ||
| 2914 : | t $cur_template = $mainframe->getTemplate(); | ||
| 2915 : | t | ||
| 2916 : | counterpoi | 67 | t require_once( $configuration->rootPath().'/includes/frontend.php' ); |
| 2917 : | t require_once( $configuration->rootPath().'/includes/mambo.php' ); | ||
| 2918 : | counterpoi | 82 | t require_once ($configuration->rootPath().'/includes/mambofunc.php'); |
| 2919 : | counterpoi | 83 | t require_once ($configuration->rootPath().'/includes/mamboHTML.php'); |
| 2920 : | counterpoi | 81 | t require_once( $configuration->rootPath().'/includes/mamboxml.php' ); |
| 2921 : | counterpoi | 4 | t |
| 2922 : | counterpoi | 67 | t if ($indextype == 2 AND $do_pdf == 1 ) { |
| 2923 : | t include_once('includes/pdf.php'); | ||
| 2924 : | t exit(); | ||
| 2925 : | counterpoi | 4 | t } |
| 2926 : | t | ||
| 2927 : | t /** detect first visit */ | ||
| 2928 : | t $mainframe->detect(); | ||
| 2929 : | t | ||
| 2930 : | t /** @global mosPlugin $_MAMBOTS */ | ||
| 2931 : | t $_MAMBOTS = mosMambotHandler::getInstance(); | ||
| 2932 : | t require_once( $configuration->rootPath().'/editor/editor.php' ); | ||
| 2933 : | counterpoi | 82 | t require_once( $configuration->rootPath() . '/includes/gacl.class.php' ); |
| 2934 : | t require_once( $configuration->rootPath() . '/includes/gacl_api.class.php' ); | ||
| 2935 : | counterpoi | 4 | t $acl = new gacl_api(); |
| 2936 : | t | ||
| 2937 : | t /** @global A places to store information from processing of the component */ | ||
| 2938 : | t $_MOS_OPTION = array(); | ||
| 2939 : | t | ||
| 2940 : | t ob_start(); | ||
| 2941 : | t | ||
| 2942 : | counterpoi | 79 | t if (!$urlerror AND $path = $mainframe->getPath( 'front' )) { |
| 2943 : | counterpoi | 67 | t $menuhandler = mosMenuHandler::getInstance(); |
| 2944 : | t $ret = $menuhandler->menuCheck($Itemid, $option, $task, $gid); | ||
| 2945 : | t $menuhandler->setPathway($Itemid); | ||
| 2946 : | counterpoi | 4 | t if ($ret) require_once( $path ); |
| 2947 : | t else mosNotAuth(); | ||
| 2948 : | t } | ||
| 2949 : | counterpoi | 79 | t else { |
| 2950 : | t header ("HTTP/1.0 404 Not Found"); | ||
| 2951 : | t include ($configuration->rootPath().'/page404.php'); | ||
| 2952 : | t } | ||
| 2953 : | counterpoi | 4 | t |
| 2954 : | t $_MOS_OPTION['buffer'] = ob_get_contents(); | ||
| 2955 : | t ob_end_clean(); | ||
| 2956 : | t | ||
| 2957 : | t $configuration->initGzip(); | ||
| 2958 : | t | ||
| 2959 : | t $configuration->standardHeaders(); | ||
| 2960 : | t | ||
| 2961 : | counterpoi | 67 | t if ($indextype == 1) { |
| 2962 : | t // loads template file | ||
| 2963 : | t if ( !file_exists( 'templates/'. $cur_template .'/index.php' ) ) { | ||
| 2964 : | t echo _TEMPLATE_WARN . $cur_template; | ||
| 2965 : | t } else { | ||
| 2966 : | t require_once( 'templates/'. $cur_template .'/index.php' ); | ||
| 2967 : | t echo "<!-- ".time()." -->"; | ||
| 2968 : | t } | ||
| 2969 : | counterpoi | 4 | t } |
| 2970 : | counterpoi | 67 | t elseif ($indextype == 2) { |
| 2971 : | t if ( $no_html == 0 ) { | ||
| 2972 : | t // needed to seperate the ISO number from the language file constant _ISO | ||
| 2973 : | t $iso = split( '=', _ISO ); | ||
| 2974 : | t // xml prolog | ||
| 2975 : | t echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>'; | ||
| 2976 : | t ?> | ||
| 2977 : | t <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
| 2978 : | t <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| 2979 : | t <head> | ||
| 2980 : | t <link rel="stylesheet" href="templates/<?php echo $cur_template;?>/css/template_css.css" type="text/css" /> | ||
| 2981 : | t <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?>" /> | ||
| 2982 : | t <meta name="robots" content="noindex, nofollow"> | ||
| 2983 : | t </head> | ||
| 2984 : | t <body class="contentpane"> | ||
| 2985 : | t <?php mosMainBody(); ?> | ||
| 2986 : | t </body> | ||
| 2987 : | t </html> | ||
| 2988 : | t <?php | ||
| 2989 : | t } else { | ||
| 2990 : | t mosMainBody(); | ||
| 2991 : | t } | ||
| 2992 : | t } | ||
| 2993 : | counterpoi | 4 | t |
| 2994 : | t | ||
| 2995 : | t $configuration->doGzip(); | ||
| 2996 : | t } | ||
| 2997 : | t // displays queries performed for page | ||
| 2998 : | t if ($configuration->get('mosConfig_debug')) $database->displayLogged(); | ||
| 2999 : | t | ||
| 3000 : | t ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

