summaryrefslogtreecommitdiff
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
parent66c674cc5716364cd6b450d8398b0a26aba0a2ae (diff)
- Plugin API: improved 'abort' flag handling, added 'result' item in some hooks: group_*, contact_*, identity_* (#1486914)
-rw-r--r--CHANGELOG1
-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
-rw-r--r--program/steps/mail/addcontact.inc13
-rw-r--r--program/steps/settings/delete_identity.inc13
-rw-r--r--program/steps/settings/save_identity.inc35
9 files changed, 112 insertions, 71 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 9a9bb5af1..405f9634a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,7 @@ CHANGELOG Roundcube Webmail
- Add option do bind for an individual LDAP address book (#1486997)
- Change reply prefix to display email address only if sender name doesn't exist (#1486550)
- Fix charset replacement in HTML message bodies (#1487021)
+- Plugin API: improved 'abort' flag handling, added 'result' item in some hooks (#1486914)
RELEASE 0.4.1
-------------
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');
}
}
-
-
diff --git a/program/steps/mail/addcontact.inc b/program/steps/mail/addcontact.inc
index 7a2b69e3d..d46db8ece 100644
--- a/program/steps/mail/addcontact.inc
+++ b/program/steps/mail/addcontact.inc
@@ -30,8 +30,7 @@ if (!empty($_POST['_address']) && is_object($CONTACTS))
{
$contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
- if (!empty($contact_arr[1]['mailto']))
- {
+ if (!empty($contact_arr[1]['mailto'])) {
$contact = array(
'email' => $contact_arr[1]['mailto'],
'name' => $contact_arr[1]['name']
@@ -45,21 +44,23 @@ if (!empty($_POST['_address']) && is_object($CONTACTS))
// check for existing contacts
$existing = $CONTACTS->search('email', $contact['email'], true, false);
+
if ($done = $existing->count)
$OUTPUT->show_message('contactexists', 'warning');
- else
- {
+ else {
$plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
$contact = $plugin['record'];
- if (!$plugin['abort'] && ($done = $CONTACTS->insert($contact)))
+ $done = !$plugin['abort'] ? $CONTACTS->insert($contact) : $plugin['result'];
+
+ if ($done)
$OUTPUT->show_message('addedsuccessfully', 'confirmation');
}
}
}
if (!$done)
- $OUTPUT->show_message('errorsavingcontact', 'warning');
+ $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsavingcontact', 'warning');
$OUTPUT->send();
diff --git a/program/steps/settings/delete_identity.inc b/program/steps/settings/delete_identity.inc
index 4667fd315..81609d622 100644
--- a/program/steps/settings/delete_identity.inc
+++ b/program/steps/settings/delete_identity.inc
@@ -32,12 +32,13 @@ if ($iid && preg_match('/^[0-9]+(,[0-9]+)*$/', $iid))
{
$plugin = $RCMAIL->plugins->exec_hook('identity_delete', array('id' => $iid));
- if (!$plugin['abort'] && $USER->delete_identity($iid)) {
+ $deleted = !$plugin['abort'] ? $USER->delete_identity($iid) : $plugin['result'];
+
+ if ($deleted)
$OUTPUT->show_message('deletedsuccessfully', 'confirmation', null, false);
- }
- else {
- $OUTPUT->show_message('nodeletelastidentity', 'error', null, false);
- }
+ else
+ $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'nodeletelastidentity', 'error', null, false);
+
// send response
if ($OUTPUT->ajax_call)
$OUTPUT->send();
@@ -48,5 +49,3 @@ if ($OUTPUT->ajax_call)
// go to identities page
rcmail_overwrite_action('identities');
-
-
diff --git a/program/steps/settings/save_identity.inc b/program/steps/settings/save_identity.inc
index 313e9df4d..30cc12495 100644
--- a/program/steps/settings/save_identity.inc
+++ b/program/steps/settings/save_identity.inc
@@ -83,23 +83,25 @@ if ($_POST['_iid'])
if ($save_data['reply-to'])
$save_data['reply-to'] = idn_to_ascii($save_data['reply-to']);
- if (!$plugin['abort'] && ($updated = $USER->update_identity($iid, $save_data)))
- {
+ if (!$plugin['abort'])
+ $updated = $USER->update_identity($iid, $save_data);
+ else
+ $updated = $plugin['result'];
+
+ if ($updated) {
$OUTPUT->show_message('successfullysaved', 'confirmation');
-
+
if (!empty($_POST['_standard']))
$default_id = get_input_value('_iid', RCUBE_INPUT_POST);
-
- if ($_POST['_framed'])
- {
+
+ if ($_POST['_framed']) {
// update the changed col in list
// ...
}
}
- else if ($plugin['abort'] || $DB->is_error())
- {
+ 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('edit-identity');
return;
}
@@ -118,8 +120,12 @@ else if (IDENTITIES_LEVEL < 2)
$save_data['bcc'] = idn_to_ascii($save_data['bcc']);
$save_data['reply-to'] = idn_to_ascii($save_data['reply-to']);
- if (!$plugin['abort'] && $save_data['email'] && ($insert_id = $USER->insert_identity($save_data)))
- {
+ if (!$plugin['abort'])
+ $insert_id = $save_data['email'] ? $USER->insert_identity($save_data) : null;
+ else
+ $insert_id = $plugin['result'];
+
+ if ($insert_id) {
$OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
$_GET['_iid'] = $insert_id;
@@ -127,10 +133,9 @@ else if (IDENTITIES_LEVEL < 2)
if (!empty($_POST['_standard']))
$default_id = $insert_id;
}
- 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('edit-identity');
return;
}
@@ -145,5 +150,3 @@ if ($default_id)
// go to next step
rcmail_overwrite_action('identities');
-
-