Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add seperate storage class

  • Loading branch information...
commit 32da781e099ce25f93ec09c073ff6cab1dbd83b4 1 parent 8df6211
JohnDoh authored
6 CHANGELOG
... ... @@ -1,6 +1,12 @@
1 1 Roundcube Webmail SAUserPrefs
2 2 =============================
3 3
  4 +2012 04 08
  5 +==========
  6 + * Make storage class to handle SQL work
  7 + * Add new config option sauserprefs_bayes_delete to seperate function from SQL
  8 + * Remove sauserprefs_deprecated_prefs config option
  9 +
4 10 2012 03 24
5 11 ==========
6 12 * Make username configurable
9 config.inc.php.dist
@@ -75,6 +75,10 @@ $rcmail_config['sauserprefs_default_prefs'] = array(
75 75 // spam score increment - increment values in the the score threshold drop down by this, from 0 to 10
76 76 $rcmail_config['sauserprefs_score_inc'] = 1;
77 77
  78 +// allow the user to delete bayesian data
  79 +// please also see sauserprefs_bayes_delete_query option
  80 +$rcmail_config['sauserprefs_bayes_delete'] = false;
  81 +
78 82 // delete user bayesian data stored in database
79 83 // the query can contain the following macros that will be expanded as follows:
80 84 // %u is replaced with the username from the sauserprefs_userid setting above
@@ -86,11 +90,6 @@ $rcmail_config['sauserprefs_score_inc'] = 1;
86 90 // );
87 91 $rcmail_config['sauserprefs_bayes_delete_query'] = '';
88 92
89   -// Override old or deprecated preferences: 'old name' => 'new name'
90   -$rcmail_config['sauserprefs_deprecated_prefs'] = array(
91   - 'required_hits' => 'required_score'
92   - );
93   -
94 93 // define languages
95 94 $rcmail_config['sauserprefs_languages'] = array(
96 95 "af" => "Afrikaans",
268 include/rcube_sauserprefs_storage.php
... ... @@ -0,0 +1,268 @@
  1 +<?php
  2 +
  3 +/**
  4 + * SAUserPrefs storage class
  5 + *
  6 + * Class to handle the SQL work for SAUserPrefs
  7 + *
  8 + * @author Philip Weir
  9 + */
  10 +class rcube_sauserprefs_storage
  11 +{
  12 + private $db;
  13 + private $db_dsnw;
  14 + private $db_dsnr;
  15 + private $db_persistent;
  16 + private $sa_user;
  17 + private $table_name;
  18 + private $username_field;
  19 + private $preference_field;
  20 + private $value_field;
  21 + private $bayes_delete_query;
  22 +
  23 + function __construct($db_dsnw, $db_dsnr, $db_persistent, $sa_user, $table_name, $username_field, $preference_field, $value_field, $bayes_delete_query)
  24 + {
  25 + $this->db_dsnw = $db_dsnw;
  26 + $this->db_dsnr = $db_dsnr;
  27 + $this->db_persistent = $db_persistent;
  28 + $this->sa_user = $sa_user;
  29 + $this->table_name = $table_name;
  30 + $this->username_field = $username_field;
  31 + $this->preference_field = $preference_field;
  32 + $this->value_field = $value_field;
  33 + $this->bayes_delete_query = $bayes_delete_query;
  34 + }
  35 +
  36 + function load_prefs($user)
  37 + {
  38 + $this->_db_connect('r');
  39 + $prefs = array();
  40 +
  41 + $sql_result = $this->db->query(
  42 + "SELECT ". $this->preference_field.
  43 + ", ". $this->value_field.
  44 + " FROM ". $this->table_name.
  45 + " WHERE ". $this->username_field ." = ?;",
  46 + $user);
  47 +
  48 + while ($sql_result && ($sql_arr = $this->db->fetch_assoc($sql_result))) {
  49 + $pref_name = $sql_arr[$this->preference_field];
  50 + $pref_name = sauserprefs::map_pref_name($pref_name, true);
  51 + $pref_value = $sql_arr[$this->value_field];
  52 +
  53 + if ($pref_name == 'whitelist_from' || $pref_name == 'blacklist_from' || $pref_name == 'whitelist_to')
  54 + $prefs['addresses'][] = array('field' => $pref_name, 'value' => $pref_value);
  55 + else
  56 + $prefs[$pref_name] = $pref_value;
  57 +
  58 + // update deprecated prefs in db
  59 + if ($sql_arr[$this->preference_field] != sauserprefs::map_pref_name($pref_name)) {
  60 + $this->_db_connect('w');
  61 +
  62 + $this->db->query(
  63 + "UPDATE ". $this->table_name.
  64 + " SET ". $this->preference_field ." = ?".
  65 + " WHERE ". $this->username_field ." = ?".
  66 + " AND ". $this->preference_field ." = ?;",
  67 + sauserprefs::map_pref_name($pref_name),
  68 + $user,
  69 + $sql_arr[$this->preference_field]);
  70 + }
  71 + }
  72 +
  73 + return $prefs;
  74 + }
  75 +
  76 + function save_prefs($new_prefs, $cur_prefs, $global_prefs)
  77 + {
  78 + $this->_db_connect('w');
  79 + $result = true;
  80 +
  81 + // save prefs
  82 + foreach ($new_prefs as $preference => $value) {
  83 + if ($preference == 'addresses') {
  84 + foreach ($value as $address) {
  85 + if ($address['action'] == "DELETE") {
  86 + $result = false;
  87 +
  88 + $this->db->query(
  89 + "DELETE FROM ". $this->table_name.
  90 + " WHERE ". $this->username_field ." = ?".
  91 + " AND ". $this->preference_field ." = ?".
  92 + " AND ". $this->value_field ." = ?;",
  93 + $this->sa_user,
  94 + sauserprefs::map_pref_name($address['field']),
  95 + $address['value']);
  96 +
  97 + $result = $this->db->affected_rows();
  98 +
  99 + if (!$result) {
  100 + write_log('errors', 'sauserprefs error: cannot delete "' . sauserprefs::map_pref_name($prefs[$idx]) . '" = "' . $vals[$idx] . '" for ' . $this->sa_user);
  101 + break;
  102 + }
  103 + }
  104 + elseif ($address['action'] == "INSERT") {
  105 + $result = false;
  106 +
  107 + $this->db->query(
  108 + "INSERT INTO ". $this->table_name.
  109 + " (". $this->username_field.
  110 + ", ". $this->preference_field.
  111 + ", ". $this->value_field.
  112 + ") VALUES (?, ?, ?);",
  113 + $this->sa_user,
  114 + sauserprefs::map_pref_name($address['field']),
  115 + $address['value']);
  116 +
  117 + $result = $this->db->affected_rows();
  118 +
  119 + if (!$result) {
  120 + write_log('errors', 'sauserprefs error: cannot insert "' . sauserprefs::map_pref_name($prefs[$idx]) . '" = "' . $vals[$idx] . '" for ' . $this->sa_user);
  121 + break;
  122 + }
  123 + }
  124 + }
  125 + }
  126 + elseif (array_key_exists($preference, $cur_prefs) && ($value == "" || $value == $global_prefs[$preference])) {
  127 + $result = false;
  128 +
  129 + $this->db->query(
  130 + "DELETE FROM ". $this->table_name.
  131 + " WHERE ". $this->username_field ." = ?".
  132 + " AND ". $this->preference_field ." = ?;",
  133 + $this->sa_user,
  134 + sauserprefs::map_pref_name($preference));
  135 +
  136 + $result = $this->db->affected_rows();
  137 +
  138 + if (!$result) {
  139 + write_log('errors', 'sauserprefs error: cannot delete "' . sauserprefs::map_pref_name($preference) . '" for "' . $this->sa_user);
  140 + break;
  141 + }
  142 + }
  143 + elseif (array_key_exists($preference, $cur_prefs) && $value != $cur_prefs[$preference]) {
  144 + $result = false;
  145 +
  146 + $this->db->query(
  147 + "UPDATE ". $this->table_name.
  148 + " SET ". $this->value_field ." = ?".
  149 + " WHERE ". $this->username_field ." = ?".
  150 + " AND ". $this->preference_field ." = ?;",
  151 + $value,
  152 + $this->sa_user,
  153 + sauserprefs::map_pref_name($preference));
  154 +
  155 + $result = $this->db->affected_rows();
  156 +
  157 + if (!$result) {
  158 + write_log('errors', 'sauserprefs error: cannot update "' . sauserprefs::map_pref_name($preference) . '" = "' . $value . '" for ' . $this->sa_user);
  159 + break;
  160 + }
  161 + }
  162 + elseif (!array_key_exists($preference, $cur_prefs) && $value != $global_prefs[$preference]) {
  163 + $result = false;
  164 +
  165 + $this->db->query(
  166 + "INSERT INTO ". $this->table_name.
  167 + " (". $this->username_field.
  168 + ", ". $this->preference_field.
  169 + ", ". $this->value_field.
  170 + ") VALUES (?, ?, ?);",
  171 + $this->sa_user,
  172 + sauserprefs::map_pref_name($preference),
  173 + $value);
  174 +
  175 + $result = $this->db->affected_rows();
  176 +
  177 + if (!$result) {
  178 + write_log('errors', 'sauserprefs error: cannot insert "' . sauserprefs::map_pref_name($preference) . '" = "' . $value . '" for ' . $this->sa_user);
  179 + break;
  180 + }
  181 + }
  182 + }
  183 +
  184 + return $result;
  185 + }
  186 +
  187 + function whitelist_add($emails)
  188 + {
  189 + $this->_db_connect('w');
  190 +
  191 + foreach ($emails as $email) {
  192 + // check address is not already whitelisted
  193 + $sql_result = $this->db->query(
  194 + "SELECT ". $this->value_field.
  195 + " FROM ". $this->table_name.
  196 + " WHERE ". $this->username_field ." = ?".
  197 + " AND ". $this->preference_field ." = ?".
  198 + " AND ". $this->value_field ." = ?;",
  199 + $this->sa_user,
  200 + sauserprefs::map_pref_name('whitelist_from'),
  201 + $email);
  202 +
  203 + if ($this->db->num_rows($sql_result) == 0)
  204 + $this->db->query(
  205 + "INSERT INTO ". $this->table_name.
  206 + " (". $this->username_field.
  207 + ", ". $this->preference_field.
  208 + ", ". $this->value_field.
  209 + ") VALUES (?, ?, ?);",
  210 + $this->sa_user,
  211 + sauserprefs::map_pref_name('whitelist_from'),
  212 + $email);
  213 + }
  214 + }
  215 +
  216 + function whitelist_delete($emails)
  217 + {
  218 + $this->_db_connect('w');
  219 +
  220 + foreach ($emails as $email)
  221 + $this->db->query(
  222 + "DELETE FROM ". $this->table_name.
  223 + " WHERE ". $this->username_field ." = ?".
  224 + " AND ". $this->preference_field ." = ?".
  225 + " AND ". $this->value_field ." = ?;",
  226 + $this->sa_user,
  227 + sauserprefs::map_pref_name('whitelist_from'),
  228 + $email);
  229 +
  230 + }
  231 +
  232 + function purge_bayes()
  233 + {
  234 + $this->_db_connect('w');
  235 + $queries = !is_array($this->bayes_delete_query) ? array($this->bayes_delete_query) : $this->bayes_delete_query;
  236 +
  237 + foreach ($queries as $sql) {
  238 + $sql = str_replace('%u', $this->db->quote($this->sa_user, 'text'), $sql);
  239 + $this->db->query($sql);
  240 +
  241 + if ($this->db->is_error())
  242 + break;
  243 + }
  244 +
  245 + if (!$this->db->is_error())
  246 + return true;
  247 + else
  248 + return false;
  249 + }
  250 +
  251 + private function _db_connect($mode)
  252 + {
  253 + if (!$this->db)
  254 + $this->db = new rcube_mdb2($this->db_dsnw, $this->db_dsnr, $this->db_persistent);
  255 +
  256 + $this->db->db_connect($mode);
  257 +
  258 + // check DB connections and exit on failure
  259 + if ($err_str = $this->db->is_error()) {
  260 + raise_error(array(
  261 + 'code' => 603,
  262 + 'type' => 'db',
  263 + 'message' => $err_str), false, true);
  264 + }
  265 + }
  266 +}
  267 +
  268 +?>
9 package.xml
@@ -13,11 +13,11 @@
13 13 <email>roundcube@tehinterweb.co.uk</email>
14 14 <active>yes</active>
15 15 </lead>
16   - <date>2012-01-22</date>
17   - <time>10:42:53</time>
  16 + <date>2012-04-08</date>
  17 + <time>10:19:14</time>
18 18 <version>
19   - <release>1.8</release>
20   - <api>1.8</api>
  19 + <release>1.9</release>
  20 + <api>1.9</api>
21 21 </version>
22 22 <stability>
23 23 <release>stable</release>
@@ -38,6 +38,7 @@
38 38 <file name="config.inc.php.dist" role="data"/>
39 39 <file name="CHANGELOG" role="data"/>
40 40 <file name="README" role="data"/>
  41 + <file name="include/rcube_sauserprefs_storage.php" role="php"/>
41 42 <file name="localization/de_CH.inc" role="data"/>
42 43 <file name="localization/de_DE.inc" role="data"/>
43 44 <file name="localization/en_GB.inc" role="data"/>
192 sauserprefs.php
@@ -11,7 +11,7 @@
11 11 class sauserprefs extends rcube_plugin
12 12 {
13 13 public $task = 'mail|addressbook|settings';
14   - private $db;
  14 + private $storage;
15 15 private $sections = array();
16 16 private $cur_section;
17 17 private $global_prefs;
@@ -19,6 +19,7 @@ class sauserprefs extends rcube_plugin
19 19 private $addressbook = '0';
20 20 private $sa_locales = array('en', 'ja', 'ko', 'ru', 'th', 'zh');
21 21 private $sa_user;
  22 + static $deprecated_prefs = array('required_hits' => 'required_score');
22 23
23 24 function init()
24 25 {
@@ -33,6 +34,12 @@ function init()
33 34 $this->sa_user = str_replace('%d', $rcmail->user->get_username('domain'), $this->sa_user);
34 35 $this->sa_user = str_replace('%i', $identity, $this->sa_user);
35 36
  37 + // init storage
  38 + include('include/rcube_sauserprefs_storage.php');
  39 + $this->storage = new rcube_sauserprefs_storage($rcmail->config->get('sauserprefs_db_dsnw'), $rcmail->config->get('sauserprefs_db_dsnr'), $rcmail->config->get('sauserprefs_db_persistent'),
  40 + $this->sa_user, $rcmail->config->get('sauserprefs_sql_table_name'), $rcmail->config->get('sauserprefs_sql_username_field'), $rcmail->config->get('sauserprefs_sql_preference_field'),
  41 + $rcmail->config->get('sauserprefs_sql_value_field'), $rcmail->config->get('sauserprefs_bayes_delete_query'));
  42 +
36 43 if ($rcmail->config->get('sauserprefs_whitelist_abook_id', false))
37 44 $this->addressbook = $rcmail->config->get('sauserprefs_whitelist_abook_id');
38 45
@@ -66,7 +73,6 @@ function init()
66 73
67 74 function init_html()
68 75 {
69   - $this->_db_connect('r');
70 76 $this->_load_global_prefs();
71 77 $this->_load_user_prefs();
72 78
@@ -156,7 +162,6 @@ function prefs_section_name()
156 162 function save()
157 163 {
158 164 $rcmail = rcmail::get_instance();
159   - $this->_db_connect('r');
160 165 $this->_load_global_prefs();
161 166 $this->_load_user_prefs();
162 167
@@ -264,96 +269,7 @@ function save()
264 269
265 270 if (!$data['abort']) {
266 271 // save prefs
267   - foreach ($data['new_prefs'] as $preference => $value) {
268   - if ($preference == 'addresses') {
269   - foreach ($value as $address) {
270   - if ($address['action'] == "DELETE") {
271   - $result = false;
272   -
273   - $this->db->query(
274   - "DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ."
275   - WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $this->sa_user ."'
276   - AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = '". $this->_map_pref_name($address['field']) ."'
277   - AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = '". $address['value'] . "';"
278   - );
279   -
280   - $result = $this->db->affected_rows();
281   -
282   - if (!$result) {
283   - write_log('errors', 'sauserprefs error: cannot delete "' . $this->_map_pref_name($prefs[$idx]) . '" = "' . $vals[$idx] . '" for ' . $this->sa_user);
284   - break;
285   - }
286   - }
287   - elseif ($address['action'] == "INSERT") {
288   - $result = false;
289   -
290   - $this->db->query(
291   - "INSERT INTO ". $rcmail->config->get('sauserprefs_sql_table_name') ."
292   - (".$rcmail->config->get('sauserprefs_sql_username_field').", ".$rcmail->config->get('sauserprefs_sql_preference_field').", ".$rcmail->config->get('sauserprefs_sql_value_field').")
293   - VALUES ('". $this->sa_user ."', '". $this->_map_pref_name($address['field']) ."', '". $address['value'] ."')"
294   - );
295   -
296   - $result = $this->db->affected_rows();
297   -
298   - if (!$result) {
299   - write_log('errors', 'sauserprefs error: cannot insert "' . $this->_map_pref_name($prefs[$idx]) . '" = "' . $vals[$idx] . '" for ' . $this->sa_user);
300   - break;
301   - }
302   - }
303   - }
304   - }
305   - elseif (array_key_exists($preference, $this->user_prefs) && ($value == "" || $value == $this->global_prefs[$preference])) {
306   - $result = false;
307   -
308   - $this->db->query(
309   - "DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ."
310   - WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $this->sa_user ."'
311   - AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = '". $this->_map_pref_name($preference) ."';"
312   - );
313   -
314   - $result = $this->db->affected_rows();
315   -
316   - if (!$result) {
317   - write_log('errors', 'sauserprefs error: cannot delete "' . $this->_map_pref_name($preference) . '" for "' . $this->sa_user);
318   - break;
319   - }
320   - }
321   - elseif (array_key_exists($preference, $this->user_prefs) && $value != $this->user_prefs[$preference]) {
322   - $result = false;
323   -
324   - $this->db->query(
325   - "UPDATE ". $rcmail->config->get('sauserprefs_sql_table_name') ."
326   - SET ". $rcmail->config->get('sauserprefs_sql_value_field') ." = '". $value ."'
327   - WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $this->sa_user ."'
328   - AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = '". $this->_map_pref_name($preference) ."';"
329   - );
330   -
331   - $result = $this->db->affected_rows();
332   -
333   - if (!$result) {
334   - write_log('errors', 'sauserprefs error: cannot update "' . $this->_map_pref_name($preference) . '" = "' . $value . '" for ' . $this->sa_user);
335   - break;
336   - }
337   - }
338   - elseif (!array_key_exists($preference, $this->user_prefs) && $value != $this->global_prefs[$preference]) {
339   - $result = false;
340   -
341   - $this->db->query(
342   - "INSERT INTO ". $rcmail->config->get('sauserprefs_sql_table_name') ."
343   - (".$rcmail->config->get('sauserprefs_sql_username_field').", ".$rcmail->config->get('sauserprefs_sql_preference_field').", ".$rcmail->config->get('sauserprefs_sql_value_field').")
344   - VALUES ('". $this->sa_user ."', '". $this->_map_pref_name($preference) ."', '". $value ."')"
345   - );
346   -
347   - $result = $this->db->affected_rows();
348   -
349   - if (!$result) {
350   - write_log('errors', 'sauserprefs error: cannot insert "' . $this->_map_pref_name($preference) . '" = "' . $value . '" for ' . $this->sa_user);
351   - break;
352   - }
353   - }
354   - }
355   -
356   - if ($result)
  272 + if ($this->storage->save_prefs($data['new_prefs'], $this->user_prefs, $this->global_prefs))
357 273 $this->api->output->command('display_message', $this->gettext('sauserprefchanged'), 'confirmation');
358 274 else
359 275 $this->api->output->command('display_message', $this->gettext('sauserpreffailed'), 'error');
@@ -391,26 +307,15 @@ function purge_bayes()
391 307 {
392 308 $rcmail = rcmail::get_instance();
393 309
394   - if (strlen($rcmail->config->get('sauserprefs_bayes_delete_query')) == 0) {
  310 + if ($rcmail->config->get('sauserprefs_bayes_delete', false)) {
395 311 $this->api->output->command('display_message', $this->gettext('servererror'), 'error');
396 312 return;
397 313 }
398 314
399   - $this->_db_connect('w');
400   - $queries = !is_array($rcmail->config->get('sauserprefs_bayes_delete_query')) ? array($rcmail->config->get('sauserprefs_bayes_delete_query')) : $rcmail->config->get('sauserprefs_bayes_delete_query');
401   -
402   - foreach ($queries as $sql) {
403   - $sql = str_replace('%u', $this->db->quote($this->sa_user, 'text'), $sql);
404   - $this->db->query($sql);
405   -
406   - if ($this->db->is_error())
407   - break;
408   - }
409   -
410   - if ($this->db->is_error())
411   - $this->api->output->command('display_message', $this->gettext('servererror'), 'error');
412   - else
  315 + if ($this->storage->purge_bayes())
413 316 $this->api->output->command('display_message', $this->gettext('done'), 'confirmation');
  317 + else
  318 + $this->api->output->command('display_message', $this->gettext('servererror'), 'error');
414 319 }
415 320
416 321 function contact_add($args)
@@ -421,15 +326,8 @@ function contact_add($args)
421 326 if ($args['source'] != $this->addressbook && $args['source'] != null)
422 327 return;
423 328
424   - $this->_db_connect('w');
425 329 $emails = $this->_gen_email_arr($args['record']);
426   -
427   - foreach ($emails as $email) {
428   - // check address is not already whitelisted
429   - $sql_result = $this->db->query("SELECT value FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $this->sa_user ."' AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = '". $this->_map_pref_name('whitelist_from') ."' AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = '". $email ."';");
430   - if ($this->db->num_rows($sql_result) == 0)
431   - $this->db->query("INSERT INTO ". $rcmail->config->get('sauserprefs_sql_table_name') ." (". $rcmail->config->get('sauserprefs_sql_username_field') .", ". $rcmail->config->get('sauserprefs_sql_preference_field') .", ". $rcmail->config->get('sauserprefs_sql_value_field') .") VALUES ('". $this->sa_user ."', '". $this->_map_pref_name('whitelist_from') ."', '". $email ."');");
432   - }
  330 + $this->storage->whitelist_add($emails);
433 331 }
434 332
435 333 function contact_save($args)
@@ -449,33 +347,15 @@ function contact_delete($args)
449 347 if (!is_array($args['id']))
450 348 $args['id'] = array($args['id']);
451 349
452   - $this->_db_connect('w');
453 350 $contacts = $rcmail->get_address_book($this->addressbook);
454 351 foreach ($args['id'] as $id) {
455 352 $emails = $this->_gen_email_arr($contacts->get_record($id, true));
456   -
457   - foreach ($emails as $email)
458   - $this->db->query("DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $this->sa_user ."' AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = '". $this->_map_pref_name('whitelist_from') ."' AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = '". $email ."';");
  353 + $this->storage->whitelist_delete($emails);
459 354 }
460 355
461 356 $contacts->close();
462 357 }
463 358
464   - private function _db_connect($mode)
465   - {
466   - $rcmail = rcmail::get_instance();
467   - $this->db = new rcube_mdb2($rcmail->config->get('sauserprefs_db_dsnw'), $rcmail->config->get('sauserprefs_db_dsnr'), $rcmail->config->get('sauserprefs_db_persistent'));
468   - $this->db->db_connect($mode);
469   -
470   - // check DB connections and exit on failure
471   - if ($err_str = $this->db->is_error()) {
472   - raise_error(array(
473   - 'code' => 603,
474   - 'type' => 'db',
475   - 'message' => $err_str), FALSE, TRUE);
476   - }
477   - }
478   -
479 359 private function _load_global_prefs()
480 360 {
481 361 $rcmail = rcmail::get_instance();
@@ -491,36 +371,7 @@ private function _load_user_prefs()
491 371 private function _load_prefs($user)
492 372 {
493 373 $rcmail = rcmail::get_instance();
494   - $prefs = array();
495   -
496   - $sql_result = $this->db->query(
497   - "SELECT ". $rcmail->config->get('sauserprefs_sql_preference_field') .", ". $rcmail->config->get('sauserprefs_sql_value_field') ."
498   - FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ."
499   - WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $user ."';"
500   - );
501   -
502   - while ($sql_result && ($sql_arr = $this->db->fetch_assoc($sql_result))) {
503   - $pref_name = $sql_arr[$rcmail->config->get('sauserprefs_sql_preference_field')];
504   - $pref_name = $this->_map_pref_name($pref_name, true);
505   - $pref_value = $sql_arr[$rcmail->config->get('sauserprefs_sql_value_field')];
506   -
507   - if ($pref_name == 'whitelist_from' || $pref_name == 'blacklist_from' || $pref_name == 'whitelist_to') {
508   - $prefs['addresses'][] = array('field' => $pref_name, 'value' => $pref_value);
509   - }
510   - else {
511   - $prefs[$pref_name] = $pref_value;
512   - }
513   -
514   - // update deprecated prefs in db
515   - if ($sql_arr[$rcmail->config->get('sauserprefs_sql_preference_field')] != $this->_map_pref_name($pref_name)) {
516   - $this->db->query(
517   - "UPDATE ". $rcmail->config->get('sauserprefs_sql_table_name') ."
518   - SET ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = '". $this->_map_pref_name($pref_name) ."'
519   - WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $user ."'
520   - AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = '". $sql_arr[$rcmail->config->get('sauserprefs_sql_preference_field')] ."';"
521   - );
522   - }
523   - }
  374 + $prefs = $this->storage->load_prefs($user);
524 375
525 376 // sort address rules
526 377 $prefs['addresses'] = $this->_subval_sort($prefs['addresses'], 'value');
@@ -801,7 +652,7 @@ private function _prefs_block($part, $attrib)
801 652 $input_spamtest = new html_checkbox(array('name' => '_spamusebayes', 'id' => $field_id, 'value' => '1',
802 653 'onchange' => JS_OBJECT_NAME . '.sauserprefs_toggle_bayes(this)'));
803 654
804   - if (strlen($rcmail->config->get('sauserprefs_bayes_delete_query')) > 0)
  655 + if ($rcmail->config->get('sauserprefs_bayes_delete', false))
805 656 $delete_link = "&nbsp;&nbsp;&nbsp;" . html::span(array('id' => 'listcontrols'), $this->api->output->button(array('command' => 'plugin.sauserprefs.purge_bayes', 'type' => 'link', 'label' => 'sauserprefs.purgebayes', 'title' => 'sauserprefs.purgebayesexp')));
806 657
807 658 $table->add('title', html::label($field_id, Q($this->gettext('usebayes'))));
@@ -1027,15 +878,14 @@ private function _address_row($address_table, $field, $value, $attrib)
1027 878 return $address_table;
1028 879 }
1029 880
1030   - private function _map_pref_name($pref, $reverse = false)
  881 + static function map_pref_name($pref, $reverse = false)
1031 882 {
1032   - $prefs_map = rcmail::get_instance()->config->get('sauserprefs_deprecated_prefs', array());
1033 883 if (!$reverse) {
1034   - if (array_key_exists($pref, $prefs_map))
1035   - $pref = $prefs_map[$pref];
  884 + if (array_key_exists($pref, self::$deprecated_prefs))
  885 + $pref = self::$deprecated_prefs[$pref];
1036 886 }
1037 887 else {
1038   - if (($orig_pref = array_search($pref, $prefs_map)) != FALSE)
  888 + if (($orig_pref = array_search($pref, self::$deprecated_prefs)) != FALSE)
1039 889 $pref = $orig_pref;
1040 890 }
1041 891

0 comments on commit 32da781

Please sign in to comment.
Something went wrong with that request. Please try again.