Skip to content

Commit

Permalink
code refactoring, no functional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Churro committed Jun 19, 2022
1 parent 0015fa3 commit f8a6a47
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 76 deletions.
2 changes: 1 addition & 1 deletion ispconfig3_account/ispconfig3_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function template_object_identityform($args)

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

return $args;
Expand Down
9 changes: 6 additions & 3 deletions ispconfig3_autoselect/ispconfig3_autoselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ function load_con_config()
{
$config = $this->api->dir . 'ispconfig3_account/config/config.inc.php';
if (file_exists($config)) {
if (!$this->rcmail->config->load_from_file($config))
if (!$this->rcmail->config->load_from_file($config)) {
rcube::raise_error(['code' => 527, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__,
'message' => "Failed to load config from $config"], true, false);
}
}
else if (file_exists($config . ".dist")) {
if (!$this->rcmail->config->load_from_file($config . '.dist'))
if (!$this->rcmail->config->load_from_file($config . '.dist')) {
rcube::raise_error(['code' => 527, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__,
'message' => "Failed to load config from $config"], true, false);
}
}
}

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

function authenticate($args)
{
if (isset($_POST['_user'], $_POST['_pass']))
if (isset($_POST['_user'], $_POST['_pass'])) {
$args['host'] = $this->getHost(rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST));
}

return $args;
}
Expand Down
6 changes: 2 additions & 4 deletions ispconfig3_filter/ispconfig3_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function gen_table($attrib)
}

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

if (empty($filter)) {
Expand All @@ -334,7 +334,7 @@ function gen_table($attrib)
return $out;
}

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

Expand All @@ -359,7 +359,5 @@ private function _rule_row($rule_table, $name, $active, $id, $attrib)
'title' => 'delete'
]);
$rule_table->add(['class' => 'control'], $del_button);

return $rule_table;
}
}
134 changes: 66 additions & 68 deletions ispconfig3_spam/ispconfig3_spam.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

