]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAVACL/Property/SupportedPrivilegeSet.php
removed community home addon
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAVACL / Property / SupportedPrivilegeSet.php
1 <?php
2
3 /**
4  * SupportedPrivilegeSet property
5  *
6  * This property encodes the {DAV:}supported-privilege-set property, as defined
7  * in rfc3744. Please consult the rfc for details about it's structure.
8  *
9  * This class expects a structure like the one given from
10  * Sabre_DAVACL_Plugin::getSupportedPrivilegeSet as the argument in its
11  * constructor.
12  *
13  * @package Sabre
14  * @subpackage DAVACL
15  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
16  * @author Evert Pot (http://www.rooftopsolutions.nl/)
17  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
18  */
19 class Sabre_DAVACL_Property_SupportedPrivilegeSet extends Sabre_DAV_Property {
20
21     /**
22      * privileges
23      *
24      * @var array
25      */
26     private $privileges;
27
28     /**
29      * Constructor
30      *
31      * @param array $privileges
32      */
33     public function __construct(array $privileges) {
34
35         $this->privileges = $privileges;
36
37     }
38
39     /**
40      * Serializes the property into a domdocument.
41      *
42      * @param Sabre_DAV_Server $server
43      * @param DOMElement $node
44      * @return void
45      */
46     public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
47
48         $doc = $node->ownerDocument;
49         $this->serializePriv($doc, $node, $this->privileges);
50
51     }
52
53     /**
54      * Serializes a property
55      *
56      * This is a recursive function.
57      *
58      * @param DOMDocument $doc
59      * @param DOMElement $node
60      * @param array $privilege
61      * @return void
62      */
63     private function serializePriv($doc,$node,$privilege) {
64
65         $xsp = $doc->createElementNS('DAV:','d:supported-privilege');
66         $node->appendChild($xsp);
67
68         $xp  = $doc->createElementNS('DAV:','d:privilege');
69         $xsp->appendChild($xp);
70
71         $privParts = null;
72         preg_match('/^{([^}]*)}(.*)$/',$privilege['privilege'],$privParts);
73
74         $xp->appendChild($doc->createElementNS($privParts[1],'d:'.$privParts[2]));
75
76         if (isset($privilege['abstract']) && $privilege['abstract']) {
77             $xsp->appendChild($doc->createElementNS('DAV:','d:abstract'));
78         }
79
80         if (isset($privilege['description'])) {
81             $xsp->appendChild($doc->createElementNS('DAV:','d:description',$privilege['description']));
82         }
83
84         if (isset($privilege['aggregates'])) {
85             foreach($privilege['aggregates'] as $subPrivilege) {
86                 $this->serializePriv($doc,$xsp,$subPrivilege);
87             }
88         }
89
90     }
91
92 }