]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/CalDAV/Principal/User.php
8453b877a73da3762382110378cf38aa91aeb65b
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / CalDAV / Principal / User.php
1 <?php
2
3 /**
4  * CalDAV principal
5  *
6  * This is a standard user-principal for CalDAV. This principal is also a
7  * collection and returns the caldav-proxy-read and caldav-proxy-write child
8  * principals.
9  *
10  * @package Sabre
11  * @subpackage CalDAV
12  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
13  * @author Evert Pot (http://www.rooftopsolutions.nl/) 
14  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
15  */
16 class Sabre_CalDAV_Principal_User extends Sabre_DAVACL_Principal implements Sabre_DAV_ICollection {
17
18     /**
19      * Creates a new file in the directory
20      *
21      * @param string $name Name of the file
22      * @param resource $data Initial payload, passed as a readable stream resource.
23      * @throws Sabre_DAV_Exception_Forbidden
24      * @return void
25      */
26     public function createFile($name, $data = null) {
27
28         throw new Sabre_DAV_Exception_Forbidden('Permission denied to create file (filename ' . $name . ')');
29
30     }
31
32     /**
33      * Creates a new subdirectory
34      *
35      * @param string $name
36      * @throws Sabre_DAV_Exception_Forbidden
37      * @return void
38      */
39     public function createDirectory($name) {
40
41         throw new Sabre_DAV_Exception_Forbidden('Permission denied to create directory');
42
43     }
44
45     /**
46      * Returns a specific child node, referenced by its name
47      *
48      * @param string $name
49      * @return Sabre_DAV_INode
50      */
51     public function getChild($name) {
52
53         $principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/' . $name);
54         if (!$principal) {
55             throw new Sabre_DAV_Exception_NotFound('Node with name ' . $name . ' was not found');
56         }
57         if ($name === 'calendar-proxy-read')
58             return new Sabre_CalDAV_Principal_ProxyRead($this->principalBackend, $this->principalProperties);
59
60         if ($name === 'calendar-proxy-write')
61             return new Sabre_CalDAV_Principal_ProxyWrite($this->principalBackend, $this->principalProperties);
62
63         throw new Sabre_DAV_Exception_NotFound('Node with name ' . $name . ' was not found');
64
65     }
66
67     /**
68      * Returns an array with all the child nodes
69      *
70      * @return Sabre_DAV_INode[]
71      */
72     public function getChildren() {
73
74         $r = array();
75         if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-read')) {
76             $r[] = new Sabre_CalDAV_Principal_ProxyRead($this->principalBackend, $this->principalProperties);
77         }
78         if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-write')) {
79             $r[] = new Sabre_CalDAV_Principal_ProxyWrite($this->principalBackend, $this->principalProperties);
80         }
81
82         return $r;
83
84     }
85
86     /**
87      * Returns whether or not the child node exists
88      *
89      * @param string $name
90      * @return bool
91      */
92     public function childExists($name) {
93
94         try {
95             $this->getChild($name);
96             return true;
97         } catch (Sabre_DAV_Exception_NotFound $e) {
98             return false;
99         }
100
101     }
102
103     /**
104      * Returns a list of ACE's for this node.
105      *
106      * Each ACE has the following properties:
107      *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
108      *     currently the only supported privileges
109      *   * 'principal', a url to the principal who owns the node
110      *   * 'protected' (optional), indicating that this ACE is not allowed to
111      *      be updated.
112      *
113      * @return array
114      */
115     public function getACL() {
116
117         $acl = parent::getACL();
118         $acl[] = array(
119             'privilege' => '{DAV:}read',
120             'principal' => $this->principalProperties['uri'] . '/calendar-proxy-read',
121             'protected' => true,
122         );
123         $acl[] = array(
124             'privilege' => '{DAV:}read',
125             'principal' => $this->principalProperties['uri'] . '/calendar-proxy-write',
126             'protected' => true,
127         );
128         return $acl;
129
130     }
131
132 }