You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.5 KiB

16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. <?php
  2. /**
  3. * ownCloud - ajax frontend
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2010 Robin Appelman icewind1991@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. require_once('../inc/lib_base.php');
  23. function return_bytes($val) {
  24. $val = trim($val);
  25. $last = strtolower($val[strlen($val)-1]);
  26. switch($last) {
  27. // The 'G' modifier is available since PHP 5.1.0
  28. case 'g':
  29. $val *= 1024;
  30. case 'm':
  31. $val *= 1024;
  32. case 'k':
  33. $val *= 1024;
  34. }
  35. return $val;
  36. }
  37. // header('Content-type: text/plain');
  38. header('Content-type: application/xml');
  39. $dir=isset($_GET['dir'])?$_GET['dir']:'';
  40. $files=OC_FILES::getdirectorycontent($dir);
  41. $dirname=(isset($files[0]))?$files[0]['directory']:'';
  42. $dirname=substr($dirname,strrpos($dirname,'/'));
  43. $max_upload=min(return_bytes(ini_get('post_max_size')),return_bytes(ini_get('upload_max_filesize')));
  44. ob_clean();
  45. echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n";
  46. echo "<dir name='$dirname' max_upload='$max_upload'>\n";
  47. if(is_array($files)){
  48. foreach($files as $file){
  49. $attributes='';
  50. foreach($file as $name=>$data){
  51. $data=utf8_encode($data);
  52. $data=utf8tohtml($data);
  53. $data=str_replace("'",'&#39;',$data);
  54. if (is_string($name)) $attributes.=" $name='$data'";
  55. }
  56. $attributes.=' date=\''.date($CONFIG_DATEFORMAT,$file['mtime']).'\'';
  57. echo "<file$attributes/>\n";
  58. }
  59. }
  60. echo "</dir>";
  61. // converts a UTF8-string into HTML entities
  62. // - $utf8: the UTF8-string to convert
  63. // - $encodeTags: booloean. TRUE will convert "<" to "&lt;"
  64. // - return: returns the converted HTML-string
  65. function utf8tohtml($utf8, $encodeTags=true) {
  66. $result = '';
  67. for ($i = 0; $i < strlen($utf8); $i++) {
  68. $char = $utf8[$i];
  69. $ascii = ord($char);
  70. if ($ascii < 128) {
  71. // one-byte character
  72. $result .= ($encodeTags) ? htmlentities($char) : $char;
  73. } else if ($ascii < 192) {
  74. // non-utf8 character or not a start byte
  75. } else if ($ascii < 224) {
  76. // two-byte character
  77. $result .= htmlentities(substr($utf8, $i, 2), ENT_QUOTES, 'UTF-8');
  78. $i++;
  79. } else if ($ascii < 240) {
  80. // three-byte character
  81. $ascii1 = ord($utf8[$i+1]);
  82. $ascii2 = ord($utf8[$i+2]);
  83. $unicode = (15 & $ascii) * 4096 +
  84. (63 & $ascii1) * 64 +
  85. (63 & $ascii2);
  86. $result .= "&#$unicode;";
  87. $i += 2;
  88. } else if ($ascii < 248) {
  89. // four-byte character
  90. $ascii1 = ord($utf8[$i+1]);
  91. $ascii2 = ord($utf8[$i+2]);
  92. $ascii3 = ord($utf8[$i+3]);
  93. $unicode = (15 & $ascii) * 262144 +
  94. (63 & $ascii1) * 4096 +
  95. (63 & $ascii2) * 64 +
  96. (63 & $ascii3);
  97. $result .= "&#$unicode;";
  98. $i += 3;
  99. }
  100. }
  101. return $result;
  102. }
  103. ?>