xref: /plugin/davcal/vendor/sabre/dav/lib/CalDAV/Subscriptions/Plugin.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV\Subscriptions;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\DAV\INode;
6*a1a3b679SAndreas Boehleruse Sabre\DAV\PropFind;
7*a1a3b679SAndreas Boehleruse Sabre\DAV\ServerPlugin;
8*a1a3b679SAndreas Boehleruse Sabre\DAV\Server;
9*a1a3b679SAndreas Boehler
10*a1a3b679SAndreas Boehler/**
11*a1a3b679SAndreas Boehler * This plugin adds calendar-subscription support to your CalDAV server.
12*a1a3b679SAndreas Boehler *
13*a1a3b679SAndreas Boehler * Some clients support 'managed subscriptions' server-side. This is basically
14*a1a3b679SAndreas Boehler * a list of subscription urls a user is using.
15*a1a3b679SAndreas Boehler *
16*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
17*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
18*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
19*a1a3b679SAndreas Boehler */
20*a1a3b679SAndreas Boehlerclass Plugin extends ServerPlugin {
21*a1a3b679SAndreas Boehler
22*a1a3b679SAndreas Boehler    /**
23*a1a3b679SAndreas Boehler     * This initializes the plugin.
24*a1a3b679SAndreas Boehler     *
25*a1a3b679SAndreas Boehler     * This function is called by Sabre\DAV\Server, after
26*a1a3b679SAndreas Boehler     * addPlugin is called.
27*a1a3b679SAndreas Boehler     *
28*a1a3b679SAndreas Boehler     * This method should set up the required event subscriptions.
29*a1a3b679SAndreas Boehler     *
30*a1a3b679SAndreas Boehler     * @param Server $server
31*a1a3b679SAndreas Boehler     * @return void
32*a1a3b679SAndreas Boehler     */
33*a1a3b679SAndreas Boehler    function initialize(Server $server) {
34*a1a3b679SAndreas Boehler
35*a1a3b679SAndreas Boehler        $server->resourceTypeMapping['Sabre\\CalDAV\\Subscriptions\\ISubscription'] =
36*a1a3b679SAndreas Boehler            '{http://calendarserver.org/ns/}subscribed';
37*a1a3b679SAndreas Boehler
38*a1a3b679SAndreas Boehler        $server->xml->elementMap['{http://calendarserver.org/ns/}source'] =
39*a1a3b679SAndreas Boehler            'Sabre\\DAV\\Xml\\Property\\Href';
40*a1a3b679SAndreas Boehler
41*a1a3b679SAndreas Boehler        $server->on('propFind', [$this, 'propFind'], 150);
42*a1a3b679SAndreas Boehler
43*a1a3b679SAndreas Boehler    }
44*a1a3b679SAndreas Boehler
45*a1a3b679SAndreas Boehler    /**
46*a1a3b679SAndreas Boehler     * This method should return a list of server-features.
47*a1a3b679SAndreas Boehler     *
48*a1a3b679SAndreas Boehler     * This is for example 'versioning' and is added to the DAV: header
49*a1a3b679SAndreas Boehler     * in an OPTIONS response.
50*a1a3b679SAndreas Boehler     *
51*a1a3b679SAndreas Boehler     * @return array
52*a1a3b679SAndreas Boehler     */
53*a1a3b679SAndreas Boehler    function getFeatures() {
54*a1a3b679SAndreas Boehler
55*a1a3b679SAndreas Boehler        return ['calendarserver-subscribed'];
56*a1a3b679SAndreas Boehler
57*a1a3b679SAndreas Boehler    }
58*a1a3b679SAndreas Boehler
59*a1a3b679SAndreas Boehler    /**
60*a1a3b679SAndreas Boehler     * Triggered after properties have been fetched.
61*a1a3b679SAndreas Boehler     *
62*a1a3b679SAndreas Boehler     * @param PropFind $propFind
63*a1a3b679SAndreas Boehler     * @param INode $node
64*a1a3b679SAndreas Boehler     * @return void
65*a1a3b679SAndreas Boehler     */
66*a1a3b679SAndreas Boehler    function propFind(PropFind $propFind, INode $node) {
67*a1a3b679SAndreas Boehler
68*a1a3b679SAndreas Boehler        // There's a bunch of properties that must appear as a self-closing
69*a1a3b679SAndreas Boehler        // xml-element. This event handler ensures that this will be the case.
70*a1a3b679SAndreas Boehler        $props = [
71*a1a3b679SAndreas Boehler            '{http://calendarserver.org/ns/}subscribed-strip-alarms',
72*a1a3b679SAndreas Boehler            '{http://calendarserver.org/ns/}subscribed-strip-attachments',
73*a1a3b679SAndreas Boehler            '{http://calendarserver.org/ns/}subscribed-strip-todos',
74*a1a3b679SAndreas Boehler        ];
75*a1a3b679SAndreas Boehler
76*a1a3b679SAndreas Boehler        foreach ($props as $prop) {
77*a1a3b679SAndreas Boehler
78*a1a3b679SAndreas Boehler            if ($propFind->getStatus($prop) === 200) {
79*a1a3b679SAndreas Boehler                $propFind->set($prop, '', 200);
80*a1a3b679SAndreas Boehler            }
81*a1a3b679SAndreas Boehler
82*a1a3b679SAndreas Boehler        }
83*a1a3b679SAndreas Boehler
84*a1a3b679SAndreas Boehler    }
85*a1a3b679SAndreas Boehler
86*a1a3b679SAndreas Boehler    /**
87*a1a3b679SAndreas Boehler     * Returns a plugin name.
88*a1a3b679SAndreas Boehler     *
89*a1a3b679SAndreas Boehler     * Using this name other plugins will be able to access other plugins
90*a1a3b679SAndreas Boehler     * using \Sabre\DAV\Server::getPlugin
91*a1a3b679SAndreas Boehler     *
92*a1a3b679SAndreas Boehler     * @return string
93*a1a3b679SAndreas Boehler     */
94*a1a3b679SAndreas Boehler    function getPluginName() {
95*a1a3b679SAndreas Boehler
96*a1a3b679SAndreas Boehler        return 'subscriptions';
97*a1a3b679SAndreas Boehler
98*a1a3b679SAndreas Boehler    }
99*a1a3b679SAndreas Boehler
100*a1a3b679SAndreas Boehler    /**
101*a1a3b679SAndreas Boehler     * Returns a bunch of meta-data about the plugin.
102*a1a3b679SAndreas Boehler     *
103*a1a3b679SAndreas Boehler     * Providing this information is optional, and is mainly displayed by the
104*a1a3b679SAndreas Boehler     * Browser plugin.
105*a1a3b679SAndreas Boehler     *
106*a1a3b679SAndreas Boehler     * The description key in the returned array may contain html and will not
107*a1a3b679SAndreas Boehler     * be sanitized.
108*a1a3b679SAndreas Boehler     *
109*a1a3b679SAndreas Boehler     * @return array
110*a1a3b679SAndreas Boehler     */
111*a1a3b679SAndreas Boehler    function getPluginInfo() {
112*a1a3b679SAndreas Boehler
113*a1a3b679SAndreas Boehler        return [
114*a1a3b679SAndreas Boehler            'name'        => $this->getPluginName(),
115*a1a3b679SAndreas Boehler            'description' => 'This plugin allows users to store iCalendar subscriptions in their calendar-home.',
116*a1a3b679SAndreas Boehler            'link'        => null,
117*a1a3b679SAndreas Boehler        ];
118*a1a3b679SAndreas Boehler
119*a1a3b679SAndreas Boehler    }
120*a1a3b679SAndreas Boehler}
121