class ispconfig3_spam extends rcube_plugin
{
public $task = 'settings';
private $rcmail;
private $rc;
private $soap;

const content_filters = [
const CONTENT_FILTERS = [
'amavisd' => [
'policy_tag' => 'spam_tag_level',
'policy_tag2' => 'spam_tag2_level',
Expand All @@ -26,29 +27,25 @@ function init()
$this->add_texts('localization/');
$this->require_plugin('ispconfig3_account');

$this->register_action('plugin.ispconfig3_spam', array($this, 'init_html'));
$this->register_action('plugin.ispconfig3_spam.save', array($this, 'save'));
$this->register_action('plugin.ispconfig3_spam', [$this, 'init_html']);
$this->register_action('plugin.ispconfig3_spam.save', [$this, 'save']);

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

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

$this->soap = new SoapClient(null, array(
$this->soap = new SoapClient(null, [
'location' => $this->rcmail->config->get('soap_url') . 'index.php',
'uri' => $this->rcmail->config->get('soap_url'),
$this->rcmail->config->get('soap_validate_cert') ?:
'stream_context' => stream_context_create(
array('ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
))
));
'stream_context' => stream_context_create(['ssl' => [
'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true
]])
]);
}
}

Expand All @@ -67,64 +64,66 @@ function save()
{
$policy_id = rcube_utils::get_input_value('_spampolicy_name', rcube_utils::INPUT_POST);
$move_junk = rcube_utils::get_input_value('_spammove', rcube_utils::INPUT_POST);

if (!$move_junk)
$move_junk = 'n';
else
$move_junk = 'y';
$move_junk = (!$move_junk) ? 'n': 'y';

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

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

if ($spam_user[0]['id'] == '') {
$params = array('server_id' => $mail_user[0]['server_id'],
'priority' => '5',
'policy_id' => $policy_id,
'email' => $mail_user[0]['email'],
'fullname' => $mail_user[0]['email'],
'local' => 'Y');

$add = $this->soap->mail_spamfilter_user_add($session_id, $uid, $params);
$params = [
'server_id' => $mail_user[0]['server_id'],
'priority' => '5',
'policy_id' => $policy_id,
'email' => $mail_user[0]['email'],
'fullname' => $mail_user[0]['email'],
'local' => 'Y'
];

$this->soap->mail_spamfilter_user_add($session_id, $uid, $params);
}
else {
$params = $spam_user[0];
$params['policy_id'] = $policy_id;

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

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

$ispconfig_version = $this->soap->server_get_app_version($session_id);
if (version_compare($ispconfig_version['ispc_app_version'], '3.1dev', '<')) {
$startdate = array('year' => substr($params['autoresponder_start_date'], 0, 4),
$startdate = [
'year' => substr($params['autoresponder_start_date'], 0, 4),
'month' => substr($params['autoresponder_start_date'], 5, 2),
'day' => substr($params['autoresponder_start_date'], 8, 2),
'hour' => substr($params['autoresponder_start_date'], 11, 2),
'minute' => substr($params['autoresponder_start_date'], 14, 2));
'minute' => substr($params['autoresponder_start_date'], 14, 2)
];

$enddate = array('year' => substr($params['autoresponder_end_date'], 0, 4),
$enddate = [
'year' => substr($params['autoresponder_end_date'], 0, 4),
'month' => substr($params['autoresponder_end_date'], 5, 2),
'day' => substr($params['autoresponder_end_date'], 8, 2),
'hour' => substr($params['autoresponder_end_date'], 11, 2),
'minute' => substr($params['autoresponder_end_date'], 14, 2));
'minute' => substr($params['autoresponder_end_date'], 14, 2)
];

$params['autoresponder_end_date'] = $enddate;
$params['autoresponder_start_date'] = $startdate;
}

$params['move_junk'] = $move_junk;

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

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

function gen_form($attrib)
{
$policy_name = array();
$policy_id = array();
$policy_name = [];
$policy_id = [];
$enabled = 0;

$form_id = $attrib['id'] ?: 'form';
$out = $this->rcmail->output->request_form(array(
$out = $this->rcmail->output->request_form([
'id' => $form_id,
'name' => $form_id,
'method' => 'post',
'task' => 'settings',
'action' => 'plugin.ispconfig3_spam.save',
'noclose' => true
) + $attrib);
] + $attrib);

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

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

$spam_user = $this->soap->mail_spamfilter_user_get($session_id, array('email' => $mail_user[0]['email']));
$policies = $this->soap->mail_policy_get($session_id, array());
$policy_sel = $this->soap->mail_policy_get($session_id, array('id' => $spam_user[0]['policy_id']));
$spam_user = $this->soap->mail_spamfilter_user_get($session_id, ['email' => $mail_user[0]['email']]);
$policies = $this->soap->mail_policy_get($session_id, []);
$policy_sel = $this->soap->mail_policy_get($session_id, ['id' => $spam_user[0]['policy_id']]);
$this->soap->logout($session_id);

foreach ($policies as $policy) {
foreach ((array) $policies as $policy) {
$policy_name[] = $policy['policy_name'];
$policy_id[] = $policy['id'];
}

$enabled = $mail_user[0]['move_junk'];
if ($enabled == 'y')
if ($enabled == 'y') {
$enabled = 1;
}
}
catch (SoapFault $e) {
$error = $this->rc->text_exists($e->getMessage(), $this->ID) ? $this->gettext($e->getMessage()) : $e->getMessage();
$this->rcmail->output->command('display_message', 'Soap Error: ' . $error, 'error');
}

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

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

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

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

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

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

Expand All @@ -226,20 +226,20 @@ function gen_table($attrib)
$filter = 'rspamd';
}

$policy_titles = array_keys(self::content_filters[$filter]);
$policy_fields = array_values(self::content_filters[$filter]);
$policy_titles = array_keys(self::CONTENT_FILTERS[$filter]);
$policy_fields = array_values(self::CONTENT_FILTERS[$filter]);

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

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

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

if (empty($policies)) {
Expand All @@ -259,13 +259,11 @@ function gen_table($attrib)
return $out;
}

private function _spam_row($spam_table, $name, $tag, $tag2, $kill, $attrib)
private function _spam_row($spam_table, $name, $tag, $tag2, $kill)
{
$spam_table->add(array('class' => 'policy'), $name);
$spam_table->add(array('class' => 'value'), '&nbsp;' . $tag);
$spam_table->add(array('class' => 'value'), '&nbsp;' . $tag2);
$spam_table->add(array('class' => 'value'), $kill);

return $spam_table;
$spam_table->add(['class' => 'policy'], $name);
$spam_table->add(['class' => 'value'], '&nbsp;' . $tag);
$spam_table->add(['class' => 'value'], '&nbsp;' . $tag2);
$spam_table->add(['class' => 'value'], $kill);
}
}

0 comments on commit f8a6a47

Please sign in to comment.