- Plugin API: improved 'abort' flag handling, added 'result' item in some hooks: group_*, contact_*, identity_* (#1486914)

release-0.6
alecpl 14 years ago
parent 66c674cc57
commit ce92ba767a

@ -12,6 +12,7 @@ CHANGELOG Roundcube Webmail
- Add option do bind for an individual LDAP address book (#1486997) - 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) - Change reply prefix to display email address only if sender name doesn't exist (#1486550)
- Fix charset replacement in HTML message bodies (#1487021) - 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 RELEASE 0.4.1
------------- -------------

@ -37,30 +37,32 @@ if ($cid && preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) &
$ids = array(); $ids = array();
foreach ($arr_cids as $cid) { foreach ($arr_cids as $cid) {
$plugin = $RCMAIL->plugins->exec_hook('contact_create', array( $a_record = $CONTACTS->get_record($cid, true);
'record' => $CONTACTS->get_record($cid, true),
'source' => $target,
'group' => $target_group,
));
$a_record = $plugin['record'];
if (!$plugin['abort']) {
// check if contact exists, if so, we'll need it's ID // check if contact exists, if so, we'll need it's ID
$result = $TARGET->search('email', $a_record['email'], true, true); $result = $TARGET->search('email', $a_record['email'], true, true);
// insert contact record // insert contact record
if (!$result->count) { if (!$result->count) {
$plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
'record' => $a_record, 'source' => $target, 'group' => $target_group));
if (!$plugin['abort']) {
if ($insert_id = $TARGET->insert($a_record, false)) { if ($insert_id = $TARGET->insert($a_record, false)) {
$ids[] = $insert_id; $ids[] = $insert_id;
$success++; $success++;
} }
} }
else if ($plugin['result']) {
$ids = array_merge($ids, $plugin['result']);
$success++;
}
}
else { else {
$record = $result->first(); $record = $result->first();
$ids[] = $record['ID']; $ids[] = $record['ID'];
} }
} }
}
// assign to group // assign to group
if ($target_group && $TARGET->groups && !empty($ids)) { if ($target_group && $TARGET->groups && !empty($ids)) {
@ -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) if (($cnt = $TARGET->add_to_group($target_group, $plugin['ids'])) && $cnt > $success)
$success = $cnt; $success = $cnt;
} }
else if ($plugin['result'])
$success = $plugin['result'];
} }
} }

@ -23,11 +23,12 @@ if ($OUTPUT->ajax_call &&
($cid = get_input_value('_cid', RCUBE_INPUT_POST)) && ($cid = get_input_value('_cid', RCUBE_INPUT_POST)) &&
preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) 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; $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : $plugin['result'];
if (!$deleted)
{ if (!$deleted) {
// send error message // send error message
exit; exit;
} }
@ -46,7 +47,7 @@ if ($OUTPUT->ajax_call &&
// send response // send response
$OUTPUT->send(); $OUTPUT->send();
} }
exit; exit;

@ -33,9 +33,18 @@ if ($RCMAIL->action == 'group-addmembers') {
$CONTACTS->set_group($gid); $CONTACTS->set_group($gid);
$num2add = count(explode(',', $plugin['ids'])); $num2add = count(explode(',', $plugin['ids']));
if (!$plugin['abort'] && ($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) 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->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
else if (!$plugin['abort'] && $CONTACTS->add_to_group($gid, $plugin['ids'])) $OUTPUT->send();
}
$result = $CONTACTS->add_to_group($gid, $plugin['ids']);
}
else {
$result = $plugin['result'];
}
if ($result)
$OUTPUT->show_message('contactaddedtogroup'); $OUTPUT->show_message('contactaddedtogroup');
else if ($plugin['message']) else if ($plugin['message'])
$OUTPUT->show_message($plugin['message'], 'warning'); $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))) { 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)); $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'); $OUTPUT->show_message('contactremovedfromgroup');
else if ($plugin['message']) else if ($plugin['message'])
$OUTPUT->show_message($plugin['message'], 'warning'); $OUTPUT->show_message($plugin['message'], 'warning');
@ -56,8 +70,11 @@ else if ($RCMAIL->action == 'group-delmembers') {
else if ($RCMAIL->action == 'group-create') { else if ($RCMAIL->action == 'group-create') {
if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST))) { if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST))) {
$plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source)); $plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source));
if (!$plugin['abort']) if (!$plugin['abort'])
$created = $CONTACTS->create_group($plugin['name']); $created = $CONTACTS->create_group($plugin['name']);
else
$created = $plugin['result'];
} }
if ($created && $OUTPUT->ajax_call) { if ($created && $OUTPUT->ajax_call) {
@ -72,8 +89,11 @@ else if ($RCMAIL->action == 'group-create') {
else if ($RCMAIL->action == 'group-rename') { else if ($RCMAIL->action == 'group-rename') {
if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST)))) { 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)); $plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source));
if (!$plugin['abort']) if (!$plugin['abort'])
$newname = $CONTACTS->rename_group($gid, $plugin['name']); $newname = $CONTACTS->rename_group($gid, $plugin['name']);
else
$newname = $plugin['result'];
} }
if ($newname && $OUTPUT->ajax_call) if ($newname && $OUTPUT->ajax_call)
@ -85,8 +105,11 @@ else if ($RCMAIL->action == 'group-rename') {
else if ($RCMAIL->action == 'group-delete') { else if ($RCMAIL->action == 'group-delete') {
if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) { if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) {
$plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source)); $plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source));
if (!$plugin['abort']) if (!$plugin['abort'])
$deleted = $CONTACTS->delete_group($gid); $deleted = $CONTACTS->delete_group($gid);
else
$deleted = $plugin['result'];
} }
if ($deleted) if ($deleted)

@ -159,7 +159,12 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'
$a_record = $plugin['record']; $a_record = $plugin['record'];
// insert record and send response // 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->inserted++;
$IMPORT_STATS->names[] = $vcard->displayname; $IMPORT_STATS->names[] = $vcard->displayname;
} else { } else {

@ -58,8 +58,12 @@ if (!empty($cid))
array('id' => $cid, 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); array('id' => $cid, 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
$a_record = $plugin['record']; $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 // LDAP DN change
if (is_string($result) && strlen($result)>1) { if (is_string($result) && strlen($result)>1) {
$newcid = $result; $newcid = $result;
@ -81,34 +85,37 @@ if (!empty($cid))
$OUTPUT->show_message('successfullysaved', 'confirmation', null, false); $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
rcmail_overwrite_action('show'); rcmail_overwrite_action('show');
} }
else else {
{
// show error message // 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'); rcmail_overwrite_action('show');
} }
} }
// insert a new contact // insert a new contact
else else {
{
// check for existing contacts // check for existing contacts
$existing = $CONTACTS->search('email', $a_record['email'], true, false); $existing = $CONTACTS->search('email', $a_record['email'], true, false);
// show warning message // show warning message
if ($existing->count) if ($existing->count) {
{
$OUTPUT->show_message('contactexists', 'warning', null, false); $OUTPUT->show_message('contactexists', 'warning', null, false);
rcmail_overwrite_action('add'); rcmail_overwrite_action('add');
return; 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']; $a_record = $plugin['record'];
// insert record and send response // 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 // add contact row or jump to the page where it should appear
$CONTACTS->reset(); $CONTACTS->reset();
$result = $CONTACTS->search($CONTACTS->primary_key, $insert_id); $result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
@ -124,12 +131,9 @@ else
$OUTPUT->show_message('successfullysaved', 'confirmation', null, false); $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
$OUTPUT->send('iframe'); $OUTPUT->send('iframe');
} }
else else {
{
// show error message // 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'); rcmail_overwrite_action('add');
} }
} }

@ -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); $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( $contact = array(
'email' => $contact_arr[1]['mailto'], 'email' => $contact_arr[1]['mailto'],
'name' => $contact_arr[1]['name'] 'name' => $contact_arr[1]['name']
@ -45,21 +44,23 @@ if (!empty($_POST['_address']) && is_object($CONTACTS))
// check for existing contacts // check for existing contacts
$existing = $CONTACTS->search('email', $contact['email'], true, false); $existing = $CONTACTS->search('email', $contact['email'], true, false);
if ($done = $existing->count) if ($done = $existing->count)
$OUTPUT->show_message('contactexists', 'warning'); $OUTPUT->show_message('contactexists', 'warning');
else else {
{
$plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null)); $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
$contact = $plugin['record']; $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'); $OUTPUT->show_message('addedsuccessfully', 'confirmation');
} }
} }
} }
if (!$done) if (!$done)
$OUTPUT->show_message('errorsavingcontact', 'warning'); $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsavingcontact', 'warning');
$OUTPUT->send(); $OUTPUT->send();

@ -32,12 +32,13 @@ if ($iid && preg_match('/^[0-9]+(,[0-9]+)*$/', $iid))
{ {
$plugin = $RCMAIL->plugins->exec_hook('identity_delete', array('id' => $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); $OUTPUT->show_message('deletedsuccessfully', 'confirmation', null, false);
} else
else { $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'nodeletelastidentity', 'error', null, false);
$OUTPUT->show_message('nodeletelastidentity', 'error', null, false);
}
// send response // send response
if ($OUTPUT->ajax_call) if ($OUTPUT->ajax_call)
$OUTPUT->send(); $OUTPUT->send();
@ -48,5 +49,3 @@ if ($OUTPUT->ajax_call)
// go to identities page // go to identities page
rcmail_overwrite_action('identities'); rcmail_overwrite_action('identities');

@ -83,23 +83,25 @@ if ($_POST['_iid'])
if ($save_data['reply-to']) if ($save_data['reply-to'])
$save_data['reply-to'] = idn_to_ascii($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'); $OUTPUT->show_message('successfullysaved', 'confirmation');
if (!empty($_POST['_standard'])) if (!empty($_POST['_standard']))
$default_id = get_input_value('_iid', RCUBE_INPUT_POST); $default_id = get_input_value('_iid', RCUBE_INPUT_POST);
if ($_POST['_framed']) if ($_POST['_framed']) {
{
// update the changed col in list // update the changed col in list
// ... // ...
} }
} }
else if ($plugin['abort'] || $DB->is_error()) else {
{
// show error message // 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'); rcmail_overwrite_action('edit-identity');
return; return;
} }
@ -118,8 +120,12 @@ else if (IDENTITIES_LEVEL < 2)
$save_data['bcc'] = idn_to_ascii($save_data['bcc']); $save_data['bcc'] = idn_to_ascii($save_data['bcc']);
$save_data['reply-to'] = idn_to_ascii($save_data['reply-to']); $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); $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
$_GET['_iid'] = $insert_id; $_GET['_iid'] = $insert_id;
@ -127,10 +133,9 @@ else if (IDENTITIES_LEVEL < 2)
if (!empty($_POST['_standard'])) if (!empty($_POST['_standard']))
$default_id = $insert_id; $default_id = $insert_id;
} }
else else {
{
// show error message // 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'); rcmail_overwrite_action('edit-identity');
return; return;
} }
@ -145,5 +150,3 @@ if ($default_id)
// go to next step // go to next step
rcmail_overwrite_action('identities'); rcmail_overwrite_action('identities');

Loading…
Cancel
Save