diff --git a/components/editor/init.js b/components/editor/init.js index a064ffc..e9fc366 100755 --- a/components/editor/init.js +++ b/components/editor/init.js @@ -1368,7 +1368,8 @@ 400, 'components/editor/dialog.php?action=search&type=' + type, {}, - function( c ) { + ) + .then( function( c ) { let input = c.find( 'input:first' ); let textarea = c.find( 'textarea:first' ); diff --git a/components/filemanager/class.filemanager.php b/components/filemanager/class.filemanager.php index ec52b5c..1a54e51 100755 --- a/components/filemanager/class.filemanager.php +++ b/components/filemanager/class.filemanager.php @@ -68,6 +68,63 @@ class Filemanager extends Common { return $path; } + ////////////////////////////////////////////////////////////////// + // DUPLICATE (Creates a duplicate of the object - (cut/copy/paste) + ////////////////////////////////////////////////////////////////// + + public function copy( $source, $destination, $replace = false ) { + + $response = array( + "status" => "none", + "message" => null, + ); + + $source = self::formatPath( $source ); + $destination = self::formatPath( $destination ); + $new_destination = $destination; + $path_parts = pathinfo( $destination ); + $i = 1; + + if( ! $replace ) { + + do { + + if( is_dir( $new_destination ) ) { + + $new_destination = rtrim( $destination, "/" ) . " $i/"; + } elseif( is_file( $new_destination ) ) { + + if( isset( $path_parts["extension"] ) ) { + + $new_destination = str_replace( ".{$path_parts["extension"]}", " {$i}.{$path_parts["extension"]}", $destination ); + } else { + + $new_destination = $destination . " $i"; + } + } + $i++; + } while( ( is_file( $new_destination ) || is_dir( $new_destination ) ) ); + } + + if( file_exists( $source ) ) { + + if( is_file( $source ) ) { + + copy( $source, $new_destination ); + $response["status"] = "success"; + } else { + + self::recursive_copy( $source, $new_destination ); + $response["status"] = "success"; + } + } else { + + $response["status"] = "error"; + $response["message"] = "Invalid Source"; + } + return $response; + } + ////////////////////////////////////////////////////////////////// // CREATE (Creates a new file or directory) ////////////////////////////////////////////////////////////////// @@ -159,60 +216,6 @@ class Filemanager extends Common { return $response; } - ////////////////////////////////////////////////////////////////// - // DUPLICATE (Creates a duplicate of the object - (cut/copy/paste) - ////////////////////////////////////////////////////////////////// - - public function duplicate( $source, $destination ) { - - $response = array( - "status" => "none", - "message" => null, - ); - - $source = self::formatPath( $source ); - $destination = self::formatPath( $destination ); - $new_destination = $destination; - $path_parts = pathinfo( $destination ); - $i = 1; - - do { - - if( is_dir( $new_destination ) ) { - - $new_destination = rtrim( $destination, "/" ) . " $i/"; - } elseif( is_file( $new_destination ) ) { - - if( isset( $path_parts["extension"] ) ) { - - $new_destination = str_replace( ".{$path_parts["extension"]}", " {$i}.{$path_parts["extension"]}", $destination ); - } else { - - $new_destination = $destination . " $i"; - } - } - $i++; - } while( ( is_file( $new_destination ) || is_dir( $new_destination ) ) ); - - if( file_exists( $source ) ) { - - if( is_file( $source ) ) { - - copy( $source, $new_destination ); - $response["status"] = "success"; - } else { - - self::recursive_copy( $source, $new_destination ); - $response["status"] = "success"; - } - } else { - - $response["status"] = "error"; - $response["message"] = "Invalid Source"; - } - return $response; - } - public function find( $path, $query, $options = array() ) { $response = array( @@ -634,7 +637,7 @@ class Filemanager extends Common { if ( is_dir( $source . '/' . $file ) ) { - self::recurse_copy( $source . '/' . $file, $destination . '/' . $file ); + self::recursive_copy( $source . '/' . $file, $destination . '/' . $file ); } else { copy( $source . '/' . $file, $destination . '/' . $file ); @@ -729,6 +732,9 @@ class Filemanager extends Common { $response["status"] = "success"; $response["data"] = array(); $response["data"]["index"] = $return; + $response["data"]["cmd"] = $cmd; + $response["data"]["output"] = $output; + $response["data"]["output_array"] = $output_arr; } } return $response; diff --git a/components/filemanager/context_menu.json b/components/filemanager/context_menu.json index 6649195..356625c 100755 --- a/components/filemanager/context_menu.json +++ b/components/filemanager/context_menu.json @@ -81,7 +81,7 @@ "title": "Paste", "icon": "icon-docs", "applies-to" : "directory-only", - "onclick": "codiad.filemanager.pasteNode($('#context-menu').attr('data-path'));" + "onclick": "codiad.filemanager.paste_node($('#context-menu').attr('data-path'));" }, { "title": "Break", diff --git a/components/filemanager/controller.php b/components/filemanager/controller.php index 8f54ac9..2d82ca4 100755 --- a/components/filemanager/controller.php +++ b/components/filemanager/controller.php @@ -118,6 +118,19 @@ switch( $action ) { exit( $response ); break; + case( 'copy' ): + + if( isset( $_POST["replace"] ) ) { + + $replace = $_POST["replace"]; + } else { + + $replace = false; + } + + $response = $Filemanager->copy( $path, $destination, $replace ); + break; + case 'create': if( isset( $_GET["type"] ) ) { @@ -141,11 +154,6 @@ switch( $action ) { $response = $Filemanager->delete( $path, true, true ); break; - case 'duplicate': - - $response = $Filemanager->duplicate( $path, $destination ); - break; - case 'find': if( ! isset( $_GET["query"] ) ) { diff --git a/components/filemanager/dialog.php b/components/filemanager/dialog.php index de87003..6d94d82 100755 --- a/components/filemanager/dialog.php +++ b/components/filemanager/dialog.php @@ -101,12 +101,12 @@ switch( $_GET['action'] ) { break; ////////////////////////////////////////////////////////////////// - // Overwrite + // replace ////////////////////////////////////////////////////////////////// - case 'overwrite': + case 'replace': ?> - +