]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAVACL/Exception/NeedPrivileges.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAVACL / Exception / NeedPrivileges.php
1 <?php
2
3 /**
4  * NeedPrivileges
5  *
6  * The 403-need privileges is thrown when a user didn't have the appropriate
7  * permissions to perform an operation
8  *
9  * @package Sabre
10  * @subpackage DAVACL
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_DAVACL_Exception_NeedPrivileges extends Sabre_DAV_Exception_Forbidden {
16
17     /**
18      * The relevant uri
19      *
20      * @var string
21      */
22     protected $uri;
23
24     /**
25      * The privileges the user didn't have.
26      *
27      * @var array
28      */
29     protected $privileges;
30
31     /**
32      * Constructor
33      *
34      * @param string $uri
35      * @param array $privileges
36      */
37     public function __construct($uri,array $privileges) {
38
39         $this->uri = $uri;
40         $this->privileges = $privileges;
41
42         parent::__construct('User did not have the required privileges (' . implode(',', $privileges) . ') for path "' . $uri . '"');
43
44     }
45
46     /**
47      * Adds in extra information in the xml response.
48      *
49      * This method adds the {DAV:}need-privileges element as defined in rfc3744
50      *
51      * @param Sabre_DAV_Server $server
52      * @param DOMElement $errorNode
53      * @return void
54      */
55     public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
56
57         $doc = $errorNode->ownerDocument;
58
59         $np = $doc->createElementNS('DAV:','d:need-privileges');
60         $errorNode->appendChild($np);
61
62         foreach($this->privileges as $privilege) {
63
64             $resource = $doc->createElementNS('DAV:','d:resource');
65             $np->appendChild($resource);
66
67             $resource->appendChild($doc->createElementNS('DAV:','d:href',$server->getBaseUri() . $this->uri));
68
69             $priv = $doc->createElementNS('DAV:','d:privilege');
70             $resource->appendChild($priv);
71
72             preg_match('/^{([^}]*)}(.*)$/',$privilege,$privilegeParts);
73             $priv->appendChild($doc->createElementNS($privilegeParts[1],'d:' . $privilegeParts[2]));
74
75
76         }
77
78     }
79
80 }
81