- Unify hooks names, see rcube_plugin_api::deprecated_hooks for complete list (old names are supported without errors nor warnings)

release-0.6
alecpl 14 years ago
parent ee09d464a8
commit e6ce0062f2

@ -255,7 +255,7 @@ class rcmail
$ldap_config = (array)$this->config->get('ldap_public'); $ldap_config = (array)$this->config->get('ldap_public');
$abook_type = strtolower($this->config->get('address_book_type')); $abook_type = strtolower($this->config->get('address_book_type'));
$plugin = $this->plugins->exec_hook('get_address_book', array('id' => $id, 'writeable' => $writeable)); $plugin = $this->plugins->exec_hook('addressbook_get', array('id' => $id, 'writeable' => $writeable));
// plugin returned instance of a rcube_addressbook // plugin returned instance of a rcube_addressbook
if ($plugin['instance'] instanceof rcube_addressbook) { if ($plugin['instance'] instanceof rcube_addressbook) {
@ -321,7 +321,7 @@ class rcmail
); );
} }
$plugin = $this->plugins->exec_hook('address_sources', array('sources' => $list)); $plugin = $this->plugins->exec_hook('addressbooks_list', array('sources' => $list));
$list = $plugin['sources']; $list = $plugin['sources'];
if ($writeable && !empty($list)) { if ($writeable && !empty($list)) {
@ -928,7 +928,7 @@ class rcmail
*/ */
public function kill_session() public function kill_session()
{ {
$this->plugins->exec_hook('kill_session'); $this->plugins->exec_hook('session_destroy');
$this->session->remove(); $this->session->remove();
$_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true); $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true);

@ -2589,7 +2589,7 @@ class rcube_imap
$a_defaults = $a_out = array(); $a_defaults = $a_out = array();
// Give plugins a chance to provide a list of mailboxes // Give plugins a chance to provide a list of mailboxes
$data = rcmail::get_instance()->plugins->exec_hook('list_mailboxes', $data = rcmail::get_instance()->plugins->exec_hook('mailboxes_list',
array('root' => $root, 'filter' => $filter, 'mode' => 'LSUB')); array('root' => $root, 'filter' => $filter, 'mode' => 'LSUB'));
if (isset($data['folders'])) { if (isset($data['folders'])) {
@ -2620,7 +2620,7 @@ class rcube_imap
function list_unsubscribed($root='', $filter='*') function list_unsubscribed($root='', $filter='*')
{ {
// Give plugins a chance to provide a list of mailboxes // Give plugins a chance to provide a list of mailboxes
$data = rcmail::get_instance()->plugins->exec_hook('list_mailboxes', $data = rcmail::get_instance()->plugins->exec_hook('mailboxes_list',
array('root' => $root, 'filter' => $filter, 'mode' => 'LIST')); array('root' => $root, 'filter' => $filter, 'mode' => 'LIST'));
if (isset($data['folders'])) { if (isset($data['folders'])) {

@ -43,6 +43,33 @@ class rcube_plugin_api
private $required_plugins = array('filesystem_attachments'); private $required_plugins = array('filesystem_attachments');
private $active_hook = false; private $active_hook = false;
// Deprecated names of hooks, will be removed after 0.5-stable release
private $deprecated_hooks = array(
'create_user' => 'user_create',
'kill_session' => 'session_destroy',
'upload_attachment' => 'attachment_upload',
'save_attachment' => 'attachment_save',
'get_attachment' => 'attachment_get',
'cleanup_attachments' => 'attachments_cleanup',
'display_attachment' => 'attachment_display',
'remove_attachment' => 'attachment_delete',
'outgoing_message_headers' => 'message_outgoing_headers',
'outgoing_message_body' => 'message_outgoing_body',
'address_sources' => 'addressbooks_list',
'get_address_book' => 'addressbook_get',
'create_contact' => 'contact_create',
'save_contact' => 'contact_save',
'delete_contact' => 'contact_delete',
'manage_folders' => 'folders_list',
'list_mailboxes' => 'mailboxes_list',
'save_preferences' => 'preferences_save',
'user_preferences' => 'preferences_list',
'list_prefs_sections' => 'preferences_sections_list',
'list_identities' => 'identities_list',
'create_identity' => 'identity_create',
'save_identity' => 'identity_save',
);
/** /**
* This implements the 'singleton' design pattern * This implements the 'singleton' design pattern
* *
@ -164,8 +191,17 @@ class rcube_plugin_api
*/ */
public function register_hook($hook, $callback) public function register_hook($hook, $callback)
{ {
if (is_callable($callback)) if (is_callable($callback)) {
if (isset($this->deprecated_hooks[$hook])) {
/* Uncoment after 0.4-stable release
raise_error(array('code' => 522, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Deprecated hook name. ".$hook.' -> '.$this->deprecated_hooks[$hook]), true, false);
*/
$hook = $this->deprecated_hooks[$hook];
}
$this->handlers[$hook][] = $callback; $this->handlers[$hook][] = $callback;
}
else else
raise_error(array('code' => 521, 'type' => 'php', raise_error(array('code' => 521, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,

@ -385,7 +385,7 @@ class rcube_user
$user_email = is_array($email_list[0]) ? $email_list[0]['email'] : $email_list[0]; $user_email = is_array($email_list[0]) ? $email_list[0]['email'] : $email_list[0];
} }
$data = $rcmail->plugins->exec_hook('create_user', $data = $rcmail->plugins->exec_hook('user_create',
array('user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email)); array('user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email));
// plugin aborted this operation // plugin aborted this operation
@ -444,7 +444,7 @@ class rcube_user
$record['user_id'] = $user_id; $record['user_id'] = $user_id;
$record['standard'] = $standard; $record['standard'] = $standard;
$plugin = $rcmail->plugins->exec_hook('create_identity', $plugin = $rcmail->plugins->exec_hook('identity_create',
array('login' => true, 'record' => $record)); array('login' => true, 'record' => $record));
if (!$plugin['abort'] && $plugin['record']['email']) { if (!$plugin['abort'] && $plugin['record']['email']) {

@ -37,7 +37,7 @@ 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('create_contact', array( $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
'record' => $CONTACTS->get_record($cid, true), 'record' => $CONTACTS->get_record($cid, true),
'source' => $target, 'source' => $target,
'group' => $target_group, 'group' => $target_group,

@ -23,7 +23,7 @@ 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('delete_contact', 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) : false;
if (!$deleted) if (!$deleted)

@ -155,7 +155,7 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'
'vcard' => $vcard->export(), 'vcard' => $vcard->export(),
); );
$plugin = $RCMAIL->plugins->exec_hook('create_contact', array('record' => $a_record, 'source' => null)); $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $a_record, 'source' => null));
$a_record = $plugin['record']; $a_record = $plugin['record'];
// insert record and send response // insert record and send response

@ -54,7 +54,7 @@ foreach ($a_save_cols as $col)
// update an existing contact // update an existing contact
if (!empty($cid)) if (!empty($cid))
{ {
$plugin = $RCMAIL->plugins->exec_hook('save_contact', array('id' => $cid, 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); $plugin = $RCMAIL->plugins->exec_hook('contact_save', 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)))
@ -102,7 +102,7 @@ else
return; return;
} }
$plugin = $RCMAIL->plugins->exec_hook('create_contact', 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

@ -47,7 +47,7 @@ if (!empty($_POST['_address']) && is_object($CONTACTS))
$OUTPUT->show_message('contactexists', 'warning'); $OUTPUT->show_message('contactexists', 'warning');
else else
{ {
$plugin = $RCMAIL->plugins->exec_hook('create_contact', 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))) if (!$plugin['abort'] && ($done = $CONTACTS->insert($contact)))

@ -32,7 +32,7 @@ if ($RCMAIL->action=='remove-attachment')
if (preg_match('/^rcmfile(\w+)$/', $_POST['_file'], $regs)) if (preg_match('/^rcmfile(\w+)$/', $_POST['_file'], $regs))
$id = $regs[1]; $id = $regs[1];
if ($attachment = $_SESSION['compose']['attachments'][$id]) if ($attachment = $_SESSION['compose']['attachments'][$id])
$attachment = $RCMAIL->plugins->exec_hook('remove_attachment', $attachment); $attachment = $RCMAIL->plugins->exec_hook('attachment_delete', $attachment);
if ($attachment['status']) { if ($attachment['status']) {
if (is_array($_SESSION['compose']['attachments'][$id])) { if (is_array($_SESSION['compose']['attachments'][$id])) {
unset($_SESSION['compose']['attachments'][$id]); unset($_SESSION['compose']['attachments'][$id]);
@ -50,7 +50,7 @@ if ($RCMAIL->action=='display-attachment')
if (preg_match('/^rcmfile(\w+)$/', $_GET['_file'], $regs)) if (preg_match('/^rcmfile(\w+)$/', $_GET['_file'], $regs))
$id = $regs[1]; $id = $regs[1];
if ($attachment = $_SESSION['compose']['attachments'][$id]) if ($attachment = $_SESSION['compose']['attachments'][$id])
$attachment = $RCMAIL->plugins->exec_hook('display_attachment', $attachment); $attachment = $RCMAIL->plugins->exec_hook('attachment_display', $attachment);
if ($attachment['status']) { if ($attachment['status']) {
if (empty($attachment['size'])) if (empty($attachment['size']))
@ -87,7 +87,7 @@ if (is_array($_FILES['_attachments']['tmp_name'])) {
'mimetype' => rc_mime_content_type($filepath, $_FILES['_attachments']['name'][$i], $_FILES['_attachments']['type'][$i]) 'mimetype' => rc_mime_content_type($filepath, $_FILES['_attachments']['name'][$i], $_FILES['_attachments']['type'][$i])
); );
$attachment = $RCMAIL->plugins->exec_hook('upload_attachment', $attachment); $attachment = $RCMAIL->plugins->exec_hook('attachment_upload', $attachment);
if ($attachment['status'] && !$attachment['abort']) { if ($attachment['status'] && !$attachment['abort']) {
$id = $attachment['id']; $id = $attachment['id'];

@ -81,7 +81,7 @@ if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_v
// save attachment if valid // save attachment if valid
if (($attachment['data'] && $attachment['name']) || ($attachment['path'] && file_exists($attachment['path']))) { if (($attachment['data'] && $attachment['name']) || ($attachment['path'] && file_exists($attachment['path']))) {
$attachment = rcmail::get_instance()->plugins->exec_hook('save_attachment', $attachment); $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
} }
if ($attachment['status'] && !$attachment['abort']) { if ($attachment['status'] && !$attachment['abort']) {
@ -829,7 +829,7 @@ function rcmail_save_attachment(&$message, $pid)
'size' => $path ? filesize($path) : strlen($data), 'size' => $path ? filesize($path) : strlen($data),
); );
$attachment = rcmail::get_instance()->plugins->exec_hook('save_attachment', $attachment); $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
if ($attachment['status']) { if ($attachment['status']) {
unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);
@ -853,7 +853,7 @@ function rcmail_save_image($path, $mimetype='')
'size' => strlen($data), 'size' => strlen($data),
); );
$attachment = rcmail::get_instance()->plugins->exec_hook('save_attachment', $attachment); $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
if ($attachment['status']) { if ($attachment['status']) {
unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);

@ -1325,7 +1325,7 @@ function rcmail_compose_cleanup()
return; return;
$rcmail = rcmail::get_instance(); $rcmail = rcmail::get_instance();
$rcmail->plugins->exec_hook('cleanup_attachments',array()); $rcmail->plugins->exec_hook('attachments_cleanup', array());
$rcmail->session->remove('compose'); $rcmail->session->remove('compose');
} }

@ -358,7 +358,7 @@ if (!empty($CONFIG['useragent']))
$headers['User-Agent'] = $CONFIG['useragent']; $headers['User-Agent'] = $CONFIG['useragent'];
// exec hook for header checking and manipulation // exec hook for header checking and manipulation
$data = $RCMAIL->plugins->exec_hook('outgoing_message_headers', array('headers' => $headers)); $data = $RCMAIL->plugins->exec_hook('message_outgoing_headers', array('headers' => $headers));
// sending aborted by plugin // sending aborted by plugin
if ($data['abort'] && !$savedraft) { if ($data['abort'] && !$savedraft) {
@ -428,7 +428,7 @@ if (is_array($_SESSION['compose']['attachments']) && $CONFIG['smtp_server']
// the HTML part and the plain-text part // the HTML part and the plain-text part
if ($isHtml) { if ($isHtml) {
$plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', $plugin = $RCMAIL->plugins->exec_hook('message_outgoing_body',
array('body' => $message_body, 'type' => 'html', 'message' => $MAIL_MIME)); array('body' => $message_body, 'type' => 'html', 'message' => $MAIL_MIME));
$MAIL_MIME->setHTMLBody($plugin['body']); $MAIL_MIME->setHTMLBody($plugin['body']);
@ -446,7 +446,7 @@ if ($isHtml) {
$plainTextPart = preg_replace('/\r?\n/', "\r\n", $plainTextPart); $plainTextPart = preg_replace('/\r?\n/', "\r\n", $plainTextPart);
} }
$plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', $plugin = $RCMAIL->plugins->exec_hook('message_outgoing_body',
array('body' => $plainTextPart, 'type' => 'alternative', 'message' => $MAIL_MIME)); array('body' => $plainTextPart, 'type' => 'alternative', 'message' => $MAIL_MIME));
$MAIL_MIME->setTXTBody($plugin['body']); $MAIL_MIME->setTXTBody($plugin['body']);
@ -456,7 +456,7 @@ if ($isHtml) {
$message_body = rcmail_fix_emoticon_paths($MAIL_MIME); $message_body = rcmail_fix_emoticon_paths($MAIL_MIME);
} }
else { else {
$plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', $plugin = $RCMAIL->plugins->exec_hook('message_outgoing_body',
array('body' => $message_body, 'type' => 'plain', 'message' => $MAIL_MIME)); array('body' => $message_body, 'type' => 'plain', 'message' => $MAIL_MIME));
$message_body = $plugin['body']; $message_body = $plugin['body'];
@ -481,7 +481,7 @@ if (is_array($_SESSION['compose']['attachments']))
{ {
foreach ($_SESSION['compose']['attachments'] as $id => $attachment) { foreach ($_SESSION['compose']['attachments'] as $id => $attachment) {
// This hook retrieves the attachment contents from the file storage backend // This hook retrieves the attachment contents from the file storage backend
$attachment = $RCMAIL->plugins->exec_hook('get_attachment', $attachment); $attachment = $RCMAIL->plugins->exec_hook('attachment_get', $attachment);
$dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]*/'; $dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]*/';
$message_body = $MAIL_MIME->getHTMLBody(); $message_body = $MAIL_MIME->getHTMLBody();

@ -75,7 +75,7 @@ function rcmail_identities_list($attrib)
$list[$idx]['mail'] = trim($row['name'] . ' <' . $row['email'] .'>'); $list[$idx]['mail'] = trim($row['name'] . ' <' . $row['email'] .'>');
// get all identites from DB and define list of cols to be displayed // get all identites from DB and define list of cols to be displayed
$plugin = $RCMAIL->plugins->exec_hook('list_identities', array( $plugin = $RCMAIL->plugins->exec_hook('identities_list', array(
'list' => $list, 'list' => $list,
'cols' => array('mail'))); 'cols' => array('mail')));
@ -131,7 +131,7 @@ function rcmail_user_prefs($current=null)
$sections['server'] = array('id' => 'server', 'section' => rcube_label('serversettings')); $sections['server'] = array('id' => 'server', 'section' => rcube_label('serversettings'));
// hook + define list cols // hook + define list cols
$plugin = $RCMAIL->plugins->exec_hook('list_prefs_sections', $plugin = $RCMAIL->plugins->exec_hook('preferences_sections_list',
array('list' => $sections, 'cols' => array('section'))); array('list' => $sections, 'cols' => array('section')));
$sections = $plugin['list']; $sections = $plugin['list'];
@ -676,7 +676,7 @@ function rcmail_user_prefs($current=null)
break; break;
} }
$data = $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $sect['id'], 'blocks' => $blocks)); $data = $RCMAIL->plugins->exec_hook('preferences_list', array('section' => $sect['id'], 'blocks' => $blocks));
$found = false; $found = false;
// create output // create output

@ -312,7 +312,7 @@ function rcube_subscription_form($attrib)
$a_js_folders['rcmrow'.$idx] = array($folder_utf8, $display_folder, $protected || $folder['virtual']); $a_js_folders['rcmrow'.$idx] = array($folder_utf8, $display_folder, $protected || $folder['virtual']);
} }
rcmail::get_instance()->plugins->exec_hook('manage_folders', array('table'=>$table)); rcmail::get_instance()->plugins->exec_hook('folders_list', array('table'=>$table));
$OUTPUT->add_gui_object('subscriptionlist', $attrib['id']); $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']);
$OUTPUT->set_env('subscriptionrows', $a_js_folders); $OUTPUT->set_env('subscriptionrows', $a_js_folders);

@ -61,7 +61,7 @@ if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3)
if ($_POST['_iid']) if ($_POST['_iid'])
{ {
$iid = get_input_value('_iid', RCUBE_INPUT_POST); $iid = get_input_value('_iid', RCUBE_INPUT_POST);
$plugin = $RCMAIL->plugins->exec_hook('save_identity', array('id' => $iid, 'record' => $save_data)); $plugin = $RCMAIL->plugins->exec_hook('identity_save', array('id' => $iid, 'record' => $save_data));
$save_data = $plugin['record']; $save_data = $plugin['record'];
if (!$plugin['abort'] && ($updated = $USER->update_identity($iid, $save_data))) if (!$plugin['abort'] && ($updated = $USER->update_identity($iid, $save_data)))
@ -92,7 +92,7 @@ else if (IDENTITIES_LEVEL < 2)
if (IDENTITIES_LEVEL == 1) if (IDENTITIES_LEVEL == 1)
$save_data['email'] = $RCMAIL->user->get_username(); $save_data['email'] = $RCMAIL->user->get_username();
$plugin = $RCMAIL->plugins->exec_hook('create_identity', array('record' => $save_data)); $plugin = $RCMAIL->plugins->exec_hook('identity_create', array('record' => $save_data));
$save_data = $plugin['record']; $save_data = $plugin['record'];
if (!$plugin['abort'] && $save_data['email'] && ($insert_id = $USER->insert_identity($save_data))) if (!$plugin['abort'] && $save_data['email'] && ($insert_id = $USER->insert_identity($save_data)))

@ -95,7 +95,7 @@ switch ($CURR_SECTION)
break; break;
} }
$data = rcmail::get_instance()->plugins->exec_hook('save_preferences', $data = rcmail::get_instance()->plugins->exec_hook('preferences_save',
array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION)); array('prefs' => $a_user_prefs, 'section' => $CURR_SECTION));
$a_user_prefs = $data['prefs']; $a_user_prefs = $data['prefs'];

Loading…
Cancel
Save