annotate plugins/libcalendaring/lib/Sabre/VObject/Component/VCard.php @ 4:888e774ee983

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