ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Plugin.php
Go to the documentation of this file.
1<?php
2
4
5use Sabre\DAV;
6use Sabre\DAV\INode as BaseINode;
10use Sabre\DAVACL;
13
27class Plugin extends ServerPlugin {
28
32 const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
33
39 protected $server;
40
49 function getPluginName() {
50
51 return 'notifications';
52
53 }
54
67
68 $this->server = $server;
69 $server->on('method:GET', [$this, 'httpGet'], 90);
70 $server->on('propFind', [$this, 'propFind']);
71
72 $server->xml->namespaceMap[self::NS_CALENDARSERVER] = 'cs';
73 $server->resourceTypeMapping['\\Sabre\\CalDAV\\Notifications\\ICollection'] = '{' . self::NS_CALENDARSERVER . '}notification';
74
75 array_push($server->protectedProperties,
76 '{' . self::NS_CALENDARSERVER . '}notification-URL',
77 '{' . self::NS_CALENDARSERVER . '}notificationtype'
78 );
79
80 }
81
89 function propFind(PropFind $propFind, BaseINode $node) {
90
91 $caldavPlugin = $this->server->getPlugin('caldav');
92
93 if ($node instanceof DAVACL\IPrincipal) {
94
95 $principalUrl = $node->getPrincipalUrl();
96
97 // notification-URL property
98 $propFind->handle('{' . self::NS_CALENDARSERVER . '}notification-URL', function() use ($principalUrl, $caldavPlugin) {
99
100 $notificationPath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl) . '/notifications/';
101 return new DAV\Xml\Property\Href($notificationPath);
102
103 });
104
105 }
106
107 if ($node instanceof INode) {
108
109 $propFind->handle(
110 '{' . self::NS_CALENDARSERVER . '}notificationtype',
111 [$node, 'getNotificationType']
112 );
113
114 }
115
116 }
117
129
130 $path = $request->getPath();
131
132 try {
133 $node = $this->server->tree->getNodeForPath($path);
134 } catch (DAV\Exception\NotFound $e) {
135 return;
136 }
137
138 if (!$node instanceof INode)
139 return;
140
141 $writer = $this->server->xml->getWriter();
142 $writer->contextUri = $this->server->getBaseUri();
143 $writer->openMemory();
144 $writer->startDocument('1.0', 'UTF-8');
145 $writer->startElement('{http://calendarserver.org/ns/}notification');
146 $node->getNotificationType()->xmlSerializeFull($writer);
147 $writer->endElement();
148
149 $response->setHeader('Content-Type', 'application/xml');
150 $response->setHeader('ETag', $node->getETag());
151 $response->setStatus(200);
152 $response->setBody($writer->outputMemory());
153
154 // Return false to break the event chain.
155 return false;
156
157 }
158
170 function getPluginInfo() {
171
172 return [
173 'name' => $this->getPluginName(),
174 'description' => 'Adds support for caldav-notifications, which is required to enable caldav-sharing.',
175 'link' => 'http://sabre.io/dav/caldav-sharing/',
176 ];
177
178 }
179
180}
$path
Definition: aliased.php:25
foreach($paths as $path) $request
Definition: asyncclient.php:32
$caldavPlugin
An exception for terminatinating execution or to throw for unit testing.
Notifications plugin.
Definition: Plugin.php:27
initialize(Server $server)
This initializes the plugin.
Definition: Plugin.php:66
httpGet(RequestInterface $request, ResponseInterface $response)
This event is triggered before the usual GET request handler.
Definition: Plugin.php:128
const NS_CALENDARSERVER
This is the namespace for the proprietary calendarserver extensions.
Definition: Plugin.php:32
getPluginInfo()
Returns a bunch of meta-data about the plugin.
Definition: Plugin.php:170
getPluginName()
Returns a plugin name.
Definition: Plugin.php:49
propFind(PropFind $propFind, BaseINode $node)
PropFind.
Definition: Plugin.php:89
Main Exception class.
Definition: Exception.php:18
This class holds all the information about a PROPFIND request.
Definition: PropFind.php:11
handle($propertyName, $valueOrCallBack)
Handles a specific property.
Definition: PropFind.php:94
The baseclass for all server plugins.
Main DAV server class.
Definition: Server.php:23
Href property.
Definition: Href.php:26
This node represents a single notification.
Definition: INode.php:21
IPrincipal interface.
Definition: IPrincipal.php:16
The INode interface is the base interface, and the parent class of both ICollection and IFile.
Definition: INode.php:12
The RequestInterface represents a HTTP request.
This interface represents a HTTP response.
$response