diff options
author | Henrik Kjölhede <hkjolhede@gmail.com> | 2013-01-26 21:51:18 +0100 |
---|---|---|
committer | Henrik Kjölhede <hkjolhede@gmail.com> | 2013-01-26 21:51:18 +0100 |
commit | b1b2eafa50db54b2613cf2bc52bfab2015d67b2f (patch) | |
tree | 68992916824e3bdd4c6ba9ab5af955420bfd8123 /apps/files/ajax | |
parent | a26d50640fc4a2524255c85b10fb010676b3e22d (diff) | |
parent | c9e25d3fab17b178759dd6d2f9488aa4cf37fbbb (diff) | |
download | nextcloud-server-b1b2eafa50db54b2613cf2bc52bfab2015d67b2f.tar.gz nextcloud-server-b1b2eafa50db54b2613cf2bc52bfab2015d67b2f.zip |
Merge remote-tracking branch 'upstream/master'
Conflicts:
apps/files_external/lib/config.php
Diffstat (limited to 'apps/files/ajax')
-rw-r--r-- | apps/files/ajax/autocomplete.php | 54 | ||||
-rw-r--r-- | apps/files/ajax/delete.php | 13 | ||||
-rw-r--r-- | apps/files/ajax/getstoragestats.php | 9 | ||||
-rw-r--r-- | apps/files/ajax/move.php | 5 | ||||
-rw-r--r-- | apps/files/ajax/rename.php | 8 | ||||
-rw-r--r-- | apps/files/ajax/scan.php | 3 | ||||
-rw-r--r-- | apps/files/ajax/upload.php | 71 |
7 files changed, 66 insertions, 97 deletions
diff --git a/apps/files/ajax/autocomplete.php b/apps/files/ajax/autocomplete.php deleted file mode 100644 index b32ba7c3d5b..00000000000 --- a/apps/files/ajax/autocomplete.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php -//provide auto completion of paths for use with jquer ui autocomplete - - -// Init owncloud - - -OCP\JSON::checkLoggedIn(); - -// Get data -$query = $_GET['term']; -$dirOnly=(isset($_GET['dironly']))?($_GET['dironly']=='true'):false; - -if($query[0]!='/') { - $query='/'.$query; -} - -if(substr($query, -1, 1)=='/') { - $base=$query; -} else { - $base=dirname($query); -} - -$query=substr($query, strlen($base)); - -if($base!='/') { - $query=substr($query, 1); -} -$queryLen=strlen($query); -$query=strtolower($query); - -// echo "$base - $query"; - -$files=array(); - -if(OC_Filesystem::file_exists($base) and OC_Filesystem::is_dir($base)) { - $dh = OC_Filesystem::opendir($base); - if($dh) { - if(substr($base, -1, 1)!='/') { - $base=$base.'/'; - } - while (($file = readdir($dh)) !== false) { - if ($file != "." && $file != "..") { - if(substr(strtolower($file), 0, $queryLen)==$query) { - $item=$base.$file; - if((!$dirOnly or OC_Filesystem::is_dir($item))) { - $files[]=(object)array('id'=>$item, 'label'=>$item, 'name'=>$item); - } - } - } - } - } -} -OCP\JSON::encodedPrint($files); diff --git a/apps/files/ajax/delete.php b/apps/files/ajax/delete.php index 6532b76df21..575b8c8d9ea 100644 --- a/apps/files/ajax/delete.php +++ b/apps/files/ajax/delete.php @@ -14,15 +14,18 @@ $files = json_decode($files); $filesWithError = ''; $success = true; //Now delete -foreach($files as $file) { - if( !OC_Files::delete( $dir, $file )) { +foreach ($files as $file) { + if (!OC_Files::delete($dir, $file)) { $filesWithError .= $file . "\n"; $success = false; } } -if($success) { - OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $files ))); +// get array with updated storage stats (e.g. max file size) after upload +$storageStats = \OCA\files\lib\Helper::buildFileStorageStatistics($dir); + +if ($success) { + OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats))); } else { - OCP\JSON::error(array("data" => array( "message" => "Could not delete:\n" . $filesWithError ))); + OCP\JSON::error(array("data" => array_merge(array("message" => "Could not delete:\n" . $filesWithError), $storageStats))); } diff --git a/apps/files/ajax/getstoragestats.php b/apps/files/ajax/getstoragestats.php new file mode 100644 index 00000000000..7a2b642a9bd --- /dev/null +++ b/apps/files/ajax/getstoragestats.php @@ -0,0 +1,9 @@ +<?php + +// only need filesystem apps +$RUNTIME_APPTYPES = array('filesystem'); + +OCP\JSON::checkLoggedIn(); + +// send back json +OCP\JSON::success(array('data' => \OCA\files\lib\Helper::buildFileStorageStatistics('/'))); diff --git a/apps/files/ajax/move.php b/apps/files/ajax/move.php index 5612716b7e4..4ebc3f42d9f 100644 --- a/apps/files/ajax/move.php +++ b/apps/files/ajax/move.php @@ -11,14 +11,15 @@ $dir = stripslashes($_GET["dir"]); $file = stripslashes($_GET["file"]); $target = stripslashes(rawurldecode($_GET["target"])); +$l=OC_L10N::get('files'); if(OC_Filesystem::file_exists($target . '/' . $file)) { - OCP\JSON::error(array("data" => array( "message" => "Could not move $file - File with this name already exists" ))); + OCP\JSON::error(array("data" => array( "message" => $l->t("Could not move %s - File with this name already exists", array($file)) ))); exit; } if(OC_Files::move($dir, $file, $target, $file)) { OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $file ))); } else { - OCP\JSON::error(array("data" => array( "message" => "Could not move $file" ))); + OCP\JSON::error(array("data" => array( "message" => $l->t("Could not move %s", array($file)) ))); } diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index 45448279fa1..89b4d4bba73 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -12,9 +12,9 @@ $file = stripslashes($_GET["file"]); $newname = stripslashes($_GET["newname"]); // Delete -if( OC_Files::move( $dir, $file, $dir, $newname )) { +if( $newname !== '.' and OC_Files::move( $dir, $file, $dir, $newname )) { 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 { + $l=OC_L10N::get('files'); + OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") ))); } diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php index 5cd9572d7f9..a819578e309 100644 --- a/apps/files/ajax/scan.php +++ b/apps/files/ajax/scan.php @@ -6,13 +6,14 @@ $force=isset($_GET['force']) and $_GET['force']=='true'; $dir=isset($_GET['dir'])?$_GET['dir']:''; $checkOnly=isset($_GET['checkonly']) and $_GET['checkonly']=='true'; +$eventSource=false; if(!$checkOnly) { $eventSource=new OC_EventSource(); } session_write_close(); -//create the file cache if necesary +//create the file cache if necessary if($force or !OC_FileCache::inCache('')) { if(!$checkOnly) { OCP\DB::beginTransaction(); diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index e7823bc4ffb..415524be629 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -8,64 +8,73 @@ OCP\JSON::setContentTypeHeader('text/plain'); OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); +$l = OC_L10N::get('files'); + +// get array with current storage stats (e.g. max file size) +$storageStats = \OCA\files\lib\Helper::buildFileStorageStatistics($dir); if (!isset($_FILES['files'])) { - OCP\JSON::error(array('data' => array( 'message' => 'No file was uploaded. Unknown error' ))); + OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('No file was uploaded. Unknown error')), $storageStats))); exit(); } + foreach ($_FILES['files']['error'] as $error) { if ($error != 0) { - $l=OC_L10N::get('files'); $errors = array( - UPLOAD_ERR_OK=>$l->t('There is no error, the file uploaded with success'), - UPLOAD_ERR_INI_SIZE=>$l->t('The uploaded file exceeds the upload_max_filesize directive in php.ini: ') - .ini_get('upload_max_filesize'), - UPLOAD_ERR_FORM_SIZE=>$l->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified' - .' in the HTML form'), - UPLOAD_ERR_PARTIAL=>$l->t('The uploaded file was only partially uploaded'), - UPLOAD_ERR_NO_FILE=>$l->t('No file was uploaded'), - UPLOAD_ERR_NO_TMP_DIR=>$l->t('Missing a temporary folder'), - UPLOAD_ERR_CANT_WRITE=>$l->t('Failed to write to disk'), + UPLOAD_ERR_OK => $l->t('There is no error, the file uploaded with success'), + UPLOAD_ERR_INI_SIZE => $l->t('The uploaded file exceeds the upload_max_filesize directive in php.ini: ') + . ini_get('upload_max_filesize'), + UPLOAD_ERR_FORM_SIZE => $l->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified' + . ' in the HTML form'), + UPLOAD_ERR_PARTIAL => $l->t('The uploaded file was only partially uploaded'), + UPLOAD_ERR_NO_FILE => $l->t('No file was uploaded'), + UPLOAD_ERR_NO_TMP_DIR => $l->t('Missing a temporary folder'), + UPLOAD_ERR_CANT_WRITE => $l->t('Failed to write to disk'), ); - OCP\JSON::error(array('data' => array( 'message' => $errors[$error] ))); + OCP\JSON::error(array('data' => array_merge(array('message' => $errors[$error]), $storageStats))); exit(); } } -$files=$_FILES['files']; +$files = $_FILES['files']; $dir = $_POST['dir']; -$error=''; +$error = ''; -$totalSize=0; -foreach($files['size'] as $size) { - $totalSize+=$size; +$totalSize = 0; +foreach ($files['size'] as $size) { + $totalSize += $size; } -if($totalSize>OC_Filesystem::free_space($dir)) { - OCP\JSON::error(array('data' => array( 'message' => 'Not enough space available' ))); +if ($totalSize > OC_Filesystem::free_space($dir)) { + OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Not enough storage available')), $storageStats))); exit(); } -$result=array(); -if(strpos($dir, '..') === false) { - $fileCount=count($files['name']); - for($i=0;$i<$fileCount;$i++) { +$result = array(); +if (strpos($dir, '..') === false) { + $fileCount = count($files['name']); + for ($i = 0; $i < $fileCount; $i++) { $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder $target = OC_Filesystem::normalizePath($target); - if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { + if (is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { $meta = OC_FileCache::get($target); $id = OC_FileCache::getId($target); - $result[]=array( 'status' => 'success', - 'mime'=>$meta['mimetype'], - 'size'=>$meta['size'], - 'id'=>$id, - 'name'=>basename($target)); + + // updated max file size after upload + $storageStats = \OCA\files\lib\Helper::buildFileStorageStatistics($dir); + + $result[] = array_merge(array('status' => 'success', + 'mime' => $meta['mimetype'], + 'size' => $meta['size'], + 'id' => $id, + 'name' => basename($target)), $storageStats + ); } } OCP\JSON::encodedPrint($result); exit(); } else { - $error='invalid dir'; + $error = $l->t('Invalid directory.'); } -OCP\JSON::error(array('data' => array('error' => $error, 'file' => $fileName))); +OCP\JSON::error(array('data' => array_merge(array('message' => $error), $storageStats))); |