34 $inputVersion = $input->getDocumentType();
35 if ($inputVersion === $targetVersion) {
40 throw new \InvalidArgumentException(
'Only vCard 2.1, 3.0 and 4.0 are supported for the input data');
43 throw new \InvalidArgumentException(
'You can only use vCard 3.0 or 4.0 for the target version');
49 'VERSION' => $newVersion,
55 foreach ($input->children() as $property) {
78 if (in_array($property->name, [
'VERSION',
'PRODID'])) {
84 if (isset($parameters[
'VALUE'])) {
85 $valueType = $parameters[
'VALUE']->getValue();
86 unset($parameters[
'VALUE']);
91 $newProperty = $output->createProperty(
101 if ($property instanceof
Property\
Uri && in_array($property->name, [
'PHOTO',
'LOGO',
'SOUND'])) {
105 } elseif ($property instanceof
Property\
VCard\DateAndOrTime) {
115 if (is_null($parts[
'year'])) {
116 $newValue =
'1604-' . $parts[
'month'] .
'-' . $parts[
'date'];
117 $newProperty->setValue($newValue);
118 $newProperty[
'X-APPLE-OMIT-YEAR'] =
'1604';
121 if ($newProperty->name ==
'ANNIVERSARY') {
123 $newProperty->name =
'X-ANNIVERSARY';
130 while ($output->select(
'ITEM' .
$x .
'.')) {
133 $output->add(
'ITEM' .
$x .
'.X-ABDATE', $newProperty->getValue(), [
'VALUE' =>
'DATE-AND-OR-TIME']);
134 $output->add(
'ITEM' .
$x .
'.X-ABLABEL',
'_$!<Anniversary>!$_');
137 } elseif ($property->name ===
'KIND') {
139 switch (strtolower($property->
getValue())) {
144 $newProperty = $output->createProperty(
'X-ABSHOWAS',
'COMPANY');
153 $newProperty = $output->createProperty(
'X-ADDRESSBOOKSERVER-KIND',
'GROUP');
163 if (in_array($property->name, [
'NAME',
'MAILER',
'LABEL',
'CLASS'])) {
171 } elseif ($property instanceof
Property\
VCard\DateAndOrTime && isset($parameters[
'X-APPLE-OMIT-YEAR'])) {
176 if ($parts[
'year'] === $property[
'X-APPLE-OMIT-YEAR']->getValue()) {
177 $newValue =
'--' . $parts[
'month'] .
'-' . $parts[
'date'];
178 $newProperty->setValue($newValue);
183 unset($parameters[
'X-APPLE-OMIT-YEAR']);
186 switch ($property->name) {
188 if (strtoupper($property->
getValue()) ===
'COMPANY') {
189 $newProperty = $output->createProperty(
'KIND',
'ORG');
192 case 'X-ADDRESSBOOKSERVER-KIND' :
193 if (strtoupper($property->
getValue()) ===
'GROUP') {
194 $newProperty = $output->createProperty(
'KIND',
'GROUP');
197 case 'X-ANNIVERSARY' :
198 $newProperty->name =
'ANNIVERSARY';
201 foreach ($output->select(
'ANNIVERSARY') as $anniversary) {
202 if ($anniversary->getValue() === $newProperty->getValue()) {
209 if (!$property->group) {
212 $label = $input->{$property->group .
'.X-ABLABEL'};
215 if (!$label || $label->getValue() !==
'_$!<Anniversary>!$_') {
221 foreach ($output->select(
'ANNIVERSARY') as $anniversary) {
222 if ($anniversary->getValue() === $newProperty->getValue()) {
226 $newProperty->name =
'ANNIVERSARY';
230 if ($newProperty->getValue() ===
'_$!<Anniversary>!$_') {
242 $newProperty->group = $property->group;
254 $tempProperty =
$output->createProperty($newProperty->name);
255 if ($tempProperty->getValueType() !== $newProperty->getValueType()) {
256 $newProperty[
'VALUE'] = $newProperty->getValueType();
278 $value = $newProperty->getValue();
279 $newProperty = $output->createProperty(
286 $mimeType =
'application/octet-stream';
289 if (isset($parameters[
'TYPE'])) {
292 foreach ($parameters[
'TYPE']->getParts() as $typePart) {
294 strtoupper($typePart),
295 [
'JPEG',
'PNG',
'GIF']
297 $mimeType =
'image/' . strtolower($typePart);
299 $newTypes[] = $typePart;
306 $parameters[
'TYPE']->setParts($newTypes);
308 unset($parameters[
'TYPE']);
313 $newProperty->setValue(
'data:' . $mimeType .
';base64,' . base64_encode($value));
332 $value = $newProperty->getValue();
335 if (substr($value, 0, 5) !==
'data:') {
339 $newProperty = $output->createProperty(
346 $mimeType = substr($value, 5, strpos($value,
',') - 5);
347 if (strpos($mimeType,
';')) {
348 $mimeType = substr($mimeType, 0, strpos($mimeType,
';'));
349 $newProperty->setValue(base64_decode(substr($value, strpos($value,
',') + 1)));
351 $newProperty->setValue(substr($value, strpos($value,
',') + 1));
355 $newProperty[
'ENCODING'] =
'b';
359 $newProperty[
'TYPE'] =
'JPEG';
362 $newProperty[
'TYPE'] =
'PNG';
365 $newProperty[
'TYPE'] =
'GIF';
386 foreach ($parameters as $param) {
389 if ($param->noName) $param->noName =
false;
391 switch ($param->name) {
396 foreach ($param->getParts() as $paramPart) {
398 if (strtoupper($paramPart) ===
'PREF') {
399 $newProperty->
add(
'PREF',
'1');
401 $newProperty->
add($param->name, $paramPart);
412 $newProperty->
add($param->name, $param->getParts());
432 foreach ($parameters as $param) {
435 if ($param->noName) $param->noName =
false;
437 switch ($param->name) {
442 if (strtoupper($param->getValue()) !==
'QUOTED-PRINTABLE') {
443 $newProperty->
add($param->name, $param->getParts());
453 if ($param->getValue() ==
'1') {
454 $newProperty->
add(
'TYPE',
'PREF');
459 $newProperty->
add($param->name, $param->getParts());
This utility converts vcards from one version to another.
convertUriToBinary(Component\VCard $output, Property\Uri $newProperty)
Converts a URI property to a BINARY property.
convert(Component\VCard $input, $targetVersion)
Converts a vCard object to a new version.
getValueType()
Returns the type of value.
getParts()
Returns a multi-valued property.
add($name, $value=null)
Adds a new parameter.
convertParameters30(Property $newProperty, array $parameters)
Adds parameters to a new property for vCard 3.0.
parameters()
Returns an iterable list of children.
convertParameters40(Property $newProperty, array $parameters)
Adds parameters to a new property for vCard 4.0.
convertBinaryToUri(Component\VCard $output, Property\Binary $newProperty, array &$parameters)
Converts a BINARY property to a URI property.
getValue()
Returns the current value.
convertProperty(Component\VCard $input, Component\VCard $output, Property $property, $targetVersion)
Handles conversion of a single property.
static parseVCardDateTime($date)
This method parses a vCard date and or time value.