From 61be822d62ea245b7f54ad313f49a956ab49076d Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 18 Jan 2013 15:24:49 +0100 Subject: Remove deprecated functions (from bc.php file) usage in plugins --- plugins/virtuser_query/virtuser_query.php | 62 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'plugins/virtuser_query') diff --git a/plugins/virtuser_query/virtuser_query.php b/plugins/virtuser_query/virtuser_query.php index 073b4e230..c479a4f7f 100644 --- a/plugins/virtuser_query/virtuser_query.php +++ b/plugins/virtuser_query/virtuser_query.php @@ -28,8 +28,8 @@ class virtuser_query extends rcube_plugin function init() { - $this->app = rcmail::get_instance(); - $this->config = $this->app->config->get('virtuser_query'); + $this->app = rcmail::get_instance(); + $this->config = $this->app->config->get('virtuser_query'); if (!empty($this->config)) { if (is_string($this->config)) { @@ -53,35 +53,35 @@ class virtuser_query extends rcube_plugin */ function user2email($p) { - $dbh = $this->app->get_dbh(); - - $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['email'])); - - while ($sql_arr = $dbh->fetch_array($sql_result)) { - if (strpos($sql_arr[0], '@')) { - if ($p['extended'] && count($sql_arr) > 1) { - $result[] = array( - 'email' => rcube_idn_to_ascii($sql_arr[0]), - 'name' => $sql_arr[1], - 'organization' => $sql_arr[2], - 'reply-to' => rcube_idn_to_ascii($sql_arr[3]), - 'bcc' => rcube_idn_to_ascii($sql_arr[4]), - 'signature' => $sql_arr[5], - 'html_signature' => (int)$sql_arr[6], - ); - } - else { - $result[] = $sql_arr[0]; - } - - if ($p['first']) - break; - } - } - - $p['email'] = $result; - - return $p; + $dbh = $this->app->get_dbh(); + + $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['email'])); + + while ($sql_arr = $dbh->fetch_array($sql_result)) { + if (strpos($sql_arr[0], '@')) { + if ($p['extended'] && count($sql_arr) > 1) { + $result[] = array( + 'email' => rcube_utils::idn_to_ascii($sql_arr[0]), + 'name' => $sql_arr[1], + 'organization' => $sql_arr[2], + 'reply-to' => rcube_utils::idn_to_ascii($sql_arr[3]), + 'bcc' => rcube_utils::idn_to_ascii($sql_arr[4]), + 'signature' => $sql_arr[5], + 'html_signature' => (int)$sql_arr[6], + ); + } + else { + $result[] = $sql_arr[0]; + } + + if ($p['first']) + break; + } + } + + $p['email'] = $result; + + return $p; } /** -- cgit v1.2.3 From b005927f919cbc09dccf71e8c638be45a8af37d0 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 19 Jan 2013 12:16:16 +0100 Subject: Add basic tests for plugins --- plugins/acl/tests/Acl.php | 23 ++++++++++++++++ .../tests/AdditionalMessageHeaders.php | 23 ++++++++++++++++ plugins/archive/tests/Archive.php | 23 ++++++++++++++++ plugins/autologon/tests/Autologon.php | 23 ++++++++++++++++ .../tests/DatabaseAttachments.php | 23 ++++++++++++++++ plugins/debug_logger/debug_logger.php | 7 ++--- plugins/debug_logger/tests/DebugLogger.php | 23 ++++++++++++++++ plugins/emoticons/tests/Emoticons.php | 23 ++++++++++++++++ plugins/enigma/tests/Enigma.php | 23 ++++++++++++++++ .../tests/ExampleAddressbook.php | 23 ++++++++++++++++ .../tests/FilesystemAttachments.php | 23 ++++++++++++++++ plugins/help/tests/Help.php | 23 ++++++++++++++++ plugins/hide_blockquote/tests/HideBlockquote.php | 23 ++++++++++++++++ .../tests/HttpAuthentication.php | 23 ++++++++++++++++ plugins/jqueryui/tests/Jqueryui.php | 23 ++++++++++++++++ plugins/managesieve/tests/Managesieve.php | 23 ++++++++++++++++ plugins/markasjunk/tests/Markasjunk.php | 23 ++++++++++++++++ plugins/new_user_dialog/tests/NewUserDialog.php | 23 ++++++++++++++++ .../new_user_identity/tests/NewUserIdentity.php | 23 ++++++++++++++++ plugins/newmail_notifier/tests/NewmailNotifier.php | 23 ++++++++++++++++ plugins/password/tests/Password.php | 23 ++++++++++++++++ .../tests/RedundantAttachments.php | 23 ++++++++++++++++ .../tests/ShowAdditionalHeaders.php | 23 ++++++++++++++++ .../tests/SquirrelmailUsercopy.php | 23 ++++++++++++++++ .../tests/SubscriptionsOption.php | 23 ++++++++++++++++ plugins/userinfo/tests/Userinfo.php | 23 ++++++++++++++++ .../vcard_attachments/tests/VcardAttachments.php | 23 ++++++++++++++++ plugins/virtuser_file/tests/VirtuserFile.php | 23 ++++++++++++++++ plugins/virtuser_query/tests/VirtuserQuery.php | 23 ++++++++++++++++ plugins/zipdownload/tests/Zipdownload.php | 23 ++++++++++++++++ tests/bootstrap.php | 6 +++++ tests/phpunit.xml | 31 +++++++++++++++++++++- 32 files changed, 707 insertions(+), 4 deletions(-) create mode 100644 plugins/acl/tests/Acl.php create mode 100644 plugins/additional_message_headers/tests/AdditionalMessageHeaders.php create mode 100644 plugins/archive/tests/Archive.php create mode 100644 plugins/autologon/tests/Autologon.php create mode 100644 plugins/database_attachments/tests/DatabaseAttachments.php create mode 100644 plugins/debug_logger/tests/DebugLogger.php create mode 100644 plugins/emoticons/tests/Emoticons.php create mode 100644 plugins/enigma/tests/Enigma.php create mode 100644 plugins/example_addressbook/tests/ExampleAddressbook.php create mode 100644 plugins/filesystem_attachments/tests/FilesystemAttachments.php create mode 100644 plugins/help/tests/Help.php create mode 100644 plugins/hide_blockquote/tests/HideBlockquote.php create mode 100644 plugins/http_authentication/tests/HttpAuthentication.php create mode 100644 plugins/jqueryui/tests/Jqueryui.php create mode 100644 plugins/managesieve/tests/Managesieve.php create mode 100644 plugins/markasjunk/tests/Markasjunk.php create mode 100644 plugins/new_user_dialog/tests/NewUserDialog.php create mode 100644 plugins/new_user_identity/tests/NewUserIdentity.php create mode 100644 plugins/newmail_notifier/tests/NewmailNotifier.php create mode 100644 plugins/password/tests/Password.php create mode 100644 plugins/redundant_attachments/tests/RedundantAttachments.php create mode 100644 plugins/show_additional_headers/tests/ShowAdditionalHeaders.php create mode 100644 plugins/squirrelmail_usercopy/tests/SquirrelmailUsercopy.php create mode 100644 plugins/subscriptions_option/tests/SubscriptionsOption.php create mode 100644 plugins/userinfo/tests/Userinfo.php create mode 100644 plugins/vcard_attachments/tests/VcardAttachments.php create mode 100644 plugins/virtuser_file/tests/VirtuserFile.php create mode 100644 plugins/virtuser_query/tests/VirtuserQuery.php create mode 100644 plugins/zipdownload/tests/Zipdownload.php (limited to 'plugins/virtuser_query') diff --git a/plugins/acl/tests/Acl.php b/plugins/acl/tests/Acl.php new file mode 100644 index 000000000..e752ac977 --- /dev/null +++ b/plugins/acl/tests/Acl.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('acl', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/additional_message_headers/tests/AdditionalMessageHeaders.php b/plugins/additional_message_headers/tests/AdditionalMessageHeaders.php new file mode 100644 index 000000000..1c54ffc42 --- /dev/null +++ b/plugins/additional_message_headers/tests/AdditionalMessageHeaders.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('additional_message_headers', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/archive/tests/Archive.php b/plugins/archive/tests/Archive.php new file mode 100644 index 000000000..0a1eeae11 --- /dev/null +++ b/plugins/archive/tests/Archive.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('archive', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/autologon/tests/Autologon.php b/plugins/autologon/tests/Autologon.php new file mode 100644 index 000000000..0de193e4a --- /dev/null +++ b/plugins/autologon/tests/Autologon.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('autologon', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/database_attachments/tests/DatabaseAttachments.php b/plugins/database_attachments/tests/DatabaseAttachments.php new file mode 100644 index 000000000..f260737ab --- /dev/null +++ b/plugins/database_attachments/tests/DatabaseAttachments.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('database_attachments', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/debug_logger/debug_logger.php b/plugins/debug_logger/debug_logger.php index 1e015c201..87a163785 100644 --- a/plugins/debug_logger/debug_logger.php +++ b/plugins/debug_logger/debug_logger.php @@ -142,8 +142,9 @@ class debug_logger extends rcube_plugin return $args; } - function __destruct(){ - $this->runlog->end(); + function __destruct() + { + if ($this->runlog) + $this->runlog->end(); } } -?> diff --git a/plugins/debug_logger/tests/DebugLogger.php b/plugins/debug_logger/tests/DebugLogger.php new file mode 100644 index 000000000..de20a069d --- /dev/null +++ b/plugins/debug_logger/tests/DebugLogger.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('debug_logger', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/emoticons/tests/Emoticons.php b/plugins/emoticons/tests/Emoticons.php new file mode 100644 index 000000000..4b6c303c2 --- /dev/null +++ b/plugins/emoticons/tests/Emoticons.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('emoticons', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/enigma/tests/Enigma.php b/plugins/enigma/tests/Enigma.php new file mode 100644 index 000000000..0d0d8f8ae --- /dev/null +++ b/plugins/enigma/tests/Enigma.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('enigma', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/example_addressbook/tests/ExampleAddressbook.php b/plugins/example_addressbook/tests/ExampleAddressbook.php new file mode 100644 index 000000000..4a54bd950 --- /dev/null +++ b/plugins/example_addressbook/tests/ExampleAddressbook.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('example_addressbook', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/filesystem_attachments/tests/FilesystemAttachments.php b/plugins/filesystem_attachments/tests/FilesystemAttachments.php new file mode 100644 index 000000000..dcab315d3 --- /dev/null +++ b/plugins/filesystem_attachments/tests/FilesystemAttachments.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('filesystem_attachments', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/help/tests/Help.php b/plugins/help/tests/Help.php new file mode 100644 index 000000000..baba492ae --- /dev/null +++ b/plugins/help/tests/Help.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('help', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/hide_blockquote/tests/HideBlockquote.php b/plugins/hide_blockquote/tests/HideBlockquote.php new file mode 100644 index 000000000..030c05324 --- /dev/null +++ b/plugins/hide_blockquote/tests/HideBlockquote.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('hide_blockquote', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/http_authentication/tests/HttpAuthentication.php b/plugins/http_authentication/tests/HttpAuthentication.php new file mode 100644 index 000000000..c17236821 --- /dev/null +++ b/plugins/http_authentication/tests/HttpAuthentication.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('http_authentication', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/jqueryui/tests/Jqueryui.php b/plugins/jqueryui/tests/Jqueryui.php new file mode 100644 index 000000000..3bcd27c9f --- /dev/null +++ b/plugins/jqueryui/tests/Jqueryui.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('jqueryui', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/managesieve/tests/Managesieve.php b/plugins/managesieve/tests/Managesieve.php new file mode 100644 index 000000000..d802f5614 --- /dev/null +++ b/plugins/managesieve/tests/Managesieve.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('managesieve', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/markasjunk/tests/Markasjunk.php b/plugins/markasjunk/tests/Markasjunk.php new file mode 100644 index 000000000..cdf13255e --- /dev/null +++ b/plugins/markasjunk/tests/Markasjunk.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('markasjunk', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/new_user_dialog/tests/NewUserDialog.php b/plugins/new_user_dialog/tests/NewUserDialog.php new file mode 100644 index 000000000..3a52f20f3 --- /dev/null +++ b/plugins/new_user_dialog/tests/NewUserDialog.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('new_user_dialog', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/new_user_identity/tests/NewUserIdentity.php b/plugins/new_user_identity/tests/NewUserIdentity.php new file mode 100644 index 000000000..c1d385853 --- /dev/null +++ b/plugins/new_user_identity/tests/NewUserIdentity.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('new_user_identity', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/newmail_notifier/tests/NewmailNotifier.php b/plugins/newmail_notifier/tests/NewmailNotifier.php new file mode 100644 index 000000000..571912a61 --- /dev/null +++ b/plugins/newmail_notifier/tests/NewmailNotifier.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('newmail_notifier', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/password/tests/Password.php b/plugins/password/tests/Password.php new file mode 100644 index 000000000..a9663a946 --- /dev/null +++ b/plugins/password/tests/Password.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('password', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/redundant_attachments/tests/RedundantAttachments.php b/plugins/redundant_attachments/tests/RedundantAttachments.php new file mode 100644 index 000000000..386f97e59 --- /dev/null +++ b/plugins/redundant_attachments/tests/RedundantAttachments.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('redundant_attachments', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/show_additional_headers/tests/ShowAdditionalHeaders.php b/plugins/show_additional_headers/tests/ShowAdditionalHeaders.php new file mode 100644 index 000000000..902ce510b --- /dev/null +++ b/plugins/show_additional_headers/tests/ShowAdditionalHeaders.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('show_additional_headers', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/squirrelmail_usercopy/tests/SquirrelmailUsercopy.php b/plugins/squirrelmail_usercopy/tests/SquirrelmailUsercopy.php new file mode 100644 index 000000000..2e35509f0 --- /dev/null +++ b/plugins/squirrelmail_usercopy/tests/SquirrelmailUsercopy.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('squirrelmail_usercopy', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/subscriptions_option/tests/SubscriptionsOption.php b/plugins/subscriptions_option/tests/SubscriptionsOption.php new file mode 100644 index 000000000..6932a955f --- /dev/null +++ b/plugins/subscriptions_option/tests/SubscriptionsOption.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('subscriptions_option', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/userinfo/tests/Userinfo.php b/plugins/userinfo/tests/Userinfo.php new file mode 100644 index 000000000..762d5a1fa --- /dev/null +++ b/plugins/userinfo/tests/Userinfo.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('userinfo', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/vcard_attachments/tests/VcardAttachments.php b/plugins/vcard_attachments/tests/VcardAttachments.php new file mode 100644 index 000000000..35fd7f447 --- /dev/null +++ b/plugins/vcard_attachments/tests/VcardAttachments.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('vcard_attachments', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/virtuser_file/tests/VirtuserFile.php b/plugins/virtuser_file/tests/VirtuserFile.php new file mode 100644 index 000000000..a4362c3dc --- /dev/null +++ b/plugins/virtuser_file/tests/VirtuserFile.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('virtuser_file', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/virtuser_query/tests/VirtuserQuery.php b/plugins/virtuser_query/tests/VirtuserQuery.php new file mode 100644 index 000000000..d5bd4ee4b --- /dev/null +++ b/plugins/virtuser_query/tests/VirtuserQuery.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('virtuser_query', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/plugins/zipdownload/tests/Zipdownload.php b/plugins/zipdownload/tests/Zipdownload.php new file mode 100644 index 000000000..f3b4e1b35 --- /dev/null +++ b/plugins/zipdownload/tests/Zipdownload.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('zipdownload', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a9e25610c..40659ebf0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -33,3 +33,9 @@ if (@is_dir(TESTS_DIR . 'config')) { require_once(INSTALL_PATH . 'program/include/iniset.php'); rcmail::get_instance()->config->set('devel_mode', false); + +// Extend include path so some plugin test won't fail +$include_path = ini_get('include_path') . PATH_SEPARATOR . TESTS_DIR . '..'; +if (set_include_path($include_path) === false) { + die("Fatal error: ini_set/set_include_path does not work."); +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 5a858111b..da0f899a9 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -32,9 +32,38 @@ Framework/Washtml.php MailFunc.php - + + ./../plugins/acl/tests/Acl.php + ./../plugins/additional_message_headers/tests/AdditionalMessageHeaders.php + ./../plugins/archive/tests/Archive.php + ./../plugins/autologon/tests/Autologon.php + ./../plugins/database_attachments/tests/DatabaseAttachments.php + ./../plugins/debug_logger/tests/DebugLogger.php + ./../plugins/emoticons/tests/Emoticons.php + ./../plugins/enigma/tests/Enigma.php + ./../plugins/example_addressbook/tests/ExampleAddressbook.php + ./../plugins/filesystem_attachments/tests/FilesystemAttachments.php + ./../plugins/help/tests/Help.php + ./../plugins/hide_blockquote/tests/HideBlockquote.php + ./../plugins/http_authentication/tests/HttpAuthentication.php + ./../plugins/jqueryui/tests/Jqueryui.php + ./../plugins/managesieve/tests/Managesieve.php ./../plugins/managesieve/tests/Parser.php ./../plugins/managesieve/tests/Tokenizer.php + ./../plugins/markasjunk/tests/Markasjunk.php + ./../plugins/new_user_dialog/tests/NewUserDialog.php + ./../plugins/new_user_identity/tests/NewUserIdentity.php + ./../plugins/newmail_notifier/tests/NewmailNotifier.php + ./../plugins/password/tests/Password.php + ./../plugins/redundant_attachments/tests/RedundantAttachments.php + ./../plugins/show_additional_headers/tests/ShowAdditionalHeaders.php + ./../plugins/squirrelmail_usercopy/tests/Squirrelmail_usercopy.php + ./../plugins/subscriptions_option/tests/SubscriptionsOption.php + ./../plugins/userinfo/tests/Userinfo.php + ./../plugins/vcard_attachments/tests/VcardAttachments.php + ./../plugins/virtuser_file/tests/VirtuserFile.php + ./../plugins/virtuser_query/tests/VirtuserQuery.php + ./../plugins/zipdownload/tests/Zipdownload.php -- cgit v1.2.3 From f5fcb92dd49622c9938462935202eeb1765cfc7c Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 17 Feb 2013 11:04:43 +0100 Subject: Add posibility to use different database for virtuser queries --- plugins/virtuser_query/package.xml | 6 +++--- plugins/virtuser_query/virtuser_query.php | 30 +++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'plugins/virtuser_query') diff --git a/plugins/virtuser_query/package.xml b/plugins/virtuser_query/package.xml index 58f697019..b7ea565d8 100644 --- a/plugins/virtuser_query/package.xml +++ b/plugins/virtuser_query/package.xml @@ -13,10 +13,10 @@ alec@alec.pl yes - 2011-11-21 + 2012-02-17 - 1.1 - 1.1 + 2.0 + 2.0 stable diff --git a/plugins/virtuser_query/virtuser_query.php b/plugins/virtuser_query/virtuser_query.php index c479a4f7f..675eb7c1b 100644 --- a/plugins/virtuser_query/virtuser_query.php +++ b/plugins/virtuser_query/virtuser_query.php @@ -17,6 +17,9 @@ * The email query can return more than one record to create more identities. * This requires identities_level option to be set to value less than 2. * + * By default Roundcube database is used. To use different database (or host) + * you can specify DSN string in $rcmail_config['virtuser_query_dsn'] option. + * * @version @package_version@ * @author Aleksander Machniak * @author Steffen Vogel @@ -25,6 +28,7 @@ class virtuser_query extends rcube_plugin { private $config; private $app; + private $db; function init() { @@ -53,7 +57,7 @@ class virtuser_query extends rcube_plugin */ function user2email($p) { - $dbh = $this->app->get_dbh(); + $dbh = $this->get_dbh(); $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['email'])); @@ -89,7 +93,7 @@ class virtuser_query extends rcube_plugin */ function email2user($p) { - $dbh = $this->app->get_dbh(); + $dbh = $this->get_dbh(); $sql_result = $dbh->query(preg_replace('/%m/', $dbh->escapeSimple($p['email']), $this->config['user'])); @@ -105,7 +109,7 @@ class virtuser_query extends rcube_plugin */ function user2host($p) { - $dbh = $this->app->get_dbh(); + $dbh = $this->get_dbh(); $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['host'])); @@ -116,5 +120,25 @@ class virtuser_query extends rcube_plugin return $p; } + /** + * Initialize database handler + */ + function get_dbh() + { + if (!$this->db) { + if ($dsn = $this->app->config->get('virtuser_query_dsn')) { + // connect to the virtuser database + $this->db = rcube_db::factory($dsn); + $this->db->set_debug((bool)$this->app->config->get('sql_debug')); + $this->db->db_connect('r'); // connect in read mode + } + else { + $this->db = $this->app->get_dbh(); + } + } + + return $this->db; + } + } -- cgit v1.2.3