Changeset View
Changeset View
Standalone View
Standalone View
plugins/libkolab/lib/kolab_format.php
Show First 20 Lines • Show All 411 Lines • ▼ Show 20 Lines | abstract class kolab_format | ||||
/** | /** | ||||
* Save the last generated UID to the object properties. | * Save the last generated UID to the object properties. | ||||
* Should be called after kolabformat::writeXXXX(); | * Should be called after kolabformat::writeXXXX(); | ||||
*/ | */ | ||||
protected function update_uid() | protected function update_uid() | ||||
{ | { | ||||
// get generated UID | // get generated UID | ||||
if (!$this->data['uid']) { | if (!($this->data['uid'] ?? null)) { | ||||
if ($this->xmlobject) { | if ($this->xmlobject) { | ||||
$this->data['uid'] = $this->xmlobject->getSerializedUID(); | $this->data['uid'] = $this->xmlobject->getSerializedUID(); | ||||
} | } | ||||
if (empty($this->data['uid'])) { | if (empty($this->data['uid'])) { | ||||
$this->data['uid'] = kolabformat::getSerializedUID(); | $this->data['uid'] = kolabformat::getSerializedUID(); | ||||
} | } | ||||
$this->obj->setUid($this->data['uid']); | $this->obj->setUid($this->data['uid']); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | public function set(&$object) | ||||
$this->init(); | $this->init(); | ||||
if (!empty($object['uid'])) | if (!empty($object['uid'])) | ||||
$this->obj->setUid($object['uid']); | $this->obj->setUid($object['uid']); | ||||
// set some automatic values if missing | // set some automatic values if missing | ||||
if (method_exists($this->obj, 'setCreated')) { | if (method_exists($this->obj, 'setCreated')) { | ||||
// Always set created date to workaround libkolabxml (>1.1.4) bug | // Always set created date to workaround libkolabxml (>1.1.4) bug | ||||
$created = $object['created'] ?: new DateTime('now'); | $created = $object['created'] ?? new DateTime('now'); | ||||
$created->setTimezone(new DateTimeZone('UTC')); // must be UTC | $created->setTimezone(new DateTimeZone('UTC')); // must be UTC | ||||
$this->obj->setCreated(self::get_datetime($created)); | $this->obj->setCreated(self::get_datetime($created)); | ||||
$object['created'] = $created; | $object['created'] = $created; | ||||
} | } | ||||
$object['changed'] = new DateTime('now', new DateTimeZone('UTC')); | $object['changed'] = new DateTime('now', new DateTimeZone('UTC')); | ||||
$this->obj->setLastModified(self::get_datetime($object['changed'])); | $this->obj->setLastModified(self::get_datetime($object['changed'])); | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public function to_array($data = array()) | ||||
$object['x-custom'][] = array($cp->identifier, $cp->value); | $object['x-custom'][] = array($cp->identifier, $cp->value); | ||||
} | } | ||||
} | } | ||||
// merge with additional data, e.g. attachments from the message | // merge with additional data, e.g. attachments from the message | ||||
if ($data) { | if ($data) { | ||||
foreach ($data as $idx => $value) { | foreach ($data as $idx => $value) { | ||||
if (is_array($value)) { | if (is_array($value)) { | ||||
$object[$idx] = array_merge((array)$object[$idx], $value); | $object[$idx] = array_merge((array)($object[$idx] ?? []), $value); | ||||
} | } | ||||
else { | else { | ||||
$object[$idx] = $value; | $object[$idx] = $value; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $object; | return $object; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | abstract class kolab_format | ||||
* | * | ||||
* @param array Object data as hash array | * @param array Object data as hash array | ||||
* @param boolean True to always overwrite attachment information | * @param boolean True to always overwrite attachment information | ||||
*/ | */ | ||||
protected function set_attachments($object, $write = true) | protected function set_attachments($object, $write = true) | ||||
{ | { | ||||
// save attachments | // save attachments | ||||
$vattach = new vectorattachment; | $vattach = new vectorattachment; | ||||
foreach ((array) $object['_attachments'] as $cid => $attr) { | foreach ((array)($object['_attachments'] ?? []) as $cid => $attr) { | ||||
if (empty($attr)) | if (empty($attr)) | ||||
continue; | continue; | ||||
$attach = new Attachment; | $attach = new Attachment; | ||||
$attach->setLabel((string)$attr['name']); | $attach->setLabel((string)$attr['name']); | ||||
$attach->setUri('cid:' . $cid, $attr['mimetype'] ?: 'application/octet-stream'); | $attach->setUri('cid:' . $cid, $attr['mimetype'] ?: 'application/octet-stream'); | ||||
if ($attach->isValid()) { | if ($attach->isValid()) { | ||||
$vattach->push($attach); | $vattach->push($attach); | ||||
$write = true; | $write = true; | ||||
} | } | ||||
else { | else { | ||||
rcube::raise_error(array( | rcube::raise_error(array( | ||||
'code' => 660, | 'code' => 660, | ||||
'type' => 'php', | 'type' => 'php', | ||||
'file' => __FILE__, | 'file' => __FILE__, | ||||
'line' => __LINE__, | 'line' => __LINE__, | ||||
'message' => "Invalid attributes for attachment $cid: " . var_export($attr, true), | 'message' => "Invalid attributes for attachment $cid: " . var_export($attr, true), | ||||
), true); | ), true); | ||||
} | } | ||||
} | } | ||||
foreach ((array) $object['links'] as $link) { | foreach ((array)($object['links'] ?? []) as $link) { | ||||
$attach = new Attachment; | $attach = new Attachment; | ||||
$attach->setUri($link, 'unknown'); | $attach->setUri($link, 'unknown'); | ||||
$vattach->push($attach); | $vattach->push($attach); | ||||
$write = true; | $write = true; | ||||
} | } | ||||
if ($write) { | if ($write) { | ||||
$this->obj->setAttachments($vattach); | $this->obj->setAttachments($vattach); | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |