CurrentUserPrivilegeSet.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * CurrentUserPrivilegeSet
  4. *
  5. * This class represents the current-user-privilege-set property. When
  6. * requested, it contain all the privileges a user has on a specific node.
  7. *
  8. * @package Sabre
  9. * @subpackage DAVACL
  10. * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
  11. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  12. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  13. */
  14. class Sabre_DAVACL_Property_CurrentUserPrivilegeSet extends Sabre_DAV_Property {
  15. /**
  16. * List of privileges
  17. *
  18. * @var array
  19. */
  20. private $privileges;
  21. /**
  22. * Creates the object
  23. *
  24. * Pass the privileges in clark-notation
  25. *
  26. * @param array $privileges
  27. */
  28. public function __construct(array $privileges) {
  29. $this->privileges = $privileges;
  30. }
  31. /**
  32. * Serializes the property in the DOM
  33. *
  34. * @param Sabre_DAV_Server $server
  35. * @param DOMElement $node
  36. * @return void
  37. */
  38. public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
  39. $doc = $node->ownerDocument;
  40. foreach($this->privileges as $privName) {
  41. $this->serializePriv($doc,$node,$privName);
  42. }
  43. }
  44. /**
  45. * Serializes one privilege
  46. *
  47. * @param DOMDocument $doc
  48. * @param DOMElement $node
  49. * @param string $privName
  50. * @return void
  51. */
  52. protected function serializePriv($doc,$node,$privName) {
  53. $xp = $doc->createElementNS('DAV:','d:privilege');
  54. $node->appendChild($xp);
  55. $privParts = null;
  56. preg_match('/^{([^}]*)}(.*)$/',$privName,$privParts);
  57. $xp->appendChild($doc->createElementNS($privParts[1],'d:'.$privParts[2]));
  58. }
  59. }