Changeset View
Changeset View
Standalone View
Standalone View
plugins/kolab_notes/kolab_notes.php
Show First 20 Lines • Show All 534 Lines • ▼ Show 20 Lines | public function get_note($note) | ||||
$list_id = $note['list']; | $list_id = $note['list']; | ||||
} | } | ||||
else { | else { | ||||
$uid = $note; | $uid = $note; | ||||
} | } | ||||
// deliver from in-memory cache | // deliver from in-memory cache | ||||
$key = $list_id . ':' . $uid; | $key = $list_id . ':' . $uid; | ||||
if ($this->cache[$key]) { | if ($this->cache[$key] ?? false) { | ||||
return $this->cache[$key]; | return $this->cache[$key]; | ||||
} | } | ||||
$result = false; | $result = false; | ||||
$this->_read_lists(); | $this->_read_lists(); | ||||
if ($list_id) { | if ($list_id) { | ||||
if ($folder = $this->get_folder($list_id)) { | if ($folder = $this->get_folder($list_id)) { | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | class kolab_notes extends rcube_plugin | ||||
{ | { | ||||
$this->_read_lists(); | $this->_read_lists(); | ||||
$list_id = $note['list']; | $list_id = $note['list']; | ||||
if (!$list_id || !($folder = $this->get_folder($list_id))) | if (!$list_id || !($folder = $this->get_folder($list_id))) | ||||
return false; | return false; | ||||
// moved from another folder | // moved from another folder | ||||
if ($note['_fromlist'] && ($fromfolder = $this->get_folder($note['_fromlist']))) { | if (($note['_fromlist'] ?? false) && ($fromfolder = $this->get_folder($note['_fromlist']))) { | ||||
if (!$fromfolder->move($note['uid'], $folder->name)) | if (!$fromfolder->move($note['uid'], $folder->name)) | ||||
return false; | return false; | ||||
unset($note['_fromlist']); | unset($note['_fromlist']); | ||||
} | } | ||||
// load previous version of this record to merge | // load previous version of this record to merge | ||||
$old = null; | |||||
if ($note['uid']) { | if ($note['uid']) { | ||||
$old = $folder->get_object($note['uid']); | $old = $folder->get_object($note['uid']); | ||||
if (!$old || PEAR::isError($old)) | if (!$old || PEAR::isError($old)) | ||||
return false; | return false; | ||||
// merge existing properties if the update isn't complete | // merge existing properties if the update isn't complete | ||||
if (!isset($note['title']) || !isset($note['description'])) | if (!isset($note['title']) || !isset($note['description'])) | ||||
$note += $old; | $note += $old; | ||||
} | } | ||||
// generate new note object from input | // generate new note object from input | ||||
$object = $this->_write_preprocess($note, $old); | $object = $this->_write_preprocess($note, $old); | ||||
// email links and tags are handled separately | // email links and tags are handled separately | ||||
$links = $object['links']; | $links = $object['links'] ?? null; | ||||
$tags = $object['tags']; | $tags = $object['tags'] ?? null; | ||||
unset($object['links']); | unset($object['links']); | ||||
unset($object['tags']); | unset($object['tags']); | ||||
$saved = $folder->save($object, 'note', $note['uid']); | $saved = $folder->save($object, 'note', $note['uid']); | ||||
if (!$saved) { | if (!$saved) { | ||||
rcube::raise_error(array( | rcube::raise_error(array( | ||||
▲ Show 20 Lines • Show All 600 Lines • ▼ Show 20 Lines | private function _write_preprocess($note, $old = array()) | ||||
// TODO: handle attachments | // TODO: handle attachments | ||||
// convert link references into simple URIs | // convert link references into simple URIs | ||||
if (array_key_exists('links', $note)) { | if (array_key_exists('links', $note)) { | ||||
$object['links'] = array_map(function($link){ return is_array($link) ? $link['uri'] : strval($link); }, $note['links']); | $object['links'] = array_map(function($link){ return is_array($link) ? $link['uri'] : strval($link); }, $note['links']); | ||||
} | } | ||||
else { | else { | ||||
$object['links'] = $old['links']; | if ($old) { | ||||
$object['links'] = $old['links'] ?? null; | |||||
} | |||||
} | } | ||||
// clean up HTML content | // clean up HTML content | ||||
$object['description'] = $this->_wash_html($note['description']); | $object['description'] = $this->_wash_html($note['description']); | ||||
$is_html = true; | $is_html = true; | ||||
// try to be smart and convert to plain-text if no real formatting is detected | // try to be smart and convert to plain-text if no real formatting is detected | ||||
if (preg_match('!<body><(?:p|pre)>(.*)</(?:p|pre)></body>!Uims', $object['description'], $m)) { | if (preg_match('!<body><(?:p|pre)>(.*)</(?:p|pre)></body>!Uims', $object['description'], $m)) { | ||||
Show All 15 Lines | private function _write_preprocess($note, $old = array()) | ||||
// copy meta data (starting with _) from old object | // copy meta data (starting with _) from old object | ||||
foreach ((array)$old as $key => $val) { | foreach ((array)$old as $key => $val) { | ||||
if (!isset($object[$key]) && $key[0] == '_') | if (!isset($object[$key]) && $key[0] == '_') | ||||
$object[$key] = $val; | $object[$key] = $val; | ||||
} | } | ||||
// make list of categories unique | // make list of categories unique | ||||
if (is_array($object['tags'])) { | if (is_array($object['tags'] ?? null)) { | ||||
$object['tags'] = array_unique(array_filter($object['tags'])); | $object['tags'] = array_unique(array_filter($object['tags'])); | ||||
} | } | ||||
unset($object['list'], $object['tempid'], $object['created'], $object['changed'], $object['created_'], $object['changed_']); | unset($object['list'], $object['tempid'], $object['created'], $object['changed'], $object['created_'], $object['changed_']); | ||||
return $object; | return $object; | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |