PageRenderTime 142ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

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

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