Skip to content

Commit

Permalink
Idea for sabre-io#589
Browse files Browse the repository at this point in the history
  • Loading branch information
djmaze committed Nov 14, 2023
1 parent 154a84d commit cb9ebb8
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Component/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class VCard extends VObject\Document
'HOBBY' => VObject\Property\FlatText::class,
'INTEREST' => VObject\Property\FlatText::class,
'ORG-DIRECTORY' => VObject\Property\FlatText::class,

'X-CRYPTO' => VObject\Property\XCrypto::class,
];

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/Parser/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ public function parseProperty(array $jProp): Property
unset($parameters['group']);
}

if ('X-CRYPTO' === $propertyName) {
$propertyType = 'X-CRYPTO';
}

$prop = $this->root->createProperty($propertyName, null, $parameters, $valueType);
$prop->setJsonValue($value);

Expand Down
21 changes: 21 additions & 0 deletions lib/Parser/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ protected function parseProperties(Component $parentComponent, string $propertyN
}
break;

case 'xcard:x-crypto':
foreach ($xmlProperty['value'] as $i => $xmlPropertyChild) {
if (is_array($xmlPropertyChild)) {
$propertyParameterValues = [];
foreach ($xmlPropertyChild['value'] as $xmlParameter) {
if (is_array($xmlParameter['value'])) {
foreach ($xmlParameter['value'] as $xmlParameterValues) {
$propertyParameterValues[] = $xmlParameterValues['value'];
}
} else {
$propertyParameterValues[] = $xmlParameter['value'];
}
}
$propertyParameters[static::getTagName($xmlPropertyChild['name'])]
= implode(',', $propertyParameterValues);
}
array_splice($xmlProperty['value'], $i, 1);
}
$propertyType = 'X-CRYPTO';
break;

default:
$propertyType = static::getTagName($xmlProperty['value'][0]['name']);

Expand Down
74 changes: 74 additions & 0 deletions lib/Property/XCrypto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Sabre\VObject\Property;

use Sabre\VObject\Property;
//use Sabre\VObject\Property\Text;

/**
* XCrypto property.
*
* This object encodes X-CRYPTO values, as defined in KDE KAddressBook
*
* @copyright Copyright (C) SnappyMail (https://snappymail.eu/)
* @author DJMaze (https://snappymail.eu/)
* @license http://sabre.io/license/ Modified BSD License
*
* https://github.com/sabre-io/vobject/issues/589
*/

class XCrypto extends Property
//class XCrypto extends Text
{
/**
* Returns the type of value.
*
* This corresponds to the VALUE= parameter. Every property also has a
* 'default' valueType.
*
* @return string
*/
public function getValueType()
{
return 'X-CRYPTO';
}

/**
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
*
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
* not yet done, but parameters are not included.
*
* @param string $val
*/
public function setRawMimeDirValue($val)
{
error_log("setRawMimeDirValue({$val})");
// $this->setValue(MimeDir::unescapeValue($val, $this->delimiter));
}

/**
* Returns a raw mime-dir representation of the value.
*
* @return string
*/
public function getRawMimeDirValue()
{
$result = [];
foreach ($this->parameters as $parameter) {
$result[] = strtolower($parameter->name) . '=' . $parameter->getValue();
}
return implode(',', $result);
}

public function xmlSerialize(\Sabre\Xml\Writer $writer): void
{
$writer->startElement(strtolower($this->name));
foreach ($this->parameters as $parameter) {
$writer->startElement(strtolower($parameter->name));
$writer->write($parameter);
$writer->endElement();
}
$writer->endElement();
}
}

0 comments on commit cb9ebb8

Please sign in to comment.