You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalendarObject.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2017, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\CalDAV;
  25. use Sabre\VObject\Component;
  26. use Sabre\VObject\Property;
  27. use Sabre\VObject\Reader;
  28. class CalendarObject extends \Sabre\CalDAV\CalendarObject {
  29. /**
  30. * @inheritdoc
  31. */
  32. function get() {
  33. $data = parent::get();
  34. if (!$this->isShared()) {
  35. return $data;
  36. }
  37. $vObject = Reader::read($data);
  38. // remove VAlarms if calendar is shared read-only
  39. if (!$this->canWrite()) {
  40. $this->removeVAlarms($vObject);
  41. }
  42. // shows as busy if event is declared confidential
  43. if ($this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) {
  44. $this->createConfidentialObject($vObject);
  45. }
  46. return $vObject->serialize();
  47. }
  48. protected function isShared() {
  49. if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
  50. return false;
  51. }
  52. return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
  53. }
  54. /**
  55. * @param Component\VCalendar $vObject
  56. * @return void
  57. */
  58. private static function createConfidentialObject(Component\VCalendar $vObject) {
  59. /** @var Component $vElement */
  60. $vElement = null;
  61. if(isset($vObject->VEVENT)) {
  62. $vElement = $vObject->VEVENT;
  63. }
  64. if(isset($vObject->VJOURNAL)) {
  65. $vElement = $vObject->VJOURNAL;
  66. }
  67. if(isset($vObject->VTODO)) {
  68. $vElement = $vObject->VTODO;
  69. }
  70. if(!is_null($vElement)) {
  71. foreach ($vElement->children() as &$property) {
  72. /** @var Property $property */
  73. switch($property->name) {
  74. case 'CREATED':
  75. case 'DTSTART':
  76. case 'RRULE':
  77. case 'DURATION':
  78. case 'DTEND':
  79. case 'CLASS':
  80. case 'UID':
  81. break;
  82. case 'SUMMARY':
  83. $property->setValue('Busy');
  84. break;
  85. default:
  86. $vElement->__unset($property->name);
  87. unset($property);
  88. break;
  89. }
  90. }
  91. }
  92. }
  93. /**
  94. * @param Component\VCalendar $vObject
  95. * @return void
  96. */
  97. private function removeVAlarms(Component\VCalendar $vObject) {
  98. $subcomponents = $vObject->getComponents();
  99. foreach($subcomponents as $subcomponent) {
  100. unset($subcomponent->VALARM);
  101. }
  102. }
  103. /**
  104. * @return bool
  105. */
  106. private function canWrite() {
  107. if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
  108. return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
  109. }
  110. return true;
  111. }
  112. }