diff options
author | Robin <robin@Amaya.(none)> | 2010-04-25 14:21:04 +0200 |
---|---|---|
committer | Robin <robin@Amaya.(none)> | 2010-04-25 14:21:04 +0200 |
commit | c2bdd6134be53dcf822632192af10cf3cf80be1e (patch) | |
tree | ea6e177f18584e873abd3ec816e2da130ec985c0 /files | |
parent | 76eeaaea01868a3777a66d9f5591b414539cff77 (diff) | |
download | nextcloud-server-c2bdd6134be53dcf822632192af10cf3cf80be1e.tar.gz nextcloud-server-c2bdd6134be53dcf822632192af10cf3cf80be1e.zip |
some cleanup/refactoring
Diffstat (limited to 'files')
-rw-r--r-- | files/api.php (renamed from files/delete.php) | 31 | ||||
-rw-r--r-- | files/get_file.php | 108 | ||||
-rw-r--r-- | files/get_files.php | 49 | ||||
-rw-r--r-- | files/move.php | 35 | ||||
-rw-r--r-- | files/new.php | 38 | ||||
-rw-r--r-- | files/rename.php | 34 |
6 files changed, 69 insertions, 226 deletions
diff --git a/files/delete.php b/files/api.php index 7d19a45a73a..5a4c8801d4e 100644 --- a/files/delete.php +++ b/files/api.php @@ -22,15 +22,28 @@ */ require_once('../inc/lib_base.php'); -$dir=$_GET['dir']; -$file=$_GET['file']; -if(isset($_SESSION['username']) and $_SESSION['username'] and strpos($dir,'..')===false){ - $file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$file; - if(is_file($file)){ - unlink($file); - }elseif(is_dir($file)){ - rmdir($file); - } +$arguments=$_POST; + +foreach($arguments as &$argument){ + $argument=stripslashes($argument); +} +ob_clean(); +switch($arguments['action']){ + case 'delete': + OC_FILES::delete($arguments['dir'],$arguments['file']); + break; + case 'rename': + OC_FILES::move($arguments['dir'],$arguments['file'],$arguments['dir'],$arguments['newname']); + break; + case 'new': + OC_FILES::newfile($arguments['dir'],$arguments['name'],$arguments['type']); + break; + case 'move': + OC_FILES::move($arguments['sourcedir'],$arguments['source'],$arguments['targetdir'],$arguments['target']); + break; + case 'get': + OC_FILES::get($arguments['dir'],$arguments['file']); + break; } ?>
\ No newline at end of file diff --git a/files/get_file.php b/files/get_file.php deleted file mode 100644 index 9ec539ee7e0..00000000000 --- a/files/get_file.php +++ /dev/null @@ -1,108 +0,0 @@ -<?php -/** -* ownCloud - ajax frontend -* -* @author Robin Appelman -* @copyright 2010 Robin Appelman icewind1991@gmail.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -//note this file is for getting files themselves, get_files.php is for getting a list of files. - -require_once('../inc/lib_base.php'); - -if(!function_exists('sys_get_temp_dir')) { - function sys_get_temp_dir() { - if( $temp=getenv('TMP') ) return $temp; - if( $temp=getenv('TEMP') ) return $temp; - if( $temp=getenv('TMPDIR') ) return $temp; - $temp=tempnam(__FILE__,''); - if (file_exists($temp)) { - unlink($temp); - return dirname($temp); - } - return null; - } -} - -function addDir($dir,$zip,$internalDir=''){ - $dirname=basename($dir); - $zip->addEmptyDir($internalDir.$dirname); - $internalDir.=$dirname.='/'; - $files=OC_FILES::getdirectorycontent($dir); - foreach($files as $file){ - $filename=$file['name']; - $file=$dir.'/'.$filename; - if(is_file($file)){ - $zip->addFile($file,$internalDir.$filename); - }elseif(is_dir($file)){ - addDir($file,$zip,$internalDir); - } - } -} - -$files=$_GET['files']; -$dir=(isset($_GET['dir']))?$_GET['dir']:''; -if(strstr($files,'..') or strstr($dir,'..')){ - die(); -} -if(strpos($files,',')){ - $files=explode(',',$files); -} - - -if(is_array($files)){ - $zip = new ZipArchive(); - $filename = sys_get_temp_dir()."/ownCloud.zip"; - if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { - exit("cannot open <$filename>\n"); - } - foreach($files as $file){ - $file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$file; - if(is_file($file)){ - $zip->addFile($file,basename($file)); - }elseif(is_dir($file)){ - addDir($file,$zip); - } - } - $zip->close(); -}elseif(is_dir($CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files)){ - $zip = new ZipArchive(); - $filename = sys_get_temp_dir()."/ownCloud.zip"; - if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { - exit("cannot open <$filename>\n"); - } - $file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files; - addDir($file,$zip); - $zip->close(); -}else{ - $zip=false; - $filename=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files; -} -header('Content-Description: File Transfer'); -header('Content-Type: application/octet-stream'); -header('Content-Disposition: attachment; filename='.basename($filename)); -header('Content-Transfer-Encoding: binary'); -header('Expires: 0'); -header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); -header('Pragma: public'); -header('Content-Length: ' . filesize($filename)); -ob_end_clean(); -readfile($filename); -if($zip){ - unlink($filename); -} -?>
\ No newline at end of file diff --git a/files/get_files.php b/files/get_files.php index 287b8cd453e..21866dbf636 100644 --- a/files/get_files.php +++ b/files/get_files.php @@ -47,12 +47,14 @@ $dirname=(isset($files[0]))?$files[0]['directory']:''; $dirname=substr($dirname,strrpos($dirname,'/')); $max_upload=min(return_bytes(ini_get('post_max_size')),return_bytes(ini_get('upload_max_filesize'))); ob_clean(); -echo "<?xml version='1.0' standalone='yes'?>\n"; +echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n"; echo "<dir name='$dirname' max_upload='$max_upload'>\n"; if(is_array($files)){ foreach($files as $file){ $attributes=''; foreach($file as $name=>$data){ + $data=utf8_encode($data); + $data=utf8tohtml($data); $data=str_replace("'",''',$data); if (is_string($name)) $attributes.=" $name='$data'"; } @@ -60,5 +62,48 @@ if(is_array($files)){ echo "<file$attributes/>\n"; } } -echo "\n</dir>"; +echo "</dir>"; + +// converts a UTF8-string into HTML entities +// - $utf8: the UTF8-string to convert +// - $encodeTags: booloean. TRUE will convert "<" to "<" +// - return: returns the converted HTML-string +function utf8tohtml($utf8, $encodeTags=true) { + $result = ''; + for ($i = 0; $i < strlen($utf8); $i++) { + $char = $utf8[$i]; + $ascii = ord($char); + if ($ascii < 128) { + // one-byte character + $result .= ($encodeTags) ? htmlentities($char) : $char; + } else if ($ascii < 192) { + // non-utf8 character or not a start byte + } else if ($ascii < 224) { + // two-byte character + $result .= htmlentities(substr($utf8, $i, 2), ENT_QUOTES, 'UTF-8'); + $i++; + } else if ($ascii < 240) { + // three-byte character + $ascii1 = ord($utf8[$i+1]); + $ascii2 = ord($utf8[$i+2]); + $unicode = (15 & $ascii) * 4096 + + (63 & $ascii1) * 64 + + (63 & $ascii2); + $result .= "&#$unicode;"; + $i += 2; + } else if ($ascii < 248) { + // four-byte character + $ascii1 = ord($utf8[$i+1]); + $ascii2 = ord($utf8[$i+2]); + $ascii3 = ord($utf8[$i+3]); + $unicode = (15 & $ascii) * 262144 + + (63 & $ascii1) * 4096 + + (63 & $ascii2) * 64 + + (63 & $ascii3); + $result .= "&#$unicode;"; + $i += 3; + } + } + return $result; +} ?>
\ No newline at end of file diff --git a/files/move.php b/files/move.php deleted file mode 100644 index 7103662c4a2..00000000000 --- a/files/move.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -/** -* ownCloud - ajax frontend -* -* @author Robin Appelman -* @copyright 2010 Robin Appelman icewind1991@gmail.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ -require_once('../inc/lib_base.php'); - -$sourceDir=$_GET['sourcedir']; -$targetDir=$_GET['targetdir']; -$source=$_GET['source']; -$target=$_GET['target']; -if(isset($_SESSION['username']) and $_SESSION['username'] and strpos($sourceDir,'..')===false and strpos($source,'..')===false and strpos($targetDir,'..')===false and strpos($target,'..')===false){ - $target=$CONFIG_DATADIRECTORY.'/'.$targetDir.'/'.$target.'/'.$source; - $source=$CONFIG_DATADIRECTORY.'/'.$sourceDir.'/'.$source; - rename($source,$target); -} - -?>
\ No newline at end of file diff --git a/files/new.php b/files/new.php deleted file mode 100644 index c5d5608a567..00000000000 --- a/files/new.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -/** -* ownCloud - ajax frontend -* -* @author Robin Appelman -* @copyright 2010 Robin Appelman icewind1991@gmail.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ -require_once('../inc/lib_base.php'); - -$dir=$_GET['dir']; -$name=$_GET['name']; -$type=$_GET['type']; -if(isset($_SESSION['username']) and $_SESSION['username'] and strpos($dir,'..')===false and strpos($name,'..')===false){ - $file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$name; - if($type=='dir'){ - mkdir($file); - }elseif($type=='file'){ - $fileHandle=fopen($file, 'w') or die("can't open file"); - fclose($fileHandle); - } -} - -?>
\ No newline at end of file diff --git a/files/rename.php b/files/rename.php deleted file mode 100644 index f0f272f018f..00000000000 --- a/files/rename.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -/** -* ownCloud - ajax frontend -* -* @author Robin Appelman -* @copyright 2010 Robin Appelman icewind1991@gmail.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ -require_once('../inc/lib_base.php'); - -$dir=$_GET['dir']; -$file=$_GET['file']; -$newname=$_GET['newname']; -if($file!=$newname and $newname!='' and isset($_SESSION['username']) and $_SESSION['username'] and strpos($dir,'..')===false){ - $source=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$file; - $target=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$newname; - rename($source,$target); -} - -?>
\ No newline at end of file |