PageRenderTime 67ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_patch/patch/administrator/components/com_jaclplus/patch/joomla.php

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

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