]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/FSExt/Directory.php
privacy_image_cache: checking if the cached file really is an image
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / FSExt / Directory.php
1 <?php
2
3 /**
4  * Directory class
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_FSExt_Directory extends Sabre_DAV_FSExt_Node implements Sabre_DAV_ICollection, Sabre_DAV_IQuota {
13
14     /**
15      * Creates a new file in the directory
16      *
17      * Data will either be supplied as a stream resource, or in certain cases
18      * as a string. Keep in mind that you may have to support either.
19      *
20      * After successful creation of the file, you may choose to return the ETag
21      * of the new file here.
22      *
23      * The returned ETag must be surrounded by double-quotes (The quotes should
24      * be part of the actual string).
25      *
26      * If you cannot accurately determine the ETag, you should not return it.
27      * If you don't store the file exactly as-is (you're transforming it
28      * somehow) you should also not return an ETag.
29      *
30      * This means that if a subsequent GET to this new file does not exactly
31      * return the same contents of what was submitted here, you are strongly
32      * recommended to omit the ETag.
33      *
34      * @param string $name Name of the file
35      * @param resource|string $data Initial payload
36      * @return null|string
37      */
38     public function createFile($name, $data = null) {
39
40         // We're not allowing dots
41         if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
42         $newPath = $this->path . '/' . $name;
43         file_put_contents($newPath,$data);
44
45         return '"' . md5_file($newPath) . '"';
46
47     }
48
49     /**
50      * Creates a new subdirectory
51      *
52      * @param string $name
53      * @return void
54      */
55     public function createDirectory($name) {
56
57         // We're not allowing dots
58         if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
59         $newPath = $this->path . '/' . $name;
60         mkdir($newPath);
61
62     }
63
64     /**
65      * Returns a specific child node, referenced by its name
66      *
67      * This method must throw Sabre_DAV_Exception_NotFound if the node does not
68      * exist.
69      *
70      * @param string $name
71      * @throws Sabre_DAV_Exception_NotFound
72      * @return Sabre_DAV_INode
73      */
74     public function getChild($name) {
75
76         $path = $this->path . '/' . $name;
77
78         if (!file_exists($path)) throw new Sabre_DAV_Exception_NotFound('File could not be located');
79         if ($name=='.' || $name=='..') throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
80
81         if (is_dir($path)) {
82
83             return new Sabre_DAV_FSExt_Directory($path);
84
85         } else {
86
87             return new Sabre_DAV_FSExt_File($path);
88
89         }
90
91     }
92
93     /**
94      * Checks if a child exists.
95      *
96      * @param string $name
97      * @return bool
98      */
99     public function childExists($name) {
100
101         if ($name=='.' || $name=='..')
102             throw new Sabre_DAV_Exception_Forbidden('Permission denied to . and ..');
103
104         $path = $this->path . '/' . $name;
105         return file_exists($path);
106
107     }
108
109     /**
110      * Returns an array with all the child nodes
111      *
112      * @return Sabre_DAV_INode[]
113      */
114     public function getChildren() {
115
116         $nodes = array();
117         foreach(scandir($this->path) as $node) if($node!='.' && $node!='..' && $node!='.sabredav') $nodes[] = $this->getChild($node);
118         return $nodes;
119
120     }
121
122     /**
123      * Deletes all files in this directory, and then itself
124      *
125      * @return bool
126      */
127     public function delete() {
128
129         // Deleting all children
130         foreach($this->getChildren() as $child) $child->delete();
131
132         // Removing resource info, if its still around
133         if (file_exists($this->path . '/.sabredav')) unlink($this->path . '/.sabredav');
134
135         // Removing the directory itself
136         rmdir($this->path);
137
138         return parent::delete();
139
140     }
141
142     /**
143      * Returns available diskspace information
144      *
145      * @return array
146      */
147     public function getQuotaInfo() {
148
149         return array(
150             disk_total_space($this->path)-disk_free_space($this->path),
151             disk_free_space($this->path)
152             );
153
154     }
155
156 }
157