WebdavFile.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. class WebdavFile {
  3. public $davpath = '';
  4. public $realpath = '';
  5. public $is_dir = null;
  6. public $virtual_dirs = array();
  7. public $virtual_files = array();
  8. public $perms = 'R';
  9. public $prevent_scandir = false;
  10. function __construct($davpath) {
  11. $this->davpath = $davpath;
  12. }
  13. public function getRealPath() {
  14. return $this->realpath;
  15. }
  16. public function getIsDir() {
  17. return $this->is_dir;
  18. }
  19. public function getVirtualDirs() {
  20. return $this->virtual_dirs;
  21. }
  22. public function getVirtualFiles() {
  23. return $this->virtual_files;
  24. }
  25. public function getPerms() {
  26. return $this->perms;
  27. }
  28. public function setRealPath($realpath) {
  29. $this->realpath = $realpath;
  30. }
  31. public function addRealPathPart($part) {
  32. $this->realpath .= '/' . $part;
  33. }
  34. public function setIsDir($isDir) {
  35. $this->is_dir = $isDir;
  36. }
  37. public function setVirtualDirs($virtual_dirs) {
  38. $this->virtual_dirs = $virtual_dirs;
  39. }
  40. public function addVirtualDir($virtual_dir) {
  41. $this->virtual_dirs[] = $virtual_dir;
  42. }
  43. public function setVirtualFiles($virtual_files) {
  44. $this->virtual_files = $virtual_files;
  45. }
  46. public function addVirtualFile($virtual_file) {
  47. $this->virtual_files[] = $virtual_file;
  48. }
  49. public function setPerms($perms) {
  50. $this->perms = $perms;
  51. }
  52. public function setPreventScandir($prevent_scandir) {
  53. $this->prevent_scandir = $prevent_scandir;
  54. }
  55. /**
  56. * @param string $davpath eg.: SE/DRUKI/1379.UMOWA.2011-06-03.umowa_abonencka.2011-06-03
  57. *
  58. * @returns array $list [realname => type(dir,file,virtualdir?)]
  59. */
  60. function getChildren() {
  61. $list = array();
  62. if ($this->is_dir === true) {
  63. if (!empty($this->virtual_dirs)) {
  64. foreach ($this->virtual_dirs as $name) {
  65. $list[$name] = 'dir';
  66. }
  67. }
  68. if (!empty($this->virtual_files)) {
  69. foreach ($this->virtual_files as $name) {
  70. $list[$name] = 'file';
  71. }
  72. }
  73. if (empty($this->prevent_scandir)) {
  74. foreach (scandir($this->realpath) as $name) {
  75. if (substr($name, 0, 1) == '.') continue;
  76. //$id = reset(explode('.', $name));
  77. //if (is_numeric($id)) {// TODO: check name format
  78. if (is_dir($this->realpath . '/' . $name)) {
  79. $list[$name] = 'dir';
  80. } else {
  81. $list[$name] = 'file';
  82. }
  83. //}
  84. }
  85. }
  86. }
  87. return $list;
  88. }
  89. }