Skip to content

Commit f8a6a47

Browse files
committed
code refactoring, no functional changes
1 parent 0015fa3 commit f8a6a47

File tree

4 files changed

+75
-76
lines changed

4 files changed

+75
-76
lines changed

ispconfig3_account/ispconfig3_account.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function template_object_identityform($args)
105105

106106
$email_pattern = '/<input type=\"text\" size=\"40\" id=\"rcmfd_email\" name=\"_email\" class=\"ff_email\"(?: value=\"(.*)\")?>/U';
107107
preg_match($email_pattern, $args['content'], $test);
108-
$email = isset($test[1]) ? $test[1] : '';
108+
$email = $test[1] ?? '';
109109
$args['content'] = preg_replace($email_pattern, $emails->show($email), $args['content']);
110110

111111
return $args;

ispconfig3_autoselect/ispconfig3_autoselect.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ function load_con_config()
3535
{
3636
$config = $this->api->dir . 'ispconfig3_account/config/config.inc.php';
3737
if (file_exists($config)) {
38-
if (!$this->rcmail->config->load_from_file($config))
38+
if (!$this->rcmail->config->load_from_file($config)) {
3939
rcube::raise_error(['code' => 527, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__,
4040
'message' => "Failed to load config from $config"], true, false);
41+
}
4142
}
4243
else if (file_exists($config . ".dist")) {
43-
if (!$this->rcmail->config->load_from_file($config . '.dist'))
44+
if (!$this->rcmail->config->load_from_file($config . '.dist')) {
4445
rcube::raise_error(['code' => 527, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__,
4546
'message' => "Failed to load config from $config"], true, false);
47+
}
4648
}
4749
}
4850

@@ -55,8 +57,9 @@ function template_object_loginform($args)
5557

5658
function authenticate($args)
5759
{
58-
if (isset($_POST['_user'], $_POST['_pass']))
60+
if (isset($_POST['_user'], $_POST['_pass'])) {
5961
$args['host'] = $this->getHost(rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST));
62+
}
6063

6164
return $args;
6265
}

ispconfig3_filter/ispconfig3_filter.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function gen_table($attrib)
314314
}
315315

316316
$rule_table->set_row_attribs($row_attribs);
317-
$this->_rule_row($rule_table, $filter_value['rulename'], $filter_value['active'], $filter_value['filter_id'], $attrib);
317+
$this->_rule_row($rule_table, $filter_value['rulename'], $filter_value['active'], $filter_value['filter_id']);
318318
}
319319

320320
if (empty($filter)) {
@@ -334,7 +334,7 @@ function gen_table($attrib)
334334
return $out;
335335
}
336336

337-
private function _rule_row($rule_table, $name, $active, $id, $attrib)
337+
private function _rule_row($rule_table, $name, $active, $id)
338338
{
339339
$rule_table->add(['class' => 'rule', 'onclick' => 'filter_edit(' . $id . ');'], $name);
340340

@@ -359,7 +359,5 @@ private function _rule_row($rule_table, $name, $active, $id, $attrib)
359359
'title' => 'delete'
360360
]);
361361
$rule_table->add(['class' => 'control'], $del_button);
362-
363-
return $rule_table;
364362
}
365363
}

ispconfig3_spam/ispconfig3_spam.php

