Initial rewrite of filemanager to allow for easier future customizations

This commit is contained in:
xevidos 2019-07-16 16:02:35 -04:00
parent 400618c0bb
commit 67674d41a7
4 changed files with 724 additions and 678 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,95 +1,230 @@
<?php
/*
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
* as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
/*
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
* as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
require_once('../../common.php');
require_once('class.filemanager.php');
require_once( '../../common.php' );
require_once( 'class.filemanager.php' );
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////
checkSession();
checkSession();
//////////////////////////////////////////////////////////////////
// Get Action
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// Get Action
//////////////////////////////////////////////////////////////////
$response = array(
"status" => "none",
);
if (!empty($_GET['action'])) {
$action = $_GET['action'];
$action = $_GET['action'];
} else {
exit('{"status":"error","data":{"error":"No Action Specified"}}');
$response["status"] = "error";
$response["data"] = array(
"error" => "No action specified"
);
exit( json_encode( $response ) );
}
//////////////////////////////////////////////////////////////////
// Ensure Project Has Been Loaded
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// Ensure Project Has Been Loaded
//////////////////////////////////////////////////////////////////
if (!isset($_SESSION['project'])) {
$_GET['action']='get_current';
$_GET['no_return']='true';
require_once('../project/controller.php');
}
//////////////////////////////////////////////////////////////////
// Security Check
//////////////////////////////////////////////////////////////////
if (!checkPath($_GET['path'])) {
die('{"status":"error","message":"Invalid Path"}');
if ( ! isset( $_SESSION['project'] ) ) {
$_GET['action'] = 'get_current';
$_GET['no_return'] = 'true';
require_once('../project/controller.php');
}
//////////////////////////////////////////////////////////////////
// Define Root
//////////////////////////////////////////////////////////////////
$_GET['root'] = WORKSPACE;
//////////////////////////////////////////////////////////////////
// Handle Action
//////////////////////////////////////////////////////////////////
$Filemanager = new Filemanager($_GET, $_POST, $_FILES);
$Filemanager->project = @$_SESSION['project']['path'];
switch ($action) {
case 'index':
$Filemanager->index();
break;
case 'search':
$Filemanager->search();
break;
case 'find':
$Filemanager->find();
break;
case 'open':
$Filemanager->open();
break;
case 'open_in_browser':
$Filemanager->openinbrowser();
break;
case 'create':
$Filemanager->create();
break;
case 'delete':
$Filemanager->delete();
break;
case 'deleteInner':
$Filemanager->delete( true );
break;
case 'modify':
$Filemanager->modify();
break;
case 'duplicate':
$Filemanager->duplicate();
break;
case 'upload':
$Filemanager->upload();
break;
default:
exit('{"status":"fail","data":{"error":"Unknown Action"}}');
if( isset( $_GET["path"] ) ) {
$path = $_GET["path"];
} else {
$response["status"] = "error";
$response["message"] = "Missing path.";
exit( json_encode( $response ) );
}
//////////////////////////////////////////////////////////////////
// Security Check
//////////////////////////////////////////////////////////////////
if ( ! checkPath( $path ) ) {
$response["status"] = "error";
$response["message"] = "Invalid Path";
exit( json_encode( $response ) );
}
if( isset( $_GET["destination"] ) ) {
$destination = $_GET["destination"];
if ( ! checkPath( $destination ) ) {
$response["status"] = "error";
$response["message"] = "Invalid destination";
exit( json_encode( $response ) );
}
}
//////////////////////////////////////////////////////////////////
// Handle Action
//////////////////////////////////////////////////////////////////
$Filemanager = new Filemanager();
switch( $action ) {
case 'create':
if( isset( $_GET["type"] ) ) {
$type = $_GET["type"];
$response = $Filemanager->create( $path, $type );
} else {
$response["status"] = "error";
$response["message"] = "No filetype set";
}
break;
case 'delete':
$response = $Filemanager->delete( $path, true );
break;
case 'deleteInner':
$response = $Filemanager->delete( $path, true, true );
break;
case 'duplicate':
$response = $Filemanager->duplicate( $path, $destination );
break;
case 'find':
if( ! isset( $_GET["query"] ) ) {
$response["status"] = "error";
$response["message"] = "Missing search query.";
} else {
$query = $_GET["query"];
if( isset( $_GET["options"] ) ) {
$options = $_GET["options"];
}
$response = $Filemanager->find( $path, $query, @$options );
}
break;
case 'index':
$response = $Filemanager->index( $path );
break;
case 'modify':
if( isset( $_POST["content"] ) || isset( $_POST["patch"] ) ) {
$content = isset( $_POST["content"] ) ? $_POST["content"] : "";
$patch = isset( $_POST["patch"] ) ? $_POST["patch"] : false;
$mtime = isset( $_POST["mtime"] ) ? $_POST["mtime"] : 0;
if( get_magic_quotes_gpc() ){
$content = stripslashes( $content );
$patch = stripslashes( $patch );
$mtime = stripslashes( $mtime );
}
$response = $Filemanager->modify( $path, $content, $mtime );
} else {
$response["status"] = "error";
$response["message"] = "Missing modification content";
}
break;
case 'move':
if( isset( $destination ) ) {
$response = $Filemanager->move( $path, $destination );
} else {
$response["status"] = "error";
$response["message"] = "Missing destination";
}
break;
case 'open':
$response = $Filemanager->open( $path );
break;
case 'open_in_browser':
$response = $Filemanager->openinbrowser( $path );
break;
case 'rename':
if( isset( $destination ) ) {
$response = $Filemanager->move( $path, $destination );
} else {
$response["status"] = "error";
$response["message"] = "Missing destination";
}
break;
case 'search':
if( isset( $_GET["query"] ) ) {
$query = $_GET["query"];
if( isset( $_GET["options"] ) ) {
$options = $_GET["options"];
}
$response = $Filemanager->search( $path, $query );
} else {
$response["status"] = "error";
$response["message"] = "Missing search query.";
}
break;
case 'upload':
$response = $Filemanager->upload( $path );
break;
default:
$response["status"] = "error";
$response["data"] = array(
"error" => "Unknown action"
);
break;
}
exit( json_encode( $response ) );

View File

@ -14,9 +14,7 @@ require_once('class.filemanager.php');
checkSession();
?>
<form>
<?php
?><form><?php
switch( $_GET['action'] ) {
@ -80,23 +78,25 @@ switch( $_GET['action'] ) {
case 'preview':
?>
<label><?php i18n("Inline Preview"); ?></label>
<div><br><br><img src="<?php echo(str_replace(BASE_PATH . "/", "", WORKSPACE) . "/" . $_GET['path']); ?>"><br><br></div>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Close"); ?></button>
<?php
break;
//////////////////////////////////////////////////////////////////
// Preview
//////////////////////////////////////////////////////////////////
case 'music_preview':
?>
<label><?php i18n("Inline Preview"); ?></label>
<div><br><br>
<audio controls>
<source src="<?php echo(str_replace(BASE_PATH . "/", "", WORKSPACE) . "/" . $_GET['path']); ?>">
</audio>
<br><br></div>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Close"); ?></button>
<div>
<?php
$source = str_replace( BASE_PATH . "/", "", WORKSPACE ) . "/" . $_GET['path'];
$type = mime_content_type( $source );
if( strpos( "audio", $type ) !== false ) {
?><audio controls><source src="<?php echo $source;?>"></audio><?php
} elseif( strpos( "image", $type ) !== false ) {
?><img src="<?php echo $source;?>"><?php
} else {
?><p>Error, unknown file type.</p><?php
}
?>
</div>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Close");?></button>
<?php
break;
@ -106,7 +106,6 @@ switch( $_GET['action'] ) {
case 'overwrite':
?>
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
<label><?php i18n("Would you like to overwrite or duplicate the following:"); ?></label>
<pre>
<?php
@ -168,5 +167,4 @@ switch( $_GET['action'] ) {
}
?>
</form>
?></form>

View File

@ -60,8 +60,6 @@
this.nodeListener();
this.auto_reload = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
console.log( this.auto_reload );
amplify.subscribe( 'settings.save', async function() {
let option = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
@ -717,7 +715,6 @@
} else if( path == this.clipboard ) {
codiad.message.error( i18n( 'Cannot Paste Directory Into Itself' ) );
} else {
let project = codiad.project.getCurrent();
var shortName = _this.getShortName( _this.clipboard );
if( $( '#file-manager a[data-path="' + path + '/' + shortName + '"]' )
.length ) { // Confirm overwrite?
@ -731,15 +728,13 @@
var duplicate = false;
if( $( '#modal-content form select[name="or_action"]' ).val() == 1 ) {
duplicate = true;
console.log( 'Dup!' );
//console.log( 'Dup!' );
}
_this.processPasteNode( path, duplicate );
});
} else { // No conflicts; proceed...
_this.processPasteNode( path, false );
}
codiad.filemanager.rescan( project );
}
},
@ -762,6 +757,7 @@
shortName: shortName,
duplicate: duplicate
});
codiad.filemanager.rescan( path );
}
});
},
@ -794,9 +790,9 @@
}
var newPath = temp.join( '/' ) + '/' + newName;
$.get( _this.controller, {
action: 'modify',
action: 'rename',
path: path,
new_name: newName
destination: newPath
}, function( data ) {
var renameResponse = codiad.jsend.parse( data );
let renamedMessage = "";