Annotation of /mambo/branches/4.6/includes/mambo.php
Parent Directory
|
Revision Log
Revision 39 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: mambo.php,v 1.14 2005/11/14 21:56:04 eliasan Exp $ | ||
| 4 : | csouza | 39 | * @package Mambo With admin Language Pack for 4.5.3 by datahellas |
| 5 : | root | 1 | * @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 : | /** ensure this file is being included by a parent file */ | ||
| 11 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 12 : | define( '_MOS_MAMBO_INCLUDED', 1 ); | ||
| 13 : | |||
| 14 : | if (phpversion() < '4.2.0') { | ||
| 15 : | require_once( $mosConfig_absolute_path . '/includes/compat.php41x.php' ); | ||
| 16 : | } | ||
| 17 : | if (phpversion() < '4.3.0') { | ||
| 18 : | require_once( $mosConfig_absolute_path . '/includes/compat.php42x.php' ); | ||
| 19 : | } | ||
| 20 : | if (in_array( 'globals', array_keys( array_change_key_case( $_REQUEST, CASE_LOWER ) ) ) ) { | ||
| 21 : | die( 'Fatal error. Global variable hack attempted.' ); | ||
| 22 : | } | ||
| 23 : | if (in_array( '_post', array_keys( array_change_key_case( $_REQUEST, CASE_LOWER ) ) ) ) { | ||
| 24 : | die( 'Fatal error. Post variable hack attempted.' ); | ||
| 25 : | } | ||
| 26 : | |||
| 27 : | |||
| 28 : | @set_magic_quotes_runtime( 0 ); | ||
| 29 : | |||
| 30 : | if (@$mosConfig_error_reporting === 0) { | ||
| 31 : | error_reporting( 0 ); | ||
| 32 : | } else if (@$mosConfig_error_reporting > 0) { | ||
| 33 : | error_reporting( $mosConfig_error_reporting ); | ||
| 34 : | } | ||
| 35 : | |||
| 36 : | $local_backup_path = $mosConfig_absolute_path.'/administrator/backups'; | ||
| 37 : | $media_path = $mosConfig_absolute_path.'/media/'; | ||
| 38 : | $image_path = $mosConfig_absolute_path.'/images/stories'; | ||
| 39 : | $image_size = 100; | ||
| 40 : | |||
| 41 : | csouza | 39 | require_once( $mosConfig_absolute_path . "/includes/version.php" ); |
| 42 : | require_once( $mosConfig_absolute_path . "/includes/database.php" ); | ||
| 43 : | require_once( $mosConfig_absolute_path . "/includes/gacl.class.php" ); | ||
| 44 : | require_once( $mosConfig_absolute_path . "/includes/gacl_api.class.php" ); | ||
| 45 : | require_once( $mosConfig_absolute_path . "/includes/phpmailer/class.phpmailer.php" ); | ||
| 46 : | require_once( $mosConfig_absolute_path . "/includes/mamboxml.php" ); | ||
| 47 : | require_once( $mosConfig_absolute_path . "/includes/phpInputFilter/class.inputfilter.php" ); | ||
| 48 : | root | 1 | |
| 49 : | /** | ||
| 50 : | * Task routing class | ||
| 51 : | * @package Mambo | ||
| 52 : | * @abstract | ||
| 53 : | */ | ||
| 54 : | class mosAbstractTasker { | ||
| 55 : | /** @var array An array of the class methods to call for a task */ | ||
| 56 : | var $taskMap = null; | ||
| 57 : | /** @var string The name of the default task */ | ||
| 58 : | var $defaultTask = null; | ||
| 59 : | /** @var string The name of the current task*/ | ||
| 60 : | var $task = null; | ||
| 61 : | /** @var array An array of the class methods*/ | ||
| 62 : | var $_methods = null; | ||
| 63 : | /** @var string A url to redirect to */ | ||
| 64 : | var $_redirect = null; | ||
| 65 : | /** @var string A message about the operation of the task */ | ||
| 66 : | var $_message = null; | ||
| 67 : | |||
| 68 : | /** | ||
| 69 : | * Constructor | ||
| 70 : | */ | ||
| 71 : | function mosAbstractTasker() { | ||
| 72 : | $taskMap = array(); | ||
| 73 : | $this->_methods = array(); | ||
| 74 : | foreach (get_class_methods( get_class( $this ) ) as $method) { | ||
| 75 : | $this->_methods[] = strtolower( $method ); | ||
| 76 : | } | ||
| 77 : | $this->_redirect = ''; | ||
| 78 : | $this->_message = ''; | ||
| 79 : | } | ||
| 80 : | /** | ||
| 81 : | * Set a URL to redirect the browser to | ||
| 82 : | * @param string A URL | ||
| 83 : | */ | ||
| 84 : | function setRedirect( $url, $msg = null ) { | ||
| 85 : | $this->_redirect = $url; | ||
| 86 : | if ($msg !== null) { | ||
| 87 : | $this->_message = $msg; | ||
| 88 : | } | ||
| 89 : | } | ||
| 90 : | /** | ||
| 91 : | * Redirects the browser | ||
| 92 : | */ | ||
| 93 : | function redirect() { | ||
| 94 : | if ($this->_redirect) { | ||
| 95 : | mosRedirect( $this->_redirect, $this->_message ); | ||
| 96 : | } | ||
| 97 : | } | ||
| 98 : | /** | ||
| 99 : | * Register (map) a task to a method in the class | ||
| 100 : | * @param string The task | ||
| 101 : | * @param string The name of the method in the derived class to perform for this task | ||
| 102 : | */ | ||
| 103 : | function registerTask( $task, $method ) { | ||
| 104 : | if (in_array( strtolower( $method ), $this->_methods )) { | ||
| 105 : | $this->taskMap[$task] = $method; | ||
| 106 : | } else { | ||
| 107 : | $this->methodNotFound( $method ); | ||
| 108 : | } | ||
| 109 : | } | ||
| 110 : | /** | ||
| 111 : | * Register the default task to perfrom if a mapping is not found | ||
| 112 : | * @param string The name of the method in the derived class to perform if the task is not found | ||
| 113 : | */ | ||
| 114 : | function registerDefaultTask( $method ) { | ||
| 115 : | $this->registerTask( '__default', $method ); | ||
| 116 : | } | ||
| 117 : | /** | ||
| 118 : | * Perform a task by triggering a method in the derived class | ||
| 119 : | * @param string The task to perform | ||
| 120 : | * @return mixed The value returned by the function | ||
| 121 : | */ | ||
| 122 : | function performTask( $task ) { | ||
| 123 : | $this->task = $task; | ||
| 124 : | |||
| 125 : | if (isset( $this->taskMap[$task] )) { | ||
| 126 : | return call_user_func( array( &$this, $this->taskMap[$task] ) ); | ||
| 127 : | } else if (isset( $this->taskMap['__default'] )) { | ||
| 128 : | return call_user_func( array( &$this, $this->taskMap['__default'] ) ); | ||
| 129 : | } else { | ||
| 130 : | return $this->taskNotFound( $task ); | ||
| 131 : | } | ||
| 132 : | } | ||
| 133 : | /** | ||
| 134 : | * Get the last task that was to be performed | ||
| 135 : | * @return string The task that was or is being performed | ||
| 136 : | */ | ||
| 137 : | function getTask() { | ||
| 138 : | return $this->task; | ||
| 139 : | } | ||
| 140 : | /** | ||
| 141 : | * Basic method if the task is not found | ||
| 142 : | * @param string The task | ||
| 143 : | * @return null | ||
| 144 : | */ | ||
| 145 : | function taskNotFound( $task ) { | ||
| 146 : | echo 'Task ' . $task . ' not found'; | ||
| 147 : | return null; | ||
| 148 : | } | ||
| 149 : | /** | ||
| 150 : | * Basic method if the registered method is not found | ||
| 151 : | * @param string The name of the method in the derived class | ||
| 152 : | * @return null | ||
| 153 : | */ | ||
| 154 : | function methodNotFound( $name ) { | ||
| 155 : | echo 'Method ' . $name . ' not found'; | ||
| 156 : | return null; | ||
| 157 : | } | ||
| 158 : | } | ||
| 159 : | |||
| 160 : | |||
| 161 : | /** | ||
| 162 : | * Class to support function caching | ||
| 163 : | * @package Mambo | ||
| 164 : | */ | ||
| 165 : | class mosCache { | ||
| 166 : | /** | ||
| 167 : | * @return object A function cache object | ||
| 168 : | */ | ||
| 169 : | function &getCache( $group='' ) { | ||
| 170 : | global $mosConfig_absolute_path, $mosConfig_caching, $mosConfig_cachepath, $mosConfig_cachetime; | ||
| 171 : | |||
| 172 : | require_once( "$mosConfig_absolute_path/includes/Cache/Lite/Function.php" ); | ||
| 173 : | |||
| 174 : | $options = array( | ||
| 175 : | 'cacheDir' => "$mosConfig_cachepath/", | ||
| 176 : | 'caching' => $mosConfig_caching, | ||
| 177 : | 'defaultGroup' => $group, | ||
| 178 : | 'lifeTime' => $mosConfig_cachetime | ||
| 179 : | ); | ||
| 180 : | $cache =& new Cache_Lite_Function( $options ); | ||
| 181 : | return $cache; | ||
| 182 : | } | ||
| 183 : | /** | ||
| 184 : | * Cleans the cache | ||
| 185 : | */ | ||
| 186 : | function cleanCache( $group=false ) { | ||
| 187 : | global $mosConfig_caching; | ||
| 188 : | if ($mosConfig_caching) { | ||
| 189 : | $cache =& mosCache::getCache( $group ); | ||
| 190 : | $cache->clean( $group ); | ||
| 191 : | } | ||
| 192 : | } | ||
| 193 : | } | ||
| 194 : | /** | ||
| 195 : | * Mambo Mainframe class | ||
| 196 : | * | ||
| 197 : | * Provide many supporting API functions | ||
| 198 : | * @package Mambo | ||
| 199 : | */ | ||
| 200 : | class mosMainFrame { | ||
| 201 : | /** @var database Internal database class pointer */ | ||
| 202 : | var $_db=null; | ||
| 203 : | /** @var object An object of configuration variables */ | ||
| 204 : | var $_config=null; | ||
| 205 : | /** @var object An object of path variables */ | ||
| 206 : | var $_path=null; | ||
| 207 : | /** @var mosSession The current session */ | ||
| 208 : | var $_session=null; | ||
| 209 : | /** @var string The current template */ | ||
| 210 : | var $_template=null; | ||
| 211 : | /** @var array An array to hold global user state within a session */ | ||
| 212 : | var $_userstate=null; | ||
| 213 : | /** @var array An array of page meta information */ | ||
| 214 : | var $_head=null; | ||
| 215 : | /** @var string Custom html string to append to the pathway */ | ||
| 216 : | var $_custom_pathway=null; | ||
| 217 : | |||
| 218 : | /** | ||
| 219 : | * Class constructor | ||
| 220 : | * @param database A database connection object | ||
| 221 : | * @param string The url option | ||
| 222 : | * @param string The path of the mos directory | ||
| 223 : | */ | ||
| 224 : | function mosMainFrame( &$db, $option, $basePath, $isAdmin=false ) { | ||
| 225 : | $this->_db =& $db; | ||
| 226 : | |||
| 227 : | // load the configuration values | ||
| 228 : | //return( $this->loadConfig() ); | ||
| 229 : | $this->_setConfig( $basePath ); | ||
| 230 : | $this->_setTemplate( $isAdmin ); | ||
| 231 : | $this->_setAdminPaths( $option, $this->getCfg( 'absolute_path' ) ); | ||
| 232 : | if (isset( $_SESSION['session_userstate'] )) { | ||
| 233 : | $this->_userstate =& $_SESSION['session_userstate']; | ||
| 234 : | } else { | ||
| 235 : | $this->_userstate = null; | ||
| 236 : | } | ||
| 237 : | $this->_head = array(); | ||
| 238 : | $this->_head['title'] = $GLOBALS['mosConfig_sitename']; | ||
| 239 : | $this->_head['meta'] = array(); | ||
| 240 : | $this->_head['custom'] = array(); | ||
| 241 : | } | ||
| 242 : | /** | ||
| 243 : | * @param string | ||
| 244 : | */ | ||
| 245 : | function setPageTitle( $title=null ) { | ||
| 246 : | if (@$GLOBALS['mosConfig_pagetitles']) { | ||
| 247 : | $title = trim( htmlspecialchars( $title ) ); | ||
| 248 : | $this->_head['title'] = $title ? $GLOBALS['mosConfig_sitename'] . ' - '. $title : $GLOBALS['mosConfig_sitename']; | ||
| 249 : | } | ||
| 250 : | } | ||
| 251 : | /** | ||
| 252 : | * @param string The value of the name attibute | ||
| 253 : | * @param string The value of the content attibute | ||
| 254 : | * @param string Text to display before the tag | ||
| 255 : | * @param string Text to display after the tag | ||
| 256 : | */ | ||
| 257 : | function addMetaTag( $name, $content, $prepend='', $append='' ) { | ||
| 258 : | $name = trim( htmlspecialchars( $name ) ); | ||
| 259 : | $content = trim( htmlspecialchars( $content ) ); | ||
| 260 : | $prepend = trim( $prepend ); | ||
| 261 : | $append = trim( $append ); | ||
| 262 : | $this->_head['meta'][] = array( $name, $content, $prepend, $append ); | ||
| 263 : | } | ||
| 264 : | /** | ||
| 265 : | * @param string The value of the name attibute | ||
| 266 : | * @param string The value of the content attibute to append to the existing | ||
| 267 : | * Tags ordered in with Site Keywords and Description first | ||
| 268 : | */ | ||
| 269 : | function appendMetaTag( $name, $content ) { | ||
| 270 : | $name = trim( htmlspecialchars( $name ) ); | ||
| 271 : | $n = count( $this->_head['meta'] ); | ||
| 272 : | for ($i = 0; $i < $n; $i++) { | ||
| 273 : | if ($this->_head['meta'][$i][0] == $name) { | ||
| 274 : | $content = trim( htmlspecialchars( $content ) ); | ||
| 275 : | if ( $content ) { | ||
| 276 : | if ( !$this->_head['meta'][$i][1] ) { | ||
| 277 : | $this->_head['meta'][$i][1] = $content ; | ||
| 278 : | } else { | ||
| 279 : | $this->_head['meta'][$i][1] = $content .', '. $this->_head['meta'][$i][1]; | ||
| 280 : | } | ||
| 281 : | } | ||
| 282 : | return; | ||
| 283 : | } | ||
| 284 : | } | ||
| 285 : | $this->addMetaTag( $name , $content ); | ||
| 286 : | } | ||
| 287 : | |||
| 288 : | /** | ||
| 289 : | * @param string The value of the name attibute | ||
| 290 : | * @param string The value of the content attibute to append to the existing | ||
| 291 : | */ | ||
| 292 : | function prependMetaTag( $name, $content ) { | ||
| 293 : | $name = trim( htmlspecialchars( $name ) ); | ||
| 294 : | $n = count( $this->_head['meta'] ); | ||
| 295 : | for ($i = 0; $i < $n; $i++) { | ||
| 296 : | if ($this->_head['meta'][$i][0] == $name) { | ||
| 297 : | $content = trim( htmlspecialchars( $content ) ); | ||
| 298 : | $this->_head['meta'][$i][1] = $content . $this->_head['meta'][$i][1]; | ||
| 299 : | return; | ||
| 300 : | } | ||
| 301 : | } | ||
| 302 : | $this->addMetaTag( $name, $content ); | ||
| 303 : | } | ||
| 304 : | /** | ||
| 305 : | * Adds a custom html string to the head block | ||
| 306 : | * @param string The html to add to the head | ||
| 307 : | */ | ||
| 308 : | function addCustomHeadTag( $html ) { | ||
| 309 : | $this->_head['custom'][] = trim( $html ); | ||
| 310 : | } | ||
| 311 : | /** | ||
| 312 : | * @return string | ||
| 313 : | */ | ||
| 314 : | function getHead() { | ||
| 315 : | $head = array(); | ||
| 316 : | $head[] = '<title>' . $this->_head['title'] . '</title>'; | ||
| 317 : | foreach ($this->_head['meta'] as $meta) { | ||
| 318 : | if ($meta[2]) { | ||
| 319 : | $head[] = $meta[2]; | ||
| 320 : | } | ||
| 321 : | $head[] = '<meta name="' . $meta[0] . '" content="' . $meta[1] . '" />'; | ||
| 322 : | if ($meta[3]) { | ||
| 323 : | $head[] = $meta[3]; | ||
| 324 : | } | ||
| 325 : | } | ||
| 326 : | foreach ($this->_head['custom'] as $html) { | ||
| 327 : | $head[] = $html; | ||
| 328 : | } | ||
| 329 : | return implode( "\n", $head ) . "\n"; | ||
| 330 : | } | ||
| 331 : | /** | ||
| 332 : | * @return string | ||
| 333 : | */ | ||
| 334 : | function getPageTitle() { | ||
| 335 : | return $this->_head['title']; | ||
| 336 : | } | ||
| 337 : | |||
| 338 : | /** | ||
| 339 : | * @return string | ||
| 340 : | */ | ||
| 341 : | function getCustomPathWay() { | ||
| 342 : | return $this->_custom_pathway; | ||
| 343 : | } | ||
| 344 : | |||
| 345 : | function appendPathWay( $html ) { | ||
| 346 : | $this->_custom_pathway[] = $html; | ||
| 347 : | } | ||
| 348 : | |||
| 349 : | /** | ||
| 350 : | * Gets the value of a user state variable | ||
| 351 : | * @param string The name of the variable | ||
| 352 : | */ | ||
| 353 : | function getUserState( $var_name ) { | ||
| 354 : | if (is_array( $this->_userstate )) { | ||
| 355 : | return mosGetParam( $this->_userstate, $var_name, null ); | ||
| 356 : | } else { | ||
| 357 : | return null; | ||
| 358 : | } | ||
| 359 : | } | ||
| 360 : | /** | ||
| 361 : | * Gets the value of a user state variable | ||
| 362 : | * @param string The name of the user state variable | ||
| 363 : | * @param string The name of the variable passed in a request | ||
| 364 : | * @param string The default value for the variable if not found | ||
| 365 : | */ | ||
| 366 : | function getUserStateFromRequest( $var_name, $req_name, $var_default=null ) { | ||
| 367 : | if (is_array( $this->_userstate )) { | ||
| 368 : | if (isset( $_REQUEST[$req_name] )) { | ||
| 369 : | $this->setUserState( $var_name, $_REQUEST[$req_name] ); | ||
| 370 : | } else if (!isset( $this->_userstate[$var_name] )) { | ||
| 371 : | $this->setUserState( $var_name, $var_default ); | ||
| 372 : | } | ||
| 373 : | return $this->_userstate[$var_name]; | ||
| 374 : | } else { | ||
| 375 : | return null; | ||
| 376 : | } | ||
| 377 : | } | ||
| 378 : | /** | ||
| 379 : | * Sets the value of a user state variable | ||
| 380 : | * @param string The name of the variable | ||
| 381 : | * @param string The value of the variable | ||
| 382 : | */ | ||
| 383 : | function setUserState( $var_name, $var_value ) { | ||
| 384 : | if (is_array( $this->_userstate )) { | ||
| 385 : | $this->_userstate[$var_name] = $var_value; | ||
| 386 : | } | ||
| 387 : | } | ||
| 388 : | /** | ||
| 389 : | * Initialises the user session | ||
| 390 : | * | ||
| 391 : | * Old sessions are flushed based on the configuration value for the cookie | ||
| 392 : | * lifetime. If an existing session, then the last access time is updated. | ||
| 393 : | * If a new session, a session id is generated and a record is created in | ||
| 394 : | * the mos_sessions table. | ||
| 395 : | */ | ||
| 396 : | function initSession() { | ||
| 397 : | $session =& $this->_session; | ||
| 398 : | $session = new mosSession( $this->_db ); | ||
| 399 : | $session->purge(intval( $this->getCfg( 'lifetime' ) )); | ||
| 400 : | |||
| 401 : | $sessionCookieName = md5( 'site'.$GLOBALS['mosConfig_live_site'] ); | ||
| 402 : | csouza | 39 | |
| 403 : | root | 1 | $sessioncookie = mosGetParam( $_COOKIE, $sessionCookieName, null ); |
| 404 : | $usercookie = mosGetParam( $_COOKIE, 'usercookie', null ); | ||
| 405 : | |||
| 406 : | if ($session->load( md5( $sessioncookie . $_SERVER['REMOTE_ADDR'] ) )) { | ||
| 407 : | // Session cookie exists, update time in session table | ||
| 408 : | $session->time = time(); | ||
| 409 : | $session->update(); | ||
| 410 : | } else { | ||
| 411 : | $session->generateId(); | ||
| 412 : | $session->guest = 1; | ||
| 413 : | $session->username = ''; | ||
| 414 : | $session->time = time(); | ||
| 415 : | $session->gid = 0; | ||
| 416 : | |||
| 417 : | if (!$session->insert()) { | ||
| 418 : | die( $session->getError() ); | ||
| 419 : | } | ||
| 420 : | |||
| 421 : | setcookie( $sessionCookieName, $session->getCookie(), time() + 43200, '/' ); | ||
| 422 : | //$_COOKIE["sessioncookie"] = $session->getCookie(); | ||
| 423 : | |||
| 424 : | if ($usercookie) { | ||
| 425 : | // Remember me cookie exists. Login with usercookie info. | ||
| 426 : | $this->login($usercookie['username'], $usercookie['password']); | ||
| 427 : | } | ||
| 428 : | } | ||
| 429 : | } | ||
| 430 : | |||
| 431 : | /** | ||
| 432 : | * Login validation function | ||
| 433 : | * | ||
| 434 : | * Username and encoded password is compare to db entries in the mos_users | ||
| 435 : | * table. A successful validation updates the current session record with | ||
| 436 : | * the users details. | ||
| 437 : | */ | ||
| 438 : | function login( $username=null,$passwd=null ) { | ||
| 439 : | global $acl; | ||
| 440 : | |||
| 441 : | $usercookie = mosGetParam( $_COOKIE, 'usercookie', '' ); | ||
| 442 : | $sessioncookie = mosGetParam( $_COOKIE, 'sessioncookie', '' ); | ||
| 443 : | if (!$username || !$passwd) { | ||
| 444 : | $username = trim( mosGetParam( $_POST, 'username', '' ) ); | ||
| 445 : | $passwd = trim( mosGetParam( $_POST, 'passwd', '' ) ); | ||
| 446 : | $passwd = md5( $passwd ); | ||
| 447 : | $bypost = 1; | ||
| 448 : | } | ||
| 449 : | $remember = trim( mosGetParam( $_POST, 'remember', '' ) ); | ||
| 450 : | |||
| 451 : | if (!$username || !$passwd) { | ||
| 452 : | csouza | 39 | echo "<script> alert(\"".T_('Please complete the username and password fields.')."\"); window.history.go(-1); </script>\n"; |
| 453 : | root | 1 | exit(); |
| 454 : | } else { | ||
| 455 : | $this->_db->setQuery( "SELECT id, gid, block, usertype" | ||
| 456 : | . "\nFROM #__users" | ||
| 457 : | . "\nWHERE username='$username' AND password='$passwd'" | ||
| 458 : | ); | ||
| 459 : | $row = null; | ||
| 460 : | if ($this->_db->loadObject( $row )) { | ||
| 461 : | if ($row->block == 1) { | ||
| 462 : | csouza | 39 | echo "<script>alert(\"".T_('Your login has been blocked. Please contact the administrator.')."\"); window.history.go(-1); </script>\n"; |
| 463 : | root | 1 | exit(); |
| 464 : | } | ||
| 465 : | // fudge the group stuff | ||
| 466 : | $grp = $acl->getAroGroup( $row->id ); | ||
| 467 : | $row->gid = 1; | ||
| 468 : | |||
| 469 : | if ($acl->is_group_child_of( $grp->name, 'Registered', 'ARO' ) || | ||
| 470 : | $acl->is_group_child_of( $grp->name, 'Public Backend', 'ARO' )) { | ||
| 471 : | // fudge Authors, Editors, Publishers and Super Administrators into the Special Group | ||
| 472 : | $row->gid = 2; | ||
| 473 : | } | ||
| 474 : | $row->usertype = $grp->name; | ||
| 475 : | |||
| 476 : | $session =& $this->_session; | ||
| 477 : | $session->guest = 0; | ||
| 478 : | $session->username = $username; | ||
| 479 : | $session->userid = intval( $row->id ); | ||
| 480 : | $session->usertype = $row->usertype; | ||
| 481 : | $session->gid = intval( $row->gid ); | ||
| 482 : | |||
| 483 : | $session->update(); | ||
| 484 : | |||
| 485 : | $currentDate = date("Y-m-d\TH:i:s"); | ||
| 486 : | $query = "UPDATE #__users SET lastvisitDate='$currentDate' where id='$session->userid'"; | ||
| 487 : | $this->_db->setQuery($query); | ||
| 488 : | if (!$this->_db->query()) { | ||
| 489 : | die($this->_db->stderr(true)); | ||
| 490 : | } | ||
| 491 : | |||
| 492 : | if ($remember=="yes") { | ||
| 493 : | $lifetime = time() + 365*24*60*60; | ||
| 494 : | setcookie( "usercookie[username]", $username, $lifetime, "/" ); | ||
| 495 : | setcookie( "usercookie[password]", $passwd, $lifetime, "/" ); | ||
| 496 : | } | ||
| 497 : | //mosCache::cleanCache('com_content'); | ||
| 498 : | mosCache::cleanCache(); | ||
| 499 : | } else { | ||
| 500 : | if (isset($bypost)) { | ||
| 501 : | csouza | 39 | echo "<script>alert(\"".T_('Incorrect username or password. Please try again.')."\"); window.history.go(-1); </script>\n"; |
| 502 : | root | 1 | } else { |
| 503 : | $this->logout(); | ||
| 504 : | mosRedirect("index.php"); | ||
| 505 : | } | ||
| 506 : | exit(); | ||
| 507 : | } | ||
| 508 : | } | ||
| 509 : | } | ||
| 510 : | /** | ||
| 511 : | * User logout | ||
| 512 : | * | ||
| 513 : | * Reverts the current session record back to 'anonymous' parameters | ||
| 514 : | */ | ||
| 515 : | function logout() { | ||
| 516 : | //mosCache::cleanCache('com_content'); | ||
| 517 : | mosCache::cleanCache(); | ||
| 518 : | $session =& $this->_session; | ||
| 519 : | |||
| 520 : | $session->guest = 1; | ||
| 521 : | $session->username = ''; | ||
| 522 : | $session->userid = ''; | ||
| 523 : | $session->usertype = ''; | ||
| 524 : | $session->gid = 0; | ||
| 525 : | |||
| 526 : | $session->update(); | ||
| 527 : | |||
| 528 : | // this is daggy?? | ||
| 529 : | $lifetime = time() - 1800; | ||
| 530 : | setcookie( "usercookie[username]", " ", $lifetime, "/" ); | ||
| 531 : | setcookie( "usercookie[password]", " ", $lifetime, "/" ); | ||
| 532 : | setcookie( "usercookie", " ", $lifetime, "/" ); | ||
| 533 : | @session_destroy(); | ||
| 534 : | } | ||
| 535 : | csouza | 39 | |
| 536 : | root | 1 | /** |
| 537 : | * @return mosUser A user object with the information from the current session | ||
| 538 : | */ | ||
| 539 : | function getUser() { | ||
| 540 : | $user = new mosUser( $this->_db ); | ||
| 541 : | |||
| 542 : | $user->id = intval( $this->_session->userid ); | ||
| 543 : | $user->username = $this->_session->username; | ||
| 544 : | $user->usertype = $this->_session->usertype; | ||
| 545 : | $user->gid = intval( $this->_session->gid ); | ||
| 546 : | |||
| 547 : | return $user; | ||
| 548 : | } | ||
| 549 : | /** | ||
| 550 : | * Loads the configuration.php file and assigns values to the internal variable | ||
| 551 : | * @param string The base path from which to load the configuration file | ||
| 552 : | */ | ||
| 553 : | function _setConfig( $basePath='.' ) { | ||
| 554 : | $this->_config = new stdClass(); | ||
| 555 : | |||
| 556 : | require( $basePath . '/configuration.php' ); | ||
| 557 : | |||
| 558 : | $this->_config->offline = $mosConfig_offline; | ||
| 559 : | $this->_config->host = $mosConfig_host; | ||
| 560 : | $this->_config->user = $mosConfig_user; | ||
| 561 : | $this->_config->password = $mosConfig_password; | ||
| 562 : | $this->_config->db = $mosConfig_db; | ||
| 563 : | $this->_config->dbprefix = $mosConfig_dbprefix; | ||
| 564 : | $this->_config->lang = $mosConfig_lang; | ||
| 565 : | $this->_config->absolute_path = $mosConfig_absolute_path; | ||
| 566 : | $this->_config->live_site = $mosConfig_live_site; | ||
| 567 : | $this->_config->sitename = $mosConfig_sitename; | ||
| 568 : | $this->_config->shownoauth = $mosConfig_shownoauth; | ||
| 569 : | $this->_config->useractivation = $mosConfig_useractivation; | ||
| 570 : | $this->_config->uniquemail = $mosConfig_uniquemail; | ||
| 571 : | $this->_config->offline_message = $mosConfig_offline_message; | ||
| 572 : | $this->_config->error_message = $mosConfig_error_message; | ||
| 573 : | $this->_config->lifetime = $mosConfig_lifetime; | ||
| 574 : | $this->_config->MetaDesc = $mosConfig_MetaDesc; | ||
| 575 : | $this->_config->MetaKeys = $mosConfig_MetaKeys; | ||
| 576 : | $this->_config->debug = $mosConfig_debug; | ||
| 577 : | $this->_config->vote = $mosConfig_vote; | ||
| 578 : | $this->_config->hideAuthor = $mosConfig_hideAuthor; | ||
| 579 : | $this->_config->hideCreateDate = $mosConfig_hideCreateDate; | ||
| 580 : | $this->_config->hideModifyDate = $mosConfig_hideModifyDate; | ||
| 581 : | $this->_config->hidePdf = $mosConfig_hidePdf; | ||
| 582 : | $this->_config->hidePrint = $mosConfig_hidePrint; | ||
| 583 : | $this->_config->hideEmail = $mosConfig_hideEmail; | ||
| 584 : | $this->_config->enable_log_items = $mosConfig_enable_log_items; | ||
| 585 : | $this->_config->enable_log_searches = $mosConfig_enable_log_searches; | ||
| 586 : | $this->_config->enable_stats = $mosConfig_enable_stats; | ||
| 587 : | $this->_config->sef = $mosConfig_sef; | ||
| 588 : | $this->_config->vote = $mosConfig_vote; | ||
| 589 : | $this->_config->hideModifyDate = $mosConfig_hideModifyDate; | ||
| 590 : | $this->_config->multipage_toc = $mosConfig_multipage_toc; | ||
| 591 : | $this->_config->allowUserRegistration = $mosConfig_allowUserRegistration; | ||
| 592 : | $this->_config->error_reporting = $mosConfig_error_reporting; | ||
| 593 : | $this->_config->link_titles = $mosConfig_link_titles; | ||
| 594 : | $this->_config->list_limit = $mosConfig_list_limit; | ||
| 595 : | $this->_config->caching = $mosConfig_caching; | ||
| 596 : | $this->_config->cachepath = $mosConfig_cachepath; | ||
| 597 : | $this->_config->cachetime = $mosConfig_cachetime; | ||
| 598 : | $this->_config->mailer = $mosConfig_mailer; | ||
| 599 : | $this->_config->mailfrom = $mosConfig_mailfrom; | ||
| 600 : | $this->_config->fromname = $mosConfig_fromname; | ||
| 601 : | $this->_config->smtpauth = $mosConfig_smtpauth; | ||
| 602 : | $this->_config->smtpuser = $mosConfig_smtpuser; | ||
| 603 : | $this->_config->smtppass = $mosConfig_smtppass; | ||
| 604 : | $this->_config->smtphost = $mosConfig_smtphost; | ||
| 605 : | $this->_config->back_button = $mosConfig_back_button; | ||
| 606 : | $this->_config->item_navigation = $mosConfig_item_navigation; | ||
| 607 : | $this->_config->secret = $mosConfig_secret; | ||
| 608 : | $this->_config->pagetitles = $mosConfig_pagetitles; | ||
| 609 : | $this->_config->readmore = $mosConfig_readmore; | ||
| 610 : | $this->_config->hits = $mosConfig_hits; | ||
| 611 : | $this->_config->icons = $mosConfig_icons; | ||
| 612 : | |||
| 613 : | if (@$mosConfig_error_reporting === 0) { | ||
| 614 : | error_reporting( 0 ); | ||
| 615 : | } else if (@$mosConfig_error_reporting > 0) { | ||
| 616 : | error_reporting( $mosConfig_error_reporting ); | ||
| 617 : | } | ||
| 618 : | } | ||
| 619 : | /** | ||
| 620 : | * @param string The name of the variable (from configuration.php) | ||
| 621 : | * @return mixed The value of the configuration variable or null if not found | ||
| 622 : | */ | ||
| 623 : | function getCfg( $varname ) { | ||
| 624 : | if (isset( $this->_config->$varname )) { | ||
| 625 : | return $this->_config->$varname; | ||
| 626 : | } else { | ||
| 627 : | return null; | ||
| 628 : | } | ||
| 629 : | } | ||
| 630 : | |||
| 631 : | // TODO | ||
| 632 : | function loadConfig() { | ||
| 633 : | unset( $this->_config ); | ||
| 634 : | |||
| 635 : | $this->_db->setQuery( "SELECT name,value FROM #__config2" ); | ||
| 636 : | if (!$this->_config = $this->_db->loadObjectList( 'name' )) { | ||
| 637 : | echo $this->_db->stderr(); | ||
| 638 : | return false; | ||
| 639 : | } | ||
| 640 : | return true; | ||
| 641 : | } | ||
| 642 : | |||
| 643 : | function _setTemplate( $isAdmin=false ) { | ||
| 644 : | global $Itemid; | ||
| 645 : | $mosConfig_absolute_path = $this->getCfg( 'absolute_path' ); | ||
| 646 : | |||
| 647 : | // Default template | ||
| 648 : | $this->_db->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'" ); | ||
| 649 : | $cur_template = $this->_db->loadResult(); | ||
| 650 : | |||
| 651 : | // Assigned template | ||
| 652 : | if (isset($Itemid) && $Itemid!="" && $Itemid!=0) { | ||
| 653 : | $this->_db->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='$Itemid' LIMIT 1" ); | ||
| 654 : | $cur_template = $this->_db->loadResult() ? $this->_db->loadResult() : $cur_template; | ||
| 655 : | } | ||
| 656 : | |||
| 657 : | if ($isAdmin) { | ||
| 658 : | $this->_db->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='1' AND menuid='0'" ); | ||
| 659 : | $cur_template = $this->_db->loadResult(); | ||
| 660 : | $path = "$mosConfig_absolute_path/administrator/templates/$cur_template/index.php"; | ||
| 661 : | if (!file_exists( $path )) { | ||
| 662 : | $cur_template = 'mambo_admin'; | ||
| 663 : | } | ||
| 664 : | } else { | ||
| 665 : | // TemplateChooser Start | ||
| 666 : | $mos_user_template = mosGetParam( $_COOKIE, 'mos_user_template', '' ); | ||
| 667 : | $mos_change_template = mosGetParam( $_REQUEST, 'mos_change_template', $mos_user_template ); | ||
| 668 : | if ($mos_change_template) { | ||
| 669 : | // check that template exists in case it was deleted | ||
| 670 : | if (file_exists( "$mosConfig_absolute_path/templates/$mos_change_template/index.php" )) { | ||
| 671 : | $lifetime = 60*10; | ||
| 672 : | $cur_template = $mos_change_template; | ||
| 673 : | setcookie( "mos_user_template", "$mos_change_template", time()+$lifetime); | ||
| 674 : | } else { | ||
| 675 : | setcookie( "mos_user_template", "", time()-3600 ); | ||
| 676 : | } | ||
| 677 : | } | ||
| 678 : | // TemplateChooser End | ||
| 679 : | } | ||
| 680 : | |||
| 681 : | $this->_template = $cur_template; | ||
| 682 : | } | ||
| 683 : | |||
| 684 : | function getTemplate() { | ||
| 685 : | return $this->_template; | ||
| 686 : | } | ||
| 687 : | |||
| 688 : | /** | ||
| 689 : | * Determines the paths for including engine and menu files | ||
| 690 : | * @param string The current option used in the url | ||
| 691 : | * @param string The base path from which to load the configuration file | ||
| 692 : | */ | ||
| 693 : | function _setAdminPaths( $option, $basePath='.' ) { | ||
| 694 : | $option = strtolower( $option ); | ||
| 695 : | $this->_path = new stdClass(); | ||
| 696 : | |||
| 697 : | $prefix = substr( $option, 0, 4 ); | ||
| 698 : | if ($prefix != 'com_') { | ||
| 699 : | // ensure backward compatibility with existing links | ||
| 700 : | $name = $option; | ||
| 701 : | $option = "com_$option"; | ||
| 702 : | } else { | ||
| 703 : | $name = substr( $option, 4 ); | ||
| 704 : | } | ||
| 705 : | // components | ||
| 706 : | if (file_exists( "$basePath/templates/$this->_template/components/$name.html.php" )) { | ||
| 707 : | $this->_path->front = "$basePath/components/$option/$name.php"; | ||
| 708 : | $this->_path->front_html = "$basePath/templates/$this->_template/components/$name.html.php"; | ||
| 709 : | } else if (file_exists( "$basePath/components/$option/$name.php" )) { | ||
| 710 : | $this->_path->front = "$basePath/components/$option/$name.php"; | ||
| 711 : | $this->_path->front_html = "$basePath/components/$option/$name.html.php"; | ||
| 712 : | } | ||
| 713 : | if (file_exists( "$basePath/administrator/components/$option/admin.$name.php" )) { | ||
| 714 : | $this->_path->admin = "$basePath/administrator/components/$option/admin.$name.php"; | ||
| 715 : | $this->_path->admin_html = "$basePath/administrator/components/$option/admin.$name.html.php"; | ||
| 716 : | } | ||
| 717 : | if (file_exists( "$basePath/administrator/components/$option/toolbar.$name.php" )) { | ||
| 718 : | $this->_path->toolbar = "$basePath/administrator/components/$option/toolbar.$name.php"; | ||
| 719 : | $this->_path->toolbar_html = "$basePath/administrator/components/$option/toolbar.$name.html.php"; | ||
| 720 : | $this->_path->toolbar_default = "$basePath/administrator/includes/toolbar.html.php"; | ||
| 721 : | } | ||
| 722 : | if (file_exists( "$basePath/components/$option/$name.class.php" )) { | ||
| 723 : | $this->_path->class = "$basePath/components/$option/$name.class.php"; | ||
| 724 : | } else if (file_exists( "$basePath/administrator/components/$option/$name.class.php" )) { | ||
| 725 : | $this->_path->class = "$basePath/administrator/components/$option/$name.class.php"; | ||
| 726 : | } else if (file_exists( "$basePath/includes/$name.php" )) { | ||
| 727 : | $this->_path->class = "$basePath/includes/$name.php"; | ||
| 728 : | } | ||
| 729 : | if (file_exists("$basePath/administrator/components/$option/admin.$name.php" )) { | ||
| 730 : | $this->_path->admin = "$basePath/administrator/components/$option/admin.$name.php"; | ||
| 731 : | $this->_path->admin_html = "$basePath/administrator/components/$option/admin.$name.html.php"; | ||
| 732 : | } else { | ||
| 733 : | $this->_path->admin = "$basePath/administrator/components/com_admin/admin.admin.php"; | ||
| 734 : | $this->_path->admin_html = "$basePath/administrator/components/com_admin/admin.admin.html.php"; | ||
| 735 : | } | ||
| 736 : | } | ||
| 737 : | /** | ||
| 738 : | * Returns a stored path variable | ||
| 739 : | * | ||
| 740 : | */ | ||
| 741 : | function getPath( $varname, $option='' ) { | ||
| 742 : | global $mosConfig_absolute_path; | ||
| 743 : | if ($option) { | ||
| 744 : | $temp = $this->_path; | ||
| 745 : | $this->_setAdminPaths( $option, $this->getCfg( 'absolute_path' ) ); | ||
| 746 : | } | ||
| 747 : | $result = null; | ||
| 748 : | if (isset( $this->_path->$varname )) { | ||
| 749 : | $result = $this->_path->$varname; | ||
| 750 : | } else { | ||
| 751 : | switch ($varname) { | ||
| 752 : | case 'com_xml': | ||
| 753 : | $name = substr( $option, 4 ); | ||
| 754 : | $path = "$mosConfig_absolute_path/administrator/components/$option/$name.xml"; | ||
| 755 : | if (file_exists( $path )) { | ||
| 756 : | $result = $path; | ||
| 757 : | } else { | ||
| 758 : | $path = "$mosConfig_absolute_path/components/$option/$name.xml"; | ||
| 759 : | if (file_exists( $path )) { | ||
| 760 : | $result = $path; | ||
| 761 : | } | ||
| 762 : | } | ||
| 763 : | break; | ||
| 764 : | case 'mod0_xml': | ||
| 765 : | // Site modules | ||
| 766 : | if ($option == '') { | ||
| 767 : | $path = $mosConfig_absolute_path . "/modules/custom.xml"; | ||
| 768 : | } else { | ||
| 769 : | $path = $mosConfig_absolute_path . "/modules/$option.xml"; | ||
| 770 : | } | ||
| 771 : | if (file_exists( $path )) { | ||
| 772 : | $result = $path; | ||
| 773 : | } | ||
| 774 : | break; | ||
| 775 : | case 'mod1_xml': | ||
| 776 : | // admin modules | ||
| 777 : | if ($option == '') { | ||
| 778 : | $path = $mosConfig_absolute_path . '/administrator/modules/custom.xml'; | ||
| 779 : | } else { | ||
| 780 : | $path = $mosConfig_absolute_path . "/administrator/modules/$option.xml"; | ||
| 781 : | } | ||
| 782 : | if (file_exists( $path )) { | ||
| 783 : | $result = $path; | ||
| 784 : | } | ||
| 785 : | break; | ||
| 786 : | case 'bot_xml': | ||
| 787 : | // Site mambots | ||
| 788 : | $path = $mosConfig_absolute_path . "/mambots/$option.xml"; | ||
| 789 : | if (file_exists( $path )) { | ||
| 790 : | $result = $path; | ||
| 791 : | } | ||
| 792 : | break; | ||
| 793 : | case 'menu_xml': | ||
| 794 : | $path = $mosConfig_absolute_path . "/administrator/components/com_menus/$option/$option.xml"; | ||
| 795 : | if (file_exists( $path )) { | ||
| 796 : | $result = $path; | ||
| 797 : | } | ||
| 798 : | break; | ||
| 799 : | case 'installer_html': | ||
| 800 : | $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$option/$option.html.php"; | ||
| 801 : | if (file_exists( $path )) { | ||
| 802 : | $result = $path; | ||
| 803 : | } | ||
| 804 : | break; | ||
| 805 : | case 'installer_class': | ||
| 806 : | $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$option/$option.class.php"; | ||
| 807 : | if (file_exists( $path )) { | ||
| 808 : | $result = $path; | ||
| 809 : | } | ||
| 810 : | break; | ||
| 811 : | } | ||
| 812 : | } | ||
| 813 : | if ($option) { | ||
| 814 : | $this->_path = $temp; | ||
| 815 : | } | ||
| 816 : | return $result; | ||
| 817 : | } | ||
| 818 : | /** | ||
| 819 : | * Detects a 'visit' | ||
| 820 : | * | ||
| 821 : | * This function updates the agent and domain table hits for a particular | ||
| 822 : | * visitor. The user agent is recorded/incremented if this is the first visit. | ||
| 823 : | * A cookie is set to mark the first visit. | ||
| 824 : | */ | ||
| 825 : | function detect() { | ||
| 826 : | global $mosConfig_enable_stats; | ||
| 827 : | if ($mosConfig_enable_stats == 1) { | ||
| 828 : | if (mosGetParam( $_COOKIE, 'mosvisitor', 0 )) { | ||
| 829 : | return; | ||
| 830 : | } | ||
| 831 : | setcookie( "mosvisitor", "1" ); | ||
| 832 : | |||
| 833 : | if (phpversion() <= "4.2.1") { | ||
| 834 : | $agent = getenv( "HTTP_USER_AGENT" ); | ||
| 835 : | $domain = gethostbyaddr( getenv( "REMOTE_ADDR" ) ); | ||
| 836 : | } else { | ||
| 837 : | $agent = $_SERVER['HTTP_USER_AGENT']; | ||
| 838 : | $domain = gethostbyaddr( $_SERVER['REMOTE_ADDR'] ); | ||
| 839 : | } | ||
| 840 : | |||
| 841 : | $browser = mosGetBrowser( $agent ); | ||
| 842 : | |||
| 843 : | $this->_db->setQuery( "SELECT count(*) FROM #__stats_agents WHERE agent='$browser' AND type='0'" ); | ||
| 844 : | if ($this->_db->loadResult()) { | ||
| 845 : | $this->_db->setQuery( "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$browser' AND type='0'" ); | ||
| 846 : | } else { | ||
| 847 : | $this->_db->setQuery( "INSERT INTO #__stats_agents (agent,type) VALUES ('$browser','0')" ); | ||
| 848 : | } | ||
| 849 : | $this->_db->query(); | ||
| 850 : | |||
| 851 : | $os = mosGetOS( $agent ); | ||
| 852 : | |||
| 853 : | $this->_db->setQuery( "SELECT count(*) FROM #__stats_agents WHERE agent='$os' AND type='1'" ); | ||
| 854 : | if ($this->_db->loadResult()) { | ||
| 855 : | $this->_db->setQuery( "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$os' AND type='1'" ); | ||
| 856 : | } else { | ||
| 857 : | $this->_db->setQuery( "INSERT INTO #__stats_agents (agent,type) VALUES ('$os','1')" ); | ||
| 858 : | } | ||
| 859 : | $this->_db->query(); | ||
| 860 : | |||
| 861 : | // tease out the last element of the domain | ||
| 862 : | $tldomain = split( "\.", $domain ); | ||
| 863 : | $tldomain = $tldomain[count( $tldomain )-1]; | ||
| 864 : | |||
| 865 : | if (is_numeric( $tldomain )) { | ||
| 866 : | $tldomain = "Unknown"; | ||
| 867 : | } | ||
| 868 : | |||
| 869 : | $this->_db->setQuery( "SELECT count(*) FROM #__stats_agents WHERE agent='$tldomain' AND type='2'" ); | ||
| 870 : | if ($this->_db->loadResult()) { | ||
| 871 : | $this->_db->setQuery( "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$tldomain' AND type='2'" ); | ||
| 872 : | } else { | ||
| 873 : | $this->_db->setQuery( "INSERT INTO #__stats_agents (agent,type) VALUES ('$tldomain','2')" ); | ||
| 874 : | } | ||
| 875 : | $this->_db->query(); | ||
| 876 : | } | ||
| 877 : | } | ||
| 878 : | |||
| 879 : | /** | ||
| 880 : | * @return correct Itemid for Content Item | ||
| 881 : | */ | ||
| 882 : | function getItemid( $id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1 ) { | ||
| 883 : | global $Itemid; | ||
| 884 : | |||
| 885 : | $_Itemid = ''; | ||
| 886 : | if ($_Itemid == '' && $typed) { | ||
| 887 : | // Search for typed link | ||
| 888 : | $this->_db->setQuery( "SELECT id " | ||
| 889 : | ."\nFROM #__menu " | ||
| 890 : | ."\nWHERE type='content_typed' AND published='1' AND link='index.php?option=com_content&task=view&id=$id'" ); | ||
| 891 : | $_Itemid = $this->_db->loadResult(); | ||
| 892 : | } | ||
| 893 : | |||
| 894 : | if ($_Itemid == '' && $link) { | ||
| 895 : | // Search for item link | ||
| 896 : | $this->_db->setQuery( "SELECT id " | ||
| 897 : | ."\nFROM #__menu " | ||
| 898 : | ."\nWHERE type='content_item_link' AND published='1' AND link='index.php?option=com_content&task=view&id=$id'" ); | ||
| 899 : | $_Itemid = $this->_db->loadResult(); | ||
| 900 : | } | ||
| 901 : | |||
| 902 : | if ($_Itemid == '') { | ||
| 903 : | // Search in sections | ||
| 904 : | $this->_db->setQuery( "SELECT m.id " | ||
| 905 : | ."\nFROM #__content AS i" | ||
| 906 : | ."\nLEFT JOIN #__sections AS s ON i.sectionid=s.id" | ||
| 907 : | ."\nLEFT JOIN #__menu AS m ON m.componentid=s.id " | ||
| 908 : | ."\nWHERE m.type='content_section' AND m.published='1' AND i.id=".$id ); | ||
| 909 : | $_Itemid = $this->_db->loadResult(); | ||
| 910 : | } | ||
| 911 : | |||
| 912 : | if ($_Itemid == '' && $bs) { | ||
| 913 : | // Search in specific blog section | ||
| 914 : | $this->_db->setQuery( "SELECT m.id " | ||
| 915 : | ."\nFROM #__content AS i" | ||
| 916 : | ."\nLEFT JOIN #__sections AS s ON i.sectionid=s.id" | ||
| 917 : | ."\nLEFT JOIN #__menu AS m ON m.componentid=s.id " | ||
| 918 : | ."\nWHERE m.type='content_blog_section' AND m.published='1' AND i.id=".$id ); | ||
| 919 : | $_Itemid = $this->_db->loadResult(); | ||
| 920 : | } | ||
| 921 : | |||
| 922 : | if ($_Itemid == '' && $bc) { | ||
| 923 : | // Search in specific blog category | ||
| 924 : | $this->_db->setQuery( "SELECT m.id " | ||
| 925 : | ."\nFROM #__content AS i" | ||
| 926 : | ."\nLEFT JOIN #__categories AS c ON i.catid=c.id" | ||
| 927 : | ."\nLEFT JOIN #__menu AS m ON m.componentid=c.id " | ||
| 928 : | ."\nWHERE m.type='content_blog_category' AND m.published='1' AND i.id=".$id ); | ||
| 929 : | $_Itemid = $this->_db->loadResult(); | ||
| 930 : | } | ||
| 931 : | |||
| 932 : | if ($_Itemid == '' && $gbs) { | ||
| 933 : | // Search in global blog section | ||
| 934 : | $this->_db->setQuery( "SELECT id " | ||
| 935 : | ."\nFROM #__menu " | ||
| 936 : | ."\nWHERE type='content_blog_section' AND published='1' AND componentid=0" ); | ||
| 937 : | $_Itemid = $this->_db->loadResult(); | ||
| 938 : | } | ||
| 939 : | /* | ||
| 940 : | if ($_Itemid == '') { | ||
| 941 : | // Search in global blog category | ||
| 942 : | $this->_db->setQuery( "SELECT id " | ||
| 943 : | ."\nFROM #__menu " | ||
| 944 : | ."\nWHERE type='content_blog_category' AND published='1' AND componentid=0" ); | ||
| 945 : | $_Itemid = $this->_db->loadResult(); | ||
| 946 : | } | ||
| 947 : | */ | ||
| 948 : | if ($_Itemid != "") { | ||
| 949 : | return $_Itemid; | ||
| 950 : | } else { | ||
| 951 : | return $Itemid; | ||
| 952 : | } | ||
| 953 : | } | ||
| 954 : | |||
| 955 : | /** | ||
| 956 : | * @return number of Published Blog Sections | ||
| 957 : | */ | ||
| 958 : | function getBlogSectionCount( ) { | ||
| 959 : | $query = "SELECT COUNT( m.id )" | ||
| 960 : | ."\n FROM #__content AS i" | ||
| 961 : | ."\n LEFT JOIN #__sections AS s ON i.sectionid=s.id" | ||
| 962 : | ."\n LEFT JOIN #__menu AS m ON m.componentid=s.id " | ||
| 963 : | ."\n WHERE m.type='content_blog_section'" | ||
| 964 : | ."\n AND m.published='1'" | ||
| 965 : | ; | ||
| 966 : | $this->_db->setQuery( $query ); | ||
| 967 : | $count = $this->_db->loadResult(); | ||
| 968 : | return $count; | ||
| 969 : | } | ||
| 970 : | |||
| 971 : | /** | ||
| 972 : | * @return number of Published Blog Categories | ||
| 973 : | */ | ||
| 974 : | function getBlogCategoryCount( ) { | ||
| 975 : | $query = "SELECT COUNT( m.id )" | ||
| 976 : | . "\n FROM #__content AS i" | ||
| 977 : | . "\n LEFT JOIN #__categories AS c ON i.catid=c.id" | ||
| 978 : | . "\n LEFT JOIN #__menu AS m ON m.componentid=c.id " | ||
| 979 : | . "\n WHERE m.type='content_blog_category'" | ||
| 980 : | . "\n AND m.published='1'" | ||
| 981 : | ; | ||
| 982 : | $this->_db->setQuery( $query ); | ||
| 983 : | $count = $this->_db->loadResult(); | ||
| 984 : | return $count; | ||
| 985 : | } | ||
| 986 : | |||
| 987 : | /** | ||
| 988 : | * @return number of Published Global Blog Sections | ||
| 989 : | */ | ||
| 990 : | function getGlobalBlogSectionCount( ) { | ||
| 991 : | $query = "SELECT COUNT( id )" | ||
| 992 : | ."\n FROM #__menu " | ||
| 993 : | ."\n WHERE type='content_blog_section'" | ||
| 994 : | ."\n AND published='1'" | ||
| 995 : | ."\n AND componentid=0" | ||
| 996 : | ; | ||
| 997 : | $this->_db->setQuery( $query ); | ||
| 998 : | $count = $this->_db->loadResult(); | ||
| 999 : | return $count; | ||
| 1000 : | } | ||
| 1001 : | |||
| 1002 : | /** | ||
| 1003 : | * @return number of Static Content | ||
| 1004 : | */ | ||
| 1005 : | function getStaticContentCount( ) { | ||
| 1006 : | $query = "SELECT COUNT( id )" | ||
| 1007 : | ."\n FROM #__menu " | ||
| 1008 : | ."\n WHERE type='content_typed'" | ||
| 1009 : | ."\n AND published='1'" | ||
| 1010 : | ; | ||
| 1011 : | $this->_db->setQuery( $query ); | ||
| 1012 : | $count = $this->_db->loadResult(); | ||
| 1013 : | return $count; | ||
| 1014 : | } | ||
| 1015 : | |||
| 1016 : | /** | ||
| 1017 : | * @return number of Content Item Links | ||
| 1018 : | */ | ||
| 1019 : | function getContentItemLinkCount( ) { | ||
| 1020 : | $query = "SELECT COUNT( id )" | ||
| 1021 : | ."\n FROM #__menu " | ||
| 1022 : | ."\n WHERE type='content_item_link'" | ||
| 1023 : | ."\n AND published='1'" | ||
| 1024 : | ; | ||
| 1025 : | $this->_db->setQuery( $query ); | ||
| 1026 : | $count = $this->_db->loadResult(); | ||
| 1027 : | return $count; | ||
| 1028 : | } | ||
| 1029 : | } | ||
| 1030 : | |||
| 1031 : | /** | ||
| 1032 : | * Component database table class | ||
| 1033 : | * @package Mambo | ||
| 1034 : | */ | ||
| 1035 : | class mosComponent extends mosDBTable { | ||
| 1036 : | /** @var int Primary key */ | ||
| 1037 : | var $id=null; | ||
| 1038 : | /** @var string */ | ||
| 1039 : | var $name=null; | ||
| 1040 : | /** @var string */ | ||
| 1041 : | var $link=null; | ||
| 1042 : | /** @var int */ | ||
| 1043 : | var $menuid=null; | ||
| 1044 : | /** @var int */ | ||
| 1045 : | var $parent=null; | ||
| 1046 : | /** @var string */ | ||
| 1047 : | var $admin_menu_link=null; | ||
| 1048 : | /** @var string */ | ||
| 1049 : | var $admin_menu_alt=null; | ||
| 1050 : | /** @var string */ | ||
| 1051 : | var $option=null; | ||
| 1052 : | /** @var string */ | ||
| 1053 : | var $ordering=null; | ||
| 1054 : | /** @var string */ | ||
| 1055 : | var $admin_menu_img=null; | ||
| 1056 : | /** @var int */ | ||
| 1057 : | var $iscore=null; | ||
| 1058 : | /** @var string */ | ||
| 1059 : | var $params=null; | ||
| 1060 : | |||
| 1061 : | /** | ||
| 1062 : | * @param database A database connector object | ||
| 1063 : | */ | ||
| 1064 : | function mosComponent( &$db ) { | ||
| 1065 : | $this->mosDBTable( '#__components', 'id', $db ); | ||
| 1066 : | } | ||
| 1067 : | } | ||
| 1068 : | |||
| 1069 : | /** | ||
| 1070 : | * Utility class for all HTML drawing classes | ||
| 1071 : | * @package Mambo | ||
| 1072 : | */ | ||
| 1073 : | class mosHTML { | ||
| 1074 : | function makeOption( $value, $text='' ) { | ||
| 1075 : | $obj = new stdClass; | ||
| 1076 : | $obj->value = $value; | ||
| 1077 : | $obj->text = trim( $text ) ? $text : $value; | ||
| 1078 : | return $obj; | ||
| 1079 : | } | ||
| 1080 : | |||
| 1081 : | function writableCell( $folder ) { | ||
| 1082 : | |||
| 1083 : | echo '<tr>'; | ||
| 1084 : | echo '<td class="item">' . $folder . '/</td>'; | ||
| 1085 : | echo '<td align="left">'; | ||
| 1086 : | csouza | 39 | echo is_writable( "../$folder" ) ? '<b><font color="green">'.T_('Writeable').'</font></b>' : '<b><font color="red">'.T_('Unwriteable').'</font></b>' . '</td>'; |
| 1087 : | root | 1 | echo '</tr>'; |
| 1088 : | } | ||
| 1089 : | |||
| 1090 : | /** | ||
| 1091 : | * Generates an HTML select list | ||
| 1092 : | * @param array An array of objects | ||
| 1093 : | * @param string The value of the HTML name attribute | ||
| 1094 : | * @param string Additional HTML attributes for the <select> tag | ||
| 1095 : | * @param string The name of the object variable for the option value | ||
| 1096 : | * @param string The name of the object variable for the option text | ||
| 1097 : | * @param mixed The key that is selected | ||
| 1098 : | * @returns string HTML for the select list | ||
| 1099 : | */ | ||
| 1100 : | function selectList( &$arr, $tag_name, $tag_attribs, $key, $text, $selected=NULL ) { | ||
| 1101 : | reset( $arr ); | ||
| 1102 : | $html = "\n<select name=\"$tag_name\" $tag_attribs>"; | ||
| 1103 : | for ($i=0, $n=count( $arr ); $i < $n; $i++ ) { | ||
| 1104 : | $k = $arr[$i]->$key; | ||
| 1105 : | $t = $arr[$i]->$text; | ||
| 1106 : | $id = @$arr[$i]->id; | ||
| 1107 : | |||
| 1108 : | $extra = ''; | ||
| 1109 : | $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : ''; | ||
| 1110 : | if (is_array( $selected )) { | ||
| 1111 : | foreach ($selected as $obj) { | ||
| 1112 : | $k2 = $obj->$key; | ||
| 1113 : | if ($k == $k2) { | ||
| 1114 : | $extra .= " selected=\"selected\""; | ||
| 1115 : | break; | ||
| 1116 : | } | ||
| 1117 : | } | ||
| 1118 : | } else { | ||
| 1119 : | $extra .= ($k == $selected ? " selected=\"selected\"" : ''); | ||
| 1120 : | } | ||
| 1121 : | $html .= "\n\t<option value=\"".$k."\"$extra>" . $t . "</option>"; | ||
| 1122 : | } | ||
| 1123 : | $html .= "\n</select>\n"; | ||
| 1124 : | return $html; | ||
| 1125 : | } | ||
| 1126 : | |||
| 1127 : | /** | ||
| 1128 : | * Writes a select list of integers | ||
| 1129 : | * @param int The start integer | ||
| 1130 : | * @param int The end integer | ||
| 1131 : | * @param int The increment | ||
| 1132 : | * @param string The value of the HTML name attribute | ||
| 1133 : | * @param string Additional HTML attributes for the <select> tag | ||
| 1134 : | * @param mixed The key that is selected | ||
| 1135 : | * @param string The printf format to be applied to the number | ||
| 1136 : | * @returns string HTML for the select list | ||
| 1137 : | */ | ||
| 1138 : | function integerSelectList( $start, $end, $inc, $tag_name, $tag_attribs, $selected, $format="" ) { | ||
| 1139 : | $start = intval( $start ); | ||
| 1140 : | $end = intval( $end ); | ||
| 1141 : | $inc = intval( $inc ); | ||
| 1142 : | $arr = array(); | ||
| 1143 : | for ($i=$start; $i <= $end; $i+=$inc) { | ||
| 1144 : | $fi = $format ? sprintf( "$format", $i ) : "$i"; | ||
| 1145 : | $arr[] = mosHTML::makeOption( $fi, $fi ); | ||
| 1146 : | } | ||
| 1147 : | |||
| 1148 : | return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected ); | ||
| 1149 : | } | ||
| 1150 : | |||
| 1151 : | /** | ||
| 1152 : | * Writes a select list of month names based on Language settings | ||
| 1153 : | * @param string The value of the HTML name attribute | ||
| 1154 : | * @param string Additional HTML attributes for the <select> tag | ||
| 1155 : | * @param mixed The key that is selected | ||
| 1156 : | * @returns string HTML for the select list values | ||
| 1157 : | */ | ||
| 1158 : | function monthSelectList( $tag_name, $tag_attribs, $selected ) { | ||
| 1159 : | $arr = array( | ||
| 1160 : | csouza | 39 | mosHTML::makeOption( '01', T_('January') ), |
| 1161 : | mosHTML::makeOption( '02', T_('February') ), | ||
| 1162 : | mosHTML::makeOption( '03', T_('March') ), | ||
| 1163 : | mosHTML::makeOption( '04', T_('April') ), | ||
| 1164 : | mosHTML::makeOption( '05', T_('May') ), | ||
| 1165 : | mosHTML::makeOption( '06', T_('June') ), | ||
| 1166 : | mosHTML::makeOption( '07', T_('July') ), | ||
| 1167 : | mosHTML::makeOption( '08', T_('August') ), | ||
| 1168 : | mosHTML::makeOption( '09', T_('September') ), | ||
| 1169 : | mosHTML::makeOption( '10', T_('October') ), | ||
| 1170 : | mosHTML::makeOption( '11', T_('November') ), | ||
| 1171 : | mosHTML::makeOption( '12', T_('December') ) | ||
| 1172 : | root | 1 | ); |
| 1173 : | |||
| 1174 : | return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected ); | ||
| 1175 : | } | ||
| 1176 : | |||
| 1177 : | /** | ||
| 1178 : | * Generates an HTML select list from a tree based query list | ||
| 1179 : | * @param array Source array with id and parent fields | ||
| 1180 : | * @param array The id of the current list item | ||
| 1181 : | * @param array Target array. May be an empty array. | ||
| 1182 : | * @param array An array of objects | ||
| 1183 : | * @param string The value of the HTML name attribute | ||
| 1184 : | * @param string Additional HTML attributes for the <select> tag | ||
| 1185 : | * @param string The name of the object variable for the option value | ||
| 1186 : | * @param string The name of the object variable for the option text | ||
| 1187 : | * @param mixed The key that is selected | ||
| 1188 : | * @returns string HTML for the select list | ||
| 1189 : | */ | ||
| 1190 : | function treeSelectList( &$src_list, $src_id, $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected ) { | ||
| 1191 : | |||
| 1192 : | // establish the hierarchy of the menu | ||
| 1193 : | $children = array(); | ||
| 1194 : | // first pass - collect children | ||
| 1195 : | foreach ($src_list as $v ) { | ||
| 1196 : | $pt = $v->parent; | ||
| 1197 : | $list = @$children[$pt] ? $children[$pt] : array(); | ||
| 1198 : | array_push( $list, $v ); | ||
| 1199 : | $children[$pt] = $list; | ||
| 1200 : | } | ||
| 1201 : | // second pass - get an indent list of the items | ||
| 1202 : | $ilist = mosTreeRecurse( 0, '', array(), $children ); | ||
| 1203 : | |||
| 1204 : | // assemble menu items to the array | ||
| 1205 : | $this_treename = ''; | ||
| 1206 : | foreach ($ilist as $item) { | ||
| 1207 : | if ($this_treename) { | ||
| 1208 : | if ($item->id != $src_id && strpos( $item->treename, $this_treename ) === false) { | ||
| 1209 : | $tgt_list[] = mosHTML::makeOption( $item->id, $item->treename ); | ||
| 1210 : | } | ||
| 1211 : | } else { | ||
| 1212 : | if ($item->id != $src_id) { | ||
| 1213 : | $tgt_list[] = mosHTML::makeOption( $item->id, $item->treename ); | ||
| 1214 : | } else { | ||
| 1215 : | $this_treename = "$item->treename/"; | ||
| 1216 : | } | ||
| 1217 : | } | ||
| 1218 : | } | ||
| 1219 : | // build the html select list | ||
| 1220 : | return mosHTML::selectList( $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected ); | ||
| 1221 : | } | ||
| 1222 : | |||
| 1223 : | /** | ||
| 1224 : | * Writes a yes/no select list | ||
| 1225 : | * @param string The value of the HTML name attribute | ||
| 1226 : | * @param string Additional HTML attributes for the <select> tag | ||
| 1227 : | * @param mixed The key that is selected | ||
| 1228 : | * @returns string HTML for the select list values | ||
| 1229 : | */ | ||
| 1230 : | csouza | 39 | function yesnoSelectList( $tag_name, $tag_attribs, $selected, $yes=null, $no=null ) { |
| 1231 : | // modified by csouza for gettext localization | ||
| 1232 : | if (is_null($yes)) $yes = T_('Yes'); | ||
| 1233 : | if (is_null($yes)) $no = T_('No'); | ||
| 1234 : | |||
| 1235 : | $arr = array( | ||
| 1236 : | root | 1 | mosHTML::makeOption( '0', $no ), |
| 1237 : | mosHTML::makeOption( '1', $yes ), | ||
| 1238 : | ); | ||
| 1239 : | |||
| 1240 : | return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected ); | ||
| 1241 : | } | ||
| 1242 : | |||
| 1243 : | /** | ||
| 1244 : | * Generates an HTML radio list | ||
| 1245 : | * @param array An array of objects | ||
| 1246 : | * @param string The value of the HTML name attribute | ||
| 1247 : | * @param string Additional HTML attributes for the <select> tag | ||
| 1248 : | * @param mixed The key that is selected | ||
| 1249 : | * @param string The name of the object variable for the option value | ||
| 1250 : | * @param string The name of the object variable for the option text | ||
| 1251 : | * @returns string HTML for the select list | ||
| 1252 : | */ | ||
| 1253 : | function radioList( &$arr, $tag_name, $tag_attribs, $selected=null, $key='value', $text='text' ) { | ||
| 1254 : | reset( $arr ); | ||
| 1255 : | $html = ""; | ||
| 1256 : | for ($i=0, $n=count( $arr ); $i < $n; $i++ ) { | ||
| 1257 : | $k = $arr[$i]->$key; | ||
| 1258 : | $t = $arr[$i]->$text; | ||
| 1259 : | $id = @$arr[$i]->id; | ||
| 1260 : | |||
| 1261 : | $extra = ''; | ||
| 1262 : | $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : ''; | ||
| 1263 : | if (is_array( $selected )) { | ||
| 1264 : | foreach ($selected as $obj) { | ||
| 1265 : | $k2 = $obj->$key; | ||
| 1266 : | if ($k == $k2) { | ||
| 1267 : | $extra .= " selected=\"selected\""; | ||
| 1268 : | break; | ||
| 1269 : | } | ||
| 1270 : | } | ||
| 1271 : | } else { | ||
| 1272 : | $extra .= ($k == $selected ? " checked=\"checked\"" : ''); | ||
| 1273 : | } | ||
| 1274 : | $html .= "\n\t<input type=\"radio\" name=\"$tag_name\" value=\"".$k."\"$extra $tag_attribs />" . $t; | ||
| 1275 : | } | ||
| 1276 : | $html .= "\n"; | ||
| 1277 : | return $html; | ||
| 1278 : | } | ||
| 1279 : | |||
| 1280 : | /** | ||
| 1281 : | * Writes a yes/no radio list | ||
| 1282 : | * @param string The value of the HTML name attribute | ||
| 1283 : | * @param string Additional HTML attributes for the <select> tag | ||
| 1284 : | * @param mixed The key that is selected | ||
| 1285 : | * @returns string HTML for the radio list | ||
| 1286 : | */ | ||
| 1287 : | csouza | 39 | function yesnoRadioList( $tag_name, $tag_attribs, $selected, $yes=null, $no=null ) { |
| 1288 : | // modified by csouza for gettext localization | ||
| 1289 : | if (is_null($yes)) $yes = T_('Yes'); | ||
| 1290 : | if (is_null($yes)) $no = T_('No'); | ||
| 1291 : | |||
| 1292 : | $arr = array( | ||
| 1293 : | root | 1 | mosHTML::makeOption( '0', $no, true ), |
| 1294 : | mosHTML::makeOption( '1', $yes, true ) | ||
| 1295 : | ); | ||
| 1296 : | return mosHTML::radioList( $arr, $tag_name, $tag_attribs, $selected ); | ||
| 1297 : | } | ||
| 1298 : | |||
| 1299 : | /** | ||
| 1300 : | * @param int The row index | ||
| 1301 : | * @param int The record id | ||
| 1302 : | * @param boolean | ||
| 1303 : | * @param string The name of the form element | ||
| 1304 : | * @return string | ||
| 1305 : | */ | ||
| 1306 : | function idBox( $rowNum, $recId, $checkedOut=false, $name='cid' ) { | ||
| 1307 : | if ( $checkedOut ) { | ||
| 1308 : | return ''; | ||
| 1309 : | } else { | ||
| 1310 : | return '<input type="checkbox" id="cb'.$rowNum.'" name="'.$name.'[]" value="'.$recId.'" onclick="isChecked(this.checked);" />'; | ||
| 1311 : | } | ||
| 1312 : | } | ||
| 1313 : | |||
| 1314 : | function sortIcon( $base_href, $field, $state='none' ) { | ||
| 1315 : | global $mosConfig_live_site; | ||
| 1316 : | |||
| 1317 : | $alts = array( | ||
| 1318 : | csouza | 39 | 'none' => T_('No Sorting'), |
| 1319 : | 'asc' => T_('Sort Ascending'), | ||
| 1320 : | 'desc' => T_('Sort Descending'), | ||
| 1321 : | root | 1 | ); |
| 1322 : | $next_state = 'asc'; | ||
| 1323 : | if ($state == 'asc') { | ||
| 1324 : | $next_state = 'desc'; | ||
| 1325 : | } else if ($state == 'desc') { | ||
| 1326 : | $next_state = 'none'; | ||
| 1327 : | } | ||
| 1328 : | |||
| 1329 : | $html = "<a href=\"$base_href&field=$field&order=$next_state\">" | ||
| 1330 : | . "<img src=\"$mosConfig_live_site/images/M_images/sort_$state.png\" width=\"12\" height=\"12\" border=\"0\" alt=\"{$alts[$next_state]}\" />" | ||
| 1331 : | . "</a>"; | ||
| 1332 : | return $html; | ||
| 1333 : | } | ||
| 1334 : | |||
| 1335 : | /** | ||
| 1336 : | * Writes Close Button | ||
| 1337 : | */ | ||
| 1338 : | function CloseButton ( &$params, $hide_js=NULL ) { | ||
| 1339 : | // displays close button in Pop-up window | ||
| 1340 : | if ( $params->get( 'popup' ) && !$hide_js ) { | ||
| 1341 : | ?> | ||
| 1342 : | <div align="center" style="margin-top: 30px; margin-bottom: 30px;"> | ||
| 1343 : | <a href='javascript:window.close();'> | ||
| 1344 : | <span class="small"> | ||
| 1345 : | csouza | 39 | <?php echo T_('Close Window');?> |
| 1346 : | root | 1 | </span> |
| 1347 : | </a> | ||
| 1348 : | </div> | ||
| 1349 : | <?php | ||
| 1350 : | } | ||
| 1351 : | } | ||
| 1352 : | |||
| 1353 : | /** | ||
| 1354 : | * Writes Back Button | ||
| 1355 : | */ | ||
| 1356 : | function BackButton ( &$params, $hide_js=NULL ) { | ||
| 1357 : | // Back Button | ||
| 1358 : | if ( $params->get( 'back_button' ) && !$params->get( 'popup' ) && !$hide_js) { | ||
| 1359 : | ?> | ||
| 1360 : | <div class="back_button"> | ||
| 1361 : | <a href='javascript:history.go(-1)'> | ||
| 1362 : | csouza | 39 | <?php echo '['.T_('Back').']'; ?> |
| 1363 : | root | 1 | </a> |
| 1364 : | </div> | ||
| 1365 : | <?php | ||
| 1366 : | } | ||
| 1367 : | } | ||
| 1368 : | |||
| 1369 : | /** | ||
| 1370 : | * Cleans text of all formating and scripting code | ||
| 1371 : | */ | ||
| 1372 : | function cleanText ( &$text ) { | ||
| 1373 : | $text = preg_replace( "'<script[^>]*>.*?</script>'si", '', $text ); | ||
| 1374 : | $text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text ); | ||
| 1375 : | $text = preg_replace( '/<!--.+?-->/', '', $text ); | ||
| 1376 : | $text = preg_replace( '/{.+?}/', '', $text ); | ||
| 1377 : | $text = preg_replace( '/ /', ' ', $text ); | ||
| 1378 : | $text = preg_replace( '/&/', ' ', $text ); | ||
| 1379 : | $text = preg_replace( '/"/', ' ', $text ); | ||
| 1380 : | $text = strip_tags( $text ); | ||
| 1381 : | $text = htmlspecialchars( $text ); | ||
| 1382 : | return $text; | ||
| 1383 : | } | ||
| 1384 : | |||
| 1385 : | /** | ||
| 1386 : | * Writes Print icon | ||
| 1387 : | */ | ||
| 1388 : | function PrintIcon( &$row, &$params, $hide_js, $link, $status=NULL ) { | ||
| 1389 : | global $mosConfig_live_site, $mosConfig_absolute_path, $cur_template, $Itemid; | ||
| 1390 : | if ( $params->get( 'print' ) && !$hide_js ) { | ||
| 1391 : | // use default settings if none declared | ||
| 1392 : | if ( !$status ) { | ||
| 1393 : | $status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no'; | ||
| 1394 : | } | ||
| 1395 : | |||
| 1396 : | // checks template image directory for image, if non found default are loaded | ||
| 1397 : | if ( $params->get( 'icons' ) ) { | ||
| 1398 : | csouza | 39 | $image = mosAdminMenus::ImageCheck( 'printButton.png', '/images/M_images/', NULL, NULL, T_('Print') ); |
| 1399 : | root | 1 | } else { |
| 1400 : | csouza | 39 | $image = _ICON_SEP .' '. T_('Print'). ' '. _ICON_SEP; |
| 1401 : | root | 1 | } |
| 1402 : | |||
| 1403 : | if ( $params->get( 'popup' ) && !$hide_js ) { | ||
| 1404 : | // Print Preview button - used when viewing page | ||
| 1405 : | ?> | ||
| 1406 : | <td align="right" width="100%" class="buttonheading"> | ||
| 1407 : | csouza | 39 | <a href="#" onclick="javascript:window.print(); return false" title="<?php echo T_('Print');?>"> |
| 1408 : | root | 1 | <?php echo $image;?> |
| 1409 : | </a> | ||
| 1410 : | </td> | ||
| 1411 : | <?php | ||
| 1412 : | } else { | ||
| 1413 : | // Print Button - used in pop-up window | ||
| 1414 : | ?> | ||
| 1415 : | <td align="right" width="100%" class="buttonheading"> | ||
| 1416 : | csouza | 39 | <a href="javascript:void window.open('<?php echo $link; ?>', 'win2', '<?php echo $status; ?>');" title="<?php echo T_('Print');?>"> |
| 1417 : | root | 1 | <?php echo $image;?> |
| 1418 : | </a> | ||
| 1419 : | </td> | ||
| 1420 : | <?php | ||
| 1421 : | } | ||
| 1422 : | } | ||
| 1423 : | } | ||
| 1424 : | |||
| 1425 : | /** | ||
| 1426 : | * simple Javascript Cloaking | ||
| 1427 : | * email cloacking | ||
| 1428 : | * by default replaces an email with a mailto link with email cloacked | ||
| 1429 : | */ | ||
| 1430 : | function emailCloaking( $mail, $mailto=1, $text='', $email=1 ) { | ||
| 1431 : | // convert text | ||
| 1432 : | $mail = mosHTML::encoding_converter( $mail ); | ||
| 1433 : | // split email by @ symbol | ||
| 1434 : | $mail = explode( '@', $mail ); | ||
| 1435 : | $mail_parts = explode( '.', $mail[1] ); | ||
| 1436 : | // random number | ||
| 1437 : | $rand = rand( 1, 100000 ); | ||
| 1438 : | |||
| 1439 : | $replacement = "\n<script language='JavaScript' type='text/javascript'> \n"; | ||
| 1440 : | $replacement .= "<!-- \n"; | ||
| 1441 : | $replacement .= "var prefix = 'ma' + 'il' + 'to'; \n"; | ||
| 1442 : | $replacement .= "var path = 'hr' + 'ef' + '='; \n"; | ||
| 1443 : | $replacement .= "var addy". $rand ." = '". @$mail[0] ."' + '@' + '". implode( "' + '.' + '", $mail_parts ) ."'; \n"; | ||
| 1444 : | if ( $mailto ) { | ||
| 1445 : | // special handling when mail text is different from mail addy | ||
| 1446 : | if ( $text ) { | ||
| 1447 : | if ( $email ) { | ||
| 1448 : | // convert text | ||
| 1449 : | $text = mosHTML::encoding_converter( $text ); | ||
| 1450 : | // split email by @ symbol | ||
| 1451 : | $text = explode( '@', $text ); | ||
| 1452 : | $text_parts = explode( '.', $text[1] ); | ||
| 1453 : | $replacement .= "var addy_text". $rand ." = '". @$text[0] ."' + '@' + '". implode( "' + '.' + '", @$text_parts ) ."'; \n"; | ||
| 1454 : | } else { | ||
| 1455 : | $text = mosHTML::encoding_converter( $text ); | ||
| 1456 : | $replacement .= "var addy_text". $rand ." = '". $text ."';\n"; | ||
| 1457 : | } | ||
| 1458 : | $replacement .= "document.write( '<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>' ); \n"; | ||
| 1459 : | $replacement .= "document.write( addy_text". $rand ." ); \n"; | ||
| 1460 : | $replacement .= "document.write( '<\/a>' ); \n"; | ||
| 1461 : | } else { | ||
| 1462 : | $replacement .= "document.write( '<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>' ); \n"; | ||
| 1463 : | $replacement .= "document.write( addy". $rand ." ); \n"; | ||
| 1464 : | $replacement .= "document.write( '<\/a>' ); \n"; | ||
| 1465 : | } | ||
| 1466 : | } else { | ||
| 1467 : | $replacement .= "document.write( addy". $rand ." ); \n"; | ||
| 1468 : | } | ||
| 1469 : | $replacement .= "//--> \n"; | ||
| 1470 : | $replacement .= "</script> \n"; | ||
| 1471 : | $replacement .= "<noscript> \n"; | ||
| 1472 : | csouza | 39 | $replacement .= T_('This email address is being protected from spam bots, you need Javascript enabled to view it'); |
| 1473 : | root | 1 | $replacement .= "\n</noscript> \n"; |
| 1474 : | |||
| 1475 : | return $replacement; | ||
| 1476 : | } | ||
| 1477 : | |||
| 1478 : | function encoding_converter( $text ) { | ||
| 1479 : | // replace vowels with character encoding | ||
| 1480 : | $text = str_replace( 'a', 'a', $text ); | ||
| 1481 : | $text = str_replace( 'e', 'e', $text ); | ||
| 1482 : | $text = str_replace( 'i', 'i', $text ); | ||
| 1483 : | $text = str_replace( 'o', 'o', $text ); | ||
| 1484 : | $text = str_replace( 'u', 'u', $text ); | ||
| 1485 : | |||
| 1486 : | return $text; | ||
| 1487 : | } | ||
| 1488 : | } | ||
| 1489 : | |||
| 1490 : | /** | ||
| 1491 : | * Category database table class | ||
| 1492 : | * @package Mambo | ||
| 1493 : | */ | ||
| 1494 : | class mosCategory extends mosDBTable { | ||
| 1495 : | /** @var int Primary key */ | ||
| 1496 : | var $id=null; | ||
| 1497 : | /** @var string The menu title for the Category (a short name)*/ | ||
| 1498 : | var $title=null; | ||
| 1499 : | /** @var string The full name for the Category*/ | ||
| 1500 : | var $name=null; | ||
| 1501 : | /** @var string */ | ||
| 1502 : | var $image=null; | ||
| 1503 : | /** @var string */ | ||
| 1504 : | var $section=null; | ||
| 1505 : | /** @var int */ | ||
| 1506 : | var $image_position=null; | ||
| 1507 : | /** @var string */ | ||
| 1508 : | var $description=null; | ||
| 1509 : | /** @var boolean */ | ||
| 1510 : | var $published=null; | ||
| 1511 : | /** @var boolean */ | ||
| 1512 : | var $checked_out=null; | ||
| 1513 : | /** @var time */ | ||
| 1514 : | var $checked_out_time=null; | ||
| 1515 : | /** @var int */ | ||
| 1516 : | var $ordering=null; | ||
| 1517 : | /** @var int */ | ||
| 1518 : | var $access=null; | ||
| 1519 : | /** @var string */ | ||
| 1520 : | var $params=null; | ||
| 1521 : | |||
| 1522 : | /** | ||
| 1523 : | * @param database A database connector object | ||
| 1524 : | */ | ||
| 1525 : | function mosCategory( &$db ) { | ||
| 1526 : | $this->mosDBTable( '#__categories', 'id', $db ); | ||
| 1527 : | } | ||
| 1528 : | // overloaded check function | ||
| 1529 : | function check() { | ||
| 1530 : | // check for valid name | ||
| 1531 : | if (trim( $this->title ) == '') { | ||
| 1532 : | csouza | 39 | $this->_error = T_("Your Category must contain a title."); |
| 1533 : | root | 1 | return false; |
| 1534 : | } | ||
| 1535 : | if (trim( $this->name ) == '') { | ||
| 1536 : | csouza | 39 | $this->_error = T_("Your Category must have a name."); |
| 1537 : | root | 1 | return false; |
| 1538 : | } | ||
| 1539 : | // check for existing name | ||
| 1540 : | $this->_db->setQuery( "SELECT id FROM #__categories " | ||
| 1541 : | . "\nWHERE name='".$this->name."' AND section='".$this->section."'" | ||
| 1542 : | ); | ||
| 1543 : | |||
| 1544 : | $xid = intval( $this->_db->loadResult() ); | ||
| 1545 : | if ($xid && $xid != intval( $this->id )) { | ||
| 1546 : | csouza | 39 | $this->_error = T_("There is a category already with that name, please try again."); |
| 1547 : | root | 1 | return false; |
| 1548 : | } | ||
| 1549 : | return true; | ||
| 1550 : | } | ||
| 1551 : | } | ||
| 1552 : | |||
| 1553 : | /** | ||
| 1554 : | * Section database table class | ||
| 1555 : | * @package Mambo | ||
| 1556 : | */ | ||
| 1557 : | class mosSection extends mosDBTable { | ||
| 1558 : | /** @var int Primary key */ | ||
| 1559 : | var $id=null; | ||
| 1560 : | /** @var string The menu title for the Section (a short name)*/ | ||
| 1561 : | var $title=null; | ||
| 1562 : | /** @var string The full name for the Section*/ | ||
| 1563 : | var $name=null; | ||
| 1564 : | /** @var string */ | ||
| 1565 : | var $image=null; | ||
| 1566 : | /** @var string */ | ||
| 1567 : | var $scope=null; | ||
| 1568 : | /** @var int */ | ||
| 1569 : | var $image_position=null; | ||
| 1570 : | /** @var string */ | ||
| 1571 : | var $description=null; | ||
| 1572 : | /** @var boolean */ | ||
| 1573 : | var $published=null; | ||
| 1574 : | /** @var boolean */ | ||
| 1575 : | var $checked_out=null; | ||
| 1576 : | /** @var time */ | ||
| 1577 : | var $checked_out_time=null; | ||
| 1578 : | /** @var int */ | ||
| 1579 : | var $ordering=null; | ||
| 1580 : | /** @var int */ | ||
| 1581 : | var $access=null; | ||
| 1582 : | /** @var string */ | ||
| 1583 : | var $params=null; | ||
| 1584 : | |||
| 1585 : | /** | ||
| 1586 : | * @param database A database connector object | ||
| 1587 : | */ | ||
| 1588 : | function mosSection( &$db ) { | ||
| 1589 : | $this->mosDBTable( '#__sections', 'id', $db ); | ||
| 1590 : | } | ||
| 1591 : | // overloaded check function | ||
| 1592 : | function check() { | ||
| 1593 : | // check for valid name | ||
| 1594 : | if (trim( $this->title ) == '') { | ||
| 1595 : | csouza | 39 | $this->_error = T_("Your Section must contain a title."); |
| 1596 : | root | 1 | return false; |
| 1597 : | } | ||
| 1598 : | if (trim( $this->name ) == '') { | ||
| 1599 : | csouza | 39 | $this->_error = T_("Your Section must have a name."); |
| 1600 : | root | 1 | return false; |
| 1601 : | } | ||
| 1602 : | // check for existing name | ||
| 1603 : | $this->_db->setQuery( "SELECT id FROM #__sections " | ||
| 1604 : | . "\nWHERE name='$this->name' AND scope='$this->scope'" | ||
| 1605 : | ); | ||
| 1606 : | |||
| 1607 : | $xid = intval( $this->_db->loadResult() ); | ||
| 1608 : | if ($xid && $xid != intval( $this->id )) { | ||
| 1609 : | csouza | 39 | $this->_error = T_("There is a section already with that name, please try again."); |
| 1610 : | root | 1 | return false; |
| 1611 : | } | ||
| 1612 : | return true; | ||
| 1613 : | } | ||
| 1614 : | } | ||
| 1615 : | |||
| 1616 : | /** | ||
| 1617 : | * Module database table class | ||
| 1618 : | * @package Mambo | ||
| 1619 : | */ | ||
| 1620 : | class mosContent extends mosDBTable { | ||
| 1621 : | /** @var int Primary key */ | ||
| 1622 : | var $id=null; | ||
| 1623 : | /** @var string */ | ||
| 1624 : | var $title=null; | ||
| 1625 : | /** @var string */ | ||
| 1626 : | var $title_alias=null; | ||
| 1627 : | /** @var string */ | ||
| 1628 : | var $introtext=null; | ||
| 1629 : | /** @var string */ | ||
| 1630 : | var $fulltext=null; | ||
| 1631 : | /** @var int */ | ||
| 1632 : | var $state=null; | ||
| 1633 : | /** @var int The id of the category section*/ | ||
| 1634 : | var $sectionid=null; | ||
| 1635 : | /** @var int DEPRECATED */ | ||
| 1636 : | var $mask=null; | ||
| 1637 : | /** @var int */ | ||
| 1638 : | var $catid=null; | ||
| 1639 : | /** @var datetime */ | ||
| 1640 : | var $created=null; | ||
| 1641 : | /** @var int User id*/ | ||
| 1642 : | var $created_by=null; | ||
| 1643 : | /** @var string An alias for the author*/ | ||
| 1644 : | var $created_by_alias=null; | ||
| 1645 : | /** @var datetime */ | ||
| 1646 : | var $modified=null; | ||
| 1647 : | /** @var int User id*/ | ||
| 1648 : | var $modified_by=null; | ||
| 1649 : | /** @var boolean */ | ||
| 1650 : | var $checked_out=null; | ||
| 1651 : | /** @var time */ | ||
| 1652 : | var $checked_out_time=null; | ||
| 1653 : | /** @var datetime */ | ||
| 1654 : | var $frontpage_up=null; | ||
| 1655 : | /** @var datetime */ | ||
| 1656 : | var $frontpage_down=null; | ||
| 1657 : | /** @var datetime */ | ||
| 1658 : | var $publish_up=null; | ||
| 1659 : | /** @var datetime */ | ||
| 1660 : | var $publish_down=null; | ||
| 1661 : | /** @var string */ | ||
| 1662 : | var $images=null; | ||
| 1663 : | /** @var string */ | ||
| 1664 : | var $urls=null; | ||
| 1665 : | /** @var string */ | ||
| 1666 : | var $attribs=null; | ||
| 1667 : | /** @var int */ | ||
| 1668 : | var $version=null; | ||
| 1669 : | /** @var int */ | ||
| 1670 : | var $parentid=null; | ||
| 1671 : | /** @var int */ | ||
| 1672 : | var $ordering=null; | ||
| 1673 : | /** @var string */ | ||
| 1674 : | var $metakey=null; | ||
| 1675 : | /** @var string */ | ||
| 1676 : | var $metadesc=null; | ||
| 1677 : | /** @var int */ | ||
| 1678 : | var $access=null; | ||
| 1679 : | /** @var int */ | ||
| 1680 : | var $hits=null; | ||
| 1681 : | |||
| 1682 : | /** | ||
| 1683 : | * @param database A database connector object | ||
| 1684 : | */ | ||
| 1685 : | function mosContent( &$db ) { | ||
| 1686 : | $this->mosDBTable( '#__content', 'id', $db ); | ||
| 1687 : | } | ||
| 1688 : | |||
| 1689 : | /** | ||
| 1690 : | * Validation and filtering | ||
| 1691 : | */ | ||
| 1692 : | function check() { | ||
| 1693 : | // filter malicious code | ||
| 1694 : | $ignoreList = array( 'introtext', 'fulltext' ); | ||
| 1695 : | $this->filter( $ignoreList ); | ||
| 1696 : | |||
| 1697 : | /* | ||
| 1698 : | TODO: This filter is too rigorous, | ||
| 1699 : | need to implement more configurable solution | ||
| 1700 : | // specific filters | ||
| 1701 : | $iFilter = new InputFilter( null, null, 1, 1 ); | ||
| 1702 : | $this->introtext = trim( $iFilter->process( $this->introtext ) ); | ||
| 1703 : | $this->fulltext = trim( $iFilter->process( $this->fulltext ) ); | ||
| 1704 : | */ | ||
| 1705 : | |||
| 1706 : | if (trim( str_replace( ' ', '', $this->fulltext ) ) == '') { | ||
| 1707 : | $this->fulltext = ''; | ||
| 1708 : | } | ||
| 1709 : | |||
| 1710 : | return true; | ||
| 1711 : | } | ||
| 1712 : | |||
| 1713 : | /** | ||
| 1714 : | * Converts record to XML | ||
| 1715 : | * @param boolean Map foreign keys to text values | ||
| 1716 : | */ | ||
| 1717 : | function toXML( $mapKeysToText=false ) { | ||
| 1718 : | global $database; | ||
| 1719 : | |||
| 1720 : | if ($mapKeysToText) { | ||
| 1721 : | $query = 'SELECT name FROM #__sections WHERE id=' . $this->sectionid; | ||
| 1722 : | $database->setQuery( $query ); | ||
| 1723 : | $this->sectionid = $database->loadResult(); | ||
| 1724 : | |||
| 1725 : | $query = 'SELECT name FROM #__categories WHERE id=' . $this->catid; | ||
| 1726 : | $database->setQuery( $query ); | ||
| 1727 : | $this->catid = $database->loadResult(); | ||
| 1728 : | |||
| 1729 : | $query = 'SELECT name FROM #__users WHERE id=' . $this->created_by; | ||
| 1730 : | $database->setQuery( $query ); | ||
| 1731 : | $this->created_by = $database->loadResult(); | ||
| 1732 : | } | ||
| 1733 : | |||
| 1734 : | return parent::toXML( $mapKeysToText ); | ||
| 1735 : | } | ||
| 1736 : | } | ||
| 1737 : | |||
| 1738 : | /** | ||
| 1739 : | * Module database table class | ||
| 1740 : | * @package Mambo | ||
| 1741 : | */ | ||
| 1742 : | class mosMenu extends mosDBTable { | ||
| 1743 : | /** @var int Primary key */ | ||
| 1744 : | var $id=null; | ||
| 1745 : | /** @var string */ | ||
| 1746 : | var $menutype=null; | ||
| 1747 : | /** @var string */ | ||
| 1748 : | var $name=null; | ||
| 1749 : | /** @var string */ | ||
| 1750 : | var $link=null; | ||
| 1751 : | /** @var int */ | ||
| 1752 : | var $type=null; | ||
| 1753 : | /** @var int */ | ||
| 1754 : | var $published=null; | ||
| 1755 : | /** @var int */ | ||
| 1756 : | var $componentid=null; | ||
| 1757 : | /** @var int */ | ||
| 1758 : | var $parent=null; | ||
| 1759 : | /** @var int */ | ||
| 1760 : | var $sublevel=null; | ||
| 1761 : | /** @var int */ | ||
| 1762 : | var $ordering=null; | ||
| 1763 : | /** @var boolean */ | ||
| 1764 : | var $checked_out=null; | ||
| 1765 : | /** @var datetime */ | ||
| 1766 : | var $checked_out_time=null; | ||
| 1767 : | /** @var boolean */ | ||
| 1768 : | var $pollid=null; | ||
| 1769 : | |||
| 1770 : | /** @var string */ | ||
| 1771 : | var $browserNav=null; | ||
| 1772 : | /** @var int */ | ||
| 1773 : | var $access=null; | ||
| 1774 : | /** @var int */ | ||
| 1775 : | var $utaccess=null; | ||
| 1776 : | /** @var string */ | ||
| 1777 : | var $params=null; | ||
| 1778 : | |||
| 1779 : | /** | ||
| 1780 : | * @param database A database connector object | ||
| 1781 : | */ | ||
| 1782 : | function mosMenu( &$db ) { | ||
| 1783 : | $this->mosDBTable( '#__menu', 'id', $db ); | ||
| 1784 : | } | ||
| 1785 : | } | ||
| 1786 : | |||
| 1787 : | /** | ||
| 1788 : | * Users Table Class | ||
| 1789 : | * | ||
| 1790 : | * Provides access to the mos_templates table | ||
| 1791 : | * @package Mambo | ||
| 1792 : | */ | ||
| 1793 : | class mosUser extends mosDBTable { | ||
| 1794 : | /** @var int Unique id*/ | ||
| 1795 : | var $id=null; | ||
| 1796 : | /** @var string The users real name (or nickname)*/ | ||
| 1797 : | var $name=null; | ||
| 1798 : | /** @var string The login name*/ | ||
| 1799 : | var $username=null; | ||
| 1800 : | /** @var string email*/ | ||
| 1801 : | var $email=null; | ||
| 1802 : | /** @var string MD5 encrypted password*/ | ||
| 1803 : | var $password=null; | ||
| 1804 : | /** @var string */ | ||
| 1805 : | var $usertype=null; | ||
| 1806 : | /** @var int */ | ||
| 1807 : | var $block=null; | ||
| 1808 : | /** @var int */ | ||
| 1809 : | var $sendEmail=null; | ||
| 1810 : | /** @var int The group id number */ | ||
| 1811 : | var $gid=null; | ||
| 1812 : | /** @var datetime */ | ||
| 1813 : | var $registerDate=null; | ||
| 1814 : | /** @var datetime */ | ||
| 1815 : | var $lastvisitDate=null; | ||
| 1816 : | /** @var string activation hash*/ | ||
| 1817 : | var $activation=null; | ||
| 1818 : | /** @var string */ | ||
| 1819 : | var $params=null; | ||
| 1820 : | |||
| 1821 : | /** | ||
| 1822 : | * @param database A database connector object | ||
| 1823 : | */ | ||
| 1824 : | function mosUser( &$database ) { | ||
| 1825 : | $this->mosDBTable( '#__users', 'id', $database ); | ||
| 1826 : | } | ||
| 1827 : | |||
| 1828 : | /** | ||
| 1829 : | * Validation and filtering | ||
| 1830 : | * @return boolean True is satisfactory | ||
| 1831 : | */ | ||
| 1832 : | function check() { | ||
| 1833 : | global $mosConfig_uniquemail; | ||
| 1834 : | |||
| 1835 : | // filter malicious code | ||
| 1836 : | //$this->filter(); | ||
| 1837 : | |||
| 1838 : | // Validate user information | ||
| 1839 : | if (trim( $this->name ) == '') { | ||
| 1840 : | csouza | 39 | $this->_error = T_('Please enter your name.'); |
| 1841 : | root | 1 | return false; |
| 1842 : | } | ||
| 1843 : | |||
| 1844 : | if (trim( $this->username ) == '') { | ||
| 1845 : | csouza | 39 | $this->_error = T_('Please enter a user name.'); |
| 1846 : | root | 1 | return false; |
| 1847 : | } | ||
| 1848 : | |||
| 1849 : | if (eregi( "[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", $this->username) || strlen( $this->username ) < 3) { | ||
| 1850 : | csouza | 39 | $this->_error = sprintf( T_("Please enter a valid %s. No spaces, more than %d characters and containing only the characters 0-9,a-z, or A-Z"), T_('Username:'), 2 ); |
| 1851 : | root | 1 | return false; |
| 1852 : | } | ||
| 1853 : | |||
| 1854 : | if ((trim($this->email == "")) || (preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $this->email )==false)) { | ||
| 1855 : | csouza | 39 | $this->_error = T_('Please enter a valid e-mail address.'); |
| 1856 : | root | 1 | return false; |
| 1857 : | } | ||
| 1858 : | |||
| 1859 : | // check for existing username | ||
| 1860 : | $this->_db->setQuery( "SELECT id FROM #__users " | ||
| 1861 : | . "\nWHERE LOWER(username)=LOWER('$this->username') AND id!='$this->id'" | ||
| 1862 : | ); | ||
| 1863 : | |||
| 1864 : | $xid = intval( $this->_db->loadResult() ); | ||
| 1865 : | if ($xid && $xid != intval( $this->id )) { | ||
| 1866 : | csouza | 39 | $this->_error = T_('This username/password is already in use. Please try another.'); |
| 1867 : | root | 1 | return false; |
| 1868 : | } | ||
| 1869 : | |||
| 1870 : | if ($mosConfig_uniquemail) { | ||
| 1871 : | // check for existing email | ||
| 1872 : | $this->_db->setQuery( "SELECT id FROM #__users " | ||
| 1873 : | . "\nWHERE email='$this->email' AND id!='$this->id'" | ||
| 1874 : | ); | ||
| 1875 : | |||
| 1876 : | $xid = intval( $this->_db->loadResult() ); | ||
| 1877 : | if ($xid && $xid != intval( $this->id )) { | ||
| 1878 : | csouza | 39 | $this->_error = T_('This e-mail is already registered. If you forgot the password click on "Password Reminder" and new password will be sent to you.'); |
| 1879 : | root | 1 | return false; |
| 1880 : | } | ||
| 1881 : | } | ||
| 1882 : | |||
| 1883 : | return true; | ||
| 1884 : | } | ||
| 1885 : | |||
| 1886 : | function store( $updateNulls=false ) { | ||
| 1887 : | global $acl, $migrate; | ||
| 1888 : | $section_value = 'users'; | ||
| 1889 : | |||
| 1890 : | $k = $this->_tbl_key; | ||
| 1891 : | $key = $this->$k; | ||
| 1892 : | if( $key && !$migrate) { | ||
| 1893 : | // existing record | ||
| 1894 : | $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls ); | ||
| 1895 : | // syncronise ACL | ||
| 1896 : | // single group handled at the moment | ||
| 1897 : | // trivial to expand to multiple groups | ||
| 1898 : | $groups = $acl->get_object_groups( $section_value, $this->$k, 'ARO' ); | ||
| 1899 : | $acl->del_group_object( $groups[0], $section_value, $this->$k, 'ARO' ); | ||
| 1900 : | $acl->add_group_object( $this->gid, $section_value, $this->$k, 'ARO' ); | ||
| 1901 : | |||
| 1902 : | $object_id = $acl->get_object_id( $section_value, $this->$k, 'ARO' ); | ||
| 1903 : | $acl->edit_object( $object_id, $section_value, $this->_db->getEscaped( $this->name ), $this->$k, 0, 0, 'ARO' ); | ||
| 1904 : | } else { | ||
| 1905 : | // new record | ||
| 1906 : | $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key ); | ||
| 1907 : | // syncronise ACL | ||
| 1908 : | $acl->add_object( $section_value, $this->_db->getEscaped( $this->name ), $this->$k, null, null, 'ARO' ); | ||
| 1909 : | $acl->add_group_object( $this->gid, $section_value, $this->$k, 'ARO' ); | ||
| 1910 : | } | ||
| 1911 : | if( !$ret ) { | ||
| 1912 : | $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->getErrorMsg(); | ||
| 1913 : | return false; | ||
| 1914 : | } else { | ||
| 1915 : | return true; | ||
| 1916 : | } | ||
| 1917 : | } | ||
| 1918 : | |||
| 1919 : | function delete( $oid=null ) { | ||
| 1920 : | global $acl; | ||
| 1921 : | |||
| 1922 : | $k = $this->_tbl_key; | ||
| 1923 : | if ($oid) { | ||
| 1924 : | $this->$k = intval( $oid ); | ||
| 1925 : | } | ||
| 1926 : | $aro_id = $acl->get_object_id( 'users', $this->$k, 'ARO' ); | ||
| 1927 : | // $acl->del_object( $aro_id, 'ARO', true ); | ||
| 1928 : | |||
| 1929 : | $this->_db->setQuery( "DELETE FROM $this->_tbl WHERE $this->_tbl_key = '".$this->$k."'" ); | ||
| 1930 : | |||
| 1931 : | if ($this->_db->query()) { | ||
| 1932 : | // cleanup related data | ||
| 1933 : | |||
| 1934 : | // :: private messaging | ||
| 1935 : | $this->_db->setQuery( "DELETE FROM #__messages_cfg WHERE user_id='".$this->$k."'" ); | ||
| 1936 : | if (!$this->_db->query()) { | ||
| 1937 : | $this->_error = $this->_db->getErrorMsg(); | ||
| 1938 : | return false; | ||
| 1939 : | } | ||
| 1940 : | $this->_db->setQuery( "DELETE FROM #__messages WHERE user_id_to='".$this->$k."'" ); | ||
| 1941 : | if (!$this->_db->query()) { | ||
| 1942 : | $this->_error = $this->_db->getErrorMsg(); | ||
| 1943 : | return false; | ||
| 1944 : | } | ||
| 1945 : | |||
| 1946 : | return true; | ||
| 1947 : | } else { | ||
| 1948 : | $this->_error = $this->_db->getErrorMsg(); | ||
| 1949 : | return false; | ||
| 1950 : | } | ||
| 1951 : | } | ||
| 1952 : | } | ||
| 1953 : | |||
| 1954 : | /** | ||
| 1955 : | * Template Table Class | ||
| 1956 : | * | ||
| 1957 : | * Provides access to the mos_templates table | ||
| 1958 : | * @package Mambo | ||
| 1959 : | */ | ||
| 1960 : | class mosTemplate extends mosDBTable { | ||
| 1961 : | /** @var int */ | ||
| 1962 : | var $id=null; | ||
| 1963 : | /** @var string */ | ||
| 1964 : | var $cur_template=null; | ||
| 1965 : | /** @var int */ | ||
| 1966 : | var $col_main=null; | ||
| 1967 : | |||
| 1968 : | /** | ||
| 1969 : | * @param database A database connector object | ||
| 1970 : | */ | ||
| 1971 : | function mosTemplate( &$database ) { | ||
| 1972 : | $this->mosDBTable( '#__templates', 'id', $database ); | ||
| 1973 : | } | ||
| 1974 : | } | ||
| 1975 : | |||
| 1976 : | /** | ||
| 1977 : | * Utility function to return a value from a named array or a specified default | ||
| 1978 : | */ | ||
| 1979 : | define( "_MOS_NOTRIM", 0x0001 ); | ||
| 1980 : | define( "_MOS_ALLOWHTML", 0x0002 ); | ||
| 1981 : | define( "_MOS_ALLOWRAW", 0x0004 ); | ||
| 1982 : | function mosGetParam( &$arr, $name, $def=null, $mask=0 ) { | ||
| 1983 : | if (isset( $arr[$name] )) { | ||
| 1984 : | if (is_array($arr[$name])) foreach ($arr[$name] as $key=>$element) mosGetParam ($arr[$name], $key, $def, $mask); | ||
| 1985 : | else { | ||
| 1986 : | if (!($mask&_MOS_NOTRIM)) $arr[$name] = trim( $arr[$name] ); | ||
| 1987 : | if (!is_numeric( $arr[$name] )) { | ||
| 1988 : | if (!($mask&_MOS_ALLOWHTML)) $arr[$name] = strip_tags( $arr[$name] ); | ||
| 1989 : | if (!($mask&_MOS_ALLOWRAW)) { | ||
| 1990 : | if (is_numeric($def)) $arr[$name] = intval($arr[$name]); | ||
| 1991 : | } | ||
| 1992 : | } | ||
| 1993 : | } | ||
| 1994 : | return $arr[$name]; | ||
| 1995 : | } else { | ||
| 1996 : | return $def; | ||
| 1997 : | } | ||
| 1998 : | } | ||
| 1999 : | |||
| 2000 : | /** | ||
| 2001 : | * Strip slashes from strings or arrays of strings | ||
| 2002 : | * @param value the input string or array | ||
| 2003 : | */ | ||
| 2004 : | function mosStripslashes(&$value) | ||
| 2005 : | { | ||
| 2006 : | $ret = ''; | ||
| 2007 : | if (is_string($value)) { | ||
| 2008 : | $ret = stripslashes($value); | ||
| 2009 : | } else { | ||
| 2010 : | if (is_array($value)) { | ||
| 2011 : | $ret = array(); | ||
| 2012 : | while (list($key,$val) = each($value)) { | ||
| 2013 : | $ret[$key] = mosStripslashes($val); | ||
| 2014 : | } // while | ||
| 2015 : | } else { | ||
| 2016 : | $ret = $value; | ||
| 2017 : | } // if | ||
| 2018 : | } // if | ||
| 2019 : | return $ret; | ||
| 2020 : | } // mosStripSlashes | ||
| 2021 : | |||
| 2022 : | /** | ||
| 2023 : | * Copy the named array content into the object as properties | ||
| 2024 : | * only existing properties of object are filled. when undefined in hash, properties wont be deleted | ||
| 2025 : | * @param array the input array | ||
| 2026 : | * @param obj byref the object to fill of any class | ||
| 2027 : | * @param string | ||
| 2028 : | * @param boolean | ||
| 2029 : | */ | ||
| 2030 : | function mosBindArrayToObject( $array, &$obj, $ignore='', $prefix=NULL, $checkSlashes=true ) { | ||
| 2031 : | if (!is_array( $array ) || !is_object( $obj )) { | ||
| 2032 : | return (false); | ||
| 2033 : | } | ||
| 2034 : | |||
| 2035 : | foreach (get_object_vars($obj) as $k => $v) { | ||
| 2036 : | if( substr( $k, 0, 1 ) != '_' ) { // internal attributes of an object are ignored | ||
| 2037 : | if (strpos( $ignore, $k) === false) { | ||
| 2038 : | if ($prefix) { | ||
| 2039 : | $ak = $prefix . $k; | ||
| 2040 : | } else { | ||
| 2041 : | $ak = $k; | ||
| 2042 : | } | ||
| 2043 : | if (isset($array[$ak])) { | ||
| 2044 : | $obj->$k = ($checkSlashes && get_magic_quotes_gpc()) ? mosStripslashes( $array[$k] ) : $array[$k]; | ||
| 2045 : | } | ||
| 2046 : | } | ||
| 2047 : | } | ||
| 2048 : | } | ||
| 2049 : | |||
| 2050 : | return true; | ||
| 2051 : | } | ||
| 2052 : | |||
| 2053 : | /** | ||
| 2054 : | * Utility function to read the files in a directory | ||
| 2055 : | * @param string The file system path | ||
| 2056 : | * @param string A filter for the names | ||
| 2057 : | * @param boolean Recurse search into sub-directories | ||
| 2058 : | * @param boolean True if to prepend the full path to the file name | ||
| 2059 : | */ | ||
| 2060 : | function mosReadDirectory( $path, $filter='.', $recurse=false, $fullpath=false ) { | ||
| 2061 : | $arr = array(); | ||
| 2062 : | if (!@is_dir( $path )) { | ||
| 2063 : | return $arr; | ||
| 2064 : | } | ||
| 2065 : | $handle = opendir( $path ); | ||
| 2066 : | |||
| 2067 : | while ($file = readdir($handle)) { | ||
| 2068 : | $dir = mosPathName( $path.'/'.$file, false ); | ||
| 2069 : | $isDir = is_dir( $dir ); | ||
| 2070 : | if (($file <> ".") && ($file <> "..")) { | ||
| 2071 : | if (preg_match( "/$filter/", $file )) { | ||
| 2072 : | if ($fullpath) { | ||
| 2073 : | $arr[] = trim( mosPathName( $path.'/'.$file, false ) ); | ||
| 2074 : | } else { | ||
| 2075 : | $arr[] = trim( $file ); | ||
| 2076 : | } | ||
| 2077 : | } | ||
| 2078 : | if ($recurse && $isDir) { | ||
| 2079 : | $arr2 = mosReadDirectory( $dir, $filter, $recurse, $fullpath ); | ||
| 2080 : | $arr = array_merge( $arr, $arr2 ); | ||
| 2081 : | } | ||
| 2082 : | } | ||
| 2083 : | } | ||
| 2084 : | closedir($handle); | ||
| 2085 : | asort($arr); | ||
| 2086 : | return $arr; | ||
| 2087 : | } | ||
| 2088 : | |||
| 2089 : | /** | ||
| 2090 : | * Utility function redirect the browser location to another url | ||
| 2091 : | * | ||
| 2092 : | * Can optionally provide a message. | ||
| 2093 : | * @param string The file system path | ||
| 2094 : | * @param string A filter for the names | ||
| 2095 : | */ | ||
| 2096 : | function mosRedirect( $url, $msg='' ) { | ||
| 2097 : | // specific filters | ||
| 2098 : | $iFilter = new InputFilter(); | ||
| 2099 : | $url = $iFilter->process( $url ); | ||
| 2100 : | $msg = $iFilter->process( $msg ); | ||
| 2101 : | |||
| 2102 : | if ($iFilter->badAttributeValue( array( 'href', $url ))) { | ||
| 2103 : | $url = $GLOBALS['mosConfig_live_site']; | ||
| 2104 : | } | ||
| 2105 : | |||
| 2106 : | if (trim( $msg )) { | ||
| 2107 : | if (strpos( $url, '?' )) { | ||
| 2108 : | $url .= '&mosmsg=' . urlencode( $msg ); | ||
| 2109 : | } else { | ||
| 2110 : | $url .= '?mosmsg=' . urlencode( $msg ); | ||
| 2111 : | } | ||
| 2112 : | } | ||
| 2113 : | |||
| 2114 : | if (headers_sent()) { | ||
| 2115 : | echo "<script>document.location.href='$url';</script>\n"; | ||
| 2116 : | } else { | ||
| 2117 : | @ob_end_clean(); // clear output buffer | ||
| 2118 : | header( "Location: $url" ); | ||
| 2119 : | } | ||
| 2120 : | exit(); | ||
| 2121 : | } | ||
| 2122 : | |||
| 2123 : | function mosTreeRecurse( $id, $indent, $list, &$children, $maxlevel=9999, $level=0, $type=1 ) { | ||
| 2124 : | if (@$children[$id] && $level <= $maxlevel) { | ||
| 2125 : | foreach ($children[$id] as $v) { | ||
| 2126 : | $id = $v->id; | ||
| 2127 : | |||
| 2128 : | if ( $type ) { | ||
| 2129 : | $pre = '<sup>L</sup> '; | ||
| 2130 : | $spacer = '. '; | ||
| 2131 : | } else { | ||
| 2132 : | $pre = '- '; | ||
| 2133 : | $spacer = ' '; | ||
| 2134 : | } | ||
| 2135 : | |||
| 2136 : | if ( $v->parent == 0 ) { | ||
| 2137 : | $txt = $v->name; | ||
| 2138 : | } else { | ||
| 2139 : | $txt = $pre . $v->name; | ||
| 2140 : | } | ||
| 2141 : | $pt = $v->parent; | ||
| 2142 : | $list[$id] = $v; | ||
| 2143 : | $list[$id]->treename = "$indent$txt"; | ||
| 2144 : | $list[$id]->children = count( @$children[$id] ); | ||
| 2145 : | $list = mosTreeRecurse( $id, $indent . $spacer, $list, $children, $maxlevel, $level+1, $type ); | ||
| 2146 : | } | ||
| 2147 : | } | ||
| 2148 : | return $list; | ||
| 2149 : | } | ||
| 2150 : | |||
| 2151 : | /** | ||
| 2152 : | * Function to strip additional / or \ in a path name | ||
| 2153 : | * @param string The path | ||
| 2154 : | * @param boolean Add trailing slash | ||
| 2155 : | */ | ||
| 2156 : | function mosPathName($p_path,$p_addtrailingslash = true) { | ||
| 2157 : | $retval = ""; | ||
| 2158 : | |||
| 2159 : | $isWin = (substr(PHP_OS, 0, 3) == 'WIN'); | ||
| 2160 : | |||
| 2161 : | if ($isWin) { | ||
| 2162 : | $retval = str_replace( '/', '\\', $p_path ); | ||
| 2163 : | if ($p_addtrailingslash) { | ||
| 2164 : | if (substr( $retval, -1 ) != '\\') { | ||
| 2165 : | $retval .= '\\'; | ||
| 2166 : | } | ||
| 2167 : | } | ||
| 2168 : | // Remove double \\ | ||
| 2169 : | $retval = str_replace( '\\\\', '\\', $retval ); | ||
| 2170 : | } else { | ||
| 2171 : | $retval = str_replace( '\\', '/', $p_path ); | ||
| 2172 : | if ($p_addtrailingslash) { | ||
| 2173 : | if (substr( $retval, -1 ) != '/') { | ||
| 2174 : | $retval .= '/'; | ||
| 2175 : | } | ||
| 2176 : | } | ||
| 2177 : | // Remove double // | ||
| 2178 : | $retval = str_replace('//','/',$retval); | ||
| 2179 : | } | ||
| 2180 : | |||
| 2181 : | return $retval; | ||
| 2182 : | } | ||
| 2183 : | |||
| 2184 : | /** | ||
| 2185 : | * Class mosMambot | ||
| 2186 : | * @package Mambo | ||
| 2187 : | */ | ||
| 2188 : | class mosMambot extends mosDBTable { | ||
| 2189 : | /** @var int */ | ||
| 2190 : | var $id=null; | ||
| 2191 : | /** @var varchar */ | ||
| 2192 : | var $name=null; | ||
| 2193 : | /** @var varchar */ | ||
| 2194 : | var $element=null; | ||
| 2195 : | /** @var varchar */ | ||
| 2196 : | var $folder=null; | ||
| 2197 : | /** @var tinyint unsigned */ | ||
| 2198 : | var $access=null; | ||
| 2199 : | /** @var int */ | ||
| 2200 : | var $ordering=null; | ||
| 2201 : | /** @var tinyint */ | ||
| 2202 : | var $published=null; | ||
| 2203 : | /** @var tinyint */ | ||
| 2204 : | var $iscore=null; | ||
| 2205 : | /** @var tinyint */ | ||
| 2206 : | var $client_id=null; | ||
| 2207 : | /** @var int unsigned */ | ||
| 2208 : | var $checked_out=null; | ||
| 2209 : | /** @var datetime */ | ||
| 2210 : | var $checked_out_time=null; | ||
| 2211 : | /** @var text */ | ||
| 2212 : | var $params=null; | ||
| 2213 : | |||
| 2214 : | function mosMambot( &$db ) { | ||
| 2215 : | $this->mosDBTable( '#__mambots', 'id', $db ); | ||
| 2216 : | } | ||
| 2217 : | } | ||
| 2218 : | |||
| 2219 : | /** | ||
| 2220 : | * Module database table class | ||
| 2221 : | * @package Mambo | ||
| 2222 : | */ | ||
| 2223 : | class mosModule extends mosDBTable { | ||
| 2224 : | /** @var int Primary key */ | ||
| 2225 : | var $id=null; | ||
| 2226 : | /** @var string */ | ||
| 2227 : | var $title=null; | ||
| 2228 : | /** @var string */ | ||
| 2229 : | var $showtitle=null; | ||
| 2230 : | /** @var int */ | ||
| 2231 : | var $content=null; | ||
| 2232 : | /** @var int */ | ||
| 2233 : | var $ordering=null; | ||
| 2234 : | /** @var string */ | ||
| 2235 : | var $position=null; | ||
| 2236 : | /** @var boolean */ | ||
| 2237 : | var $checked_out=null; | ||
| 2238 : | /** @var time */ | ||
| 2239 : | var $checked_out_time=null; | ||
| 2240 : | /** @var boolean */ | ||
| 2241 : | var $published=null; | ||
| 2242 : | /** @var string */ | ||
| 2243 : | var $module=null; | ||
| 2244 : | /** @var int */ | ||
| 2245 : | var $numnews=null; | ||
| 2246 : | /** @var int */ | ||
| 2247 : | var $access=null; | ||
| 2248 : | /** @var string */ | ||
| 2249 : | var $params=null; | ||
| 2250 : | /** @var string */ | ||
| 2251 : | var $iscore=null; | ||
| 2252 : | /** @var string */ | ||
| 2253 : | var $client_id=null; | ||
| 2254 : | |||
| 2255 : | /** | ||
| 2256 : | * @param database A database connector object | ||
| 2257 : | */ | ||
| 2258 : | function mosModule( &$db ) { | ||
| 2259 : | $this->mosDBTable( '#__modules', 'id', $db ); | ||
| 2260 : | } | ||
| 2261 : | // overloaded check function | ||
| 2262 : | function check() { | ||
| 2263 : | // check for valid name | ||
| 2264 : | if (trim( $this->title ) == '') { | ||
| 2265 : | $this->_error = "Your Module must contain a title."; | ||
| 2266 : | return false; | ||
| 2267 : | } | ||
| 2268 : | |||
| 2269 : | // limitation has been removed | ||
| 2270 : | // check for existing title | ||
| 2271 : | //$this->_db->setQuery( "SELECT id FROM #__modules" | ||
| 2272 : | //. "\nWHERE title='$this->title'" | ||
| 2273 : | //); | ||
| 2274 : | // check for module of same name | ||
| 2275 : | //$xid = intval( $this->_db->loadResult() ); | ||
| 2276 : | //if ($xid && $xid != intval( $this->id )) { | ||
| 2277 : | // $this->_error = "There is a module already with that name, please try again."; | ||
| 2278 : | // return false; | ||
| 2279 : | //} | ||
| 2280 : | return true; | ||
| 2281 : | } | ||
| 2282 : | } | ||
| 2283 : | |||
| 2284 : | /** | ||
| 2285 : | * Session database table class | ||
| 2286 : | * @package Mambo | ||
| 2287 : | */ | ||
| 2288 : | class mosSession extends mosDBTable { | ||
| 2289 : | /** @var int Primary key */ | ||
| 2290 : | var $session_id=null; | ||
| 2291 : | /** @var string */ | ||
| 2292 : | var $time=null; | ||
| 2293 : | /** @var string */ | ||
| 2294 : | var $userid=null; | ||
| 2295 : | /** @var string */ | ||
| 2296 : | var $usertype=null; | ||
| 2297 : | /** @var string */ | ||
| 2298 : | var $username=null; | ||
| 2299 : | /** @var time */ | ||
| 2300 : | var $gid=null; | ||
| 2301 : | /** @var int */ | ||
| 2302 : | var $guest=null; | ||
| 2303 : | /** @var string */ | ||
| 2304 : | var $_session_cookie=null; | ||
| 2305 : | |||
| 2306 : | /** | ||
| 2307 : | * @param database A database connector object | ||
| 2308 : | */ | ||
| 2309 : | function mosSession( &$db ) { | ||
| 2310 : | $this->mosDBTable( '#__session', 'session_id', $db ); | ||
| 2311 : | } | ||
| 2312 : | |||
| 2313 : | function insert() { | ||
| 2314 : | $ret = $this->_db->insertObject( $this->_tbl, $this ); | ||
| 2315 : | |||
| 2316 : | if( !$ret ) { | ||
| 2317 : | csouza | 39 | $this->_error = strtolower(get_class( $this ))."::store() ". T_('failed') ." <br />" . $this->_db->stderr(); |
| 2318 : | root | 1 | return false; |
| 2319 : | } else { | ||
| 2320 : | return true; | ||
| 2321 : | } | ||
| 2322 : | } | ||
| 2323 : | |||
| 2324 : | function update( $updateNulls=false ) { | ||
| 2325 : | $ret = $this->_db->updateObject( $this->_tbl, $this, 'session_id', $updateNulls ); | ||
| 2326 : | |||
| 2327 : | if( !$ret ) { | ||
| 2328 : | csouza | 39 | $this->_error = strtolower(get_class( $this ))."::store() ". T_('failed') ." <br />" . $this->_db->stderr(); |
| 2329 : | root | 1 | return false; |
| 2330 : | } else { | ||
| 2331 : | return true; | ||
| 2332 : | } | ||
| 2333 : | } | ||
| 2334 : | |||
| 2335 : | function generateId() { | ||
| 2336 : | $failsafe = 20; | ||
| 2337 : | $randnum = 0; | ||
| 2338 : | while ($failsafe--) { | ||
| 2339 : | $randnum = md5( uniqid( microtime(), 1 ) ); | ||
| 2340 : | if ($randnum != "") { | ||
| 2341 : | $cryptrandnum = md5( $randnum ); | ||
| 2342 : | $this->_db->setQuery( "SELECT $this->_tbl_key FROM $this->_tbl WHERE $this->_tbl_key=MD5('$randnum')" ); | ||
| 2343 : | if(!$result = $this->_db->query()) { | ||
| 2344 : | die( $this->_db->stderr( true )); | ||
| 2345 : | // todo: handle gracefully | ||
| 2346 : | } | ||
| 2347 : | if ($this->_db->getNumRows($result) == 0) { | ||
| 2348 : | break; | ||
| 2349 : | } | ||
| 2350 : | } | ||
| 2351 : | } | ||
| 2352 : | $this->_session_cookie = $randnum; | ||
| 2353 : | $this->session_id = md5( $randnum . $_SERVER['REMOTE_ADDR'] ); | ||
| 2354 : | } | ||
| 2355 : | |||
| 2356 : | function getCookie() { | ||
| 2357 : | return $this->_session_cookie; | ||
| 2358 : | } | ||
| 2359 : | |||
| 2360 : | function purge( $inc=1800 ) { | ||
| 2361 : | $past = time() - $inc; | ||
| 2362 : | $query = "DELETE FROM $this->_tbl" | ||
| 2363 : | . "\nWHERE (time < $past)"; | ||
| 2364 : | $this->_db->setQuery($query); | ||
| 2365 : | |||
| 2366 : | return $this->_db->query(); | ||
| 2367 : | } | ||
| 2368 : | } | ||
| 2369 : | |||
| 2370 : | |||
| 2371 : | function mosObjectToArray($p_obj) | ||
| 2372 : | { | ||
| 2373 : | $retarray = null; | ||
| 2374 : | if(is_object($p_obj)) | ||
| 2375 : | { | ||
| 2376 : | $retarray = array(); | ||
| 2377 : | foreach (get_object_vars($p_obj) as $k => $v) | ||
| 2378 : | { | ||
| 2379 : | if(is_object($v)) | ||
| 2380 : | $retarray[$k] = mosObjectToArray($v); | ||
| 2381 : | else | ||
| 2382 : | $retarray[$k] = $v; | ||
| 2383 : | } | ||
| 2384 : | } | ||
| 2385 : | return $retarray; | ||
| 2386 : | } | ||
| 2387 : | /** | ||
| 2388 : | * Checks the user agent string against known browsers | ||
| 2389 : | */ | ||
| 2390 : | function mosGetBrowser( $agent ) { | ||
| 2391 : | require( "includes/agent_browser.php" ); | ||
| 2392 : | |||
| 2393 : | if (preg_match( "/msie[\/\sa-z]*([\d\.]*)/i", $agent, $m ) | ||
| 2394 : | && !preg_match( "/webtv/i", $agent ) | ||
| 2395 : | && !preg_match( "/omniweb/i", $agent ) | ||
| 2396 : | && !preg_match( "/opera/i", $agent )) { | ||
| 2397 : | // IE | ||
| 2398 : | return "MS Internet Explorer $m[1]"; | ||
| 2399 : | } else if (preg_match( "/netscape.?\/([\d\.]*)/i", $agent, $m )) { | ||
| 2400 : | // Netscape 6.x, 7.x ... | ||
| 2401 : | return "Netscape $m[1]"; | ||
| 2402 : | } else if ( preg_match( "/mozilla[\/\sa-z]*([\d\.]*)/i", $agent, $m ) | ||
| 2403 : | && !preg_match( "/gecko/i", $agent ) | ||
| 2404 : | && !preg_match( "/compatible/i", $agent ) | ||
| 2405 : | && !preg_match( "/opera/i", $agent ) | ||
| 2406 : | && !preg_match( "/galeon/i", $agent ) | ||
| 2407 : | && !preg_match( "/safari/i", $agent )) { | ||
| 2408 : | // Netscape 3.x, 4.x ... | ||
| 2409 : | return "Netscape $m[2]"; | ||
| 2410 : | } else { | ||
| 2411 : | // Other | ||
| 2412 : | $found = false; | ||
| 2413 : | foreach ($browserSearchOrder as $key) { | ||
| 2414 : | if (preg_match( "/$key.?\/([\d\.]*)/i", $agent, $m )) { | ||
| 2415 : | $name = "$browsersAlias[$key] $m[1]"; | ||
| 2416 : | return $name; | ||
| 2417 : | break; | ||
| 2418 : | } | ||
| 2419 : | } | ||
| 2420 : | } | ||
| 2421 : | |||
| 2422 : | return 'Unknown'; | ||
| 2423 : | } | ||
| 2424 : | |||
| 2425 : | /** | ||
| 2426 : | * Checks the user agent string against known operating systems | ||
| 2427 : | */ | ||
| 2428 : | function mosGetOS( $agent ) { | ||
| 2429 : | require( "includes/agent_os.php" ); | ||
| 2430 : | |||
| 2431 : | foreach ($osSearchOrder as $key) { | ||
| 2432 : | if (preg_match( "/$key/i", $agent )) { | ||
| 2433 : | return $osAlias[$key]; | ||
| 2434 : | break; | ||
| 2435 : | } | ||
| 2436 : | } | ||
| 2437 : | |||
| 2438 : | return 'Unknown'; | ||
| 2439 : | } | ||
| 2440 : | |||
| 2441 : | /** | ||
| 2442 : | * @param string SQL with ordering As value and 'name field' AS text | ||
| 2443 : | * @param integer The length of the truncated headline | ||
| 2444 : | */ | ||
| 2445 : | function mosGetOrderingList( $sql, $chop='30' ) { | ||
| 2446 : | global $database; | ||
| 2447 : | |||
| 2448 : | $order = array(); | ||
| 2449 : | $database->setQuery( $sql ); | ||
| 2450 : | if (!($orders = $database->loadObjectList())) { | ||
| 2451 : | if ($database->getErrorNum()) { | ||
| 2452 : | echo $database->stderr(); | ||
| 2453 : | return false; | ||
| 2454 : | } else { | ||
| 2455 : | $order[] = mosHTML::makeOption( 1, 'first' ); | ||
| 2456 : | return $order; | ||
| 2457 : | } | ||
| 2458 : | } | ||
| 2459 : | $order[] = mosHTML::makeOption( 0, '0 first' ); | ||
| 2460 : | for ($i=0, $n=count( $orders ); $i < $n; $i++) { | ||
| 2461 : | |||
| 2462 : | if (strlen($orders[$i]->text) > $chop) { | ||
| 2463 : | $text = substr($orders[$i]->text,0,$chop)."..."; | ||
| 2464 : | } else { | ||
| 2465 : | $text = $orders[$i]->text; | ||
| 2466 : | } | ||
| 2467 : | |||
| 2468 : | $order[] = mosHTML::makeOption( $orders[$i]->value, $orders[$i]->value.' ('.$text.')' ); | ||
| 2469 : | } | ||
| 2470 : | $order[] = mosHTML::makeOption( $orders[$i-1]->value+1, ($orders[$i-1]->value+1).' last' ); | ||
| 2471 : | |||
| 2472 : | return $order; | ||
| 2473 : | } | ||
| 2474 : | |||
| 2475 : | /** | ||
| 2476 : | * Makes a variable safe to display in forms | ||
| 2477 : | * | ||
| 2478 : | * Object parameters that are non-string, array, object or start with underscore | ||
| 2479 : | * will be converted | ||
| 2480 : | * @param object An object to be parsed | ||
| 2481 : | * @param int The optional quote style for the htmlspecialchars function | ||
| 2482 : | * @param string|array An optional single field name or array of field names not | ||
| 2483 : | * to be parsed (eg, for a textarea) | ||
| 2484 : | */ | ||
| 2485 : | function mosMakeHtmlSafe( &$mixed, $quote_style=ENT_QUOTES, $exclude_keys='' ) { | ||
| 2486 : | if (is_object( $mixed )) { | ||
| 2487 : | foreach (get_object_vars( $mixed ) as $k => $v) { | ||
| 2488 : | if (is_array( $v ) || is_object( $v ) || $v == NULL || substr( $k, 1, 1 ) == '_' ) { | ||
| 2489 : | continue; | ||
| 2490 : | } | ||
| 2491 : | if (is_string( $exclude_keys ) && $k == $exclude_keys) { | ||
| 2492 : | continue; | ||
| 2493 : | } else if (is_array( $exclude_keys ) && in_array( $k, $exclude_keys )) { | ||
| 2494 : | continue; | ||
| 2495 : | } | ||
| 2496 : | $mixed->$k = htmlspecialchars( $v, $quote_style ); | ||
| 2497 : | } | ||
| 2498 : | } | ||
| 2499 : | } | ||
| 2500 : | |||
| 2501 : | /** | ||
| 2502 : | * Checks whether a menu option is within the users access level | ||
| 2503 : | * @param int Item id number | ||
| 2504 : | * @param string The menu option | ||
| 2505 : | * @param int The users group ID number | ||
| 2506 : | * @param database A database connector object | ||
| 2507 : | * @return boolean True if the visitor's group at least equal to the menu access | ||
| 2508 : | */ | ||
| 2509 : | function mosMenuCheck( $Itemid, $menu_option, $task, $gid ) { | ||
| 2510 : | global $database; | ||
| 2511 : | $dblink="index.php?option=$menu_option"; | ||
| 2512 : | if ($Itemid!="" && $Itemid!=0) { | ||
| 2513 : | $database->setQuery( "SELECT access FROM #__menu WHERE id='$Itemid'" ); | ||
| 2514 : | } else { | ||
| 2515 : | if ($task!="") { | ||
| 2516 : | $dblink.="&task=$task"; | ||
| 2517 : | } | ||
| 2518 : | $database->setQuery( "SELECT access FROM #__menu WHERE link like '$dblink%'" ); | ||
| 2519 : | } | ||
| 2520 : | $results = $database->loadObjectList(); | ||
| 2521 : | $access = 0; | ||
| 2522 : | //echo "<pre>"; print_r($results); echo "</pre>"; | ||
| 2523 : | foreach ($results as $result) { | ||
| 2524 : | $access = max( $access, $result->access ); | ||
| 2525 : | } | ||
| 2526 : | return ($access <= $gid); | ||
| 2527 : | } | ||
| 2528 : | |||
| 2529 : | /** | ||
| 2530 : | * Returns formated date according to current local and adds time offset | ||
| 2531 : | * @param string date in datetime format | ||
| 2532 : | * @param string format optional format for strftime | ||
| 2533 : | * @param offset time offset if different than global one | ||
| 2534 : | * @returns formated date | ||
| 2535 : | */ | ||
| 2536 : | function mosFormatDate( $date, $format="", $offset="" ){ | ||
| 2537 : | global $mosConfig_offset; | ||
| 2538 : | if ( $format == '' ) { | ||
| 2539 : | // %Y-%m-%d %H:%M:%S | ||
| 2540 : | $format = _DATE_FORMAT_LC; | ||
| 2541 : | } | ||
| 2542 : | if ( $offset == '' ) { | ||
| 2543 : | $offset = $mosConfig_offset; | ||
| 2544 : | } | ||
| 2545 : | if ( $date && ereg( "([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $date, $regs ) ) { | ||
| 2546 : | $date = mktime( $regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] ); | ||
| 2547 : | $date = $date > -1 ? strftime( $format, $date + ($offset*60*60) ) : '-'; | ||
| 2548 : | } | ||
| 2549 : | return $date; | ||
| 2550 : | } | ||
| 2551 : | |||
| 2552 : | /** | ||
| 2553 : | * Returns current date according to current local and time offset | ||
| 2554 : | * @param string format optional format for strftime | ||
| 2555 : | * @returns current date | ||
| 2556 : | */ | ||
| 2557 : | function mosCurrentDate( $format="" ) { | ||
| 2558 : | global $mosConfig_offset; | ||
| 2559 : | if ($format=="") { | ||
| 2560 : | $format = _DATE_FORMAT_LC; | ||
| 2561 : | } | ||
| 2562 : | $date = strftime( $format, time() + ($mosConfig_offset*60*60) ); | ||
| 2563 : | return $date; | ||
| 2564 : | } | ||
| 2565 : | |||
| 2566 : | /** | ||
| 2567 : | * Utility function to provide ToolTips | ||
| 2568 : | * @param string ToolTip text | ||
| 2569 : | * @param string Box title | ||
| 2570 : | * @returns HTML code for ToolTip | ||
| 2571 : | */ | ||
| 2572 : | function mosToolTip( $tooltip, $title='', $width='', $image='tooltip.png', $text='', $href='#' ) { | ||
| 2573 : | global $mosConfig_live_site; | ||
| 2574 : | |||
| 2575 : | if ( $width ) { | ||
| 2576 : | $width = ', WIDTH, \''.$width .'\''; | ||
| 2577 : | } | ||
| 2578 : | if ( $title ) { | ||
| 2579 : | $title = ', CAPTION, \''.$title .'\''; | ||
| 2580 : | } | ||
| 2581 : | if ( !$text ) { | ||
| 2582 : | $image = $mosConfig_live_site . '/includes/js/ThemeOffice/'. $image; | ||
| 2583 : | $text = '<img src="'. $image .'" border="0" />'; | ||
| 2584 : | } | ||
| 2585 : | $style = 'style="text-decoration: none; color: #333;"'; | ||
| 2586 : | if ( $href ) { | ||
| 2587 : | $style = ''; | ||
| 2588 : | } | ||
| 2589 : | $tip = "<a href=\"". $href ."\" onMouseOver=\"return overlib('" . $tooltip . "'". $title .", BELOW, RIGHT". $width .");\" onmouseout=\"return nd();\" ". $style .">". $text ."</a>"; | ||
| 2590 : | return $tip; | ||
| 2591 : | } | ||
| 2592 : | |||
| 2593 : | /** | ||
| 2594 : | * Utility function to provide Warning Icons | ||
| 2595 : | * @param string Warning text | ||
| 2596 : | * @param string Box title | ||
| 2597 : | * @returns HTML code for Warning | ||
| 2598 : | */ | ||
| 2599 : | function mosWarning($warning, $title='Mambo Warning') { | ||
| 2600 : | global $mosConfig_live_site; | ||
| 2601 : | $tip = "<a href=\"#\" onMouseOver=\"return overlib('" . $warning . "', CAPTION, '$title', BELOW, RIGHT);\" onmouseout=\"return nd();\"><img src=\"" . $mosConfig_live_site . "/includes/js/ThemeOffice/warning.png\" border=\"0\" /></a>"; | ||
| 2602 : | return $tip; | ||
| 2603 : | } | ||
| 2604 : | |||
| 2605 : | function mosCreateGUID(){ | ||
| 2606 : | srand((double)microtime()*1000000); | ||
| 2607 : | $r = rand ; | ||
| 2608 : | $u = uniqid(getmypid() . $r . (double)microtime()*1000000,1); | ||
| 2609 : | $m = md5 ($u); | ||
| 2610 : | return($m); | ||
| 2611 : | } | ||
| 2612 : | |||
| 2613 : | function mosCompressID( $ID ){ | ||
| 2614 : | return(Base64_encode(pack("H*",$ID))); | ||
| 2615 : | } | ||
| 2616 : | |||
| 2617 : | function mosExpandID( $ID ) { | ||
| 2618 : | return ( implode(unpack("H*",Base64_decode($ID)), '') ); | ||
| 2619 : | } | ||
| 2620 : | |||
| 2621 : | /** | ||
| 2622 : | * Page generation time | ||
| 2623 : | * @package Mambo | ||
| 2624 : | */ | ||
| 2625 : | class mosProfiler { | ||
| 2626 : | var $start=0; | ||
| 2627 : | var $prefix=''; | ||
| 2628 : | |||
| 2629 : | function mosProfiler( $prefix='' ) { | ||
| 2630 : | $this->start = $this->getmicrotime(); | ||
| 2631 : | $this->prefix = $prefix; | ||
| 2632 : | } | ||
| 2633 : | |||
| 2634 : | function mark( $label ) { | ||
| 2635 : | return sprintf ( "\n<div class=\"profiler\">$this->prefix %.3f $label</div>", $this->getmicrotime() - $this->start ); | ||
| 2636 : | } | ||
| 2637 : | |||
| 2638 : | function getmicrotime(){ | ||
| 2639 : | list($usec, $sec) = explode(" ",microtime()); | ||
| 2640 : | return ((float)$usec + (float)$sec); | ||
| 2641 : | } | ||
| 2642 : | } | ||
| 2643 : | |||
| 2644 : | /** | ||
| 2645 : | * Function to create a mail object for futher use (uses phpMailer) | ||
| 2646 : | * @param string From e-mail address | ||
| 2647 : | * @param string From name | ||
| 2648 : | * @param string E-mail subject | ||
| 2649 : | * @param string Message body | ||
| 2650 : | * @return object Mail object | ||
| 2651 : | */ | ||
| 2652 : | function mosCreateMail( $from='', $fromname='', $subject, $body ) { | ||
| 2653 : | global $mosConfig_absolute_path, $mosConfig_sendmail; | ||
| 2654 : | global $mosConfig_smtpauth, $mosConfig_smtpuser; | ||
| 2655 : | global $mosConfig_smtppass, $mosConfig_smtphost; | ||
| 2656 : | global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_mailer; | ||
| 2657 : | |||
| 2658 : | $mail = new mosPHPMailer(); | ||
| 2659 : | |||
| 2660 : | $mail->PluginDir = $mosConfig_absolute_path .'/includes/phpmailer/'; | ||
| 2661 : | $mail->SetLanguage( 'en', $mosConfig_absolute_path . '/includes/phpmailer/language/' ); | ||
| 2662 : | $mail->CharSet = substr_replace(_ISO, '', 0, 8); | ||
| 2663 : | $mail->IsMail(); | ||
| 2664 : | $mail->From = $from ? $from : $mosConfig_mailfrom; | ||
| 2665 : | $mail->FromName = $fromname ? $fromname : $mosConfig_fromname; | ||
| 2666 : | $mail->Mailer = $mosConfig_mailer; | ||
| 2667 : | |||
| 2668 : | // Add smtp values if needed | ||
| 2669 : | if ( $mosConfig_mailer == 'smtp' ) { | ||
| 2670 : | $mail->SMTPAuth = $mosConfig_smtpauth; | ||
| 2671 : | $mail->Username = $mosConfig_smtpuser; | ||
| 2672 : | $mail->Password = $mosConfig_smtppass; | ||
| 2673 : | $mail->Host = $mosConfig_smtphost; | ||
| 2674 : | } else | ||
| 2675 : | |||
| 2676 : | // Set sendmail path | ||
| 2677 : | if ( $mosConfig_mailer == 'sendmail' ) { | ||
| 2678 : | if (isset($mosConfig_sendmail)) | ||
| 2679 : | $mail->Sendmail = $mosConfig_sendmail; | ||
| 2680 : | } // if | ||
| 2681 : | |||
| 2682 : | $mail->Subject = $subject; | ||
| 2683 : | $mail->Body = $body; | ||
| 2684 : | |||
| 2685 : | return $mail; | ||
| 2686 : | } | ||
| 2687 : | |||
| 2688 : | /** | ||
| 2689 : | * Mail function (uses phpMailer) | ||
| 2690 : | * @param string From e-mail address | ||
| 2691 : | * @param string From name | ||
| 2692 : | * @param string/array Recipient e-mail address(es) | ||
| 2693 : | * @param string E-mail subject | ||
| 2694 : | * @param string Message body | ||
| 2695 : | * @param boolean false = plain text, true = HTML | ||
| 2696 : | * @param string/array CC e-mail address(es) | ||
| 2697 : | * @param string/array BCC e-mail address(es) | ||
| 2698 : | * @param string/array Attachment file name(s) | ||
| 2699 : | * @param string/array Reply-to e-mail address | ||
| 2700 : | * @param string/array Reply-to name | ||
| 2701 : | */ | ||
| 2702 : | function mosMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=NULL, $bcc=NULL, $attachment=NULL, $replyto=NULL, $replytoname=NULL ) { | ||
| 2703 : | global $mosConfig_debug; | ||
| 2704 : | $mail = mosCreateMail( $from, $fromname, $subject, $body ); | ||
| 2705 : | |||
| 2706 : | // activate HTML formatted emails | ||
| 2707 : | if ( $mode ) { | ||
| 2708 : | $mail->IsHTML(true); | ||
| 2709 : | } | ||
| 2710 : | |||
| 2711 : | if( is_array($recipient) ) { | ||
| 2712 : | foreach ($recipient as $to) { | ||
| 2713 : | $mail->AddAddress($to); | ||
| 2714 : | } | ||
| 2715 : | } else { | ||
| 2716 : | $mail->AddAddress($recipient); | ||
| 2717 : | } | ||
| 2718 : | if (isset($cc)) { | ||
| 2719 : | if( is_array($cc) ) | ||
| 2720 : | foreach ($cc as $to) $mail->AddCC($to); | ||
| 2721 : | else | ||
| 2722 : | $mail->AddCC($cc); | ||
| 2723 : | } | ||
| 2724 : | if (isset($bcc)) { | ||
| 2725 : | if( is_array($bcc) ) | ||
| 2726 : | foreach ($bcc as $to) $mail->AddBCC($to); | ||
| 2727 : | else | ||
| 2728 : | $mail->AddBCC($bcc); | ||
| 2729 : | } | ||
| 2730 : | if ($attachment) { | ||
| 2731 : | if ( is_array($attachment) ) | ||
| 2732 : | foreach ($attachment as $fname) $mail->AddAttachment($fname); | ||
| 2733 : | else | ||
| 2734 : | $mail->AddAttachment($attachment); | ||
| 2735 : | } // if | ||
| 2736 : | if ($replyto) { | ||
| 2737 : | if ( is_array($replyto) ) { | ||
| 2738 : | reset($replytoname); | ||
| 2739 : | foreach ($replyto as $to) { | ||
| 2740 : | $toname = ((list($key, $value) = each($replytoname)) | ||
| 2741 : | ? $value : ""); | ||
| 2742 : | $mail->AddReplyTo($to, $toname); | ||
| 2743 : | } | ||
| 2744 : | } else | ||
| 2745 : | $mail->AddReplyTo($replyto, $replytoname); | ||
| 2746 : | } | ||
| 2747 : | $mailssend = $mail->Send(); | ||
| 2748 : | |||
| 2749 : | if( $mosConfig_debug ) { | ||
| 2750 : | //$mosDebug->message( "Mails send: $mailssend"); | ||
| 2751 : | } | ||
| 2752 : | if( $mail->error_count > 0 ) { | ||
| 2753 : | //$mosDebug->message( "The mail message $fromname <$from> about $subject to $recipient <b>failed</b><br /><pre>$body</pre>", false ); | ||
| 2754 : | //$mosDebug->message( "Mailer Error: " . $mail->ErrorInfo . "" ); | ||
| 2755 : | } | ||
| 2756 : | return $mailssend; | ||
| 2757 : | } // mosMail | ||
| 2758 : | |||
| 2759 : | /** | ||
| 2760 : | * Initialise GZIP | ||
| 2761 : | */ | ||
| 2762 : | function initGzip() { | ||
| 2763 : | global $mosConfig_gzip, $do_gzip_compress; | ||
| 2764 : | $do_gzip_compress = FALSE; | ||
| 2765 : | csouza | 39 | |
| 2766 : | root | 1 | //zlib.output_compression and ob_gzhandler don't get along well so we'll check to make |
| 2767 : | //that zlib.output_compression is not enable in the php.ini before turning on ob_gzhandler | ||
| 2768 : | if ( $mosConfig_gzip == 1 && (int)ini_get('zlib.output_compression') != 1 ) { | ||
| 2769 : | $phpver = phpversion(); | ||
| 2770 : | $useragent = mosGetParam( $_SERVER, 'HTTP_USER_AGENT', '' ); | ||
| 2771 : | $canZip = mosGetParam( $_SERVER, 'HTTP_ACCEPT_ENCODING', '' ); | ||
| 2772 : | |||
| 2773 : | if ( $phpver >= '4.0.4pl1' && | ||
| 2774 : | ( strpos($useragent,'compatible') !== false || | ||
| 2775 : | strpos($useragent,'Gecko') !== false | ||
| 2776 : | ) | ||
| 2777 : | ) { | ||
| 2778 : | if ( extension_loaded('zlib') ) { | ||
| 2779 : | ob_start( 'ob_gzhandler' ); | ||
| 2780 : | return; | ||
| 2781 : | } | ||
| 2782 : | } else if ( $phpver > '4.0' ) { | ||
| 2783 : | if ( strpos($canZip,'gzip') !== false ) { | ||
| 2784 : | if (extension_loaded( 'zlib' )) { | ||
| 2785 : | $do_gzip_compress = TRUE; | ||
| 2786 : | ob_start(); | ||
| 2787 : | ob_implicit_flush(0); | ||
| 2788 : | |||
| 2789 : | header( 'Content-Encoding: gzip' ); | ||
| 2790 : | return; | ||
| 2791 : | } | ||
| 2792 : | } | ||
| 2793 : | } | ||
| 2794 : | } | ||
| 2795 : | ob_start(); | ||
| 2796 : | } | ||
| 2797 : | |||
| 2798 : | /** | ||
| 2799 : | * Perform GZIP | ||
| 2800 : | */ | ||
| 2801 : | function doGzip() { | ||
| 2802 : | global $do_gzip_compress; | ||
| 2803 : | if ( $do_gzip_compress ) { | ||
| 2804 : | /** | ||
| 2805 : | *Borrowed from php.net! | ||
| 2806 : | */ | ||
| 2807 : | $gzip_contents = ob_get_contents(); | ||
| 2808 : | ob_end_clean(); | ||
| 2809 : | |||
| 2810 : | $gzip_size = strlen($gzip_contents); | ||
| 2811 : | $gzip_crc = crc32($gzip_contents); | ||
| 2812 : | |||
| 2813 : | $gzip_contents = gzcompress($gzip_contents, 9); | ||
| 2814 : | $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4); | ||
| 2815 : | |||
| 2816 : | echo "\x1f\x8b\x08\x00\x00\x00\x00\x00"; | ||
| 2817 : | echo $gzip_contents; | ||
| 2818 : | echo pack('V', $gzip_crc); | ||
| 2819 : | echo pack('V', $gzip_size); | ||
| 2820 : | } else { | ||
| 2821 : | ob_end_flush(); | ||
| 2822 : | } | ||
| 2823 : | } | ||
| 2824 : | |||
| 2825 : | /** | ||
| 2826 : | * Random password generator | ||
| 2827 : | * @return password | ||
| 2828 : | */ | ||
| 2829 : | function mosMakePassword() { | ||
| 2830 : | $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
| 2831 : | $len = strlen($salt); | ||
| 2832 : | $makepass=""; | ||
| 2833 : | mt_srand(10000000*(double)microtime()); | ||
| 2834 : | for ($i = 0; $i < 8; $i++) | ||
| 2835 : | $makepass .= $salt[mt_rand(0,$len - 1)]; | ||
| 2836 : | return $makepass; | ||
| 2837 : | } | ||
| 2838 : | |||
| 2839 : | if (!function_exists('html_entity_decode')) { | ||
| 2840 : | /** | ||
| 2841 : | * html_entity_decode function for backward compatability in PHP | ||
| 2842 : | * @param string | ||
| 2843 : | * @param string | ||
| 2844 : | */ | ||
| 2845 : | function html_entity_decode ($string, $opt = ENT_COMPAT) { | ||
| 2846 : | |||
| 2847 : | $trans_tbl = get_html_translation_table (HTML_ENTITIES); | ||
| 2848 : | $trans_tbl = array_flip ($trans_tbl); | ||
| 2849 : | |||
| 2850 : | if ($opt & 1) { // Translating single quotes | ||
| 2851 : | // Add single quote to translation table; | ||
| 2852 : | // doesn't appear to be there by default | ||
| 2853 : | $trans_tbl["'"] = "'"; | ||
| 2854 : | } | ||
| 2855 : | |||
| 2856 : | if (!($opt & 2)) { // Not translating double quotes | ||
| 2857 : | // Remove double quote from translation table | ||
| 2858 : | unset($trans_tbl["""]); | ||
| 2859 : | } | ||
| 2860 : | |||
| 2861 : | return strtr ($string, $trans_tbl); | ||
| 2862 : | } | ||
| 2863 : | } | ||
| 2864 : | |||
| 2865 : | /** | ||
| 2866 : | * Plugin handler | ||
| 2867 : | * @package Mambo | ||
| 2868 : | */ | ||
| 2869 : | class mosMambotHandler { | ||
| 2870 : | /** @var array An array of functions in event groups */ | ||
| 2871 : | var $_events=null; | ||
| 2872 : | /** @var array An array of lists */ | ||
| 2873 : | var $_lists=null; | ||
| 2874 : | /** @var array An array of mambots */ | ||
| 2875 : | var $_bots=null; | ||
| 2876 : | /** @var int Index of the mambot being loaded */ | ||
| 2877 : | var $_loading=null; | ||
| 2878 : | |||
| 2879 : | /** | ||
| 2880 : | * Constructor | ||
| 2881 : | */ | ||
| 2882 : | function mosMambotHandler() { | ||
| 2883 : | $this->_events = array(); | ||
| 2884 : | } | ||
| 2885 : | /** | ||
| 2886 : | * Loads all the bot files for a particular group | ||
| 2887 : | * @param string The group name, relates to the sub-directory in the mambots directory | ||
| 2888 : | */ | ||
| 2889 : | function loadBotGroup( $group ) { | ||
| 2890 : | global $database, $my, $mosConfig_absolute_path; | ||
| 2891 : | global $_MAMBOTS; | ||
| 2892 : | |||
| 2893 : | $group = trim( $group ); | ||
| 2894 : | $database->setQuery( "SELECT folder, element, published, CONCAT_WS('/',folder,element) AS lookup" | ||
| 2895 : | . "\nFROM #__mambots" | ||
| 2896 : | . "\nWHERE published >= 1 AND access <= $my->gid AND folder='$group'" | ||
| 2897 : | . "\nORDER BY ordering" | ||
| 2898 : | ); | ||
| 2899 : | if (!($bots = $database->loadObjectList())) { | ||
| 2900 : | //echo "Error loading Mambots: " . $database->getErrorMsg(); | ||
| 2901 : | return false; | ||
| 2902 : | } | ||
| 2903 : | $n = count( $bots); | ||
| 2904 : | for ($i = 0; $i < $n; $i++) { | ||
| 2905 : | $path = $mosConfig_absolute_path . '/mambots/' . $bots[$i]->folder . '/' . $bots[$i]->element . '.php'; | ||
| 2906 : | if (file_exists( $path )) { | ||
| 2907 : | $this->_loading = count( $this->_bots ); | ||
| 2908 : | $this->_bots[] = $bots[$i]; | ||
| 2909 : | require_once( $path ); | ||
| 2910 : | $this->_loading = null; | ||
| 2911 : | } | ||
| 2912 : | } | ||
| 2913 : | return true; | ||
| 2914 : | } | ||
| 2915 : | /** | ||
| 2916 : | * Registers a function to a particular event group | ||
| 2917 : | * @param string The event name | ||
| 2918 : | * @param string The function name | ||
| 2919 : | */ | ||
| 2920 : | function registerFunction( $event, $function ) { | ||
| 2921 : | $this->_events[$event][] = array( $function, $this->_loading ); | ||
| 2922 : | } | ||
| 2923 : | /** | ||
| 2924 : | * Makes a option for a particular list in a group | ||
| 2925 : | * @param string The group name | ||
| 2926 : | * @param string The list name | ||
| 2927 : | * @param string The value for the list option | ||
| 2928 : | * @param string The text for the list option | ||
| 2929 : | */ | ||
| 2930 : | function addListOption( $group, $listName, $value, $text='' ) { | ||
| 2931 : | $this->_lists[$group][$listName][] = mosHTML::makeOption( $value, $text ); | ||
| 2932 : | } | ||
| 2933 : | /** | ||
| 2934 : | * @param string The group name | ||
| 2935 : | * @param string The list name | ||
| 2936 : | * @return array | ||
| 2937 : | */ | ||
| 2938 : | function getList( $group, $listName ) { | ||
| 2939 : | return $this->_lists[$group][$listName]; | ||
| 2940 : | } | ||
| 2941 : | /** | ||
| 2942 : | * Calls all functions associated with an event group | ||
| 2943 : | * @param string The event name | ||
| 2944 : | * @param array An array of arguments | ||
| 2945 : | * @param boolean True is unpublished bots are to be processed | ||
| 2946 : | * @return array An array of results from each function call | ||
| 2947 : | */ | ||
| 2948 : | function trigger( $event, $args=null, $doUnpublished=false ) { | ||
| 2949 : | $result = array(); | ||
| 2950 : | |||
| 2951 : | if ($args === null) { | ||
| 2952 : | $args = array(); | ||
| 2953 : | } | ||
| 2954 : | if ($doUnpublished) { | ||
| 2955 : | // prepend the published argument | ||
| 2956 : | array_unshift( $args, null ); | ||
| 2957 : | } | ||
| 2958 : | if (isset( $this->_events[$event] )) { | ||
| 2959 : | foreach ($this->_events[$event] as $func) { | ||
| 2960 : | if (function_exists( $func[0] )) { | ||
| 2961 : | if ($doUnpublished) { | ||
| 2962 : | $args[0] = $this->_bots[$func[1]]->published; | ||
| 2963 : | $result[] = call_user_func_array( $func[0], $args ); | ||
| 2964 : | } else if ($this->_bots[$func[1]]->published) { | ||
| 2965 : | $result[] = call_user_func_array( $func[0], $args ); | ||
| 2966 : | } | ||
| 2967 : | } | ||
| 2968 : | } | ||
| 2969 : | } | ||
| 2970 : | return $result; | ||
| 2971 : | } | ||
| 2972 : | /** | ||
| 2973 : | * Same as trigger but only returns the first event and | ||
| 2974 : | * allows for a variable argument list | ||
| 2975 : | * @param string The event name | ||
| 2976 : | * @return array The result of the first function call | ||
| 2977 : | */ | ||
| 2978 : | function call( $event ) { | ||
| 2979 : | $doUnpublished=false; | ||
| 2980 : | |||
| 2981 : | $args =& func_get_args(); | ||
| 2982 : | array_shift( $args ); | ||
| 2983 : | |||
| 2984 : | if (isset( $this->_events[$event] )) { | ||
| 2985 : | foreach ($this->_events[$event] as $func) { | ||
| 2986 : | if (function_exists( $func[0] )) { | ||
| 2987 : | if ($this->_bots[$func[1]]->published) { | ||
| 2988 : | return call_user_func_array( $func[0], $args ); | ||
| 2989 : | } | ||
| 2990 : | } | ||
| 2991 : | } | ||
| 2992 : | } | ||
| 2993 : | return null; | ||
| 2994 : | } | ||
| 2995 : | } | ||
| 2996 : | |||
| 2997 : | /** | ||
| 2998 : | * Tab Creation handler | ||
| 2999 : | * @package Mambo | ||
| 3000 : | * @author Phil Taylor | ||
| 3001 : | */ | ||
| 3002 : | class mosTabs { | ||
| 3003 : | /** @var int Use cookies */ | ||
| 3004 : | var $useCookies = 0; | ||
| 3005 : | |||
| 3006 : | /** | ||
| 3007 : | * Constructor | ||
| 3008 : | * Includes files needed for displaying tabs and sets cookie options | ||
| 3009 : | * @param int useCookies, if set to 1 cookie will hold last used tab between page refreshes | ||
| 3010 : | */ | ||
| 3011 : | function mosTabs($useCookies) { | ||
| 3012 : | global $mosConfig_live_site; | ||
| 3013 : | echo "<link id=\"luna-tab-style-sheet\" type=\"text/css\" rel=\"stylesheet\" href=\"" . $mosConfig_live_site. "/includes/js/tabs/tabpane.css\" />"; | ||
| 3014 : | echo "<script type=\"text/javascript\" src=\"". $mosConfig_live_site . "/includes/js/tabs/tabpane.js\"></script>"; | ||
| 3015 : | $this->useCookies = $useCookies; | ||
| 3016 : | } | ||
| 3017 : | |||
| 3018 : | /** | ||
| 3019 : | * creates a tab pane and creates JS obj | ||
| 3020 : | * @param string The Tab Pane Name | ||
| 3021 : | */ | ||
| 3022 : | function startPane($id){ | ||
| 3023 : | echo "<div class=\"tab-page\" id=\"".$id."\">"; | ||
| 3024 : | echo "<script type=\"text/javascript\">\n"; | ||
| 3025 : | echo " var tabPane1 = new WebFXTabPane( document.getElementById( \"".$id."\" ), ".$this->useCookies." )\n"; | ||
| 3026 : | echo "</script>\n"; | ||
| 3027 : | } | ||
| 3028 : | |||
| 3029 : | /** | ||
| 3030 : | * Ends Tab Pane | ||
| 3031 : | */ | ||
| 3032 : | function endPane() { | ||
| 3033 : | echo "</div>"; | ||
| 3034 : | } | ||
| 3035 : | |||
| 3036 : | /* | ||
| 3037 : | * Creates a tab with title text and starts that tabs page | ||
| 3038 : | * @param tabText - This is what is displayed on the tab | ||
| 3039 : | * @param paneid - This is the parent pane to build this tab on | ||
| 3040 : | */ | ||
| 3041 : | function startTab( $tabText, $paneid ) { | ||
| 3042 : | echo "<div class=\"tab-page\" id=\"".$paneid."\">"; | ||
| 3043 : | echo "<h2 class=\"tab\">".$tabText."</h2>"; | ||
| 3044 : | echo "<script type=\"text/javascript\">\n"; | ||
| 3045 : | echo " tabPane1.addTabPage( document.getElementById( \"".$paneid."\" ) );"; | ||
| 3046 : | echo "</script>"; | ||
| 3047 : | } | ||
| 3048 : | |||
| 3049 : | /* | ||
| 3050 : | * Ends a tab page | ||
| 3051 : | */ | ||
| 3052 : | function endTab() { | ||
| 3053 : | echo "</div>"; | ||
| 3054 : | } | ||
| 3055 : | } | ||
| 3056 : | |||
| 3057 : | /** | ||
| 3058 : | * Common HTML Output Files | ||
| 3059 : | * @package Mambo | ||
| 3060 : | */ | ||
| 3061 : | class mosAdminMenus { | ||
| 3062 : | /** | ||
| 3063 : | * build the select list for Menu Ordering | ||
| 3064 : | */ | ||
| 3065 : | function Ordering( &$row, $id ) { | ||
| 3066 : | global $database; | ||
| 3067 : | |||
| 3068 : | if ( $id ) { | ||
| 3069 : | $order = mosGetOrderingList( "SELECT ordering AS value, name AS text" | ||
| 3070 : | . "\n FROM #__menu" | ||
| 3071 : | . "\n WHERE menutype='". $row->menutype ."'" | ||
| 3072 : | . "\n AND parent='". $row->parent ."'" | ||
| 3073 : | . "\n AND published != '-2'" | ||
| 3074 : | . "\n ORDER BY ordering" | ||
| 3075 : | ); | ||
| 3076 : | $ordering = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) ); | ||
| 3077 : | } else { | ||
| 3078 : | csouza | 39 | $ordering = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />'. T_('New items default to the last place. Ordering can be changed after this item is saved.'); |
| 3079 : | root | 1 | } |
| 3080 : | return $ordering; | ||
| 3081 : | } | ||
| 3082 : | |||
| 3083 : | /** | ||
| 3084 : | * build the select list for access level | ||
| 3085 : | */ | ||
| 3086 : | function Access( &$row ) { | ||
| 3087 : | global $database; | ||
| 3088 : | |||
| 3089 : | $query = 'SELECT id AS value, name AS text FROM #__groups ORDER BY id'; | ||
| 3090 : | $database->setQuery( $query ); | ||
| 3091 : | $groups = $database->loadObjectList(); | ||
| 3092 : | $access = mosHTML::selectList( $groups, 'access', 'class="inputbox" size="3"', 'value', 'text', intval( $row->access ) ); | ||
| 3093 : | return $access; | ||
| 3094 : | } | ||
| 3095 : | |||
| 3096 : | /** | ||
| 3097 : | * build the select list for parent item | ||
| 3098 : | */ | ||
| 3099 : | function Parent( &$row ) { | ||
| 3100 : | global $database; | ||
| 3101 : | |||
| 3102 : | // get a list of the menu items | ||
| 3103 : | $query = "SELECT m.*" | ||
| 3104 : | . "\n FROM #__menu m" | ||
| 3105 : | . "\n WHERE menutype='$row->menutype'" | ||
| 3106 : | . "\n AND published <> -2" | ||
| 3107 : | . "\n ORDER BY ordering" | ||
| 3108 : | ; | ||
| 3109 : | $database->setQuery( $query ); | ||
| 3110 : | $mitems = $database->loadObjectList(); | ||
| 3111 : | |||
| 3112 : | // establish the hierarchy of the menu | ||
| 3113 : | $children = array(); | ||
| 3114 : | // first pass - collect children | ||
| 3115 : | foreach ( $mitems as $v ) { | ||
| 3116 : | $pt = $v->parent; | ||
| 3117 : | $list = @$children[$pt] ? $children[$pt] : array(); | ||
| 3118 : | array_push( $list, $v ); | ||
| 3119 : | $children[$pt] = $list; | ||
| 3120 : | } | ||
| 3121 : | // second pass - get an indent list of the items | ||
| 3122 : | $list = mosTreeRecurse( 0, '', array(), $children, 9999, 0, 0 ); | ||
| 3123 : | |||
| 3124 : | // assemble menu items to the array | ||
| 3125 : | $mitems = array(); | ||
| 3126 : | $mitems[] = mosHTML::makeOption( '0', 'Top' ); | ||
| 3127 : | $this_treename = ''; | ||
| 3128 : | foreach ( $list as $item ) { | ||
| 3129 : | if ( $this_treename ) { | ||
| 3130 : | if ( $item->id != $row->id && strpos( $item->treename, $this_treename ) === false) { | ||
| 3131 : | $mitems[] = mosHTML::makeOption( $item->id, $item->treename ); | ||
| 3132 : | } | ||
| 3133 : | } else { | ||
| 3134 : | if ( $item->id != $row->id ) { | ||
| 3135 : | $mitems[] = mosHTML::makeOption( $item->id, $item->treename ); | ||
| 3136 : | } else { | ||
| 3137 : | $this_treename = "$item->treename/"; | ||
| 3138 : | } | ||
| 3139 : | } | ||
| 3140 : | } | ||
| 3141 : | $parent = mosHTML::selectList( $mitems, 'parent', 'class="inputbox" size="1"', 'value', 'text', $row->parent ); | ||
| 3142 : | return $parent; | ||
| 3143 : | } | ||
| 3144 : | |||
| 3145 : | /** | ||
| 3146 : | * build a radio button option for published state | ||
| 3147 : | */ | ||
| 3148 : | function Published( &$row ) { | ||
| 3149 : | $published = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published ); | ||
| 3150 : | return $published; | ||
| 3151 : | } | ||
| 3152 : | |||
| 3153 : | /** | ||
| 3154 : | * build the link/url of a menu item | ||
| 3155 : | */ | ||
| 3156 : | function Link( &$row, $id, $link=NULL ) { | ||
| 3157 : | if ( $id ) { | ||
| 3158 : | if ( $link ) { | ||
| 3159 : | $link = $row->link; | ||
| 3160 : | } else { | ||
| 3161 : | $link = $row->link .'&Itemid='. $row->id; | ||
| 3162 : | } | ||
| 3163 : | } else { | ||
| 3164 : | $link = NULL; | ||
| 3165 : | } | ||
| 3166 : | return $link; | ||
| 3167 : | } | ||
| 3168 : | |||
| 3169 : | /** | ||
| 3170 : | * build the select list for target window | ||
| 3171 : | */ | ||
| 3172 : | function Target( &$row ) { | ||
| 3173 : | csouza | 39 | $click[] = mosHTML::makeOption( '0', T_('Parent Window With Browser Navigation') ); |
| 3174 : | $click[] = mosHTML::makeOption( '1', T_('New Window With Browser Navigation') ); | ||
| 3175 : | $click[] = mosHTML::makeOption( '2', T_('New Window Without Browser Navigation') ); | ||
| 3176 : | root | 1 | $target = mosHTML::selectList( $click, 'browserNav', 'class="inputbox" size="4"', 'value', 'text', intval( $row->browserNav ) ); |
| 3177 : | return $target; | ||
| 3178 : | } | ||
| 3179 : | |||
| 3180 : | /** | ||
| 3181 : | * build the multiple select list for Menu Links/Pages | ||
| 3182 : | */ | ||
| 3183 : | function MenuLinks( &$lookup, $all=NULL, $none=NULL ) { | ||
| 3184 : | global $database; | ||
| 3185 : | |||
| 3186 : | // get a list of the menu items | ||
| 3187 : | $database->setQuery( "SELECT m.*" | ||
| 3188 : | . "\n FROM #__menu m" | ||
| 3189 : | . "\n WHERE type != 'separator'" | ||
| 3190 : | . "\n AND link NOT LIKE '%tp:/%'" | ||
| 3191 : | . "\n AND published = '1'" | ||
| 3192 : | . "\n ORDER BY menutype, parent, ordering" | ||
| 3193 : | ); | ||
| 3194 : | $mitems = $database->loadObjectList(); | ||
| 3195 : | $mitems_temp = $mitems; | ||
| 3196 : | |||
| 3197 : | // establish the hierarchy of the menu | ||
| 3198 : | $children = array(); | ||
| 3199 : | // first pass - collect children | ||
| 3200 : | foreach ( $mitems as $v ) { | ||
| 3201 : | $id = $v->id; | ||
| 3202 : | $pt = $v->parent; | ||
| 3203 : | $list = @$children[$pt] ? $children[$pt] : array(); | ||
| 3204 : | array_push( $list, $v ); | ||
| 3205 : | $children[$pt] = $list; | ||
| 3206 : | } | ||
| 3207 : | // second pass - get an indent list of the items | ||
| 3208 : | $list = mosTreeRecurse( intval( $mitems[0]->parent ), '', array(), $children, 9999, 0, 0 ); | ||
| 3209 : | |||
| 3210 : | // Code that adds menu name to Display of Page(s) | ||
| 3211 : | $text_count = "0"; | ||
| 3212 : | $mitems_spacer = $mitems_temp[0]->menutype; | ||
| 3213 : | foreach ($list as $list_a) { | ||
| 3214 : | foreach ($mitems_temp as $mitems_a) { | ||
| 3215 : | if ($mitems_a->id == $list_a->id) { | ||
| 3216 : | // Code that inserts the blank line that seperates different menus | ||
| 3217 : | if ($mitems_a->menutype <> $mitems_spacer) { | ||
| 3218 : | $list_temp[] = mosHTML::makeOption( -999, '----' ); | ||
| 3219 : | $mitems_spacer = $mitems_a->menutype; | ||
| 3220 : | } | ||
| 3221 : | $text = $mitems_a->menutype." | ".$list_a->treename; | ||
| 3222 : | $list_temp[] = mosHTML::makeOption( $list_a->id, $text ); | ||
| 3223 : | if ( strlen($text) > $text_count) { | ||
| 3224 : | $text_count = strlen($text); | ||
| 3225 : | } | ||
| 3226 : | } | ||
| 3227 : | } | ||
| 3228 : | } | ||
| 3229 : | $list = $list_temp; | ||
| 3230 : | |||
| 3231 : | $mitems = array(); | ||
| 3232 : | if ( $all ) { | ||
| 3233 : | // prepare an array with 'all' as the first item | ||
| 3234 : | csouza | 39 | $mitems[] = mosHTML::makeOption( 0, T_('All') ); |
| 3235 : | root | 1 | // adds space, in select box which is not saved |
| 3236 : | $mitems[] = mosHTML::makeOption( -999, '----' ); | ||
| 3237 : | } | ||
| 3238 : | if ( $none ) { | ||
| 3239 : | // prepare an array with 'all' as the first item | ||
| 3240 : | csouza | 39 | $mitems[] = mosHTML::makeOption( -999, T_('None') ); |
| 3241 : | root | 1 | // adds space, in select box which is not saved |
| 3242 : | $mitems[] = mosHTML::makeOption( -999, '----' ); | ||
| 3243 : | } | ||
| 3244 : | // append the rest of the menu items to the array | ||
| 3245 : | foreach ($list as $item) { | ||
| 3246 : | $mitems[] = mosHTML::makeOption( $item->value, $item->text ); | ||
| 3247 : | } | ||
| 3248 : | $pages = mosHTML::selectList( $mitems, 'selections[]', 'class="inputbox" size="26" multiple="multiple"', 'value', 'text', $lookup ); | ||
| 3249 : | return $pages; | ||
| 3250 : | } | ||
| 3251 : | |||
| 3252 : | |||
| 3253 : | /** | ||
| 3254 : | * build the select list to choose a category | ||
| 3255 : | */ | ||
| 3256 : | function Category( &$menu, $id, $javascript='' ) { | ||
| 3257 : | global $database; | ||
| 3258 : | |||
| 3259 : | $query = "SELECT c.id AS `value`, c.section AS `id`, CONCAT_WS( ' / ', s.title, c.title) AS `text`" | ||
| 3260 : | . "\n FROM #__sections AS s" | ||
| 3261 : | . "\n INNER JOIN #__categories AS c ON c.section = s.id" | ||
| 3262 : | . "\n WHERE s.scope = 'content'" | ||
| 3263 : | . "\n ORDER BY s.name,c.name" | ||
| 3264 : | ; | ||
| 3265 : | $database->setQuery( $query ); | ||
| 3266 : | $rows = $database->loadObjectList(); | ||
| 3267 : | $category = ''; | ||
| 3268 : | if ( $id ) { | ||
| 3269 : | foreach ( $rows as $row ) { | ||
| 3270 : | if ( $row->value == $menu->componentid ) { | ||
| 3271 : | $category = $row->text; | ||
| 3272 : | } | ||
| 3273 : | } | ||
| 3274 : | $category .= '<input type="hidden" name="componentid" value="'. $menu->componentid .'" />'; | ||
| 3275 : | $category .= '<input type="hidden" name="link" value="'. $menu->link .'" />'; | ||
| 3276 : | } else { | ||
| 3277 : | $category = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"'. $javascript, 'value', 'text' ); | ||
| 3278 : | $category .= '<input type="hidden" name="link" value="" />'; | ||
| 3279 : | } | ||
| 3280 : | return $category; | ||
| 3281 : | } | ||
| 3282 : | |||
| 3283 : | /** | ||
| 3284 : | * build the select list to choose a section | ||
| 3285 : | */ | ||
| 3286 : | function Section( &$menu, $id, $all=0 ) { | ||
| 3287 : | global $database; | ||
| 3288 : | |||
| 3289 : | $query = "SELECT s.id AS `value`, s.id AS `id`, s.title AS `text`" | ||
| 3290 : | . "\n FROM #__sections AS s" | ||
| 3291 : | . "\n WHERE s.scope = 'content'" | ||
| 3292 : | . "\n ORDER BY s.name" | ||
| 3293 : | ; | ||
| 3294 : | $database->setQuery( $query ); | ||
| 3295 : | if ( $all ) { | ||
| 3296 : | csouza | 39 | $rows[] = mosHTML::makeOption( 0, T_('- All Sections -') ); |
| 3297 : | root | 1 | $rows = array_merge( $rows, $database->loadObjectList() ); |
| 3298 : | } else { | ||
| 3299 : | $rows = $database->loadObjectList(); | ||
| 3300 : | } | ||
| 3301 : | |||
| 3302 : | if ( $id ) { | ||
| 3303 : | foreach ( $rows as $row ) { | ||
| 3304 : | if ( $row->value == $menu->componentid ) { | ||
| 3305 : | $section = $row->text; | ||
| 3306 : | } | ||
| 3307 : | } | ||
| 3308 : | $section .= '<input type="hidden" name="componentid" value="'. $menu->componentid .'" />'; | ||
| 3309 : | $section .= '<input type="hidden" name="link" value="'. $menu->link .'" />'; | ||
| 3310 : | } else { | ||
| 3311 : | $section = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"', 'value', 'text' ); | ||
| 3312 : | $section .= '<input type="hidden" name="link" value="" />'; | ||
| 3313 : | } | ||
| 3314 : | return $section; | ||
| 3315 : | } | ||
| 3316 : | |||
| 3317 : | /** | ||
| 3318 : | * build the select list to choose a component | ||
| 3319 : | */ | ||
| 3320 : | function Component( &$menu, $id ) { | ||
| 3321 : | global $database; | ||
| 3322 : | |||
| 3323 : | $query = "SELECT c.id AS value, c.name AS text, c.link" | ||
| 3324 : | . "\n FROM #__components AS c" | ||
| 3325 : | . "\n WHERE c.link <> ''" | ||
| 3326 : | . "\n ORDER BY c.name" | ||
| 3327 : | ; | ||
| 3328 : | $database->setQuery( $query ); | ||
| 3329 : | $rows = $database->loadObjectList( ); | ||
| 3330 : | |||
| 3331 : | if ( $id ) { | ||
| 3332 : | // existing component, just show name | ||
| 3333 : | foreach ( $rows as $row ) { | ||
| 3334 : | if ( $row->value == $menu->componentid ) { | ||
| 3335 : | $component = $row->text; | ||
| 3336 : | } | ||
| 3337 : | } | ||
| 3338 : | $component .= '<input type="hidden" name="componentid" value="'. $menu->componentid .'" />'; | ||
| 3339 : | } else { | ||
| 3340 : | $component = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"', 'value', 'text' ); | ||
| 3341 : | } | ||
| 3342 : | return $component; | ||
| 3343 : | } | ||
| 3344 : | |||
| 3345 : | /** | ||
| 3346 : | * build the select list to choose a component | ||
| 3347 : | */ | ||
| 3348 : | function ComponentName( &$menu, $id ) { | ||
| 3349 : | global $database; | ||
| 3350 : | |||
| 3351 : | $query = "SELECT c.id AS value, c.name AS text, c.link" | ||
| 3352 : | . "\n FROM #__components AS c" | ||
| 3353 : | . "\n WHERE c.link <> ''" | ||
| 3354 : | . "\n ORDER BY c.name" | ||
| 3355 : | ; | ||
| 3356 : | $database->setQuery( $query ); | ||
| 3357 : | $rows = $database->loadObjectList( ); | ||
| 3358 : | |||
| 3359 : | $component = 'Component'; | ||
| 3360 : | foreach ( $rows as $row ) { | ||
| 3361 : | if ( $row->value == $menu->componentid ) { | ||
| 3362 : | $component = $row->text; | ||
| 3363 : | } | ||
| 3364 : | } | ||
| 3365 : | |||
| 3366 : | return $component; | ||
| 3367 : | } | ||
| 3368 : | |||
| 3369 : | /** | ||
| 3370 : | * build the select list to choose an image | ||
| 3371 : | */ | ||
| 3372 : | function Images( $name, &$active, $javascript=NULL, $directory=NULL ) { | ||
| 3373 : | global $mosConfig_absolute_path; | ||
| 3374 : | |||
| 3375 : | if ( !$javascript ) { | ||
| 3376 : | $javascript = "onchange=\"javascript:if (document.forms[0].image.options[selectedIndex].value!='') {document.imagelib.src='../images/stories/' + document.forms[0].image.options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\""; | ||
| 3377 : | } | ||
| 3378 : | if ( !$directory ) { | ||
| 3379 : | $directory = '/images/stories'; | ||
| 3380 : | } | ||
| 3381 : | |||
| 3382 : | $imageFiles = mosReadDirectory( $mosConfig_absolute_path . $directory ); | ||
| 3383 : | csouza | 39 | $images = array( mosHTML::makeOption( '', T_('- Select Image -') ) ); |
| 3384 : | root | 1 | foreach ( $imageFiles as $file ) { |
| 3385 : | if ( eregi( "bmp|gif|jpg|png", $file ) ) { | ||
| 3386 : | $images[] = mosHTML::makeOption( $file ); | ||
| 3387 : | } | ||
| 3388 : | } | ||
| 3389 : | $images = mosHTML::selectList( $images, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active ); | ||
| 3390 : | |||
| 3391 : | return $images; | ||
| 3392 : | } | ||
| 3393 : | |||
| 3394 : | /** | ||
| 3395 : | * build the select list for Ordering of a specified Table | ||
| 3396 : | */ | ||
| 3397 : | function SpecificOrdering( &$row, $id, $query, $neworder=0 ) { | ||
| 3398 : | global $database; | ||
| 3399 : | |||
| 3400 : | if ( $neworder ) { | ||
| 3401 : | csouza | 39 | $text = T_('New items default to the first place. Ordering can be changed after this item is saved.'); |
| 3402 : | root | 1 | } else { |
| 3403 : | csouza | 39 | $text = T_('New items default to the last place. Ordering can be changed after this item is saved.'); |
| 3404 : | root | 1 | } |
| 3405 : | |||
| 3406 : | if ( $id ) { | ||
| 3407 : | $order = mosGetOrderingList( $query ); | ||
| 3408 : | $ordering = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) ); | ||
| 3409 : | } else { | ||
| 3410 : | $ordering = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />'. $text; | ||
| 3411 : | } | ||
| 3412 : | return $ordering; | ||
| 3413 : | } | ||
| 3414 : | |||
| 3415 : | /** | ||
| 3416 : | * Select list of active users | ||
| 3417 : | */ | ||
| 3418 : | function UserSelect( $name, $active, $nouser=0, $javascript=NULL, $order='name' ) { | ||
| 3419 : | global $database, $my; | ||
| 3420 : | |||
| 3421 : | $query = "SELECT id AS value, name AS text" | ||
| 3422 : | . "\n FROM #__users" | ||
| 3423 : | . "\n WHERE block = '0'" | ||
| 3424 : | . "\n ORDER BY ". $order | ||
| 3425 : | ; | ||
| 3426 : | $database->setQuery( $query ); | ||
| 3427 : | if ( $nouser ) { | ||
| 3428 : | csouza | 39 | $users[] = mosHTML::makeOption( '0', T_('- No User -') ); |
| 3429 : | root | 1 | $users = array_merge( $users, $database->loadObjectList() ); |
| 3430 : | } else { | ||
| 3431 : | $users = $database->loadObjectList(); | ||
| 3432 : | } | ||
| 3433 : | |||
| 3434 : | $users = mosHTML::selectList( $users, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active ); | ||
| 3435 : | |||
| 3436 : | return $users; | ||
| 3437 : | } | ||
| 3438 : | |||
| 3439 : | /** | ||
| 3440 : | * Select list of positions - generally used for location of images | ||
| 3441 : | */ | ||
| 3442 : | function Positions( $name, $active=NULL, $javascript=NULL, $none=1, $center=1, $left=1, $right=1 ) { | ||
| 3443 : | if ( $none ) { | ||
| 3444 : | csouza | 39 | $pos[] = mosHTML::makeOption( '', T_('None') ); |
| 3445 : | root | 1 | } |
| 3446 : | if ( $center ) { | ||
| 3447 : | csouza | 39 | $pos[] = mosHTML::makeOption( 'center', T_('Center') ); |
| 3448 : | root | 1 | } |
| 3449 : | if ( $left ) { | ||
| 3450 : | csouza | 39 | $pos[] = mosHTML::makeOption( 'left', T_('Left') ); |
| 3451 : | root | 1 | } |
| 3452 : | if ( $right ) { | ||
| 3453 : | csouza | 39 | $pos[] = mosHTML::makeOption( 'right', T_('Right') ); |
| 3454 : | root | 1 | } |
| 3455 : | |||
| 3456 : | $positions = mosHTML::selectList( $pos, $name, 'class="inputbox" size="1"'. $javascript, 'value', 'text', $active ); | ||
| 3457 : | |||
| 3458 : | return $positions; | ||
| 3459 : | } | ||
| 3460 : | |||
| 3461 : | /** | ||
| 3462 : | * Select list of active categories for components | ||
| 3463 : | */ | ||
| 3464 : | function ComponentCategory( $name, $section, $active=NULL, $javascript=NULL, $order='ordering', $size=1, $sel_cat=1 ) { | ||
| 3465 : | global $database; | ||
| 3466 : | |||
| 3467 : | $query = "SELECT id AS value, name AS text" | ||
| 3468 : | . "\n FROM #__categories" | ||
| 3469 : | . "\n WHERE section = '". $section ."'" | ||
| 3470 : | . "\n AND published = '1'" | ||
| 3471 : | . "\n ORDER BY ". $order | ||
| 3472 : | ; | ||
| 3473 : | $database->setQuery( $query ); | ||
| 3474 : | if ( $sel_cat ) { | ||
| 3475 : | csouza | 39 | $categories[] = mosHTML::makeOption( '0', T_('- All Categories -') ); |
| 3476 : | root | 1 | $categories = array_merge( $categories, $database->loadObjectList() ); |
| 3477 : | } else { | ||
| 3478 : | $categories = $database->loadObjectList(); | ||
| 3479 : | } | ||
| 3480 : | |||
| 3481 : | if ( count( $categories ) < 1 ) { | ||
| 3482 : | csouza | 39 | mosRedirect( 'index2.php?option=com_categories§ion='. $section, T_('You must create a category first.') ); |
| 3483 : | root | 1 | } |
| 3484 : | |||
| 3485 : | $category = mosHTML::selectList( $categories, $name, 'class="inputbox" size="'. $size .'" '. $javascript, 'value', 'text', $active ); | ||
| 3486 : | |||
| 3487 : | return $category; | ||
| 3488 : | } | ||
| 3489 : | |||
| 3490 : | /** | ||
| 3491 : | * Select list of active sections | ||
| 3492 : | */ | ||
| 3493 : | function SelectSection( $name, $active=NULL, $javascript=NULL, $order='ordering' ) { | ||
| 3494 : | global $database; | ||
| 3495 : | |||
| 3496 : | csouza | 39 | $categories[] = mosHTML::makeOption( '0', T_('- All Sections -') ); |
| 3497 : | root | 1 | $query = "SELECT id AS value, title AS text" |
| 3498 : | . "\n FROM #__sections" | ||
| 3499 : | . "\n WHERE published = '1'" | ||
| 3500 : | . "\n ORDER BY ". $order | ||
| 3501 : | ; | ||
| 3502 : | $database->setQuery( $query ); | ||
| 3503 : | $sections = array_merge( $categories, $database->loadObjectList() ); | ||
| 3504 : | |||
| 3505 : | $category = mosHTML::selectList( $sections, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active ); | ||
| 3506 : | |||
| 3507 : | return $category; | ||
| 3508 : | } | ||
| 3509 : | |||
| 3510 : | /** | ||
| 3511 : | * Select list of menu items for a specific menu | ||
| 3512 : | */ | ||
| 3513 : | function Links2Menu( $type, $and ) { | ||
| 3514 : | global $database; | ||
| 3515 : | |||
| 3516 : | $query = "SELECT *" | ||
| 3517 : | . "\n FROM #__menu" | ||
| 3518 : | . "\n WHERE type = '". $type ."'" | ||
| 3519 : | . "\n AND published = '1'" | ||
| 3520 : | . $and | ||
| 3521 : | ; | ||
| 3522 : | $database->setQuery( $query ); | ||
| 3523 : | $menus = $database->loadObjectList(); | ||
| 3524 : | |||
| 3525 : | return $menus; | ||
| 3526 : | } | ||
| 3527 : | |||
| 3528 : | /** | ||
| 3529 : | * Select list of menus | ||
| 3530 : | */ | ||
| 3531 : | function MenuSelect( $name='menuselect', $javascript=NULL ) { | ||
| 3532 : | global $database; | ||
| 3533 : | |||
| 3534 : | $query = "SELECT params" | ||
| 3535 : | . "\n FROM #__modules" | ||
| 3536 : | . "\n WHERE module = 'mod_mainmenu'" | ||
| 3537 : | ; | ||
| 3538 : | $database->setQuery( $query ); | ||
| 3539 : | $menus = $database->loadObjectList(); | ||
| 3540 : | $total = count( $menus ); | ||
| 3541 : | for( $i = 0; $i < $total; $i++ ) { | ||
| 3542 : | $params = mosParseParams( $menus[$i]->params ); | ||
| 3543 : | $menuselect[$i]->value = $params->menutype; | ||
| 3544 : | $menuselect[$i]->text = $params->menutype; | ||
| 3545 : | } | ||
| 3546 : | // sort array of objects | ||
| 3547 : | SortArrayObjects( $menuselect, 'text', 1 ); | ||
| 3548 : | |||
| 3549 : | $menus = mosHTML::selectList( $menuselect, $name, 'class="inputbox" size="10" '. $javascript, 'value', 'text' ); | ||
| 3550 : | |||
| 3551 : | return $menus; | ||
| 3552 : | } | ||
| 3553 : | |||
| 3554 : | /** | ||
| 3555 : | * Internal function to recursive scan the media manager directories | ||
| 3556 : | * @param string Path to scan | ||
| 3557 : | * @param string root path of this folder | ||
| 3558 : | * @param array Value array of all existing folders | ||
| 3559 : | * @param array Value array of all existing images | ||
| 3560 : | */ | ||
| 3561 : | function ReadImages( $imagePath, $folderPath, &$folders, &$images ) { | ||
| 3562 : | $imgFiles = mosReadDirectory( $imagePath ); | ||
| 3563 : | |||
| 3564 : | foreach ($imgFiles as $file) { | ||
| 3565 : | $ff_ = $folderPath . $file .'/'; | ||
| 3566 : | $ff = $folderPath . $file; | ||
| 3567 : | $i_f = $imagePath .'/'. $file; | ||
| 3568 : | |||
| 3569 : | if ( is_dir( $i_f ) && $file <> 'CVS' ) { | ||
| 3570 : | $folders[] = mosHTML::makeOption( $ff_ ); | ||
| 3571 : | mosAdminMenus::ReadImages( $i_f, $ff_, $folders, $images ); | ||
| 3572 : | } else if ( eregi( "bmp|gif|jpg|png", $file ) && is_file( $i_f ) ) { | ||
| 3573 : | // leading / we don't need | ||
| 3574 : | $imageFile = substr( $ff, 1 ); | ||
| 3575 : | $images[$folderPath][] = mosHTML::makeOption( $imageFile, $file ); | ||
| 3576 : | } | ||
| 3577 : | } | ||
| 3578 : | } | ||
| 3579 : | |||
| 3580 : | function GetImageFolders( &$folders, $path ) { | ||
| 3581 : | $javascript = "onchange=\"changeDynaList( 'imagefiles', folderimages, document.adminForm.folders.options[document.adminForm.folders.selectedIndex].value, 0, 0); previewImage( 'imagefiles', 'view_imagefiles', '$path/' );\""; | ||
| 3582 : | $getfolders = mosHTML::selectList( $folders, 'folders', 'class="inputbox" size="1" '. $javascript, 'value', 'text', '/' ); | ||
| 3583 : | return $getfolders; | ||
| 3584 : | } | ||
| 3585 : | |||
| 3586 : | function GetImages( &$images, $path ) { | ||
| 3587 : | if ( !isset($images['/'] ) ) { | ||
| 3588 : | $images['/'][] = mosHTML::makeOption( '' ); | ||
| 3589 : | } | ||
| 3590 : | |||
| 3591 : | //$javascript = "onchange=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\" onfocus=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\""; | ||
| 3592 : | $javascript = "onchange=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\""; | ||
| 3593 : | $getimages = mosHTML::selectList( $images['/'], 'imagefiles', 'class="inputbox" size="10" multiple="multiple" '. $javascript , 'value', 'text', null ); | ||
| 3594 : | |||
| 3595 : | return $getimages; | ||
| 3596 : | } | ||
| 3597 : | |||
| 3598 : | function GetSavedImages( &$row, $path ) { | ||
| 3599 : | $images2 = array(); | ||
| 3600 : | foreach( $row->images as $file ) { | ||
| 3601 : | $temp = explode( '|', $file ); | ||
| 3602 : | if( strrchr($temp[0], '/') ) { | ||
| 3603 : | $filename = substr( strrchr($temp[0], '/' ), 1 ); | ||
| 3604 : | } else { | ||
| 3605 : | $filename = $temp[0]; | ||
| 3606 : | } | ||
| 3607 : | $images2[] = mosHTML::makeOption( $file, $filename ); | ||
| 3608 : | } | ||
| 3609 : | //$javascript = "onchange=\"previewImage( 'imagelist', 'view_imagelist', '$path/' ); showImageProps( '$path/' ); \" onfocus=\"previewImage( 'imagelist', 'view_imagelist', '$path/' )\""; | ||
| 3610 : | $javascript = "onchange=\"previewImage( 'imagelist', 'view_imagelist', '$path/' ); showImageProps( '$path/' ); \""; | ||
| 3611 : | $imagelist = mosHTML::selectList( $images2, 'imagelist', 'class="inputbox" size="10" '. $javascript, 'value', 'text' ); | ||
| 3612 : | |||
| 3613 : | return $imagelist; | ||
| 3614 : | } | ||
| 3615 : | |||
| 3616 : | /** | ||
| 3617 : | * Checks to see if an image exists in the current templates image directory | ||
| 3618 : | * if it does it loads this image. Otherwise the default image is loaded. | ||
| 3619 : | * Also can be used in conjunction with the menulist param to create the chosen image | ||
| 3620 : | * load the default or use no image | ||
| 3621 : | */ | ||
| 3622 : | function ImageCheck( $file, $directory='/images/M_images/', $param=NULL, $param_directory='/images/M_images/', $alt=NULL, $name='image', $type=1, $align='middle' ) { | ||
| 3623 : | global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe; | ||
| 3624 : | $cur_template = $mainframe->getTemplate(); | ||
| 3625 : | |||
| 3626 : | if ( $param ) { | ||
| 3627 : | $image = $mosConfig_live_site. $param_directory . $param; | ||
| 3628 : | if ( $type ) { | ||
| 3629 : | $image = '<img src="'. $image .'" align="'. $align .'" alt="'. $alt .'" name="'. $name .'" border="0" />'; | ||
| 3630 : | } | ||
| 3631 : | } else if ( $param == -1 ) { | ||
| 3632 : | $image = ''; | ||
| 3633 : | } else { | ||
| 3634 : | if ( file_exists( $mosConfig_absolute_path .'/templates/'. $cur_template .'/images/'. $file ) ) { | ||
| 3635 : | $image = $mosConfig_live_site .'/templates/'. $cur_template .'/images/'. $file; | ||
| 3636 : | } else { | ||
| 3637 : | // outputs only path to image | ||
| 3638 : | $image = $mosConfig_live_site. $directory . $file; | ||
| 3639 : | } | ||
| 3640 : | |||
| 3641 : | // outputs actual html <img> tag | ||
| 3642 : | if ( $type ) { | ||
| 3643 : | $image = '<img src="'. $image .'" alt="'. $alt .'" align="'. $align .'" name="'. $name .'" border="0" />'; | ||
| 3644 : | } | ||
| 3645 : | } | ||
| 3646 : | |||
| 3647 : | return $image; | ||
| 3648 : | } | ||
| 3649 : | |||
| 3650 : | /** | ||
| 3651 : | * Checks to see if an image exists in the current templates image directory | ||
| 3652 : | * if it does it loads this image. Otherwise the default image is loaded. | ||
| 3653 : | * Also can be used in conjunction with the menulist param to create the chosen image | ||
| 3654 : | * load the default or use no image | ||
| 3655 : | */ | ||
| 3656 : | function ImageCheckAdmin( $file, $directory='/administrator/images/', $param=NULL, $param_directory='/administrator/images/', $alt=NULL, $name=NULL, $type=1, $align='middle' ) { | ||
| 3657 : | global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe; | ||
| 3658 : | $cur_template = $mainframe->getTemplate(); | ||
| 3659 : | |||
| 3660 : | if ( $param ) { | ||
| 3661 : | $image = $mosConfig_live_site. $param_directory . $param; | ||
| 3662 : | if ( $type ) { | ||
| 3663 : | $image = '<img src="'. $image .'" align="'. $align .'" alt="'. $alt .'" name="'. $name .'" border="0" />'; | ||
| 3664 : | } | ||
| 3665 : | } else if ( $param == -1 ) { | ||
| 3666 : | $image = ''; | ||
| 3667 : | } else { | ||
| 3668 : | if ( file_exists( $mosConfig_absolute_path .'/administrator/templates/'. $cur_template .'/images/'. $file ) ) { | ||
| 3669 : | $image = $mosConfig_live_site .'/administrator/templates/'. $cur_template .'/images/'. $file; | ||
| 3670 : | } else { | ||
| 3671 : | $image = $mosConfig_live_site. $directory . $file; | ||
| 3672 : | } | ||
| 3673 : | |||
| 3674 : | // outputs actual html <img> tag | ||
| 3675 : | if ( $type ) { | ||
| 3676 : | $image = '<img src="'. $image .'" alt="'. $alt .'" align="'. $align .'" name="'. $name .'" border="0" />'; | ||
| 3677 : | } | ||
| 3678 : | } | ||
| 3679 : | |||
| 3680 : | return $image; | ||
| 3681 : | } | ||
| 3682 : | |||
| 3683 : | function menutypes() { | ||
| 3684 : | global $database; | ||
| 3685 : | |||
| 3686 : | $query = "SELECT params" | ||
| 3687 : | . "\n FROM #__modules" | ||
| 3688 : | . "\n WHERE module = 'mod_mainmenu'" | ||
| 3689 : | . "\n ORDER BY title" | ||
| 3690 : | ; | ||
| 3691 : | $database->setQuery( $query ); | ||
| 3692 : | $modMenus = $database->loadObjectList(); | ||
| 3693 : | |||
| 3694 : | $query = "SELECT menutype" | ||
| 3695 : | . "\n FROM #__menu" | ||
| 3696 : | . "\n GROUP BY menutype" | ||
| 3697 : | . "\n ORDER BY menutype" | ||
| 3698 : | ; | ||
| 3699 : | $database->setQuery( $query ); | ||
| 3700 : | $menuMenus = $database->loadObjectList(); | ||
| 3701 : | |||
| 3702 : | $menuTypes = ''; | ||
| 3703 : | foreach ( $modMenus as $modMenu ) { | ||
| 3704 : | $check = 1; | ||
| 3705 : | mosMakeHtmlSafe( $modMenu) ; | ||
| 3706 : | $modParams = mosParseParams( $modMenu->params ); | ||
| 3707 : | $menuType = @$modParams->menutype; | ||
| 3708 : | if (!$menuType) { | ||
| 3709 : | $menuType = 'mainmenu'; | ||
| 3710 : | } | ||
| 3711 : | |||
| 3712 : | // stop duplicate menutype being shown | ||
| 3713 : | if ( !is_array( $menuTypes) ) { | ||
| 3714 : | // handling to create initial entry into array | ||
| 3715 : | $menuTypes[] = $menuType; | ||
| 3716 : | } else { | ||
| 3717 : | $check = 1; | ||
| 3718 : | foreach ( $menuTypes as $a ) { | ||
| 3719 : | if ( $a == $menuType ) { | ||
| 3720 : | $check = 0; | ||
| 3721 : | } | ||
| 3722 : | } | ||
| 3723 : | if ( $check ) { | ||
| 3724 : | $menuTypes[] = $menuType; | ||
| 3725 : | } | ||
| 3726 : | } | ||
| 3727 : | |||
| 3728 : | } | ||
| 3729 : | // add menutypes from mos_menu | ||
| 3730 : | foreach ( $menuMenus as $menuMenu ) { | ||
| 3731 : | $check = 1; | ||
| 3732 : | foreach ( $menuTypes as $a ) { | ||
| 3733 : | if ( $a == $menuMenu->menutype ) { | ||
| 3734 : | $check = 0; | ||
| 3735 : | } | ||
| 3736 : | } | ||
| 3737 : | if ( $check ) { | ||
| 3738 : | $menuTypes[] = $menuMenu->menutype; | ||
| 3739 : | } | ||
| 3740 : | } | ||
| 3741 : | |||
| 3742 : | // sorts menutypes | ||
| 3743 : | asort( $menuTypes ); | ||
| 3744 : | |||
| 3745 : | return $menuTypes; | ||
| 3746 : | } | ||
| 3747 : | |||
| 3748 : | /* | ||
| 3749 : | * loads files required for menu items | ||
| 3750 : | */ | ||
| 3751 : | function menuItem( $item ) { | ||
| 3752 : | global $mosConfig_absolute_path; | ||
| 3753 : | |||
| 3754 : | $path = $mosConfig_absolute_path .'/administrator/components/com_menus/'. $item .'/'; | ||
| 3755 : | include_once( $path . $item .'.class.php' ); | ||
| 3756 : | include_once( $path . $item .'.menu.html.php' ); | ||
| 3757 : | } | ||
| 3758 : | } | ||
| 3759 : | |||
| 3760 : | |||
| 3761 : | class mosCommonHTML { | ||
| 3762 : | |||
| 3763 : | function ContentLegend( ) { | ||
| 3764 : | ?> | ||
| 3765 : | <table cellspacing="0" cellpadding="4" border="0" align="center"> | ||
| 3766 : | <tr align="center"> | ||
| 3767 : | <td> | ||
| 3768 : | <img src="images/publish_y.png" width="12" height="12" border="0" alt="Pending" /> | ||
| 3769 : | </td> | ||
| 3770 : | <td> | ||
| 3771 : | csouza | 39 | <?php echo T_('Published, but is <u>Pending</u>') ?> | |
| 3772 : | root | 1 | </td> |
| 3773 : | <td> | ||
| 3774 : | <img src="images/publish_g.png" width="12" height="12" border="0" alt="Visible" /> | ||
| 3775 : | </td> | ||
| 3776 : | <td> | ||
| 3777 : | csouza | 39 | <?php echo T_('Published and is <u>Current</u>') ?> | |
| 3778 : | root | 1 | </td> |
| 3779 : | <td> | ||
| 3780 : | <img src="images/publish_r.png" width="12" height="12" border="0" alt="Finished" /> | ||
| 3781 : | </td> | ||
| 3782 : | <td> | ||
| 3783 : | csouza | 39 | <?php echo T_('Published, but has <u>Expired</u>') ?> | |
| 3784 : | root | 1 | </td> |
| 3785 : | <td> | ||
| 3786 : | <img src="images/publish_x.png" width="12" height="12" border="0" alt="Finished" /> | ||
| 3787 : | </td> | ||
| 3788 : | <td> | ||
| 3789 : | csouza | 39 | <?php echo T_('Not Published') ?> |
| 3790 : | root | 1 | </td> |
| 3791 : | </tr> | ||
| 3792 : | <tr> | ||
| 3793 : | <td colspan="8" align="center"> | ||
| 3794 : | csouza | 39 | <?php echo T_('Click on icon to toggle state.') ?> |
| 3795 : | root | 1 | </td> |
| 3796 : | </tr> | ||
| 3797 : | </table> | ||
| 3798 : | <?php | ||
| 3799 : | } | ||
| 3800 : | |||
| 3801 : | function menuLinksContent( &$menus ) { | ||
| 3802 : | ?> | ||
| 3803 : | <script language="javascript" type="text/javascript"> | ||
| 3804 : | function go2( pressbutton, menu, id ) { | ||
| 3805 : | var form = document.adminForm; | ||
| 3806 : | |||
| 3807 : | if (pressbutton == 'go2menu') { | ||
| 3808 : | form.menu.value = menu; | ||
| 3809 : | submitform( pressbutton ); | ||
| 3810 : | return; | ||
| 3811 : | } | ||
| 3812 : | |||
| 3813 : | if (pressbutton == 'go2menuitem') { | ||
| 3814 : | form.menu.value = menu; | ||
| 3815 : | form.menuid.value = id; | ||
| 3816 : | submitform( pressbutton ); | ||
| 3817 : | return; | ||
| 3818 : | } | ||
| 3819 : | } | ||
| 3820 : | </script> | ||
| 3821 : | <?php | ||
| 3822 : | foreach( $menus as $menu ) { | ||
| 3823 : | ?> | ||
| 3824 : | <tr> | ||
| 3825 : | <td colspan="2"> | ||
| 3826 : | <hr /> | ||
| 3827 : | </td> | ||
| 3828 : | </tr> | ||
| 3829 : | <tr> | ||
| 3830 : | <td width="90px" valign="top"> | ||
| 3831 : | csouza | 39 | <?php echo T_('Menu') ?> |
| 3832 : | root | 1 | </td> |
| 3833 : | <td> | ||
| 3834 : | csouza | 39 | <a href="javascript:go2( 'go2menu', '<?php echo $menu->menutype; ?>' );" title="<?php echo T_('Go to Menu') ?>"> |
| 3835 : | root | 1 | <?php echo $menu->menutype; ?> |
| 3836 : | </a> | ||
| 3837 : | </td> | ||
| 3838 : | </tr> | ||
| 3839 : | <tr> | ||
| 3840 : | <td width="90px" valign="top"> | ||
| 3841 : | csouza | 39 | <?php echo T_('Link Name') ?> |
| 3842 : | root | 1 | </td> |
| 3843 : | <td> | ||
| 3844 : | <strong> | ||
| 3845 : | <a href="javascript:go2( 'go2menuitem', '<?php echo $menu->menutype; ?>', '<?php echo $menu->id; ?>' );" title="Go to Menu Item"> | ||
| 3846 : | <?php echo $menu->name; ?> | ||
| 3847 : | </a> | ||
| 3848 : | </strong> | ||
| 3849 : | </td> | ||
| 3850 : | </tr> | ||
| 3851 : | <tr> | ||
| 3852 : | <td width="90px" valign="top"> | ||
| 3853 : | csouza | 39 | <?php echo T_('State') ?> |
| 3854 : | root | 1 | </td> |
| 3855 : | <td> | ||
| 3856 : | <?php | ||
| 3857 : | switch ( $menu->published ) { | ||
| 3858 : | case -2: | ||
| 3859 : | echo '<font color="red">Trashed</font>'; | ||
| 3860 : | break; | ||
| 3861 : | case 0: | ||
| 3862 : | echo 'UnPublished'; | ||
| 3863 : | break; | ||
| 3864 : | case 1: | ||
| 3865 : | default: | ||
| 3866 : | echo '<font color="green">Published</font>'; | ||
| 3867 : | break; | ||
| 3868 : | } | ||
| 3869 : | ?> | ||
| 3870 : | </td> | ||
| 3871 : | </tr> | ||
| 3872 : | <?php | ||
| 3873 : | } | ||
| 3874 : | ?> | ||
| 3875 : | <input type="hidden" name="menu" value="" /> | ||
| 3876 : | <input type="hidden" name="menuid" value="" /> | ||
| 3877 : | <?php | ||
| 3878 : | } | ||
| 3879 : | |||
| 3880 : | function menuLinksSecCat( &$menus ) { | ||
| 3881 : | ?> | ||
| 3882 : | <script language="javascript" type="text/javascript"> | ||
| 3883 : | function go2( pressbutton, menu, id ) { | ||
| 3884 : | var form = document.adminForm; | ||
| 3885 : | |||
| 3886 : | if (pressbutton == 'go2menu') { | ||
| 3887 : | form.menu.value = menu; | ||
| 3888 : | submitform( pressbutton ); | ||
| 3889 : | return; | ||
| 3890 : | } | ||
| 3891 : | |||
| 3892 : | if (pressbutton == 'go2menuitem') { | ||
| 3893 : | form.menu.value = menu; | ||
| 3894 : | form.menuid.value = id; | ||
| 3895 : | submitform( pressbutton ); | ||
| 3896 : | return; | ||
| 3897 : | } | ||
| 3898 : | } | ||
| 3899 : | </script> | ||
| 3900 : | <?php | ||
| 3901 : | foreach( $menus as $menu ) { | ||
| 3902 : | ?> | ||
| 3903 : | <tr> | ||
| 3904 : | <td colspan="2"> | ||
| 3905 : | <hr/> | ||
| 3906 : | </td> | ||
| 3907 : | </tr> | ||
| 3908 : | <tr> | ||
| 3909 : | <td width="90px" valign="top"> | ||
| 3910 : | csouza | 39 | <?php echo T_('Menu') ?> |
| 3911 : | root | 1 | </td> |
| 3912 : | <td> | ||
| 3913 : | <a href="javascript:go2( 'go2menu', '<?php echo $menu->menutype; ?>' );" title="Go to Menu"> | ||
| 3914 : | <?php echo $menu->menutype; ?> | ||
| 3915 : | </a> | ||
| 3916 : | </td> | ||
| 3917 : | </tr> | ||
| 3918 : | <tr> | ||
| 3919 : | <td width="90px" valign="top"> | ||
| 3920 : | csouza | 39 | <?php echo T_('Type') ?> |
| 3921 : | root | 1 | </td> |
| 3922 : | <td> | ||
| 3923 : | <?php echo $menu->type; ?> | ||
| 3924 : | </td> | ||
| 3925 : | </tr> | ||
| 3926 : | <tr> | ||
| 3927 : | <td width="90px" valign="top"> | ||
| 3928 : | csouza | 39 | <?php echo T_('Item Name') ?> |
| 3929 : | root | 1 | </td> |
| 3930 : | <td> | ||
| 3931 : | <strong> | ||
| 3932 : | <a href="javascript:go2( 'go2menuitem', '<?php echo $menu->menutype; ?>', '<?php echo $menu->id; ?>' );" title="Go to Menu Item"> | ||
| 3933 : | <?php echo $menu->name; ?> | ||
| 3934 : | </a> | ||
| 3935 : | </strong> | ||
| 3936 : | </td> | ||
| 3937 : | </tr> | ||
| 3938 : | <tr> | ||
| 3939 : | <td width="90px" valign="top"> | ||
| 3940 : | csouza | 39 | <?php echo T_('State') ?> |
| 3941 : | root | 1 | </td> |
| 3942 : | <td> | ||
| 3943 : | <?php | ||
| 3944 : | switch ( $menu->published ) { | ||
| 3945 : | case -2: | ||
| 3946 : | csouza | 39 | echo '<font color="red">'.T_('Trashed').'</font>'; |
| 3947 : | root | 1 | break; |
| 3948 : | case 0: | ||
| 3949 : | csouza | 39 | echo T_('UnPublished'); |
| 3950 : | root | 1 | break; |
| 3951 : | case 1: | ||
| 3952 : | default: | ||
| 3953 : | csouza | 39 | echo '<font color="green">'.T_('Published').'</font>'; |
| 3954 : | root | 1 | break; |
| 3955 : | } | ||
| 3956 : | ?> | ||
| 3957 : | </td> | ||
| 3958 : | </tr> | ||
| 3959 : | <?php | ||
| 3960 : | } | ||
| 3961 : | ?> | ||
| 3962 : | <input type="hidden" name="menu" value="" /> | ||
| 3963 : | <input type="hidden" name="menuid" value="" /> | ||
| 3964 : | <?php | ||
| 3965 : | } | ||
| 3966 : | |||
| 3967 : | function checkedOut( &$row, $overlib=1 ) { | ||
| 3968 : | $hover = ''; | ||
| 3969 : | if ( $overlib ) { | ||
| 3970 : | $date = mosFormatDate( $row->checked_out_time, '%A, %d %B %Y' ); | ||
| 3971 : | $time = mosFormatDate( $row->checked_out_time, '%H:%M' ); | ||
| 3972 : | $checked_out_text = '<table>'; | ||
| 3973 : | $checked_out_text .= '<tr><td>'. $row->editor .'</td></tr>'; | ||
| 3974 : | $checked_out_text .= '<tr><td>'. $date .'</td></tr>'; | ||
| 3975 : | $checked_out_text .= '<tr><td>'. $time .'</td></tr>'; | ||
| 3976 : | $checked_out_text .= '</table>'; | ||
| 3977 : | $hover = 'onMouseOver="return overlib(\''. $checked_out_text .'\', CAPTION, \'Checked Out\', BELOW, RIGHT);" onMouseOut="return nd();"'; | ||
| 3978 : | } | ||
| 3979 : | $checked = '<img src="images/checked_out.png" '. $hover .'/>'; | ||
| 3980 : | |||
| 3981 : | return $checked; | ||
| 3982 : | } | ||
| 3983 : | |||
| 3984 : | /* | ||
| 3985 : | * Loads all necessary files for JS Overlib tooltips | ||
| 3986 : | */ | ||
| 3987 : | function loadOverlib() { | ||
| 3988 : | global $mosConfig_live_site; | ||
| 3989 : | ?> | ||
| 3990 : | <script language="Javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/overlib_mini.js"></script> | ||
| 3991 : | <div id="overDiv" style="position:absolute; visibility:hidden; z-index:10000;"></div> | ||
| 3992 : | <?php | ||
| 3993 : | } | ||
| 3994 : | |||
| 3995 : | |||
| 3996 : | /* | ||
| 3997 : | * Loads all necessary files for JS Calendar | ||
| 3998 : | */ | ||
| 3999 : | function loadCalendar() { | ||
| 4000 : | global $mosConfig_live_site; | ||
| 4001 : | ?> | ||
| 4002 : | <link rel="stylesheet" type="text/css" media="all" href="<?php echo $mosConfig_live_site;?>/includes/js/calendar/calendar-mos.css" title="green" /> | ||
| 4003 : | <!-- import the calendar script --> | ||
| 4004 : | <script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/calendar/calendar.js"></script> | ||
| 4005 : | <!-- import the language module --> | ||
| 4006 : | <script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/calendar/lang/calendar-en.js"></script> | ||
| 4007 : | <?php | ||
| 4008 : | } | ||
| 4009 : | |||
| 4010 : | function AccessProcessing( &$row, $i ) { | ||
| 4011 : | if ( !$row->access ) { | ||
| 4012 : | $color_access = 'style="color: green;"'; | ||
| 4013 : | $task_access = 'accessregistered'; | ||
| 4014 : | } else if ( $row->access == 1 ) { | ||
| 4015 : | $color_access = 'style="color: red;"'; | ||
| 4016 : | $task_access = 'accessspecial'; | ||
| 4017 : | } else { | ||
| 4018 : | $color_access = 'style="color: black;"'; | ||
| 4019 : | $task_access = 'accesspublic'; | ||
| 4020 : | } | ||
| 4021 : | |||
| 4022 : | $href = ' | ||
| 4023 : | <a href="javascript: void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task_access .'\')" '. $color_access .'> | ||
| 4024 : | '. $row->groupname .' | ||
| 4025 : | </a>' | ||
| 4026 : | ; | ||
| 4027 : | |||
| 4028 : | return $href; | ||
| 4029 : | } | ||
| 4030 : | |||
| 4031 : | function CheckedOutProcessing( &$row, $i ) { | ||
| 4032 : | global $my; | ||
| 4033 : | |||
| 4034 : | if ( $row->checked_out ) { | ||
| 4035 : | $checked = mosCommonHTML::checkedOut( $row ); | ||
| 4036 : | } else { | ||
| 4037 : | $checked = mosHTML::idBox( $i, $row->id, ($row->checked_out && $row->checked_out != $my->id ) ); | ||
| 4038 : | } | ||
| 4039 : | |||
| 4040 : | return $checked; | ||
| 4041 : | } | ||
| 4042 : | |||
| 4043 : | function PublishedProcessing( &$row, $i ) { | ||
| 4044 : | $img = $row->published ? 'publish_g.png' : 'publish_x.png'; | ||
| 4045 : | $task = $row->published ? 'unpublish' : 'publish'; | ||
| 4046 : | csouza | 39 | $alt = $row->published ? T_('Published' ): T_('Unpublished'); |
| 4047 : | $action = $row->published ? T_('Unpublish Item') : T_('Publish item'); | ||
| 4048 : | root | 1 | |
| 4049 : | $href = ' | ||
| 4050 : | <a href="javascript: void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task .'\')" title="'. $action .'"> | ||
| 4051 : | <img src="images/'. $img .'" border="0" alt="'. $alt .'" /> | ||
| 4052 : | </a>' | ||
| 4053 : | ; | ||
| 4054 : | |||
| 4055 : | return $href; | ||
| 4056 : | } | ||
| 4057 : | } | ||
| 4058 : | |||
| 4059 : | /** | ||
| 4060 : | * Sorts an Array of objects | ||
| 4061 : | */ | ||
| 4062 : | function SortArrayObjects_cmp( &$a, &$b ) { | ||
| 4063 : | global $csort_cmp; | ||
| 4064 : | |||
| 4065 : | if ( $a->$csort_cmp['key'] > $b->$csort_cmp['key'] ) { | ||
| 4066 : | return $csort_cmp['direction']; | ||
| 4067 : | } | ||
| 4068 : | |||
| 4069 : | if ( $a->$csort_cmp['key'] < $b->$csort_cmp['key'] ) { | ||
| 4070 : | return -1 * $csort_cmp['direction']; | ||
| 4071 : | } | ||
| 4072 : | |||
| 4073 : | return 0; | ||
| 4074 : | } | ||
| 4075 : | |||
| 4076 : | /** | ||
| 4077 : | * Sorts an Array of objects | ||
| 4078 : | * sort_direction [1 = Ascending] [-1 = Descending] | ||
| 4079 : | */ | ||
| 4080 : | function SortArrayObjects( &$a, $k, $sort_direction=1 ) { | ||
| 4081 : | global $csort_cmp; | ||
| 4082 : | |||
| 4083 : | $csort_cmp = array( | ||
| 4084 : | 'key' => $k, | ||
| 4085 : | 'direction' => $sort_direction | ||
| 4086 : | ); | ||
| 4087 : | |||
| 4088 : | usort( $a, 'SortArrayObjects_cmp' ); | ||
| 4089 : | |||
| 4090 : | unset( $csort_cmp ); | ||
| 4091 : | } | ||
| 4092 : | |||
| 4093 : | /** | ||
| 4094 : | * Sends mail to admin | ||
| 4095 : | */ | ||
| 4096 : | function mosSendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author ) { | ||
| 4097 : | global $mosConfig_live_site; | ||
| 4098 : | |||
| 4099 : | csouza | 39 | $subject = T_('User Submitted')." '$type'"; |
| 4100 : | $message = T_('_MAIL_MSG'); | ||
| 4101 : | $message = sprintf(T_('Hello %s,\n\n\nA user submitted %s:\n [ %s ]\n has been just been submitted by user:\n [ %s ]\n for %s.\n\n\n\n | ||
| 4102 : | Please go to %s/administrator to view and approve this %s.\n\n | ||
| 4103 : | Please do not respond to this message as it is automatically generated and is for information purposes only\n'), $adminName, $type, $title, $author, $mosConfig_live_site, $mosConfig_live_site, $type); | ||
| 4104 : | root | 1 | mosMail($mosConfig_mailfrom, $mosConfig_fromname, $adminEmail, $subject, $message); |
| 4105 : | } | ||
| 4106 : | |||
| 4107 : | /* | ||
| 4108 : | * Includes pathway file | ||
| 4109 : | */ | ||
| 4110 : | function mosPathWay() { | ||
| 4111 : | $Itemid = mosGetParam($_REQUEST,'Itemid',''); | ||
| 4112 : | require $GLOBALS['mosConfig_absolute_path'] . '/includes/pathway.php'; | ||
| 4113 : | } | ||
| 4114 : | |||
| 4115 : | /** | ||
| 4116 : | * Displays a not authorised message | ||
| 4117 : | * | ||
| 4118 : | * If the user is not logged in then an addition message is displayed. | ||
| 4119 : | */ | ||
| 4120 : | function mosNotAuth() { | ||
| 4121 : | global $my; | ||
| 4122 : | |||
| 4123 : | csouza | 39 | echo T_('You are not authorized to view this resource.'); |
| 4124 : | root | 1 | if ($my->id < 1) { |
| 4125 : | csouza | 39 | echo "<br />" . T_('You need to login.'); |
| 4126 : | root | 1 | } |
| 4127 : | } | ||
| 4128 : | |||
| 4129 : | /** | ||
| 4130 : | * Replaces & with & for xhtml compliance | ||
| 4131 : | * | ||
| 4132 : | * Needed to handle unicode conflicts due to unicode conflicts | ||
| 4133 : | */ | ||
| 4134 : | function ampReplace( $text ) { | ||
| 4135 : | $text = str_replace( '&#', '*-*', $text ); | ||
| 4136 : | $text = str_replace( '&', '&', $text ); | ||
| 4137 : | $text = str_replace( '*-*', '&#', $text ); | ||
| 4138 : | |||
| 4139 : | return $text; | ||
| 4140 : | } | ||
| 4141 : | |||
| 4142 : | /** | ||
| 4143 : | * Prepares results from search for display | ||
| 4144 : | * @param string The source string | ||
| 4145 : | * @param int Number of chars to trim | ||
| 4146 : | * @param string The searchword to select around | ||
| 4147 : | * @return string | ||
| 4148 : | */ | ||
| 4149 : | function mosPrepareSearchContent( $text, $length=200, $searchword ) { | ||
| 4150 : | // strips tags won't remove the actual jscript | ||
| 4151 : | $text = preg_replace( "'<script[^>]*>.*?</script>'si", "", $text ); | ||
| 4152 : | $text = preg_replace( '/{.+?}/', '', $text); | ||
| 4153 : | //$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2', $text ); | ||
| 4154 : | return mosSmartSubstr( strip_tags( $text ), $length, $searchword ); | ||
| 4155 : | } | ||
| 4156 : | |||
| 4157 : | /** | ||
| 4158 : | * returns substring of characters around a searchword | ||
| 4159 : | * @param string The source string | ||
| 4160 : | * @param int Number of chars to return | ||
| 4161 : | * @param string The searchword to select around | ||
| 4162 : | * @return string | ||
| 4163 : | */ | ||
| 4164 : | function mosSmartSubstr($text, $length=200, $searchword) { | ||
| 4165 : | $wordpos = strpos(strtolower($text), strtolower($searchword)); | ||
| 4166 : | $halfside = intval($wordpos - $length/2 - strlen($searchword)); | ||
| 4167 : | if ($wordpos && $halfside > 0) { | ||
| 4168 : | return '...' . substr($text, $halfside, $length); | ||
| 4169 : | } else { | ||
| 4170 : | return substr( $text, 0, $length); | ||
| 4171 : | } | ||
| 4172 : | } | ||
| 4173 : | |||
| 4174 : | /** | ||
| 4175 : | * Chmods files and directories recursively to given permissions. Available from 4.5.2 up. | ||
| 4176 : | * @param path The starting file or directory (no trailing slash) | ||
| 4177 : | * @param filemode Integer value to chmod files. NULL = dont chmod files. | ||
| 4178 : | * @param dirmode Integer value to chmod directories. NULL = dont chmod directories. | ||
| 4179 : | * @return TRUE=all succeeded FALSE=one or more chmods failed | ||
| 4180 : | */ | ||
| 4181 : | function mosChmodRecursive($path, $filemode=NULL, $dirmode=NULL) | ||
| 4182 : | { | ||
| 4183 : | $ret = TRUE; | ||
| 4184 : | if (is_dir($path)) { | ||
| 4185 : | $dh = opendir($path); | ||
| 4186 : | while ($file = readdir($dh)) { | ||
| 4187 : | if ($file != '.' && $file != '..') { | ||
| 4188 : | $fullpath = $path.'/'.$file; | ||
| 4189 : | if (is_dir($fullpath)) { | ||
| 4190 : | if (!mosChmodRecursive($fullpath, $filemode, $dirmode)) | ||
| 4191 : | $ret = FALSE; | ||
| 4192 : | } else { | ||
| 4193 : | if (isset($filemode)) | ||
| 4194 : | if (!@chmod($fullpath, $filemode)) | ||
| 4195 : | $ret = FALSE; | ||
| 4196 : | } // if | ||
| 4197 : | } // if | ||
| 4198 : | } // while | ||
| 4199 : | closedir($dh); | ||
| 4200 : | if (isset($dirmode)) | ||
| 4201 : | if (!@chmod($path, $dirmode)) | ||
| 4202 : | $ret = FALSE; | ||
| 4203 : | } else { | ||
| 4204 : | if (isset($filemode)) | ||
| 4205 : | $ret = @chmod($path, $filemode); | ||
| 4206 : | } // if | ||
| 4207 : | return $ret; | ||
| 4208 : | } // mosChmodRecursive | ||
| 4209 : | |||
| 4210 : | /** | ||
| 4211 : | * Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up. | ||
| 4212 : | * @param path The starting file or directory (no trailing slash) | ||
| 4213 : | * @param filemode Integer value to chmod files. NULL = dont chmod files. | ||
| 4214 : | * @param dirmode Integer value to chmod directories. NULL = dont chmod directories. | ||
| 4215 : | * @return TRUE=all succeeded FALSE=one or more chmods failed | ||
| 4216 : | */ | ||
| 4217 : | function mosChmod($path) | ||
| 4218 : | { | ||
| 4219 : | global $mosConfig_fileperms, $mosConfig_dirperms; | ||
| 4220 : | $filemode = NULL; | ||
| 4221 : | if ($mosConfig_fileperms != '') | ||
| 4222 : | $filemode = octdec($mosConfig_fileperms); | ||
| 4223 : | $dirmode = NULL; | ||
| 4224 : | if ($mosConfig_dirperms != '') | ||
| 4225 : | $dirmode = octdec($mosConfig_dirperms); | ||
| 4226 : | if (isset($filemode) || isset($dirmode)) | ||
| 4227 : | return mosChmodRecursive($path, $filemode, $dirmode); | ||
| 4228 : | return TRUE; | ||
| 4229 : | } // mosChmod | ||
| 4230 : | |||
| 4231 : | /** | ||
| 4232 : | * Function to convert array to integer values | ||
| 4233 : | */ | ||
| 4234 : | function mosArrayToInts( &$array, $default=null ) { | ||
| 4235 : | if (is_array( $array )) { | ||
| 4236 : | $n = count( $array ); | ||
| 4237 : | for ($i = 0; $i < $n; $i++) { | ||
| 4238 : | $array[$i] = intval( $array[$i] ); | ||
| 4239 : | } | ||
| 4240 : | } else { | ||
| 4241 : | if (is_null( $default )) { | ||
| 4242 : | return array(); | ||
| 4243 : | } else { | ||
| 4244 : | return array( $default ); | ||
| 4245 : | } | ||
| 4246 : | } | ||
| 4247 : | } | ||
| 4248 : | |||
| 4249 : | // ----- NO MORE CLASSES OR FUNCTIONS PASSED THIS POINT ----- | ||
| 4250 : | // Post class declaration initialisations | ||
| 4251 : | // some version of PHP don't allow the instantiation of classes | ||
| 4252 : | // before they are defined | ||
| 4253 : | |||
| 4254 : | /** @global mosPlugin $_MAMBOTS */ | ||
| 4255 : | $_MAMBOTS = new mosMambotHandler(); | ||
| 4256 : | csouza | 39 | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

