ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Plugin.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Sabre\DAV;
10 use Sabre\DAVACL;
13 
27 class 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 }
This interface represents a HTTP response.
httpGet(RequestInterface $request, ResponseInterface $response)
This event is triggered before the usual GET request handler.
Definition: Plugin.php:128
The RequestInterface represents a HTTP request.
handle($propertyName, $valueOrCallBack)
Handles a specific property.
Definition: PropFind.php:94
$path
Definition: aliased.php:25
getPluginInfo()
Returns a bunch of meta-data about the plugin.
Definition: Plugin.php:170
The baseclass for all server plugins.
setBody($body)
Updates the body resource with a new stream.
on($eventName, callable $callBack, $priority=100)
Subscribe to an event.
foreach($paths as $path) $request
Definition: asyncclient.php:32
const NS_CALENDARSERVER
This is the namespace for the proprietary calendarserver extensions.
Definition: Plugin.php:32
This node represents a single notification.
Definition: INode.php:21
This class holds all the information about a PROPFIND request.
Definition: PropFind.php:11
propFind(PropFind $propFind, BaseINode $node)
PropFind.
Definition: Plugin.php:89
Notifications plugin.
Definition: Plugin.php:27
Href property.
Definition: Href.php:26
setStatus($status)
Sets the HTTP status code.
Main DAV server class.
Definition: Server.php:23
getPath()
Returns the relative path.
IPrincipal interface.
Definition: IPrincipal.php:16
getPluginName()
Returns a plugin name.
Definition: Plugin.php:49
initialize(Server $server)
This initializes the plugin.
Definition: Plugin.php:66
$response
$caldavPlugin
setHeader($name, $value)
Updates a HTTP header.