PageRenderTime 52ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_patch/patch/includes/joomla.php.jaclplus.bak

https://github.com/viollarr/alab
Unknown | 6152 lines | 5473 code | 679 blank | 0 comment | 0 complexity | 998a564579c53c8be5b6ba652266a75a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-3.0, Apache-2.0, BSD-3-Clause, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @version $Id: joomla.php 9997 2008-02-07 11:27:04Z eddieajau $
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. // no direct access
  14. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  15. define( '_MOS_MAMBO_INCLUDED', 1 );
  16. /**
  17. * Page generation time
  18. * @package Joomla
  19. */
  20. class mosProfiler {
  21. /** @var int Start time stamp */
  22. var $start=0;
  23. /** @var string A prefix for mark messages */
  24. var $prefix='';
  25. /**
  26. * Constructor
  27. * @param string A prefix for mark messages
  28. */
  29. function mosProfiler( $prefix='' ) {
  30. $this->start = $this->getmicrotime();
  31. $this->prefix = $prefix;
  32. }
  33. /**
  34. * @return string A format message of the elapsed time
  35. */
  36. function mark( $label ) {
  37. return sprintf ( "\n<div class=\"profiler\">$this->prefix %.3f $label</div>", $this->getmicrotime() - $this->start );
  38. }
  39. /**
  40. * @return float The current time in milliseconds
  41. */
  42. function getmicrotime(){
  43. list($usec, $sec) = explode(" ",microtime());
  44. return ((float)$usec + (float)$sec);
  45. }
  46. }
  47. if (phpversion() < '4.2.0') {
  48. require_once( dirname( __FILE__ ) . '/compat.php41x.php' );
  49. }
  50. if (phpversion() < '4.3.0') {
  51. require_once( dirname( __FILE__ ) . '/compat.php42x.php' );
  52. }
  53. if (version_compare( phpversion(), '5.0' ) < 0) {
  54. require_once( dirname( __FILE__ ) . '/compat.php50x.php' );
  55. }
  56. @set_magic_quotes_runtime( 0 );
  57. if ( @$mosConfig_error_reporting === 0 || @$mosConfig_error_reporting === '0' ) {
  58. error_reporting( 0 );
  59. } else if (@$mosConfig_error_reporting > 0) {
  60. error_reporting( $mosConfig_error_reporting );
  61. }
  62. require_once( $mosConfig_absolute_path . '/includes/version.php' );
  63. require_once( $mosConfig_absolute_path . '/includes/database.php' );
  64. require_once( $mosConfig_absolute_path . '/includes/gacl.class.php' );
  65. require_once( $mosConfig_absolute_path . '/includes/gacl_api.class.php' );
  66. require_once( $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php' );
  67. require_once( $mosConfig_absolute_path . '/includes/joomla.xml.php' );
  68. require_once( $mosConfig_absolute_path . '/includes/phpInputFilter/class.inputfilter.php' );
  69. $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  70. if ($database->getErrorNum()) {
  71. $mosSystemError = $database->getErrorNum();
  72. $basePath = dirname( __FILE__ );
  73. include $basePath . '/../configuration.php';
  74. include $basePath . '/../offline.php';
  75. exit();
  76. }
  77. $database->debug( $mosConfig_debug );
  78. $acl = new gacl_api();
  79. // platform neurtral url handling
  80. if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  81. $request_uri = $_SERVER['REQUEST_URI'];
  82. } else {
  83. $request_uri = $_SERVER['SCRIPT_NAME'];
  84. // Append the query string if it exists and isn't null
  85. if ( isset( $_SERVER['QUERY_STRING'] ) && !empty( $_SERVER['QUERY_STRING'] ) ) {
  86. $request_uri .= '?' . $_SERVER['QUERY_STRING'];
  87. }
  88. }
  89. $_SERVER['REQUEST_URI'] = $request_uri;
  90. // current server time
  91. $now = date( 'Y-m-d H:i', time() );
  92. DEFINE( '_CURRENT_SERVER_TIME', $now );
  93. DEFINE( '_CURRENT_SERVER_TIME_FORMAT', '%Y-%m-%d %H:%M:%S' );
  94. // Non http/https URL Schemes
  95. $url_schemes = 'data:, file:, ftp:, gopher:, imap:, ldap:, mailto:, news:, nntp:, telnet:, javascript:, irc:, mms:';
  96. DEFINE( '_URL_SCHEMES', $url_schemes );
  97. // disable strict mode in MySQL 5
  98. if (!defined( '_JOS_SET_SQLMODE' )) {
  99. /** ensure that functions are declared only once */
  100. define( '_JOS_SET_SQLMODE', 1 );
  101. // if running mysql 5, set sql-mode to mysql40 - thereby circumventing strict mode problems
  102. if ( strpos( $database->getVersion(), '5' ) === 0 ) {
  103. $query = "SET sql_mode = 'MYSQL40'";
  104. $database->setQuery( $query );
  105. $database->query();
  106. }
  107. }
  108. /**
  109. * @package Joomla
  110. * @abstract
  111. */
  112. class mosAbstractLog {
  113. /** @var array */
  114. var $_log = null;
  115. /**
  116. * Constructor
  117. */
  118. function mosAbstractLog() {
  119. $this->__constructor();
  120. }
  121. /**
  122. * Generic constructor
  123. */
  124. function __constructor() {
  125. $this->_log = array();
  126. }
  127. /**
  128. * @param string Log message
  129. * @param boolean True to append to last message
  130. */
  131. function log( $text, $append=false ) {
  132. $n = count( $this->_log );
  133. if ($append && $n > 0) {
  134. $this->_log[count( $this->_log )-1] .= $text;
  135. } else {
  136. $this->_log[] = $text;
  137. }
  138. }
  139. /**
  140. * @param string The glue for each log item
  141. * @return string Returns the log
  142. */
  143. function getLog( $glue='<br/>', $truncate=9000, $htmlSafe=false ) {
  144. $logs = array();
  145. foreach ($this->_log as $log) {
  146. if ($htmlSafe) {
  147. $log = htmlspecialchars( $log );
  148. }
  149. $logs[] = substr( $log, 0, $truncate );
  150. }
  151. return implode( $glue, $logs );
  152. }
  153. }
  154. /**
  155. * Task routing class
  156. * @package Joomla
  157. * @abstract
  158. */
  159. class mosAbstractTasker {
  160. /** @var array An array of the class methods to call for a task */
  161. var $_taskMap = null;
  162. /** @var string The name of the current task*/
  163. var $_task = null;
  164. /** @var array An array of the class methods*/
  165. var $_methods = null;
  166. /** @var string A url to redirect to */
  167. var $_redirect = null;
  168. /** @var string A message about the operation of the task */
  169. var $_message = null;
  170. // action based access control
  171. /** @var string The ACO Section */
  172. var $_acoSection = null;
  173. /** @var string The ACO Section value */
  174. var $_acoSectionValue = null;
  175. /**
  176. * Constructor
  177. * @param string Set the default task
  178. */
  179. function mosAbstractTasker( $default='' ) {
  180. $this->_taskMap = array();
  181. $this->_methods = array();
  182. foreach (get_class_methods( get_class( $this ) ) as $method) {
  183. if (substr( $method, 0, 1 ) != '_') {
  184. $this->_methods[] = strtolower( $method );
  185. // auto register public methods as tasks
  186. $this->_taskMap[strtolower( $method )] = $method;
  187. }
  188. }
  189. $this->_redirect = '';
  190. $this->_message = '';
  191. if ($default) {
  192. $this->registerDefaultTask( $default );
  193. }
  194. }
  195. /**
  196. * Sets the access control levels
  197. * @param string The ACO section (eg, the component)
  198. * @param string The ACO section value (if using a constant value)
  199. */
  200. function setAccessControl( $section, $value=null ) {
  201. $this->_acoSection = $section;
  202. $this->_acoSectionValue = $value;
  203. }
  204. /**
  205. * Access control check
  206. */
  207. function accessCheck( $task ) {
  208. global $acl, $my;
  209. // only check if the derived class has set these values
  210. if ($this->_acoSection) {
  211. // ensure user has access to this function
  212. if ($this->_acoSectionValue) {
  213. // use a 'constant' task for this task handler
  214. $task = $this->_acoSectionValue;
  215. }
  216. return $acl->acl_check( $this->_acoSection, $task, 'users', $my->usertype );
  217. } else {
  218. return true;
  219. }
  220. }
  221. /**
  222. * Set a URL to redirect the browser to
  223. * @param string A URL
  224. */
  225. function setRedirect( $url, $msg = null ) {
  226. $this->_redirect = $url;
  227. if ($msg !== null) {
  228. $this->_message = $msg;
  229. }
  230. }
  231. /**
  232. * Redirects the browser
  233. */
  234. function redirect() {
  235. if ($this->_redirect) {
  236. mosRedirect( $this->_redirect, $this->_message );
  237. }
  238. }
  239. /**
  240. * Register (map) a task to a method in the class
  241. * @param string The task
  242. * @param string The name of the method in the derived class to perform for this task
  243. */
  244. function registerTask( $task, $method ) {
  245. if (in_array( strtolower( $method ), $this->_methods )) {
  246. $this->_taskMap[strtolower( $task )] = $method;
  247. } else {
  248. $this->methodNotFound( $method );
  249. }
  250. }
  251. /**
  252. * Register the default task to perfrom if a mapping is not found
  253. * @param string The name of the method in the derived class to perform if the task is not found
  254. */
  255. function registerDefaultTask( $method ) {
  256. $this->registerTask( '__default', $method );
  257. }
  258. /**
  259. * Perform a task by triggering a method in the derived class
  260. * @param string The task to perform
  261. * @return mixed The value returned by the function
  262. */
  263. function performTask( $task ) {
  264. $this->_task = $task;
  265. $task = strtolower( $task );
  266. if (isset( $this->_taskMap[$task] )) {
  267. $doTask = $this->_taskMap[$task];
  268. } else if (isset( $this->_taskMap['__default'] )) {
  269. $doTask = $this->_taskMap['__default'];
  270. } else {
  271. return $this->taskNotFound( $this->_task );
  272. }
  273. if ($this->accessCheck( $doTask )) {
  274. return call_user_func( array( &$this, $doTask ) );
  275. } else {
  276. return $this->notAllowed( $task );
  277. }
  278. }
  279. /**
  280. * Get the last task that was to be performed
  281. * @return string The task that was or is being performed
  282. */
  283. function getTask() {
  284. return $this->_task;
  285. }
  286. /**
  287. * Basic method if the task is not found
  288. * @param string The task
  289. * @return null
  290. */
  291. function taskNotFound( $task ) {
  292. echo 'Task ' . $task . ' not found';
  293. return null;
  294. }
  295. /**
  296. * Basic method if the registered method is not found
  297. * @param string The name of the method in the derived class
  298. * @return null
  299. */
  300. function methodNotFound( $name ) {
  301. echo 'Method ' . $name . ' not found';
  302. return null;
  303. }
  304. /**
  305. * Basic method if access is not permitted to the task
  306. * @param string The name of the method in the derived class
  307. * @return null
  308. */
  309. function notAllowed( $name ) {
  310. echo _NOT_AUTH;
  311. return null;
  312. }
  313. }
  314. /**
  315. * Class to support function caching
  316. * @package Joomla
  317. */
  318. class mosCache {
  319. /**
  320. * @return object A function cache object
  321. */
  322. function &getCache( $group='' ) {
  323. global $mosConfig_absolute_path, $mosConfig_caching, $mosConfig_cachepath, $mosConfig_cachetime;
  324. require_once( $mosConfig_absolute_path . '/includes/joomla.cache.php' );
  325. $options = array(
  326. 'cacheDir' => $mosConfig_cachepath . '/',
  327. 'caching' => $mosConfig_caching,
  328. 'defaultGroup' => $group,
  329. 'lifeTime' => $mosConfig_cachetime
  330. );
  331. $cache = new JCache_Lite_Function( $options );
  332. return $cache;
  333. }
  334. /**
  335. * Cleans the cache
  336. */
  337. function cleanCache( $group=false ) {
  338. global $mosConfig_caching;
  339. if ($mosConfig_caching) {
  340. $cache =& mosCache::getCache( $group );
  341. $cache->clean( $group );
  342. }
  343. }
  344. }
  345. /**
  346. * Joomla! Mainframe class
  347. *
  348. * Provide many supporting API functions
  349. * @package Joomla
  350. */
  351. class mosMainFrame {
  352. /** @var database Internal database class pointer */
  353. var $_db = null;
  354. /** @var object An object of configuration variables */
  355. var $_config = null;
  356. /** @var object An object of path variables */
  357. var $_path = null;
  358. /** @var mosSession The current session */
  359. var $_session = null;
  360. /** @var string The current template */
  361. var $_template = null;
  362. /** @var array An array to hold global user state within a session */
  363. var $_userstate = null;
  364. /** @var array An array of page meta information */
  365. var $_head = null;
  366. /** @var string Custom html string to append to the pathway */
  367. var $_custom_pathway = null;
  368. /** @var boolean True if in the admin client */
  369. var $_isAdmin = false;
  370. /**
  371. * Class constructor
  372. * @param database A database connection object
  373. * @param string The url option
  374. * @param string The path of the mos directory
  375. */
  376. function mosMainFrame( &$db, $option, $basePath, $isAdmin=false ) {
  377. $this->_db =& $db;
  378. // load the configuration values
  379. $this->_setTemplate( $isAdmin );
  380. $this->_setAdminPaths( $option, $this->getCfg( 'absolute_path' ) );
  381. if (isset( $_SESSION['session_userstate'] )) {
  382. $this->_userstate =& $_SESSION['session_userstate'];
  383. } else {
  384. $this->_userstate = null;
  385. }
  386. $this->_head = array();
  387. $this->_head['title'] = $GLOBALS['mosConfig_sitename'];
  388. $this->_head['meta'] = array();
  389. $this->_head['custom'] = array();
  390. //set the admin check
  391. $this->_isAdmin = (boolean) $isAdmin;
  392. $now = date( 'Y-m-d H:i:s', time() );
  393. $this->set( 'now', $now );
  394. }
  395. /**
  396. * Gets the id number for a client
  397. * @param mixed A client identifier
  398. */
  399. function getClientID( $client ) {
  400. switch ($client) {
  401. case '2':
  402. case 'installation':
  403. return 2;
  404. break;
  405. case '1':
  406. case 'admin':
  407. case 'administrator':
  408. return 1;
  409. break;
  410. case '0':
  411. case 'site':
  412. case 'front':
  413. default:
  414. return 0;
  415. break;
  416. }
  417. }
  418. /**
  419. * Gets the client name
  420. * @param int The client identifier
  421. * @return strint The text name of the client
  422. */
  423. function getClientName( $client_id ) {
  424. // do not translate
  425. $clients = array( 'site', 'admin', 'installer' );
  426. return mosGetParam( $clients, $client_id, 'unknown' );
  427. }
  428. /**
  429. * Gets the base path for the client
  430. * @param mixed A client identifier
  431. * @param boolean True (default) to add traling slash
  432. */
  433. function getBasePath( $client=0, $addTrailingSlash=true ) {
  434. global $mosConfig_absolute_path;
  435. switch ($client) {
  436. case '0':
  437. case 'site':
  438. case 'front':
  439. default:
  440. return mosPathName( $mosConfig_absolute_path, $addTrailingSlash );
  441. break;
  442. case '2':
  443. case 'installation':
  444. return mosPathName( $mosConfig_absolute_path . '/installation', $addTrailingSlash );
  445. break;
  446. case '1':
  447. case 'admin':
  448. case 'administrator':
  449. return mosPathName( $mosConfig_absolute_path . '/administrator', $addTrailingSlash );
  450. break;
  451. }
  452. }
  453. /**
  454. * @param string
  455. */
  456. function setPageTitle( $title=null ) {
  457. if (@$GLOBALS['mosConfig_pagetitles']) {
  458. $title = trim( htmlspecialchars( $title ) );
  459. $title = stripslashes($title);
  460. $this->_head['title'] = $title ? $GLOBALS['mosConfig_sitename'] . ' - '. $title : $GLOBALS['mosConfig_sitename'];
  461. }
  462. }
  463. /**
  464. * @param string The value of the name attibute
  465. * @param string The value of the content attibute
  466. * @param string Text to display before the tag
  467. * @param string Text to display after the tag
  468. */
  469. function addMetaTag( $name, $content, $prepend='', $append='' ) {
  470. $name = trim( htmlspecialchars( $name ) );
  471. $content = trim( htmlspecialchars( $content ) );
  472. $prepend = trim( $prepend );
  473. $append = trim( $append );
  474. $this->_head['meta'][] = array( $name, $content, $prepend, $append );
  475. }
  476. /**
  477. * @param string The value of the name attibute
  478. * @param string The value of the content attibute to append to the existing
  479. * Tags ordered in with Site Keywords and Description first
  480. */
  481. function appendMetaTag( $name, $content ) {
  482. $name = trim( htmlspecialchars( $name ) );
  483. $n = count( $this->_head['meta'] );
  484. for ($i = 0; $i < $n; $i++) {
  485. if ($this->_head['meta'][$i][0] == $name) {
  486. $content = trim( htmlspecialchars( $content ) );
  487. if ( $content ) {
  488. if ( !$this->_head['meta'][$i][1] ) {
  489. $this->_head['meta'][$i][1] = $content ;
  490. } else {
  491. $this->_head['meta'][$i][1] = $content .', '. $this->_head['meta'][$i][1];
  492. }
  493. }
  494. return;
  495. }
  496. }
  497. $this->addMetaTag( $name , $content );
  498. }
  499. /**
  500. * @param string The value of the name attibute
  501. * @param string The value of the content attibute to append to the existing
  502. */
  503. function prependMetaTag( $name, $content ) {
  504. $name = trim( htmlspecialchars( $name ) );
  505. $n = count( $this->_head['meta'] );
  506. for ($i = 0; $i < $n; $i++) {
  507. if ($this->_head['meta'][$i][0] == $name) {
  508. $content = trim( htmlspecialchars( $content ) );
  509. $this->_head['meta'][$i][1] = $content . $this->_head['meta'][$i][1];
  510. return;
  511. }
  512. }
  513. $this->addMetaTag( $name, $content );
  514. }
  515. /**
  516. * Adds a custom html string to the head block
  517. * @param string The html to add to the head
  518. */
  519. function addCustomHeadTag( $html ) {
  520. $this->_head['custom'][] = trim( $html );
  521. }
  522. /**
  523. * @return string
  524. */
  525. function getHead() {
  526. $head = array();
  527. $head[] = '<title>' . $this->_head['title'] . '</title>';
  528. foreach ($this->_head['meta'] as $meta) {
  529. if ($meta[2]) {
  530. $head[] = $meta[2];
  531. }
  532. $head[] = '<meta name="' . $meta[0] . '" content="' . $meta[1] . '" />';
  533. if ($meta[3]) {
  534. $head[] = $meta[3];
  535. }
  536. }
  537. foreach ($this->_head['custom'] as $html) {
  538. $head[] = $html;
  539. }
  540. return implode( "\n", $head ) . "\n";
  541. }
  542. /**
  543. * @return string
  544. */
  545. function getPageTitle() {
  546. return $this->_head['title'];
  547. }
  548. /**
  549. * @return string
  550. */
  551. function getCustomPathWay() {
  552. return $this->_custom_pathway;
  553. }
  554. function appendPathWay( $html ) {
  555. $this->_custom_pathway[] = $html;
  556. }
  557. /**
  558. * Gets the value of a user state variable
  559. * @param string The name of the variable
  560. */
  561. function getUserState( $var_name ) {
  562. if (is_array( $this->_userstate )) {
  563. return mosGetParam( $this->_userstate, $var_name, null );
  564. } else {
  565. return null;
  566. }
  567. }
  568. /**
  569. * Gets the value of a user state variable
  570. * @param string The name of the user state variable
  571. * @param string The name of the variable passed in a request
  572. * @param string The default value for the variable if not found
  573. */
  574. function getUserStateFromRequest( $var_name, $req_name, $var_default=null ) {
  575. if (is_array( $this->_userstate )) {
  576. if (isset( $_REQUEST[$req_name] )) {
  577. $this->setUserState( $var_name, $_REQUEST[$req_name] );
  578. } else if (!isset( $this->_userstate[$var_name] )) {
  579. $this->setUserState( $var_name, $var_default );
  580. }
  581. // filter input
  582. $iFilter = new InputFilter();
  583. $this->_userstate[$var_name] = $iFilter->process( $this->_userstate[$var_name] );
  584. return $this->_userstate[$var_name];
  585. } else {
  586. return null;
  587. }
  588. }
  589. /**
  590. * Sets the value of a user state variable
  591. * @param string The name of the variable
  592. * @param string The value of the variable
  593. */
  594. function setUserState( $var_name, $var_value ) {
  595. if (is_array( $this->_userstate )) {
  596. $this->_userstate[$var_name] = $var_value;
  597. }
  598. }
  599. /**
  600. * Initialises the user session
  601. *
  602. * Old sessions are flushed based on the configuration value for the cookie
  603. * lifetime. If an existing session, then the last access time is updated.
  604. * If a new session, a session id is generated and a record is created in
  605. * the jos_sessions table.
  606. */
  607. function initSession() {
  608. // initailize session variables
  609. $session =& $this->_session;
  610. $session = new mosSession( $this->_db );
  611. // purge expired sessions
  612. $session->purge('core');
  613. // Session Cookie `name`
  614. $sessionCookieName = mosMainFrame::sessionCookieName();
  615. // Get Session Cookie `value`
  616. $sessioncookie = strval( mosGetParam( $_COOKIE, $sessionCookieName, null ) );
  617. // Session ID / `value`
  618. $sessionValueCheck = mosMainFrame::sessionCookieValue( $sessioncookie );
  619. // Check if existing session exists in db corresponding to Session cookie `value`
  620. // extra check added in 1.0.8 to test sessioncookie value is of correct length
  621. if ( $sessioncookie && strlen($sessioncookie) == 32 && $sessioncookie != '-' && $session->load($sessionValueCheck) ) {
  622. // update time in session table
  623. $session->time = time();
  624. $session->update();
  625. } else {
  626. // Remember Me Cookie `name`
  627. $remCookieName = mosMainFrame::remCookieName_User();
  628. // test if cookie found
  629. $cookie_found = false;
  630. if ( isset($_COOKIE[$sessionCookieName]) || isset($_COOKIE[$remCookieName]) || isset($_POST['force_session']) ) {
  631. $cookie_found = true;
  632. }
  633. // check if neither remembermecookie or sessioncookie found
  634. if (!$cookie_found) {
  635. // create sessioncookie and set it to a test value set to expire on session end
  636. setcookie( $sessionCookieName, '-', false, '/' );
  637. } else {
  638. // otherwise, sessioncookie was found, but set to test val or the session expired, prepare for session registration and register the session
  639. $url = strval( mosGetParam( $_SERVER, 'REQUEST_URI', null ) );
  640. // stop sessions being created for requests to syndicated feeds
  641. if ( strpos( $url, 'option=com_rss' ) === false && strpos( $url, 'feed=' ) === false ) {
  642. $session->guest = 1;
  643. $session->username = '';
  644. $session->time = time();
  645. $session->gid = 0;
  646. // Generate Session Cookie `value`
  647. $session->generateId();
  648. if (!$session->insert()) {
  649. die( $session->getError() );
  650. }
  651. // create Session Tracking Cookie set to expire on session end
  652. setcookie( $sessionCookieName, $session->getCookie(), false, '/' );
  653. }
  654. }
  655. // Cookie used by Remember me functionality
  656. $remCookieValue = strval( mosGetParam( $_COOKIE, $remCookieName, null ) );
  657. // test if cookie is correct length
  658. if ( strlen($remCookieValue) > 64 ) {
  659. // Separate Values from Remember Me Cookie
  660. $remUser = substr( $remCookieValue, 0, 32 );
  661. $remPass = substr( $remCookieValue, 32, 32 );
  662. $remID = intval( substr( $remCookieValue, 64 ) );
  663. // check if Remember me cookie exists. Login with usercookie info.
  664. if ( strlen($remUser) == 32 && strlen($remPass) == 32 ) {
  665. $this->login( $remUser, $remPass, 1, $remID );
  666. }
  667. }
  668. }
  669. }
  670. /*
  671. * Function used to conduct admin session duties
  672. * Added as of 1.0.8
  673. * Deprecated 1.1
  674. */
  675. function initSessionAdmin($option, $task) {
  676. global $_VERSION, $mosConfig_admin_expired;
  677. // logout check
  678. if ($option == 'logout') {
  679. require $GLOBALS['mosConfig_absolute_path'] .'/administrator/logout.php';
  680. exit();
  681. }
  682. $site = $GLOBALS['mosConfig_live_site'];
  683. // check if session name corresponds to correct format
  684. if ( session_name() != md5( $site ) ) {
  685. echo "<script>document.location.href='index.php'</script>\n";
  686. exit();
  687. }
  688. // restore some session variables
  689. $my = new mosUser( $this->_db );
  690. $my->id = intval( mosGetParam( $_SESSION, 'session_user_id', '' ) );
  691. $my->username = strval( mosGetParam( $_SESSION, 'session_username', '' ) );
  692. $my->usertype = strval( mosGetParam( $_SESSION, 'session_usertype', '' ) );
  693. $my->gid = intval( mosGetParam( $_SESSION, 'session_gid', '' ) );
  694. $my->params = mosGetParam( $_SESSION, 'session_user_params', '' );
  695. $session_id = mosGetParam( $_SESSION, 'session_id', '' );
  696. $logintime = mosGetParam( $_SESSION, 'session_logintime', '' );
  697. if ($session_id != session_id()) {
  698. // session id does not correspond to required session format
  699. echo "<script>document.location.href='index.php?mosmsg=Invalid Session'</script>\n";
  700. exit();
  701. }
  702. // check to see if session id corresponds with correct format
  703. if ($session_id == md5( $my->id . $my->username . $my->usertype . $logintime )) {
  704. // if task action is to `save` or `apply` complete action before doing session checks.
  705. if ($task != 'save' && $task != 'apply') {
  706. // test for session_life_admin
  707. if ( @$GLOBALS['mosConfig_session_life_admin'] ) {
  708. $session_life_admin = $GLOBALS['mosConfig_session_life_admin'];
  709. } else {
  710. $session_life_admin = 1800;
  711. }
  712. // purge expired admin sessions only
  713. $past = time() - $session_life_admin;
  714. $query = "DELETE FROM #__session"
  715. . "\n WHERE time < '" . (int) $past . "'"
  716. . "\n AND guest = 1"
  717. . "\n AND gid = 0"
  718. . "\n AND userid <> 0"
  719. ;
  720. $this->_db->setQuery( $query );
  721. $this->_db->query();
  722. $current_time = time();
  723. // update session timestamp
  724. $query = "UPDATE #__session"
  725. . "\n SET time = " . $this->_db->Quote( $current_time )
  726. . "\n WHERE session_id = " . $this->_db->Quote( $session_id )
  727. ;
  728. $this->_db->setQuery( $query );
  729. $this->_db->query();
  730. // set garbage cleaning timeout
  731. $this->setSessionGarbageClean();
  732. // check against db record of session
  733. $query = "SELECT COUNT( session_id )"
  734. . "\n FROM #__session"
  735. . "\n WHERE session_id = " . $this->_db->Quote( $session_id )
  736. . "\n AND username = ". $this->_db->Quote( $my->username )
  737. . "\n AND userid = ". intval( $my->id )
  738. ;
  739. $this->_db->setQuery( $query );
  740. $count = $this->_db->loadResult();
  741. // if no entry in session table that corresponds boot from admin area
  742. if ( $count == 0 ) {
  743. $link = NULL;
  744. if ($_SERVER['QUERY_STRING']) {
  745. $link = 'index2.php?'. $_SERVER['QUERY_STRING'];
  746. }
  747. // check if site designated as a production site
  748. // for a demo site disallow expired page functionality
  749. // link must also be a Joomla link to stop malicious redirection
  750. if ( $link && strpos( $link, 'index2.php?option=com_' ) === 0 && $_VERSION->SITE == 1 && @$mosConfig_admin_expired === '1' ) {
  751. $now = time();
  752. $file = $this->getPath( 'com_xml', 'com_users' );
  753. $params =& new mosParameters( $my->params, $file, 'component' );
  754. // return to expired page functionality
  755. $params->set( 'expired', $link );
  756. $params->set( 'expired_time', $now );
  757. // param handling
  758. if (is_array( $params->toArray() )) {
  759. $txt = array();
  760. foreach ( $params->toArray() as $k=>$v) {
  761. $txt[] = "$k=$v";
  762. }
  763. $saveparams = implode( "\n", $txt );
  764. }
  765. // save expired page info to user data
  766. $query = "UPDATE #__users"
  767. . "\n SET params = ". $this->_db->Quote( $saveparams )
  768. . "\n WHERE id = " . (int) $my->id
  769. . "\n AND username = ". $this->_db->Quote( $my->username )
  770. . "\n AND usertype = ". $this->_db->Quote( $my->usertype )
  771. ;
  772. $this->_db->setQuery( $query );
  773. $this->_db->query();
  774. }
  775. echo "<script>document.location.href='index.php?mosmsg=Admin Session Expired'</script>\n";
  776. exit();
  777. } else {
  778. // load variables into session, used to help secure /popups/ functionality
  779. $_SESSION['option'] = $option;
  780. $_SESSION['task'] = $task;
  781. }
  782. }
  783. } else if ($session_id == '') {
  784. // no session_id as user has not attempted to login, or session.auto_start is switched on
  785. if (ini_get( 'session.auto_start' ) || !ini_get( 'session.use_cookies' )) {
  786. echo "<script>document.location.href='index.php?mosmsg=You need to login. If PHP\'s session.auto_start setting is on or session.use_cookies setting is off, you may need to correct this before you will be able to login.'</script>\n";
  787. } else {
  788. echo "<script>document.location.href='index.php?mosmsg=You need to login'</script>\n";
  789. }
  790. exit();
  791. } else {
  792. // session id does not correspond to required session format
  793. echo "<script>document.location.href='index.php?mosmsg=Invalid Session'</script>\n";
  794. exit();
  795. }
  796. return $my;
  797. }
  798. /*
  799. * Function used to set Session Garbage Cleaning
  800. * garbage cleaning set at configured session time + 600 seconds
  801. * Added as of 1.0.8
  802. * Deprecated 1.1
  803. */
  804. function setSessionGarbageClean() {
  805. /** ensure that funciton is only called once */
  806. if (!defined( '_JOS_GARBAGECLEAN' )) {
  807. define( '_JOS_GARBAGECLEAN', 1 );
  808. $garbage_timeout = $this->getCfg('session_life_admin') + 600;
  809. @ini_set('session.gc_maxlifetime', $garbage_timeout);
  810. }
  811. }
  812. /*
  813. * Static Function used to generate the Session Cookie Name
  814. * Added as of 1.0.8
  815. * Deprecated 1.1
  816. */
  817. function sessionCookieName() {
  818. global $mainframe, $mosConfig_live_site;
  819. if( substr( $mosConfig_live_site, 0, 7 ) == 'http://' ) {
  820. $hash = md5( 'site' . substr( $mosConfig_live_site, 7 ) );
  821. } elseif( substr( $mosConfig_live_site, 0, 8 ) == 'https://' ) {
  822. $hash = md5( 'site' . substr( $mosConfig_live_site, 8 ) );
  823. } else {
  824. $hash = md5( 'site' . $mainframe->getCfg( 'live_site' ) );
  825. }
  826. return $hash;
  827. }
  828. /*
  829. * Static Function used to generate the Session Cookie Value
  830. * Added as of 1.0.8
  831. * Deprecated 1.1
  832. */
  833. function sessionCookieValue( $id=null ) {
  834. global $mainframe;
  835. $type = $mainframe->getCfg( 'session_type' );
  836. $browser = @$_SERVER['HTTP_USER_AGENT'];
  837. switch ($type) {
  838. case 2:
  839. // 1.0.0 to 1.0.7 Compatibility
  840. // lowest level security
  841. $value = md5( $id . $_SERVER['REMOTE_ADDR'] );
  842. break;
  843. case 1:
  844. // slightly reduced security - 3rd level IP authentication for those behind IP Proxy
  845. $remote_addr = explode('.',$_SERVER['REMOTE_ADDR']);
  846. $ip = $remote_addr[0] .'.'. $remote_addr[1] .'.'. $remote_addr[2];
  847. $value = mosHash( $id . $ip . $browser );
  848. break;
  849. default:
  850. // Highest security level - new default for 1.0.8 and beyond
  851. $ip = $_SERVER['REMOTE_ADDR'];
  852. $value = mosHash( $id . $ip . $browser );
  853. break;
  854. }
  855. return $value;
  856. }
  857. /*
  858. * Static Function used to generate the Rememeber Me Cookie Name for Username information
  859. * Added as of 1.0.8
  860. * Depreciated 1.1
  861. */
  862. function remCookieName_User() {
  863. $value = mosHash( 'remembermecookieusername'. mosMainFrame::sessionCookieName() );
  864. return $value;
  865. }
  866. /*
  867. * Static Function used to generate the Rememeber Me Cookie Name for Password information
  868. * Added as of 1.0.8
  869. * Depreciated 1.1
  870. */
  871. function remCookieName_Pass() {
  872. $value = mosHash( 'remembermecookiepassword'. mosMainFrame::sessionCookieName() );
  873. return $value;
  874. }
  875. /*
  876. * Static Function used to generate the Remember Me Cookie Value for Username information
  877. * Added as of 1.0.8
  878. * Depreciated 1.1
  879. */
  880. function remCookieValue_User( $username ) {
  881. $value = md5( $username . mosHash( @$_SERVER['HTTP_USER_AGENT'] ) );
  882. return $value;
  883. }
  884. /*
  885. * Static Function used to generate the Remember Me Cookie Value for Password information
  886. * Added as of 1.0.8
  887. * Depreciated 1.1
  888. */
  889. function remCookieValue_Pass( $passwd ) {
  890. $value = md5( $passwd . mosHash( @$_SERVER['HTTP_USER_AGENT'] ) );
  891. return $value;
  892. }
  893. /**
  894. * Login validation function
  895. *
  896. * Username and encoded password is compare to db entries in the jos_users
  897. * table. A successful validation updates the current session record with
  898. * the users details.
  899. */
  900. function login( $username=null, $passwd=null, $remember=0, $userid=NULL ) {
  901. global $acl, $_VERSION;
  902. $bypost = 0;
  903. $valid_remember = false;
  904. // if no username and password passed from function, then function is being called from login module/component
  905. if (!$username || !$passwd) {
  906. $username = stripslashes( strval( mosGetParam( $_POST, 'username', '' ) ) );
  907. $passwd = stripslashes( strval( mosGetParam( $_POST, 'passwd', '' ) ) );
  908. $bypost = 1;
  909. // extra check to ensure that Joomla! sessioncookie exists
  910. if (!$this->_session->session_id) {
  911. mosErrorAlert( _ALERT_ENABLED );
  912. return;
  913. }
  914. josSpoofCheck(NULL,1);
  915. }
  916. $row = null;
  917. if (!$username || !$passwd) {
  918. mosErrorAlert( _LOGIN_INCOMPLETE );
  919. exit();
  920. } else {
  921. if ( $remember && strlen($username) == 32 && $userid ) {
  922. // query used for remember me cookie
  923. $harden = mosHash( @$_SERVER['HTTP_USER_AGENT'] );
  924. $query = "SELECT id, name, username, password, usertype, block, gid"
  925. . "\n FROM #__users"
  926. . "\n WHERE id = " . (int) $userid
  927. ;
  928. $this->_db->setQuery( $query );
  929. $this->_db->loadObject($user);
  930. list($hash, $salt) = explode(':', $user->password);
  931. $check_username = md5( $user->username . $harden );
  932. $check_password = md5( $hash . $harden );
  933. if ( $check_username == $username && $check_password == $passwd ) {
  934. $row = $user;
  935. $valid_remember = true;
  936. }
  937. } else {
  938. // query used for login via login module
  939. $query = "SELECT id, name, username, password, usertype, block, gid"
  940. . "\n FROM #__users"
  941. . "\n WHERE username = ". $this->_db->Quote( $username )
  942. ;
  943. $this->_db->setQuery( $query );
  944. $this->_db->loadObject( $row );
  945. }
  946. if (is_object($row)) {
  947. // user blocked from login
  948. if ($row->block == 1) {
  949. mosErrorAlert(_LOGIN_BLOCKED);
  950. }
  951. if (!$valid_remember) {
  952. // Conversion to new type
  953. if ((strpos($row->password, ':') === false) && $row->password == md5($passwd)) {
  954. // Old password hash storage but authentic ... lets convert it
  955. $salt = mosMakePassword(16);
  956. $crypt = md5($passwd.$salt);
  957. $row->password = $crypt.':'.$salt;
  958. // Now lets store it in the database
  959. $query = 'UPDATE #__users'
  960. . ' SET password = '.$this->_db->Quote($row->password)
  961. . ' WHERE id = '.(int)$row->id;
  962. $this->_db->setQuery($query);
  963. if (!$this->_db->query()) {
  964. // This is an error but not sure what to do with it ... we'll still work for now
  965. }
  966. }
  967. list($hash, $salt) = explode(':', $row->password);
  968. $cryptpass = md5($passwd.$salt);
  969. if ($hash != $cryptpass) {
  970. if ( $bypost ) {
  971. mosErrorAlert(_LOGIN_INCORRECT);
  972. } else {
  973. $this->logout();
  974. mosRedirect('index.php');
  975. }
  976. exit();
  977. }
  978. }
  979. // fudge the group stuff
  980. $grp = $acl->getAroGroup( $row->id );
  981. $row->gid = 1;
  982. if ($acl->is_group_child_of( $grp->name, 'Registered', 'ARO' ) || $acl->is_group_child_of( $grp->name, 'Public Backend', 'ARO' )) {
  983. // fudge Authors, Editors, Publishers and Super Administrators into the Special Group
  984. $row->gid = 2;
  985. }
  986. $row->usertype = $grp->name;
  987. // initialize session data
  988. $session =& $this->_session;
  989. $session->guest = 0;
  990. $session->username = $row->username;
  991. $session->userid = intval( $row->id );
  992. $session->usertype = $row->usertype;
  993. $session->gid = intval( $row->gid );
  994. $session->update();
  995. // check to see if site is a production site
  996. // allows multiple logins with same user for a demo site
  997. if ( $_VERSION->SITE ) {
  998. // delete any old front sessions to stop duplicate sessions
  999. $query = "DELETE FROM #__session"
  1000. . "\n WHERE session_id != ". $this->_db->Quote( $session->session_id )
  1001. . "\n AND username = ". $this->_db->Quote( $row->username )
  1002. . "\n AND userid = " . (int) $row->id
  1003. . "\n AND gid = " . (int) $row->gid
  1004. . "\n AND guest = 0"
  1005. ;
  1006. $this->_db->setQuery( $query );
  1007. $this->_db->query();
  1008. }
  1009. // update user visit data
  1010. $currentDate = date("Y-m-d\TH:i:s");
  1011. $query = "UPDATE #__users"
  1012. . "\n SET lastvisitDate = ". $this->_db->Quote( $currentDate )
  1013. . "\n WHERE id = " . (int) $session->userid
  1014. ;
  1015. $this->_db->setQuery($query);
  1016. if (!$this->_db->query()) {
  1017. die($this->_db->stderr(true));
  1018. }
  1019. // set remember me cookie if selected
  1020. $remember = strval( mosGetParam( $_POST, 'remember', '' ) );
  1021. if ( $remember == 'yes' ) {
  1022. // cookie lifetime of 365 days
  1023. $lifetime = time() + 365*24*60*60;
  1024. $remCookieName = mosMainFrame::remCookieName_User();
  1025. $remCookieValue = mosMainFrame::remCookieValue_User( $row->username ) . mosMainFrame::remCookieValue_Pass( $hash ) . $row->id;
  1026. setcookie( $remCookieName, $remCookieValue, $lifetime, '/' );
  1027. }
  1028. mosCache::cleanCache();
  1029. } else {
  1030. if ( $bypost ) {
  1031. mosErrorAlert(_LOGIN_INCORRECT);
  1032. } else {
  1033. $this->logout();
  1034. mosRedirect('index.php');
  1035. }
  1036. exit();
  1037. }
  1038. }
  1039. }
  1040. /**
  1041. * User logout
  1042. *
  1043. * Reverts the current session record back to 'anonymous' parameters
  1044. */
  1045. function logout() {
  1046. mosCache::cleanCache();
  1047. $session =& $this->_session;
  1048. $session->guest = 1;
  1049. $session->username = '';
  1050. $session->userid = '';
  1051. $session->usertype = '';
  1052. $session->gid = 0;
  1053. $session->update();
  1054. // kill remember me cookie
  1055. $lifetime = time() - 86400;
  1056. $remCookieName = mosMainFrame::remCookieName_User();
  1057. setcookie( $remCookieName, ' ', $lifetime, '/' );
  1058. @session_destroy();
  1059. }
  1060. /**
  1061. * @return mosUser A user object with the information from the current session
  1062. */
  1063. function getUser() {
  1064. global $database;
  1065. $user = new mosUser( $this->_db );
  1066. $user->id = intval( $this->_session->userid );
  1067. $user->username = $this->_session->username;
  1068. $user->usertype = $this->_session->usertype;
  1069. $user->gid = intval( $this->_session->gid );
  1070. if ($user->id) {
  1071. $query = "SELECT id, name, email, block, sendEmail, registerDate, lastvisitDate, activation, params"
  1072. . "\n FROM #__users"
  1073. . "\n WHERE id = " . (int) $user->id
  1074. ;
  1075. $database->setQuery( $query );
  1076. $database->loadObject( $my );
  1077. $user->params = $my->params;
  1078. $user->name = $my->name;
  1079. $user->email = $my->email;
  1080. $user->block = $my->block;
  1081. $user->sendEmail = $my->sendEmail;
  1082. $user->registerDate = $my->registerDate;
  1083. $user->lastvisitDate = $my->lastvisitDate;
  1084. $user->activation = $my->activation;
  1085. }
  1086. return $user;
  1087. }
  1088. /**
  1089. * @param string The name of the variable (from configuration.php)
  1090. * @return mixed The value of the configuration variable or null if not found
  1091. */
  1092. function getCfg( $varname ) {
  1093. $varname = 'mosConfig_' . $varname;
  1094. if (isset( $GLOBALS[$varname] )) {
  1095. return $GLOBALS[$varname];
  1096. } else {
  1097. return null;
  1098. }
  1099. }
  1100. function _setTemplate( $isAdmin=false ) {
  1101. global $Itemid;
  1102. $mosConfig_absolute_path = $this->getCfg( 'absolute_path' );
  1103. if ($isAdmin) {
  1104. $query = "SELECT template"
  1105. . "\n FROM #__templates_menu"
  1106. . "\n WHERE client_id = 1"
  1107. . "\n AND menuid = 0"
  1108. ;
  1109. $this->_db->setQuery( $query );
  1110. $cur_template = $this->_db->loadResult();
  1111. $path = "$mosConfig_absolute_path/administrator/templates/$cur_template/index.php";
  1112. if (!file_exists( $path )) {
  1113. $cur_template = 'joomla_admin';
  1114. }
  1115. } else {
  1116. $assigned = ( !empty( $Itemid ) ? " OR menuid = " . (int) $Itemid : '' );
  1117. $query = "SELECT template"
  1118. . "\n FROM #__templates_menu"
  1119. . "\n WHERE client_id = 0"
  1120. . "\n AND ( menuid = 0 $assigned )"
  1121. . "\n ORDER BY menuid DESC"
  1122. ;
  1123. $this->_db->setQuery( $query, 0, 1 );
  1124. $cur_template = $this->_db->loadResult();
  1125. // TemplateChooser Start
  1126. $jos_user_template = strval( mosGetParam( $_COOKIE, 'jos_user_template', '' ) );
  1127. $jos_change_template = strval( mosGetParam( $_REQUEST, 'jos_change_template', $jos_user_template ) );
  1128. if ($jos_change_template) {
  1129. // clean template name
  1130. $jos_change_template = preg_replace( '#\W#', '', $jos_change_template );
  1131. if ( strlen( $jos_change_template ) >= 40 ) {
  1132. $jos_change_template = substr($jos_change_template, 0 , 39);
  1133. }
  1134. // check that template exists in case it was deleted
  1135. if (file_exists( $mosConfig_absolute_path .'/templates/'. $jos_change_template .'/index.php' )) {
  1136. $lifetime = 60*10;
  1137. $cur_template = $jos_change_template;
  1138. setcookie( 'jos_user_template', "$jos_change_template", time()+$lifetime);
  1139. } else {
  1140. setcookie( 'jos_user_template', '', time()-3600 );
  1141. }
  1142. }
  1143. // TemplateChooser End
  1144. }
  1145. $this->_template = $cur_template;
  1146. }
  1147. function getTemplate() {
  1148. return $this->_template;
  1149. }
  1150. /**
  1151. * Determines the paths for including engine and menu files
  1152. * @param string The current option used in the url
  1153. * @param string The base path from which to load the configuration file
  1154. */
  1155. function _setAdminPaths( $option, $basePath='.' ) {
  1156. $option = strtolower( $option );
  1157. $this->_path = new stdClass();
  1158. // security check to disable use of `/`, `\\` and `:` in $options variable
  1159. if (strpos($option, '/') !== false || strpos($option, '\\') !== false || strpos($option, ':') !== false) {
  1160. mosErrorAlert( 'Restricted access' );
  1161. return;
  1162. }
  1163. $prefix = substr( $option, 0, 4 );
  1164. if ($prefix != 'com_' && $prefix != 'mod_') {
  1165. // ensure backward compatibility with existing links
  1166. $name = $option;
  1167. $option = "com_$option";
  1168. } else {
  1169. $name = substr( $option, 4 );
  1170. }
  1171. // components
  1172. if (file_exists( "$basePath/templates/$this->_template/components/$name.html.php" )) {
  1173. $this->_path->front = "$basePath/components/$option/$name.php";
  1174. $this->_path->front_html = "$basePath/templates/$this->_template/components/$name.html.php";
  1175. } else if (file_exists( "$basePath/components/$option/$name.php" )) {
  1176. $this->_path->front = "$basePath/components/$option/$name.php";
  1177. $this->_path->front_html = "$basePath/components/$option/$name.html.php";
  1178. }
  1179. if (file_exists( "$basePath/administrator/components/$option/admin.$name.php" )) {
  1180. $this->_path->admin = "$basePath/administrator/components/$option/admin.$name.php";
  1181. $this->_path->admin_html = "$basePath/administrator/components/$option/admin.$name.html.php";
  1182. }
  1183. if (file_exists( "$basePath/administrator/components/$option/toolbar.$name.php" )) {
  1184. $this->_path->toolbar = "$basePath/administrator/components/$option/toolbar.$name.php";
  1185. $this->_path->toolbar_html = "$basePath/administrator/components/$option/toolbar.$name.html.php";
  1186. $this->_path->toolbar_default = "$basePath/administrator/includes/toolbar.html.php";
  1187. }
  1188. if (file_exists( "$basePath/components/$option/$name.class.php" )) {
  1189. $this->_path->class = "$basePath/components/$option/$name.class.php";
  1190. } else if (file_exists( "$basePath/administrator/components/$option/$name.class.php" )) {
  1191. $this->_path->class = "$basePath/administrator/components/$option/$name.class.php";
  1192. } else if (file_exists( "$basePath/includes/$name.php" )) {
  1193. $this->_path->class = "$basePath/includes/$name.php";
  1194. }
  1195. if ($prefix == 'mod_' && file_exists("$basePath/administrator/modules/$option.php")) {
  1196. $this->_path->admin = "$basePath/administrator/modules/$option.php";
  1197. $this->_path->admin_html = "$basePath/administrator/modules/mod_$name.html.php";
  1198. } else if (file_exists("$basePath/administrator/components/$option/admin.$name.php" )) {
  1199. $this->_path->admin = "$basePath/administrator/components/$option/admin.$name.php";
  1200. $this->_path->admin_html = "$basePath/administrator/components/$option/admin.$name.html.php";
  1201. } else {
  1202. $this->_path->admin = "$basePath/administrator/components/com_admin/admin.admin.php";
  1203. $this->_path->admin_html = "$basePath/administrator/components/com_admin/admin.admin.html.php";
  1204. }
  1205. }
  1206. /**
  1207. * Returns a stored path variable
  1208. *
  1209. */
  1210. function getPath( $varname, $option='' ) {
  1211. global $mosConfig_absolute_path;
  1212. if ($option) {
  1213. $temp = $this->_path;
  1214. $this->_setAdminPaths( $option, $this->getCfg( 'absolute_path' ) );
  1215. }
  1216. $result = null;
  1217. if (isset( $this->_path->$varname )) {
  1218. $result = $this->_path->$varname;
  1219. } else {
  1220. switch ($varname) {
  1221. case 'com_xml':
  1222. $name = substr( $option, 4 );
  1223. $path = "$mosConfig_absolute_path/administrator/components/$option/$name.xml";
  1224. if (file_exists( $path )) {
  1225. $result = $path;
  1226. } else {
  1227. $path = "$mosConfig_absolute_path/components/$option/$name.xml";
  1228. if (file_exists( $path )) {
  1229. $result = $path;
  1230. }
  1231. }
  1232. break;
  1233. case 'mod0_xml':
  1234. // Site modules
  1235. if ($option == '') {
  1236. $path = $mosConfig_absolute_path . "/modules/custom.xml";
  1237. } else {
  1238. $path = $mosConfig_absolute_path . "/modules/$option.xml";
  1239. }
  1240. if (file_exists( $path )) {
  1241. $result = $path;
  1242. }
  1243. break;
  1244. case 'mod1_xml':
  1245. // admin modules
  1246. if ($option == '') {
  1247. $path = $mosConfig_absolute_path . '/administrator/modules/custom.xml';
  1248. } else {
  1249. $path = $mosConfig_absolute_path . "/administrator/modules/$option.xml";
  1250. }
  1251. if (file_exists( $path )) {
  1252. $result = $path;
  1253. }
  1254. break;
  1255. case 'bot_xml':
  1256. // Site mambots
  1257. $path = $mosConfig_absolute_path . "/mambots/$option.xml";
  1258. if (file_exists( $path )) {
  1259. $result = $path;
  1260. }
  1261. break;
  1262. case 'menu_xml':
  1263. $path = $mosConfig_absolute_path . "/administrator/components/com_menus/$option/$option.xml";
  1264. if (file_exists( $path )) {
  1265. $result = $path;
  1266. }
  1267. break;
  1268. case 'installer_html':
  1269. $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$option/$option.html.php";
  1270. if (file_exists( $path )) {
  1271. $result = $path;
  1272. }
  1273. break;
  1274. case 'installer_class':
  1275. $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$option/$option.class.php";
  1276. if (file_exists( $path )) {
  1277. $result = $path;
  1278. }
  1279. break;
  1280. }
  1281. }
  1282. if ($option) {
  1283. $this->_path = $temp;
  1284. }
  1285. return $result;
  1286. }
  1287. /**
  1288. * Detects a 'visit'
  1289. *
  1290. * This function updates the agent and domain table hits for a particular
  1291. * visitor. The user agent is recorded/incremented if this is the first visit.
  1292. * A cookie is set to mark the first visit.
  1293. */
  1294. function detect() {
  1295. global $mosConfig_enable_stats;
  1296. if ($mosConfig_enable_stats == 1) {
  1297. if (mosGetParam( $_COOKIE, 'mosvisitor', 0 )) {
  1298. return;
  1299. }
  1300. setcookie( 'mosvisitor', 1 );
  1301. if (phpversion() <= '4.2.1') {
  1302. $agent = getenv( 'HTTP_USER_AGENT' );
  1303. $domain = @gethostbyaddr( getenv( "REMOTE_ADDR" ) );
  1304. } else {
  1305. if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
  1306. $agent = $_SERVER['HTTP_USER_AGENT'];
  1307. } else {
  1308. $agent = 'Unknown';
  1309. }
  1310. $domain = @gethostbyaddr( $_SERVER['REMOTE_ADDR'] );
  1311. }
  1312. $browser = mosGetBrowser( $agent );
  1313. $query = "SELECT COUNT(*)"
  1314. . "\n FROM #__stats_agents"
  1315. . "\n WHERE agent = " . $this->_db->Quote( $browser )
  1316. . "\n AND type = 0"
  1317. ;
  1318. $this->_db->setQuery( $query );
  1319. if ($this->_db->loadResult()) {
  1320. $query = "UPDATE #__stats_agents"
  1321. . "\n SET hits = ( hits + 1 )"
  1322. . "\n WHERE agent = " . $this->_db->Quote( $browser )
  1323. . "\n AND type = 0"
  1324. ;
  1325. $this->_db->setQuery( $query );
  1326. } else {
  1327. $query = "INSERT INTO #__stats_agents"
  1328. . "\n ( agent, type )"
  1329. . "\n VALUES ( " . $this->_db->Quote( $browser ) . ", 0 )"
  1330. ;
  1331. $this->_db->setQuery( $query );
  1332. }
  1333. $this->_db->query();
  1334. $os = mosGetOS( $agent );
  1335. $query = "SELECT COUNT(*)"
  1336. . "\n FROM #__stats_agents"
  1337. . "\n WHERE agent = " . $this->_db->Quote( $os )
  1338. . "\n AND type = 1"
  1339. ;
  1340. $this->_db->setQuery( $query );
  1341. if ($this->_db->loadResult()) {
  1342. $query = "UPDATE #__stats_agents"
  1343. . "\n SET hits = ( hits + 1 )"
  1344. . "\n WHERE agent = " . $this->_db->Quote( $os )
  1345. . "\n AND type = 1"
  1346. ;
  1347. $this->_db->setQuery( $query );
  1348. } else {
  1349. $query = "INSERT INTO #__stats_agents"
  1350. . "\n ( agent, type )"
  1351. . "\n VALUES ( " . $this->_db->Quote( $os ) . ", 1 )"
  1352. ;
  1353. $this->_db->setQuery( $query );
  1354. }
  1355. $this->_db->query();
  1356. // tease out the last element of the domain
  1357. $tldomain = split( "\.", $domain );
  1358. $tldomain = $tldomain[count( $tldomain )-1];
  1359. if (is_numeric( $tldomain )) {
  1360. $tldomain = "Unknown";
  1361. }
  1362. $query = "SELECT COUNT(*)"
  1363. . "\n FROM #__stats_agents"
  1364. . "\n WHERE agent = " . $this->_db->Quote( $tldomain )
  1365. . "\n AND type = 2"
  1366. ;
  1367. $this->_db->setQuery( $query );
  1368. if ($this->_db->loadResult()) {
  1369. $query = "UPDATE #__stats_agents"
  1370. . "\n SET hits = ( hits + 1 )"
  1371. . "\n WHERE agent = " . $this->_db->Quote( $tldomain )
  1372. . "\n AND type = 2"
  1373. ;
  1374. $this->_db->setQuery( $query );
  1375. } else {
  1376. $query = "INSERT INTO #__stats_agents"
  1377. . "\n ( agent, type )"
  1378. . "\n VALUES ( " . $this->_db->Quote( $tldomain ) . ", 2 )"
  1379. ;
  1380. $this->_db->setQuery( $query );
  1381. }
  1382. $this->_db->query();
  1383. }
  1384. }
  1385. /**
  1386. * @return correct Itemid for Content Item
  1387. */
  1388. function getItemid( $id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1 ) {
  1389. global $Itemid;
  1390. // getItemid compatibility mode, holds maintenance version number
  1391. $compat = (int) $this->getCfg('itemid_compat');
  1392. $compat = ($compat == 0)? 12 : $compat;
  1393. $_Itemid = '';
  1394. if ($_Itemid == '' && $typed && $this->getStaticContentCount()) {
  1395. $exists = 0;
  1396. foreach( $this->get( '_ContentTyped', array() ) as $key => $value ) {
  1397. // check if id has been tested before, if it is pull from class variable store
  1398. if ( $key == $id ) {
  1399. $_Itemid = $value;
  1400. $exists = 1;
  1401. break;
  1402. }
  1403. }
  1404. // if id hasnt been checked before initaite query
  1405. if ( !$exists ) {
  1406. // Search for typed link
  1407. $query = "SELECT id"
  1408. . "\n FROM #__menu"
  1409. . "\n WHERE type = 'content_typed'"
  1410. . "\n AND published = 1"
  1411. . "\n AND link = 'index.php?option=com_content&task=view&id=" . (int) $id . "'"
  1412. ;
  1413. $this->_db->setQuery( $query );
  1414. // pull existing query storage into temp variable
  1415. $ContentTyped = $this->get( '_ContentTyped', array() );
  1416. // add query result to temp array storage
  1417. $ContentTyped[$id] = $this->_db->loadResult();
  1418. // save temp array to main array storage
  1419. $this->set( '_ContentTyped', $ContentTyped );
  1420. $_Itemid = $ContentTyped[$id];
  1421. }
  1422. }
  1423. if ($_Itemid == '' && $link && $this->getContentItemLinkCount()) {
  1424. $exists = 0;
  1425. foreach( $this->get( '_ContentItemLink', array() ) as $key => $value ) {
  1426. // check if id has been tested before, if it is pull from class variable store
  1427. if ( $key == $id ) {
  1428. $_Itemid = $value;
  1429. $exists = 1;
  1430. break;
  1431. }
  1432. }
  1433. // if id hasnt been checked before initaite query
  1434. if ( !$exists ) {
  1435. // Search for item link
  1436. $query = "SELECT id"
  1437. ."\n FROM #__menu"
  1438. ."\n WHERE type = 'content_item_link'"
  1439. . "\n AND published = 1"
  1440. . "\n AND link = 'index.php?option=com_content&task=view&id=" . (int) $id . "'"
  1441. ;
  1442. $this->_db->setQuery( $query );
  1443. // pull existing query storage into temp variable
  1444. $ContentItemLink = $this->get( '_ContentItemLink', array() );
  1445. // add query result to temp array storage
  1446. $ContentItemLink[$id] = $this->_db->loadResult();
  1447. // save temp array to main array storage
  1448. $this->set( '_ContentItemLink', $ContentItemLink );
  1449. $_Itemid = $ContentItemLink[$id];
  1450. }
  1451. }
  1452. if ($_Itemid == '') {
  1453. $exists = 0;
  1454. foreach( $this->get( '_ContentSection', array() ) as $key => $value ) {
  1455. // check if id has been tested before, if it is pull from class variable store
  1456. if ( $key == $id ) {
  1457. $_Itemid = $value;
  1458. $exists = 1;
  1459. break;
  1460. }
  1461. }
  1462. // if id hasnt been checked before initaite query
  1463. if ( !$exists ) {
  1464. $query = "SELECT ms.id AS sid, ms.type AS stype, mc.id AS cid, mc.type AS ctype, i.id as sectionid, i.id As catid, ms.published AS spub, mc.published AS cpub"
  1465. . "\n FROM #__content AS i"
  1466. . "\n LEFT JOIN #__sections AS s ON i.sectionid = s.id"
  1467. . "\n LEFT JOIN #__menu AS ms ON ms.componentid = s.id "
  1468. . "\n LEFT JOIN #__categories AS c ON i.catid = c.id"
  1469. . "\n LEFT JOIN #__menu AS mc ON mc.componentid = c.id "
  1470. . "\n WHERE ( ms.type IN ( 'content_section', 'content_blog_section' ) OR mc.type IN ( 'content_blog_category', 'content_category' ) )"
  1471. . "\n AND i.id = " . (int) $id
  1472. . "\n ORDER BY ms.type DESC, mc.type DESC, ms.id, mc.id"
  1473. ;
  1474. $this->_db->setQuery( $query );
  1475. $links = $this->_db->loadObjectList();
  1476. if (count($links)) {
  1477. foreach($links as $link) {
  1478. if ($link->stype == 'content_section' && $link->sectionid == $id && !isset($content_section) && $link->spub == 1) {
  1479. $content_section = $link->sid;
  1480. }
  1481. if

Large files files are truncated, but you can click here to view the full file