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.

Publisher.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Thomas Citharel <tcit@tcit.fr>
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. * @author Thomas Citharel <nextcloud@tcit.fr>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  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
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\CalDAV\Publishing\Xml;
  25. use Sabre\Xml\Writer;
  26. use Sabre\Xml\XmlSerializable;
  27. class Publisher implements XmlSerializable {
  28. /**
  29. * @var string $publishUrl
  30. */
  31. protected $publishUrl;
  32. /**
  33. * @var boolean $isPublished
  34. */
  35. protected $isPublished;
  36. /**
  37. * @param string $publishUrl
  38. * @param boolean $isPublished
  39. */
  40. function __construct($publishUrl, $isPublished) {
  41. $this->publishUrl = $publishUrl;
  42. $this->isPublished = $isPublished;
  43. }
  44. /**
  45. * @return string
  46. */
  47. function getValue() {
  48. return $this->publishUrl;
  49. }
  50. /**
  51. * The xmlSerialize metod is called during xml writing.
  52. *
  53. * Use the $writer argument to write its own xml serialization.
  54. *
  55. * An important note: do _not_ create a parent element. Any element
  56. * implementing XmlSerializble should only ever write what's considered
  57. * its 'inner xml'.
  58. *
  59. * The parent of the current element is responsible for writing a
  60. * containing element.
  61. *
  62. * This allows serializers to be re-used for different element names.
  63. *
  64. * If you are opening new elements, you must also close them again.
  65. *
  66. * @param Writer $writer
  67. * @return void
  68. */
  69. function xmlSerialize(Writer $writer) {
  70. if (!$this->isPublished) {
  71. // for pre-publish-url
  72. $writer->write($this->publishUrl);
  73. } else {
  74. // for publish-url
  75. $writer->writeElement('{DAV:}href', $this->publishUrl);
  76. }
  77. }
  78. }