Changeset View
Changeset View
Standalone View
Standalone View
plugins/kolab_notes/kolab_notes.php
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | public function get_lists(&$tree = null) | ||||
'group' => 'other virtual', | 'group' => 'other virtual', | ||||
'class' => 'user', | 'class' => 'user', | ||||
'parent' => $parent_id, | 'parent' => $parent_id, | ||||
); | ); | ||||
} | } | ||||
else if ($folder->virtual) { | else if ($folder->virtual) { | ||||
$lists[$list_id] = array( | $lists[$list_id] = array( | ||||
'id' => $list_id, | 'id' => $list_id, | ||||
'name' => kolab_storage::object_name($fullname), | 'name' => $fullname, | ||||
'listname' => $listname, | 'listname' => $listname, | ||||
'virtual' => true, | 'virtual' => true, | ||||
'editable' => false, | 'editable' => false, | ||||
'rights' => 'l', | 'rights' => 'l', | ||||
'group' => $folder->get_namespace(), | 'group' => $folder->get_namespace(), | ||||
'parent' => $parent_id, | 'parent' => $parent_id, | ||||
); | ); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | class kolab_notes extends rcube_plugin | ||||
/** | /** | ||||
* Convert the given note records for delivery to the client | * Convert the given note records for delivery to the client | ||||
*/ | */ | ||||
protected function notes_data($records, &$tags) | protected function notes_data($records, &$tags) | ||||
{ | { | ||||
$config = kolab_storage_config::get_instance(); | $config = kolab_storage_config::get_instance(); | ||||
$tags = $config->apply_tags($records); | $tags = $config->apply_tags($records); | ||||
$config->apply_links($records); | |||||
foreach ($records as $i => $rec) { | foreach ($records as $i => $rec) { | ||||
unset($records[$i]['description']); | unset($records[$i]['description']); | ||||
$this->_client_encode($records[$i]); | $this->_client_encode($records[$i]); | ||||
} | } | ||||
return $records; | return $records; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | public function get_note($note) | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ($result) { | if ($result) { | ||||
// get note tags | // get note tags | ||||
$result['tags'] = $this->get_tags($result['uid']); | $result['tags'] = $this->get_tags($result['uid']); | ||||
// get note links | |||||
$result['links'] = $this->get_links($result['uid']); | |||||
} | } | ||||
return $result; | return $result; | ||||
} | } | ||||
/** | /** | ||||
* Helper method to encode the given note record for use in the client | * Helper method to encode the given note record for use in the client | ||||
*/ | */ | ||||
private function _client_encode(&$note, $resolve = false) | private function _client_encode(&$note) | ||||
{ | { | ||||
foreach ($note as $key => $prop) { | foreach ($note as $key => $prop) { | ||||
if ($key[0] == '_' || $key == 'x-custom') { | if ($key[0] == '_' || $key == 'x-custom') { | ||||
unset($note[$key]); | unset($note[$key]); | ||||
} | } | ||||
} | } | ||||
foreach (array('created','changed') as $key) { | foreach (array('created','changed') as $key) { | ||||
if (is_object($note[$key]) && $note[$key] instanceof DateTime) { | if (is_object($note[$key]) && $note[$key] instanceof DateTime) { | ||||
$note[$key.'_'] = $note[$key]->format('U'); | $note[$key.'_'] = $note[$key]->format('U'); | ||||
$note[$key] = $this->rc->format_date($note[$key]); | $note[$key] = $this->rc->format_date($note[$key]); | ||||
} | } | ||||
} | } | ||||
// clean HTML contents | // clean HTML contents | ||||
if (!empty($note['description']) && $this->is_html($note)) { | if (!empty($note['description']) && $this->is_html($note)) { | ||||
$note['html'] = $this->_wash_html($note['description']); | $note['html'] = $this->_wash_html($note['description']); | ||||
} | } | ||||
// resolve message links | // convert link URIs references into structs | ||||
$note['links'] = array_map(function($link) { | if (array_key_exists('links', $note)) { | ||||
return kolab_storage_config::get_message_reference($link, 'note') ?: array('uri' => $link); | foreach ((array)$note['links'] as $i => $link) { | ||||
}, $this->get_links($note['uid'])); | if (strpos($link, 'imap://') === 0 && ($msgref = kolab_storage_config::get_message_reference($link, 'note'))) { | ||||
$note['links'][$i] = $msgref; | |||||
} | |||||
} | |||||
} | |||||
return $note; | return $note; | ||||
} | } | ||||
/** | /** | ||||
* Handler for client-initiated actions on a single note record | * Handler for client-initiated actions on a single note record | ||||
*/ | */ | ||||
public function note_action() | public function note_action() | ||||
▲ Show 20 Lines • Show All 440 Lines • ▼ Show 20 Lines | public function list_action() | ||||
break; | break; | ||||
case 'edit': | case 'edit': | ||||
$this->_read_lists(); | $this->_read_lists(); | ||||
$oldparent = $this->lists[$list['id']]['parentfolder']; | $oldparent = $this->lists[$list['id']]['parentfolder']; | ||||
$newfolder = kolab_storage::folder_update($list); | $newfolder = kolab_storage::folder_update($list); | ||||
if ($newfolder === false) { | if ($newfolder === false) { | ||||
$save_error = $this->gettext(kolab_storage::$last_error); | $save_error = $this->gettext(kolab_storage::$last_error); | ||||
} | } | ||||
else { | else { | ||||
$success = true; | $success = true; | ||||
$update_cmd = 'plugin.update_list'; | $update_cmd = 'plugin.update_list'; | ||||
$list['newid'] = kolab_storage::folder_id($newfolder); | $list['newid'] = kolab_storage::folder_id($newfolder); | ||||
$list['_reload'] = $list['parent'] != $oldparent; | $list['_reload'] = $list['parent'] != $oldparent; | ||||
// compose the new display name | // compose the new display name | ||||
$delim = $this->rc->get_storage()->get_hierarchy_delimiter(); | $delim = $this->rc->get_storage()->get_hierarchy_delimiter(); | ||||
$path_imap = explode($delim, $newfolder); | $path_imap = explode($delim, $newfolder); | ||||
$list['name'] = kolab_storage::object_name($newfolder); | $list['name'] = kolab_storage::object_name($newfolder); | ||||
$list['editname'] = rcube_charset::convert(array_pop($path_imap), 'UTF7-IMAP'); | $list['editname'] = rcube_charset::convert(array_pop($path_imap), 'UTF7-IMAP'); | ||||
$list['listname'] = str_repeat(' ', count($path_imap)) . '» ' . $list['editname']; | $list['listname'] = str_repeat(' ', count($path_imap)) . '» ' . $list['editname']; | ||||
} | } | ||||
break; | break; | ||||
case 'delete': | case 'delete': | ||||
$this->_read_lists(); | $this->_read_lists(); | ||||
$folder = $this->get_folder($list['id']); | $folder = $this->get_folder($list['id']); | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | private function note2message($note) | ||||
$message->setTXTBody($note['description']); | $message->setTXTBody($note['description']); | ||||
} | } | ||||
return $message->getMessage(); | return $message->getMessage(); | ||||
} | } | ||||
private function save_links($uid, $links) | private function save_links($uid, $links) | ||||
{ | { | ||||
if (empty($links)) { | |||||
$links = array(); | |||||
} | |||||
$config = kolab_storage_config::get_instance(); | $config = kolab_storage_config::get_instance(); | ||||
$remove = array_diff($config->get_object_links($uid), $links); | return $config->save_object_links($uid, (array) $links); | ||||
return $config->save_object_links($uid, $links, $remove); | |||||
} | } | ||||
/** | /** | ||||
* Find messages assigned to specified note | * Find messages assigned to specified note | ||||
*/ | */ | ||||
private function get_links($uid) | private function get_links($uid) | ||||
{ | { | ||||
$config = kolab_storage_config::get_instance(); | $config = kolab_storage_config::get_instance(); | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |