diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-09-07 15:42:37 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-09-07 15:51:44 +0200 |
commit | 5eba5798274823fe3147a8d671ca5e15b3eb7843 (patch) | |
tree | eb9cfb3fc687b8be26dde07a08fd23ca3455991f /lib/files.php | |
parent | b483f2aab856e3324026588a9702043072fd7ad2 (diff) | |
parent | 3829460ab8cbb6de65c53583a20fd04cbe7927dd (diff) | |
download | nextcloud-server-5eba5798274823fe3147a8d671ca5e15b3eb7843.tar.gz nextcloud-server-5eba5798274823fe3147a8d671ca5e15b3eb7843.zip |
Merge branch 'master' into routing
Conflicts:
apps/files/js/fileactions.js
lib/base.php
lib/helper.php
lib/ocs.php
Diffstat (limited to 'lib/files.php')
-rw-r--r-- | lib/files.php | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/lib/files.php b/lib/files.php index 0c71f6e5e42..63dd96b9509 100644 --- a/lib/files.php +++ b/lib/files.php @@ -32,9 +32,9 @@ class OC_Files { * get the content of a directory * @param dir $directory path under datadirectory */ - public static function getDirectoryContent($directory, $mimetype_filter = ''){ + public static function getDirectoryContent($directory, $mimetype_filter = '') { $directory=OC_Filesystem::normalizePath($directory); - if($directory=='/'){ + if($directory=='/') { $directory=''; } $files = array(); @@ -56,7 +56,11 @@ class OC_Files { foreach ($files as &$file) { $file['directory'] = $directory; $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; - $permissions = OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE; + $permissions = OCP\Share::PERMISSION_READ; + // NOTE: Remove check when new encryption is merged + if (!$file['encrypted']) { + $permissions |= OCP\Share::PERMISSION_SHARE; + } if ($file['type'] == 'dir' && $file['writable']) { $permissions |= OCP\Share::PERMISSION_CREATE; } @@ -83,12 +87,12 @@ class OC_Files { * @param file $file ; seperated list of files to download * @param boolean $only_header ; boolean to only send header of the request */ - public static function get($dir,$files, $only_header = false){ - if(strpos($files,';')){ + public static function get($dir,$files, $only_header = false) { + if(strpos($files,';')) { $files=explode(';',$files); } - if(is_array($files)){ + if(is_array($files)) { self::validateZipDownload($dir,$files); $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); @@ -97,19 +101,19 @@ class OC_Files { if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } - foreach($files as $file){ + foreach($files as $file) { $file=$dir.'/'.$file; - if(OC_Filesystem::is_file($file)){ + if(OC_Filesystem::is_file($file)) { $tmpFile=OC_Filesystem::toTmpFile($file); self::$tmpFiles[]=$tmpFile; $zip->addFile($tmpFile,basename($file)); - }elseif(OC_Filesystem::is_dir($file)){ + }elseif(OC_Filesystem::is_dir($file)) { self::zipAddDir($file,$zip); } } $zip->close(); set_time_limit($executionTime); - }elseif(OC_Filesystem::is_dir($dir.'/'.$files)){ + }elseif(OC_Filesystem::is_dir($dir.'/'.$files)) { self::validateZipDownload($dir,$files); $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); @@ -127,18 +131,18 @@ class OC_Files { $filename=$dir.'/'.$files; } @ob_end_clean(); - if($zip or OC_Filesystem::is_readable($filename)){ + if($zip or OC_Filesystem::is_readable($filename)) { header('Content-Disposition: attachment; filename="'.basename($filename).'"'); header('Content-Transfer-Encoding: binary'); OC_Response::disableCaching(); - if($zip){ + if($zip) { ini_set('zlib.output_compression', 'off'); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($filename)); }else{ header('Content-Type: '.OC_Filesystem::getMimeType($filename)); } - }elseif($zip or !OC_Filesystem::file_exists($filename)){ + }elseif($zip or !OC_Filesystem::file_exists($filename)) { header("HTTP/1.0 404 Not Found"); $tmpl = new OC_Template( '', '404', 'guest' ); $tmpl->assign('file',$filename); @@ -147,12 +151,12 @@ class OC_Files { header("HTTP/1.0 403 Forbidden"); die('403 Forbidden'); } - if($only_header){ + if($only_header) { if(!$zip) header("Content-Length: ".OC_Filesystem::filesize($filename)); return ; } - if($zip){ + if($zip) { $handle=fopen($filename,'r'); if ($handle) { $chunkSize = 8*1024;// 1 MB chunks @@ -165,26 +169,26 @@ class OC_Files { }else{ OC_Filesystem::readfile($filename); } - foreach(self::$tmpFiles as $tmpFile){ - if(file_exists($tmpFile) and is_file($tmpFile)){ + foreach(self::$tmpFiles as $tmpFile) { + if(file_exists($tmpFile) and is_file($tmpFile)) { unlink($tmpFile); } } } - public static function zipAddDir($dir,$zip,$internalDir=''){ + public static function zipAddDir($dir,$zip,$internalDir='') { $dirname=basename($dir); $zip->addEmptyDir($internalDir.$dirname); $internalDir.=$dirname.='/'; $files=OC_Files::getdirectorycontent($dir); - foreach($files as $file){ + foreach($files as $file) { $filename=$file['name']; $file=$dir.'/'.$filename; - if(OC_Filesystem::is_file($file)){ + if(OC_Filesystem::is_file($file)) { $tmpFile=OC_Filesystem::toTmpFile($file); OC_Files::$tmpFiles[]=$tmpFile; $zip->addFile($tmpFile,$internalDir.$filename); - }elseif(OC_Filesystem::is_dir($file)){ + }elseif(OC_Filesystem::is_dir($file)) { self::zipAddDir($file,$zip,$internalDir); } } @@ -197,8 +201,8 @@ class OC_Files { * @param dir $targetDir * @param file $target */ - public static function move($sourceDir,$source,$targetDir,$target){ - if(OC_User::isLoggedIn() && ($sourceDir != '' || $source != 'Shared') && !OC_Filesystem::file_exists($targetDir.'/'.$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_Filesystem::rename($sourceFile,$targetFile); @@ -215,8 +219,8 @@ class OC_Files { * @param dir $targetDir * @param file $target */ - public static function copy($sourceDir,$source,$targetDir,$target){ - if(OC_User::isLoggedIn()){ + public static function copy($sourceDir,$source,$targetDir,$target) { + if(OC_User::isLoggedIn()) { $targetFile=$targetDir.'/'.$target; $sourceFile=$sourceDir.'/'.$source; return OC_Filesystem::copy($sourceFile,$targetFile); @@ -230,14 +234,14 @@ class OC_Files { * @param file $name * @param type $type */ - public static function newFile($dir,$name,$type){ - if(OC_User::isLoggedIn()){ + public static function newFile($dir,$name,$type) { + if(OC_User::isLoggedIn()) { $file=$dir.'/'.$name; - if($type=='dir'){ + if($type=='dir') { return OC_Filesystem::mkdir($file); - }elseif($type=='file'){ + }elseif($type=='file') { $fileHandle=OC_Filesystem::fopen($file, 'w'); - if($fileHandle){ + if($fileHandle) { fclose($fileHandle); return true; }else{ @@ -253,7 +257,7 @@ class OC_Files { * @param dir $dir * @param file $name */ - public static function delete($dir,$file){ + public static function delete($dir,$file) { if(OC_User::isLoggedIn() && ($dir!= '' || $file != 'Shared')) { $file=$dir.'/'.$file; return OC_Filesystem::unlink($file); @@ -268,7 +272,7 @@ class OC_Files { */ static function validateZipDownload($dir, $files) { if(!OC_Config::getValue('allowZipDownload', true)) { - $l = OC_L10N::get('files'); + $l = OC_L10N::get('lib'); header("HTTP/1.0 409 Conflict"); $tmpl = new OC_Template( '', 'error', 'user' ); $errors = array( @@ -285,15 +289,15 @@ class OC_Files { $zipLimit = OC_Config::getValue('maxZipInputSize', OC_Helper::computerFileSize('800 MB')); if($zipLimit > 0) { $totalsize = 0; - if(is_array($files)){ - foreach($files as $file){ + if(is_array($files)) { + foreach($files as $file) { $totalsize += OC_Filesystem::filesize($dir.'/'.$file); } }else{ $totalsize += OC_Filesystem::filesize($dir.'/'.$files); } if($totalsize > $zipLimit) { - $l = OC_L10N::get('files'); + $l = OC_L10N::get('lib'); header("HTTP/1.0 409 Conflict"); $tmpl = new OC_Template( '', 'error', 'user' ); $errors = array( @@ -315,7 +319,7 @@ class OC_Files { * @param string path * @return string guessed mime type */ - static function getMimeType($path){ + static function getMimeType($path) { return OC_Filesystem::getMimeType($path); } @@ -325,7 +329,7 @@ class OC_Files { * @param string path * @return array */ - static function getTree($path){ + static function getTree($path) { return OC_Filesystem::getTree($path); } @@ -337,7 +341,7 @@ class OC_Files { * @param string file * @return string guessed mime type */ - static function pull($source,$token,$dir,$file){ + static function pull($source,$token,$dir,$file) { $tmpfile=tempnam(get_temp_dir(),'remoteCloudFile'); $fp=fopen($tmpfile,'w+'); $url=$source.="/files/pull.php?token=$token"; @@ -349,7 +353,7 @@ class OC_Files { $info=curl_getinfo($ch); $httpCode=$info['http_code']; curl_close($ch); - if($httpCode==200 or $httpCode==0){ + if($httpCode==200 or $httpCode==0) { OC_Filesystem::fromTmpFile($tmpfile,$dir.'/'.$file); return true; }else{ @@ -362,7 +366,7 @@ class OC_Files { * @param int size filesisze in bytes * @return false on failure, size on success */ - static function setUploadLimit($size){ + static function setUploadLimit($size) { //don't allow user to break his config -- upper boundary if($size > PHP_INT_MAX) { //max size is always 1 byte lower than computerFileSize returns @@ -417,10 +421,10 @@ class OC_Files { * @param string $path * @return string */ - static public function normalizePath($path){ + static public function normalizePath($path) { $path='/'.$path; $old=''; - while($old!=$path){//replace any multiplicity of slashes with a single one + while($old!=$path) {//replace any multiplicity of slashes with a single one $old=$path; $path=str_replace('//','/',$path); } @@ -428,10 +432,10 @@ class OC_Files { } } -function fileCmp($a,$b){ - if($a['type']=='dir' and $b['type']!='dir'){ +function fileCmp($a,$b) { + if($a['type']=='dir' and $b['type']!='dir') { return -1; - }elseif($a['type']!='dir' and $b['type']=='dir'){ + }elseif($a['type']!='dir' and $b['type']=='dir') { return 1; }else{ return strnatcasecmp($a['name'],$b['name']); |