/usr/share/php/Horde/Kolab/Storage/List/Query/List/Base.php is in php-horde-kolab-storage 2.0.5-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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | <?php
/**
* The basic list query.
*
* PHP version 5
*
* @category Kolab
* @package Kolab_Storage
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
/**
* The basic list query.
*
* Copyright 2010-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Kolab
* @package Kolab_Storage
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
class Horde_Kolab_Storage_List_Query_List_Base
extends Horde_Kolab_Storage_List_Query_List
{
/**
* The IMAP driver to query the backend.
*
* @var Horde_Kolab_Storage_Driver
*/
private $_driver;
/**
* The factory for folder types.
*
* @var Horde_Kolab_Storage_Folder_Types
*/
private $_folder_types;
/**
* Handles default folders.
*
* @var Horde_Kolab_Storage_List_Query_List_Defaults
*/
private $_defaults;
/**
* Constructor.
*
* @param Horde_Kolab_Storage_Driver $driver The driver to access the backend.
* @param Horde_Kolab_Storage_Folder_Types $types Handler of folder types.
* @param Horde_Kolab_Storage_List_Query_List_Defaults $defaults Handler of defaults.
*/
public function __construct(Horde_Kolab_Storage_Driver $driver,
Horde_Kolab_Storage_Folder_Types $types,
Horde_Kolab_Storage_List_Query_List_Defaults $defaults)
{
$this->_driver = $driver;
$this->_folder_types = $types;
$this->_defaults = $defaults;
}
/**
* Returns the folder type annotation as associative array.
*
* @return array The list folder types with the folder names as key and the
* type handler as values.
*/
private function listFolderTypeAnnotations()
{
$result = array();
foreach ($this->_driver->listAnnotation(self::ANNOTATION_FOLDER_TYPE) as $folder => $annotation) {
$result[$folder] = $this->_folder_types->create($annotation);
}
return $result;
}
/**
* Returns the folder types as associative array.
*
* @return array The list folder types with the folder names as key and the
* type as values.
*/
public function listTypes()
{
$result = array();
foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
$result[$folder] = $annotation->getType();
}
return $result;
}
/**
* List all folders of a specific type.
*
* @param string $type The folder type the listing should be limited to.
*
* @return array The list of folders.
*/
public function listByType($type)
{
$result = array();
foreach ($this->listTypes() as $folder => $folder_type) {
if ($folder_type == $type) {
$result[] = $folder;
}
}
return $result;
}
/**
* List basic folder data for the folders of a specific type.
*
* @param string $type The folder type the listing should be limited to.
*
* @return array The list of folders.
*/
public function dataByType($type)
{
$result = array();
$namespace = $this->_driver->getNamespace();
foreach ($this->listFolderTypeAnnotations() as $folder => $folder_type) {
if ($folder_type->getType() == $type) {
$data = new Horde_Kolab_Storage_Folder_Data(
$folder, $folder_type, $namespace
);
$result[$folder] = $data->toArray();
}
}
return $result;
}
/**
* List basic folder data for the specified folder.
*
* @param string $folder The folder path.
*
* @return array The folder data.
*/
public function folderData($folder)
{
$list = $this->_driver->listFolders();
if (!in_array($folder, $list)) {
throw new Horde_Kolab_Storage_List_Exception(
sprintf('Folder %s does not exist!', $folder)
);
}
$annotations = $this->listFolderTypeAnnotations();
if (!isset($annotations[$folder])) {
$type = $this->_folder_types->create('mail');
} else {
$type = $annotations[$folder];
}
$data = new Horde_Kolab_Storage_Folder_Data(
$folder, $type, $this->_driver->getNamespace()
);
return $data->toArray();
}
/**
* Get the folder owners.
*
* @return array The folder owners with the folder names as key and the
* owner as values.
*/
public function listOwners()
{
$result = array();
$namespace = $this->_driver->getNamespace();
foreach ($this->_driver->listFolders() as $folder) {
$result[$folder] = $namespace->getOwner($folder);
}
return $result;
}
/**
* Set the specified folder as default for its current type.
*
* @param string $folder The folder name.
*/
public function setDefault($folder)
{
$types = $this->listTypes();
if (!isset($types[$folder])) {
throw new Horde_Kolab_Storage_List_Exception(
sprintf(
"The folder %s has no Kolab type. It cannot be marked as 'default' folder!",
$folder
)
);
}
$previous = $this->getDefault($types[$folder]);
if ($previous) {
$this->_driver->setAnnotation($previous, self::ANNOTATION_FOLDER_TYPE, $types[$folder]);
}
$this->_driver->setAnnotation($folder, self::ANNOTATION_FOLDER_TYPE, $types[$folder] . '.default');
}
/**
* Return the list of personal default folders.
*
* @return array An array that associates type (key) with the corresponding
* default folder name (value).
*/
public function listPersonalDefaults()
{
return $this->_getPersonalDefaults();
}
/**
* Return the list of default folders.
*
* @return array An array with owners as keys and another array as
* value. The second array associates type (key) with the
* corresponding default folder (value).
*/
public function listDefaults()
{
return $this->_getDefaults();
}
/**
* Get the default folder for a certain type.
*
* @param string $type The type of the share/folder.
*
* @return string|boolean The name of the default folder, false if there is no default.
*/
public function getDefault($type)
{
$defaults = $this->_getPersonalDefaults();
if (!isset($defaults[$type])) {
return false;
} else {
return $defaults[$type];
}
}
/**
* Get the default folder for a certain type from a different owner.
*
* @param string $owner The folder owner.
* @param string $type The type of the share/folder.
*
* @return string|boolean The name of the default folder, false if there is no default.
*/
public function getForeignDefault($owner, $type)
{
$defaults = $this->_getDefaults();
if (!isset($defaults[$owner][$type])) {
return false;
} else {
return $defaults[$owner][$type];
}
}
/**
* Return the list of personal defaults.
*/
private function _getPersonalDefaults()
{
$this->_initDefaults();
return $this->_defaults->getPersonalDefaults();
}
/**
* Return the complete list of defaults.
*/
private function _getDefaults()
{
$this->_initDefaults();
return $this->_defaults->getDefaults();
}
/**
* Initialize the list of defaults.
*/
private function _initDefaults()
{
if (!$this->_defaults->isComplete()) {
$namespace = $this->_driver->getNamespace();
foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
if ($annotation->isDefault()) {
$this->_defaults->rememberDefault(
$folder,
$annotation->getType(),
$namespace->getOwner($folder),
$namespace->matchNamespace($folder)->getType() == Horde_Kolab_Storage_Folder_Namespace::PERSONAL
);
}
}
$this->_defaults->markComplete();
}
}
/**
* Return the last sync stamp.
*
* @return string The stamp.
*/
public function getStamp()
{
return pack('Nn', time(), mt_rand());
}
}
|