Skip to content

Commit

Permalink
working with RC 1.3, 1.2, 1.X and 0.9 by deprecating the rcmail usage
Browse files Browse the repository at this point in the history
* hpes fixed sblaisot#20
  • Loading branch information
mckaygerhard committed Jan 1, 2020
1 parent ca622de commit 641e493
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.5 :
* able to work wit rouncube 0.9 to 1.3, including the 1.2 and 1.X releases, deprecating the rcmail usage

v0.4 :
* Refresh contact list when editing a contact in collected addressbook and having on_edit_move_to_default set to true (#68)
* Refresh contact list when copying a contact from collected addressbook and having on_edit_move_to_default set to true (Fix #69)
Expand Down
14 changes: 7 additions & 7 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Look at https://github.com/sblaisot/automatic_addressbook
Installing automatic addressbook plugin
---------------------------------------

You need roundcube > 0.4 installed.
You need roundcube > 0.9 installed.

automatic_addressbook plugin version 0.2 has been tester against roundcube 0.5 and 0.6.
above versions have been tested against roundcube 0.8.0 and 0.8.1 with larry skin and mysql backend.
automatic_addressbook plugin version 0.2 has been tester against roundcube 0.9
with larry skin and mysql backend.

Download the latest version archive

Expand All @@ -16,15 +16,13 @@ Download the latest version archive
mv automatic_addressbook <path_to_roundcube>/plugins/

2. Execute the relevant SQL/<db engine>.initial.sql script on your database (process depends on your DB engine)
If your Roundcube Database starts with a prefix set the prefix also in the SQL Statement: "REFERENCES `PREFIX_users`(`user_id`)"
If your Roundcube Database starts with a prefix set the prefix also in create table also references table query sentences.

3. Add "automatic_addressbook" to the plugins list in
<path_to_roundcube>/config/main.inc.php or <path_to_roundcube>/config/config.inc.php depending on your roundcube version, for example :

$rcmail_config['plugins'] = array('automatic_addressbook',);

It works :)


Configuration
-------------
Expand All @@ -37,9 +35,11 @@ You can customize some settings :
Among others, you can choose if your users will have automatic_addressbook enabled or disabled by default (use_auto_abook option).


Upgrading roundcube to 0.6
Olders roundcube up to 0.8
--------------------------

you must use files before commit ca622de3364b996c655eea2e7724ce6e325e9b9d for older versions.

If you upgrade from roundcube 0.5 to 0.6, automatic addressbook plugin will continue to work :

Be sure to use the last version of the plugin ;
Expand Down
62 changes: 31 additions & 31 deletions automatic_addressbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function init()


// use this address book for autocompletion queries
$config = rcmail::get_instance()->config;
$config = rcube::get_instance()->config;
$sources = $config->get('autocomplete_addressbooks', array('sql'));

if (!in_array($this->abook_id, $sources) &&
Expand All @@ -74,8 +74,8 @@ public function init()
*/
public function address_sources($p)
{
$rcmail = rcmail::get_instance();
if ($rcmail->config->get('use_auto_abook', true)) {
$rcube = rcube::get_instance();
if ($rcube->config->get('use_auto_abook', true)) {
$p['sources'][$this->abook_id] =
array('id' => $this->abook_id,
'name' => rcube_utils::rep_specialchars_output($this->gettext('automaticallycollected')),
Expand All @@ -93,10 +93,10 @@ public function address_sources($p)
*/
public function get_address_book($p)
{
$rcmail = rcmail::get_instance();
if (($p['id'] === $this->abook_id) && $rcmail->config->get('use_auto_abook', true)) {
$rcube = rcube::get_instance();
if (($p['id'] === $this->abook_id) && $rcube->config->get('use_auto_abook', true)) {
require_once dirname(__FILE__) . '/automatic_addressbook_backend.php';
$p['instance'] = new automatic_addressbook_backend($rcmail->db, $rcmail->user->ID);
$p['instance'] = new automatic_addressbook_backend($rcube->db, $rcube->user->ID);
$p['instance']->groups = false;
}
return $p;
Expand All @@ -112,9 +112,9 @@ public function get_address_book($p)
*/
public function register_recipients($p)
{
$rcmail = rcmail::get_instance();
$rcube = rcube::get_instance();

if (!$rcmail->config->get('use_auto_abook', true)) {
if (!$rcube->config->get('use_auto_abook', true)) {
return;
}

Expand All @@ -136,7 +136,7 @@ public function register_recipients($p)
}

require_once dirname(__FILE__) . '/automatic_addressbook_backend.php';
$CONTACTS = new automatic_addressbook_backend($rcmail->db, $rcmail->user->ID);
$CONTACTS = new automatic_addressbook_backend($rcube->db, $rcube->user->ID);

foreach ($all_recipients as $recipient) {
// Bcc and Cc can be empty
Expand All @@ -156,18 +156,18 @@ public function register_recipients($p)
* address book if it is not already in an addressbook, so we
* first lookup in every address source.
*/
$book_types = (array)$rcmail->config->get('autocomplete_addressbooks', 'sql');
$book_types = (array)$rcube->config->get('autocomplete_addressbooks', 'sql');

foreach ($book_types as $id) {
$abook = $rcmail->get_address_book($id);
$abook = $rcube->get_address_book($id);
$previous_entries = $abook->search('email', $contact['email'], false, false);

if ($previous_entries->count) {
break;
}
}
if (!$previous_entries->count) {
$plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact,
$plugin = $rcube->plugins->exec_hook('contact_create', array('record' => $contact,
'source' => $this->abook_id));
if (!$plugin['abort']) {
$CONTACTS->insert($contact, false);
Expand Down Expand Up @@ -205,7 +205,7 @@ public function add_addressbook_category($args)
public function settings_table($args)
{
if ($args['section'] == 'addressbook') {
$use_auto_abook = rcmail::get_instance()->config->get('use_auto_abook', true);
$use_auto_abook = rcube::get_instance()->config->get('use_auto_abook', true);
$field_id = 'rcmfd_use_auto_abook';

$checkbox = new html_checkbox(array(
Expand All @@ -218,7 +218,7 @@ public function settings_table($args)
'content' => $checkbox->show($use_auto_abook ? 1 : 0),
);

$use_auto_abook_for_completion = rcmail::get_instance()->config->get('use_auto_abook_for_completion', true);
$use_auto_abook_for_completion = rcube::get_instance()->config->get('use_auto_abook_for_completion', true);
$field_id2 = 'rcmfd_use_auto_abook_for_completion';
$checkbox2 = new html_checkbox(array(
'name' => '_use_auto_abook_for_completion',
Expand All @@ -242,10 +242,10 @@ public function settings_table($args)
public function save_prefs($args)
{
if ($args['section'] == 'addressbook') {
$rcmail = rcmail::get_instance();
$use_auto_abook = $rcmail->config->get('use_auto_abook');
$rcube = rcube::get_instance();
$use_auto_abook = $rcube->config->get('use_auto_abook');
$args['prefs']['use_auto_abook'] = isset($_POST['_use_auto_abook']) ? true : false;
$use_auto_abook_for_completion = $rcmail->config->get('use_auto_abook_for_completion');
$use_auto_abook_for_completion = $rcube->config->get('use_auto_abook_for_completion');
$args['prefs']['use_auto_abook_for_completion'] = isset($_POST['_use_auto_abook_for_completion']) ? true : false;
}
return $args;
Expand All @@ -260,24 +260,24 @@ public function save_prefs($args)
*/
public function handle_doubles($args)
{
$rcmail = rcmail::get_instance();
if (!$rcmail->config->get('use_auto_abook', true)) {
$rcube = rcube::get_instance();
if (!$rcube->config->get('use_auto_abook', true)) {
return $args;
}
$moveto = $rcmail->config->get('on_edit_move_to_default');
$moveto = $rcube->config->get('on_edit_move_to_default');

if ($args['source'] == $this->abook_id && !empty($args['id']) && $moveto) {
$args['source'] = $rcmail->config->get('default_addressbook');
$plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $args['record'],
$args['source'] = $rcube->config->get('default_addressbook');
$plugin = $rcube->plugins->exec_hook('contact_create', array('record' => $args['record'],
'source' => $args['source']));
if (!$plugin['abort']) {
$CONTACTS = $rcmail->get_address_book($args['source']);
$CONTACTS = $rcube->get_address_book($args['source']);
$insert_id = $CONTACTS->insert($args['record'], false);
} else {
$insert_id = $plugin['result'];
}
$rcmail->output->show_message('automatic_addressbook.contactmoved', 'confirmation');
$rcmail->output->command('parent.list_contacts');
$rcube->output->show_message('automatic_addressbook.contactmoved', 'confirmation');
$rcube->output->command('parent.list_contacts');
return array('abort' => true, 'result' => $insert_id);
}

Expand All @@ -296,23 +296,23 @@ public function handle_doubles($args)

foreach ($contact_emails as $contact_email) {
if (!empty($contact_email)) {
$auto_abook = $rcmail->get_address_book($this->abook_id);
$auto_abook = $rcube->get_address_book($this->abook_id);
$auto_abook->reset();
$collected_contact = $auto_abook->search('email', $contact_email, false, true);
while ($record = $collected_contact->iterate()) {
$plugin = $rcmail->plugins->exec_hook('contact_delete', array('id' => $record['contact_id'],
$plugin = $rcube->plugins->exec_hook('contact_delete', array('id' => $record['contact_id'],
'source' => $this->abook_id));
if (!$plugin['abort']) {
$auto_abook->delete($record['contact_id']);
$rcmail->output->show_message('automatic_addressbook.contactremoved', 'confirmation');
$rcube->output->show_message('automatic_addressbook.contactremoved', 'confirmation');
}
}
}
}
if ($rcmail->task == "addressbook" &&
$rcmail->action == "copy" &&
if ($rcube->task == "addressbook" &&
$rcube->action == "copy" &&
$_REQUEST['_source'] == $this->abook_id) {
$rcmail->output->command('parent.list_contacts');
$rcube->output->command('parent.list_contacts');
}
}

Expand Down
2 changes: 1 addition & 1 deletion automatic_addressbook_backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class automatic_addressbook_backend extends rcube_contacts
function __construct($dbconn, $user)
{
parent::__construct($dbconn, $user);
$this->db_name = rcmail::get_instance()->db->table_name('collected_contacts');
$this->db_name = rcube::get_instance()->db->table_name('collected_contacts');
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"extra":
{
"roundcube": {
"min-version": "0.6.0",
"min-version": "0.9.0",
"max-version": "10.21",
"sql-dir": "SQL"
}
Expand Down

0 comments on commit 641e493

Please sign in to comment.