Skip to content

Commit

Permalink
json_encode in html class
Browse files Browse the repository at this point in the history
This make it easier for the calling code.
  • Loading branch information
pabzm committed Jul 25, 2024
1 parent 320964a commit 958b02a
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 97 deletions.
2 changes: 1 addition & 1 deletion plugins/archive/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function prefs_table($args)
'maxlength' => 30,
'folder_filter' => 'mail',
'folder_rights' => 'w',
'data-onchange' => json_encode(['reset_value_if_inbox', '__THIS__']),
'data-onchange' => ['reset_value_if_inbox', '__THIS__'],
'class' => 'custom-select',
]);
} else {
Expand Down
8 changes: 4 additions & 4 deletions plugins/enigma/lib/enigma_ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ public function tpl_key_import_form($attrib)
$max_filesize = rcmail_action::upload_init();
$upload_button = new html_button([
'class' => 'button import',
'data-onclick' => json_encode(['command', 'plugin.enigma-import', '', '__THIS__', '__EVENT__']),
'data-onclick' => ['command', 'plugin.enigma-import', '', '__THIS__', '__EVENT__'],
]);

$form = html::div(null, html::p(null, rcube::Q($this->enigma->gettext('keyimporttext'), 'show'))
Expand Down Expand Up @@ -639,7 +639,7 @@ public function tpl_key_import_form($attrib)

$search_button = new html_button([
'class' => 'button search',
'data-onclick' => json_encode(['command', 'plugin.enigma-import-search', '', '__THIS__', '__EVENT__']),
'data-onclick' => ['command', 'plugin.enigma-import-search', '', '__THIS__', '__EVENT__'],
]);

$form = html::div(null,
Expand Down Expand Up @@ -848,7 +848,7 @@ private function compose_ui()
$this->enigma->add_button([
'type' => 'link',
'command' => 'plugin.enigma',
'data-onclick' => json_encode(['command', 'menu-open', 'enigmamenu', '__THIS__', '__EVENT__']),
'data-onclick' => ['command', 'menu-open', 'enigmamenu', '__THIS__', '__EVENT__'],
'class' => 'button enigma',
'title' => 'encryptionoptions',
'label' => 'encryption',
Expand Down Expand Up @@ -1107,7 +1107,7 @@ public function message_output($p)
$p['content'] = html::p(['class' => 'enigmaattachment boxinformation aligned-buttons'],
html::span(null, rcube::Q($this->enigma->gettext('keyattfound'))) .
html::tag('button', [
'data-onclick' => json_encode(['enigma_import_attachment', $part]),
'data-onclick' => ['enigma_import_attachment', $part],
'title' => $this->enigma->gettext('keyattimport'),
'class' => 'import btn-sm',
], rcube::Q($this->rc->gettext('import'))
Expand Down
2 changes: 1 addition & 1 deletion plugins/help/help.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function tablink($attrib)
// so button() will translate it correctly
$attrib['title'] = $attrib['label'];

$attrib['data-onclick'] = json_encode(['show_help_content', $attrib['action'], '__EVENT__']);
$attrib['data-onclick'] = ['show_help_content', $attrib['action'], '__EVENT__'];

return $rcmail->output->button($attrib);
}
Expand Down
38 changes: 19 additions & 19 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ public function filtersets_list($attrib, $no_env = false)
'name' => '_set',
'id' => $attrib['id'],
'class' => 'custom-select',
'data-onchange' => $this->rc->task != 'mail' ? json_encode(['managesieve_set']) : '',
'data-onchange' => $this->rc->task != 'mail' ? ['managesieve_set'] : '',
]);

if ($list) {
Expand Down Expand Up @@ -1557,7 +1557,7 @@ public function filter_form($attrib)

if ($compact) {
$select = new html_select(['name' => '_join', 'id' => '_join', 'class' => 'custom-select',
'data-onchange' => json_encode(['managesieve_rule_join_radio_with_this_value'])]);
'data-onchange' => ['managesieve_rule_join_radio_with_this_value']]);

foreach (['allof', 'anyof', 'any'] as $val) {
$select->add($this->plugin->gettext('filter' . $val), $val);
Expand All @@ -1582,7 +1582,7 @@ public function filter_form($attrib)
// any, allof, anyof radio buttons
$field_id = '_allof';
$input_join = new html_radiobutton(['name' => '_join', 'id' => $field_id, 'value' => 'allof',
'data-onclick' => json_encode(['managesieve_rule_join_radio', 'allof']), 'class' => 'radio']);
'data-onclick' => ['managesieve_rule_join_radio', 'allof'], 'class' => 'radio']);

if (isset($scr) && !$any) {
$input_join = $input_join->show($scr['join'] ? 'allof' : '');
Expand All @@ -1594,7 +1594,7 @@ public function filter_form($attrib)

$field_id = '_anyof';
$input_join = new html_radiobutton(['name' => '_join', 'id' => $field_id, 'value' => 'anyof',
'data-onclick' => json_encode(['managesieve_rule_join_radio', 'anyof']), 'class' => 'radio']);
'data-onclick' => ['managesieve_rule_join_radio', 'anyof'], 'class' => 'radio']);

if (isset($scr) && !$any) {
$input_join = $input_join->show($scr['join'] ? '' : 'anyof');
Expand All @@ -1606,7 +1606,7 @@ public function filter_form($attrib)

$field_id = '_any';
$input_join = new html_radiobutton(['name' => '_join', 'id' => $field_id, 'value' => 'any',
'data-onclick' => json_encode(['managesieve_rule_join_radio', 'any']), 'class' => 'radio']);
'data-onclick' => ['managesieve_rule_join_radio', 'any'], 'class' => 'radio']);

$input_join = $input_join->show($any ? 'any' : '');

Expand Down Expand Up @@ -1677,7 +1677,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)

