|
4
|
1 <?php
|
|
|
2
|
|
|
3 namespace Sabre\VObject\Component;
|
|
|
4
|
|
|
5 use Sabre\VObject;
|
|
|
6
|
|
|
7 /**
|
|
|
8 * The VCard component
|
|
|
9 *
|
|
|
10 * This component represents the BEGIN:VCARD and END:VCARD found in every
|
|
|
11 * vcard.
|
|
|
12 *
|
|
|
13 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
|
|
|
14 * @author Evert Pot (http://evertpot.com/)
|
|
|
15 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
|
|
16 */
|
|
|
17 class VCard extends VObject\Component {
|
|
|
18
|
|
|
19 static $defaultName = 'VCARD';
|
|
|
20
|
|
|
21 /**
|
|
|
22 * VCards with version 2.1, 3.0 and 4.0 are found.
|
|
|
23 *
|
|
|
24 * If the VCARD doesn't know its version, 4.0 is assumed.
|
|
|
25 */
|
|
|
26 const DEFAULT_VERSION = '4.0';
|
|
|
27
|
|
|
28 /**
|
|
|
29 * Validates the node for correctness.
|
|
|
30 *
|
|
|
31 * The following options are supported:
|
|
|
32 * - Node::REPAIR - If something is broken, and automatic repair may
|
|
|
33 * be attempted.
|
|
|
34 *
|
|
|
35 * An array is returned with warnings.
|
|
|
36 *
|
|
|
37 * Every item in the array has the following properties:
|
|
|
38 * * level - (number between 1 and 3 with severity information)
|
|
|
39 * * message - (human readable message)
|
|
|
40 * * node - (reference to the offending node)
|
|
|
41 *
|
|
|
42 * @param int $options
|
|
|
43 * @return array
|
|
|
44 */
|
|
|
45 public function validate($options = 0) {
|
|
|
46
|
|
|
47 $warnings = array();
|
|
|
48
|
|
|
49 $version = $this->select('VERSION');
|
|
|
50 if (count($version)!==1) {
|
|
|
51 $warnings[] = array(
|
|
|
52 'level' => 1,
|
|
|
53 'message' => 'The VERSION property must appear in the VCARD component exactly 1 time',
|
|
|
54 'node' => $this,
|
|
|
55 );
|
|
|
56 if ($options & self::REPAIR) {
|
|
|
57 $this->VERSION = self::DEFAULT_VERSION;
|
|
|
58 }
|
|
|
59 } else {
|
|
|
60 $version = (string)$this->VERSION;
|
|
|
61 if ($version!=='2.1' && $version!=='3.0' && $version!=='4.0') {
|
|
|
62 $warnings[] = array(
|
|
|
63 'level' => 1,
|
|
|
64 'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
|
|
|
65 'node' => $this,
|
|
|
66 );
|
|
|
67 if ($options & self::REPAIR) {
|
|
|
68 $this->VERSION = '4.0';
|
|
|
69 }
|
|
|
70 }
|
|
|
71
|
|
|
72 }
|
|
|
73 $fn = $this->select('FN');
|
|
|
74 if (count($fn)!==1) {
|
|
|
75 $warnings[] = array(
|
|
|
76 'level' => 1,
|
|
|
77 'message' => 'The FN property must appear in the VCARD component exactly 1 time',
|
|
|
78 'node' => $this,
|
|
|
79 );
|
|
|
80 if (($options & self::REPAIR) && count($fn) === 0) {
|
|
|
81 // We're going to try to see if we can use the contents of the
|
|
|
82 // N property.
|
|
|
83 if (isset($this->N)) {
|
|
|
84 $value = explode(';', (string)$this->N);
|
|
|
85 if (isset($value[1]) && $value[1]) {
|
|
|
86 $this->FN = $value[1] . ' ' . $value[0];
|
|
|
87 } else {
|
|
|
88 $this->FN = $value[0];
|
|
|
89 }
|
|
|
90
|
|
|
91 // Otherwise, the ORG property may work
|
|
|
92 } elseif (isset($this->ORG)) {
|
|
|
93 $this->FN = (string)$this->ORG;
|
|
|
94 }
|
|
|
95
|
|
|
96 }
|
|
|
97 }
|
|
|
98
|
|
|
99 return array_merge(
|
|
|
100 parent::validate($options),
|
|
|
101 $warnings
|
|
|
102 );
|
|
|
103
|
|
|
104 }
|
|
|
105
|
|
|
106 }
|
|
|
107
|