]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/Tree/Filesystem.php
privacy_image_cache: checking if the cached file really is an image
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / Tree / Filesystem.php
1 <?php
2
3 /**
4  * Sabre_DAV_Tree_Filesystem
5  *
6  * @package Sabre
7  * @subpackage DAV
8  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
9  * @author Evert Pot (http://www.rooftopsolutions.nl/)
10  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
11  */
12 class Sabre_DAV_Tree_Filesystem extends Sabre_DAV_Tree {
13
14     /**
15      * Base url on the filesystem.
16      *
17      * @var string
18      */
19     protected $basePath;
20
21     /**
22      * Creates this tree
23      *
24      * Supply the path you'd like to share.
25      *
26      * @param string $basePath
27      */
28     public function __construct($basePath) {
29
30         $this->basePath = $basePath;
31
32     }
33
34     /**
35      * Returns a new node for the given path
36      *
37      * @param string $path
38      * @return Sabre_DAV_FS_Node
39      */
40     public function getNodeForPath($path) {
41
42         $realPath = $this->getRealPath($path);
43         if (!file_exists($realPath)) throw new Sabre_DAV_Exception_NotFound('File at location ' . $realPath . ' not found');
44         if (is_dir($realPath)) {
45             return new Sabre_DAV_FS_Directory($path);
46         } else {
47             return new Sabre_DAV_FS_File($path);
48         }
49
50     }
51
52     /**
53      * Returns the real filesystem path for a webdav url.
54      *
55      * @param string $publicPath
56      * @return string
57      */
58     protected function getRealPath($publicPath) {
59
60         return rtrim($this->basePath,'/') . '/' . trim($publicPath,'/');
61
62     }
63
64     /**
65      * Copies a file or directory.
66      *
67      * This method must work recursively and delete the destination
68      * if it exists
69      *
70      * @param string $source
71      * @param string $destination
72      * @return void
73      */
74     public function copy($source,$destination) {
75
76         $source = $this->getRealPath($source);
77         $destination = $this->getRealPath($destination);
78         $this->realCopy($source,$destination);
79
80     }
81
82     /**
83      * Used by self::copy
84      *
85      * @param string $source
86      * @param string $destination
87      * @return void
88      */
89     protected function realCopy($source,$destination) {
90
91         if (is_file($source)) {
92             copy($source,$destination);
93         } else {
94             mkdir($destination);
95             foreach(scandir($source) as $subnode) {
96
97                 if ($subnode=='.' || $subnode=='..') continue;
98                 $this->realCopy($source.'/'.$subnode,$destination.'/'.$subnode);
99
100             }
101         }
102
103     }
104
105     /**
106      * Moves a file or directory recursively.
107      *
108      * If the destination exists, delete it first.
109      *
110      * @param string $source
111      * @param string $destination
112      * @return void
113      */
114     public function move($source,$destination) {
115
116         $source = $this->getRealPath($source);
117         $destination = $this->getRealPath($destination);
118         rename($source,$destination);
119
120     }
121
122 }
123