From dad9738ee440ba43b0507ee26a75115b614dda88 Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Wed, 5 Jul 2017 21:36:02 +0200 Subject: [PATCH] prepare for inline mode, added support for empty config --- src/main.php | 69 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/src/main.php b/src/main.php index fb26042..2fc4147 100644 --- a/src/main.php +++ b/src/main.php @@ -24,16 +24,13 @@ class IFM { "auth" => 0,"auth_source" => 'inlineadmin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC', "root_dir" => "","defaulttimezone" => "Europe/Berlin","tmp_dir" => "","ajaxrequest" => 1 ); - private $config = array(); - public function __construct( $config ) { + private $config = array(); + public $mode = ""; + + public function __construct( $config=array() ) { session_start(); - if( ! is_array( $config ) ) { - trigger_error( "IFM: could not load config" ); - exit( 1 ); - } else { - $this->config = array_merge( $this->defaultconfig, $config ); - } + $this->config = array_merge( $this->defaultconfig, $config ); } /** @@ -46,14 +43,36 @@ class IFM { IFM - improved file manager - - - - - + '; + $this->getCSS(); + print ' -
+
'; + $this->getJS(); + print ' + + + '; + } + + public function getInlineApplication() { + $this->getCSS(); + print '
'; + $this->getJS(); + } + + private function getCSS() { + print ' + + + + + '; + } + + private function getJS() { + print ' @@ -62,8 +81,6 @@ class IFM { - - '; } @@ -85,7 +102,7 @@ class IFM { $this->getFiles( "" ); } elseif( $_REQUEST["api"] == "getConfig" ) { - echo json_encode( $this->config ); + $this->getConfig(); } elseif( $_REQUEST["api"] == "getTemplates" ) { echo json_encode( $this->getTemplates() ); } else { @@ -117,17 +134,20 @@ class IFM { } } - public function run() { + public function run( $mode="standalone" ) { if ( $this->checkAuth() ) { // go to our root_dir if( ! is_dir( realpath( $this->config['root_dir'] ) ) || ! is_readable( realpath( $this->config['root_dir'] ) ) ) die( "Cannot access root_dir."); else chdir( realpath( $this->config['root_dir'] ) ); - if ( ! isset($_REQUEST['api']) ) { - $this->getApplication(); - } else { + $this->mode = $mode; + if ( isset($_REQUEST['api']) ) { $this->handleRequest(); + } elseif( $mode == "standalone" ) { + $this->getApplication(); + } else { + $this->getInlineApplication(); } } } @@ -207,6 +227,13 @@ class IFM { echo json_encode( array_merge( $dirs, $files ) ); } + private function getConfig() { + $ret = $this->config; + $ret['inline'] = ( $this->mode == "inline" ) ? true : false; + $ret['isDocroot'] = ( realpath( IFMConfig::root_dir ) == dirname( __FILE__ ) ) ? "true" : "false"; + echo json_encode( $ret ); + } + private function getFolderTreeRecursive( $start_dir ) { $ret = array(); $start_dir = realpath( $start_dir );