@@ -36,116 +36,116 @@ |
||
| 36 | 36 | |
| 37 | 37 | class Plugin extends ServerPlugin { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * list of regular expressions for calendar user agents, |
|
| 41 | - * that do not support subscriptions on their own |
|
| 42 | - * |
|
| 43 | - * /^MSFT-WIN-3/ - Windows 10 Calendar |
|
| 44 | - * @var string[] |
|
| 45 | - */ |
|
| 46 | - public const ENABLE_FOR_CLIENTS = [ |
|
| 47 | - "/^MSFT-WIN-3/" |
|
| 48 | - ]; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var bool |
|
| 52 | - */ |
|
| 53 | - private $enabled = false; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var Server |
|
| 57 | - */ |
|
| 58 | - private $server; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Plugin constructor. |
|
| 62 | - * |
|
| 63 | - * @param IRequest $request |
|
| 64 | - */ |
|
| 65 | - public function __construct(IRequest $request) { |
|
| 66 | - if ($request->isUserAgent(self::ENABLE_FOR_CLIENTS)) { |
|
| 67 | - $this->enabled = true; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $magicHeader = $request->getHeader('X-NC-CalDAV-Webcal-Caching'); |
|
| 71 | - if ($magicHeader === 'On') { |
|
| 72 | - $this->enabled = true; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * This initializes the plugin. |
|
| 78 | - * |
|
| 79 | - * This function is called by Sabre\DAV\Server, after |
|
| 80 | - * addPlugin is called. |
|
| 81 | - * |
|
| 82 | - * This method should set up the required event subscriptions. |
|
| 83 | - * |
|
| 84 | - * @param Server $server |
|
| 85 | - */ |
|
| 86 | - public function initialize(Server $server) { |
|
| 87 | - $this->server = $server; |
|
| 88 | - $server->on('beforeMethod:*', [$this, 'beforeMethod']); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param RequestInterface $request |
|
| 93 | - * @param ResponseInterface $response |
|
| 94 | - */ |
|
| 95 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
| 96 | - if (!$this->enabled) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $path = $request->getPath(); |
|
| 101 | - $pathParts = explode('/', ltrim($path, '/')); |
|
| 102 | - if (\count($pathParts) < 2) { |
|
| 103 | - return; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // $calendarHomePath will look like: calendars/username |
|
| 107 | - $calendarHomePath = $pathParts[0] . '/' . $pathParts[1]; |
|
| 108 | - try { |
|
| 109 | - $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath); |
|
| 110 | - if (!($calendarHome instanceof CalendarHome)) { |
|
| 111 | - //how did we end up here? |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $calendarHome->enableCachedSubscriptionsForThisRequest(); |
|
| 116 | - } catch (NotFound $ex) { |
|
| 117 | - return; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return bool |
|
| 123 | - */ |
|
| 124 | - public function isCachingEnabledForThisRequest():bool { |
|
| 125 | - return $this->enabled; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * This method should return a list of server-features. |
|
| 130 | - * |
|
| 131 | - * This is for example 'versioning' and is added to the DAV: header |
|
| 132 | - * in an OPTIONS response. |
|
| 133 | - * |
|
| 134 | - * @return string[] |
|
| 135 | - */ |
|
| 136 | - public function getFeatures():array { |
|
| 137 | - return ['nc-calendar-webcal-cache']; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns a plugin name. |
|
| 142 | - * |
|
| 143 | - * Using this name other plugins will be able to access other plugins |
|
| 144 | - * using Sabre\DAV\Server::getPlugin |
|
| 145 | - * |
|
| 146 | - * @return string |
|
| 147 | - */ |
|
| 148 | - public function getPluginName():string { |
|
| 149 | - return 'nc-calendar-webcal-cache'; |
|
| 150 | - } |
|
| 39 | + /** |
|
| 40 | + * list of regular expressions for calendar user agents, |
|
| 41 | + * that do not support subscriptions on their own |
|
| 42 | + * |
|
| 43 | + * /^MSFT-WIN-3/ - Windows 10 Calendar |
|
| 44 | + * @var string[] |
|
| 45 | + */ |
|
| 46 | + public const ENABLE_FOR_CLIENTS = [ |
|
| 47 | + "/^MSFT-WIN-3/" |
|
| 48 | + ]; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var bool |
|
| 52 | + */ |
|
| 53 | + private $enabled = false; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var Server |
|
| 57 | + */ |
|
| 58 | + private $server; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Plugin constructor. |
|
| 62 | + * |
|
| 63 | + * @param IRequest $request |
|
| 64 | + */ |
|
| 65 | + public function __construct(IRequest $request) { |
|
| 66 | + if ($request->isUserAgent(self::ENABLE_FOR_CLIENTS)) { |
|
| 67 | + $this->enabled = true; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $magicHeader = $request->getHeader('X-NC-CalDAV-Webcal-Caching'); |
|
| 71 | + if ($magicHeader === 'On') { |
|
| 72 | + $this->enabled = true; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * This initializes the plugin. |
|
| 78 | + * |
|
| 79 | + * This function is called by Sabre\DAV\Server, after |
|
| 80 | + * addPlugin is called. |
|
| 81 | + * |
|
| 82 | + * This method should set up the required event subscriptions. |
|
| 83 | + * |
|
| 84 | + * @param Server $server |
|
| 85 | + */ |
|
| 86 | + public function initialize(Server $server) { |
|
| 87 | + $this->server = $server; |
|
| 88 | + $server->on('beforeMethod:*', [$this, 'beforeMethod']); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @param RequestInterface $request |
|
| 93 | + * @param ResponseInterface $response |
|
| 94 | + */ |
|
| 95 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
| 96 | + if (!$this->enabled) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $path = $request->getPath(); |
|
| 101 | + $pathParts = explode('/', ltrim($path, '/')); |
|
| 102 | + if (\count($pathParts) < 2) { |
|
| 103 | + return; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // $calendarHomePath will look like: calendars/username |
|
| 107 | + $calendarHomePath = $pathParts[0] . '/' . $pathParts[1]; |
|
| 108 | + try { |
|
| 109 | + $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath); |
|
| 110 | + if (!($calendarHome instanceof CalendarHome)) { |
|
| 111 | + //how did we end up here? |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $calendarHome->enableCachedSubscriptionsForThisRequest(); |
|
| 116 | + } catch (NotFound $ex) { |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return bool |
|
| 123 | + */ |
|
| 124 | + public function isCachingEnabledForThisRequest():bool { |
|
| 125 | + return $this->enabled; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * This method should return a list of server-features. |
|
| 130 | + * |
|
| 131 | + * This is for example 'versioning' and is added to the DAV: header |
|
| 132 | + * in an OPTIONS response. |
|
| 133 | + * |
|
| 134 | + * @return string[] |
|
| 135 | + */ |
|
| 136 | + public function getFeatures():array { |
|
| 137 | + return ['nc-calendar-webcal-cache']; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns a plugin name. |
|
| 142 | + * |
|
| 143 | + * Using this name other plugins will be able to access other plugins |
|
| 144 | + * using Sabre\DAV\Server::getPlugin |
|
| 145 | + * |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | + public function getPluginName():string { |
|
| 149 | + return 'nc-calendar-webcal-cache'; |
|
| 150 | + } |
|
| 151 | 151 | } |