PageRenderTime 82ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/joomla.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 6162 lines | 5299 code | 229 blank | 634 comment | 243 complexity | cf8c9fc2ca538599acf0e77cba0d55f8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: joomla.php 5993 2006-12-13 00:24:58Z friesengeist $
  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. //Organic: TO make XHTML strict target="_blank" must be replaced with rel="external"
  463. $this->addCustomHeadTag("<script type='text/javascript' src='".$GLOBALS['mosConfig_live_site']."/includes/externalLink.js'></script>");
  464. }
  465. /**
  466. * @param string The value of the name attibute
  467. * @param string The value of the content attibute
  468. * @param string Text to display before the tag
  469. * @param string Text to display after the tag
  470. */
  471. function addMetaTag( $name, $content, $prepend='', $append='' ) {
  472. $name = trim( htmlspecialchars( $name ) );
  473. $content = trim( htmlspecialchars( $content ) );
  474. $prepend = trim( $prepend );
  475. $append = trim( $append );
  476. $this->_head['meta'][] = array( $name, $content, $prepend, $append );
  477. }
  478. /**
  479. * @param string The value of the name attibute
  480. * @param string The value of the content attibute to append to the existing
  481. * Tags ordered in with Site Keywords and Description first
  482. */
  483. function appendMetaTag( $name, $content ) {
  484. $name = trim( htmlspecialchars( $name ) );
  485. $n = count( $this->_head['meta'] );
  486. for ($i = 0; $i < $n; $i++) {
  487. if ($this->_head['meta'][$i][0] == $name) {
  488. $content = trim( htmlspecialchars( $content ) );
  489. if ( $content ) {
  490. if ( !$this->_head['meta'][$i][1] ) {
  491. $this->_head['meta'][$i][1] = $content ;
  492. } else {
  493. $this->_head['meta'][$i][1] = $content .', '. $this->_head['meta'][$i][1];
  494. }
  495. }
  496. return;
  497. }
  498. }
  499. $this->addMetaTag( $name , $content );
  500. }
  501. /**
  502. * @param string The value of the name attibute
  503. * @param string The value of the content attibute to append to the existing
  504. */
  505. function prependMetaTag( $name, $content ) {
  506. $name = trim( htmlspecialchars( $name ) );
  507. $n = count( $this->_head['meta'] );
  508. for ($i = 0; $i < $n; $i++) {
  509. if ($this->_head['meta'][$i][0] == $name) {
  510. $content = trim( htmlspecialchars( $content ) );
  511. $this->_head['meta'][$i][1] = $content . $this->_head['meta'][$i][1];
  512. return;
  513. }
  514. }
  515. $this->addMetaTag( $name, $content );
  516. }
  517. /**
  518. * Adds a custom html string to the head block
  519. * @param string The html to add to the head
  520. */
  521. function addCustomHeadTag( $html ) {
  522. $this->_head['custom'][] = trim( $html );
  523. }
  524. /**
  525. * @return string
  526. */
  527. function getHead() {
  528. global $mosConfig_mootools, $mosConfig_live_site;
  529. $head = array();
  530. $head[] = '<title>' . $this->_head['title'] . '</title>';
  531. foreach ($this->_head['meta'] as $meta) {
  532. if ($meta[2]) {
  533. $head[] = $meta[2];
  534. }
  535. $head[] = '<meta name="' . $meta[0] . '" content="' . $meta[1] . '" />';
  536. if ($meta[3]) {
  537. $head[] = $meta[3];
  538. }
  539. }
  540. if($mosConfig_mootools) $head[] = "<script type='text/javascript' src='$mosConfig_live_site/includes/js/mootools-release-1.11.js'></script>";
  541. foreach ($this->_head['custom'] as $html) {
  542. $head[] = $html;
  543. }
  544. return implode( "\n", $head ) . "\n";
  545. }
  546. /**
  547. * @return string
  548. */
  549. function getPageTitle() {
  550. return $this->_head['title'];
  551. }
  552. /**
  553. * @return string
  554. */
  555. function getCustomPathWay() {
  556. return $this->_custom_pathway;
  557. }
  558. function appendPathWay( $html ) {
  559. $this->_custom_pathway[] = $html;
  560. }
  561. /**
  562. * Gets the value of a user state variable
  563. * @param string The name of the variable
  564. */
  565. function getUserState( $var_name ) {
  566. if (is_array( $this->_userstate )) {
  567. return mosGetParam( $this->_userstate, $var_name, null );
  568. } else {
  569. return null;
  570. }
  571. }
  572. /**
  573. * Gets the value of a user state variable
  574. * @param string The name of the user state variable
  575. * @param string The name of the variable passed in a request
  576. * @param string The default value for the variable if not found
  577. */
  578. function getUserStateFromRequest( $var_name, $req_name, $var_default=null ) {
  579. if (is_array( $this->_userstate )) {
  580. if (isset( $_REQUEST[$req_name] )) {
  581. $this->setUserState( $var_name, $_REQUEST[$req_name] );
  582. } else if (!isset( $this->_userstate[$var_name] )) {
  583. $this->setUserState( $var_name, $var_default );
  584. }
  585. // filter input
  586. $iFilter = new InputFilter();
  587. $this->_userstate[$var_name] = $iFilter->process( $this->_userstate[$var_name] );
  588. return $this->_userstate[$var_name];
  589. } else {
  590. return null;
  591. }
  592. }
  593. /**
  594. * Sets the value of a user state variable
  595. * @param string The name of the variable
  596. * @param string The value of the variable
  597. */
  598. function setUserState( $var_name, $var_value ) {
  599. if (is_array( $this->_userstate )) {
  600. $this->_userstate[$var_name] = $var_value;
  601. }
  602. }
  603. /**
  604. * Initialises the user session
  605. *
  606. * Old sessions are flushed based on the configuration value for the cookie
  607. * lifetime. If an existing session, then the last access time is updated.
  608. * If a new session, a session id is generated and a record is created in
  609. * the jos_sessions table.
  610. */
  611. function initSession() {
  612. // initailize session variables
  613. $session =& $this->_session;
  614. $session = new mosSession( $this->_db );
  615. // purge expired sessions
  616. $session->purge('core');
  617. // Session Cookie `name`
  618. $sessionCookieName = mosMainFrame::sessionCookieName();
  619. // Get Session Cookie `value`
  620. $sessioncookie = strval( mosGetParam( $_COOKIE, $sessionCookieName, null ) );
  621. // Session ID / `value`
  622. $sessionValueCheck = mosMainFrame::sessionCookieValue( $sessioncookie );
  623. // Check if existing session exists in db corresponding to Session cookie `value`
  624. // extra check added in 1.0.8 to test sessioncookie value is of correct length
  625. if ( $sessioncookie && strlen($sessioncookie) == 32 && $sessioncookie != '-' && $session->load($sessionValueCheck) ) {
  626. // update time in session table
  627. $session->time = time();
  628. $session->update();
  629. } else {
  630. // Remember Me Cookie `name`
  631. $remCookieName = mosMainFrame::remCookieName_User();
  632. // test if cookie found
  633. $cookie_found = false;
  634. if ( isset($_COOKIE[$sessionCookieName]) || isset($_COOKIE[$remCookieName]) || isset($_POST['force_session']) ) {
  635. $cookie_found = true;
  636. }
  637. // check if neither remembermecookie or sessioncookie found
  638. if (!$cookie_found) {
  639. // create sessioncookie and set it to a test value set to expire on session end
  640. setcookie( $sessionCookieName, '-', false, '/' );
  641. } else {
  642. // otherwise, sessioncookie was found, but set to test val or the session expired, prepare for session registration and register the session
  643. $url = strval( mosGetParam( $_SERVER, 'REQUEST_URI', null ) );
  644. // stop sessions being created for requests to syndicated feeds
  645. if ( strpos( $url, 'option=com_rss' ) === false && strpos( $url, 'feed=' ) === false ) {
  646. $session->guest = 1;
  647. $session->username = '';
  648. $session->time = time();
  649. $session->gid = 0;
  650. // Generate Session Cookie `value`
  651. $session->generateId();
  652. if (!$session->insert()) {
  653. die( $session->getError() );
  654. }
  655. // create Session Tracking Cookie set to expire on session end
  656. setcookie( $sessionCookieName, $session->getCookie(), false, '/' );
  657. }
  658. }
  659. // Cookie used by Remember me functionality
  660. $remCookieValue = strval( mosGetParam( $_COOKIE, $remCookieName, null ) );
  661. // test if cookie is correct length
  662. if ( strlen($remCookieValue) > 64 ) {
  663. // Separate Values from Remember Me Cookie
  664. $remUser = substr( $remCookieValue, 0, 32 );
  665. $remPass = substr( $remCookieValue, 32, 32 );
  666. $remID = intval( substr( $remCookieValue, 64 ) );
  667. // check if Remember me cookie exists. Login with usercookie info.
  668. if ( strlen($remUser) == 32 && strlen($remPass) == 32 ) {
  669. $this->login( $remUser, $remPass, 1, $remID );
  670. }
  671. }
  672. }
  673. }
  674. /*
  675. * Function used to conduct admin session duties
  676. * Added as of 1.0.8
  677. * Deperciated 1.1
  678. */
  679. function initSessionAdmin($option, $task) {
  680. global $_VERSION, $mosConfig_admin_expired;
  681. // logout check
  682. if ($option == 'logout') {
  683. require $GLOBALS['mosConfig_absolute_path'] .'/administrator/logout.php';
  684. exit();
  685. }
  686. $site = $GLOBALS['mosConfig_live_site'];
  687. // check if session name corresponds to correct format
  688. if ( session_name() != md5( $site ) ) {
  689. echo "<script>document.location.href='index.php'</script>\n";
  690. exit();
  691. }
  692. // restore some session variables
  693. $my = new mosUser( $this->_db );
  694. $my->id = intval( mosGetParam( $_SESSION, 'session_user_id', '' ) );
  695. $my->username = strval( mosGetParam( $_SESSION, 'session_username', '' ) );
  696. $my->usertype = strval( mosGetParam( $_SESSION, 'session_usertype', '' ) );
  697. $my->gid = intval( mosGetParam( $_SESSION, 'session_gid', '' ) );
  698. $my->params = mosGetParam( $_SESSION, 'session_user_params', '' );
  699. //Create params object
  700. $params = new mosParameters($my->params);
  701. $session_id = mosGetParam( $_SESSION, 'session_id', '' );
  702. $logintime = mosGetParam( $_SESSION, 'session_logintime', '' );
  703. if ($session_id != session_id()) {
  704. // session id does not correspond to required session format
  705. echo "<script>document.location.href='index.php?mosmsg=Invalid Session'</script>\n";
  706. exit();
  707. }
  708. // check to see if session id corresponds with correct format
  709. if ( $session_id == md5( $my->id . $my->username . $my->usertype . $logintime ) ) {
  710. // if task action is to `save` or `apply` complete action before doing session checks.
  711. if ($task != 'save' && $task != 'apply') {
  712. // test for session_life_admin
  713. if ( @$GLOBALS['mosConfig_session_life_admin'] ) {
  714. $session_life_admin = $GLOBALS['mosConfig_session_life_admin'];
  715. } else {
  716. $session_life_admin = 1800;
  717. }
  718. // purge expired admin sessions only
  719. $past = time() - $session_life_admin;
  720. $query = "DELETE FROM #__session"
  721. . "\n WHERE time < '" . (int) $past . "'"
  722. . "\n AND guest = 1"
  723. . "\n AND gid = 0"
  724. . "\n AND userid <> 0"
  725. ;
  726. $this->_db->setQuery( $query );
  727. if(!$params->get('keep_session',0)) $this->_db->query();
  728. // update session timestamp
  729. $current_time = time();
  730. $query = "UPDATE #__session"
  731. . "\n SET time = " . $this->_db->Quote( $current_time )
  732. . "\n WHERE session_id = " . $this->_db->Quote( $session_id )
  733. ;
  734. $this->_db->setQuery( $query );
  735. $this->_db->query();
  736. // set garbage cleaning timeout
  737. $this->setSessionGarbageClean();
  738. // check against db record of session
  739. $query = "SELECT COUNT( session_id )"
  740. . "\n FROM #__session"
  741. . "\n WHERE session_id = " . $this->_db->Quote( $session_id )
  742. . "\n AND username = ". $this->_db->Quote( $my->username )
  743. . "\n AND userid = ". intval( $my->id )
  744. ;
  745. $this->_db->setQuery( $query );
  746. $count = $this->_db->loadResult();
  747. // if no entry in session table that corresponds boot from admin area
  748. if ( $count == 0 ) {
  749. $link = NULL;
  750. if ($_SERVER['QUERY_STRING']) {
  751. $link = 'index2.php?'. $_SERVER['QUERY_STRING'];
  752. }
  753. // check if site designated as a production site
  754. // for a demo site disallow expired page functionality
  755. // link must also be a Joomla link to stop malicious redirection
  756. if ( $link && strpos( $link, 'index2.php?option=com_' ) === 0 && $_VERSION->SITE == 1 && @$mosConfig_admin_expired === '1' ) {
  757. $now = time();
  758. $file = $this->getPath( 'com_xml', 'com_users' );
  759. $params = new mosParameters( $my->params, $file, 'component' );
  760. // return to expired page functionality
  761. $params->set( 'expired', $link );
  762. $params->set( 'expired_time', $now );
  763. // param handling
  764. if (is_array( $params->toArray() )) {
  765. $txt = array();
  766. foreach ( $params->toArray() as $k=>$v) {
  767. $txt[] = "$k=$v";
  768. }
  769. $saveparams = implode( "\n", $txt );
  770. }
  771. // save expired page info to user data
  772. $query = "UPDATE #__users"
  773. . "\n SET params = ". $this->_db->Quote( $saveparams )
  774. . "\n WHERE id = " . (int) $my->id
  775. . "\n AND username = ". $this->_db->Quote( $my->username )
  776. . "\n AND usertype = ". $this->_db->Quote( $my->usertype )
  777. ;
  778. $this->_db->setQuery( $query );
  779. $this->_db->query();
  780. }
  781. echo "<script>document.location.href='index.php?mosmsg=Admin Session Expired'</script>\n";
  782. exit();
  783. } else {
  784. // load variables into session, used to help secure /popups/ functionality
  785. $_SESSION['option'] = $option;
  786. $_SESSION['task'] = $task;
  787. }
  788. }
  789. } else if ($session_id == '') {
  790. // no session_id as user has not attempted to login, or session.auto_start is switched on
  791. if (ini_get( 'session.auto_start' ) || !ini_get( 'session.use_cookies' )) {
  792. 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";
  793. } else {
  794. echo "<script>document.location.href='index.php?mosmsg=You need to login'</script>\n";
  795. }
  796. exit();
  797. } else {
  798. // session id does not correspond to required session format
  799. echo "<script>document.location.href='index.php?mosmsg=Invalid Session'</script>\n";
  800. exit();
  801. }
  802. return $my;
  803. }
  804. /*
  805. * Function used to set Session Garbage Cleaning
  806. * garbage cleaning set at configured session time + 600 seconds
  807. * Added as of 1.0.8
  808. * Deperciated 1.1
  809. */
  810. function setSessionGarbageClean() {
  811. /** ensure that funciton is only called once */
  812. if (!defined( '_JOS_GARBAGECLEAN' )) {
  813. define( '_JOS_GARBAGECLEAN', 1 );
  814. $garbage_timeout = $this->getCfg('session_life_admin') + 600;
  815. @ini_set('session.gc_maxlifetime', $garbage_timeout);
  816. }
  817. }
  818. /*
  819. * Static Function used to generate the Session Cookie Name
  820. * Added as of 1.0.8
  821. * Deperciated 1.1
  822. */
  823. function sessionCookieName() {
  824. global $mainframe, $mosConfig_live_site;
  825. if( substr( $mosConfig_live_site, 0, 7 ) == 'http://' ) {
  826. $hash = md5( 'site' . substr( $mosConfig_live_site, 7 ) );
  827. } elseif( substr( $mosConfig_live_site, 0, 8 ) == 'https://' ) {
  828. $hash = md5( 'site' . substr( $mosConfig_live_site, 8 ) );
  829. } else {
  830. $hash = md5( 'site' . $mainframe->getCfg( 'live_site' ) );
  831. }
  832. return $hash;
  833. }
  834. /*
  835. * Static Function used to generate the Session Cookie Value
  836. * Added as of 1.0.8
  837. * Deperciated 1.1
  838. */
  839. function sessionCookieValue( $id=null ) {
  840. global $mainframe;
  841. $type = $mainframe->getCfg( 'session_type' );
  842. $browser = @$_SERVER['HTTP_USER_AGENT'];
  843. switch ($type) {
  844. case 2:
  845. // 1.0.0 to 1.0.7 Compatibility
  846. // lowest level security
  847. $value = md5( $id . $_SERVER['REMOTE_ADDR'] );
  848. break;
  849. case 1:
  850. // slightly reduced security - 3rd level IP authentication for those behind IP Proxy
  851. $remote_addr = explode('.',$_SERVER['REMOTE_ADDR']);
  852. $ip = $remote_addr[0] .'.'. $remote_addr[1] .'.'. $remote_addr[2];
  853. $value = mosHash( $id . $ip . $browser );
  854. break;
  855. default:
  856. // Highest security level - new default for 1.0.8 and beyond
  857. $ip = $_SERVER['REMOTE_ADDR'];
  858. $value = mosHash( $id . $ip . $browser );
  859. break;
  860. }
  861. return $value;
  862. }
  863. /*
  864. * Static Function used to generate the Rememeber Me Cookie Name for Username information
  865. * Added as of 1.0.8
  866. * Depreciated 1.1
  867. */
  868. function remCookieName_User() {
  869. $value = mosHash( 'remembermecookieusername'. mosMainFrame::sessionCookieName() );
  870. return $value;
  871. }
  872. /*
  873. * Static Function used to generate the Rememeber Me Cookie Name for Password information
  874. * Added as of 1.0.8
  875. * Depreciated 1.1
  876. */
  877. function remCookieName_Pass() {
  878. $value = mosHash( 'remembermecookiepassword'. mosMainFrame::sessionCookieName() );
  879. return $value;
  880. }
  881. /*
  882. * Static Function used to generate the Remember Me Cookie Value for Username information
  883. * Added as of 1.0.8
  884. * Depreciated 1.1
  885. */
  886. function remCookieValue_User( $username ) {
  887. $value = md5( $username . mosHash( @$_SERVER['HTTP_USER_AGENT'] ) );
  888. return $value;
  889. }
  890. /*
  891. * Static Function used to generate the Remember Me Cookie Value for Password information
  892. * Added as of 1.0.8
  893. * Depreciated 1.1
  894. */
  895. function remCookieValue_Pass( $passwd ) {
  896. $value = md5( $passwd . mosHash( @$_SERVER['HTTP_USER_AGENT'] ) );
  897. return $value;
  898. }
  899. /**
  900. * Login validation function
  901. *
  902. * Username and encoded password is compare to db entries in the jos_users
  903. * table. A successful validation updates the current session record with
  904. * the users details.
  905. */
  906. function login( $username=null,$passwd=null, $remember=0, $userid=NULL ) {
  907. global $acl, $_VERSION;
  908. $bypost = 0;
  909. $valid_remember = false;
  910. // if no username and password passed from function, then function is being called from login module/component
  911. if (!$username || !$passwd) {
  912. $username = stripslashes( strval( mosGetParam( $_POST, 'username', '' ) ) );
  913. $passwd = stripslashes( strval( mosGetParam( $_POST, 'passwd', '' ) ) );
  914. $bypost = 1;
  915. // extra check to ensure that Joomla! sessioncookie exists
  916. if (!$this->_session->session_id) {
  917. mosErrorAlert( _ALERT_ENABLED );
  918. return;
  919. }
  920. josSpoofCheck(NULL,1);
  921. }
  922. $row = null;
  923. if (!$username || !$passwd) {
  924. mosErrorAlert( _LOGIN_INCOMPLETE );
  925. exit();
  926. } else {
  927. if ( $remember && strlen($username) == 32 && $userid ) {
  928. // query used for remember me cookie
  929. $harden = mosHash( @$_SERVER['HTTP_USER_AGENT'] );
  930. $query = "SELECT id, name, username, password, usertype, block, gid"
  931. . "\n FROM #__users"
  932. . "\n WHERE id = " . (int) $userid
  933. ;
  934. $this->_db->setQuery( $query );
  935. $this->_db->loadObject($user);
  936. list($hash, $salt) = explode(':', $user->password);
  937. $check_username = md5( $user->username . $harden );
  938. $check_password = md5( $hash . $harden );
  939. if ( $check_username == $username && $check_password == $passwd ) {
  940. $row = $user;
  941. $valid_remember = true;
  942. }
  943. } else {
  944. // query used for login via login module
  945. $query = "SELECT id, name, username, password, usertype, block, gid"
  946. . "\n FROM #__users"
  947. . "\n WHERE username = ". $this->_db->Quote( $username )
  948. ;
  949. $this->_db->setQuery( $query );
  950. $this->_db->loadObject( $row );
  951. }
  952. if (is_object($row)) {
  953. // user blocked from login
  954. if ($row->block == 1) {
  955. mosErrorAlert(_LOGIN_BLOCKED);
  956. }
  957. if (!$valid_remember) {
  958. // Conversion to new type
  959. if ((strpos($row->password, ':') === false) && $row->password == md5($passwd)) {
  960. // Old password hash storage but authentic ... lets convert it
  961. $salt = mosMakePassword(16);
  962. $crypt = md5($passwd.$salt);
  963. $row->password = $crypt.':'.$salt;
  964. // Now lets store it in the database
  965. $query = 'UPDATE #__users'
  966. . ' SET password = '.$this->_db->Quote($row->password)
  967. . ' WHERE id = '.(int)$row->id;
  968. $this->_db->setQuery($query);
  969. if (!$this->_db->query()) {
  970. // This is an error but not sure what to do with it ... we'll still work for now
  971. }
  972. }
  973. list($hash, $salt) = explode(':', $row->password);
  974. $cryptpass = md5($passwd.$salt);
  975. if ($hash != $cryptpass) {
  976. if ( $bypost ) {
  977. mosErrorAlert(_LOGIN_INCORRECT);
  978. } else {
  979. $this->logout();
  980. mosRedirect('index.php');
  981. }
  982. exit();
  983. }
  984. }
  985. // fudge the group stuff
  986. $grp = $acl->getAroGroup( $row->id );
  987. $row->gid = 1;
  988. if ($acl->is_group_child_of( $grp->name, 'Registered', 'ARO' ) || $acl->is_group_child_of( $grp->name, 'Public Backend', 'ARO' )) {
  989. // fudge Authors, Editors, Publishers and Super Administrators into the Special Group
  990. $row->gid = 2;
  991. }
  992. $row->usertype = $grp->name;
  993. // initialize session data
  994. $session =& $this->_session;
  995. $session->guest = 0;
  996. $session->username = $row->username;
  997. $session->userid = intval( $row->id );
  998. $session->usertype = $row->usertype;
  999. $session->gid = intval( $row->gid );
  1000. $session->update();
  1001. // check to see if site is a production site
  1002. // allows multiple logins with same user for a demo site
  1003. if ( $_VERSION->SITE ) {
  1004. // delete any old front sessions to stop duplicate sessions
  1005. $query = "DELETE FROM #__session"
  1006. . "\n WHERE session_id != ". $this->_db->Quote( $session->session_id )
  1007. . "\n AND username = ". $this->_db->Quote( $row->username )
  1008. . "\n AND userid = " . (int) $row->id
  1009. . "\n AND gid = " . (int) $row->gid
  1010. . "\n AND guest = 0"
  1011. ;
  1012. $this->_db->setQuery( $query );
  1013. $this->_db->query();
  1014. }
  1015. // update user visit data
  1016. $currentDate = date("Y-m-d\TH:i:s");
  1017. $query = "UPDATE #__users"
  1018. . "\n SET lastvisitDate = ". $this->_db->Quote( $currentDate )
  1019. . "\n WHERE id = " . (int) $session->userid
  1020. ;
  1021. $this->_db->setQuery($query);
  1022. if (!$this->_db->query()) {
  1023. die($this->_db->stderr(true));
  1024. }
  1025. // set remember me cookie if selected
  1026. $remember = strval( mosGetParam( $_POST, 'remember', '' ) );
  1027. if ( $remember == 'yes' ) {
  1028. // cookie lifetime of 365 days
  1029. $lifetime = time() + 365*24*60*60;
  1030. $remCookieName = mosMainFrame::remCookieName_User();
  1031. $remCookieValue = mosMainFrame::remCookieValue_User( $row->username ) . mosMainFrame::remCookieValue_Pass( $hash ) . $row->id;
  1032. setcookie( $remCookieName, $remCookieValue, $lifetime, '/' );
  1033. }
  1034. mosCache::cleanCache();
  1035. } else {
  1036. if ( $bypost ) {
  1037. mosErrorAlert(_LOGIN_INCORRECT);
  1038. } else {
  1039. $this->logout();
  1040. mosRedirect('index.php');
  1041. }
  1042. exit();
  1043. }
  1044. }
  1045. }
  1046. /**
  1047. * User logout
  1048. *
  1049. * Reverts the current session record back to 'anonymous' parameters
  1050. */
  1051. function logout() {
  1052. mosCache::cleanCache();
  1053. $session =& $this->_session;
  1054. $session->guest = 1;
  1055. $session->username = '';
  1056. $session->userid = '';
  1057. $session->usertype = '';
  1058. $session->gid = 0;
  1059. $session->update();
  1060. // kill remember me cookie
  1061. $lifetime = time() - 86400;
  1062. $remCookieName = mosMainFrame::remCookieName_User();
  1063. setcookie( $remCookieName, ' ', $lifetime, '/' );
  1064. @session_destroy();
  1065. }
  1066. /**
  1067. * @return mosUser A user object with the information from the current session
  1068. */
  1069. function getUser() {
  1070. global $database;
  1071. $user = new mosUser( $this->_db );
  1072. $user->id = intval( $this->_session->userid );
  1073. $user->username = $this->_session->username;
  1074. $user->usertype = $this->_session->usertype;
  1075. $user->gid = intval( $this->_session->gid );
  1076. if ($user->id) {
  1077. $query = "SELECT id, name, email, block, sendEmail, registerDate, lastvisitDate, activation, params"
  1078. . "\n FROM #__users"
  1079. . "\n WHERE id = " . (int) $user->id
  1080. ;
  1081. $database->setQuery( $query );
  1082. $database->loadObject( $my );
  1083. $user->params = $my->params;
  1084. $user->name = $my->name;
  1085. $user->email = $my->email;
  1086. $user->block = $my->block;
  1087. $user->sendEmail = $my->sendEmail;
  1088. $user->registerDate = $my->registerDate;
  1089. $user->lastvisitDate = $my->lastvisitDate;
  1090. $user->activation = $my->activation;
  1091. }
  1092. return $user;
  1093. }
  1094. /**
  1095. * @param string The name of the variable (from configuration.php)
  1096. * @return mixed The value of the configuration variable or null if not found
  1097. */
  1098. function getCfg( $varname ) {
  1099. $varname = 'mosConfig_' . $varname;
  1100. if (isset( $GLOBALS[$varname] )) {
  1101. return $GLOBALS[$varname];
  1102. } else {
  1103. return null;
  1104. }
  1105. }
  1106. function _setTemplate( $isAdmin=false ) {
  1107. global $Itemid;
  1108. $mosConfig_absolute_path = $this->getCfg( 'absolute_path' );
  1109. if ($isAdmin) {
  1110. $query = "SELECT template"
  1111. . "\n FROM #__templates_menu"
  1112. . "\n WHERE client_id = 1"
  1113. . "\n AND menuid = 0"
  1114. ;
  1115. $this->_db->setQuery( $query );
  1116. $cur_template = $this->_db->loadResult();
  1117. $path = "$mosConfig_absolute_path/administrator/templates/$cur_template/index.php";
  1118. if (!file_exists( $path )) {
  1119. $cur_template = 'joomla_admin';
  1120. }
  1121. } else {
  1122. $assigned = ( !empty( $Itemid ) ? " OR menuid = " . (int) $Itemid : '' );
  1123. $query = "SELECT template"
  1124. . "\n FROM #__templates_menu"
  1125. . "\n WHERE client_id = 0"
  1126. . "\n AND ( menuid = 0 $assigned )"
  1127. . "\n ORDER BY menuid DESC"
  1128. ;
  1129. $this->_db->setQuery( $query, 0, 1 );
  1130. $cur_template = $this->_db->loadResult();
  1131. // TemplateChooser Start
  1132. $jos_user_template = strval( mosGetParam( $_COOKIE, 'jos_user_template', '' ) );
  1133. $jos_change_template = strval( mosGetParam( $_REQUEST, 'jos_change_template', $jos_user_template ) );
  1134. if ($jos_change_template) {
  1135. // clean template name
  1136. $jos_change_template = preg_replace( '#\W#', '', $jos_change_template );
  1137. if ( strlen( $jos_change_template ) >= 40 ) {
  1138. $jos_change_template = substr($jos_change_template, 0 , 39);
  1139. }
  1140. // check that template exists in case it was deleted
  1141. if (file_exists( $mosConfig_absolute_path .'/templates/'. $jos_change_template .'/index.php' )) {
  1142. $lifetime = 60*10;
  1143. $cur_template = $jos_change_template;
  1144. setcookie( 'jos_user_template', "$jos_change_template", time()+$lifetime);
  1145. } else {
  1146. setcookie( 'jos_user_template', '', time()-3600 );
  1147. }
  1148. }
  1149. // TemplateChooser End
  1150. }
  1151. $this->_template = $cur_template;
  1152. }
  1153. function getTemplate() {
  1154. return $this->_template;
  1155. }
  1156. /**
  1157. * Determines the paths for including engine and menu files
  1158. * @param string The current option used in the url
  1159. * @param string The base path from which to load the configuration file
  1160. */
  1161. function _setAdminPaths( $option, $basePath='.' ) {
  1162. $option = strtolower( $option );
  1163. $this->_path = new stdClass();
  1164. // security check to disable use of `/`, `\\` and `:` in $options variable
  1165. if (strpos($option, '/') !== false || strpos($option, '\\') !== false || strpos($option, ':') !== false) {
  1166. mosErrorAlert( 'Restricted access' );
  1167. return;
  1168. }
  1169. $prefix = substr( $option, 0, 4 );
  1170. if ($prefix != 'com_' && $prefix != 'mod_') {
  1171. // ensure backward compatibility with existing links
  1172. $name = $option;
  1173. $option = "com_$option";
  1174. } else {
  1175. $name = substr( $option, 4 );
  1176. }
  1177. // components
  1178. if (file_exists( "$basePath/templates/$this->_template/components/$name.html.php" )) {
  1179. $this->_path->front = "$basePath/components/$option/$name.php";
  1180. $this->_path->front_html = "$basePath/templates/$this->_template/components/$name.html.php";
  1181. } else if (file_exists( "$basePath/components/$option/$name.php" )) {
  1182. $this->_path->front = "$basePath/components/$option/$name.php";
  1183. $this->_path->front_html = "$basePath/components/$option/$name.html.php";
  1184. }
  1185. if (file_exists( "$basePath/administrator/components/$option/admin.$name.php" )) {
  1186. $this->_path->admin = "$basePath/administrator/components/$option/admin.$name.php";
  1187. $this->_path->admin_html = "$basePath/administrator/components/$option/admin.$name.html.php";
  1188. }
  1189. if (file_exists( "$basePath/administrator/components/$option/toolbar.$name.php" )) {
  1190. $this->_path->toolbar = "$basePath/administrator/components/$option/toolbar.$name.php";
  1191. $this->_path->toolbar_html = "$basePath/administrator/components/$option/toolbar.$name.html.php";
  1192. $this->_path->toolbar_default = "$basePath/administrator/includes/toolbar.html.php";
  1193. }
  1194. if (file_exists( "$basePath/components/$option/$name.class.php" )) {
  1195. $this->_path->class = "$basePath/components/$option/$name.class.php";
  1196. } else if (file_exists( "$basePath/administrator/components/$option/$name.class.php" )) {
  1197. $this->_path->class = "$basePath/administrator/components/$option/$name.class.php";
  1198. } else if (file_exists( "$basePath/includes/$name.php" )) {
  1199. $this->_path->class = "$basePath/includes/$name.php";
  1200. }
  1201. if ($prefix == 'mod_' && file_exists("$basePath/administrator/modules/$option.php")) {
  1202. $this->_path->admin = "$basePath/administrator/modules/$option.php";
  1203. $this->_path->admin_html = "$basePath/administrator/modules/mod_$name.html.php";
  1204. } else if (file_exists("$basePath/administrator/components/$option/admin.$name.php" )) {
  1205. $this->_path->admin = "$basePath/administrator/components/$option/admin.$name.php";
  1206. $this->_path->admin_html = "$basePath/administrator/components/$option/admin.$name.html.php";
  1207. } else {
  1208. $this->_path->admin = "$basePath/administrator/components/com_admin/admin.admin.php";
  1209. $this->_path->admin_html = "$basePath/administrator/components/com_admin/admin.admin.html.php";
  1210. }
  1211. }
  1212. /**
  1213. * Returns a stored path variable
  1214. *
  1215. */
  1216. function getPath( $varname, $option='' ) {
  1217. global $mosConfig_absolute_path;
  1218. if ($option) {
  1219. $temp = $this->_path;
  1220. $this->_setAdminPaths( $option, $this->getCfg( 'absolute_path' ) );
  1221. }
  1222. $result = null;
  1223. if (isset( $this->_path->$varname )) {
  1224. $result = $this->_path->$varname;
  1225. } else {
  1226. switch ($varname) {
  1227. case 'com_xml':
  1228. $name = substr( $option, 4 );
  1229. $path = "$mosConfig_absolute_path/administrator/components/$option/$name.xml";
  1230. if (file_exists( $path )) {
  1231. $result = $path;
  1232. } else {
  1233. $path = "$mosConfig_absolute_path/components/$option/$name.xml";
  1234. if (file_exists( $path )) {
  1235. $result = $path;
  1236. }
  1237. }
  1238. break;
  1239. case 'mod0_xml':
  1240. // Site modules
  1241. if ($option == '') {
  1242. $path = $mosConfig_absolute_path . "/modules/custom.xml";
  1243. } else {
  1244. $path = $mosConfig_absolute_path . "/modules/$option.xml";
  1245. }
  1246. if (file_exists( $path )) {
  1247. $result = $path;
  1248. }
  1249. break;
  1250. case 'mod1_xml':
  1251. // admin modules
  1252. if ($option == '') {
  1253. $path = $mosConfig_absolute_path . '/administrator/modules/custom.xml';
  1254. } else {
  1255. $path = $mosConfig_absolute_path . "/administrator/modules/$option.xml";
  1256. }
  1257. if (file_exists( $path )) {
  1258. $result = $path;
  1259. }
  1260. break;
  1261. case 'bot_xml':
  1262. // Site mambots
  1263. $path = $mosConfig_absolute_path . "/mambots/$option.xml";
  1264. if (file_exists( $path )) {
  1265. $result = $path;
  1266. }
  1267. break;
  1268. case 'menu_xml':
  1269. $path = $mosConfig_absolute_path . "/administrator/components/com_menus/$option/$option.xml";
  1270. if (file_exists( $path )) {
  1271. $result = $path;
  1272. }
  1273. break;
  1274. case 'installer_html':
  1275. $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$option/$option.html.php";
  1276. if (file_exists( $path )) {
  1277. $result = $path;
  1278. }
  1279. break;
  1280. case 'installer_class':
  1281. $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$option/$option.class.php";
  1282. if (file_exists( $path )) {
  1283. $result = $path;
  1284. }
  1285. break;
  1286. }
  1287. }
  1288. if ($option) {
  1289. $this->_path = $temp;
  1290. }
  1291. return $result;
  1292. }
  1293. /**
  1294. * Detects a 'visit'
  1295. *
  1296. * This function updates the agent and domain table hits for a particular
  1297. * visitor. The user agent is recorded/incremented if this is the first visit.
  1298. * A cookie is set to mark the first visit.
  1299. */
  1300. function detect() {
  1301. global $mosConfig_enable_stats;
  1302. if ($mosConfig_enable_stats == 1) {
  1303. if (mosGetParam( $_COOKIE, 'mosvisitor', 0 )) {
  1304. return;
  1305. }
  1306. setcookie( 'mosvisitor', 1 );
  1307. if (phpversion() <= '4.2.1') {
  1308. $agent = getenv( 'HTTP_USER_AGENT' );
  1309. $domain = @gethostbyaddr( getenv( "REMOTE_ADDR" ) );
  1310. } else {
  1311. if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
  1312. $agent = $_SERVER['HTTP_USER_AGENT'];
  1313. } else {
  1314. $agent = 'Unknown';
  1315. }
  1316. $domain = @gethostbyaddr( $_SERVER['REMOTE_ADDR'] );
  1317. }
  1318. $browser = mosGetBrowser( $agent );
  1319. $query = "SELECT COUNT(*)"
  1320. . "\n FROM #__stats_agents"
  1321. . "\n WHERE agent = " . $this->_db->Quote( $browser )
  1322. . "\n AND type = 0"
  1323. ;
  1324. $this->_db->setQuery( $query );
  1325. if ($this->_db->loadResult()) {
  1326. $query = "UPDATE #__stats_agents"
  1327. . "\n SET hits = ( hits + 1 )"
  1328. . "\n WHERE agent = " . $this->_db->Quote( $browser )
  1329. . "\n AND type = 0"
  1330. ;
  1331. $this->_db->setQuery( $query );
  1332. } else {
  1333. $query = "INSERT INTO #__stats_agents"
  1334. . "\n ( agent, type )"
  1335. . "\n VALUES ( " . $this->_db->Quote( $browser ) . ", 0 )"
  1336. ;
  1337. $this->_db->setQuery( $query );
  1338. }
  1339. $this->_db->query();
  1340. $os = mosGetOS( $agent );
  1341. $query = "SELECT COUNT(*)"
  1342. . "\n FROM #__stats_agents"
  1343. . "\n WHERE agent = " . $this->_db->Quote( $os )
  1344. . "\n AND type = 1"
  1345. ;
  1346. $this->_db->setQuery( $query );
  1347. if ($this->_db->loadResult()) {
  1348. $query = "UPDATE #__stats_agents"
  1349. . "\n SET hits = ( hits + 1 )"
  1350. . "\n WHERE agent = " . $this->_db->Quote( $os )
  1351. . "\n AND type = 1"
  1352. ;
  1353. $this->_db->setQuery( $query );
  1354. } else {
  1355. $query = "INSERT INTO #__stats_agents"
  1356. . "\n ( agent, type )"
  1357. . "\n VALUES ( " . $this->_db->Quote( $os ) . ", 1 )"
  1358. ;
  1359. $this->_db->setQuery( $query );
  1360. }
  1361. $this->_db->query();
  1362. // tease out the last element of the domain
  1363. $tldomain = split( "\.", $domain );
  1364. $tldomain = $tldomain[count( $tldomain )-1];
  1365. if (is_numeric( $tldomain )) {
  1366. $tldomain = "Unknown";
  1367. }
  1368. $query = "SELECT COUNT(*)"
  1369. . "\n FROM #__stats_agents"
  1370. . "\n WHERE agent = " . $this->_db->Quote( $tldomain )
  1371. . "\n AND type = 2"
  1372. ;
  1373. $this->_db->setQuery( $query );
  1374. if ($this->_db->loadResult()) {
  1375. $query = "UPDATE #__stats_agents"
  1376. . "\n SET hits = ( hits + 1 )"
  1377. . "\n WHERE agent = " . $this->_db->Quote( $tldomain )
  1378. . "\n AND type = 2"
  1379. ;
  1380. $this->_db->setQuery( $query );
  1381. } else {
  1382. $query = "INSERT INTO #__stats_agents"
  1383. . "\n ( agent, type )"
  1384. . "\n VALUES ( " . $this->_db->Quote( $tldomain ) . ", 2 )"
  1385. ;
  1386. $this->_db->setQuery( $query );
  1387. }
  1388. $this->_db->query();
  1389. }
  1390. }
  1391. /**
  1392. * @return correct Itemid for Content Item
  1393. */
  1394. function getItemid( $id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1 ) {
  1395. global $Itemid;
  1396. // getItemid compatibility mode, holds maintenance version number
  1397. $compat = (int) $this->getCfg('itemid_compat');
  1398. $compat = ($compat == 0)? 12 : $compat;
  1399. $_Itemid = '';
  1400. if ($_Itemid == '' && $typed && $this->getStaticContentCount()) {
  1401. $exists = 0;
  1402. foreach( $this->get( '_ContentTyped', array() ) as $key => $value ) {
  1403. // check if id has been tested before, if it is pull from class variable store
  1404. if ( $key == $id ) {
  1405. $_Itemid = $value;
  1406. $exists = 1;
  1407. break;
  1408. }
  1409. }
  1410. // if id hasnt been checked before initaite query
  1411. if ( !$exists ) {
  1412. // Search for typed link
  1413. $query = "SELECT id"
  1414. . "\n FROM #__menu"
  1415. . "\n WHERE type = 'content_typed'"
  1416. . "\n AND published = 1"
  1417. . "\n AND link = 'index.php?option=com_content&task=view&id=" . (int) $id . "'"
  1418. ;
  1419. $this->_db->setQuery( $query );
  1420. // pull existing query storage into temp variable
  1421. $ContentTyped = $this->get( '_ContentTyped', array() );
  1422. // add query result to temp array storage
  1423. $ContentTyped[$id] = $this->_db->loadResult();
  1424. // save temp array to main array storage
  1425. $this->set( '_ContentTyped', $ContentTyped );
  1426. $_Itemid = $ContentTyped[$id];
  1427. }
  1428. }
  1429. if ($_Itemid == '' && $link && $this->getContentItemLinkCount()) {
  1430. $exists = 0;
  1431. foreach( $this->get( '_ContentItemLink', array() ) as $key => $value ) {
  1432. // check if id has been tested before, if it is pull from class variable store
  1433. if ( $key == $id ) {
  1434. $_Itemid = $value;
  1435. $exists = 1;
  1436. break;
  1437. }
  1438. }
  1439. // if id hasnt been checked before initaite query
  1440. if ( !$exists ) {
  1441. // Search for item link
  1442. $query = "SELECT id"
  1443. ."\n FROM #__menu"
  1444. ."\n WHERE type = 'content_item_link'"
  1445. . "\n AND published = 1"
  1446. . "\n AND link = 'index.php?option=com_content&task=view&id=" . (int) $id . "'"
  1447. ;
  1448. $this->_db->setQuery( $query );
  1449. // pull existing query storage into temp variable
  1450. $ContentItemLink = $this->get( '_ContentItemLink', array() );
  1451. // add query result to temp array storage
  1452. $ContentItemLink[$id] = $this->_db->loadResult();
  1453. // save temp array to main array storage
  1454. $this->set( '_ContentItemLink', $ContentItemLink );
  1455. $_Itemid = $ContentItemLink[$id];
  1456. }
  1457. }
  1458. if ($_Itemid == '') {
  1459. $exists = 0;
  1460. foreach( $this->get( '_ContentSection', array() ) as $key => $value ) {
  1461. // check if id has been tested before, if it is pull from class variable store
  1462. if ( $key == $id ) {
  1463. $_Itemid = $value;
  1464. $exists = 1;
  1465. break;
  1466. }
  1467. }
  1468. // if id hasnt been checked before initaite query
  1469. if ( !$exists ) {
  1470. $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"
  1471. . "\n FROM #__content AS i"
  1472. . "\n LEFT JOIN #__sections AS s ON i.sectionid = s.id"
  1473. . "\n LEFT JOIN #__menu AS ms ON ms.componentid = s.id "
  1474. . "\n LEFT JOIN #__categories AS c ON i.catid = c.id"
  1475. . "\n LEFT JOIN #__menu AS mc ON mc.componentid = c.id "
  1476. . "\n WHERE ( ms.type IN ( 'content_section', 'content_blog_section' ) OR mc.type IN ( 'content_blog_category', 'content_category' ) )"
  1477. . "\n AND i.id = " . (int) $id
  1478. . "\n ORDER BY ms.type DESC, mc.type DESC, ms.id, mc.id"
  1479. ;
  1480. $this->_db->setQuery( $query );
  1481. $links = $this->_db->loadObjectList();
  1482. if (count($links)) {
  1483. foreach($links as $link) {
  1484. if ($link->stype == 'content_section' && $link->sectionid == $id && !isset($content_section) && $link->spub == 1) {
  1485. $content_section = $link->sid;
  1486. }
  1487. if ($link->stype == 'content_blog_section' && $link->sectionid == $id && !isset($content_blog_section) && $link->spub == 1) {
  1488. $content_blog_section = $link->sid;
  1489. }
  1490. if ($link->ctype == 'content_blog_category' && $link->catid == $id && !isset($content_blog_category) && $link->cpub == 1) {
  1491. $content_blog_category = $link->cid;
  1492. }
  1493. if ($link->ctype == 'content_category' && $link->catid == $id && !isset($content_category) && $link->cpub == 1) {
  1494. $content_category = $link->cid;
  1495. }
  1496. }
  1497. }
  1498. if (!isset($content_section)) {
  1499. $content_section = null;
  1500. }
  1501. // pull existing query storage into temp variable
  1502. $ContentSection = $this->get( '_ContentSection', array() );
  1503. // add query result to temp array storage
  1504. $ContentSection[$id] = $content_section;
  1505. // save temp array to main array storage
  1506. $this->set( '_ContentSection', $ContentSection );
  1507. $_Itemid = $ContentSection[$id];
  1508. }
  1509. }
  1510. if ( $compat <= 11 && $_Itemid == '') {
  1511. $exists = 0;
  1512. foreach( $this->get( '_ContentBlogSection', array() ) as $key => $value ) {
  1513. // check if id has been tested before, if it is pull from class variable store
  1514. if ( $key == $id ) {
  1515. $_Itemid = $value;
  1516. $exists = 1;
  1517. break;
  1518. }
  1519. }
  1520. // if id hasnt been checked before initaite query
  1521. if ( !$exists ) {
  1522. if (!isset($content_blog_section)) {
  1523. $content_blog_section = null;
  1524. }
  1525. // pull existing query storage into temp variable
  1526. $ContentBlogSection = $this->get( '_ContentBlogSection', array() );
  1527. // add query result to temp array storage
  1528. $ContentBlogSection[$id] = $content_blog_section;
  1529. // save temp array to main array storage
  1530. $this->set( '_ContentBlogSection', $ContentBlogSection );
  1531. $_Itemid = $ContentBlogSection[$id];
  1532. }
  1533. }
  1534. if ($_Itemid == '') {
  1535. $exists = 0;
  1536. foreach( $this->get( '_ContentBlogCategory', array() ) as $key => $value ) {
  1537. // check if id has been tested before, if it is pull from class variable store
  1538. if ( $key == $id ) {
  1539. $_Itemid = $value;
  1540. $exists = 1;
  1541. break;
  1542. }
  1543. }
  1544. // if id hasnt been checked before initaite query
  1545. if ( !$exists ) {
  1546. if (!isset($content_blog_category)) {
  1547. $content_blog_category = null;
  1548. }
  1549. // pull existing query storage into temp variable
  1550. $ContentBlogCategory = $this->get( '_ContentBlogCategory', array() );
  1551. // add query result to temp array storage
  1552. $ContentBlogCategory[$id] = $content_blog_category;
  1553. // save temp array to main array storage
  1554. $this->set( '_ContentBlogCategory', $ContentBlogCategory );
  1555. $_Itemid = $ContentBlogCategory[$id];
  1556. }
  1557. }
  1558. if ($_Itemid == '') {
  1559. // ensure that query is only called once
  1560. if ( !$this->get( '_GlobalBlogSection' ) && !defined( '_JOS_GBS' ) ) {
  1561. define( '_JOS_GBS', 1 );
  1562. // Search in global blog section
  1563. $query = "SELECT id "
  1564. . "\n FROM #__menu "
  1565. . "\n WHERE type = 'content_blog_section'"
  1566. . "\n AND published = 1"
  1567. . "\n AND componentid = 0"
  1568. ;
  1569. $this->_db->setQuery( $query );
  1570. $this->set( '_GlobalBlogSection', $this->_db->loadResult() );
  1571. }
  1572. $_Itemid = $this->get( '_GlobalBlogSection' );
  1573. }
  1574. if ($compat >= 12 && $_Itemid == '') {
  1575. $exists = 0;
  1576. foreach( $this->get( '_ContentBlogSection', array() ) as $key => $value ) {
  1577. // check if id has been tested before, if it is pull from class variable store
  1578. if ( $key == $id ) {
  1579. $_Itemid = $value;
  1580. $exists = 1;
  1581. break;
  1582. }
  1583. }
  1584. // if id hasnt been checked before initaite query
  1585. if ( !$exists ) {
  1586. if (!isset($content_blog_section)) {
  1587. $content_blog_section = null;
  1588. }
  1589. // pull existing query storage into temp variable
  1590. $ContentBlogSection = $this->get( '_ContentBlogSection', array() );
  1591. // add query result to temp array storage
  1592. $ContentBlogSection[$id] = $content_blog_section;
  1593. // save temp array to main array storage
  1594. $this->set( '_ContentBlogSection', $ContentBlogSection );
  1595. $_Itemid = $ContentBlogSection[$id];
  1596. }
  1597. }
  1598. if ($_Itemid == '') {
  1599. $exists = 0;
  1600. foreach( $this->get( '_ContentCategory', array() ) as $key => $value ) {
  1601. // check if id has been tested before, if it is pull from class variable store
  1602. if ( $key == $id ) {
  1603. $_Itemid = $value;
  1604. $exists = 1;
  1605. break;
  1606. }
  1607. }
  1608. // if id hasnt been checked before initaite query
  1609. if ( !$exists ) {
  1610. if (!isset($content_category)) {
  1611. $content_category = null;
  1612. }
  1613. // pull existing query storage into temp variable
  1614. $ContentCategory = $this->get( '_ContentCategory', array() );
  1615. // add query result to temp array storage
  1616. //$ContentCategory[$id] = $this->_db->loadResult();
  1617. $ContentCategory[$id] = $content_category;
  1618. // save temp array to main array storage
  1619. $this->set( '_ContentCategory', $ContentCategory );
  1620. $_Itemid = $ContentCategory[$id];
  1621. }
  1622. }
  1623. if ($_Itemid == '') {
  1624. // ensure that query is only called once
  1625. if ( !$this->get( '_GlobalBlogCategory' ) && !defined( '_JOS_GBC' ) ) {
  1626. define( '_JOS_GBC', 1 );
  1627. // Search in global blog category
  1628. $query = "SELECT id "
  1629. . "\n FROM #__menu "
  1630. . "\n WHERE type = 'content_blog_category'"
  1631. . "\n AND published = 1"
  1632. . "\n AND componentid = 0"
  1633. ;
  1634. $this->_db->setQuery( $query );
  1635. $this->set( '_GlobalBlogCategory', $this->_db->loadResult() );
  1636. }
  1637. $_Itemid = $this->get( '_GlobalBlogCategory' );
  1638. }
  1639. if ( $_Itemid != '' ) {
  1640. // if Itemid value discovered by queries, return this value
  1641. return $_Itemid;
  1642. } else if ( $compat >= 12 && $Itemid != 99999999 && $Itemid > 0 ) {
  1643. // if queries do not return Itemid value, return Itemid of page - if it is not 99999999
  1644. return $Itemid;
  1645. } else if ( $compat <= 11 && $Itemid === 0 ) {
  1646. // if queries do not return Itemid value, return Itemid of page - if it is not 99999999
  1647. return $Itemid;
  1648. }
  1649. }
  1650. /**
  1651. * @return number of Published Blog Sections
  1652. * Kept for Backward Compatability
  1653. */
  1654. function getBlogSectionCount( ) {
  1655. return 1;
  1656. }
  1657. /**
  1658. * @return number of Published Blog Categories
  1659. * Kept for Backward Compatability
  1660. */
  1661. function getBlogCategoryCount( ) {
  1662. return 1;
  1663. }
  1664. /**
  1665. * @return number of Published Global Blog Sections
  1666. * Kept for Backward Compatability
  1667. */
  1668. function getGlobalBlogSectionCount( ) {
  1669. return 1;
  1670. }
  1671. /**
  1672. * @return number of Static Content
  1673. */
  1674. function getStaticContentCount( ) {
  1675. // ensure that query is only called once
  1676. if ( !$this->get( '_StaticContentCount' ) && !defined( '_JOS_SCC' ) ) {
  1677. define( '_JOS_SCC', 1 );
  1678. $query = "SELECT COUNT( id )"
  1679. ."\n FROM #__menu "
  1680. ."\n WHERE type = 'content_typed'"
  1681. ."\n AND published = 1"
  1682. ;
  1683. $this->_db->setQuery( $query );
  1684. // saves query result to variable
  1685. $this->set( '_StaticContentCount', $this->_db->loadResult() );
  1686. }
  1687. return $this->get( '_StaticContentCount' );
  1688. }
  1689. /**
  1690. * @return number of Content Item Links
  1691. */
  1692. function getContentItemLinkCount( ) {
  1693. // ensure that query is only called once
  1694. if ( !$this->get( '_ContentItemLinkCount' ) && !defined( '_JOS_CILC' ) ) {
  1695. define( '_JOS_CILC', 1 );
  1696. $query = "SELECT COUNT( id )"
  1697. ."\n FROM #__menu "
  1698. ."\n WHERE type = 'content_item_link'"
  1699. ."\n AND published = 1"
  1700. ;
  1701. $this->_db->setQuery( $query );
  1702. // saves query result to variable
  1703. $this->set( '_ContentItemLinkCount', $this->_db->loadResult() );
  1704. }
  1705. return $this->get( '_ContentItemLinkCount' );
  1706. }
  1707. /**
  1708. * @param string The name of the property
  1709. * @param mixed The value of the property to set
  1710. */
  1711. function set( $property, $value=null ) {
  1712. $this->$property = $value;
  1713. }
  1714. /**
  1715. * @param string The name of the property
  1716. * @param mixed The default value
  1717. * @return mixed The value of the property
  1718. */
  1719. function get($property, $default=null) {
  1720. if(isset($this->$property)) {
  1721. return $this->$property;
  1722. } else {
  1723. return $default;
  1724. }
  1725. }
  1726. /** Is admin interface?
  1727. * @return boolean
  1728. * @since 1.0.2
  1729. */
  1730. function isAdmin() {
  1731. return $this->_isAdmin;
  1732. }
  1733. }
  1734. /**
  1735. * Component database table class
  1736. * @package Joomla
  1737. */
  1738. class mosComponent extends mosDBTable {
  1739. /** @var int Primary key */
  1740. var $id = null;
  1741. /** @var string */
  1742. var $name = null;
  1743. /** @var string */
  1744. var $link = null;
  1745. /** @var int */
  1746. var $menuid = null;
  1747. /** @var int */
  1748. var $parent = null;
  1749. /** @var string */
  1750. var $admin_menu_link = null;
  1751. /** @var string */
  1752. var $admin_menu_alt = null;
  1753. /** @var string */
  1754. var $option = null;
  1755. /** @var string */
  1756. var $ordering = null;
  1757. /** @var string */
  1758. var $admin_menu_img = null;
  1759. /** @var int */
  1760. var $iscore = null;
  1761. /** @var string */
  1762. var $params = null;
  1763. /**
  1764. * @param database A database connector object
  1765. */
  1766. function mosComponent( &$db ) {
  1767. $this->mosDBTable( '#__components', 'id', $db );
  1768. }
  1769. }
  1770. /**
  1771. * Utility class for all HTML drawing classes
  1772. * @package Joomla
  1773. */
  1774. class mosHTML {
  1775. function makeOption( $value, $text='', $value_name='value', $text_name='text' ) {
  1776. $obj = new stdClass;
  1777. $obj->$value_name = $value;
  1778. $obj->$text_name = trim( $text ) ? $text : $value;
  1779. return $obj;
  1780. }
  1781. function writableCell( $folder, $relative=1, $text='', $visible=1 ) {
  1782. $writeable = '<b><font color="green">Writeable</font></b>';
  1783. $unwriteable = '<b><font color="red">Unwriteable</font></b>';
  1784. echo '<tr>';
  1785. echo '<td class="item">';
  1786. echo $text;
  1787. if ( $visible ) {
  1788. echo $folder . '/';
  1789. }
  1790. echo '</td>';
  1791. echo '<td align="left">';
  1792. if ( $relative ) {
  1793. echo is_writable( "../$folder" ) ? $writeable : $unwriteable;
  1794. } else {
  1795. echo is_writable( "$folder" ) ? $writeable : $unwriteable;
  1796. }
  1797. echo '</td>';
  1798. echo '</tr>';
  1799. }
  1800. /**
  1801. * Generates an HTML select list
  1802. * @param array An array of objects
  1803. * @param string The value of the HTML name attribute
  1804. * @param string Additional HTML attributes for the <select> tag
  1805. * @param string The name of the object variable for the option value
  1806. * @param string The name of the object variable for the option text
  1807. * @param mixed The key that is selected
  1808. * @returns string HTML for the select list
  1809. */
  1810. function selectList( &$arr, $tag_name, $tag_attribs, $key, $text, $selected=NULL ) {
  1811. // check if array
  1812. if ( is_array( $arr ) ) {
  1813. reset( $arr );
  1814. }
  1815. $html = "\n<select name=\"$tag_name\" $tag_attribs>";
  1816. $count = count( $arr );
  1817. for ($i=0, $n=$count; $i < $n; $i++ ) {
  1818. $k = $arr[$i]->$key;
  1819. $t = $arr[$i]->$text;
  1820. $id = ( isset($arr[$i]->id) ? @$arr[$i]->id : null);
  1821. $extra = '';
  1822. $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
  1823. if (is_array( $selected )) {
  1824. foreach ($selected as $obj) {
  1825. $k2 = $obj->$key;
  1826. if ($k == $k2) {
  1827. $extra .= " selected=\"selected\"";
  1828. break;
  1829. }
  1830. }
  1831. } else {
  1832. $extra .= ($k == $selected ? " selected=\"selected\"" : '');
  1833. }
  1834. $html .= "\n\t<option value=\"".$k."\"$extra>" . $t . "</option>";
  1835. }
  1836. $html .= "\n</select>\n";
  1837. return $html;
  1838. }
  1839. /**
  1840. * Writes a select list of integers
  1841. * @param int The start integer
  1842. * @param int The end integer
  1843. * @param int The increment
  1844. * @param string The value of the HTML name attribute
  1845. * @param string Additional HTML attributes for the <select> tag
  1846. * @param mixed The key that is selected
  1847. * @param string The printf format to be applied to the number
  1848. * @returns string HTML for the select list
  1849. */
  1850. function integerSelectList( $start, $end, $inc, $tag_name, $tag_attribs, $selected, $format="" ) {
  1851. $start = intval( $start );
  1852. $end = intval( $end );
  1853. $inc = intval( $inc );
  1854. $arr = array();
  1855. for ($i=$start; $i <= $end; $i+=$inc) {
  1856. $fi = $format ? sprintf( "$format", $i ) : "$i";
  1857. $arr[] = mosHTML::makeOption( $fi, $fi );
  1858. }
  1859. return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
  1860. }
  1861. /**
  1862. * Writes a select list of month names based on Language settings
  1863. * @param string The value of the HTML name attribute
  1864. * @param string Additional HTML attributes for the <select> tag
  1865. * @param mixed The key that is selected
  1866. * @returns string HTML for the select list values
  1867. */
  1868. function monthSelectList( $tag_name, $tag_attribs, $selected ) {
  1869. $arr = array(
  1870. mosHTML::makeOption( '01', _JAN ),
  1871. mosHTML::makeOption( '02', _FEB ),
  1872. mosHTML::makeOption( '03', _MAR ),
  1873. mosHTML::makeOption( '04', _APR ),
  1874. mosHTML::makeOption( '05', _MAY ),
  1875. mosHTML::makeOption( '06', _JUN ),
  1876. mosHTML::makeOption( '07', _JUL ),
  1877. mosHTML::makeOption( '08', _AUG ),
  1878. mosHTML::makeOption( '09', _SEP ),
  1879. mosHTML::makeOption( '10', _OCT ),
  1880. mosHTML::makeOption( '11', _NOV ),
  1881. mosHTML::makeOption( '12', _DEC )
  1882. );
  1883. return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
  1884. }
  1885. /**
  1886. * Generates an HTML select list from a tree based query list
  1887. * @param array Source array with id and parent fields
  1888. * @param array The id of the current list item
  1889. * @param array Target array. May be an empty array.
  1890. * @param array An array of objects
  1891. * @param string The value of the HTML name attribute
  1892. * @param string Additional HTML attributes for the <select> tag
  1893. * @param string The name of the object variable for the option value
  1894. * @param string The name of the object variable for the option text
  1895. * @param mixed The key that is selected
  1896. * @returns string HTML for the select list
  1897. */
  1898. function treeSelectList( &$src_list, $src_id, $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected ) {
  1899. // establish the hierarchy of the menu
  1900. $children = array();
  1901. // first pass - collect children
  1902. foreach ($src_list as $v ) {
  1903. $pt = $v->parent;
  1904. $list = @$children[$pt] ? $children[$pt] : array();
  1905. array_push( $list, $v );
  1906. $children[$pt] = $list;
  1907. }
  1908. // second pass - get an indent list of the items
  1909. $ilist = mosTreeRecurse( 0, '', array(), $children );
  1910. // assemble menu items to the array
  1911. $this_treename = '';
  1912. foreach ($ilist as $item) {
  1913. if ($this_treename) {
  1914. if ($item->id != $src_id && strpos( $item->treename, $this_treename ) === false) {
  1915. $tgt_list[] = mosHTML::makeOption( $item->id, $item->treename );
  1916. }
  1917. } else {
  1918. if ($item->id != $src_id) {
  1919. $tgt_list[] = mosHTML::makeOption( $item->id, $item->treename );
  1920. } else {
  1921. $this_treename = "$item->treename/";
  1922. }
  1923. }
  1924. }
  1925. // build the html select list
  1926. return mosHTML::selectList( $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected );
  1927. }
  1928. /**
  1929. * Writes a yes/no select list
  1930. * @param string The value of the HTML name attribute
  1931. * @param string Additional HTML attributes for the <select> tag
  1932. * @param mixed The key that is selected
  1933. * @returns string HTML for the select list values
  1934. */
  1935. function yesnoSelectList( $tag_name, $tag_attribs, $selected, $yes=_CMN_YES, $no=_CMN_NO ) {
  1936. $arr = array(
  1937. mosHTML::makeOption( '0', $no ),
  1938. mosHTML::makeOption( '1', $yes ),
  1939. );
  1940. return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
  1941. }
  1942. /**
  1943. * Generates an HTML radio list
  1944. * @param array An array of objects
  1945. * @param string The value of the HTML name attribute
  1946. * @param string Additional HTML attributes for the <select> tag
  1947. * @param mixed The key that is selected
  1948. * @param string The name of the object variable for the option value
  1949. * @param string The name of the object variable for the option text
  1950. * @returns string HTML for the select list
  1951. */
  1952. function radioList( &$arr, $tag_name, $tag_attribs, $selected=null, $key='value', $text='text' ) {
  1953. reset( $arr );
  1954. $html = "";
  1955. for ($i=0, $n=count( $arr ); $i < $n; $i++ ) {
  1956. $k = $arr[$i]->$key;
  1957. $t = $arr[$i]->$text;
  1958. $id = ( isset($arr[$i]->id) ? @$arr[$i]->id : null);
  1959. $extra = '';
  1960. $extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
  1961. if (is_array( $selected )) {
  1962. foreach ($selected as $obj) {
  1963. $k2 = $obj->$key;
  1964. if ($k == $k2) {
  1965. $extra .= " selected=\"selected\"";
  1966. break;
  1967. }
  1968. }
  1969. } else {
  1970. $extra .= ($k == $selected ? " checked=\"checked\"" : '');
  1971. }
  1972. $html .= "\n\t<input type=\"radio\" name=\"$tag_name\" id=\"$tag_name$k\" value=\"".$k."\"$extra $tag_attribs />";
  1973. $html .= "\n\t<label for=\"$tag_name$k\">$t</label>";
  1974. }
  1975. $html .= "\n";
  1976. return $html;
  1977. }
  1978. /**
  1979. * Writes a yes/no radio list
  1980. * @param string The value of the HTML name attribute
  1981. * @param string Additional HTML attributes for the <select> tag
  1982. * @param mixed The key that is selected
  1983. * @returns string HTML for the radio list
  1984. */
  1985. function yesnoRadioList( $tag_name, $tag_attribs, $selected, $yes=_CMN_YES, $no=_CMN_NO ) {
  1986. $arr = array(
  1987. mosHTML::makeOption( '0', $no ),
  1988. mosHTML::makeOption( '1', $yes )
  1989. );
  1990. return mosHTML::radioList( $arr, $tag_name, $tag_attribs, $selected );
  1991. }
  1992. /**
  1993. * @param int The row index
  1994. * @param int The record id
  1995. * @param boolean
  1996. * @param string The name of the form element
  1997. * @return string
  1998. */
  1999. function idBox( $rowNum, $recId, $checkedOut=false, $name='cid' ) {
  2000. if ( $checkedOut ) {
  2001. return '';
  2002. } else {
  2003. return '<input type="checkbox" id="cb'.$rowNum.'" name="'.$name.'[]" value="'.$recId.'" onclick="isChecked(this.checked);" />';
  2004. }
  2005. }
  2006. function sortIcon( $base_href, $field, $state='none' ) {
  2007. global $mosConfig_live_site;
  2008. $alts = array(
  2009. 'none' => _CMN_SORT_NONE,
  2010. 'asc' => _CMN_SORT_ASC,
  2011. 'desc' => _CMN_SORT_DESC,
  2012. );
  2013. $next_state = 'asc';
  2014. if ($state == 'asc') {
  2015. $next_state = 'desc';
  2016. } else if ($state == 'desc') {
  2017. $next_state = 'none';
  2018. }
  2019. $html = "<a href=\"$base_href&field=$field&order=$next_state\">"
  2020. . "<img src=\"$mosConfig_live_site/images/M_images/sort_$state.png\" width=\"12\" height=\"12\" border=\"0\" alt=\"{$alts[$next_state]}\" />"
  2021. . "</a>";
  2022. return $html;
  2023. }
  2024. /**
  2025. * Writes Close Button
  2026. */
  2027. function CloseButton ( &$params, $hide_js=NULL ) {
  2028. // displays close button in Pop-up window
  2029. if ( $params->get( 'popup' ) && !$hide_js ) {
  2030. ?>
  2031. <script language="javascript" type="text/javascript">
  2032. <!--
  2033. document.write('<div align="center" style="margin-top: 30px; margin-bottom: 30px;">');
  2034. document.write('<a href="#" onclick="javascript:window.close();"><span class="small"><?php echo _PROMPT_CLOSE;?></span></a>');
  2035. document.write('</div>');
  2036. //-->
  2037. </script>
  2038. <?php
  2039. }
  2040. }
  2041. /**
  2042. * Writes Back Button
  2043. */
  2044. function BackButton ( &$params, $hide_js=NULL ) {
  2045. // Back Button
  2046. if ( $params->get( 'back_button' ) && !$params->get( 'popup' ) && !$hide_js) {
  2047. ?>
  2048. <div class="back_button">
  2049. <a href='javascript:history.go(-1)'>
  2050. <?php echo _BACK; ?></a>
  2051. </div>
  2052. <?php
  2053. }
  2054. }
  2055. /**
  2056. * Cleans text of all formating and scripting code
  2057. */
  2058. function cleanText ( &$text ) {
  2059. $text = preg_replace( "'<script[^>]*>.*?</script>'si", '', $text );
  2060. $text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text );
  2061. $text = preg_replace( '/<!--.+?-->/', '', $text );
  2062. $text = preg_replace( '/{.+?}/', '', $text );
  2063. $text = preg_replace( '/&nbsp;/', ' ', $text );
  2064. $text = preg_replace( '/&amp;/', ' ', $text );
  2065. $text = preg_replace( '/&quot;/', ' ', $text );
  2066. $text = strip_tags( $text );
  2067. $text = htmlspecialchars( $text );
  2068. return $text;
  2069. }
  2070. /**
  2071. * Writes Print icon
  2072. */
  2073. function PrintIcon( &$row, &$params, $hide_js, $link, $status=NULL ) {
  2074. if ( $params->get( 'print' ) && !$hide_js ) {
  2075. // use default settings if none declared
  2076. if ( !$status ) {
  2077. $status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
  2078. }
  2079. // checks template image directory for image, if non found default are loaded
  2080. if ( $params->get( 'icons' ) ) {
  2081. $image = mosAdminMenus::ImageCheck( 'printButton.png', '/images/M_images/', NULL, NULL, _CMN_PRINT, NULL );
  2082. } else {
  2083. $image = _ICON_SEP .'&nbsp;'. _CMN_PRINT. '&nbsp;'. _ICON_SEP;
  2084. }
  2085. // ------------------------ A8E fixes start ------------------------
  2086. if ( $params->get( 'popup' ) && !$hide_js ) {
  2087. // Print Preview button - used when viewing page
  2088. ?>
  2089. <script language="javascript" type="text/javascript">
  2090. <!--
  2091. document.write('<a href="#" onclick="window.print(); return false;" title="<?php echo _CMN_PRINT;?>" class="print_icon">');
  2092. document.write('<?php echo $image;?>');
  2093. document.write('</a>');
  2094. window.onload = self.print();
  2095. //-->
  2096. </script>
  2097. <?php
  2098. } else {
  2099. // Print Button - used in pop-up window
  2100. ?>
  2101. <a href="<?php echo $link; ?>" onclick="window.open('<?php echo $link; ?>','win2','<?php echo $status; ?>'); return false;" title="<?php echo _CMN_PRINT;?>" class="print_icon" rel='nofollow external'>
  2102. <?php echo $image;?></a>
  2103. <?php
  2104. }
  2105. // ------------------------ A8E fixes end ------------------------
  2106. }
  2107. }
  2108. /**
  2109. * simple Javascript Cloaking
  2110. * email cloacking
  2111. * by default replaces an email with a mailto link with email cloacked
  2112. */
  2113. function emailCloaking( $mail, $mailto=1, $text='', $email=1 ) {
  2114. // convert text
  2115. $mail = mosHTML::encoding_converter( $mail );
  2116. // split email by @ symbol
  2117. $mail = explode( '@', $mail );
  2118. $mail_parts = explode( '.', $mail[1] );
  2119. // random number
  2120. $rand = rand( 1, 100000 );
  2121. $replacement = "\n <script type='text/javascript'>";
  2122. $replacement .= "\n <!--";
  2123. $replacement .= "\n var prefix = '&#109;a' + 'i&#108;' + '&#116;o';";
  2124. $replacement .= "\n var path = 'hr' + 'ef' + '=';";
  2125. $replacement .= "\n var addy". $rand ." = '". @$mail[0] ."' + '&#64;';";
  2126. $replacement .= "\n addy". $rand ." = addy". $rand ." + '". implode( "' + '&#46;' + '", $mail_parts ) ."';";
  2127. if ( $mailto ) {
  2128. // special handling when mail text is different from mail addy
  2129. if ( $text ) {
  2130. if ( $email ) {
  2131. // convert text
  2132. $text = mosHTML::encoding_converter( $text );
  2133. // split email by @ symbol
  2134. $text = explode( '@', $text );
  2135. $text_parts = explode( '.', $text[1] );
  2136. $replacement .= "\n var addy_text". $rand ." = '". @$text[0] ."' + '&#64;' + '". implode( "' + '&#46;' + '", @$text_parts ) ."';";
  2137. } else {
  2138. $replacement .= "\n var addy_text". $rand ." = '". $text ."';";
  2139. }
  2140. $replacement .= "\n document.write( '<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>' );";
  2141. $replacement .= "\n document.write( addy_text". $rand ." );";
  2142. $replacement .= "\n document.write( '<\/a>' );";
  2143. } else {
  2144. $replacement .= "\n document.write( '<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>' );";
  2145. $replacement .= "\n document.write( addy". $rand ." );";
  2146. $replacement .= "\n document.write( '<\/a>' );";
  2147. }
  2148. } else {
  2149. $replacement .= "\n document.write( addy". $rand ." );";
  2150. }
  2151. $replacement .= "\n //-->";
  2152. $replacement .= '\n </script>';
  2153. // XHTML compliance `No Javascript` text handling
  2154. $replacement .= "<script language='JavaScript' type='text/javascript'>";
  2155. $replacement .= "\n <!--";
  2156. $replacement .= "\n document.write( '<span style=\'display: none;\'>' );";
  2157. $replacement .= "\n //-->";
  2158. $replacement .= "\n </script>";
  2159. $replacement .= _CLOAKING;
  2160. $replacement .= "\n <script language='JavaScript' type='text/javascript'>";
  2161. $replacement .= "\n <!--";
  2162. $replacement .= "\n document.write( '</' );";
  2163. $replacement .= "\n document.write( 'span>' );";
  2164. $replacement .= "\n //-->";
  2165. $replacement .= "\n </script>";
  2166. return $replacement;
  2167. }
  2168. function encoding_converter( $text ) {
  2169. // replace vowels with character encoding
  2170. $text = str_replace( 'a', '&#97;', $text );
  2171. $text = str_replace( 'e', '&#101;', $text );
  2172. $text = str_replace( 'i', '&#105;', $text );
  2173. $text = str_replace( 'o', '&#111;', $text );
  2174. $text = str_replace( 'u', '&#117;', $text );
  2175. return $text;
  2176. }
  2177. }
  2178. /**
  2179. * Category database table class
  2180. * @package Joomla
  2181. */
  2182. class mosCategory extends mosDBTable {
  2183. /** @var int Primary key */
  2184. var $id = null;
  2185. /** @var int */
  2186. var $parent_id = null;
  2187. /** @var string The menu title for the Category (a short name)*/
  2188. var $title = null;
  2189. /** @var string The full name for the Category*/
  2190. var $name = null;
  2191. /** @var string */
  2192. var $image = null;
  2193. /** @var string */
  2194. var $section = null;
  2195. /** @var int */
  2196. var $image_position = null;
  2197. /** @var string */
  2198. var $description = null;
  2199. /** @var boolean */
  2200. var $published = null;
  2201. /** @var boolean */
  2202. var $checked_out = null;
  2203. /** @var time */
  2204. var $checked_out_time = null;
  2205. /** @var int */
  2206. var $ordering = null;
  2207. /** @var int */
  2208. var $access = null;
  2209. /** @var string */
  2210. var $params = null;
  2211. /**
  2212. * @param database A database connector object
  2213. */
  2214. function mosCategory( &$db ) {
  2215. $this->mosDBTable( '#__categories', 'id', $db );
  2216. }
  2217. // overloaded check function
  2218. function check() {
  2219. // check for valid name
  2220. if (trim( $this->title ) == '') {
  2221. $this->_error = "Your Category must contain a title.";
  2222. return false;
  2223. }
  2224. if (trim( $this->name ) == '') {
  2225. $this->_error = "Your Category must have a name.";
  2226. return false;
  2227. }
  2228. $ignoreList = array('description');
  2229. $this->filter($ignoreList);
  2230. // check for existing name
  2231. $query = "SELECT id"
  2232. . "\n FROM #__categories "
  2233. . "\n WHERE name = " . $this->_db->Quote( $this->name )
  2234. . "\n AND section = " . $this->_db->Quote( $this->section )
  2235. ;
  2236. $this->_db->setQuery( $query );
  2237. $xid = intval( $this->_db->loadResult() );
  2238. if ($xid && $xid != intval( $this->id )) {
  2239. $this->_error = "There is a category already with that name, please try again.";
  2240. return false;
  2241. }
  2242. return true;
  2243. }
  2244. }
  2245. /**
  2246. * Section database table class
  2247. * @package Joomla
  2248. */
  2249. class mosSection extends mosDBTable {
  2250. /** @var int Primary key */
  2251. var $id = null;
  2252. /** @var string The menu title for the Section (a short name)*/
  2253. var $title = null;
  2254. /** @var string The full name for the Section*/
  2255. var $name = null;
  2256. /** @var string */
  2257. var $image = null;
  2258. /** @var string */
  2259. var $scope = null;
  2260. /** @var int */
  2261. var $image_position = null;
  2262. /** @var string */
  2263. var $description = null;
  2264. /** @var boolean */
  2265. var $published = null;
  2266. /** @var boolean */
  2267. var $checked_out = null;
  2268. /** @var time */
  2269. var $checked_out_time = null;
  2270. /** @var int */
  2271. var $ordering = null;
  2272. /** @var int */
  2273. var $access = null;
  2274. /** @var string */
  2275. var $params = null;
  2276. /**
  2277. * @param database A database connector object
  2278. */
  2279. function mosSection( &$db ) {
  2280. $this->mosDBTable( '#__sections', 'id', $db );
  2281. }
  2282. // overloaded check function
  2283. function check() {
  2284. // check for valid name
  2285. if (trim( $this->title ) == '') {
  2286. $this->_error = "Your Section must contain a title.";
  2287. return false;
  2288. }
  2289. if (trim( $this->name ) == '') {
  2290. $this->_error = "Your Section must have a name.";
  2291. return false;
  2292. }
  2293. $ignoreList = array('description');
  2294. $this->filter($ignoreList);
  2295. // check for existing name
  2296. $query = "SELECT id"
  2297. . "\n FROM #__sections "
  2298. . "\n WHERE name = " . $this->_db->Quote( $this->name )
  2299. . "\n AND scope = " . $this->_db->Quote( $this->scope )
  2300. ;
  2301. $this->_db->setQuery( $query );
  2302. $xid = intval( $this->_db->loadResult() );
  2303. if ($xid && $xid != intval( $this->id )) {
  2304. $this->_error = "There is a section already with that name, please try again.";
  2305. return false;
  2306. }
  2307. return true;
  2308. }
  2309. }
  2310. /**
  2311. * Module database table class
  2312. * @package Joomla
  2313. */
  2314. class mosContent extends mosDBTable {
  2315. /** @var int Primary key */
  2316. var $id = null;
  2317. /** @var string */
  2318. var $title = null;
  2319. /** @var string */
  2320. var $title_alias = null;
  2321. /** @var string */
  2322. var $introtext = null;
  2323. /** @var string */
  2324. var $fulltext = null;
  2325. /** @var int */
  2326. var $state = null;
  2327. /** @var int The id of the category section*/
  2328. var $sectionid = null;
  2329. /** @var int DEPRECATED */
  2330. var $mask = null;
  2331. /** @var int */
  2332. var $catid = null;
  2333. /** @var datetime */
  2334. var $created = null;
  2335. /** @var int User id*/
  2336. var $created_by = null;
  2337. /** @var string An alias for the author*/
  2338. var $created_by_alias = null;
  2339. /** @var datetime */
  2340. var $modified = null;
  2341. /** @var int User id*/
  2342. var $modified_by = null;
  2343. /** @var boolean */
  2344. var $checked_out = null;
  2345. /** @var time */
  2346. var $checked_out_time = null;
  2347. /** @var datetime */
  2348. var $frontpage_up = null;
  2349. /** @var datetime */
  2350. var $frontpage_down = null;
  2351. /** @var datetime */
  2352. var $publish_up = null;
  2353. /** @var datetime */
  2354. var $publish_down = null;
  2355. /** @var string */
  2356. var $images = null;
  2357. /** @var string */
  2358. var $urls = null;
  2359. /** @var string */
  2360. var $attribs = null;
  2361. /** @var int */
  2362. var $version = null;
  2363. /** @var int */
  2364. var $parentid = null;
  2365. /** @var int */
  2366. var $ordering = null;
  2367. /** @var string */
  2368. var $metakey = null;
  2369. /** @var string */
  2370. var $metadesc = null;
  2371. /** @var int */
  2372. var $access = null;
  2373. /** @var int */
  2374. var $hits = null;
  2375. /**
  2376. * @param database A database connector object
  2377. */
  2378. function mosContent( &$db ) {
  2379. $this->mosDBTable( '#__content', 'id', $db );
  2380. }
  2381. /**
  2382. * Validation and filtering
  2383. */
  2384. function check() {
  2385. // filter malicious code
  2386. $ignoreList = array( 'introtext', 'fulltext' );
  2387. $this->filter( $ignoreList );
  2388. /*
  2389. TODO: This filter is too rigorous,
  2390. need to implement more configurable solution
  2391. // specific filters
  2392. $iFilter = new InputFilter( null, null, 1, 1 );
  2393. $this->introtext = trim( $iFilter->process( $this->introtext ) );
  2394. $this->fulltext = trim( $iFilter->process( $this->fulltext ) );
  2395. */
  2396. if (trim( str_replace( '&nbsp;', '', $this->fulltext ) ) == '') {
  2397. $this->fulltext = '';
  2398. }
  2399. return true;
  2400. }
  2401. /**
  2402. * Converts record to XML
  2403. * @param boolean Map foreign keys to text values
  2404. */
  2405. function toXML( $mapKeysToText=false ) {
  2406. global $database;
  2407. if ($mapKeysToText) {
  2408. $query = "SELECT name"
  2409. . "\n FROM #__sections"
  2410. . "\n WHERE id = " . (int) $this->sectionid
  2411. ;
  2412. $database->setQuery( $query );
  2413. $this->sectionid = $database->loadResult();
  2414. $query = "SELECT name"
  2415. . "\n FROM #__categories"
  2416. . "\n WHERE id = " . (int) $this->catid
  2417. ;
  2418. $database->setQuery( $query );
  2419. $this->catid = $database->loadResult();
  2420. $query = "SELECT name"
  2421. . "\n FROM #__users"
  2422. . "\n WHERE id = " . (int) $this->created_by
  2423. ;
  2424. $database->setQuery( $query );
  2425. $this->created_by = $database->loadResult();
  2426. }
  2427. return parent::toXML( $mapKeysToText );
  2428. }
  2429. }
  2430. /**
  2431. * Module database table class
  2432. * @package Joomla
  2433. */
  2434. class mosMenu extends mosDBTable {
  2435. /** @var int Primary key */
  2436. var $id = null;
  2437. /** @var string */
  2438. var $menutype = null;
  2439. /** @var string */
  2440. var $name = null;
  2441. /** @var string */
  2442. var $link = null;
  2443. /** @var int */
  2444. var $type = null;
  2445. /** @var int */
  2446. var $published = null;
  2447. /** @var int */
  2448. var $componentid = null;
  2449. /** @var int */
  2450. var $parent = null;
  2451. /** @var int */
  2452. var $sublevel = null;
  2453. /** @var int */
  2454. var $ordering = null;
  2455. /** @var boolean */
  2456. var $checked_out = null;
  2457. /** @var datetime */
  2458. var $checked_out_time = null;
  2459. /** @var boolean */
  2460. var $pollid = null;
  2461. /** @var string */
  2462. var $browserNav = null;
  2463. /** @var int */
  2464. var $access = null;
  2465. /** @var int */
  2466. var $utaccess = null;
  2467. /** @var string */
  2468. var $params = null;
  2469. /** @var bool */
  2470. var $default = null;
  2471. /**
  2472. * @param database A database connector object
  2473. */
  2474. function mosMenu( &$db ) {
  2475. $this->mosDBTable( '#__menu', 'id', $db );
  2476. }
  2477. function check() {
  2478. $this->id = (int) $this->id;
  2479. $this->params = (string) trim( $this->params . ' ' );
  2480. $ignoreList = array( 'link' );
  2481. $this->filter( $ignoreList );
  2482. return true;
  2483. }
  2484. }
  2485. /**
  2486. * Users Table Class
  2487. *
  2488. * Provides access to the jos_user table
  2489. * @package Joomla
  2490. */
  2491. class mosUser extends mosDBTable {
  2492. /** @var int Unique id*/
  2493. var $id = null;
  2494. /** @var string The users real name (or nickname)*/
  2495. var $name = null;
  2496. /** @var string The login name*/
  2497. var $username = null;
  2498. /** @var string email*/
  2499. var $email = null;
  2500. /** @var string MD5 encrypted password*/
  2501. var $password = null;
  2502. /** @var string */
  2503. var $usertype = null;
  2504. /** @var int */
  2505. var $block = null;
  2506. /** @var int */
  2507. var $sendEmail = null;
  2508. /** @var int The group id number */
  2509. var $gid = null;
  2510. /** @var datetime */
  2511. var $registerDate = null;
  2512. /** @var datetime */
  2513. var $lastvisitDate = null;
  2514. /** @var string activation hash*/
  2515. var $activation = null;
  2516. /** @var string */
  2517. var $params = null;
  2518. /**
  2519. * @param database A database connector object
  2520. */
  2521. function mosUser( &$database ) {
  2522. $this->mosDBTable( '#__users', 'id', $database );
  2523. }
  2524. /**
  2525. * Validation and filtering
  2526. * @return boolean True is satisfactory
  2527. */
  2528. function check() {
  2529. global $mosConfig_uniquemail;
  2530. // Validate user information
  2531. if (trim( $this->name ) == '') {
  2532. $this->_error = addslashes( _REGWARN_NAME );
  2533. return false;
  2534. }
  2535. if (trim( $this->username ) == '') {
  2536. $this->_error = addslashes( _REGWARN_UNAME );
  2537. return false;
  2538. }
  2539. // check that username is not greater than 25 characters
  2540. $username = $this->username;
  2541. if ( strlen($username) > 25 ) {
  2542. $this->username = substr( $username, 0, 25 );
  2543. }
  2544. // check that password is not greater than 50 characters
  2545. $password = $this->password;
  2546. if ( strlen($password) > 50 ) {
  2547. $this->password = substr( $password, 0, 50 );
  2548. }
  2549. if (eregi( "[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", $this->username) || strlen( $this->username ) < 3) {
  2550. $this->_error = sprintf( addslashes( _VALID_AZ09 ), addslashes( _PROMPT_UNAME ), 2 );
  2551. return false;
  2552. }
  2553. if ((trim($this->email == "")) || (preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $this->email )==false)) {
  2554. $this->_error = addslashes( _REGWARN_MAIL );
  2555. return false;
  2556. }
  2557. // check for existing username
  2558. $query = "SELECT id"
  2559. . "\n FROM #__users "
  2560. . "\n WHERE username = " . $this->_db->Quote( $this->username )
  2561. . "\n AND id != " . (int)$this->id
  2562. ;
  2563. $this->_db->setQuery( $query );
  2564. $xid = intval( $this->_db->loadResult() );
  2565. if ($xid && $xid != intval( $this->id )) {
  2566. $this->_error = addslashes( _REGWARN_INUSE );
  2567. return false;
  2568. }
  2569. if ($mosConfig_uniquemail) {
  2570. // check for existing email
  2571. $query = "SELECT id"
  2572. . "\n FROM #__users "
  2573. . "\n WHERE email = " . $this->_db->Quote( $this->email )
  2574. . "\n AND id != " . (int) $this->id
  2575. ;
  2576. $this->_db->setQuery( $query );
  2577. $xid = intval( $this->_db->loadResult() );
  2578. if ($xid && $xid != intval( $this->id )) {
  2579. $this->_error = addslashes( _REGWARN_EMAIL_INUSE );
  2580. return false;
  2581. }
  2582. }
  2583. return true;
  2584. }
  2585. function store( $updateNulls=false ) {
  2586. global $acl, $migrate;
  2587. $section_value = 'users';
  2588. $k = $this->_tbl_key;
  2589. $key = $this->$k;
  2590. if( $key && !$migrate) {
  2591. // existing record
  2592. $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls );
  2593. // syncronise ACL
  2594. // single group handled at the moment
  2595. // trivial to expand to multiple groups
  2596. $groups = $acl->get_object_groups( $section_value, $this->$k, 'ARO' );
  2597. if(isset($groups[0])) $acl->del_group_object( $groups[0], $section_value, $this->$k, 'ARO' );
  2598. $acl->add_group_object( $this->gid, $section_value, $this->$k, 'ARO' );
  2599. $object_id = $acl->get_object_id( $section_value, $this->$k, 'ARO' );
  2600. $acl->edit_object( $object_id, $section_value, $this->_db->getEscaped( $this->name ), $this->$k, 0, 0, 'ARO' );
  2601. } else {
  2602. // new record
  2603. $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key );
  2604. // syncronise ACL
  2605. $acl->add_object( $section_value, $this->_db->getEscaped( $this->name ), $this->$k, null, null, 'ARO' );
  2606. $acl->add_group_object( $this->gid, $section_value, $this->$k, 'ARO' );
  2607. }
  2608. if( !$ret ) {
  2609. $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->getErrorMsg();
  2610. return false;
  2611. } else {
  2612. return true;
  2613. }
  2614. }
  2615. function delete( $oid=null ) {
  2616. global $acl;
  2617. $k = $this->_tbl_key;
  2618. if ($oid) {
  2619. $this->$k = intval( $oid );
  2620. }
  2621. $aro_id = $acl->get_object_id( 'users', $this->$k, 'ARO' );
  2622. $acl->del_object( $aro_id, 'ARO', true );
  2623. $query = "DELETE FROM $this->_tbl"
  2624. . "\n WHERE $this->_tbl_key = " . (int) $this->$k
  2625. ;
  2626. $this->_db->setQuery( $query );
  2627. if ($this->_db->query()) {
  2628. // cleanup related data
  2629. // :: private messaging
  2630. $query = "DELETE FROM #__messages_cfg"
  2631. . "\n WHERE user_id = " . (int) $this->$k
  2632. ;
  2633. $this->_db->setQuery( $query );
  2634. if (!$this->_db->query()) {
  2635. $this->_error = $this->_db->getErrorMsg();
  2636. return false;
  2637. }
  2638. $query = "DELETE FROM #__messages"
  2639. . "\n WHERE user_id_to = " . (int) $this->$k
  2640. ;
  2641. $this->_db->setQuery( $query );
  2642. if (!$this->_db->query()) {
  2643. $this->_error = $this->_db->getErrorMsg();
  2644. return false;
  2645. }
  2646. return true;
  2647. } else {
  2648. $this->_error = $this->_db->getErrorMsg();
  2649. return false;
  2650. }
  2651. }
  2652. /**
  2653. * Gets the users from a group
  2654. * @param string The value for the group (not used 1.0)
  2655. * @param string The name for the group
  2656. * @param string If RECURSE, will drill into child groups
  2657. * @param string Ordering for the list
  2658. * @return array
  2659. */
  2660. function getUserListFromGroup( $value, $name, $recurse='NO_RECURSE', $order='name' ) {
  2661. global $acl;
  2662. // Change back in
  2663. //$group_id = $acl->get_group_id( $value, $name, $group_type = 'ARO');
  2664. $group_id = $acl->get_group_id( $name, $group_type = 'ARO');
  2665. $objects = $acl->get_group_objects( $group_id, 'ARO', 'RECURSE');
  2666. if (isset( $objects['users'] )) {
  2667. mosArrayToInts( $objects['users'] );
  2668. $gWhere = '(id =' . implode( ' OR id =', $objects['users'] ) . ')';
  2669. $query = "SELECT id AS value, name AS text"
  2670. . "\n FROM #__users"
  2671. . "\n WHERE block = '0'"
  2672. . "\n AND " . $gWhere
  2673. . "\n ORDER BY ". $order
  2674. ;
  2675. $this->_db->setQuery( $query );
  2676. $options = $this->_db->loadObjectList();
  2677. return $options;
  2678. } else {
  2679. return array();
  2680. }
  2681. }
  2682. }
  2683. /**
  2684. * Template Table Class
  2685. *
  2686. * Provides access to the jos_templates table
  2687. * @package Joomla
  2688. */
  2689. class mosTemplate extends mosDBTable {
  2690. /** @var int */
  2691. var $id = null;
  2692. /** @var string */
  2693. var $cur_template = null;
  2694. /** @var int */
  2695. var $col_main = null;
  2696. /**
  2697. * @param database A database connector object
  2698. */
  2699. function mosTemplate( &$database ) {
  2700. $this->mosDBTable( '#__templates', 'id', $database );
  2701. }
  2702. }
  2703. /**
  2704. * Utility function to return a value from a named array or a specified default
  2705. * @param array A named array
  2706. * @param string The key to search for
  2707. * @param mixed The default value to give if no key found
  2708. * @param int An options mask: _MOS_NOTRIM prevents trim, _MOS_ALLOWHTML allows safe html, _MOS_ALLOWRAW allows raw input
  2709. */
  2710. define( "_MOS_NOTRIM", 0x0001 );
  2711. define( "_MOS_ALLOWHTML", 0x0002 );
  2712. define( "_MOS_ALLOWRAW", 0x0004 );
  2713. function mosGetParam( &$arr, $name, $def=null, $mask=0 ) {
  2714. static $noHtmlFilter = null;
  2715. static $safeHtmlFilter = null;
  2716. $return = null;
  2717. if (isset( $arr[$name] )) {
  2718. $return = $arr[$name];
  2719. if (is_string( $return )) {
  2720. // trim data
  2721. if (!($mask&_MOS_NOTRIM)) {
  2722. $return = trim( $return );
  2723. }
  2724. if ($mask&_MOS_ALLOWRAW) {
  2725. // do nothing
  2726. } else if ($mask&_MOS_ALLOWHTML) {
  2727. // do nothing - compatibility mode
  2728. } else {
  2729. // send to inputfilter
  2730. if (is_null( $noHtmlFilter )) {
  2731. $noHtmlFilter = new InputFilter( /* $tags, $attr, $tag_method, $attr_method, $xss_auto */ );
  2732. }
  2733. $return = $noHtmlFilter->process( $return );
  2734. if (empty($return) && is_numeric($def)) {
  2735. // if value is defined and default value is numeric set variable type to integer
  2736. $return = intval($return);
  2737. }
  2738. }
  2739. // account for magic quotes setting
  2740. if (!get_magic_quotes_gpc()) {
  2741. $return = addslashes( $return );
  2742. }
  2743. }
  2744. return $return;
  2745. } else {
  2746. return $def;
  2747. }
  2748. }
  2749. /**
  2750. * Strip slashes from strings or arrays of strings
  2751. * @param mixed The input string or array
  2752. * @return mixed String or array stripped of slashes
  2753. */
  2754. function mosStripslashes( &$value ) {
  2755. $ret = '';
  2756. if (is_string( $value )) {
  2757. $ret = stripslashes( $value );
  2758. } else {
  2759. if (is_array( $value )) {
  2760. $ret = array();
  2761. foreach ($value as $key => $val) {
  2762. $ret[$key] = mosStripslashes( $val );
  2763. }
  2764. } else {
  2765. $ret = $value;
  2766. }
  2767. }
  2768. return $ret;
  2769. }
  2770. /**
  2771. * Copy the named array content into the object as properties
  2772. * only existing properties of object are filled. when undefined in hash, properties wont be deleted
  2773. * @param array the input array
  2774. * @param obj byref the object to fill of any class
  2775. * @param string
  2776. * @param boolean
  2777. */
  2778. function mosBindArrayToObject( $array, &$obj, $ignore='', $prefix=NULL, $checkSlashes=true ) {
  2779. if (!is_array( $array ) || !is_object( $obj )) {
  2780. return (false);
  2781. }
  2782. $ignore = ' ' . $ignore . ' ';
  2783. foreach (get_object_vars($obj) as $k => $v) {
  2784. if( substr( $k, 0, 1 ) != '_' ) { // internal attributes of an object are ignored
  2785. if (strpos( $ignore, ' ' . $k . ' ') === false) {
  2786. if ($prefix) {
  2787. $ak = $prefix . $k;
  2788. } else {
  2789. $ak = $k;
  2790. }
  2791. if (isset($array[$ak])) {
  2792. $obj->$k = ($checkSlashes && get_magic_quotes_gpc()) ? mosStripslashes( $array[$ak] ) : $array[$ak];
  2793. }
  2794. }
  2795. }
  2796. }
  2797. return true;
  2798. }
  2799. /**
  2800. * Utility function to read the files in a directory
  2801. * @param string The file system path
  2802. * @param string A filter for the names
  2803. * @param boolean Recurse search into sub-directories
  2804. * @param boolean True if to prepend the full path to the file name
  2805. */
  2806. function mosReadDirectory( $path, $filter='.', $recurse=false, $fullpath=false ) {
  2807. $arr = array();
  2808. if (!@is_dir( $path )) {
  2809. return $arr;
  2810. }
  2811. $handle = opendir( $path );
  2812. while ($file = readdir($handle)) {
  2813. $dir = mosPathName( $path.'/'.$file, false );
  2814. $isDir = is_dir( $dir );
  2815. if (($file != ".") && ($file != "..")) {
  2816. if (preg_match( "/$filter/", $file )) {
  2817. if ($fullpath) {
  2818. $arr[] = trim( mosPathName( $path.'/'.$file, false ) );
  2819. } else {
  2820. $arr[] = trim( $file );
  2821. }
  2822. }
  2823. if ($recurse && $isDir) {
  2824. $arr2 = mosReadDirectory( $dir, $filter, $recurse, $fullpath );
  2825. $arr = array_merge( $arr, $arr2 );
  2826. }
  2827. }
  2828. }
  2829. closedir($handle);
  2830. asort($arr);
  2831. return $arr;
  2832. }
  2833. /**
  2834. * Utility function redirect the browser location to another url
  2835. *
  2836. * Can optionally provide a message.
  2837. * @param string The file system path
  2838. * @param string A filter for the names
  2839. */
  2840. function mosRedirect( $url, $msg='' ) {
  2841. global $mainframe;
  2842. // specific filters
  2843. $iFilter = new InputFilter();
  2844. $url = $iFilter->process( $url );
  2845. if (!empty($msg)) {
  2846. $msg = $iFilter->process( $msg );
  2847. }
  2848. // Strip out any line breaks and throw away the rest
  2849. $url = preg_split("/[\r\n]/", $url);
  2850. $url = $url[0];
  2851. if ($iFilter->badAttributeValue( array( 'href', $url ))) {
  2852. $url = $GLOBALS['mosConfig_live_site'];
  2853. }
  2854. if (trim( $msg )) {
  2855. if (strpos( $url, '?' )) {
  2856. $url .= '&mosmsg=' . urlencode( $msg );
  2857. } else {
  2858. $url .= '?mosmsg=' . urlencode( $msg );
  2859. }
  2860. }
  2861. if (headers_sent()) {
  2862. echo "<script>document.location.href='$url';</script>\n";
  2863. } else {
  2864. @ob_end_clean(); // clear output buffer
  2865. header( 'HTTP/1.1 301 Moved Permanently' );
  2866. header( "Location: ". $url );
  2867. }
  2868. exit();
  2869. }
  2870. function mosErrorAlert( $text, $action='window.history.go(-1);', $mode=1 ) {
  2871. $text = nl2br( $text );
  2872. $text = addslashes( $text );
  2873. $text = strip_tags( $text );
  2874. switch ( $mode ) {
  2875. case 2:
  2876. echo "<script>$action</script> \n";
  2877. break;
  2878. case 1:
  2879. default:
  2880. // ------------------------ A8E fixes ------------------------
  2881. //echo $text;
  2882. //echo '<noscript>';
  2883. mosRedirect( @$_SERVER['HTTP_REFERER'], $text );
  2884. //echo '</noscript>';
  2885. break;
  2886. }
  2887. exit;
  2888. }
  2889. function mosTreeRecurse( $id, $indent, $list, &$children, $maxlevel=9999, $level=0, $type=1 ) {
  2890. if (@$children[$id] && $level <= $maxlevel) {
  2891. foreach ($children[$id] as $v) {
  2892. $id = $v->id;
  2893. if ( $type ) {
  2894. $pre = '<sup>L</sup>&nbsp;';
  2895. $spacer = '.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  2896. } else {
  2897. $pre = '- ';
  2898. $spacer = '&nbsp;&nbsp;';
  2899. }
  2900. if ( $v->parent == 0 ) {
  2901. $txt = $v->name;
  2902. } else {
  2903. $txt = $pre . $v->name;
  2904. }
  2905. $pt = $v->parent;
  2906. $list[$id] = $v;
  2907. $list[$id]->treename = "$indent$txt";
  2908. $list[$id]->children = count( @$children[$id] );
  2909. $list = mosTreeRecurse( $id, $indent . $spacer, $list, $children, $maxlevel, $level+1, $type );
  2910. }
  2911. }
  2912. return $list;
  2913. }
  2914. /**
  2915. * Function to strip additional / or \ in a path name
  2916. * @param string The path
  2917. * @param boolean Add trailing slash
  2918. */
  2919. function mosPathName($p_path,$p_addtrailingslash = true) {
  2920. $retval = "";
  2921. $isWin = (substr(PHP_OS, 0, 3) == 'WIN');
  2922. if ($isWin) {
  2923. $retval = str_replace( '/', '\\', $p_path );
  2924. if ($p_addtrailingslash) {
  2925. if (substr( $retval, -1 ) != '\\') {
  2926. $retval .= '\\';
  2927. }
  2928. }
  2929. // Check if UNC path
  2930. $unc = substr($retval,0,2) == '\\\\' ? 1 : 0;
  2931. // Remove double \\
  2932. $retval = str_replace( '\\\\', '\\', $retval );
  2933. // If UNC path, we have to add one \ in front or everything breaks!
  2934. if ( $unc == 1 ) {
  2935. $retval = '\\'.$retval;
  2936. }
  2937. } else {
  2938. $retval = str_replace( '\\', '/', $p_path );
  2939. if ($p_addtrailingslash) {
  2940. if (substr( $retval, -1 ) != '/') {
  2941. $retval .= '/';
  2942. }
  2943. }
  2944. // Check if UNC path
  2945. $unc = substr($retval,0,2) == '//' ? 1 : 0;
  2946. // Remove double //
  2947. $retval = str_replace('//','/',$retval);
  2948. // If UNC path, we have to add one / in front or everything breaks!
  2949. if ( $unc == 1 ) {
  2950. $retval = '/'.$retval;
  2951. }
  2952. }
  2953. return $retval;
  2954. }
  2955. /**
  2956. * Class mosMambot
  2957. * @package Joomla
  2958. */
  2959. class mosMambot extends mosDBTable {
  2960. /** @var int */
  2961. var $id = null;
  2962. /** @var varchar */
  2963. var $name = null;
  2964. /** @var varchar */
  2965. var $element = null;
  2966. /** @var varchar */
  2967. var $folder = null;
  2968. /** @var tinyint unsigned */
  2969. var $access = null;
  2970. /** @var int */
  2971. var $ordering = null;
  2972. /** @var tinyint */
  2973. var $published = null;
  2974. /** @var tinyint */
  2975. var $iscore = null;
  2976. /** @var tinyint */
  2977. var $client_id = null;
  2978. /** @var int unsigned */
  2979. var $checked_out = null;
  2980. /** @var datetime */
  2981. var $checked_out_time = null;
  2982. /** @var text */
  2983. var $params = null;
  2984. function mosMambot( &$db ) {
  2985. $this->mosDBTable( '#__mambots', 'id', $db );
  2986. }
  2987. }
  2988. /**
  2989. * Module database table class
  2990. * @package Joomla
  2991. */
  2992. class mosModule extends mosDBTable {
  2993. /** @var int Primary key */
  2994. var $id = null;
  2995. /** @var string */
  2996. var $title = null;
  2997. /** @var string */
  2998. var $showtitle = null;
  2999. /** @var int */
  3000. var $content = null;
  3001. /** @var int */
  3002. var $ordering = null;
  3003. /** @var string */
  3004. var $position = null;
  3005. /** @var boolean */
  3006. var $checked_out = null;
  3007. /** @var time */
  3008. var $checked_out_time = null;
  3009. /** @var boolean */
  3010. var $published = null;
  3011. /** @var string */
  3012. var $module = null;
  3013. /** @var int */
  3014. var $numnews = null;
  3015. /** @var int */
  3016. var $access = null;
  3017. /** @var string */
  3018. var $params = null;
  3019. /** @var string */
  3020. var $iscore = null;
  3021. /** @var string */
  3022. var $client_id = null;
  3023. /**
  3024. * @param database A database connector object
  3025. */
  3026. function mosModule( &$db ) {
  3027. $this->mosDBTable( '#__modules', 'id', $db );
  3028. }
  3029. // overloaded check function
  3030. function check() {
  3031. // check for valid name
  3032. if (trim( $this->title ) == '') {
  3033. $this->_error = "Your Module must contain a title.";
  3034. return false;
  3035. }
  3036. return true;
  3037. }
  3038. }
  3039. /**
  3040. * Session database table class
  3041. * @package Joomla
  3042. */
  3043. class mosSession extends mosDBTable {
  3044. /** @var int Primary key */
  3045. var $session_id = null;
  3046. /** @var string */
  3047. var $time = null;
  3048. /** @var string */
  3049. var $userid = null;
  3050. /** @var string */
  3051. var $usertype = null;
  3052. /** @var string */
  3053. var $username = null;
  3054. /** @var time */
  3055. var $gid = null;
  3056. /** @var int */
  3057. var $guest = null;
  3058. /** @var string */
  3059. var $_session_cookie = null;
  3060. /**
  3061. * @param database A database connector object
  3062. */
  3063. function mosSession( &$db ) {
  3064. $this->mosDBTable( '#__session', 'session_id', $db );
  3065. }
  3066. /**
  3067. * @param string Key search for
  3068. * @param mixed Default value if not set
  3069. * @return mixed
  3070. */
  3071. function get( $key, $default=null ) {
  3072. return mosGetParam( $_SESSION, $key, $default );
  3073. }
  3074. /**
  3075. * @param string Key to set
  3076. * @param mixed Value to set
  3077. * @return mixed The new value
  3078. */
  3079. function set( $key, $value ) {
  3080. $_SESSION[$key] = $value;
  3081. return $value;
  3082. }
  3083. /**
  3084. * Sets a key from a REQUEST variable, otherwise uses the default
  3085. * @param string The variable key
  3086. * @param string The REQUEST variable name
  3087. * @param mixed The default value
  3088. * @return mixed
  3089. */
  3090. function setFromRequest( $key, $varName, $default=null ) {
  3091. if (isset( $_REQUEST[$varName] )) {
  3092. return mosSession::set( $key, $_REQUEST[$varName] );
  3093. } else if (isset( $_SESSION[$key] )) {
  3094. return $_SESSION[$key];
  3095. } else {
  3096. return mosSession::set( $key, $default );
  3097. }
  3098. }
  3099. /**
  3100. * Insert a new row
  3101. * @return boolean
  3102. */
  3103. function insert() {
  3104. $ret = $this->_db->insertObject( $this->_tbl, $this );
  3105. if( !$ret ) {
  3106. $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->stderr();
  3107. return false;
  3108. } else {
  3109. return true;
  3110. }
  3111. }
  3112. /**
  3113. * Update an existing row
  3114. * @return boolean
  3115. */
  3116. function update( $updateNulls=false ) {
  3117. $ret = $this->_db->updateObject( $this->_tbl, $this, 'session_id', $updateNulls );
  3118. if( !$ret ) {
  3119. $this->_error = strtolower(get_class( $this ))."::store failed <br />" . $this->_db->stderr();
  3120. return false;
  3121. } else {
  3122. return true;
  3123. }
  3124. }
  3125. /**
  3126. * Generate a unique session id
  3127. * @return string
  3128. */
  3129. function generateId() {
  3130. $failsafe = 20;
  3131. $randnum = 0;
  3132. while ($failsafe--) {
  3133. $randnum = md5( uniqid( microtime(), 1 ) );
  3134. $new_session_id = mosMainFrame::sessionCookieValue( $randnum );
  3135. if ($randnum != '') {
  3136. $query = "SELECT $this->_tbl_key"
  3137. . "\n FROM $this->_tbl"
  3138. . "\n WHERE $this->_tbl_key = " . $this->_db->Quote( $new_session_id )
  3139. ;
  3140. $this->_db->setQuery( $query );
  3141. if(!$result = $this->_db->query()) {
  3142. die( $this->_db->stderr( true ));
  3143. }
  3144. if ($this->_db->getNumRows($result) == 0) {
  3145. break;
  3146. }
  3147. }
  3148. }
  3149. $this->_session_cookie = $randnum;
  3150. $this->session_id = $new_session_id;
  3151. }
  3152. /**
  3153. * @return string The name of the session cookie
  3154. */
  3155. function getCookie() {
  3156. return $this->_session_cookie;
  3157. }
  3158. /**
  3159. * Purge lapsed sessions
  3160. * @return boolean
  3161. */
  3162. function purge( $inc=1800, $and='' ) {
  3163. global $mainframe;
  3164. if ($inc == 'core') {
  3165. $past_logged = time() - $mainframe->getCfg( 'lifetime' );
  3166. $past_guest = time() - 900;
  3167. $query = "DELETE FROM $this->_tbl"
  3168. . "\n WHERE ("
  3169. // purging expired logged sessions
  3170. . "\n ( time < '" . (int) $past_logged . "' )"
  3171. . "\n AND guest = 0"
  3172. . "\n AND gid > 0"
  3173. . "\n ) OR ("
  3174. // purging expired guest sessions
  3175. . "\n ( time < '" . (int) $past_guest . "' )"
  3176. . "\n AND guest = 1"
  3177. . "\n AND userid = 0"
  3178. . "\n )"
  3179. ;
  3180. } else {
  3181. // kept for backward compatability
  3182. $past = time() - $inc;
  3183. $query = "DELETE FROM $this->_tbl"
  3184. . "\n WHERE ( time < '" . (int) $past . "' )"
  3185. . $and
  3186. ;
  3187. }
  3188. $this->_db->setQuery($query);
  3189. return $this->_db->query();
  3190. }
  3191. }
  3192. function mosObjectToArray($p_obj) {
  3193. $retarray = null;
  3194. if(is_object($p_obj))
  3195. {
  3196. $retarray = array();
  3197. foreach (get_object_vars($p_obj) as $k => $v)
  3198. {
  3199. if(is_object($v))
  3200. $retarray[$k] = mosObjectToArray($v);
  3201. else
  3202. $retarray[$k] = $v;
  3203. }
  3204. }
  3205. return $retarray;
  3206. }
  3207. /**
  3208. * Checks the user agent string against known browsers
  3209. */
  3210. function mosGetBrowser( $agent ) {
  3211. global $mosConfig_absolute_path;
  3212. require( $mosConfig_absolute_path .'/includes/agent_browser.php' );
  3213. if (preg_match( "/msie[\/\sa-z]*([\d\.]*)/i", $agent, $m )
  3214. && !preg_match( "/webtv/i", $agent )
  3215. && !preg_match( "/omniweb/i", $agent )
  3216. && !preg_match( "/opera/i", $agent )) {
  3217. // IE
  3218. return "MS Internet Explorer $m[1]";
  3219. } else if (preg_match( "/netscape.?\/([\d\.]*)/i", $agent, $m )) {
  3220. // Netscape 6.x, 7.x ...
  3221. return "Netscape $m[1]";
  3222. } else if ( preg_match( "/mozilla[\/\sa-z]*([\d\.]*)/i", $agent, $m )
  3223. && !preg_match( "/gecko/i", $agent )
  3224. && !preg_match( "/compatible/i", $agent )
  3225. && !preg_match( "/opera/i", $agent )
  3226. && !preg_match( "/galeon/i", $agent )
  3227. && !preg_match( "/safari/i", $agent )) {
  3228. // Netscape 3.x, 4.x ...
  3229. return "Netscape $m[1]";
  3230. } else {
  3231. // Other
  3232. $found = false;
  3233. foreach ($browserSearchOrder as $key) {
  3234. if (preg_match( "/$key.?\/([\d\.]*)/i", $agent, $m )) {
  3235. $name = "$browsersAlias[$key] $m[1]";
  3236. return $name;
  3237. break;
  3238. }
  3239. }
  3240. }
  3241. return 'Unknown';
  3242. }
  3243. /**
  3244. * Checks the user agent string against known operating systems
  3245. */
  3246. function mosGetOS( $agent ) {
  3247. global $mosConfig_absolute_path;
  3248. require( $mosConfig_absolute_path .'/includes/agent_os.php' );
  3249. foreach ($osSearchOrder as $key) {
  3250. if (preg_match( "/$key/i", $agent )) {
  3251. return $osAlias[$key];
  3252. break;
  3253. }
  3254. }
  3255. return 'Unknown';
  3256. }
  3257. /**
  3258. * @param string SQL with ordering As value and 'name field' AS text
  3259. * @param integer The length of the truncated headline
  3260. */
  3261. function mosGetOrderingList( $sql, $chop='30' ) {
  3262. global $database;
  3263. $order = array();
  3264. $database->setQuery( $sql );
  3265. if (!($orders = $database->loadObjectList())) {
  3266. if ($database->getErrorNum()) {
  3267. echo $database->stderr();
  3268. return false;
  3269. } else {
  3270. $order[] = mosHTML::makeOption( 1, 'first' );
  3271. return $order;
  3272. }
  3273. }
  3274. $order[] = mosHTML::makeOption( 0, '0 first' );
  3275. for ($i=0, $n=count( $orders ); $i < $n; $i++) {
  3276. if (strlen($orders[$i]->text) > $chop) {
  3277. $text = substr($orders[$i]->text,0,$chop)."...";
  3278. } else {
  3279. $text = $orders[$i]->text;
  3280. }
  3281. $order[] = mosHTML::makeOption( $orders[$i]->value, $orders[$i]->value.' ('.$text.')' );
  3282. }
  3283. $order[] = mosHTML::makeOption( $orders[$i-1]->value+1, ($orders[$i-1]->value+1).' last' );
  3284. return $order;
  3285. }
  3286. /**
  3287. * Makes a variable safe to display in forms
  3288. *
  3289. * Object parameters that are non-string, array, object or start with underscore
  3290. * will be converted
  3291. * @param object An object to be parsed
  3292. * @param int The optional quote style for the htmlspecialchars function
  3293. * @param string|array An optional single field name or array of field names not
  3294. * to be parsed (eg, for a textarea)
  3295. */
  3296. function mosMakeHtmlSafe( &$mixed, $quote_style=ENT_QUOTES, $exclude_keys='' ) {
  3297. if (is_object( $mixed )) {
  3298. foreach (get_object_vars( $mixed ) as $k => $v) {
  3299. if (is_array( $v ) || is_object( $v ) || $v == NULL || substr( $k, 1, 1 ) == '_' ) {
  3300. continue;
  3301. }
  3302. if (is_string( $exclude_keys ) && $k == $exclude_keys) {
  3303. continue;
  3304. } else if (is_array( $exclude_keys ) && in_array( $k, $exclude_keys )) {
  3305. continue;
  3306. }
  3307. $mixed->$k = htmlspecialchars( $v, $quote_style );
  3308. }
  3309. }
  3310. }
  3311. /**
  3312. * Checks whether a menu option is within the users access level
  3313. * @param int Item id number
  3314. * @param string The menu option
  3315. * @param int The users group ID number
  3316. * @param database A database connector object
  3317. * @return boolean True if the visitor's group at least equal to the menu access
  3318. */
  3319. function mosMenuCheck( $Itemid, $menu_option, $task, $gid ) {
  3320. global $database, $mainframe;
  3321. if ( $Itemid != '' && $Itemid != 0 && $Itemid != 99999999 ) {
  3322. $query = "SELECT *"
  3323. . "\n FROM #__menu"
  3324. . "\n WHERE id = " . (int) $Itemid
  3325. ;
  3326. } else {
  3327. $dblink = "index.php?option=" . $database->getEscaped( $menu_option, true );
  3328. if ($task != '') {
  3329. $dblink .= "&task=" . $database->getEscaped( $task, true );
  3330. }
  3331. $query = "SELECT *"
  3332. . "\n FROM #__menu"
  3333. . "\n WHERE published = 1 AND"
  3334. . "\n link LIKE '$dblink%'"
  3335. ;
  3336. }
  3337. $database->setQuery( $query );
  3338. $results = $database->loadObjectList();
  3339. $access = 0;
  3340. foreach ($results as $result) {
  3341. $access = max( $access, $result->access );
  3342. }
  3343. // save menu information to global mainframe
  3344. if(isset($results[0])) {
  3345. // loads menu info of particular Itemid
  3346. $mainframe->set( 'menu', $results[0] );
  3347. } else {
  3348. // loads empty Menu info
  3349. $mainframe->set( 'menu', new mosMenu($database) );
  3350. }
  3351. return ($access <= $gid);
  3352. }
  3353. /**
  3354. * Returns formated date according to current local and adds time offset
  3355. * @param string date in datetime format
  3356. * @param string format optional format for strftime
  3357. * @param offset time offset if different than global one
  3358. * @returns formated date
  3359. */
  3360. function mosFormatDate( $date, $format="", $offset=NULL ){
  3361. global $mosConfig_offset;
  3362. if ( $format == '' ) {
  3363. // %Y-%m-%d %H:%M:%S
  3364. $format = _DATE_FORMAT_LC;
  3365. }
  3366. if ( is_null($offset) ) {
  3367. $offset = $mosConfig_offset;
  3368. }
  3369. if ( $date && ereg( "([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $date, $regs ) ) {
  3370. $date = mktime( $regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] );
  3371. $date = $date > -1 ? strftime( $format, $date + ($offset*60*60) ) : '-';
  3372. }
  3373. return $date;
  3374. }
  3375. /**
  3376. * Returns current date according to current local and time offset
  3377. * @param string format optional format for strftime
  3378. * @returns current date
  3379. */
  3380. function mosCurrentDate( $format="" ) {
  3381. global $mosConfig_offset;
  3382. if ($format=="") {
  3383. $format = _DATE_FORMAT_LC;
  3384. }
  3385. $date = strftime( $format, time() + ($mosConfig_offset*60*60) );
  3386. return $date;
  3387. }
  3388. /**
  3389. * Utility function to provide ToolTips
  3390. * @param string ToolTip text
  3391. * @param string Box title
  3392. * @returns HTML code for ToolTip
  3393. */
  3394. function mosToolTip( $tooltip, $title='', $width='', $image='tooltip.png', $text='', $href='#', $link=1 ) {
  3395. global $mosConfig_live_site;
  3396. if ( $width ) {
  3397. $width = ', WIDTH, \''.$width .'\'';
  3398. }
  3399. if ( $title ) {
  3400. $title = ', CAPTION, \''.$title .'\'';
  3401. }
  3402. if ( !$text ) {
  3403. $image = $mosConfig_live_site . '/includes/js/ThemeOffice/'. $image;
  3404. $text = '<img src="'. $image .'" border="0" alt="tooltip"/>';
  3405. }
  3406. $style = 'style="text-decoration: none; color: #333;"';
  3407. if ( $href ) {
  3408. $style = '';
  3409. } else{
  3410. $href = '#';
  3411. }
  3412. $mousover = 'return overlib(\''. $tooltip .'\''. $title .', BELOW, RIGHT'. $width .');';
  3413. $tip = "<!-- Tooltip -->\n";
  3414. if ( $link ) {
  3415. $tip .= '<a href="'. $href .'" onmouseover="'. $mousover .'" onmouseout="return nd();" '. $style .'>'. $text .'</a>';
  3416. } else {
  3417. $tip .= '<span onmouseover="'. $mousover .'" onmouseout="return nd();" '. $style .'>'. $text .'</span>';
  3418. }
  3419. return $tip;
  3420. }
  3421. /**
  3422. * Utility function to provide Warning Icons
  3423. * @param string Warning text
  3424. * @param string Box title
  3425. * @returns HTML code for Warning
  3426. */
  3427. function mosWarning($warning, $title='Joomla! Warning') {
  3428. global $mosConfig_live_site;
  3429. $mouseover = 'return overlib(\''. $warning .'\', CAPTION, \''. $title .'\', BELOW, RIGHT);';
  3430. $tip = "<!-- Warning -->\n";
  3431. $tip .= '<a href="javascript:void(0)" onmouseover="'. $mouseover .'" onmouseout="return nd();">';
  3432. $tip .= '<img src="'. $mosConfig_live_site .'/includes/js/ThemeOffice/warning.png" border="0" alt="warning"/></a>';
  3433. return $tip;
  3434. }
  3435. function mosCreateGUID(){
  3436. srand((double)microtime()*1000000);
  3437. $r = rand();
  3438. $u = uniqid(getmypid() . $r . (double)microtime()*1000000,1);
  3439. $m = md5 ($u);
  3440. return($m);
  3441. }
  3442. function mosCompressID( $ID ){
  3443. return(Base64_encode(pack("H*",$ID)));
  3444. }
  3445. function mosExpandID( $ID ) {
  3446. return ( implode(unpack("H*",Base64_decode($ID)), '') );
  3447. }
  3448. /**
  3449. * Function to create a mail object for futher use (uses phpMailer)
  3450. * @param string From e-mail address
  3451. * @param string From name
  3452. * @param string E-mail subject
  3453. * @param string Message body
  3454. * @return object Mail object
  3455. */
  3456. function mosCreateMail( $from='', $fromname='', $subject, $body ) {
  3457. global $mosConfig_absolute_path, $mosConfig_sendmail;
  3458. global $mosConfig_smtpauth, $mosConfig_smtpuser;
  3459. global $mosConfig_smtppass, $mosConfig_smtphost;
  3460. global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_mailer;
  3461. $mail = new mosPHPMailer();
  3462. $mail->PluginDir = $mosConfig_absolute_path .'/includes/phpmailer/';
  3463. $mail->SetLanguage( 'en', $mosConfig_absolute_path . '/includes/phpmailer/language/' );
  3464. $mail->CharSet = substr_replace(_ISO, '', 0, 8);
  3465. $mail->IsMail();
  3466. $mail->From = $from ? $from : $mosConfig_mailfrom;
  3467. $mail->FromName = $fromname ? $fromname : $mosConfig_fromname;
  3468. $mail->Mailer = $mosConfig_mailer;
  3469. // Add smtp values if needed
  3470. if ( $mosConfig_mailer == 'smtp' ) {
  3471. $mail->SMTPAuth = $mosConfig_smtpauth;
  3472. $mail->Username = $mosConfig_smtpuser;
  3473. $mail->Password = $mosConfig_smtppass;
  3474. $mail->Host = $mosConfig_smtphost;
  3475. } else
  3476. // Set sendmail path
  3477. if ( $mosConfig_mailer == 'sendmail' ) {
  3478. if (isset($mosConfig_sendmail))
  3479. $mail->Sendmail = $mosConfig_sendmail;
  3480. } // if
  3481. $mail->Subject = $subject;
  3482. $mail->Body = $body;
  3483. return $mail;
  3484. }
  3485. /**
  3486. * Mail function (uses phpMailer)
  3487. * @param string From e-mail address
  3488. * @param string From name
  3489. * @param string/array Recipient e-mail address(es)
  3490. * @param string E-mail subject
  3491. * @param string Message body
  3492. * @param boolean false = plain text, true = HTML
  3493. * @param string/array CC e-mail address(es)
  3494. * @param string/array BCC e-mail address(es)
  3495. * @param string/array Attachment file name(s)
  3496. * @param string/array ReplyTo e-mail address(es)
  3497. * @param string/array ReplyTo name(s)
  3498. * @return boolean
  3499. */
  3500. function mosMail( $from, $fromname, $recipient, $subject, $body, $mode=0, $cc=NULL, $bcc=NULL, $attachment=NULL, $replyto=NULL, $replytoname=NULL ) {
  3501. global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_debug;
  3502. // Allow empty $from and $fromname settings (backwards compatibility)
  3503. if ($from == '') {
  3504. $from = $mosConfig_mailfrom;
  3505. }
  3506. if ($fromname == '') {
  3507. $fromname = $mosConfig_fromname;
  3508. }
  3509. // Filter from, fromname and subject
  3510. if (!JosIsValidEmail( $from ) || !JosIsValidName( $fromname ) || !JosIsValidName( $subject )) {
  3511. return false;
  3512. }
  3513. $mail = mosCreateMail( $from, $fromname, $subject, $body );
  3514. // activate HTML formatted emails
  3515. if ( $mode ) {
  3516. $mail->IsHTML(true);
  3517. }
  3518. if (is_array( $recipient )) {
  3519. foreach ($recipient as $to) {
  3520. if (!JosIsValidEmail( $to )) {
  3521. return false;
  3522. }
  3523. $mail->AddAddress( $to );
  3524. }
  3525. } else {
  3526. if (!JosIsValidEmail( $recipient )) {
  3527. return false;
  3528. }
  3529. $mail->AddAddress( $recipient );
  3530. }
  3531. if (isset( $cc )) {
  3532. if (is_array( $cc )) {
  3533. foreach ($cc as $to) {
  3534. if (!JosIsValidEmail( $to )) {
  3535. return false;
  3536. }
  3537. $mail->AddCC($to);
  3538. }
  3539. } else {
  3540. if (!JosIsValidEmail( $cc )) {
  3541. return false;
  3542. }
  3543. $mail->AddCC($cc);
  3544. }
  3545. }
  3546. if (isset( $bcc )) {
  3547. if (is_array( $bcc )) {
  3548. foreach ($bcc as $to) {
  3549. if (!JosIsValidEmail( $to )) {
  3550. return false;
  3551. }
  3552. $mail->AddBCC( $to );
  3553. }
  3554. } else {
  3555. if (!JosIsValidEmail( $bcc )) {
  3556. return false;
  3557. }
  3558. $mail->AddBCC( $bcc );
  3559. }
  3560. }
  3561. if ($attachment) {
  3562. if (is_array( $attachment )) {
  3563. foreach ($attachment as $fname) {
  3564. $mail->AddAttachment( $fname );
  3565. }
  3566. } else {
  3567. $mail->AddAttachment($attachment);
  3568. }
  3569. }
  3570. //Important for being able to use mosMail without spoofing...
  3571. if ($replyto) {
  3572. if (is_array( $replyto )) {
  3573. reset( $replytoname );
  3574. foreach ($replyto as $to) {
  3575. $toname = ((list( $key, $value ) = each( $replytoname )) ? $value : '');
  3576. if (!JosIsValidEmail( $to ) || !JosIsValidName( $toname )) {
  3577. return false;
  3578. }
  3579. $mail->AddReplyTo( $to, $toname );
  3580. }
  3581. } else {
  3582. if (!JosIsValidEmail( $replyto ) || !JosIsValidName( $replytoname )) {
  3583. return false;
  3584. }
  3585. $mail->AddReplyTo($replyto, $replytoname);
  3586. }
  3587. }
  3588. $mailssend = $mail->Send();
  3589. if( $mosConfig_debug ) {
  3590. //$mosDebug->message( "Mails send: $mailssend");
  3591. }
  3592. if( $mail->error_count > 0 ) {
  3593. //$mosDebug->message( "The mail message $fromname <$from> about $subject to $recipient <b>failed</b><br /><pre>$body</pre>", false );
  3594. //$mosDebug->message( "Mailer Error: " . $mail->ErrorInfo . "" );
  3595. }
  3596. return $mailssend;
  3597. } // mosMail
  3598. /**
  3599. * Checks if a given string is a valid email address
  3600. *
  3601. * @param string $email String to check for a valid email address
  3602. * @return boolean
  3603. */
  3604. function JosIsValidEmail( $email ) {
  3605. $valid = preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $email );
  3606. return $valid;
  3607. }
  3608. /**
  3609. * Checks if a given string is a valid (from-)name or subject for an email
  3610. *
  3611. * @since 1.0.11
  3612. * @deprecated 1.5
  3613. * @param string $string String to check for validity
  3614. * @return boolean
  3615. */
  3616. function JosIsValidName( $string ) {
  3617. /*
  3618. * The following regular expression blocks all strings containing any low control characters:
  3619. * 0x00-0x1F, 0x7F
  3620. * These should be control characters in almost all used charsets.
  3621. * The high control chars in ISO-8859-n (0x80-0x9F) are unused (e.g. http://en.wikipedia.org/wiki/ISO_8859-1)
  3622. * Since they are valid UTF-8 bytes (e.g. used as the second byte of a two byte char),
  3623. * they must not be filtered.
  3624. */
  3625. $invalid = preg_match( '/[\x00-\x1F\x7F]/', $string );
  3626. if ($invalid) {
  3627. return false;
  3628. } else {
  3629. return true;
  3630. }
  3631. }
  3632. /**
  3633. * Initialise GZIP
  3634. */
  3635. function initGzip() {
  3636. global $mosConfig_gzip, $do_gzip_compress;
  3637. $do_gzip_compress = FALSE;
  3638. if ($mosConfig_gzip == 1) {
  3639. $phpver = phpversion();
  3640. $useragent = mosGetParam( $_SERVER, 'HTTP_USER_AGENT', '' );
  3641. $canZip = mosGetParam( $_SERVER, 'HTTP_ACCEPT_ENCODING', '' );
  3642. $gzip_check = 0;
  3643. $zlib_check = 0;
  3644. $gz_check = 0;
  3645. $zlibO_check = 0;
  3646. $sid_check = 0;
  3647. if ( strpos( $canZip, 'gzip' ) !== false) {
  3648. $gzip_check = 1;
  3649. }
  3650. if ( extension_loaded( 'zlib' ) ) {
  3651. $zlib_check = 1;
  3652. }
  3653. if ( function_exists('ob_gzhandler') ) {
  3654. $gz_check = 1;
  3655. }
  3656. if ( ini_get('zlib.output_compression') ) {
  3657. $zlibO_check = 1;
  3658. }
  3659. if ( ini_get('session.use_trans_sid') ) {
  3660. $sid_check = 1;
  3661. }
  3662. if ( $phpver >= '4.0.4pl1' && ( strpos($useragent,'compatible') !== false || strpos($useragent,'Gecko') !== false ) ) {
  3663. // Check for gzip header or northon internet securities or session.use_trans_sid
  3664. if ( ( $gzip_check || isset( $_SERVER['---------------']) ) && $zlib_check && $gz_check && !$zlibO_check && !$sid_check ) {
  3665. // You cannot specify additional output handlers if
  3666. // zlib.output_compression is activated here
  3667. ob_start( 'ob_gzhandler' );
  3668. return;
  3669. }
  3670. } else if ( $phpver > '4.0' ) {
  3671. if ( $gzip_check ) {
  3672. if ( $zlib_check ) {
  3673. $do_gzip_compress = TRUE;
  3674. ob_start();
  3675. ob_implicit_flush(0);
  3676. header( 'Content-Encoding: gzip' );
  3677. return;
  3678. }
  3679. }
  3680. }
  3681. }
  3682. ob_start();
  3683. }
  3684. /**
  3685. * Perform GZIP
  3686. */
  3687. function doGzip() {
  3688. global $do_gzip_compress;
  3689. if ( $do_gzip_compress ) {
  3690. /**
  3691. *Borrowed from php.net!
  3692. */
  3693. $gzip_contents = ob_get_contents();
  3694. ob_end_clean();
  3695. $gzip_size = strlen($gzip_contents);
  3696. $gzip_crc = crc32($gzip_contents);
  3697. $gzip_contents = gzcompress($gzip_contents, 9);
  3698. $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
  3699. echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
  3700. echo $gzip_contents;
  3701. echo pack('V', $gzip_crc);
  3702. echo pack('V', $gzip_size);
  3703. } else {
  3704. ob_end_flush();
  3705. }
  3706. }
  3707. /**
  3708. * Random password generator
  3709. * @return password
  3710. */
  3711. function mosMakePassword($length=8) {
  3712. $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  3713. $makepass = '';
  3714. mt_srand(10000000*(double)microtime());
  3715. for ($i = 0; $i < $length; $i++)
  3716. $makepass .= $salt[mt_rand(0,61)];
  3717. return $makepass;
  3718. }
  3719. if (!function_exists('html_entity_decode')) {
  3720. /**
  3721. * html_entity_decode function for backward compatability in PHP
  3722. * @param string
  3723. * @param string
  3724. */
  3725. function html_entity_decode ($string, $opt = ENT_COMPAT) {
  3726. $trans_tbl = get_html_translation_table (HTML_ENTITIES);
  3727. $trans_tbl = array_flip ($trans_tbl);
  3728. if ($opt & 1) { // Translating single quotes
  3729. // Add single quote to translation table;
  3730. // doesn't appear to be there by default
  3731. $trans_tbl["&apos;"] = "'";
  3732. }
  3733. if (!($opt & 2)) { // Not translating double quotes
  3734. // Remove double quote from translation table
  3735. unset($trans_tbl["&quot;"]);
  3736. }
  3737. return strtr ($string, $trans_tbl);
  3738. }
  3739. }
  3740. /**
  3741. * Plugin handler
  3742. * @package Joomla
  3743. */
  3744. class mosMambotHandler {
  3745. /** @var array An array of functions in event groups */
  3746. var $_events = null;
  3747. /** @var array An array of lists */
  3748. var $_lists = null;
  3749. /** @var array An array of mambots */
  3750. var $_bots = null;
  3751. /** @var int Index of the mambot being loaded */
  3752. var $_loading = null;
  3753. /** Added as of 1.0.8 to ensure queries are only called once **/
  3754. /** @var array An array of the content mambots in the system */
  3755. var $_content_mambots = null;
  3756. /** @var array An array of the content mambot params */
  3757. var $_content_mambot_params = array();
  3758. /** @var array An array of the content mambot params */
  3759. var $_search_mambot_params = array();
  3760. /**
  3761. * Constructor
  3762. */
  3763. function mosMambotHandler() {
  3764. $this->_events = array();
  3765. }
  3766. /**
  3767. * Loads all the bot files for a particular group
  3768. * @param string The group name, relates to the sub-directory in the mambots directory
  3769. */
  3770. function loadBotGroup( $group ) {
  3771. global $database, $my;
  3772. $group = trim( $group );
  3773. if (is_object( $my )) {
  3774. $gid = $my->gid;
  3775. } else {
  3776. $gid = 0;
  3777. }
  3778. $group = trim( $group );
  3779. switch ( $group ) {
  3780. case 'content':
  3781. if (!defined( '_JOS_CONTENT_MAMBOTS' )) {
  3782. /** ensure that query is only called once */
  3783. define( '_JOS_CONTENT_MAMBOTS', 1 );
  3784. $query = "SELECT folder, element, published, params"
  3785. . "\n FROM #__mambots"
  3786. . "\n WHERE access <= " . (int) $gid
  3787. . "\n AND folder = 'content'"
  3788. . "\n ORDER BY ordering"
  3789. ;
  3790. $database->setQuery( $query );
  3791. // load query into class variable _content_mambots
  3792. if (!($this->_content_mambots = $database->loadObjectList())) {
  3793. //echo "Error loading Mambots: " . $database->getErrorMsg();
  3794. return false;
  3795. }
  3796. }
  3797. // pull bots to be processed from class variable
  3798. $bots = $this->_content_mambots;
  3799. break;
  3800. default:
  3801. $query = "SELECT folder, element, published, params"
  3802. . "\n FROM #__mambots"
  3803. . "\n WHERE published >= 1"
  3804. . "\n AND access <= " . (int) $gid
  3805. . "\n AND folder = " . $database->Quote( $group )
  3806. . "\n ORDER BY ordering"
  3807. ;
  3808. $database->setQuery( $query );
  3809. if (!($bots = $database->loadObjectList())) {
  3810. //echo "Error loading Mambots: " . $database->getErrorMsg();
  3811. return false;
  3812. }
  3813. break;
  3814. }
  3815. // load bots found by queries
  3816. $n = count( $bots);
  3817. for ($i = 0; $i < $n; $i++) {
  3818. $this->loadBot( $bots[$i]->folder, $bots[$i]->element, $bots[$i]->published, $bots[$i]->params );
  3819. }
  3820. return true;
  3821. }
  3822. /**
  3823. * Loads the bot file
  3824. * @param string The folder (group)
  3825. * @param string The elements (name of file without extension)
  3826. * @param int Published state
  3827. * @param string The params for the bot
  3828. */
  3829. function loadBot( $folder, $element, $published, $params='' ) {
  3830. global $mosConfig_absolute_path;
  3831. global $_MAMBOTS;
  3832. $path = $mosConfig_absolute_path . '/mambots/' . $folder . '/' . $element . '.php';
  3833. if (file_exists( $path )) {
  3834. $this->_loading = count( $this->_bots );
  3835. $bot = new stdClass;
  3836. $bot->folder = $folder;
  3837. $bot->element = $element;
  3838. $bot->published = $published;
  3839. $bot->lookup = $folder . '/' . $element;
  3840. $bot->params = $params;
  3841. $this->_bots[] = $bot;
  3842. require_once( $path );
  3843. $this->_loading = null;
  3844. }
  3845. }
  3846. /**
  3847. * Registers a function to a particular event group
  3848. * @param string The event name
  3849. * @param string The function name
  3850. */
  3851. function registerFunction( $event, $function ) {
  3852. $this->_events[$event][] = array( $function, $this->_loading );
  3853. }
  3854. /**
  3855. * Makes a option for a particular list in a group
  3856. * @param string The group name
  3857. * @param string The list name
  3858. * @param string The value for the list option
  3859. * @param string The text for the list option
  3860. */
  3861. function addListOption( $group, $listName, $value, $text='' ) {
  3862. $this->_lists[$group][$listName][] = mosHTML::makeOption( $value, $text );
  3863. }
  3864. /**
  3865. * @param string The group name
  3866. * @param string The list name
  3867. * @return array
  3868. */
  3869. function getList( $group, $listName ) {
  3870. return $this->_lists[$group][$listName];
  3871. }
  3872. /**
  3873. * Calls all functions associated with an event group
  3874. * @param string The event name
  3875. * @param array An array of arguments
  3876. * @param boolean True is unpublished bots are to be processed
  3877. * @return array An array of results from each function call
  3878. */
  3879. function trigger( $event, $args=null, $doUnpublished=false ) {
  3880. $result = array();
  3881. if ($args === null) {
  3882. $args = array();
  3883. }
  3884. if ($doUnpublished) {
  3885. // prepend the published argument
  3886. array_unshift( $args, null );
  3887. }
  3888. if (isset( $this->_events[$event] )) {
  3889. foreach ($this->_events[$event] as $func) {
  3890. if (function_exists( $func[0] )) {
  3891. if ($doUnpublished) {
  3892. $args[0] = $this->_bots[$func[1]]->published;
  3893. $result[] = call_user_func_array( $func[0], $args );
  3894. } else if ($this->_bots[$func[1]]->published) {
  3895. $result[] = call_user_func_array( $func[0], $args );
  3896. }
  3897. }
  3898. }
  3899. }
  3900. return $result;
  3901. }
  3902. /**
  3903. * Same as trigger but only returns the first event and
  3904. * allows for a variable argument list
  3905. * @param string The event name
  3906. * @return array The result of the first function call
  3907. */
  3908. function call( $event ) {
  3909. $doUnpublished=false;
  3910. $args =& func_get_args();
  3911. array_shift( $args );
  3912. if (isset( $this->_events[$event] )) {
  3913. foreach ($this->_events[$event] as $func) {
  3914. if (function_exists( $func[0] )) {
  3915. if ($this->_bots[$func[1]]->published) {
  3916. return call_user_func_array( $func[0], $args );
  3917. }
  3918. }
  3919. }
  3920. }
  3921. return null;
  3922. }
  3923. }
  3924. /**
  3925. * Tab Creation handler
  3926. * @package Joomla
  3927. */
  3928. class mosTabs {
  3929. /** @var int Use cookies */
  3930. var $useCookies = 0;
  3931. /**
  3932. * Constructor
  3933. * Includes files needed for displaying tabs and sets cookie options
  3934. * @param int useCookies, if set to 1 cookie will hold last used tab between page refreshes
  3935. */
  3936. function mosTabs( $useCookies, $xhtml=NULL ) {
  3937. global $mosConfig_live_site, $mainframe;
  3938. if ( $xhtml ) {
  3939. $mainframe->addCustomHeadTag( '<link rel="stylesheet" type="text/css" media="all" href="'.$mosConfig_live_site.'/includes/js/tabs/tabpane.css" id="luna-tab-style-sheet" />' );
  3940. } else {
  3941. echo "<link id=\"luna-tab-style-sheet\" type=\"text/css\" rel=\"stylesheet\" href=\"" . $mosConfig_live_site. "/includes/js/tabs/tabpane.css\" />";
  3942. }
  3943. echo "<script type=\"text/javascript\" src=\"". $mosConfig_live_site . "/includes/js/tabs/tabpane_mini.js\"></script>";
  3944. $this->useCookies = $useCookies;
  3945. }
  3946. /**
  3947. * creates a tab pane and creates JS obj
  3948. * @param string The Tab Pane Name
  3949. */
  3950. function startPane($id){
  3951. echo "<div class=\"tab-page\" id=\"".$id."\">";
  3952. echo "<script type=\"text/javascript\">\n";
  3953. echo " var tabPane1 = new WebFXTabPane( document.getElementById( \"".$id."\" ), ".$this->useCookies." )\n";
  3954. echo "</script>\n";
  3955. }
  3956. /**
  3957. * Ends Tab Pane
  3958. */
  3959. function endPane() {
  3960. echo "</div>";
  3961. }
  3962. /*
  3963. * Creates a tab with title text and starts that tabs page
  3964. * @param tabText - This is what is displayed on the tab
  3965. * @param paneid - This is the parent pane to build this tab on
  3966. */
  3967. function startTab( $tabText, $paneid ) {
  3968. echo "<div class=\"tab-page\" id=\"".$paneid."\">";
  3969. echo "<h2 class=\"tab\">".$tabText."</h2>";
  3970. echo "<script type=\"text/javascript\">\n";
  3971. echo " tabPane1.addTabPage( document.getElementById( \"".$paneid."\" ) );";
  3972. echo "</script>";
  3973. }
  3974. /*
  3975. * Ends a tab page
  3976. */
  3977. function endTab() {
  3978. echo "</div>";
  3979. }
  3980. }
  3981. /**
  3982. * Common HTML Output Files
  3983. * @package Joomla
  3984. */
  3985. class mosAdminMenus {
  3986. /**
  3987. * build the select list for Menu Ordering
  3988. */
  3989. function Ordering( &$row, $id ) {
  3990. global $database;
  3991. if ( $id ) {
  3992. $query = "SELECT ordering AS value, name AS text"
  3993. . "\n FROM #__menu"
  3994. . "\n WHERE menutype = " . $database->Quote ( $row->menutype )
  3995. . "\n AND parent = " . (int) $row->parent
  3996. . "\n AND published != -2"
  3997. . "\n ORDER BY ordering"
  3998. ;
  3999. $order = mosGetOrderingList( $query );
  4000. $ordering = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) );
  4001. } else {
  4002. $ordering = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />'. _CMN_NEW_ITEM_LAST;
  4003. }
  4004. return $ordering;
  4005. }
  4006. /**
  4007. * build the select list for access level
  4008. */
  4009. function Access( &$row ) {
  4010. global $database;
  4011. $query = "SELECT id AS value, name AS text"
  4012. . "\n FROM #__groups"
  4013. . "\n ORDER BY id"
  4014. ;
  4015. $database->setQuery( $query );
  4016. $groups = $database->loadObjectList();
  4017. $access = mosHTML::selectList( $groups, 'access', 'class="inputbox" size="3"', 'value', 'text', intval( $row->access ) );
  4018. return $access;
  4019. }
  4020. /**
  4021. * build the select list for parent item
  4022. */
  4023. function Parent( &$row ) {
  4024. global $database;
  4025. $id = '';
  4026. if ( $row->id ) {
  4027. $id = "\n AND id != " . (int) $row->id;
  4028. }
  4029. // get a list of the menu items
  4030. // excluding the current menu item and its child elements
  4031. $query = "SELECT m.*"
  4032. . "\n FROM #__menu m"
  4033. . "\n WHERE menutype = " . $database->Quote( $row->menutype )
  4034. . "\n AND published != -2"
  4035. . $id
  4036. . "\n ORDER BY parent, ordering"
  4037. ;
  4038. $database->setQuery( $query );
  4039. $mitems = $database->loadObjectList();
  4040. // establish the hierarchy of the menu
  4041. $children = array();
  4042. if ( $mitems ) {
  4043. // first pass - collect children
  4044. foreach ( $mitems as $v ) {
  4045. $pt = $v->parent;
  4046. $list = @$children[$pt] ? $children[$pt] : array();
  4047. array_push( $list, $v );
  4048. $children[$pt] = $list;
  4049. }
  4050. }
  4051. // second pass - get an indent list of the items
  4052. $list = mosTreeRecurse( 0, '', array(), $children, 20, 0, 0 );
  4053. // assemble menu items to the array
  4054. $mitems = array();
  4055. $mitems[] = mosHTML::makeOption( '0', 'Top' );
  4056. foreach ( $list as $item ) {
  4057. $mitems[] = mosHTML::makeOption( $item->id, '&nbsp;&nbsp;&nbsp;'. $item->treename );
  4058. }
  4059. $output = mosHTML::selectList( $mitems, 'parent', 'class="inputbox" size="10"', 'value', 'text', $row->parent );
  4060. return $output;
  4061. }
  4062. /**
  4063. * build a radio button option for published state
  4064. */
  4065. function Published( &$row ) {
  4066. $published = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published );
  4067. return $published;
  4068. }
  4069. /**
  4070. * build the link/url of a menu item
  4071. */
  4072. function Link( &$row, $id, $link=NULL ) {
  4073. global $mainframe;
  4074. if ( $id ) {
  4075. switch ($row->type) {
  4076. case 'content_item_link':
  4077. case 'content_typed':
  4078. // load menu params
  4079. $params = new mosParameters( $row->params, $mainframe->getPath( 'menu_xml', $row->type ), 'menu' );
  4080. if ( $params->get( 'unique_itemid' ) ) {
  4081. $row->link .= '&Itemid='. $row->id;
  4082. } else {
  4083. $temp = split( '&task=view&id=', $row->link);
  4084. $row->link .= '&Itemid='. $mainframe->getItemid($temp[1], 0, 0);
  4085. }
  4086. $link = $row->link;
  4087. break;
  4088. default:
  4089. if ( $link ) {
  4090. $link = $row->link;
  4091. } else {
  4092. $link = $row->link .'&amp;Itemid='. $row->id;
  4093. }
  4094. break;
  4095. }
  4096. } else {
  4097. $link = NULL;
  4098. }
  4099. return $link;
  4100. }
  4101. /**
  4102. * build the select list for target window
  4103. */
  4104. function Target( &$row ) {
  4105. $click[] = mosHTML::makeOption( '0', 'Parent Window With Browser Navigation' );
  4106. $click[] = mosHTML::makeOption( '1', 'New Window With Browser Navigation' );
  4107. $click[] = mosHTML::makeOption( '2', 'New Window Without Browser Navigation' );
  4108. $target = mosHTML::selectList( $click, 'browserNav', 'class="inputbox" size="4"', 'value', 'text', intval( $row->browserNav ) );
  4109. return $target;
  4110. }
  4111. /**
  4112. * build the multiple select list for Menu Links/Pages
  4113. */
  4114. function MenuLinks( &$lookup, $all=NULL, $none=NULL, $unassigned=1 ) {
  4115. global $database;
  4116. // get a list of the menu items
  4117. $query = "SELECT m.*"
  4118. . "\n FROM #__menu AS m"
  4119. . "\n WHERE m.published = 1"
  4120. //. "\n AND m.type != 'separator'"
  4121. //. "\n AND NOT ("
  4122. // . "\n ( m.type = 'url' )"
  4123. // . "\n AND ( m.link LIKE '%index.php%' )"
  4124. // . "\n AND ( m.link LIKE '%Itemid=%' )"
  4125. //. "\n )"
  4126. . "\n ORDER BY m.menutype, m.parent, m.ordering"
  4127. ;
  4128. $database->setQuery( $query );
  4129. $mitems = $database->loadObjectList();
  4130. $mitems_temp = $mitems;
  4131. // establish the hierarchy of the menu
  4132. $children = array();
  4133. // first pass - collect children
  4134. foreach ( $mitems as $v ) {
  4135. $id = $v->id;
  4136. $pt = $v->parent;
  4137. $list = @$children[$pt] ? $children[$pt] : array();
  4138. array_push( $list, $v );
  4139. $children[$pt] = $list;
  4140. }
  4141. // second pass - get an indent list of the items
  4142. $list = mosTreeRecurse( intval( $mitems[0]->parent ), '', array(), $children, 20, 0, 0 );
  4143. // Code that adds menu name to Display of Page(s)
  4144. $text_count = 0;
  4145. $mitems_spacer = $mitems_temp[0]->menutype;
  4146. foreach ($list as $list_a) {
  4147. foreach ($mitems_temp as $mitems_a) {
  4148. if ($mitems_a->id == $list_a->id) {
  4149. // Code that inserts the blank line that seperates different menus
  4150. if ($mitems_a->menutype != $mitems_spacer) {
  4151. $list_temp[] = mosHTML::makeOption( -999, '----' );
  4152. $mitems_spacer = $mitems_a->menutype;
  4153. }
  4154. // do not display `url` menu item types that contain `index.php` and `Itemid`
  4155. if (!($mitems_a->type == 'url' && strpos($mitems_a->link, 'index.php') !== false && strpos($mitems_a->link, 'Itemid=') !== false)) {
  4156. $text = $mitems_a->menutype .' | '. $list_a->treename;
  4157. $list_temp[] = mosHTML::makeOption( $list_a->id, $text );
  4158. if ( strlen($text) > $text_count) {
  4159. $text_count = strlen($text);
  4160. }
  4161. }
  4162. }
  4163. }
  4164. }
  4165. $list = $list_temp;
  4166. $mitems = array();
  4167. if ( $all ) {
  4168. // prepare an array with 'all' as the first item
  4169. $mitems[] = mosHTML::makeOption( 0, 'All' );
  4170. // adds space, in select box which is not saved
  4171. $mitems[] = mosHTML::makeOption( -999, '----' );
  4172. }
  4173. if ( $none ) {
  4174. // prepare an array with 'all' as the first item
  4175. $mitems[] = mosHTML::makeOption( -999, 'None' );
  4176. // adds space, in select box which is not saved
  4177. $mitems[] = mosHTML::makeOption( -999, '----' );
  4178. }
  4179. if ( $unassigned ) {
  4180. // prepare an array with 'all' as the first item
  4181. $mitems[] = mosHTML::makeOption( 99999999, 'Unassigned' );
  4182. // adds space, in select box which is not saved
  4183. $mitems[] = mosHTML::makeOption( -999, '----' );
  4184. }
  4185. // append the rest of the menu items to the array
  4186. foreach ($list as $item) {
  4187. $mitems[] = mosHTML::makeOption( $item->value, $item->text );
  4188. }
  4189. $pages = mosHTML::selectList( $mitems, 'selections[]', 'class="inputbox" size="26" multiple="multiple"', 'value', 'text', $lookup );
  4190. return $pages;
  4191. }
  4192. /**
  4193. * build the select list to choose a category
  4194. */
  4195. function Category( &$menu, $id, $javascript='' ) {
  4196. global $database;
  4197. $query = "SELECT c.id AS `value`, c.section AS `id`, CONCAT_WS( ' / ', s.title, c.title) AS `text`"
  4198. . "\n FROM #__sections AS s"
  4199. . "\n INNER JOIN #__categories AS c ON c.section = s.id"
  4200. . "\n WHERE s.scope = 'content'"
  4201. . "\n ORDER BY s.name, c.name"
  4202. ;
  4203. $database->setQuery( $query );
  4204. $rows = $database->loadObjectList();
  4205. $category = '';
  4206. if ( $id ) {
  4207. foreach ( $rows as $row ) {
  4208. if ( $row->value == $menu->componentid ) {
  4209. $category = $row->text;
  4210. }
  4211. }
  4212. $category .= '<input type="hidden" name="componentid" value="'. $menu->componentid .'" />';
  4213. $category .= '<input type="hidden" name="link" value="'. $menu->link .'" />';
  4214. } else {
  4215. $category = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"'. $javascript, 'value', 'text' );
  4216. $category .= '<input type="hidden" name="link" value="" />';
  4217. }
  4218. return $category;
  4219. }
  4220. /**
  4221. * build the select list to choose a section
  4222. */
  4223. function Section( &$menu, $id, $all=0 ) {
  4224. global $database;
  4225. $query = "SELECT s.id AS `value`, s.id AS `id`, s.title AS `text`"
  4226. . "\n FROM #__sections AS s"
  4227. . "\n WHERE s.scope = 'content'"
  4228. . "\n ORDER BY s.name"
  4229. ;
  4230. $database->setQuery( $query );
  4231. if ( $all ) {
  4232. $rows[] = mosHTML::makeOption( 0, '- All Sections -' );
  4233. $rows = array_merge( $rows, $database->loadObjectList() );
  4234. } else {
  4235. $rows = $database->loadObjectList();
  4236. }
  4237. if ( $id ) {
  4238. foreach ( $rows as $row ) {
  4239. if ( $row->value == $menu->componentid ) {
  4240. $section = $row->text;
  4241. }
  4242. }
  4243. $section .= '<input type="hidden" name="componentid" value="'. $menu->componentid .'" />';
  4244. $section .= '<input type="hidden" name="link" value="'. $menu->link .'" />';
  4245. } else {
  4246. $section = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"', 'value', 'text' );
  4247. $section .= '<input type="hidden" name="link" value="" />';
  4248. }
  4249. return $section;
  4250. }
  4251. /**
  4252. * build the select list to choose a component
  4253. */
  4254. function Component( &$menu, $id ) {
  4255. global $database;
  4256. $query = "SELECT c.id AS value, c.name AS text, c.link"
  4257. . "\n FROM #__components AS c"
  4258. . "\n WHERE c.link != ''"
  4259. . "\n ORDER BY c.name"
  4260. ;
  4261. $database->setQuery( $query );
  4262. $rows = $database->loadObjectList( );
  4263. if ( $id ) {
  4264. // existing component, just show name
  4265. foreach ( $rows as $row ) {
  4266. if ( $row->value == $menu->componentid ) {
  4267. $component = $row->text;
  4268. }
  4269. }
  4270. $component .= '<input type="hidden" name="componentid" value="'. $menu->componentid .'" />';
  4271. } else {
  4272. $component = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"', 'value', 'text' );
  4273. }
  4274. return $component;
  4275. }
  4276. /**
  4277. * build the select list to choose a component
  4278. */
  4279. function ComponentName( &$menu, $id ) {
  4280. global $database;
  4281. $query = "SELECT c.id AS value, c.name AS text, c.link"
  4282. . "\n FROM #__components AS c"
  4283. . "\n WHERE c.link != ''"
  4284. . "\n ORDER BY c.name"
  4285. ;
  4286. $database->setQuery( $query );
  4287. $rows = $database->loadObjectList( );
  4288. $component = 'Component';
  4289. foreach ( $rows as $row ) {
  4290. if ( $row->value == $menu->componentid ) {
  4291. $component = $row->text;
  4292. }
  4293. }
  4294. return $component;
  4295. }
  4296. /**
  4297. * build the select list to choose an image
  4298. */
  4299. function Images( $name, &$active, $javascript=NULL, $directory=NULL ) {
  4300. global $mosConfig_absolute_path;
  4301. if ( !$directory ) {
  4302. $directory = '/images/stories';
  4303. }
  4304. if ( !$javascript ) {
  4305. $javascript = "onchange=\"javascript:if (document.forms[0].image.options[selectedIndex].value!='') {document.imagelib.src='..$directory/' + document.forms[0].image.options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\"";
  4306. }
  4307. $imageFiles = mosReadDirectory( $mosConfig_absolute_path . $directory );
  4308. $images = array( mosHTML::makeOption( '', '- Select Image -' ) );
  4309. foreach ( $imageFiles as $file ) {
  4310. if ( eregi( "bmp|gif|jpg|png", $file ) ) {
  4311. $images[] = mosHTML::makeOption( $file );
  4312. }
  4313. }
  4314. $images = mosHTML::selectList( $images, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active );
  4315. return $images;
  4316. }
  4317. /**
  4318. * build the select list for Ordering of a specified Table
  4319. */
  4320. function SpecificOrdering( &$row, $id, $query, $neworder=0 ) {
  4321. global $database;
  4322. if ( $neworder ) {
  4323. $text = _CMN_NEW_ITEM_FIRST;
  4324. } else {
  4325. $text = _CMN_NEW_ITEM_LAST;
  4326. }
  4327. if ( $id ) {
  4328. $order = mosGetOrderingList( $query );
  4329. $ordering = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) );
  4330. } else {
  4331. $ordering = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />'. $text;
  4332. }
  4333. return $ordering;
  4334. }
  4335. /**
  4336. * Select list of active users
  4337. */
  4338. function UserSelect( $name, $active, $nouser=0, $javascript=NULL, $order='name', $reg=1 ) {
  4339. global $database, $my;
  4340. $and = '';
  4341. if ( $reg ) {
  4342. // does not include registered users in the list
  4343. $and = "\n AND gid > 18";
  4344. }
  4345. $query = "SELECT id AS value, name AS text"
  4346. . "\n FROM #__users"
  4347. . "\n WHERE block = 0"
  4348. . $and
  4349. . "\n ORDER BY $order"
  4350. ;
  4351. $database->setQuery( $query );
  4352. if ( $nouser ) {
  4353. $users[] = mosHTML::makeOption( '0', '- No User -' );
  4354. $users = array_merge( $users, $database->loadObjectList() );
  4355. } else {
  4356. $users = $database->loadObjectList();
  4357. }
  4358. $users = mosHTML::selectList( $users, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active );
  4359. return $users;
  4360. }
  4361. /**
  4362. * Select list of positions - generally used for location of images
  4363. */
  4364. function Positions( $name, $active=NULL, $javascript=NULL, $none=1, $center=1, $left=1, $right=1 ) {
  4365. if ( $none ) {
  4366. $pos[] = mosHTML::makeOption( '', _CMN_NONE );
  4367. }
  4368. if ( $center ) {
  4369. $pos[] = mosHTML::makeOption( 'center', _CMN_CENTER );
  4370. }
  4371. if ( $left ) {
  4372. $pos[] = mosHTML::makeOption( 'left', _CMN_LEFT );
  4373. }
  4374. if ( $right ) {
  4375. $pos[] = mosHTML::makeOption( 'right', _CMN_RIGHT );
  4376. }
  4377. $positions = mosHTML::selectList( $pos, $name, 'class="inputbox" size="1"'. $javascript, 'value', 'text', $active );
  4378. return $positions;
  4379. }
  4380. /**
  4381. * Select list of active categories for components
  4382. */
  4383. function ComponentCategory( $name, $section, $active=NULL, $javascript=NULL, $order='ordering', $size=1, $sel_cat=1 ) {
  4384. global $database;
  4385. $query = "SELECT id AS value, name AS text"
  4386. . "\n FROM #__categories"
  4387. . "\n WHERE section = " . $database->Quote( $section )
  4388. . "\n AND published = 1"
  4389. . "\n ORDER BY $order"
  4390. ;
  4391. $database->setQuery( $query );
  4392. if ( $sel_cat ) {
  4393. $categories[] = mosHTML::makeOption( '0', _SEL_CATEGORY );
  4394. $categories = array_merge( $categories, $database->loadObjectList() );
  4395. } else {
  4396. $categories = $database->loadObjectList();
  4397. }
  4398. if ( count( $categories ) < 1 ) {
  4399. mosRedirect( 'index2.php?option=com_categories&section='. $section, 'You must create a category first.' );
  4400. }
  4401. $category = mosHTML::selectList( $categories, $name, 'class="inputbox" size="'. $size .'" '. $javascript, 'value', 'text', $active );
  4402. return $category;
  4403. }
  4404. /**
  4405. * Select list of active sections
  4406. */
  4407. function SelectSection( $name, $active=NULL, $javascript=NULL, $order='ordering' ) {
  4408. global $database;
  4409. $categories[] = mosHTML::makeOption( '0', _SEL_SECTION );
  4410. $query = "SELECT id AS value, title AS text"
  4411. . "\n FROM #__sections"
  4412. . "\n WHERE published = 1"
  4413. . "\n ORDER BY $order"
  4414. ;
  4415. $database->setQuery( $query );
  4416. $sections = array_merge( $categories, $database->loadObjectList() );
  4417. $category = mosHTML::selectList( $sections, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active );
  4418. return $category;
  4419. }
  4420. /**
  4421. * Select list of menu items for a specific menu
  4422. */
  4423. function Links2Menu( $type, $and ) {
  4424. global $database;
  4425. $query = "SELECT *"
  4426. . "\n FROM #__menu"
  4427. . "\n WHERE type = " . $database->Quote( $type )
  4428. . "\n AND published = 1"
  4429. . $and
  4430. ;
  4431. $database->setQuery( $query );
  4432. $menus = $database->loadObjectList();
  4433. return $menus;
  4434. }
  4435. /**
  4436. * Select list of menus
  4437. * @param string The control name
  4438. * @param string Additional javascript
  4439. * @return string A select list
  4440. */
  4441. function MenuSelect( $name='menuselect', $javascript=NULL ) {
  4442. global $database;
  4443. $query = "SELECT params"
  4444. . "\n FROM #__modules"
  4445. . "\n WHERE module = 'mod_mainmenu'"
  4446. ;
  4447. $database->setQuery( $query );
  4448. $menus = $database->loadObjectList();
  4449. $total = count( $menus );
  4450. $menuselect = array();
  4451. for( $i = 0; $i < $total; $i++ ) {
  4452. $params = mosParseParams( $menus[$i]->params );
  4453. $menuselect[$i]->value = $params->menutype;
  4454. $menuselect[$i]->text = $params->menutype;
  4455. }
  4456. // sort array of objects
  4457. SortArrayObjects( $menuselect, 'text', 1 );
  4458. $menus = mosHTML::selectList( $menuselect, $name, 'class="inputbox" size="10" '. $javascript, 'value', 'text' );
  4459. return $menus;
  4460. }
  4461. /**
  4462. * Internal function to recursive scan the media manager directories
  4463. * @param string Path to scan
  4464. * @param string root path of this folder
  4465. * @param array Value array of all existing folders
  4466. * @param array Value array of all existing images
  4467. */
  4468. function ReadImages( $imagePath, $folderPath, &$folders, &$images ) {
  4469. $imgFiles = mosReadDirectory( $imagePath );
  4470. foreach ($imgFiles as $file) {
  4471. $ff_ = $folderPath . $file .'/';
  4472. $ff = $folderPath . $file;
  4473. $i_f = $imagePath .'/'. $file;
  4474. if ( is_dir( $i_f ) && $file != 'CVS' && $file != '.svn') {
  4475. $folders[] = mosHTML::makeOption( $ff_ );
  4476. mosAdminMenus::ReadImages( $i_f, $ff_, $folders, $images );
  4477. } else if ( eregi( "bmp|gif|jpg|png", $file ) && is_file( $i_f ) ) {
  4478. // leading / we don't need
  4479. $imageFile = substr( $ff, 1 );
  4480. $images[$folderPath][] = mosHTML::makeOption( $imageFile, $file );
  4481. }
  4482. }
  4483. }
  4484. /**
  4485. * Internal function to recursive scan the media manager directories
  4486. * @param string Path to scan
  4487. * @param string root path of this folder
  4488. * @param array Value array of all existing folders
  4489. * @param array Value array of all existing images
  4490. */
  4491. function ReadImagesX( &$folders, &$images ) {
  4492. global $mosConfig_absolute_path;
  4493. if ( $folders[0]->value != '*0*' ) {
  4494. foreach ( $folders as $folder ) {
  4495. $imagePath = $mosConfig_absolute_path .'/images/stories' . $folder->value;
  4496. $imgFiles = mosReadDirectory( $imagePath );
  4497. $folderPath = $folder->value .'/';
  4498. foreach ($imgFiles as $file) {
  4499. $ff = $folderPath . $file;
  4500. $i_f = $imagePath .'/'. $file;
  4501. if ( eregi( "bmp|gif|jpg|png", $file ) && is_file( $i_f ) ) {
  4502. // leading / we don't need
  4503. $imageFile = substr( $ff, 1 );
  4504. $images[$folderPath][] = mosHTML::makeOption( $imageFile, $file );
  4505. }
  4506. }
  4507. }
  4508. } else {
  4509. $folders = array();
  4510. $folders[] = mosHTML::makeOption( 'None' );
  4511. }
  4512. }
  4513. function GetImageFolders( &$temps, $path ) {
  4514. if ( $temps[0]->value != 'None' ) {
  4515. foreach( $temps as $temp ) {
  4516. if ( substr( $temp->value, -1, 1 ) != '/' ) {
  4517. $temp = $temp->value .'/';
  4518. $folders[] = mosHTML::makeOption( $temp, $temp );
  4519. } else {
  4520. $temp = $temp->value;
  4521. $temp = ampReplace( $temp );
  4522. $folders[] = mosHTML::makeOption( $temp, $temp );
  4523. }
  4524. }
  4525. } else {
  4526. $folders[] = mosHTML::makeOption( 'None Selected' );
  4527. }
  4528. $javascript = "onchange=\"changeDynaList( 'imagefiles', folderimages, document.adminForm.folders.options[document.adminForm.folders.selectedIndex].value, 0, 0);\"";
  4529. $getfolders = mosHTML::selectList( $folders, 'folders', 'class="inputbox" size="1" '. $javascript, 'value', 'text', '/' );
  4530. return $getfolders;
  4531. }
  4532. function GetImages( &$images, $path, $base='/' ) {
  4533. if ( is_array($base) && count($base) > 0 ) {
  4534. if ( $base[0]->value != '/' ) {
  4535. $base = $base[0]->value .'/';
  4536. } else {
  4537. $base = $base[0]->value;
  4538. }
  4539. } else {
  4540. $base = '/';
  4541. }
  4542. if ( !isset($images[$base] ) ) {
  4543. $images[$base][] = mosHTML::makeOption( '' );
  4544. }
  4545. $javascript = "onchange=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\" onfocus=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\"";
  4546. $getimages = mosHTML::selectList( $images[$base], 'imagefiles', 'class="inputbox" size="10" multiple="multiple" '. $javascript , 'value', 'text', null );
  4547. return $getimages;
  4548. }
  4549. function GetSavedImages( &$row, $path ) {
  4550. $images2 = array();
  4551. foreach( $row->images as $file ) {
  4552. $temp = explode( '|', $file );
  4553. if( strrchr($temp[0], '/') ) {
  4554. $filename = substr( strrchr($temp[0], '/' ), 1 );
  4555. } else {
  4556. $filename = $temp[0];
  4557. }
  4558. $images2[] = mosHTML::makeOption( $file, $filename );
  4559. }
  4560. $javascript = "onchange=\"previewImage( 'imagelist', 'view_imagelist', '$path/' ); showImageProps( '$path/' ); \"";
  4561. $imagelist = mosHTML::selectList( $images2, 'imagelist', 'class="inputbox" size="10" '. $javascript, 'value', 'text' );
  4562. return $imagelist;
  4563. }
  4564. /**
  4565. * Checks to see if an image exists in the current templates image directory
  4566. * if it does it loads this image. Otherwise the default image is loaded.
  4567. * Also can be used in conjunction with the menulist param to create the chosen image
  4568. * load the default or use no image
  4569. */
  4570. function ImageCheck( $file, $directory='/images/M_images/', $param=NULL, $param_directory='/images/M_images/', $alt=NULL, $name=NULL, $type=1, $align='middle', $title=NULL, $admin=NULL ) {
  4571. global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe;
  4572. $cur_template = $mainframe->getTemplate();
  4573. $name = ( $name ? ' name="'. $name .'"' : '' );
  4574. $title = ( $title ? ' title="'. $title .'"' : '' );
  4575. $alt = ( $alt ? ' alt="'. $alt .'"' : ' alt=""' );
  4576. $align = ( $align ? ' vertical-align:'.$align : '' );
  4577. // change directory path from frontend or backend
  4578. if ($admin) {
  4579. $path = '/administrator/templates/'. $cur_template .'/images/';
  4580. } else {
  4581. $path = '/templates/'. $cur_template .'/images/';
  4582. }
  4583. if ( $param ) {
  4584. $image = $mosConfig_live_site. $param_directory . $param;
  4585. if ( $type ) {
  4586. $image = '<img src="'. $image .'" '. $alt . $name . $align .' style="border: 0" />';
  4587. }
  4588. } else if ( $param == -1 ) {
  4589. $image = '';
  4590. } else {
  4591. if ( file_exists( $mosConfig_absolute_path . $path . $file ) ) {
  4592. $image = $mosConfig_live_site . $path . $file;
  4593. } else {
  4594. // outputs only path to image
  4595. $image = $mosConfig_live_site. $directory . $file;
  4596. }
  4597. // outputs actual html <img> tag
  4598. if ( $type ) {
  4599. $image = '<img src="'. $image .'" '. $alt . $name . $title . ' style="border: 0px; '.$align.'" />';
  4600. }
  4601. }
  4602. return $image;
  4603. }
  4604. /**
  4605. * Checks to see if an image exists in the current templates image directory
  4606. * if it does it loads this image. Otherwise the default image is loaded.
  4607. * Also can be used in conjunction with the menulist param to create the chosen image
  4608. * load the default or use no image
  4609. */
  4610. function ImageCheckAdmin( $file, $directory='/administrator/images/', $param=NULL, $param_directory='/administrator/images/', $alt=NULL, $name=NULL, $type=1, $align='middle', $title=NULL ) {
  4611. /*
  4612. global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe;
  4613. $cur_template = $mainframe->getTemplate();
  4614. $name = ( $name ? ' name="'. $name .'"' : '' );
  4615. $title = ( $title ? ' title="'. $title .'"' : '' );
  4616. $alt = ( $alt ? ' alt="'. $alt .'"' : ' alt=""' );
  4617. $align = ( $align ? ' align="'. $align .'"' : '' );
  4618. $path = '/administrator/templates/'. $cur_template .'/images/';
  4619. if ( $param ) {
  4620. $image = $mosConfig_live_site. $param_directory . $param;
  4621. if ( $type ) {
  4622. $image = '<img src="'. $image .'" '. $alt . $name . $align .' border="0" />';
  4623. }
  4624. } else if ( $param == -1 ) {
  4625. $image = '';
  4626. } else {
  4627. if ( file_exists( $mosConfig_absolute_path . $path . $file ) ) {
  4628. $image = $mosConfig_live_site . $path . $file;
  4629. } else {
  4630. // outputs only path to image
  4631. $image = $mosConfig_live_site. $directory . $file;
  4632. }
  4633. // outputs actual html <img> tag
  4634. if ( $type ) {
  4635. $image = '<img src="'. $image .'" '. $alt . $name . $title . $align .' border="0" />';
  4636. }
  4637. }
  4638. */
  4639. // functionality consolidated into ImageCheck
  4640. $image = mosAdminMenus::ImageCheck( $file, $directory, $param, $param_directory, $alt, $name, $type, $align, $title, $admin=1 );
  4641. return $image;
  4642. }
  4643. function menutypes() {
  4644. global $database;
  4645. $query = "SELECT params"
  4646. . "\n FROM #__modules"
  4647. . "\n WHERE module = 'mod_mainmenu'"
  4648. . "\n ORDER BY title"
  4649. ;
  4650. $database->setQuery( $query );
  4651. $modMenus = $database->loadObjectList();
  4652. $query = "SELECT menutype"
  4653. . "\n FROM #__menu"
  4654. . "\n GROUP BY menutype"
  4655. . "\n ORDER BY menutype"
  4656. ;
  4657. $database->setQuery( $query );
  4658. $menuMenus = $database->loadObjectList();
  4659. $menuTypes = '';
  4660. foreach ( $modMenus as $modMenu ) {
  4661. $check = 1;
  4662. mosMakeHtmlSafe( $modMenu) ;
  4663. $modParams = mosParseParams( $modMenu->params );
  4664. $menuType = @$modParams->menutype;
  4665. if (!$menuType) {
  4666. $menuType = 'mainmenu';
  4667. }
  4668. // stop duplicate menutype being shown
  4669. if ( !is_array( $menuTypes) ) {
  4670. // handling to create initial entry into array
  4671. $menuTypes[] = $menuType;
  4672. } else {
  4673. $check = 1;
  4674. foreach ( $menuTypes as $a ) {
  4675. if ( $a == $menuType ) {
  4676. $check = 0;
  4677. }
  4678. }
  4679. if ( $check ) {
  4680. $menuTypes[] = $menuType;
  4681. }
  4682. }
  4683. }
  4684. // add menutypes from jos_menu
  4685. foreach ( $menuMenus as $menuMenu ) {
  4686. $check = 1;
  4687. foreach ( $menuTypes as $a ) {
  4688. if ( $a == $menuMenu->menutype ) {
  4689. $check = 0;
  4690. }
  4691. }
  4692. if ( $check ) {
  4693. $menuTypes[] = $menuMenu->menutype;
  4694. }
  4695. }
  4696. // sorts menutypes
  4697. asort( $menuTypes );
  4698. return $menuTypes;
  4699. }
  4700. /*
  4701. * loads files required for menu items
  4702. */
  4703. function menuItem( $item ) {
  4704. global $mosConfig_absolute_path;
  4705. $path = $mosConfig_absolute_path .'/administrator/components/com_menus/'. $item .'/';
  4706. include_once( $path . $item .'.class.php' );
  4707. include_once( $path . $item .'.menu.html.php' );
  4708. }
  4709. }
  4710. class mosCommonHTML {
  4711. function ContentLegend( ) {
  4712. ?>
  4713. <table cellspacing="0" cellpadding="4" border="0" align="center">
  4714. <tr align="center">
  4715. <td>
  4716. <img src="images/publish_y.png" border="0" alt="Pending" />
  4717. </td>
  4718. <td>
  4719. Published, but is <u>Pending</u> |
  4720. </td>
  4721. <td>
  4722. <img src="images/publish_g.png" border="0" alt="Visible" />
  4723. </td>
  4724. <td>
  4725. Published and is <u>Current</u> |
  4726. </td>
  4727. <td>
  4728. <img src="images/publish_r.png" border="0" alt="Finished" />
  4729. </td>
  4730. <td>
  4731. Published, but has <u>Expired</u> |
  4732. </td>
  4733. <td>
  4734. <img src="images/publish_x.png" border="0" alt="Finished" />
  4735. </td>
  4736. <td>
  4737. Not Published
  4738. </td>
  4739. </tr>
  4740. <tr>
  4741. <td colspan="8" align="center">
  4742. Click on icon to toggle state.
  4743. </td>
  4744. </tr>
  4745. </table>
  4746. <?php
  4747. }
  4748. function menuLinksContent( &$menus ) {
  4749. ?>
  4750. <script language="javascript" type="text/javascript">
  4751. function go2( pressbutton, menu, id ) {
  4752. var form = document.adminForm;
  4753. // assemble the images back into one field
  4754. var temp = new Array;
  4755. for (var i=0, n=form.imagelist.options.length; i < n; i++) {
  4756. temp[i] = form.imagelist.options[i].value;
  4757. }
  4758. form.images.value = temp.join( '\n' );
  4759. if (pressbutton == 'go2menu') {
  4760. form.menu.value = menu;
  4761. submitform( pressbutton );
  4762. return;
  4763. }
  4764. if (pressbutton == 'go2menuitem') {
  4765. form.menu.value = menu;
  4766. form.menuid.value = id;
  4767. submitform( pressbutton );
  4768. return;
  4769. }
  4770. }
  4771. </script>
  4772. <?php
  4773. foreach( $menus as $menu ) {
  4774. ?>
  4775. <tr>
  4776. <td colspan="2">
  4777. <hr />
  4778. </td>
  4779. </tr>
  4780. <tr>
  4781. <td width="90px" valign="top">
  4782. Menu
  4783. </td>
  4784. <td>
  4785. <a href="javascript:go2( 'go2menu', '<?php echo $menu->menutype; ?>' );" title="Go to Menu">
  4786. <?php echo $menu->menutype; ?>
  4787. </a>
  4788. </td>
  4789. </tr>
  4790. <tr>
  4791. <td width="90px" valign="top">
  4792. Link Name
  4793. </td>
  4794. <td>
  4795. <strong>
  4796. <a href="javascript:go2( 'go2menuitem', '<?php echo $menu->menutype; ?>', '<?php echo $menu->id; ?>' );" title="Go to Menu Item">
  4797. <?php echo $menu->name; ?>
  4798. </a>
  4799. </strong>
  4800. </td>
  4801. </tr>
  4802. <tr>
  4803. <td width="90px" valign="top">
  4804. State
  4805. </td>
  4806. <td>
  4807. <?php
  4808. switch ( $menu->published ) {
  4809. case -2:
  4810. echo '<font color="red">Trashed</font>';
  4811. break;
  4812. case 0:
  4813. echo 'UnPublished';
  4814. break;
  4815. case 1:
  4816. default:
  4817. echo '<font color="green">Published</font>';
  4818. break;
  4819. }
  4820. ?>
  4821. </td>
  4822. </tr>
  4823. <?php
  4824. }
  4825. ?>
  4826. <input type="hidden" name="menu" value="" />
  4827. <input type="hidden" name="menuid" value="" />
  4828. <?php
  4829. }
  4830. function menuLinksSecCat( &$menus ) {
  4831. ?>
  4832. <script language="javascript" type="text/javascript">
  4833. function go2( pressbutton, menu, id ) {
  4834. var form = document.adminForm;
  4835. if (pressbutton == 'go2menu') {
  4836. form.menu.value = menu;
  4837. submitform( pressbutton );
  4838. return;
  4839. }
  4840. if (pressbutton == 'go2menuitem') {
  4841. form.menu.value = menu;
  4842. form.menuid.value = id;
  4843. submitform( pressbutton );
  4844. return;
  4845. }
  4846. }
  4847. </script>
  4848. <?php
  4849. foreach( $menus as $menu ) {
  4850. ?>
  4851. <tr>
  4852. <td colspan="2">
  4853. <hr/>
  4854. </td>
  4855. </tr>
  4856. <tr>
  4857. <td width="90px" valign="top">
  4858. Menu
  4859. </td>
  4860. <td>
  4861. <a href="javascript:go2( 'go2menu', '<?php echo $menu->menutype; ?>' );" title="Go to Menu">
  4862. <?php echo $menu->menutype; ?>
  4863. </a>
  4864. </td>
  4865. </tr>
  4866. <tr>
  4867. <td width="90px" valign="top">
  4868. Type
  4869. </td>
  4870. <td>
  4871. <?php echo $menu->type; ?>
  4872. </td>
  4873. </tr>
  4874. <tr>
  4875. <td width="90px" valign="top">
  4876. Item Name
  4877. </td>
  4878. <td>
  4879. <strong>
  4880. <a href="javascript:go2( 'go2menuitem', '<?php echo $menu->menutype; ?>', '<?php echo $menu->id; ?>' );" title="Go to Menu Item">
  4881. <?php echo $menu->name; ?>
  4882. </a>
  4883. </strong>
  4884. </td>
  4885. </tr>
  4886. <tr>
  4887. <td width="90px" valign="top">
  4888. State
  4889. </td>
  4890. <td>
  4891. <?php
  4892. switch ( $menu->published ) {
  4893. case -2:
  4894. echo '<font color="red">Trashed</font>';
  4895. break;
  4896. case 0:
  4897. echo 'UnPublished';
  4898. break;
  4899. case 1:
  4900. default:
  4901. echo '<font color="green">Published</font>';
  4902. break;
  4903. }
  4904. ?>
  4905. </td>
  4906. </tr>
  4907. <?php
  4908. }
  4909. ?>
  4910. <input type="hidden" name="menu" value="" />
  4911. <input type="hidden" name="menuid" value="" />
  4912. <?php
  4913. }
  4914. function checkedOut( &$row, $overlib=1 ) {
  4915. $hover = '';
  4916. if ( $overlib ) {
  4917. $date = mosFormatDate( $row->checked_out_time, '%A, %d %B %Y' );
  4918. $time = mosFormatDate( $row->checked_out_time, '%H:%M' );
  4919. $editor = addslashes( htmlspecialchars( html_entity_decode( $row->editor, ENT_QUOTES ) ) );
  4920. $checked_out_text = '<table>';
  4921. $checked_out_text .= '<tr><td>'. $editor .'</td></tr>';
  4922. $checked_out_text .= '<tr><td>'. $date .'</td></tr>';
  4923. $checked_out_text .= '<tr><td>'. $time .'</td></tr>';
  4924. $checked_out_text .= '</table>';
  4925. $hover = 'onMouseOver="return overlib(\''. $checked_out_text .'\', CAPTION, \'Checked Out\', BELOW, RIGHT);" onMouseOut="return nd();"';
  4926. }
  4927. $checked = '<img src="images/checked_out.png" '. $hover .'/>';
  4928. return $checked;
  4929. }
  4930. /*
  4931. * Loads all necessary files for JS Overlib tooltips
  4932. */
  4933. function loadOverlib() {
  4934. global $mosConfig_live_site, $mainframe;
  4935. if ( !$mainframe->get( 'loadOverlib' ) ) {
  4936. // check if this function is already loaded
  4937. ?>
  4938. <script language="javascript" type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/overlib_mini.js"></script>
  4939. <script language="javascript" type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/overlib_hideform_mini.js"></script>
  4940. <?php
  4941. // change state so it isnt loaded a second time
  4942. $mainframe->set( 'loadOverlib', true );
  4943. }
  4944. }
  4945. /*
  4946. * Loads all necessary files for JS Calendar
  4947. */
  4948. function loadCalendar() {
  4949. global $mosConfig_live_site;
  4950. ?>
  4951. <link rel="stylesheet" type="text/css" media="all" href="<?php echo $mosConfig_live_site;?>/includes/js/calendar/calendar-mos.css" title="green" />
  4952. <!-- import the calendar script -->
  4953. <script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/calendar/calendar_mini.js"></script>
  4954. <!-- import the language module -->
  4955. <script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/calendar/lang/calendar-en.js"></script>
  4956. <?php
  4957. }
  4958. function AccessProcessing( &$row, $i ) {
  4959. if ( !$row->access ) {
  4960. $color_access = 'style="color: green;"';
  4961. $task_access = 'accessregistered';
  4962. } else if ( $row->access == 1 ) {
  4963. $color_access = 'style="color: red;"';
  4964. $task_access = 'accessspecial';
  4965. } else {
  4966. $color_access = 'style="color: black;"';
  4967. $task_access = 'accesspublic';
  4968. }
  4969. $href = '
  4970. <a href="javascript: void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task_access .'\')" '. $color_access .'>
  4971. '. $row->groupname .'
  4972. </a>'
  4973. ;
  4974. return $href;
  4975. }
  4976. function CheckedOutProcessing( &$row, $i ) {
  4977. global $my;
  4978. if ( $row->checked_out) {
  4979. $checked = mosCommonHTML::checkedOut( $row );
  4980. } else {
  4981. $checked = mosHTML::idBox( $i, $row->id, ($row->checked_out && $row->checked_out != $my->id ) );
  4982. }
  4983. return $checked;
  4984. }
  4985. function PublishedProcessing( &$row, $i ) {
  4986. $img = $row->published ? 'publish_g.png' : 'publish_x.png';
  4987. $task = $row->published ? 'unpublish' : 'publish';
  4988. $alt = $row->published ? 'Published' : 'Unpublished';
  4989. $action = $row->published ? 'Unpublish Item' : 'Publish item';
  4990. $href = '
  4991. <a href="javascript: void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task .'\')" title="'. $action .'">
  4992. <img src="images/'. $img .'" border="0" alt="'. $alt .'" />
  4993. </a>'
  4994. ;
  4995. return $href;
  4996. }
  4997. /*
  4998. * Special handling for newfeed encoding and possible conflicts with page encoding and PHP version
  4999. * Added 1.0.8
  5000. * Static Function
  5001. */
  5002. function newsfeedEncoding( $rssDoc, $text ) {
  5003. if (!defined( '_JOS_FEED_ENCODING' )) {
  5004. // determine encoding of feed
  5005. $feed = $rssDoc->toNormalizedString(true);
  5006. $feed = strtolower( substr( $feed, 0, 150 ) );
  5007. $feedEncoding = strpos( $feed, 'encoding=&quot;utf-8&quot;' );
  5008. if ( $feedEncoding !== false ) {
  5009. // utf-8 feed
  5010. $utf8 = 1;
  5011. } else {
  5012. // non utf-8 page
  5013. $utf8 = 0;
  5014. }
  5015. define( '_JOS_FEED_ENCODING', $utf8 );
  5016. }
  5017. if (!defined( '_JOS_SITE_ENCODING' )) {
  5018. // determine encoding of page
  5019. if ( strpos( strtolower( _ISO ), 'utf' ) !== false ) {
  5020. // utf-8 page
  5021. $utf8 = 1;
  5022. } else {
  5023. // non utf-8 page
  5024. $utf8 = 0;
  5025. }
  5026. define( '_JOS_SITE_ENCODING', $utf8 );
  5027. }
  5028. if ( phpversion() >= 5 ) {
  5029. // handling for PHP 5
  5030. if ( _JOS_FEED_ENCODING ) {
  5031. // handling for utf-8 feed
  5032. if ( _JOS_SITE_ENCODING ) {
  5033. // utf-8 page
  5034. $encoding = 'html_entity_decode';
  5035. } else {
  5036. // non utf-8 page
  5037. $encoding = 'utf8_decode';
  5038. }
  5039. } else {
  5040. // handling for non utf-8 feed
  5041. if ( _JOS_SITE_ENCODING ) {
  5042. // utf-8 page
  5043. $encoding = '';
  5044. } else {
  5045. // non utf-8 page
  5046. $encoding = 'utf8_decode';
  5047. }
  5048. }
  5049. } else {
  5050. // handling for PHP 4
  5051. if ( _JOS_FEED_ENCODING ) {
  5052. // handling for utf-8 feed
  5053. if ( _JOS_SITE_ENCODING ) {
  5054. // utf-8 page
  5055. $encoding = '';
  5056. } else {
  5057. // non utf-8 page
  5058. $encoding = 'utf8_decode';
  5059. }
  5060. } else {
  5061. // handling for non utf-8 feed
  5062. if ( _JOS_SITE_ENCODING ) {
  5063. // utf-8 page
  5064. $encoding = 'utf8_encode';
  5065. } else {
  5066. // non utf-8 page
  5067. $encoding = 'html_entity_decode';
  5068. }
  5069. }
  5070. }
  5071. if ( $encoding ) {
  5072. $text = $encoding( $text );
  5073. }
  5074. $text = str_replace('&apos;', "'", $text);
  5075. return $text;
  5076. }
  5077. }
  5078. /**
  5079. * Sorts an Array of objects
  5080. */
  5081. function SortArrayObjects_cmp( &$a, &$b ) {
  5082. global $csort_cmp;
  5083. if ( $a->$csort_cmp['key'] > $b->$csort_cmp['key'] ) {
  5084. return $csort_cmp['direction'];
  5085. }
  5086. if ( $a->$csort_cmp['key'] < $b->$csort_cmp['key'] ) {
  5087. return -1 * $csort_cmp['direction'];
  5088. }
  5089. return 0;
  5090. }
  5091. /**
  5092. * Sorts an Array of objects
  5093. * sort_direction [1 = Ascending] [-1 = Descending]
  5094. */
  5095. function SortArrayObjects( &$a, $k, $sort_direction=1 ) {
  5096. global $csort_cmp;
  5097. $csort_cmp = array(
  5098. 'key' => $k,
  5099. 'direction' => $sort_direction
  5100. );
  5101. usort( $a, 'SortArrayObjects_cmp' );
  5102. unset( $csort_cmp );
  5103. }
  5104. /**
  5105. * Sends mail to admin
  5106. */
  5107. function mosSendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author ) {
  5108. global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_live_site;
  5109. $subject = _MAIL_SUB." '$type'";
  5110. $message = _MAIL_MSG;
  5111. eval ("\$message = \"$message\";");
  5112. mosMail($mosConfig_mailfrom, $mosConfig_fromname, $adminEmail, $subject, $message);
  5113. }
  5114. /*
  5115. * Includes pathway file
  5116. */
  5117. function mosPathWay() {
  5118. global $mosConfig_absolute_path;
  5119. $Itemid = intval( mosGetParam( $_REQUEST, 'Itemid', '' ) );
  5120. require_once ( $mosConfig_absolute_path . '/includes/pathway.php' );
  5121. }
  5122. /**
  5123. * Displays a not authorised message
  5124. *
  5125. * If the user is not logged in then an addition message is displayed.
  5126. */
  5127. function mosNotAuth() {
  5128. global $my;
  5129. echo _NOT_AUTH;
  5130. if ($my->id < 1) {
  5131. echo "<br />" . _DO_LOGIN;
  5132. }
  5133. }
  5134. /**
  5135. * Replaces &amp; with & for xhtml compliance
  5136. *
  5137. * Needed to handle unicode conflicts due to unicode conflicts
  5138. */
  5139. function ampReplace( $text ) {
  5140. $text = str_replace( '&&', '*--*', $text );
  5141. $text = str_replace( '&#', '*-*', $text );
  5142. $text = str_replace( '&amp;', '&', $text );
  5143. $text = preg_replace( '|&(?![\w]+;)|', '&amp;', $text );
  5144. $text = str_replace( '*-*', '&#', $text );
  5145. $text = str_replace( '*--*', '&&', $text );
  5146. return $text;
  5147. }
  5148. /**
  5149. * Prepares results from search for display
  5150. * @param string The source string
  5151. * @param int Number of chars to trim
  5152. * @param string The searchword to select around
  5153. * @return string
  5154. */
  5155. function mosPrepareSearchContent( $text, $length=200, $searchword ) {
  5156. // strips tags won't remove the actual jscript
  5157. $text = preg_replace( "'<script[^>]*>.*?</script>'si", "", $text );
  5158. $text = preg_replace( '/{.+?}/', '', $text);
  5159. //$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2', $text );
  5160. // replace line breaking tags with whitespace
  5161. $text = preg_replace( "'<(br[^/>]*?/|hr[^/>]*?/|/(div|h[1-6]|li|p|td))>'si", ' ', $text );
  5162. $text = mosSmartSubstr( strip_tags( $text ), $length, $searchword );
  5163. return $text;
  5164. }
  5165. /**
  5166. * returns substring of characters around a searchword
  5167. * @param string The source string
  5168. * @param int Number of chars to return
  5169. * @param string The searchword to select around
  5170. * @return string
  5171. */
  5172. function mosSmartSubstr($text, $length=200, $searchword) {
  5173. $wordpos = strpos(strtolower($text), strtolower($searchword));
  5174. $halfside = intval($wordpos - $length/2 - strlen($searchword));
  5175. if ($wordpos && $halfside > 0) {
  5176. return '...' . substr($text, $halfside, $length) . '...';
  5177. } else {
  5178. return substr( $text, 0, $length);
  5179. }
  5180. }
  5181. /**
  5182. * Chmods files and directories recursively to given permissions. Available from 1.0.0 up.
  5183. * @param path The starting file or directory (no trailing slash)
  5184. * @param filemode Integer value to chmod files. NULL = dont chmod files.
  5185. * @param dirmode Integer value to chmod directories. NULL = dont chmod directories.
  5186. * @return TRUE=all succeeded FALSE=one or more chmods failed
  5187. */
  5188. function mosChmodRecursive($path, $filemode=NULL, $dirmode=NULL)
  5189. {
  5190. $ret = TRUE;
  5191. if (is_dir($path)) {
  5192. $dh = opendir($path);
  5193. while ($file = readdir($dh)) {
  5194. if ($file != '.' && $file != '..') {
  5195. $fullpath = $path.'/'.$file;
  5196. if (is_dir($fullpath)) {
  5197. if (!mosChmodRecursive($fullpath, $filemode, $dirmode))
  5198. $ret = FALSE;
  5199. } else {
  5200. if (isset($filemode))
  5201. if (!@chmod($fullpath, $filemode))
  5202. $ret = FALSE;
  5203. } // if
  5204. } // if
  5205. } // while
  5206. closedir($dh);
  5207. if (isset($dirmode))
  5208. if (!@chmod($path, $dirmode))
  5209. $ret = FALSE;
  5210. } else {
  5211. if (isset($filemode))
  5212. $ret = @chmod($path, $filemode);
  5213. } // if
  5214. return $ret;
  5215. } // mosChmodRecursive
  5216. /**
  5217. * Chmods files and directories recursively to mos global permissions. Available from 1.0.0 up.
  5218. * @param path The starting file or directory (no trailing slash)
  5219. * @param filemode Integer value to chmod files. NULL = dont chmod files.
  5220. * @param dirmode Integer value to chmod directories. NULL = dont chmod directories.
  5221. * @return TRUE=all succeeded FALSE=one or more chmods failed
  5222. */
  5223. function mosChmod($path) {
  5224. global $mosConfig_fileperms, $mosConfig_dirperms;
  5225. $filemode = NULL;
  5226. if ($mosConfig_fileperms != '')
  5227. $filemode = octdec($mosConfig_fileperms);
  5228. $dirmode = NULL;
  5229. if ($mosConfig_dirperms != '')
  5230. $dirmode = octdec($mosConfig_dirperms);
  5231. if (isset($filemode) || isset($dirmode))
  5232. return mosChmodRecursive($path, $filemode, $dirmode);
  5233. return TRUE;
  5234. } // mosChmod
  5235. /**
  5236. * Function to convert array to integer values
  5237. * @param array
  5238. * @param int A default value to assign if $array is not an array
  5239. * @return array
  5240. */
  5241. function mosArrayToInts( &$array, $default=null ) {
  5242. if (is_array( $array )) {
  5243. foreach( $array as $key => $value ) {
  5244. $array[$key] = (int) $value;
  5245. }
  5246. } else {
  5247. if (is_null( $default )) {
  5248. $array = array();
  5249. return array(); // Kept for backwards compatibility
  5250. } else {
  5251. $array = array( (int) $default );
  5252. return array( $default ); // Kept for backwards compatibility
  5253. }
  5254. }
  5255. }
  5256. /*
  5257. * Function to handle an array of integers
  5258. * Added 1.0.11
  5259. */
  5260. function josGetArrayInts( $name, $type=NULL ) {
  5261. if ( $type == NULL ) {
  5262. $type = $_POST;
  5263. }
  5264. $array = mosGetParam( $type, $name, array(0) );
  5265. mosArrayToInts( $array );
  5266. if (!is_array( $array )) {
  5267. $array = array(0);
  5268. }
  5269. return $array;
  5270. }
  5271. /**
  5272. * Utility class for helping with patTemplate
  5273. */
  5274. class patHTML {
  5275. /**
  5276. * Converts a named array to an array or named rows suitable to option lists
  5277. * @param array The source array[key] = value
  5278. * @param mixed A value or array of selected values
  5279. * @param string The name for the value field
  5280. * @param string The name for selected attribute (use 'checked' for radio of box lists)
  5281. */
  5282. function selectArray( &$source, $selected=null, $valueName='value', $selectedAttr='selected' ) {
  5283. if (!is_array( $selected )) {
  5284. $selected = array( $selected );
  5285. }
  5286. foreach ($source as $i => $row) {
  5287. if (is_object( $row )) {
  5288. $source[$i]->selected = in_array( $row->$valueName, $selected ) ? $selectedAttr . '="true"' : '';
  5289. } else {
  5290. $source[$i]['selected'] = in_array( $row[$valueName], $selected ) ? $selectedAttr . '="true"' : '';
  5291. }
  5292. }
  5293. }
  5294. /**
  5295. * Converts a named array to an array or named rows suitable to checkbox or radio lists
  5296. * @param array The source array[key] = value
  5297. * @param mixed A value or array of selected values
  5298. * @param string The name for the value field
  5299. */
  5300. function checkArray( &$source, $selected=null, $valueName='value' ) {
  5301. patHTML::selectArray( $source, $selected, $valueName, 'checked' );
  5302. }
  5303. /**
  5304. * @param mixed The value for the option
  5305. * @param string The text for the option
  5306. * @param string The name of the value parameter (default is value)
  5307. * @param string The name of the text parameter (default is text)
  5308. */
  5309. function makeOption( $value, $text, $valueName='value', $textName='text' ) {
  5310. return array(
  5311. $valueName => $value,
  5312. $textName => $text
  5313. );
  5314. }
  5315. /**
  5316. * Writes a radio pair
  5317. * @param object Template object
  5318. * @param string The template name
  5319. * @param string The field name
  5320. * @param int The value of the field
  5321. * @param array Array of options
  5322. * @param string Optional template variable name
  5323. */
  5324. function radioSet( &$tmpl, $template, $name, $value, $a, $varname=null ) {
  5325. patHTML::checkArray( $a, $value );
  5326. $tmpl->addVar( 'radio-set', 'name', $name );
  5327. $tmpl->addRows( 'radio-set', $a );
  5328. $tmpl->parseIntoVar( 'radio-set', $template, is_null( $varname ) ? $name : $varname );
  5329. }
  5330. /**
  5331. * Writes a radio pair
  5332. * @param object Template object
  5333. * @param string The template name
  5334. * @param string The field name
  5335. * @param int The value of the field
  5336. * @param string Optional template variable name
  5337. */
  5338. function yesNoRadio( &$tmpl, $template, $name, $value, $varname=null ) {
  5339. $a = array(
  5340. patHTML::makeOption( 0, 'No' ),
  5341. patHTML::makeOption( 1, 'Yes' )
  5342. );
  5343. patHTML::radioSet( $tmpl, $template, $name, $value, $a, $varname );
  5344. }
  5345. }
  5346. /**
  5347. * Provides a secure hash based on a seed
  5348. * @param string Seed string
  5349. * @return string
  5350. */
  5351. function mosHash( $seed ) {
  5352. return md5( $GLOBALS['mosConfig_secret'] . md5( $seed ) );
  5353. }
  5354. /**
  5355. * Format a backtrace error
  5356. * @since 1.0.5
  5357. */
  5358. function mosBackTrace() {
  5359. if (function_exists( 'debug_backtrace' )) {
  5360. echo '<div align="left">';
  5361. foreach( debug_backtrace() as $back) {
  5362. if (@$back['file']) {
  5363. echo '<br />' . str_replace( $GLOBALS['mosConfig_absolute_path'], '', $back['file'] ) . ':' . $back['line'];
  5364. }
  5365. }
  5366. echo '</div>';
  5367. }
  5368. }
  5369. function josSpoofCheck( $header=NULL, $alt=NULL , $method = 'post')
  5370. {
  5371. switch(strtolower($method)) {
  5372. case "get":
  5373. $validate = mosGetParam( $_GET, josSpoofValue($alt), 0 );
  5374. break;
  5375. case "request":
  5376. $validate = mosGetParam( $_REQUEST, josSpoofValue($alt), 0 );
  5377. break;
  5378. case "post":
  5379. default:
  5380. $validate = mosGetParam( $_POST, josSpoofValue($alt), 0 );
  5381. break;
  5382. }
  5383. // probably a spoofing attack
  5384. if (!$validate) {
  5385. header( 'HTTP/1.0 403 Forbidden' );
  5386. mosErrorAlert( _NOT_AUTH );
  5387. return;
  5388. }
  5389. // First, make sure the form was posted from a browser.
  5390. // For basic web-forms, we don't care about anything
  5391. // other than requests from a browser:
  5392. if (!isset( $_SERVER['HTTP_USER_AGENT'] )) {
  5393. header( 'HTTP/1.0 403 Forbidden' );
  5394. mosErrorAlert( _NOT_AUTH );
  5395. return;
  5396. }
  5397. // Make sure the form was indeed POST'ed:
  5398. // (requires your html form to use: action="post")
  5399. if (!$_SERVER['REQUEST_METHOD'] == 'POST' ) {
  5400. header( 'HTTP/1.0 403 Forbidden' );
  5401. mosErrorAlert( _NOT_AUTH );
  5402. return;
  5403. }
  5404. if ($header) {
  5405. // Attempt to defend against header injections:
  5406. $badStrings = array(
  5407. 'Content-Type:',
  5408. 'MIME-Version:',
  5409. 'Content-Transfer-Encoding:',
  5410. 'bcc:',
  5411. 'cc:'
  5412. );
  5413. // Loop through each POST'ed value and test if it contains
  5414. // one of the $badStrings:
  5415. _josSpoofCheck( $_POST, $badStrings );
  5416. }
  5417. }
  5418. function _josSpoofCheck( $array, $badStrings )
  5419. {
  5420. // Loop through each $array value and test if it contains
  5421. // one of the $badStrings
  5422. foreach( $array as $v ) {
  5423. if (is_array( $v )) {
  5424. _josSpoofCheck( $v, $badStrings );
  5425. } else {
  5426. foreach ( $badStrings as $v2 ) {
  5427. if ( stripos( $v, $v2 ) !== false ) {
  5428. header( 'HTTP/1.0 403 Forbidden' );
  5429. mosErrorAlert( _NOT_AUTH );
  5430. exit(); // mosErrorAlert dies anyway, double check just to make sure
  5431. }
  5432. }
  5433. }
  5434. }
  5435. }
  5436. /**
  5437. * Method to determine a hash for anti-spoofing variable names
  5438. *
  5439. * @return string Hashed var name
  5440. * @static
  5441. */
  5442. function josSpoofValue($alt=NULL)
  5443. {
  5444. global $mainframe, $my;
  5445. if ($alt) {
  5446. if ( $alt == 1 ) {
  5447. $random = date( 'Ymd' );
  5448. } else {
  5449. $random = $alt . date( 'Ymd' );
  5450. }
  5451. } else {
  5452. $random = date( 'dmY' );
  5453. }
  5454. // the prefix ensures that the hash is non-numeric
  5455. // otherwise it will be intercepted by globals.php
  5456. $validate = 'j' . mosHash( $mainframe->getCfg( 'db' ) . $random . $my->id );
  5457. return $validate;
  5458. }
  5459. /**
  5460. * A simple helper function to salt and hash a clear-text password.
  5461. *
  5462. * @since 1.0.13
  5463. * @param string $password A plain-text password
  5464. * @return string An md5 hashed password with salt
  5465. */
  5466. function josHashPassword($password)
  5467. {
  5468. // Salt and hash the password
  5469. $salt = mosMakePassword(16);
  5470. $crypt = md5($password.$salt);
  5471. $hash = $crypt.':'.$salt;
  5472. return $hash;
  5473. }
  5474. // ----- NO MORE CLASSES OR FUNCTIONS PASSED THIS POINT -----
  5475. // Post class declaration initialisations
  5476. // some version of PHP don't allow the instantiation of classes
  5477. // before they are defined
  5478. /** @global mosPlugin $_MAMBOTS */
  5479. $_MAMBOTS = new mosMambotHandler();
  5480. ?>