compoundproperty.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * ownCloud - VObject Compound Property
  4. *
  5. * @author Thomas Tanghus
  6. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OC\VObject;
  23. /**
  24. * This class overrides \Sabre\VObject\Property::serialize() to not
  25. * double escape commas and semi-colons in compound properties.
  26. */
  27. class CompoundProperty extends \Sabre\VObject\Property\Compound {
  28. /**
  29. * Turns the object back into a serialized blob.
  30. *
  31. * @return string
  32. */
  33. public function serialize() {
  34. $str = $this->name;
  35. if ($this->group) {
  36. $str = $this->group . '.' . $this->name;
  37. }
  38. foreach($this->parameters as $param) {
  39. $str.=';' . $param->serialize();
  40. }
  41. $src = array(
  42. "\n",
  43. );
  44. $out = array(
  45. '\n',
  46. );
  47. $str.=':' . str_replace($src, $out, $this->value);
  48. $out = '';
  49. while(strlen($str) > 0) {
  50. if (strlen($str) > 75) {
  51. $out .= mb_strcut($str, 0, 75, 'utf-8') . "\r\n";
  52. $str = ' ' . mb_strcut($str, 75, strlen($str), 'utf-8');
  53. } else {
  54. $out .= $str . "\r\n";
  55. $str = '';
  56. break;
  57. }
  58. }
  59. return $out;
  60. }
  61. }