mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
cleanup OC_Files a bit
This commit is contained in:
parent
7b150dfa96
commit
5a3d6805a2
6 changed files with 34 additions and 156 deletions
|
|
@ -12,17 +12,22 @@ $files = isset($_POST["file"]) ? stripslashes($_POST["file"]) : stripslashes($_P
|
|||
|
||||
$files = explode(';', $files);
|
||||
$filesWithError = '';
|
||||
$success = true;
|
||||
//Now delete
|
||||
foreach($files as $file) {
|
||||
if( !OC_Files::delete( $dir, $file )) {
|
||||
$filesWithError .= $file . "\n";
|
||||
$success = false;
|
||||
if (OC_User::isLoggedIn()) {
|
||||
$success = true;
|
||||
|
||||
//Now delete
|
||||
foreach ($files as $file) {
|
||||
if ($dir != '' || $file != 'Shared' && !\OC\Files\Filesystem::unlink($dir . '/' . $file)) {
|
||||
$filesWithError .= $file . "\n";
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$success = false;
|
||||
}
|
||||
|
||||
if($success) {
|
||||
OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $files )));
|
||||
if ($success) {
|
||||
OCP\JSON::success(array("data" => array("dir" => $dir, "files" => $files)));
|
||||
} else {
|
||||
OCP\JSON::error(array("data" => array( "message" => "Could not delete:\n" . $filesWithError )));
|
||||
OCP\JSON::error(array("data" => array("message" => "Could not delete:\n" . $filesWithError)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,14 @@ $dir = stripslashes($_GET["dir"]);
|
|||
$file = stripslashes($_GET["file"]);
|
||||
$target = stripslashes($_GET["target"]);
|
||||
|
||||
|
||||
if(OC_Files::move($dir, $file, $target, $file)) {
|
||||
OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $file )));
|
||||
} else {
|
||||
if (OC_User::isLoggedIn() && ($dir != '' || $file != 'Shared')) {
|
||||
$targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
|
||||
$sourceFile = \OC\Files\Filesystem::normalizePath($target . '/' . $file);
|
||||
if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
|
||||
OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $file )));
|
||||
} else {
|
||||
OCP\JSON::error(array("data" => array( "message" => "Could not move $file" )));
|
||||
}
|
||||
}else{
|
||||
OCP\JSON::error(array("data" => array( "message" => "Could not move $file" )));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ if($source) {
|
|||
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
|
||||
exit();
|
||||
}
|
||||
}elseif(OC_Files::newFile($dir, $filename, 'file')) {
|
||||
}elseif(\OC\Files\Filesystem::touch($dir . '/' . $filename)) {
|
||||
$meta = OC_FileCache::get($dir.'/'.$filename);
|
||||
$id = OC_FileCache::getId($dir.'/'.$filename);
|
||||
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ if(strpos($foldername, '/')!==false) {
|
|||
exit();
|
||||
}
|
||||
|
||||
if(OC_Files::newFile($dir, stripslashes($foldername), 'dir')) {
|
||||
if(\OC\Files\Filesystem::mkdir($dir . '/' . stripslashes($foldername))) {
|
||||
if ( $dir != '/') {
|
||||
$path = $dir.'/'.$foldername;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,10 +11,14 @@ $dir = stripslashes($_GET["dir"]);
|
|||
$file = stripslashes($_GET["file"]);
|
||||
$newname = stripslashes($_GET["newname"]);
|
||||
|
||||
// Delete
|
||||
if( OC_Files::move( $dir, $file, $dir, $newname )) {
|
||||
OCP\JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname )));
|
||||
}
|
||||
else{
|
||||
if (OC_User::isLoggedIn() && ($dir != '' || $file != 'Shared')) {
|
||||
$targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
|
||||
$sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
|
||||
if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
|
||||
OCP\JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname )));
|
||||
} else {
|
||||
OCP\JSON::error(array("data" => array( "message" => "Unable to rename file" )));
|
||||
}
|
||||
}else{
|
||||
OCP\JSON::error(array("data" => array( "message" => "Unable to rename file" )));
|
||||
}
|
||||
|
|
|
|||
136
lib/files.php
136
lib/files.php
|
|
@ -252,77 +252,6 @@ class OC_Files {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* move a file or folder
|
||||
*
|
||||
* @param dir $sourceDir
|
||||
* @param file $source
|
||||
* @param dir $targetDir
|
||||
* @param file $target
|
||||
*/
|
||||
public static function move($sourceDir, $source, $targetDir, $target) {
|
||||
if (OC_User::isLoggedIn() && ($sourceDir != '' || $source != 'Shared')) {
|
||||
$targetFile = self::normalizePath($targetDir . '/' . $target);
|
||||
$sourceFile = self::normalizePath($sourceDir . '/' . $source);
|
||||
return \OC\Files\Filesystem::rename($sourceFile, $targetFile);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* copy a file or folder
|
||||
*
|
||||
* @param dir $sourceDir
|
||||
* @param file $source
|
||||
* @param dir $targetDir
|
||||
* @param file $target
|
||||
*/
|
||||
public static function copy($sourceDir, $source, $targetDir, $target) {
|
||||
if (OC_User::isLoggedIn()) {
|
||||
$targetFile = $targetDir . '/' . $target;
|
||||
$sourceFile = $sourceDir . '/' . $source;
|
||||
return \OC\Files\Filesystem::copy($sourceFile, $targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new file or folder
|
||||
*
|
||||
* @param dir $dir
|
||||
* @param file $name
|
||||
* @param type $type
|
||||
*/
|
||||
public static function newFile($dir, $name, $type) {
|
||||
if (OC_User::isLoggedIn()) {
|
||||
$file = $dir . '/' . $name;
|
||||
if ($type == 'dir') {
|
||||
return \OC\Files\Filesystem::mkdir($file);
|
||||
} elseif ($type == 'file') {
|
||||
$fileHandle = \OC\Files\Filesystem::fopen($file, 'w');
|
||||
if ($fileHandle) {
|
||||
fclose($fileHandle);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes a file or folder
|
||||
*
|
||||
* @param dir $dir
|
||||
* @param file $name
|
||||
*/
|
||||
public static function delete($dir, $file) {
|
||||
if (OC_User::isLoggedIn() && ($dir != '' || $file != 'Shared')) {
|
||||
$file = $dir . '/' . $file;
|
||||
return \OC\Files\Filesystem::unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the selected files are within the size constraint. If not, outputs an error page.
|
||||
*
|
||||
|
|
@ -372,55 +301,6 @@ class OC_Files {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* try to detect the mime type of a file
|
||||
*
|
||||
* @param string path
|
||||
* @return string guessed mime type
|
||||
*/
|
||||
static function getMimeType($path) {
|
||||
return \OC\Files\Filesystem::getMimeType($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* get a file tree
|
||||
*
|
||||
* @param string path
|
||||
* @return array
|
||||
*/
|
||||
static function getTree($path) {
|
||||
return \OC\Files\Filesystem::getTree($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* pull a file from a remote server
|
||||
*
|
||||
* @param string source
|
||||
* @param string token
|
||||
* @param string dir
|
||||
* @param string file
|
||||
* @return string guessed mime type
|
||||
*/
|
||||
static function pull($source, $token, $dir, $file) {
|
||||
$tmpfile = tempnam(get_temp_dir(), 'remoteCloudFile');
|
||||
$fp = fopen($tmpfile, 'w+');
|
||||
$url = $source .= "/files/pull.php?token=$token";
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
curl_exec($ch);
|
||||
fclose($fp);
|
||||
$info = curl_getinfo($ch);
|
||||
$httpCode = $info['http_code'];
|
||||
curl_close($ch);
|
||||
if ($httpCode == 200 or $httpCode == 0) {
|
||||
\OC\Files\Filesystem::fromTmpFile($tmpfile, $dir . '/' . $file);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set the maximum upload size limit for apache hosts using .htaccess
|
||||
*
|
||||
|
|
@ -478,22 +358,6 @@ class OC_Files {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* normalize a path, removing any double, add leading /, etc
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
static public function normalizePath($path) {
|
||||
$path = '/' . $path;
|
||||
$old = '';
|
||||
while ($old != $path) { //replace any multiplicity of slashes with a single one
|
||||
$old = $path;
|
||||
$path = str_replace('//', '/', $path);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
function fileCmp($a, $b) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue