PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

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

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