List Collected Recipiens and Trusted Senders at the end of the list

This commit is contained in:
Aleksander Machniak 2022-10-17 11:57:49 +02:00
parent bb01ff0f19
commit 38bada80f9

View file

@ -150,14 +150,16 @@ class kolab_addressbook extends rcube_plugin
// $p['sources'] = array_merge($sources, $p['sources']); // $p['sources'] = array_merge($sources, $p['sources']);
// Don't use array_merge(), because if you have folders name // Don't use array_merge(), because if you have folders name
// that resolve to numeric identifier it will break output array keys // that resolve to numeric identifier it will break output array keys
foreach ($p['sources'] as $idx => $value) foreach ($p['sources'] as $idx => $value) {
$sources[$idx] = $value; $sources[$idx] = $value;
}
$p['sources'] = $sources; $p['sources'] = $sources;
} }
else { else {
// $p['sources'] = array_merge($p['sources'], $sources); // $p['sources'] = array_merge($p['sources'], $sources);
foreach ($sources as $idx => $value) foreach ($sources as $idx => $value) {
$p['sources'][$idx] = $value; $p['sources'][$idx] = $value;
}
} }
return $p; return $p;
@ -205,19 +207,29 @@ class kolab_addressbook extends rcube_plugin
*/ */
public function directorylist_html($args) public function directorylist_html($args)
{ {
$out = ''; $out = '';
$jsdata = array(); $spec = '';
$sources = (array)$this->rc->get_address_sources(); $kolab = '';
$jsdata = [];
$sources = (array) $this->rc->get_address_sources();
// list all non-kolab sources first (also exclude hidden sources) // list all non-kolab sources first (also exclude hidden sources), special folders will go last
$filter = function($source){ return empty($source['kolab']) && empty($source['hidden']); }; foreach ($sources as $j => $source) {
foreach (array_filter($sources, $filter) as $j => $source) {
$id = strval(strlen($source['id']) ? $source['id'] : $j); $id = strval(strlen($source['id']) ? $source['id'] : $j);
$out .= $this->addressbook_list_item($id, $source, $jsdata) . '</li>'; if (!empty($source['kolab']) || !empty($source['hidden'])) {
} continue;
}
$filter = function($source) { return !empty($source['kolab']) && empty($source['hidden']); }; // Roundcube >= 1.5, Collected Recipients and Trusted Senders sources will be listed at the end
$folders = array_filter($sources, $filter); if ((defined('rcube_addressbook::TYPE_RECIPIENT') && $source['id'] == (string) rcube_addressbook::TYPE_RECIPIENT)
|| (defined('rcube_addressbook::TYPE_TRUSTED_SENDER') && $source['id'] == (string) rcube_addressbook::TYPE_TRUSTED_SENDER)
) {
$spec .= $this->addressbook_list_item($id, $source, $jsdata) . '</li>';
}
else {
$out .= $this->addressbook_list_item($id, $source, $jsdata) . '</li>';
}
}
// render a hierarchical list of kolab contact folders // render a hierarchical list of kolab contact folders
// TODO: Move this to the drivers // TODO: Move this to the drivers
@ -225,16 +237,19 @@ class kolab_addressbook extends rcube_plugin
$folders = kolab_storage::sort_folders(kolab_storage::get_folders('contact')); $folders = kolab_storage::sort_folders(kolab_storage::get_folders('contact'));
kolab_storage::folder_hierarchy($folders, $tree); kolab_storage::folder_hierarchy($folders, $tree);
if ($tree && !empty($tree->children)) { if ($tree && !empty($tree->children)) {
$out .= $this->folder_tree_html($tree, $sources, $jsdata); $kolab .= $this->folder_tree_html($tree, $sources, $jsdata);
} }
} }
else { else {
foreach ($folders as $j => $source) { $filter = function($source) { return !empty($source['kolab']) && empty($source['hidden']); };
foreach (array_filter($sources, $filter) as $j => $source) {
$id = strval(strlen($source['id']) ? $source['id'] : $j); $id = strval(strlen($source['id']) ? $source['id'] : $j);
$out .= $this->addressbook_list_item($id, $source, $jsdata) . '</li>'; $kolab .= $this->addressbook_list_item($id, $source, $jsdata) . '</li>';
} }
} }
$out .= $kolab . $spec;
$this->rc->output->set_env('contactgroups', array_filter($jsdata, function($src){ return $src['type'] == 'group'; })); $this->rc->output->set_env('contactgroups', array_filter($jsdata, function($src){ return $src['type'] == 'group'; }));
$this->rc->output->set_env('address_sources', array_filter($jsdata, function($src){ return $src['type'] != 'group'; })); $this->rc->output->set_env('address_sources', array_filter($jsdata, function($src){ return $src['type'] != 'group'; }));