/usr/share/php/Horde/Dav/Collection.php is in php-horde-dav 1.0.3-2.
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 | <?php
/**
* Copyright 2013 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;
use Sabre\DAVACL;
use Sabre\CalDAV;
/**
* A collection (directory) object.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Dav
*/
class Horde_Dav_Collection extends DAV\Collection
{
/**
* The path to the current collection.
*
* @var string
*/
protected $_path;
/**
* Collection details.
*
* @var array
*/
protected $_item;
/**
* A registry object.
*
* @var Horde_Registry
*/
protected $_registry;
/**
* The path to a MIME magic database.
*
* @var string
*/
protected $_mimedb;
/**
* Constructor.
*
* @param string $path The path to this
* collection.
* @param array $item Collection details.
* @param Horde_Registry $registry A registry object.
* @param string $mimedb Location of a MIME
* magic database.
*/
public function __construct($path = null,
array $item = array(),
Horde_Registry $registry,
$mimedb)
{
$this->_path = $path;
$this->_item = $item;
$this->_registry = $registry;
$this->_mimedb = $mimedb;
}
/**
* 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();
}
/**
* Returns an array with all the child nodes
*
* @return DAV\INode[]
*/
public function getChildren()
{
list($app) = explode('/', $this->_path);
try {
$items = $this->_registry->callByPackage(
$app,
'browse',
array(
'path' => $this->_path,
'properties' => array(
'name', 'browseable', 'contenttype', 'contentlength',
'created', 'modified'
)
)
);
} catch (Horde_Exception $e) {
throw new DAV\Exception($e);
}
if ($items === false) {
throw new DAV\Exception\NotFound($this->_path . ' not found');
}
if (empty($items)) {
// No content exists at this level.
return array();
}
/* A directory full of objects has been returned. */
$list = array();
foreach ($items as $path => $item) {
if ($item['browseable']) {
$list[] = new Horde_Dav_Collection(
$path,
$item,
$this->_registry,
$this->_mimedb
);
} else {
$list[] = new Horde_Dav_File($this->_registry, $path, $item);
}
}
return $list;
}
/**
* Creates a new file in the directory
*
* @param string $name Name of the file
* @param resource|string $data Initial payload
* @return null|string
*/
public function createFile($name, $data = null)
{
list($app) = explode('/', $this->_path);
if (is_resource($data)) {
$content = new Horde_Stream_Existing(array('stream' => $data));
$type = Horde_Mime_Magic::analyzeData(
$content->getString(0, 100), $this->_mimedb
);
} else {
$content = $data;
$type = Horde_Mime_Magic::analyzeData($content, $this->_mimedb);
}
if (!$type) {
$type = Horde_Mime_Magic::filenameToMime($name);
}
try {
$this->_registry->callByPackage(
$app,
'put',
array($this->_path . '/' . $name, $content, $type)
);
} catch (Horde_Exception $e) {
throw new DAV\Exception($e->getMessage(), $e->getCode(), $e);
}
}
}
|