Skip to content

Commit

Permalink
backport improvements from master
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoh committed Nov 20, 2020
1 parent 7a78168 commit 0b4eead
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 2 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@
"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",
"email": "[email protected]",
"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": {
Expand Down
22 changes: 9 additions & 13 deletions lib/Roundcube/rcube_sauserprefs_storage_sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}` = ?;",
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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];
}
}

Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
12 changes: 8 additions & 4 deletions sauserprefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'));
Expand Down
18 changes: 11 additions & 7 deletions sauserprefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'));
}

Expand Down Expand Up @@ -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;');
Expand Down Expand Up @@ -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']);
Expand All @@ -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);
}
}

Expand All @@ -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));
Expand Down Expand Up @@ -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']) {
Expand Down
4 changes: 3 additions & 1 deletion skins/elastic/templates/settingsedit.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ <h1 class="voice"><roundcube:object name="sectionname" /></h1>
// add bootstrap styles for radio buttons
$('[type=radio]', $('.propform', document)).addClass('form-check-input').parents('tr').addClass('form-check');

// add bootstrap styles for selects (done here to prevent flicker in dark mode)
$('select', $('.propform', document)).addClass('custom-select');

// special display for small spam char input box
$('#rcmfd_spamlevelchar').parents('tr').addClass('saup-spam-char-row');

Expand All @@ -35,7 +38,6 @@ <h1 class="voice"><roundcube:object name="sectionname" /></h1>
$('#test-scores-table > thead > tr > th').first().addClass('col-sm-4');
$('#test-scores-table > thead > tr > th').last().addClass('col-sm-8');
}

</script>

<roundcube:include file="includes/footer.html" />

0 comments on commit 0b4eead

Please sign in to comment.