plugins/calendar plugins/kolab_addressbook plugins/libkolab
Thomas Brüderli
bruederli at kolabsys.com
Thu Jun 21 21:34:07 CEST 2012
plugins/calendar/drivers/kolab/kolab_driver.php | 17 -
plugins/kolab_addressbook/kolab_addressbook.php | 130 +---------
plugins/kolab_addressbook/skins/larry/templates/bookedit.html | 2
plugins/libkolab/lib/kolab_storage.php | 30 ++
4 files changed, 55 insertions(+), 124 deletions(-)
New commits:
commit 4f69203125d358851808bec3ae5ae7d112e05ea4
Author: Thomas Bruederli <thomas at roundcube.net>
Date: Thu Jun 21 21:34:08 2012 +0200
More code cleanup: use common function from libkolab for folder management and naming
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index 089909d..09117f5 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -112,20 +112,7 @@ class kolab_driver extends calendar_driver
foreach ($this->calendars as $id => $cal) {
if ($cal->ready) {
- $name = $origname = $cal->get_name();
-
- // find folder prefix to truncate (the same code as in kolab_addressbook plugin)
- for ($i = count($names)-1; $i >= 0; $i--) {
- if (strpos($name, $names[$i].' » ') === 0) {
- $length = strlen($names[$i].' » ');
- $prefix = substr($name, 0, $length);
- $count = count(explode(' » ', $prefix));
- $name = str_repeat(' ', $count-1) . '» ' . substr($name, $length);
- break;
- }
- }
-
- $names[] = $origname;
+ $name = kolab_storage::folder_displayname($cal->get_name(), $names);
$calendars[$cal->id] = array(
'id' => $cal->id,
@@ -159,6 +146,7 @@ class kolab_driver extends calendar_driver
$folder = kolab_storage::folder_update($prop);
if ($folder === false) {
+ $this->last_error = $this->cal->gettext(kolab_storage::$last_error);
return false;
}
@@ -192,6 +180,7 @@ class kolab_driver extends calendar_driver
$newfolder = kolab_storage::folder_update($prop);
if ($newfolder === false) {
+ $this->last_error = $this->cal->gettext(kolab_storage::$last_error);
return false;
}
diff --git a/plugins/kolab_addressbook/kolab_addressbook.php b/plugins/kolab_addressbook/kolab_addressbook.php
index 65b4bf1..2920ebd 100644
--- a/plugins/kolab_addressbook/kolab_addressbook.php
+++ b/plugins/kolab_addressbook/kolab_addressbook.php
@@ -109,19 +109,7 @@ class kolab_addressbook extends rcube_plugin
$names = array();
foreach ($this->_list_sources() as $abook_id => $abook) {
- $name = $origname = $abook->get_name();
-
- // find folder prefix to truncate
- for ($i = count($names)-1; $i >= 0; $i--) {
- if (strpos($name, $names[$i].' » ') === 0) {
- $length = strlen($names[$i].' » ');
- $prefix = substr($name, 0, $length);
- $count = count(explode(' » ', $prefix));
- $name = str_repeat(' ', $count-1) . '» ' . substr($name, $length);
- break;
- }
- }
- $names[] = $origname;
+ $name = kolab_storage::folder_displayname($abook->get_name(), $names);
// register this address source
$sources[$abook_id] = array(
@@ -420,92 +408,34 @@ class kolab_addressbook extends rcube_plugin
*/
public function book_save()
{
- $storage = $this->rc->get_storage();
- $folder = trim(get_input_value('_name', RCUBE_INPUT_POST, true, 'UTF7-IMAP'));
- $oldfolder = trim(get_input_value('_oldname', RCUBE_INPUT_POST, true)); // UTF7-IMAP
- $path = trim(get_input_value('_parent', RCUBE_INPUT_POST, true)); // UTF7-IMAP
- $delimiter = $storage->get_hierarchy_delimiter();
-
- if (strlen($oldfolder)) {
- $options = $storage->folder_info($oldfolder);
- }
-
- if (!empty($options) && ($options['norename'] || $options['protected'])) {
- }
- // sanity checks (from steps/settings/save_folder.inc)
- else if (!strlen($folder)) {
- $error = rcube_label('cannotbeempty');
- }
- else if (strlen($folder) > 128) {
- $error = rcube_label('nametoolong');
- }
- else {
- // these characters are problematic e.g. when used in LIST/LSUB
- foreach (array($delimiter, '%', '*') as $char) {
- if (strpos($folder, $delimiter) !== false) {
- $error = rcube_label('forbiddencharacter') . " ($char)";
- break;
- }
- }
- }
-
- if (!$error) {
- if (!empty($options) && ($options['protected'] || $options['norename'])) {
- $folder = $oldfolder;
- }
- else if (strlen($path)) {
- $folder = $path . $delimiter . $folder;
+ $prop = array(
+ 'name' => trim(get_input_value('_name', RCUBE_INPUT_POST)),
+ 'oldname' => trim(get_input_value('_oldname', RCUBE_INPUT_POST, true)), // UTF7-IMAP
+ 'parent' => trim(get_input_value('_parent', RCUBE_INPUT_POST, true)), // UTF7-IMAP
+ 'type' => 'contact',
+ );
+
+ $result = $error = false;
+ $type = strlen($prop['oldname']) ? 'update' : 'create';
+ $prop = $this->rc->plugins->exec_hook('addressbook_'.$type, $prop);
+
+ if (!$prop['abort']) {
+ if ($newfolder = kolab_storage::folder_update($prop)) {
+ $folder = $newfolder;
+ $result = true;
}
else {
- // add namespace prefix (when needed)
- $folder = $storage->mod_folder($folder, 'in');
- }
-
- // Check access rights to the parent folder
- if (strlen($path) && (!strlen($oldfolder) || $oldfolder != $folder)) {
- $parent_opts = $storage->folder_info($path);
- if ($parent_opts['namespace'] != 'personal'
- && (empty($parent_opts['rights']) || !preg_match('/[ck]/', implode($parent_opts['rights'])))
- ) {
- $error = rcube_label('parentnotwritable');
- }
+ $error = kolab_storage::$last_error;
}
}
-
- if (!$error) {
- // update the folder name
- if (strlen($oldfolder)) {
- $type = 'update';
- $plugin = $this->rc->plugins->exec_hook('addressbook_update', array(
- 'name' => $folder, 'oldname' => $oldfolder));
-
- if (!$plugin['abort']) {
- if ($oldfolder != $folder)
- $result = kolab_storage::folder_rename($oldfolder, $folder);
- else
- $result = true;
- }
- else {
- $result = $plugin['result'];
- }
- }
- // create new folder
- else {
- $type = 'create';
- $plugin = $this->rc->plugins->exec_hook('addressbook_create', array('name' => $folder));
-
- $folder = $plugin['name'];
-
- if (!$plugin['abort']) {
- $result = kolab_storage::folder_create($folder, 'contact');
- }
- else {
- $result = $plugin['result'];
- }
- }
+ else {
+ $result = $prop['result'];
+ $folder = $prop['name'];
}
if ($result) {
+ $storage = $this->rc->get_storage();
+ $delimiter = $storage->get_hierarchy_delimiter();
$kolab_folder = new rcube_kolab_contacts($folder);
// create display name for the folder (see self::address_sources())
@@ -519,19 +449,7 @@ class kolab_addressbook extends rcube_plugin
$realname = $folder;
}
- $name = $origname = $abook->get_name();
-
- // find folder prefix to truncate
- for ($i = count($names)-1; $i >= 0; $i--) {
- if (strpos($name, $names[$i].' » ') === 0) {
- $length = strlen($names[$i].' » ');
- $prefix = substr($name, 0, $length);
- $count = count(explode(' » ', $prefix));
- $name = str_repeat(' ', $count-1) . '» ' . substr($name, $length);
- break;
- }
- }
- $names[] = $origname;
+ $name = kolab_storage::folder_displayname($abook->get_name(), $names);
if ($realname == $folder) {
break;
@@ -553,7 +471,7 @@ class kolab_addressbook extends rcube_plugin
'realname' => rcube_charset::convert($folder, 'UTF7-IMAP'), // IMAP folder name
'class_name' => $kolab_folder->get_namespace(),
'kolab' => true,
- ), kolab_storage::folder_id($oldfolder));
+ ), kolab_storage::folder_id($prop['oldname']));
$this->rc->output->send('iframe');
}
diff --git a/plugins/kolab_addressbook/skins/larry/templates/bookedit.html b/plugins/kolab_addressbook/skins/larry/templates/bookedit.html
index 007d512..9a91337 100644
--- a/plugins/kolab_addressbook/skins/larry/templates/bookedit.html
+++ b/plugins/kolab_addressbook/skins/larry/templates/bookedit.html
@@ -9,7 +9,7 @@
<h1 class="boxtitle"><roundcube:label name="kolab_addressbook.bookproperties" /></h1>
<div class="boxcontent">
- <roundcube:object name="bookdetails" class="propform" />
+ <roundcube:object name="bookdetails" class="propform tabbed" />
</div>
<div id="formfooter">
diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php
index a19c71b..760cd07 100644
--- a/plugins/libkolab/lib/kolab_storage.php
+++ b/plugins/libkolab/lib/kolab_storage.php
@@ -253,18 +253,18 @@ class kolab_storage
}
// sanity checks (from steps/settings/save_folder.inc)
else if (!strlen($folder)) {
- self::$last_error = 'Invalid folder name';
+ self::$last_error = 'cannotbeempty';
return false;
}
else if (strlen($folder) > 128) {
- self::$last_error = 'Folder name too long';
+ self::$last_error = 'nametoolong';
return false;
}
else {
// these characters are problematic e.g. when used in LIST/LSUB
foreach (array($delimiter, '%', '*') as $char) {
if (strpos($folder, $delimiter) !== false) {
- self::$last_error = 'Invalid folder name';
+ self::$last_error = 'forbiddencharacter';
return false;
}
}
@@ -398,6 +398,30 @@ class kolab_storage
return $folder;
}
+
+ /**
+ * Helper method to generate a truncated folder name to display
+ */
+ public static function folder_displayname($origname, &$names)
+ {
+ $name = $origname;
+
+ // find folder prefix to truncate
+ for ($i = count($names)-1; $i >= 0; $i--) {
+ if (strpos($name, $names[$i] . ' » ') === 0) {
+ $length = strlen($names[$i] . ' » ');
+ $prefix = substr($name, 0, $length);
+ $count = count(explode(' » ', $prefix));
+ $name = str_repeat(' ', $count-1) . '» ' . substr($name, $length);
+ break;
+ }
+ }
+ $names[] = $origname;
+
+ return $name;
+ }
+
+
/**
* Creates a SELECT field with folders list
*
More information about the commits
mailing list