Plugin.php 3.0 KB

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