// headers select
$select_header = new html_select(['name' => "_header[{$id}]", 'id' => 'header' . $id,
'data-onchange' => json_encode(['rule_header_select', $id]), 'class' => 'custom-select']);
'data-onchange' => ['rule_header_select', $id]), 'class' => 'custom-select'];

Check failure on line 1680 in plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Syntax error, unexpected ')', expecting ']' on line 1680

foreach ($this->headers as $index => $header) {
$header = $this->rc->text_exists($index) ? $this->plugin->gettext($index) : $header;
Expand Down Expand Up @@ -1862,7 +1862,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'name' => "_rule_spamtest_op[{$id}]",
'id' => 'rule_spamtest_op' . $id,
'class' => 'input-group-prepend custom-select',
'data-onchange' => json_encode(['rule_spamtest_select', $id]),
'data-onchange' => ['rule_spamtest_select', $id],
]);
$select_spamtest_op->add(rcube::Q($this->plugin->gettext('spamtestisunknown')), '');
$select_spamtest_op->add(rcube::Q($this->plugin->gettext('spamtestisgreaterthan')), 'value-gt');
Expand Down Expand Up @@ -1899,7 +1899,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'name' => "_rule_mod[{$id}]",
'id' => 'rule_mod_op' . $id,
'class' => 'custom-select',
'data-onchange' => json_encode(['rule_mod_select', $id]),
'data-onchange' => ['rule_mod_select', $id],
]);
$select_mod->add(rcube::Q($this->plugin->gettext('none')), '');
$select_mod->add(rcube::Q($this->plugin->gettext('address')), 'address');
Expand Down Expand Up @@ -1945,7 +1945,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
$select_mime = new html_select([
'name' => "_rule_mime_type[{$id}]",
'id' => 'rule_mime_type' . $id,
'style' => 'min-width:8em', 'data-onchange' => json_encode(['rule_mime_select', $id]),
'style' => 'min-width:8em', 'data-onchange' => ['rule_mime_select', $id],
'class' => 'custom-select',
]);
$select_mime->add('-', '');
Expand Down Expand Up @@ -1984,7 +1984,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'name' => "_rule_trans[{$id}]",
'id' => 'rule_trans_op' . $id,
'class' => 'custom-select',
'data-onchange' => json_encode(['rule_trans_select', $id]),
'data-onchange' => ['rule_trans_select', $id],
]);
$select_mod->add(rcube::Q($this->plugin->gettext('text')), 'text');
$select_mod->add(rcube::Q($this->plugin->gettext('undecoded')), 'raw');
Expand Down Expand Up @@ -2103,7 +2103,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'href' => '#',
'id' => "ruleadv{$id}",
'title' => $adv_title,
'data-onclick' => json_encode(['rule_adv_switch', $id, '__THIS__']),
'data-onclick' => ['rule_adv_switch', $id, '__THIS__'],
'class' => 'show',
],
html::span(['class' => 'inner'], $adv_title)
Expand All @@ -2130,7 +2130,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'href' => '#',
'id' => "ruleadv{$id}",
'title' => $adv_title,
'data-onclick' => json_encode(['rule_adv_switch', $id, '__THIS__']),
'data-onclick' => ['rule_adv_switch', $id, '__THIS__'],
'class' => 'advanced show',
],
html::span(['class' => 'inner'], $adv_title)
Expand All @@ -2140,7 +2140,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'href' => '#',
'id' => "ruleadd{$id}",
'title' => $add_title,
'data-onclick' => json_encode(['managesieve_ruleadd', $id]),
'data-onclick' => ['managesieve_ruleadd', $id],
'class' => 'button create add',
],
html::span(['class' => 'inner'], $add_title)
Expand All @@ -2149,7 +2149,7 @@ public function rule_div($fid, $id, $div = true, $compact = false)
'href' => '#',
'id' => "ruledel{$id}",
'title' => $del_title,
'data-onclick' => json_encode(['managesieve_ruledel', $id]),
'data-onclick' => ['managesieve_ruledel', $id],
'class' => 'button delete del ' . $rows_num < 2 ? 'disabled' : '',
],
html::span(['class' => 'inner'], $del_title)
Expand Down Expand Up @@ -2238,7 +2238,7 @@ public function action_div($fid, $id, $div = true)
'name' => "_action_type[{$id}]",
'id' => 'action_type' . $id,
'class' => 'custom-select',
'data-onchange' => json_encode(['managesieve_action_type_select', $id]),
'data-onchange' => ['managesieve_action_type_select', $id],
]);
if (in_array('fileinto', $this->exts)) {
$select_action->add($this->plugin->gettext('messagemoveto'), 'fileinto');
Expand Down Expand Up @@ -2400,7 +2400,7 @@ public function action_div($fid, $id, $div = true)
$out .= $this->list_input($id, 'action_addresses', $action['addresses'] ?? null,
30, false, ['class' => $this->error_class($id, 'action', 'addresses', 'action_addresses')]
)
. html::a(['href' => '#', 'data-onclick' => json_encode(['managesieve_vacation_addresses', $id])],
. html::a(['href' => '#', 'data-onclick' => ['managesieve_vacation_addresses', $id]],
rcube::Q($this->plugin->gettext('filladdresses')));
$out .= '<br><span class="label">' . rcube::Q($this->plugin->gettext('vacationinterval')) . '</span><br>';
$out .= '<div class="input-group">' . html::tag('input', [
Expand Down Expand Up @@ -2704,7 +2704,7 @@ public function action_div($fid, $id, $div = true)
'href' => '#',
'id' => "actionadd{$id}",
'title' => $add_label,
'data-onclick' => json_encode(['managesieve_actionadd', $id]),
'data-onclick' => ['managesieve_actionadd', $id],
'class' => 'button create add',
],
html::span(['class' => 'inner'], $add_label),
Expand All @@ -2714,7 +2714,7 @@ public function action_div($fid, $id, $div = true)
'href' => '#',
'id' => "actiondel{$id}",
'title' => $del_label,
'data-onclick' => json_encode(['managesieve_actiondel', $id]),
'data-onclick' => ['managesieve_actiondel', $id],
'class' => 'button delete del ' . ($rows_num < 2 ? 'disabled' : ''),
],
html::span(['class' => 'inner'], $del_label),
Expand Down Expand Up @@ -3279,7 +3279,7 @@ protected function match_type_selector($name, $id, $test, $rule = null, $mode =
'id' => "{$name}{$id}",
'style' => 'display:' . (!in_array($rule, ['size', 'duplicate', 'spamtest']) ? 'inline' : 'none'),
'class' => 'operator_selector col-6 custom-select',
'data-onchange' => json_encode(["managesieve_{$name}_select", '__THIS__', $id]),
'data-onchange' => ["managesieve_{$name}_select", '__THIS__', $id],
]);

$select_op->add(rcube::Q($this->plugin->gettext('filtercontains')), 'contains');
Expand Down
4 changes: 2 additions & 2 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ public function vacation_form($attrib)
. (!empty($this->vacation['addresses']) ? rcube::Q(implode("\n", (array) $this->vacation['addresses']), 'strict', false) : '')
. '</textarea>';
$status = new html_select(['name' => 'vacation_status', 'id' => 'vacation_status', 'class' => 'custom-select']);
$action = new html_select(['name' => 'vacation_action', 'id' => 'vacation_action', 'class' => 'custom-select', 'data-onchange' => json_encode(['vacation_action_select'])]);
$action = new html_select(['name' => 'vacation_action', 'id' => 'vacation_action', 'class' => 'custom-select', 'data-onchange' => ['vacation_action_select']]);
$addresses_link = new html_inputfield([
'type' => 'button',
'href' => '#',
'class' => 'button',
'data-onclick' => json_encode(['managesieve_vacation_addresses']),
'data-onclick' => ['managesieve_vacation_addresses'],
]);

$redirect = !empty($this->vacation['action'])
Expand Down
2 changes: 1 addition & 1 deletion plugins/newmail_notifier/newmail_notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function prefs_list($args)
$field_id = '_' . $key;
$input = new html_checkbox(['name' => $field_id, 'id' => $field_id, 'value' => 1]);
$content = $input->show($this->rc->config->get($key))
. ' ' . html::a(['href' => '#', 'data-onclick' => json_encode(['newmail_notifier_test_' . $type])],
. ' ' . html::a(['href' => '#', 'data-onclick' => ['newmail_notifier_test_' . $type]],
$this->gettext('test'));

$args['blocks']['new_message']['options'][$key] = [
Expand Down
4 changes: 2 additions & 2 deletions plugins/vcard_attachments/vcard_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public function message_objects($p)

if (count($contacts) == 1) {
$display = array_first($contacts);
$attr['data-onclick'] = json_encode(['vcard_attachments_plugin_vcard_import', key($contacts)]);
$attr['data-onclick'] = ['vcard_attachments_plugin_vcard_import', key($contacts)];
} else {
$display = $this->gettext(['name' => 'contactsattached', 'vars' => ['num' => count($contacts)]]);
$attr['data-onclick'] = json_encode(['vcard_attachments_plugin_vcard_import']);
$attr['data-onclick'] = ['vcard_attachments_plugin_vcard_import'];

$rcmail->output->set_env('vcards', $contacts);
$rcmail->output->add_label('vcard_attachments.addvcardmsg', 'import');
Expand Down
2 changes: 1 addition & 1 deletion program/actions/contacts/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function run($args = [])
$_SESSION['contact_undo']['ts'] = time();
$msg = html::span(null, $rcmail->gettext('contactdeleted'))
. ' ' . html::a(
['data-onclick' => json_encode(['command', 'undo', '', '__THIS__'])],
['data-onclick' => ['command', 'undo', '', '__THIS__']],
$rcmail->gettext('undo')
);

Expand Down
14 changes: 7 additions & 7 deletions program/actions/contacts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public static function directory_list($attrib)
[
'href' => '%s',
'rel' => '%s',
'data-onclick' => json_encode(['command', 'list', '%s', '__THIS__']),
'data-onclick' => ['command', 'list', '%s', '__THIS__'],
],
'%s'
)
Expand Down Expand Up @@ -527,7 +527,7 @@ public static function savedsearch_list($attrib)
html::a([
'href' => '#',
'rel' => 'S%s',
'data-onclick' => json_encode(['command', 'listsearch', '%s', '__THIS__']),
'data-onclick' => ['command', 'listsearch', '%s', '__THIS__'],
],
'%s'
)
Expand Down Expand Up @@ -571,7 +571,7 @@ public static function contact_groups($args)
html::a([
'href' => '#',
'rel' => '%s:%s',
'data-onclick' => json_encode(['command', 'listgroup', ['source' => '%s', 'id' => '%s'], '__THIS__']),
'data-onclick' => ['command', 'listgroup', ['source' => '%s', 'id' => '%s'], '__THIS__'],
],
'%s'
)
Expand Down Expand Up @@ -673,13 +673,13 @@ public static function js_contacts_list($result, $prefix = '')
'href' => '#list',
'rel' => $row['ID'],
'title' => $rcmail->gettext('listgroup'),
'data-onclick' => json_encode([
'data-onclick' => [
'command',
'pushgroup',
['source' => $source_id, 'id' => $row['CID']],
'__THIS__',
'__EVENT__',
]),
],
'class' => 'pushgroup',
'data-action-link' => true,
],
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public static function contact_photo($attrib)

$content = html::div($attrib, html::img([
'src' => $photo_img,
'data-onerror' => json_encode(['onerror_set_placeholder_src', '__EVENT__']),
'data-onerror' => ['onerror_set_placeholder_src', '__EVENT__'],
]));

if (!empty(self::$CONTACT_COLTYPES['photo']) && ($rcmail->action == 'edit' || $rcmail->action == 'add')) {
Expand Down Expand Up @@ -1483,7 +1483,7 @@ public static function source_selector($attrib)

$attrib['name'] = '_source';
$attrib['is_escaped'] = true;
$attrib['data-onchange'] = json_encode(['reloadForm', '__THIS__']);
$attrib['data-onchange'] = ['reloadForm', '__THIS__'];

$select = new html_select($attrib);

Expand Down
2 changes: 1 addition & 1 deletion program/actions/contacts/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static function render_email_value($email)

return html::a([
'href' => 'mailto:' . $email,
'data-onclick' => json_encode(['command', 'compose', rcube::JQ($email), '__THIS__']),
'data-onclick' => ['command', 'compose', rcube::JQ($email), '__THIS__'],
'title' => $rcmail->gettext('composeto'),
'class' => 'email',
],
Expand Down
Loading

0 comments on commit 958b02a

Please sign in to comment.