stringproperty.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * ownCloud - VObject String Property
  4. *
  5. * This class adds escaping of simple string properties.
  6. *
  7. * @author Thomas Tanghus
  8. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This library 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
  21. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\VObject;
  25. /**
  26. * This class overrides \Sabre\VObject\Property::serialize() properly
  27. * escape commas and semi-colons in string properties.
  28. */
  29. class StringProperty extends \Sabre\VObject\Property {
  30. /**
  31. * Turns the object back into a serialized blob.
  32. *
  33. * @return string
  34. */
  35. public function serialize() {
  36. $str = $this->name;
  37. if ($this->group) {
  38. $str = $this->group . '.' . $this->name;
  39. }
  40. foreach($this->parameters as $param) {
  41. $str.=';' . $param->serialize();
  42. }
  43. $src = array(
  44. '\\',
  45. "\n",
  46. ';',
  47. ',',
  48. );
  49. $out = array(
  50. '\\\\',
  51. '\n',
  52. '\;',
  53. '\,',
  54. );
  55. $value = strtr($this->value, array('\,' => ',', '\;' => ';', '\\\\' => '\\'));
  56. $str.=':' . str_replace($src, $out, $value);
  57. $out = '';
  58. while(strlen($str) > 0) {
  59. if (strlen($str) > 75) {
  60. $out .= mb_strcut($str, 0, 75, 'utf-8') . "\r\n";
  61. $str = ' ' . mb_strcut($str, 75, strlen($str), 'utf-8');
  62. } else {
  63. $out .= $str . "\r\n";
  64. $str = '';
  65. break;
  66. }
  67. }
  68. return $out;
  69. }
  70. }