PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/filemanager/libraries/standalone.php

https://github.com/ibnoe/Microweber
PHP | 400 lines | 263 code | 36 blank | 101 comment | 60 complexity | 1f110023615960416156174fab3fc9d2 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: standalone.php 179 2011-01-04 12:15:17Z soeren $
  4. * @package eXtplorer
  5. * @copyright Copyright (C) 2007 Open Source Matters. All rights reserved.
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. // no direct access
  14. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  15. define( 'EXT_STANDALONE', 1 );
  16. if( defined( 'E_STRICT' ) ) { // Suppress Strict Standards Warnings
  17. error_reporting(E_ALL);
  18. }
  19. if (version_compare( phpversion(), '5.0' ) < 0) {
  20. require_once( dirname( __FILE__ ) . '/compat.php50x.php' );
  21. }
  22. require_once( dirname( __FILE__ ) .'/../include/users.php' );
  23. @set_magic_quotes_runtime( 0 );
  24. // platform neurtral url handling
  25. if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  26. $request_uri = $_SERVER['REQUEST_URI'];
  27. } else {
  28. $request_uri = $_SERVER['SCRIPT_NAME'];
  29. // Append the query string if it exists and isn't null
  30. if ( isset( $_SERVER['QUERY_STRING'] ) && !empty( $_SERVER['QUERY_STRING'] ) ) {
  31. $request_uri .= '?' . $_SERVER['QUERY_STRING'];
  32. }
  33. $_SERVER['REQUEST_URI'] = $request_uri;
  34. }
  35. if( empty( $_SERVER['PHP_SELF'])) {
  36. $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
  37. }
  38. // current server time
  39. $now = @date( 'Y-m-d H:i', time() );
  40. DEFINE( '_CURRENT_SERVER_TIME', $now );
  41. DEFINE( '_CURRENT_SERVER_TIME_FORMAT', '%Y-%m-%d %H:%M:%S' );
  42. /**
  43. * Joomla! Mainframe class
  44. *
  45. * Provide many supporting API functions
  46. * @package Joomla
  47. */
  48. class extMainFrame {
  49. /** @var array An array of page meta information */
  50. var $_head = null;
  51. var $_userstate = null;
  52. /**
  53. * Class constructor
  54. * @param database A database connection object
  55. * @param string The url option
  56. * @param string The path of the ext directory
  57. */
  58. function extMainFrame() {
  59. session_name( 'eXtplorer' );
  60. if( !@is_writable(ini_get('session.save_path')) && ini_get('session.save_handler') == 'files') {
  61. ini_set('session.save_path', realpath( dirname( __FILE__ ).'/../ftp_tmp') );
  62. }
  63. session_start();
  64. if( !isset( $_SESSION['_userstate'])) {
  65. $_SESSION['_userstate'] = array();
  66. $this->_userstate = $_SESSION['_userstate'];
  67. } else {
  68. $this->_userstate = $_SESSION['_userstate'];
  69. }
  70. $this->_head = array();
  71. $this->_head['title'] = 'eXtplorer';
  72. $this->_head['meta'] = array();
  73. $this->_head['custom'] = array();
  74. $now = date( 'Y-m-d H:i:s', time() );
  75. $this->set( 'now', $now );
  76. }
  77. /**
  78. * @param string
  79. */
  80. function setPageTitle( $title=null, $append=false ) {
  81. $title = trim( htmlspecialchars( $title ) );
  82. $title = stripslashes($title);
  83. if( $append ) {
  84. $this->_head['title'] .= ' - ' . $title;
  85. } else {
  86. $this->_head['title'] = $title.' - ' . $this->_head['title'];
  87. }
  88. }
  89. /**
  90. * @param string The value of the name attibute
  91. * @param string The value of the content attibute
  92. * @param string Text to display before the tag
  93. * @param string Text to display after the tag
  94. */
  95. function addMetaTag( $name, $content, $prepend='', $append='' ) {
  96. $name = trim( htmlspecialchars( $name ) );
  97. $content = trim( htmlspecialchars( $content ) );
  98. $prepend = trim( $prepend );
  99. $append = trim( $append );
  100. $this->_head['meta'][] = array( $name, $content, $prepend, $append );
  101. }
  102. /**
  103. * @param string The value of the name attibute
  104. * @param string The value of the content attibute to append to the existing
  105. * Tags ordered in with Site Keywords and Description first
  106. */
  107. function appendMetaTag( $name, $content ) {
  108. $name = trim( htmlspecialchars( $name ) );
  109. $n = count( $this->_head['meta'] );
  110. for ($i = 0; $i < $n; $i++) {
  111. if ($this->_head['meta'][$i][0] == $name) {
  112. $content = trim( htmlspecialchars( $content ) );
  113. if ( $content ) {
  114. if ( !$this->_head['meta'][$i][1] ) {
  115. $this->_head['meta'][$i][1] = $content ;
  116. } else {
  117. $this->_head['meta'][$i][1] = $content .', '. $this->_head['meta'][$i][1];
  118. }
  119. }
  120. return;
  121. }
  122. }
  123. $this->addMetaTag( $name , $content );
  124. }
  125. /**
  126. * @param string The value of the name attibute
  127. * @param string The value of the content attibute to append to the existing
  128. */
  129. function prependMetaTag( $name, $content ) {
  130. $name = trim( htmlspecialchars( $name ) );
  131. $n = count( $this->_head['meta'] );
  132. for ($i = 0; $i < $n; $i++) {
  133. if ($this->_head['meta'][$i][0] == $name) {
  134. $content = trim( htmlspecialchars( $content ) );
  135. $this->_head['meta'][$i][1] = $content . $this->_head['meta'][$i][1];
  136. return;
  137. }
  138. }
  139. $this->addMetaTag( $name, $content );
  140. }
  141. /**
  142. * Adds a custom html string to the head block
  143. * @param string The html to add to the head
  144. */
  145. function addCustomHeadTag( $html ) {
  146. $this->_head['custom'][] = trim( $html );
  147. }
  148. /**
  149. * @return string
  150. */
  151. function getHead() {
  152. $head = array();
  153. $head[] = '<title>' . $this->_head['title'] . '</title>';
  154. foreach ($this->_head['meta'] as $meta) {
  155. if ($meta[2]) {
  156. $head[] = $meta[2];
  157. }
  158. $head[] = '<meta name="' . $meta[0] . '" content="' . $meta[1] . '" />';
  159. if ($meta[3]) {
  160. $head[] = $meta[3];
  161. }
  162. }
  163. foreach ($this->_head['custom'] as $html) {
  164. $head[] = $html;
  165. }
  166. return implode( "\n", $head ) . "\n";
  167. }
  168. /**
  169. * @return string
  170. */
  171. function getPageTitle() {
  172. return $this->_head['title'];
  173. }
  174. /**
  175. * @return string
  176. */
  177. function getCustomPathWay() {
  178. return $this->_custom_pathway;
  179. }
  180. function appendPathWay( $html ) {
  181. $this->_custom_pathway[] = $html;
  182. }
  183. function getUserName() {
  184. return @$_SESSION['credentials_'.$GLOBALS['file_mode']]['username'];
  185. }
  186. function getPassword() {
  187. return @$_SESSION['credentials_'.$GLOBALS['file_mode']]['password'];
  188. }
  189. /**
  190. * Gets the value of a user state variable
  191. * @param string The name of the variable
  192. */
  193. function getUserState( $var_name ) {
  194. if (is_array( $this->_userstate )) {
  195. return extGetParam( $this->_userstate, $var_name, null );
  196. } else {
  197. return null;
  198. }
  199. }
  200. /**
  201. * Gets the value of a user state variable
  202. * @param string The name of the user state variable
  203. * @param string The name of the variable passed in a request
  204. * @param string The default value for the variable if not found
  205. */
  206. function getUserStateFromRequest( $var_name, $req_name, $var_default=null ) {
  207. if (is_array( $this->_userstate )) {
  208. if (isset( $_REQUEST[$req_name] )) {
  209. $this->setUserState( $var_name, $_REQUEST[$req_name] );
  210. } else if (!isset( $this->_userstate[$var_name] )) {
  211. $this->setUserState( $var_name, $var_default );
  212. }
  213. // filter input
  214. $iFilter = new InputFilter();
  215. $this->_userstate[$var_name] = $iFilter->process( $this->_userstate[$var_name] );
  216. return $this->_userstate[$var_name];
  217. } else {
  218. return null;
  219. }
  220. }
  221. /**
  222. * Sets the value of a user state variable
  223. * @param string The name of the variable
  224. * @param string The value of the variable
  225. */
  226. function setUserState( $var_name, $var_value ) {
  227. if (is_array( $this->_userstate )) {
  228. $this->_userstate[$var_name] = $var_value;
  229. $_SESSION['_userstate'] = $this->_userstate;
  230. }
  231. }
  232. /**
  233. * @param string The name of the property
  234. * @param mixed The value of the property to set
  235. */
  236. function set( $property, $value=null ) {
  237. $this->$property = $value;
  238. }
  239. /**
  240. * @param string The name of the property
  241. * @param mixed The default value
  242. * @return mixed The value of the property
  243. */
  244. function get($property, $default=null) {
  245. if(isset($this->$property)) {
  246. return $this->$property;
  247. } else {
  248. return $default;
  249. }
  250. }
  251. }
  252. /**
  253. * Initialise GZIP
  254. */
  255. function extInitGzip() {
  256. global $do_gzip_compress;
  257. if( $GLOBALS['use_gzip'] ) {
  258. $do_gzip_compress = FALSE;
  259. $phpver = phpversion();
  260. $useragent = extGetParam( $_SERVER, 'HTTP_USER_AGENT', '' );
  261. $canZip = extGetParam( $_SERVER, 'HTTP_ACCEPT_ENCODING', '' );
  262. $gzip_check = 0;
  263. $zlib_check = 0;
  264. $gz_check = 0;
  265. $zlibO_check = 0;
  266. $sid_check = 0;
  267. if ( strpos( $canZip, 'gzip' ) !== false) {
  268. $gzip_check = 1;
  269. }
  270. if ( extension_loaded( 'zlib' ) ) {
  271. $zlib_check = 1;
  272. }
  273. if ( function_exists('ob_gzhandler') ) {
  274. $gz_check = 1;
  275. }
  276. if ( ini_get('zlib.output_compression') ) {
  277. $zlibO_check = 1;
  278. }
  279. if ( ini_get('session.use_trans_sid') ) {
  280. $sid_check = 1;
  281. }
  282. if ( $phpver >= '4.0.4pl1' && ( strpos($useragent,'compatible') !== false || strpos($useragent,'Gecko') !== false ) ) {
  283. // Check for gzip header or northon internet securities or session.use_trans_sid
  284. if ( ( $gzip_check || isset( $_SERVER['---------------']) ) && $zlib_check && $gz_check && !$zlibO_check && !$sid_check ) {
  285. // You cannot specify additional output handlers if
  286. // zlib.output_compression is activated here
  287. ob_start( 'ob_gzhandler' );
  288. return;
  289. }
  290. } else if ( $phpver > '4.0' ) {
  291. if ( $gzip_check ) {
  292. if ( $zlib_check ) {
  293. $do_gzip_compress = TRUE;
  294. ob_start();
  295. ob_implicit_flush(0);
  296. header( 'Content-Encoding: gzip' );
  297. return;
  298. }
  299. }
  300. }
  301. }
  302. ob_start();
  303. }
  304. /**
  305. * Perform GZIP
  306. */
  307. function extDoGzip() {
  308. global $do_gzip_compress;
  309. if ( $do_gzip_compress ) {
  310. /**
  311. *Borrowed from php.net!
  312. */
  313. $gzip_contents = ob_get_contents();
  314. ob_end_clean();
  315. $gzip_size = strlen($gzip_contents);
  316. $gzip_crc = crc32($gzip_contents);
  317. $gzip_contents = gzcompress($gzip_contents, 9);
  318. $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
  319. echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
  320. echo $gzip_contents;
  321. echo pack('V', $gzip_crc);
  322. echo pack('V', $gzip_size);
  323. } else {
  324. ob_end_flush();
  325. }
  326. }
  327. /**
  328. * Replaces &amp; with & for xhtml compliance
  329. *
  330. * Needed to handle unicode conflicts due to unicode conflicts
  331. */
  332. function ampReplace( $text ) {
  333. $text = str_replace( '&&', '*--*', $text );
  334. $text = str_replace( '&#', '*-*', $text );
  335. $text = str_replace( '&amp;', '&', $text );
  336. $text = preg_replace( '|&(?![\w]+;)|', '&amp;', $text );
  337. $text = str_replace( '*-*', '&#', $text );
  338. $text = str_replace( '*--*', '&&', $text );
  339. return $text;
  340. }
  341. $mainframe = new extMainFrame();
  342. $mypath = realpath( dirname(__FILE__).'/..');
  343. $archive_name = $mypath.'/scripts.tar.gz';
  344. if( file_exists( $archive_name ) && !file_exists( $mypath .'/scripts/functions.js.php')) {
  345. require_once($mypath . "/include/functions.php");
  346. require_once($mypath . "/libraries/Archive/archive.php");
  347. ext_RaiseMemoryLimit( '16M' );
  348. error_reporting( E_ALL ^ E_NOTICE );
  349. $extract_dir = $mypath.'/';
  350. $result = extArchive::extract( $archive_name, $extract_dir );
  351. if( !PEAR::isError( $result )) {
  352. unlink( $archive_name );
  353. } else {
  354. die( '<html><head><title>eXtplorer - Error!</title></head>
  355. <body><h2>Installation needs to be completed!</h2>
  356. <p>To complete the eXtplorer Installation you need to extract the contents of the file <strong>scripts.zip</strong>
  357. (you can find this file in the extplorer package) and upload it to the subdirectory <strong>/scripts</strong> of your eXtplorer installation.
  358. <br/>
  359. Please just upload the contents of the extracted folder &quot;/scripts&quot; into the subdirectory <strong>/scripts</strong> and do not create a subdirectory like &quot;/scripts/scripts/&quot;.
  360. </p>
  361. </body></html>');
  362. }
  363. }
  364. ?>