summaryrefslogtreecommitdiff
path: root/program/steps/addressbook
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-09-30 13:24:33 +0000
committeralecpl <alec@alec.pl>2010-09-30 13:24:33 +0000
commitce92ba767a9557daf7f18be94882dd7e6f4591fb (patch)
treef018b3c42d2d452948bc240c3d9aa8a7aaff08a3 /program/steps/addressbook
parent66c674cc5716364cd6b450d8398b0a26aba0a2ae (diff)
- Plugin API: improved 'abort' flag handling, added 'result' item in some hooks: group_*, contact_*, identity_* (#1486914)
Diffstat (limited to 'program/steps/addressbook')
-rw-r--r--program/steps/addressbook/copy.inc32
-rw-r--r--program/steps/addressbook/delete.inc13
-rw-r--r--program/steps/addressbook/groups.inc31
-rw-r--r--program/steps/addressbook/import.inc7
-rw-r--r--program/steps/addressbook/save.inc38
5 files changed, 79 insertions, 42 deletions
diff --git a/program/steps/addressbook/copy.inc b/program/steps/addressbook/copy.inc
index a37e93211..8a8379078 100644
--- a/program/steps/addressbook/copy.inc
+++ b/program/steps/addressbook/copy.inc
@@ -37,29 +37,31 @@ if ($cid && preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) &
$ids = array();
foreach ($arr_cids as $cid) {
- $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
- 'record' => $CONTACTS->get_record($cid, true),
- 'source' => $target,
- 'group' => $target_group,
- ));
- $a_record = $plugin['record'];
+ $a_record = $CONTACTS->get_record($cid, true);
- if (!$plugin['abort']) {
- // check if contact exists, if so, we'll need it's ID
- $result = $TARGET->search('email', $a_record['email'], true, true);
+ // check if contact exists, if so, we'll need it's ID
+ $result = $TARGET->search('email', $a_record['email'], true, true);
+
+ // insert contact record
+ if (!$result->count) {
+ $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
+ 'record' => $a_record, 'source' => $target, 'group' => $target_group));
- // insert contact record
- if (!$result->count) {
+ if (!$plugin['abort']) {
if ($insert_id = $TARGET->insert($a_record, false)) {
$ids[] = $insert_id;
$success++;
}
}
- else {
- $record = $result->first();
- $ids[] = $record['ID'];
+ else if ($plugin['result']) {
+ $ids = array_merge($ids, $plugin['result']);
+ $success++;
}
}
+ else {
+ $record = $result->first();
+ $ids[] = $record['ID'];
+ }
}
// assign to group
@@ -79,6 +81,8 @@ if ($cid && preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) &
if (($cnt = $TARGET->add_to_group($target_group, $plugin['ids'])) && $cnt > $success)
$success = $cnt;
}
+ else if ($plugin['result'])
+ $success = $plugin['result'];
}
}
diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc
index 08ae36dfb..bb0457be7 100644
--- a/program/steps/addressbook/delete.inc
+++ b/program/steps/addressbook/delete.inc
@@ -23,14 +23,15 @@ if ($OUTPUT->ajax_call &&
($cid = get_input_value('_cid', RCUBE_INPUT_POST)) &&
preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid)
) {
- $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array('id' => $cid, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
+ $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array(
+ 'id' => $cid, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
- $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : false;
- if (!$deleted)
- {
+ $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : $plugin['result'];
+
+ if (!$deleted) {
// send error message
exit;
- }
+ }
// count contacts for this user
$result = $CONTACTS->count();
@@ -46,7 +47,7 @@ if ($OUTPUT->ajax_call &&
// send response
$OUTPUT->send();
- }
+}
exit;
diff --git a/program/steps/addressbook/groups.inc b/program/steps/addressbook/groups.inc
index 542628e1c..66619fa7d 100644
--- a/program/steps/addressbook/groups.inc
+++ b/program/steps/addressbook/groups.inc
@@ -33,9 +33,18 @@ if ($RCMAIL->action == 'group-addmembers') {
$CONTACTS->set_group($gid);
$num2add = count(explode(',', $plugin['ids']));
- if (!$plugin['abort'] && ($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum))
- $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
- else if (!$plugin['abort'] && $CONTACTS->add_to_group($gid, $plugin['ids']))
+ if (!$plugin['abort']) {
+ if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) {
+ $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
+ $OUTPUT->send();
+ }
+ $result = $CONTACTS->add_to_group($gid, $plugin['ids']);
+ }
+ else {
+ $result = $plugin['result'];
+ }
+
+ if ($result)
$OUTPUT->show_message('contactaddedtogroup');
else if ($plugin['message'])
$OUTPUT->show_message($plugin['message'], 'warning');
@@ -46,7 +55,12 @@ else if ($RCMAIL->action == 'group-delmembers') {
if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
$plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
- if (!$plugin['abort'] && $CONTACTS->remove_from_group($gid, $plugin['ids']))
+ if (!$plugin['abort'])
+ $result = $CONTACTS->remove_from_group($gid, $plugin['ids']);
+ else
+ $result = $plugin['result'];
+
+ if ($result)
$OUTPUT->show_message('contactremovedfromgroup');
else if ($plugin['message'])
$OUTPUT->show_message($plugin['message'], 'warning');
@@ -56,8 +70,11 @@ else if ($RCMAIL->action == 'group-delmembers') {
else if ($RCMAIL->action == 'group-create') {
if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST))) {
$plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source));
+
if (!$plugin['abort'])
$created = $CONTACTS->create_group($plugin['name']);
+ else
+ $created = $plugin['result'];
}
if ($created && $OUTPUT->ajax_call) {
@@ -72,8 +89,11 @@ else if ($RCMAIL->action == 'group-create') {
else if ($RCMAIL->action == 'group-rename') {
if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST)))) {
$plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source));
+
if (!$plugin['abort'])
$newname = $CONTACTS->rename_group($gid, $plugin['name']);
+ else
+ $newname = $plugin['result'];
}
if ($newname && $OUTPUT->ajax_call)
@@ -85,8 +105,11 @@ else if ($RCMAIL->action == 'group-rename') {
else if ($RCMAIL->action == 'group-delete') {
if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) {
$plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source));
+
if (!$plugin['abort'])
$deleted = $CONTACTS->delete_group($gid);
+ else
+ $deleted = $plugin['result'];
}
if ($deleted)
diff --git a/program/steps/addressbook/import.inc b/program/steps/addressbook/import.inc
index ac6dc9277..2390e98c9 100644
--- a/program/steps/addressbook/import.inc
+++ b/program/steps/addressbook/import.inc
@@ -159,7 +159,12 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'
$a_record = $plugin['record'];
// insert record and send response
- if (!$plugin['abort'] && ($success = $CONTACTS->insert($a_record))) {
+ if (!$plugin['abort'])
+ $success = $CONTACTS->insert($a_record);
+ else
+ $success = $plugin['result'];
+
+ if ($success) {
$IMPORT_STATS->inserted++;
$IMPORT_STATS->names[] = $vcard->displayname;
} else {
diff --git a/program/steps/addressbook/save.inc b/program/steps/addressbook/save.inc
index b4b9ae46b..f0244b4a9 100644
--- a/program/steps/addressbook/save.inc
+++ b/program/steps/addressbook/save.inc
@@ -58,8 +58,12 @@ if (!empty($cid))
array('id' => $cid, 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
$a_record = $plugin['record'];
- if (!$plugin['abort'] && ($result = $CONTACTS->update($cid, $a_record)))
- {
+ if (!$plugin['abort'])
+ $result = $CONTACTS->update($cid, $a_record);
+ else
+ $result = $plugin['result'];
+
+ if ($result) {
// LDAP DN change
if (is_string($result) && strlen($result)>1) {
$newcid = $result;
@@ -81,34 +85,37 @@ if (!empty($cid))
$OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
rcmail_overwrite_action('show');
}
- else
- {
+ else {
// show error message
- $OUTPUT->show_message('errorsaving', 'error', null, false);
+ $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
rcmail_overwrite_action('show');
}
}
// insert a new contact
-else
-{
+else {
// check for existing contacts
$existing = $CONTACTS->search('email', $a_record['email'], true, false);
// show warning message
- if ($existing->count)
- {
+ if ($existing->count) {
$OUTPUT->show_message('contactexists', 'warning', null, false);
rcmail_overwrite_action('add');
return;
}
- $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
+ $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
+ 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
$a_record = $plugin['record'];
// insert record and send response
- if (!$plugin['abort'] && ($insert_id = $CONTACTS->insert($a_record)))
- {
+ if (!$plugin['abort'])
+ $insert_id = $CONTACTS->insert($a_record);
+ else
+ $insert_id = $plugin['result'];
+
+
+ if ($insert_id) {
// add contact row or jump to the page where it should appear
$CONTACTS->reset();
$result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
@@ -124,12 +131,9 @@ else
$OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
$OUTPUT->send('iframe');
}
- else
- {
+ else {
// show error message
- $OUTPUT->show_message('errorsaving', 'error', null, false);
+ $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
rcmail_overwrite_action('add');
}
}
-
-