diff --git a/CHANGELOG b/CHANGELOG index f17e9bd..12c5e3e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,11 @@ Roundcube Webmail SAUserPrefs ============================= +Version 1.18.3 (2020-11-20, rc-1.4) +================================================= + * Improve address rule input + * Fix address rule delete button + Version 1.18.2 (2020-04-27, rc-1.4) ================================================= * Revert depreciation of sortedASC & sortedDESC diff --git a/composer.json b/composer.json index 08bca4e..a4c3aa3 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "homepage": "https://github.com/johndoh/roundcube-sauserprefs/", "license": "GPL-3.0", "type": "roundcube-plugin", - "version": "1.18.1", + "version": "1.18.3", "authors": [ { "name": "Philip Weir", @@ -13,14 +13,8 @@ "role": "Developer" } ], - "repositories": [ - { - "type": "composer", - "url": "https://plugins.roundcube.net" - } - ], "require": { - "php": ">=5.2.1", + "php": ">=5.4.0", "roundcube/plugin-installer": ">=0.1.2" }, "extra": { diff --git a/lib/Roundcube/rcube_sauserprefs_storage_sql.php b/lib/Roundcube/rcube_sauserprefs_storage_sql.php index 0316070..062bce4 100644 --- a/lib/Roundcube/rcube_sauserprefs_storage_sql.php +++ b/lib/Roundcube/rcube_sauserprefs_storage_sql.php @@ -63,7 +63,7 @@ public function __construct($config) public function load_prefs($user) { $this->_db_connect('r'); - $prefs = array(); + $prefs = []; $sql_result = $this->db->query( "SELECT `{$this->preference_field}`, `{$this->value_field}` FROM `{$this->table_name}` WHERE `{$this->username_field}` = ?;", @@ -75,7 +75,7 @@ public function load_prefs($user) $pref_value = $sql_arr[$this->value_field]; if ($pref_name == 'whitelist_from' || $pref_name == 'blacklist_from' || $pref_name == 'whitelist_to') { - $prefs['addresses'][] = array('field' => $pref_name, 'value' => $pref_value); + $prefs['addresses'][] = ['field' => $pref_name, 'value' => $pref_value]; } else { $prefs[$pref_name] = $pref_value; @@ -111,7 +111,7 @@ public function save_prefs($user_id, $new_prefs, $cur_prefs, $global_prefs) $result = true; // process prefs - $actions = array(); + $actions = []; foreach ($new_prefs as $preference => $value) { if ($preference == 'addresses') { foreach ($value as $address) { @@ -122,14 +122,14 @@ public function save_prefs($user_id, $new_prefs, $cur_prefs, $global_prefs) } elseif (array_key_exists($preference, $cur_prefs)) { if ($value == "" || $value == $global_prefs[$preference]) { - $actions['DELETE'][] = array('field' => $preference, 'value' => null); + $actions['DELETE'][] = ['field' => $preference, 'value' => null]; } elseif ($value != $cur_prefs[$preference]) { - $actions['UPDATE'][] = array('field' => $preference, 'value' => $value); + $actions['UPDATE'][] = ['field' => $preference, 'value' => $value]; } } elseif ($value != $global_prefs[$preference]) { - $actions['INSERT'][] = array('field' => $preference, 'value' => $value); + $actions['INSERT'][] = ['field' => $preference, 'value' => $value]; } } @@ -168,7 +168,7 @@ public function save_prefs($user_id, $new_prefs, $cur_prefs, $global_prefs) } elseif ($type == 'DELETE') { $sql = "DELETE FROM `{$this->table_name}` WHERE `{$this->username_field}` = ? AND `{$this->preference_field}` = ?"; - $vals = array($user_id, $pref['field']); + $vals = [$user_id, $pref['field']]; $msg = '"' . $pref['field'] . '"'; if ($pref['value']) { @@ -201,7 +201,7 @@ public function purge_bayes($user_id) { $result = false; $this->_db_connect('w'); - $queries = !is_array($this->bayes_delete_query) ? array($this->bayes_delete_query) : $this->bayes_delete_query; + $queries = !is_array($this->bayes_delete_query) ? [$this->bayes_delete_query] : $this->bayes_delete_query; foreach ($queries as $sql) { $sql = str_replace('%u', $this->db->quote($user_id, 'text'), $sql); @@ -235,11 +235,7 @@ private function _db_connect($mode) // check DB connections and exit on failure if ($err_str = $this->db->is_error()) { - rcube::raise_error(array( - 'code' => 603, - 'type' => 'db', - 'message' => $err_str - ), false, true); + rcube::raise_error(['code' => 603, 'type' => 'db', 'message' => $err_str], false, true); } } } diff --git a/sauserprefs.js b/sauserprefs.js index 1411cb1..b1b8b15 100644 --- a/sauserprefs.js +++ b/sauserprefs.js @@ -87,7 +87,11 @@ rcube_webmail.prototype.sauserprefs_addressrule_insert_row = function(p) { } rcube_webmail.prototype.sauserprefs_addressrule_delete_row = function(obj) { - var actField = $(obj).closest('td').find('input[name="_address_rule_act[]"]'); + var actField = $(obj).find('input[name="_address_rule_act[]"]'); + + // skip empty rows + if (!actField.parent().is(':visible')) + return; if (actField.val() == "INSERT") { $(obj).closest('tr').remove(); @@ -233,7 +237,7 @@ $(document).ready(function() { rcmail.register_command('plugin.sauserprefs.addressrule_del', function(props, obj) { rcmail.confirm_dialog(rcmail.get_label('spamaddressdelete','sauserprefs'), 'delete', function(e, ref) { - ref.sauserprefs_addressrule_delete_row(obj); + ref.sauserprefs_addressrule_delete_row($(obj).parent()); }); return false; }, true); @@ -270,7 +274,7 @@ $(document).ready(function() { rcmail.register_command('plugin.sauserprefs.whitelist_delete_all', function() { rcmail.confirm_dialog(rcmail.get_label('spamaddressdeleteall','sauserprefs'), 'delete', function(e, ref) { - $.each($('#address-rules-table tbody tr').filter(':visible'), function() { ref.sauserprefs_addressrule_delete_row(this); }); + $.each($('#address-rules-table tbody tr'), function() { ref.sauserprefs_addressrule_delete_row(this); }); }); return false; }, true); @@ -334,7 +338,7 @@ $(document).ready(function() { $('#rcmfd_spamlevelchar').val(ref.env.add_header_all_Level.substr(7, 1)); // Spam level char // Delete whitelist - $.each($('#address-rules-table tbody tr').filter(':visible'), function() { ref.sauserprefs_addressrule_delete_row(this) }); + $.each($('#address-rules-table tbody tr'), function() { ref.sauserprefs_addressrule_delete_row(this) }); // Toggle dependant fields ref.sauserprefs_toggle_level_char($('#rcmfd_spamlevelstars')); diff --git a/sauserprefs.php b/sauserprefs.php index c865a7d..a87f40b 100644 --- a/sauserprefs.php +++ b/sauserprefs.php @@ -225,10 +225,10 @@ public function gen_form($attrib) // output table sorting prefs $sorts = $this->rcube->config->get('sauserprefs_sort', array()); - if (!array_key_exists('#spam-langs-table', $sorts)) { + if (!isset($sorts['#spam-langs-table'])) { $sorts['#spam-langs-table'] = array(0, 'true'); } - if (!array_key_exists('#address-rules-table', $sorts)) { + if (!isset($sorts['#address-rules-table'])) { $sorts['#address-rules-table'] = array(1, 'true'); } $this->rcube->output->set_env('sauserprefs_sort', $sorts); @@ -605,7 +605,7 @@ private function _load_prefs($user) $prefs = $this->storage->load_prefs($user); // sort address rules - if (is_array($prefs['addresses'])) { + if (isset($prefs['addresses']) && is_array($prefs['addresses'])) { usort($prefs['addresses'], array($this, 'sort_addresses')); } @@ -707,7 +707,7 @@ private function _prefs_block($part, $attrib) $button = ''; $checkbox_display = array(); - if ($attrib['lang_list_buttons'] == '1') { + if (isset($attrib['lang_list_buttons']) && $attrib['lang_list_buttons'] == '1') { $button_type = in_array($lang_code, $locales_langs) ? 'enabled' : 'disabled'; $button = $this->rcube->output->button(array('command' => 'plugin.sauserprefs.message_lang', 'prop' => $lang_code, 'type' => 'link', 'class' => 'lang-' . $button_type, 'id' => 'spam_lang_' . $i, 'title' => 'sauserprefs.' . $button_type, 'content' => ' ')); $checkbox_display = array('style' => 'display: none;'); @@ -1175,7 +1175,7 @@ private function _prefs_block($part, $attrib) $table->add('title', $row['title']); } - $table->add($row['content_attribs'], $row['content']); + $table->add(isset($row['content_attribs']) ? $row['content_attribs'] : null, $row['content']); if (isset($row['help'])) { $table->add('help', $row['help']); @@ -1186,7 +1186,7 @@ private function _prefs_block($part, $attrib) } if (!empty($content)) { - $out .= html::tag('fieldset', $class, html::tag('legend', null, $block['name']) . $block['intro'] . $content); + $out .= html::tag('fieldset', $class, html::tag('legend', null, $block['name']) . (isset($block['intro']) ? $block['intro'] : '') . $content); } } @@ -1209,6 +1209,10 @@ private function _address_row(&$address_table, $field, $value, $attrib, $row_att case "whitelist_to": $fieldtxt = rcube_utils::rep_specialchars_output($this->gettext('whitelist_to')); break; + default: + // for default/placeholder row + $fieldtxt = ''; + $class = ''; } $row_attrib = !isset($field) ? array_merge($row_attrib, array('style' => 'display: none;')) : array_merge($row_attrib, array('class' => $field)); @@ -1236,7 +1240,7 @@ private function _score_select($field_name, $field_id, $val, $args = array()) for ($i = $config['min']; $i <= $config['max']; $i += $config['increment']) { $vals[number_format($i, 5, '.', '')] = array('val' => number_format($i, $decPlaces, '.', ''), 'text' => number_format($i, $decPlaces, $locale_info['decimal_point'], '')); } - if (array_key_exists('extra', $config)) { + if (isset($config['extra'])) { foreach ($config['extra'] as $extra) { $decPlaces = self::decimal_places($extra['increment'], $locale_info['decimal_point']); for ($i = $extra['min']; $i <= $extra['max']; $i += $extra['increment']) { diff --git a/skins/elastic/templates/settingsedit.html b/skins/elastic/templates/settingsedit.html index 75dc8f4..0bcbfd2 100644 --- a/skins/elastic/templates/settingsedit.html +++ b/skins/elastic/templates/settingsedit.html @@ -19,6 +19,9 @@