From e6ce0062f2331b8756cc91944ceaea8d7cbffd18 Mon Sep 17 00:00:00 2001 From: alecpl Date: Fri, 30 Jul 2010 06:34:02 +0000 Subject: - Unify hooks names, see rcube_plugin_api::deprecated_hooks for complete list (old names are supported without errors nor warnings) --- program/include/rcmail.php | 6 ++--- program/include/rcube_imap.php | 4 ++-- program/include/rcube_plugin_api.php | 38 ++++++++++++++++++++++++++++++- program/include/rcube_user.php | 4 ++-- program/steps/addressbook/copy.inc | 2 +- program/steps/addressbook/delete.inc | 2 +- program/steps/addressbook/import.inc | 2 +- program/steps/addressbook/save.inc | 4 ++-- program/steps/mail/addcontact.inc | 2 +- program/steps/mail/attachments.inc | 6 ++--- program/steps/mail/compose.inc | 6 ++--- program/steps/mail/func.inc | 2 +- program/steps/mail/sendmail.inc | 10 ++++---- program/steps/settings/func.inc | 6 ++--- program/steps/settings/manage_folders.inc | 2 +- program/steps/settings/save_identity.inc | 4 ++-- program/steps/settings/save_prefs.inc | 2 +- 17 files changed, 69 insertions(+), 33 deletions(-) (limited to 'program') diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 3fa2fa2cc..5ca25df80 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -255,7 +255,7 @@ class rcmail $ldap_config = (array)$this->config->get('ldap_public'); $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 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']; if ($writeable && !empty($list)) { @@ -928,7 +928,7 @@ class rcmail */ public function kill_session() { - $this->plugins->exec_hook('kill_session'); + $this->plugins->exec_hook('session_destroy'); $this->session->remove(); $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true); diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index d6a549d10..9c3653120 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2589,7 +2589,7 @@ class rcube_imap $a_defaults = $a_out = array(); // 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')); if (isset($data['folders'])) { @@ -2620,7 +2620,7 @@ class rcube_imap function list_unsubscribed($root='', $filter='*') { // 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')); if (isset($data['folders'])) { diff --git a/program/include/rcube_plugin_api.php b/program/include/rcube_plugin_api.php index 123c56a45..7fe0d4f34 100644 --- a/program/include/rcube_plugin_api.php +++ b/program/include/rcube_plugin_api.php @@ -43,6 +43,33 @@ class rcube_plugin_api private $required_plugins = array('filesystem_attachments'); 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 * @@ -164,8 +191,17 @@ class rcube_plugin_api */ 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; + } else raise_error(array('code' => 521, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php index b1263ca02..22ec38d2e 100644 --- a/program/include/rcube_user.php +++ b/program/include/rcube_user.php @@ -385,7 +385,7 @@ class rcube_user $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)); // plugin aborted this operation @@ -444,7 +444,7 @@ class rcube_user $record['user_id'] = $user_id; $record['standard'] = $standard; - $plugin = $rcmail->plugins->exec_hook('create_identity', + $plugin = $rcmail->plugins->exec_hook('identity_create', array('login' => true, 'record' => $record)); if (!$plugin['abort'] && $plugin['record']['email']) { diff --git a/program/steps/addressbook/copy.inc b/program/steps/addressbook/copy.inc index 1b938726c..679e999ed 100644 --- a/program/steps/addressbook/copy.inc +++ b/program/steps/addressbook/copy.inc @@ -37,7 +37,7 @@ 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('create_contact', array( + $plugin = $RCMAIL->plugins->exec_hook('contact_create', array( 'record' => $CONTACTS->get_record($cid, true), 'source' => $target, 'group' => $target_group, diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc index ba0ac0fad..90719732f 100644 --- a/program/steps/addressbook/delete.inc +++ b/program/steps/addressbook/delete.inc @@ -23,7 +23,7 @@ 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('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; if (!$deleted) diff --git a/program/steps/addressbook/import.inc b/program/steps/addressbook/import.inc index 9ba1c1d90..ec77f8991 100644 --- a/program/steps/addressbook/import.inc +++ b/program/steps/addressbook/import.inc @@ -155,7 +155,7 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name' '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']; // insert record and send response diff --git a/program/steps/addressbook/save.inc b/program/steps/addressbook/save.inc index a277008c8..800bf4632 100644 --- a/program/steps/addressbook/save.inc +++ b/program/steps/addressbook/save.inc @@ -54,7 +54,7 @@ foreach ($a_save_cols as $col) // update an existing contact 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']; if (!$plugin['abort'] && ($result = $CONTACTS->update($cid, $a_record))) @@ -102,7 +102,7 @@ else 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']; // insert record and send response diff --git a/program/steps/mail/addcontact.inc b/program/steps/mail/addcontact.inc index 20a49a169..8a071be6d 100644 --- a/program/steps/mail/addcontact.inc +++ b/program/steps/mail/addcontact.inc @@ -47,7 +47,7 @@ if (!empty($_POST['_address']) && is_object($CONTACTS)) $OUTPUT->show_message('contactexists', 'warning'); 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']; if (!$plugin['abort'] && ($done = $CONTACTS->insert($contact))) diff --git a/program/steps/mail/attachments.inc b/program/steps/mail/attachments.inc index dca727278..797c30ca3 100644 --- a/program/steps/mail/attachments.inc +++ b/program/steps/mail/attachments.inc @@ -32,7 +32,7 @@ if ($RCMAIL->action=='remove-attachment') if (preg_match('/^rcmfile(\w+)$/', $_POST['_file'], $regs)) $id = $regs[1]; 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 (is_array($_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)) $id = $regs[1]; 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 (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]) ); - $attachment = $RCMAIL->plugins->exec_hook('upload_attachment', $attachment); + $attachment = $RCMAIL->plugins->exec_hook('attachment_upload', $attachment); if ($attachment['status'] && !$attachment['abort']) { $id = $attachment['id']; diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 712318d93..c154301e3 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -81,7 +81,7 @@ if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_v // save attachment if valid 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']) { @@ -829,7 +829,7 @@ function rcmail_save_attachment(&$message, $pid) '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']) { unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); @@ -853,7 +853,7 @@ function rcmail_save_image($path, $mimetype='') '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']) { unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']); diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index a1cc68d16..c96f442c7 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -1325,7 +1325,7 @@ function rcmail_compose_cleanup() return; $rcmail = rcmail::get_instance(); - $rcmail->plugins->exec_hook('cleanup_attachments',array()); + $rcmail->plugins->exec_hook('attachments_cleanup', array()); $rcmail->session->remove('compose'); } diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 91f374cea..300bea019 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -358,7 +358,7 @@ if (!empty($CONFIG['useragent'])) $headers['User-Agent'] = $CONFIG['useragent']; // 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 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 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)); $MAIL_MIME->setHTMLBody($plugin['body']); @@ -446,7 +446,7 @@ if ($isHtml) { $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)); $MAIL_MIME->setTXTBody($plugin['body']); @@ -456,7 +456,7 @@ if ($isHtml) { $message_body = rcmail_fix_emoticon_paths($MAIL_MIME); } 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)); $message_body = $plugin['body']; @@ -481,7 +481,7 @@ if (is_array($_SESSION['compose']['attachments'])) { foreach ($_SESSION['compose']['attachments'] as $id => $attachment) { // 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\'"]*/'; $message_body = $MAIL_MIME->getHTMLBody(); diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index d71714b64..b611e66f9 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -75,7 +75,7 @@ function rcmail_identities_list($attrib) $list[$idx]['mail'] = trim($row['name'] . ' <' . $row['email'] .'>'); // 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, 'cols' => array('mail'))); @@ -131,7 +131,7 @@ function rcmail_user_prefs($current=null) $sections['server'] = array('id' => 'server', 'section' => rcube_label('serversettings')); // 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'))); $sections = $plugin['list']; @@ -676,7 +676,7 @@ function rcmail_user_prefs($current=null) 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; // create output diff --git a/program/steps/settings/manage_folders.inc b/program/steps/settings/manage_folders.inc index e3231ac28..a8a4083a7 100644 --- a/program/steps/settings/manage_folders.inc +++ b/program/steps/settings/manage_folders.inc @@ -312,7 +312,7 @@ function rcube_subscription_form($attrib) $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->set_env('subscriptionrows', $a_js_folders); diff --git a/program/steps/settings/save_identity.inc b/program/steps/settings/save_identity.inc index ea8c3b13d..53cd516da 100644 --- a/program/steps/settings/save_identity.inc +++ b/program/steps/settings/save_identity.inc @@ -61,7 +61,7 @@ if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3) if ($_POST['_iid']) { $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']; if (!$plugin['abort'] && ($updated = $USER->update_identity($iid, $save_data))) @@ -92,7 +92,7 @@ else if (IDENTITIES_LEVEL < 2) if (IDENTITIES_LEVEL == 1) $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']; if (!$plugin['abort'] && $save_data['email'] && ($insert_id = $USER->insert_identity($save_data))) diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc index dd304861d..3f13c0af4 100644 --- a/program/steps/settings/save_prefs.inc +++ b/program/steps/settings/save_prefs.inc @@ -95,7 +95,7 @@ switch ($CURR_SECTION) 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)); $a_user_prefs = $data['prefs']; -- cgit v1.2.3