/usr/share/php/Horde/Dav/File.php is in php-horde-dav 1.1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | <?php
/**
* Copyright 2013-2015 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Dav
*/
use \Sabre\DAV;
/**
* A file object.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Dav
*/
class Horde_Dav_File extends Sabre\DAV\File implements DAV\IProperties
{
/**
* A registry object.
*
* @var Horde_Registry
*/
protected $_registry;
/**
* The path to the current file.
*
* @var string
*/
protected $_path;
/**
* File details.
*
* @var array
*/
protected $_item;
/**
* File size.
*
* This will only be set if the actual file data is requested, to avoid the
* overhead of building the file content only to retrieve the file size.
*
* @var integer
*/
protected $_size;
/**
* Mapping of WebDAV property names to Horde API's browse() properties.
*
* @var array
*/
protected static $_propertyMap = array(
'{DAV:}getcontentlength' => 'contentlength',
'{DAV:}getcontenttype' => 'contentype',
'{DAV:}getetag' => 'etag',
'{DAV:}owner' => 'owner',
'{http://sabredav.org/ns}read-only' => 'read-only',
);
/**
* Constructor.
*
* @param Horde_Registry $registry A registry object.
* @param string $path The path to this file.
* @param array $item File details.
*/
public function __construct(Horde_Registry $registry, $path = null,
array $item = array())
{
$this->_registry = $registry;
$this->_path = $path;
$this->_item = $item;
}
/**
* Deletes the current node.
*/
public function delete()
{
list($base) = explode('/', $this->_path);
try {
$this->_registry->callByPackage(
$base,
'path_delete',
array($this->_path)
);
} catch (Horde_Exception_NotFound $e) {
throw new DAV\Exception\NotFound($this->_path . ' not found');
} catch (Horde_Exception $e) {
throw new DAV\Exception($e);
}
}
/**
* Returns the name of the node.
*
* This is used to generate the url.
*
* @return string
*/
public function getName()
{
list($dir, $base) = DAV\URLUtil::splitPath($this->_path);
return $base;
}
/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
public function getLastModified()
{
if (!empty($this->_item['modified'])) {
return $this->_item['modified'];
}
if (!empty($this->_item['created'])) {
return $this->_item['created'];
}
return parent::getLastModified();
}
/**
* Updates the data
*
* data is a readable stream resource.
*
* @param resource $data
* @return void
*/
public function put($data)
{
list($base) = explode('/', $this->_path);
try {
rewind($data);
$this->_registry->callByPackage(
$base,
'put',
array(
$this->_path,
stream_get_contents($data),
$this->getContentType() ?: 'application/octet-stream'
)
);
} catch (Horde_Exception_NotFound $e) {
throw new DAV\Exception\NotFound($this->_path . ' not found');
} catch (Horde_Exception $e) {
throw new DAV\Exception($e);
}
}
/**
* Returns the data
*
* This method may either return a string or a readable stream resource
*
* @return mixed
*/
public function get()
{
list($base) = explode('/', $this->_path);
try {
$items = $this->_registry->callByPackage(
$base, 'browse', array($this->_path)
);
} catch (Horde_Exception_NotFound $e) {
throw new DAV\Exception\NotFound($this->_path . ' not found');
} catch (Horde_Exception $e) {
throw new DAV\Exception($e);
}
if (!$items) {
throw new DAV\Exception\NotFound($this->_path . ' not found');
}
$item = reset($items);
$this->_size = strlen($item);
return $item;
}
/**
* Returns the size of the file, in bytes.
*
* @return int
*/
public function getSize()
{
return isset($this->_size)
? $this->_size
: (isset($this->_item['contentlength'])
? $this->_item['contentlength']
: null);
}
/**
* Returns the ETag for a file.
*
* @return string|null
*/
public function getETag()
{
return empty($this->_item['etag']) ? null : $this->_item['etag'];
}
/**
* Returns the mime-type for a file
*
* If null is returned, we'll assume application/octet-stream
*
* @return string|null
*/
public function getContentType()
{
return isset($this->_item['contenttype'])
? $this->_item['contenttype']
: null;
}
/**
* Updates properties on this node.
*
* @param array $mutations
* @return bool|array
*/
public function updateProperties($mutations)
{
return false;
}
/**
* Returns a list of properties for this nodes.
*
* @param array $properties
* @return void
*/
public function getProperties($properties)
{
$response = array();
foreach (self::$_propertyMap as $property => $apiProperty) {
if (isset($this->_item[$apiProperty])) {
$response[$property] = $this->_item[$apiProperty];
}
}
if (isset($this->_item['modified'])) {
$response['{DAV:}getlastmodified'] = new DAV\Property\GetLastModified(
$this->_item['modified']
);
}
if (isset($this->_item['displayname'])) {
$response['{DAV:}displayname'] = $this->_item['displayname'];
} elseif (isset($this->_item['name'])) {
$response['{DAV:}displayname'] = $this->_item['name'];
}
return $response;
}
}
|