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

