Hello,

I have changed files/get_files.php and js/lib_files.js to use json.
Works fine for me, no problems with special chars.

You have to use "get-files-xml-error.patch" first, because I have
created the patches out of my clone.

Hope this helps.

Regards, schnere

diff --git a/files/get_files.php b/files/get_files.php
index 1481bb6..d3e53e7 100755
--- a/files/get_files.php
+++ b/files/get_files.php
@@ -53,9 +53,8 @@ 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);
+		//$data=utf8_encode($data);
+		$data=xmlentities($data);
 		if (is_string($name)) $attributes.=" $name='$data'";
 	}
 	$attributes.=' date=\''.date($CONFIG_DATEFORMAT,$file['mtime']).'\'';
@@ -64,46 +63,10 @@ if(is_array($files)){
 }
 echo "</dir>";
 
-// converts a UTF8-string into HTML entities
+// converts a UTF8-string into XML entities
 //  - $utf8:        the UTF8-string to convert
-//  - $encodeTags:  booloean. TRUE will convert "<" to "&lt;"
-//  - 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;
-}
+//  - return:       returns the converted XML-string
+function xmlentities($utf8) {
+   return str_replace ( array ( '&', '"', "'", '<', '>', '\'' ), array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;', '&apos;' ), $utf8 );
+} 
 ?>
\ No newline at end of file
diff --git a/files/get_files.php b/files/get_files.php
index d3e53e7..ed35778 100755
--- a/files/get_files.php
+++ b/files/get_files.php
@@ -38,8 +38,8 @@ function return_bytes($val) {
     return $val;
 }
 
-// header('Content-type: text/plain');
-header('Content-type: application/xml');
+header('Content-type: text/plain');
+//header('Content-type: application/xml');
 
 $dir=isset($_GET['dir'])?$_GET['dir']:'';
 $files=OC_FILES::getdirectorycontent($dir);
@@ -47,26 +47,23 @@ $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' 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=xmlentities($data);
-		if (is_string($name)) $attributes.=" $name='$data'";
-	}
-	$attributes.=' date=\''.date($CONFIG_DATEFORMAT,$file['mtime']).'\'';
-	echo "<file$attributes/>\n";
-	}
+
+$aDirectory = array(
+  "dir" => array("name" => $dirname, "max_upload" => $max_upload),
+  "files" => array()
+);
+
+if(is_array($files)) {
+  foreach($files as $file){
+    $aDirectory['files'][$file['name']] = array();
+
+    foreach($file as $name=>$data){
+      if (is_string($name)) $aDirectory['files'][$file['name']][$name] = $data;
+    }
+    
+    $aDirectory['files'][$file['name']]['date'] = date($CONFIG_DATEFORMAT,$file['mtime']);
+  }
 }
-echo "</dir>";
 
-// converts a UTF8-string into XML entities
-//  - $utf8:        the UTF8-string to convert
-//  - return:       returns the converted XML-string
-function xmlentities($utf8) {
-   return str_replace ( array ( '&', '"', "'", '<', '>', '\'' ), array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;', '&apos;' ), $utf8 );
-} 
+echo json_encode($aDirectory);
 ?>
\ No newline at end of file
diff --git a/js/lib_files.js b/js/lib_files.js
index 68c3c61..2c684e4 100755
--- a/js/lib_files.js
+++ b/js/lib_files.js
@@ -40,32 +40,37 @@ OC_FILES.cache.refresh=function(){
 OC_FILES.xmlloader=new OCXMLLoader();
 
 OC_FILES.getdirectorycontent_parse=function(req){
+	
 	var files=new Array();
-	var response=req.responseXML;
 	OC_FILES.cache.files=Array();
-	if(response){
-		var dir=response.getElementsByTagName('dir').item(0);
-		var fileElements=response.getElementsByTagName('file');
-		if(fileElements.length>0){
-			for(index=0;index<fileElements.length;index++){
-				var file=new Array();
-				var attributes=Array('size','name','type','directory','date','mime');
-				for(i in attributes){
-					var name=attributes[i];
-					file[name]=fileElements.item(index).getAttribute(name);
-				}
-				files[file.name]=file;
-			}
+	var responseText=req.responseText;
+	if(responseText) {
+		response = JSON.parse(responseText);
+		
+		var dir= (response.dir.name) ? response.dir.name : 'leer';
+		
+		for(filename in response.files) {
+
+			var file=new Array();
+			file['size']=response.files[filename].size;
+			file['name']=response.files[filename].name;
+			file['type']=response.files[filename].type;
+			file['directory']=response.files[filename].directory;
+			file['date']=response.files[filename].date;
+			file['mime']=response.files[filename].mime;
+			
+			files[response.files[filename].name] = file;
 		}
 		OC_FILES.cache.files=files;
 		if(OC_FILES.cache.incomplete[OC_FILES.dir]){
 			files=arrayMerge(files,OC_FILES.cache.incomplete[OC_FILES.dir]);
 		}
-		files['max_upload']=dir.getAttribute('max_upload');
+		files['max_upload']=response.dir.max_upload;
 		if(OC_FILES.getdirectorycontent_callback){
 			OC_FILES.getdirectorycontent_callback(files);
 		}
 	}
+	
 }
 
 OC_FILES.getdirectorycontent=function(dir,callback,refresh){
_______________________________________________
Owncloud mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/owncloud

Reply via email to