]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/Property/ResourceType.php
privacy_image_cache: checking if the cached file really is an image
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / Property / ResourceType.php
1 <?php
2
3 /**
4  * This class represents the {DAV:}resourcetype property
5  *
6  * Normally for files this is empty, and for collection {DAV:}collection.
7  * However, other specs define different values for this.
8  *
9  * @package Sabre
10  * @subpackage DAV
11  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12  * @author Evert Pot (http://www.rooftopsolutions.nl/)
13  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
14  */
15 class Sabre_DAV_Property_ResourceType extends Sabre_DAV_Property {
16
17     /**
18      * resourceType
19      *
20      * @var array
21      */
22     public $resourceType = array();
23
24     /**
25      * __construct
26      *
27      * @param mixed $resourceType
28      */
29     public function __construct($resourceType = array()) {
30
31         if ($resourceType === Sabre_DAV_Server::NODE_FILE)
32             $this->resourceType = array();
33         elseif ($resourceType === Sabre_DAV_Server::NODE_DIRECTORY)
34             $this->resourceType = array('{DAV:}collection');
35         elseif (is_array($resourceType))
36             $this->resourceType = $resourceType;
37         else
38             $this->resourceType = array($resourceType);
39
40     }
41
42     /**
43      * serialize
44      *
45      * @param Sabre_DAV_Server $server
46      * @param DOMElement $prop
47      * @return void
48      */
49     public function serialize(Sabre_DAV_Server $server, DOMElement $prop) {
50
51         $propName = null;
52         $rt = $this->resourceType;
53
54         foreach($rt as $resourceType) {
55             if (preg_match('/^{([^}]*)}(.*)$/',$resourceType,$propName)) {
56
57                 if (isset($server->xmlNamespaces[$propName[1]])) {
58                     $prop->appendChild($prop->ownerDocument->createElement($server->xmlNamespaces[$propName[1]] . ':' . $propName[2]));
59                 } else {
60                     $prop->appendChild($prop->ownerDocument->createElementNS($propName[1],'custom:' . $propName[2]));
61                 }
62
63             }
64         }
65
66     }
67
68     /**
69      * Returns the values in clark-notation
70      *
71      * For example array('{DAV:}collection')
72      *
73      * @return array
74      */
75     public function getValue() {
76
77         return $this->resourceType;
78
79     }
80
81     /**
82      * Checks if the principal contains a certain value
83      *
84      * @param string $type
85      * @return bool
86      */
87     public function is($type) {
88
89         return in_array($type, $this->resourceType);
90
91     }
92
93     /**
94      * Adds a resourcetype value to this property
95      *
96      * @param string $type
97      * @return void
98      */
99     public function add($type) {
100
101         $this->resourceType[] = $type;
102         $this->resourceType = array_unique($this->resourceType);
103
104     }
105
106     /**
107      * Unserializes a DOM element into a ResourceType property.
108      *
109      * @param DOMElement $dom
110      * @return Sabre_DAV_Property_ResourceType
111      */
112     static public function unserialize(DOMElement $dom) {
113
114         $value = array();
115         foreach($dom->childNodes as $child) {
116
117             $value[] = Sabre_DAV_XMLUtil::toClarkNotation($child);
118
119         }
120
121         return new self($value);
122
123     }
124
125 }