Uri.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Sabre\VObject\Property;
  3. use Sabre\VObject\Property;
  4. /**
  5. * URI property
  6. *
  7. * This object encodes URI values. vCard 2.1 calls these URL.
  8. *
  9. * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved.
  10. * @author Evert Pot (http://evertpot.com/)
  11. * @license http://sabre.io/license/ Modified BSD License
  12. */
  13. class Uri extends Text {
  14. /**
  15. * In case this is a multi-value property. This string will be used as a
  16. * delimiter.
  17. *
  18. * @var string|null
  19. */
  20. public $delimiter = null;
  21. /**
  22. * Returns the type of value.
  23. *
  24. * This corresponds to the VALUE= parameter. Every property also has a
  25. * 'default' valueType.
  26. *
  27. * @return string
  28. */
  29. public function getValueType() {
  30. return "URI";
  31. }
  32. /**
  33. * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
  34. *
  35. * This has been 'unfolded', so only 1 line will be passed. Unescaping is
  36. * not yet done, but parameters are not included.
  37. *
  38. * @param string $val
  39. * @return void
  40. */
  41. public function setRawMimeDirValue($val) {
  42. // Normally we don't need to do any type of unescaping for these
  43. // properties, however.. we've noticed that Google Contacts
  44. // specifically escapes the colon (:) with a blackslash. While I have
  45. // no clue why they thought that was a good idea, I'm unescaping it
  46. // anyway.
  47. //
  48. // Good thing backslashes are not allowed in urls. Makes it easy to
  49. // assume that a backslash is always intended as an escape character.
  50. if ($this->name === 'URL') {
  51. $regex = '# (?: (\\\\ (?: \\\\ | : ) ) ) #x';
  52. $matches = preg_split($regex, $val, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  53. $newVal = '';
  54. foreach($matches as $match) {
  55. switch($match) {
  56. case '\:' :
  57. $newVal.=':';
  58. break;
  59. default :
  60. $newVal.=$match;
  61. break;
  62. }
  63. }
  64. $this->value = $newVal;
  65. } else {
  66. $this->value = $val;
  67. }
  68. }
  69. /**
  70. * Returns a raw mime-dir representation of the value.
  71. *
  72. * @return string
  73. */
  74. public function getRawMimeDirValue() {
  75. if (is_array($this->value)) {
  76. return $this->value[0];
  77. } else {
  78. return $this->value;
  79. }
  80. }
  81. }