+66-68
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
23
class ispconfig3_spam extends rcube_plugin
34
{
45
public $task = 'settings';
56
private $rcmail;
67
private $rc;
78
private $soap;
89

9-
const content_filters = [
10+
const CONTENT_FILTERS = [
1011
'amavisd' => [
1112
'policy_tag' => 'spam_tag_level',
1213
'policy_tag2' => 'spam_tag2_level',
@@ -26,29 +27,25 @@ function init()
2627
$this->add_texts('localization/');
2728
$this->require_plugin('ispconfig3_account');
2829

29-
$this->register_action('plugin.ispconfig3_spam', array($this, 'init_html'));
30-
$this->register_action('plugin.ispconfig3_spam.save', array($this, 'save'));
30+
$this->register_action('plugin.ispconfig3_spam', [$this, 'init_html']);
31+
$this->register_action('plugin.ispconfig3_spam.save', [$this, 'save']);
3132

3233
if (strpos($this->rcmail->action, 'plugin.ispconfig3_spam') === 0) {
33-
$this->api->output->add_handler('spam_form', array($this, 'gen_form'));
34-
$this->api->output->add_handler('sectionname_spam', array($this, 'prefs_section_name'));
35-
$this->api->output->add_handler('spam_table', array($this, 'gen_table'));
34+
$this->api->output->add_handler('spam_form', [$this, 'gen_form']);
35+
$this->api->output->add_handler('sectionname_spam', [$this, 'prefs_section_name']);
36+
$this->api->output->add_handler('spam_table', [$this, 'gen_table']);
3637

3738
$this->include_script('spam.js');
3839
$this->include_stylesheet($this->local_skin_path() . '/spam.css');
3940

40-
$this->soap = new SoapClient(null, array(
41+
$this->soap = new SoapClient(null, [
4142
'location' => $this->rcmail->config->get('soap_url') . 'index.php',
4243
'uri' => $this->rcmail->config->get('soap_url'),
4344
$this->rcmail->config->get('soap_validate_cert') ?:
44-
'stream_context' => stream_context_create(
45-
array('ssl' => array(
46-
'verify_peer' => false,
47-
'verify_peer_name' => false,
48-
'allow_self_signed' => true
49-
)
50-
))
51-
));
45+
'stream_context' => stream_context_create(['ssl' => [
46+
'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true
47+
]])
48+
]);
5249
}
5350
}
5451

@@ -67,64 +64,66 @@ function save()
6764
{
6865
$policy_id = rcube_utils::get_input_value('_spampolicy_name', rcube_utils::INPUT_POST);
6966
$move_junk = rcube_utils::get_input_value('_spammove', rcube_utils::INPUT_POST);
70-
71-
if (!$move_junk)
72-
$move_junk = 'n';
73-
else
74-
$move_junk = 'y';
67+
$move_junk = (!$move_junk) ? 'n': 'y';
7568

7669
try {
7770
$session_id = $this->soap->login($this->rcmail->config->get('remote_soap_user'), $this->rcmail->config->get('remote_soap_pass'));
78-
$mail_user = $this->soap->mail_user_get($session_id, array('login' => $this->rcmail->user->data['username']));
71+
$mail_user = $this->soap->mail_user_get($session_id, ['login' => $this->rcmail->user->data['username']]);
7972
// Alternatively also search the email field, this can differ from the login field for legacy reasons.
8073
if (empty($mail_user)) {
81-
$mail_user = $this->soap->mail_user_get($session_id, array('email' => $this->rcmail->user->data['username']));
74+
$mail_user = $this->soap->mail_user_get($session_id, ['email' => $this->rcmail->user->data['username']]);
8275
}
8376

84-
$spam_user = $this->soap->mail_spamfilter_user_get($session_id, array('email' => $mail_user[0]['email']));
77+
$spam_user = $this->soap->mail_spamfilter_user_get($session_id, ['email' => $mail_user[0]['email']]);
8578
$uid = $this->soap->client_get_id($session_id, $mail_user[0]['sys_userid']);
8679

8780
if ($spam_user[0]['id'] == '') {
88-
$params = array('server_id' => $mail_user[0]['server_id'],
89-
'priority' => '5',
90-
'policy_id' => $policy_id,
91-
'email' => $mail_user[0]['email'],
92-
'fullname' => $mail_user[0]['email'],
93-
'local' => 'Y');
94-
95-
$add = $this->soap->mail_spamfilter_user_add($session_id, $uid, $params);
81+
$params = [
82+
'server_id' => $mail_user[0]['server_id'],
83+
'priority' => '5',
84+
'policy_id' => $policy_id,
85+
'email' => $mail_user[0]['email'],
86+
'fullname' => $mail_user[0]['email'],
87+
'local' => 'Y'
88+
];
89+
90+
$this->soap->mail_spamfilter_user_add($session_id, $uid, $params);
9691
}
9792
else {
9893
$params = $spam_user[0];
9994
$params['policy_id'] = $policy_id;
10095

101-
$update = $this->soap->mail_spamfilter_user_update($session_id, $uid, $spam_user[0]['id'], $params);
96+
$this->soap->mail_spamfilter_user_update($session_id, $uid, $spam_user[0]['id'], $params);
10297
}
10398

10499
$params = $mail_user[0];
105100
unset($params['password']);
106101

107102
$ispconfig_version = $this->soap->server_get_app_version($session_id);
108103
if (version_compare($ispconfig_version['ispc_app_version'], '3.1dev', '<')) {
109-
$startdate = array('year' => substr($params['autoresponder_start_date'], 0, 4),
104+
$startdate = [
105+
'year' => substr($params['autoresponder_start_date'], 0, 4),
110106
'month' => substr($params['autoresponder_start_date'], 5, 2),
111107
'day' => substr($params['autoresponder_start_date'], 8, 2),
112108
'hour' => substr($params['autoresponder_start_date'], 11, 2),
113-
'minute' => substr($params['autoresponder_start_date'], 14, 2));
109+
'minute' => substr($params['autoresponder_start_date'], 14, 2)
110+
];
114111

115-
$enddate = array('year' => substr($params['autoresponder_end_date'], 0, 4),
112+
$enddate = [
113+
'year' => substr($params['autoresponder_end_date'], 0, 4),
116114
'month' => substr($params['autoresponder_end_date'], 5, 2),
117115
'day' => substr($params['autoresponder_end_date'], 8, 2),
118116
'hour' => substr($params['autoresponder_end_date'], 11, 2),
119-
'minute' => substr($params['autoresponder_end_date'], 14, 2));
117+
'minute' => substr($params['autoresponder_end_date'], 14, 2)
118+
];
120119

121120
$params['autoresponder_end_date'] = $enddate;
122121
$params['autoresponder_start_date'] = $startdate;
123122
}
124123

125124
$params['move_junk'] = $move_junk;
126125

127-
$update = $this->soap->mail_user_update($session_id, $uid, $mail_user[0]['mailuser_id'], $params);
126+
$this->soap->mail_user_update($session_id, $uid, $mail_user[0]['mailuser_id'], $params);
128127
$this->soap->logout($session_id);
129128

130129
$this->rcmail->output->command('display_message', $this->gettext('successfullysaved'), 'confirmation');
@@ -139,59 +138,60 @@ function save()
139138

140139
function gen_form($attrib)
141140
{
142-
$policy_name = array();
143-
$policy_id = array();
141+
$policy_name = [];
142+
$policy_id = [];
144143
$enabled = 0;
145144

146145
$form_id = $attrib['id'] ?: 'form';
147-
$out = $this->rcmail->output->request_form(array(
146+
$out = $this->rcmail->output->request_form([
148147
'id' => $form_id,
149148
'name' => $form_id,
150149
'method' => 'post',
151150
'task' => 'settings',
152151
'action' => 'plugin.ispconfig3_spam.save',
153152
'noclose' => true
154-
) + $attrib);
153+
] + $attrib);
155154

156155
$out .= '<fieldset><legend>' . $this->gettext('acc_spam') . '</legend>' . "\n";
157156

158157
try {
159158
$session_id = $this->soap->login($this->rcmail->config->get('remote_soap_user'), $this->rcmail->config->get('remote_soap_pass'));
160-
$mail_user = $this->soap->mail_user_get($session_id, array('login' => $this->rcmail->user->data['username']));
159+
$mail_user = $this->soap->mail_user_get($session_id, ['login' => $this->rcmail->user->data['username']]);
161160
// Alternatively also search the email field, this can differ from the login field for legacy reasons.
162161
if (empty($mail_user)) {
163-
$mail_user = $this->soap->mail_user_get($session_id, array('email' => $this->rcmail->user->data['username']));
162+
$mail_user = $this->soap->mail_user_get($session_id, ['email' => $this->rcmail->user->data['username']]);
164163
}
165164

166-
$spam_user = $this->soap->mail_spamfilter_user_get($session_id, array('email' => $mail_user[0]['email']));
167-
$policies = $this->soap->mail_policy_get($session_id, array());
168-
$policy_sel = $this->soap->mail_policy_get($session_id, array('id' => $spam_user[0]['policy_id']));
165+
$spam_user = $this->soap->mail_spamfilter_user_get($session_id, ['email' => $mail_user[0]['email']]);
166+
$policies = $this->soap->mail_policy_get($session_id, []);
167+
$policy_sel = $this->soap->mail_policy_get($session_id, ['id' => $spam_user[0]['policy_id']]);
169168
$this->soap->logout($session_id);
170169

171-
foreach ($policies as $policy) {
170+
foreach ((array) $policies as $policy) {
172171
$policy_name[] = $policy['policy_name'];
173172
$policy_id[] = $policy['id'];
174173
}
175174

176175
$enabled = $mail_user[0]['move_junk'];
177-
if ($enabled == 'y')
176+
if ($enabled == 'y') {
178177
$enabled = 1;
178+
}
179179
}
180180
catch (SoapFault $e) {
181181
$error = $this->rc->text_exists($e->getMessage(), $this->ID) ? $this->gettext($e->getMessage()) : $e->getMessage();
182182
$this->rcmail->output->command('display_message', 'Soap Error: ' . $error, 'error');
183183
}
184184

185-
$table = new html_table(array('cols' => 2, 'class' => 'propform'));
185+
$table = new html_table(['cols' => 2, 'class' => 'propform']);
186186

187187
$field_id = 'spampolicy_name';
188-
$input_spampolicy_name = new html_select(array('name' => '_' . $field_id, 'id' => $field_id));
188+
$input_spampolicy_name = new html_select(['name' => '_' . $field_id, 'id' => $field_id]);
189189
$input_spampolicy_name->add($policy_name, $policy_id);
190190
$table->add('title', html::label($field_id, rcube::Q($this->gettext('policy_name'))));
191-
$table->add('', $input_spampolicy_name->show($policy_sel[0]['policy_name']));
191+
$table->add('', $input_spampolicy_name->show($policy_sel[0]['policy_name'] ?? ''));
192192

193193
$field_id = 'spammove';
194-
$input_spammove = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => '1'));
194+
$input_spammove = new html_checkbox(['name' => '_' . $field_id, 'id' => $field_id, 'value' => '1']);
195195
$table->add('title', html::label($field_id, rcube::Q($this->gettext('spammove'))));
196196
$table->add('', $input_spammove->show($enabled));
197197
$out .= $table->show();
@@ -206,18 +206,18 @@ function gen_table($attrib)
206206
$out = '<fieldset><legend>' . $this->gettext('policy_entries') . '</legend>' . "\n";
207207

208208
$spam_table = new html_table([ 'id' => 'spam-table', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 4 ]);
209-
$spam_table->add_header(array('width' => '220px'), $this->gettext('policy_name'));
209+
$spam_table->add_header(['width' => '220px'], $this->gettext('policy_name'));
210210

211211
try {
212212
$session_id = $this->soap->login($this->rcmail->config->get('remote_soap_user'), $this->rcmail->config->get('remote_soap_pass'));
213-
$mail_user = $this->soap->mail_user_get($session_id, array('login' => $this->rcmail->user->data['username']));
213+
$mail_user = $this->soap->mail_user_get($session_id, ['login' => $this->rcmail->user->data['username']]);
214214
// Alternatively also search the email field, this can differ from the login field for legacy reasons.
215215
if (empty($mail_user)) {
216-
$mail_user = $this->soap->mail_user_get($session_id, array('email' => $this->rcmail->user->data['username']));
216+
$mail_user = $this->soap->mail_user_get($session_id, ['email' => $this->rcmail->user->data['username']]);
217217
}
218218

219-
$spam_user = $this->soap->mail_spamfilter_user_get($session_id, array('email' => $mail_user[0]['email']));
220-
$policies = $this->soap->mail_policy_get($session_id, array());
219+
$spam_user = $this->soap->mail_spamfilter_user_get($session_id, ['email' => $mail_user[0]['email']]);
220+
$policies = $this->soap->mail_policy_get($session_id, []);
221221
$mail_server_config = $this->soap->server_get($session_id, $mail_user[0]['server_id'], 'mail');
222222
$this->soap->logout($session_id);
223223

@@ -226,20 +226,20 @@ function gen_table($attrib)
226226
$filter = 'rspamd';
227227
}
228228

229-
$policy_titles = array_keys(self::content_filters[$filter]);
230-
$policy_fields = array_values(self::content_filters[$filter]);
229+
$policy_titles = array_keys(self::CONTENT_FILTERS[$filter]);
230+
$policy_fields = array_values(self::CONTENT_FILTERS[$filter]);
231231

232232
$spam_table->add_header([ 'class' => 'value', 'width' => '150px' ], $this->gettext($policy_titles[0]));
233233
$spam_table->add_header([ 'class' => 'value', 'width' => '150px' ], $this->gettext($policy_titles[1]));
234234
$spam_table->add_header([ 'class' => 'value', 'width' => '130px' ], $this->gettext($policy_titles[2]));
235235

236-
foreach ($policies as $policy) {
236+
foreach ((array) $policies as $policy) {
237237
if ($policy['id'] == $spam_user[0]['policy_id']) {
238238
$spam_table->set_row_attribs([ 'class' => 'selected' ]);
239239
}
240240

241241
$this->_spam_row($spam_table, $policy['policy_name'], $policy[$policy_fields[0]],
242-
$policy[$policy_fields[1]], $policy[$policy_fields[2]], $attrib);
242+
$policy[$policy_fields[1]], $policy[$policy_fields[2]]);
243243
}
244244

245245
if (empty($policies)) {
@@ -259,13 +259,11 @@ function gen_table($attrib)
259259
return $out;
260260
}
261261

262-
private function _spam_row($spam_table, $name, $tag, $tag2, $kill, $attrib)
262+
private function _spam_row($spam_table, $name, $tag, $tag2, $kill)
263263
{
264-
$spam_table->add(array('class' => 'policy'), $name);
265-
$spam_table->add(array('class' => 'value'), '&nbsp;' . $tag);
266-
$spam_table->add(array('class' => 'value'), '&nbsp;' . $tag2);
267-
$spam_table->add(array('class' => 'value'), $kill);
268-
269-
return $spam_table;
264+
$spam_table->add(['class' => 'policy'], $name);
265+
$spam_table->add(['class' => 'value'], '&nbsp;' . $tag);
266+
$spam_table->add(['class' => 'value'], '&nbsp;' . $tag2);
267+
$spam_table->add(['class' => 'value'], $kill);
270268
}
271269
}

0 commit comments

Comments
 (0)