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