Fix #1882 add toggle to change if spamfilter rule applies to member

This commit is contained in:
Kijin Sung 2022-12-19 02:18:53 +09:00
parent 98f75ee4dd
commit 539b548509
7 changed files with 155 additions and 27 deletions

View file

@ -8,8 +8,10 @@
<action name="dispSpamfilterAdminConfigCaptcha" type="view" menu_name="spamFilter" />
<action name="procSpamfilterAdminInsertDeniedIP" type="controller" />
<action name="procSpamfilterAdminUpdateDeniedIP" type="controller" />
<action name="procSpamfilterAdminDeleteDeniedIP" type="controller" />
<action name="procSpamfilterAdminInsertDeniedWord" type="controller" />
<action name="procSpamfilterAdminUpdateDeniedWord" type="controller" />
<action name="procSpamfilterAdminDeleteDeniedWord" type="controller" />
<action name="procSpamfilterAdminInsertConfig" type="controller" />
<action name="procSpamfilterAdminInsertConfigCaptcha" type="controller" />

View file

@ -0,0 +1,11 @@
<query id="updateDeniedIPAttributes" action="update">
<tables>
<table name="spamfilter_denied_ip" />
</tables>
<columns>
<column name="except_member" var="except_member" />
</columns>
<conditions>
<condition operation="equal" column="ipaddress" var="ipaddress" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,12 @@
<query id="updateDeniedWordAttributes" action="update">
<tables>
<table name="spamfilter_denied_word" />
</tables>
<columns>
<column name="except_member" var="except_member" />
<column name="filter_html" var="filter_html" />
</columns>
<conditions>
<condition operation="equal" column="word" var="word" notnull="notnull" />
</conditions>
</query>

View file

@ -10,11 +10,11 @@ class spamfilterAdminController extends spamfilter
/**
* @brief Initialization
*/
function init()
public function init()
{
}
function procSpamfilterAdminInsertConfig()
public function procSpamfilterAdminInsertConfig()
{
// Get current config
$config = ModuleModel::getModuleConfig('spamfilter') ?: new stdClass;
@ -56,7 +56,7 @@ class spamfilterAdminController extends spamfilter
$this->setRedirectUrl($returnUrl);
}
function procSpamfilterAdminInsertConfigCaptcha()
public function procSpamfilterAdminInsertConfigCaptcha()
{
// Get current config
$config = ModuleModel::getModuleConfig('spamfilter') ?: new stdClass;
@ -113,7 +113,7 @@ class spamfilterAdminController extends spamfilter
$this->setRedirectUrl($returnUrl);
}
function procSpamfilterAdminInsertDeniedIP()
public function procSpamfilterAdminInsertDeniedIP()
{
//스팸IP 추가
$ipaddress_list = Context::get('ipaddress_list');
@ -130,8 +130,49 @@ class spamfilterAdminController extends spamfilter
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispSpamfilterAdminDeniedIPList');
$this->setRedirectUrl($returnUrl);
}
public function procSpamfilterAdminUpdateDeniedIP()
{
$ipaddress = Context::get('ipaddress');
if (!$ipaddress)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$args = new \stdClass;
$args->ipaddress = $ipaddress;
$except_member = Context::get('except_member');
if (!empty($except_member))
{
$args->except_member = $except_member === 'Y' ? 'Y' : 'N';
}
else
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$output = executeQuery('spamfilter.updateDeniedIPAttributes', $args);
if (!$output->toBool())
{
return $output;
}
Rhymix\Framework\Cache::delete('spamfilter:denied_ip_list');
}
function procSpamfilterAdminInsertDeniedWord()
public function procSpamfilterAdminDeleteDeniedIP()
{
$ipAddressList = Context::get('ipaddress');
if($ipAddressList) $this->deleteIP($ipAddressList);
$this->setMessage(lang('success_deleted'));
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispSpamfilterAdminDeniedIPList');
return $this->setRedirectUrl($returnUrl);
}
public function procSpamfilterAdminInsertDeniedWord()
{
//스팸 키워드 추가
$word_list = Context::get('word_list');
@ -148,24 +189,44 @@ class spamfilterAdminController extends spamfilter
$this->setRedirectUrl($returnUrl);
}
/**
* @brief Delete the banned IP
*/
function procSpamfilterAdminDeleteDeniedIP()
public function procSpamfilterAdminUpdateDeniedWord()
{
$ipAddressList = Context::get('ipaddress');
if($ipAddressList) $this->deleteIP($ipAddressList);
$this->setMessage(lang('success_deleted'));
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispSpamfilterAdminDeniedIPList');
return $this->setRedirectUrl($returnUrl);
$word = Context::get('word');
if (!$word)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$args = new \stdClass;
$args->word = $word;
$except_member = Context::get('except_member');
if (!empty($except_member))
{
$args->except_member = $except_member === 'Y' ? 'Y' : 'N';
}
$filter_html = Context::get('filter_html');
if (!empty($filter_html))
{
$args->filter_html = $filter_html === 'Y' ? 'Y' : 'N';
}
if (!isset($args->except_member) && !isset($args->filter_html))
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$output = executeQuery('spamfilter.updateDeniedWordAttributes', $args);
if (!$output->toBool())
{
return $output;
}
Rhymix\Framework\Cache::delete('spamfilter:denied_word_list');
}
/**
* @brief Delete the prohibited Word
*/
function procSpamfilterAdminDeleteDeniedWord()
public function procSpamfilterAdminDeleteDeniedWord()
{
$wordList = Context::get('word');
$this->deleteWord($wordList);
@ -180,7 +241,7 @@ class spamfilterAdminController extends spamfilter
* @brief Delete IP
* Remove the IP address which was previously registered as a spammers
*/
function deleteIP($ipaddress)
public function deleteIP($ipaddress)
{
if(!$ipaddress) return;
@ -196,7 +257,7 @@ class spamfilterAdminController extends spamfilter
* @brief Register the spam word
* The post, which contains the newly registered spam word, should be considered as a spam
*/
function insertWord($word_list)
public function insertWord($word_list)
{
if (!is_array($word_list))
{
@ -250,7 +311,7 @@ class spamfilterAdminController extends spamfilter
* @brief Remove the spam word
* Remove the word which was previously registered as a spam word
*/
function deleteWord($word)
public function deleteWord($word)
{
if(!$word) return;
$args = new stdClass;

View file

@ -24,7 +24,7 @@
<tr loop="$ip_list => $ip_info">
<td>{$ip_info->ipaddress}</td>
<td>{$ip_info->description}</td>
<td>{$ip_info->except_member}</td>
<td><a class="denied_ip_toggle_except_member" href="#" data-ipaddress="{$ip_info->ipaddress}">{$ip_info->except_member}</a></td>
<td><!--@if($ip_info->latest_hit)-->{zdate($ip_info->latest_hit,'Y-m-d H:i')}<!--@else-->-<!--@end--></td>
<td>{$ip_info->hit}</td>
<td>{zdate($ip_info->regdate,'Y-m-d')}</td>

View file

@ -25,8 +25,8 @@
<tr loop="$word_list => $word_info">
<td>{$word_info->word} <!--@if(preg_match('#^/.+/$#', $word_info->word))--><span class="is_regexp">{$lang->cmd_spamfilter_is_regexp}</span><!--@end--></td>
<td>{$word_info->description}</td>
<td>{$word_info->except_member}</td>
<td>{$word_info->filter_html}</td>
<td><a class="denied_word_toggle_except_member" href="#" data-word="{$word_info->word}">{$word_info->except_member}</a></td>
<td><a class="denied_word_toggle_filter_html" href="#" data-word="{$word_info->word}">{$word_info->filter_html}</a></td>
<td><!--@if($word_info->latest_hit)-->{zdate($word_info->latest_hit,'Y-m-d H:i')}<!--@else-->-<!--@end--></td>
<td>{$word_info->hit}</td>
<td>{zdate($word_info->regdate,'Y-m-d')}</td>

View file

@ -17,3 +17,45 @@ function doDeleteDeniedWord(word) {
fo_obj.act.value = "procSpamfilterAdminDeleteDeniedWord";
fo_obj.submit();
}
/**
* Toggle attributes.
*/
$(function() {
$('.denied_ip_toggle_except_member').on('click', function(e) {
e.preventDefault();
var that = $(this);
var new_value = that.text() === 'Y' ? 'N' : 'Y';
exec_json('spamfilter.procSpamfilterAdminUpdateDeniedIP', {
ipaddress: that.data('ipaddress'),
except_member: new_value
}, function() {
that.text(new_value);
});
});
$('.denied_word_toggle_except_member').on('click', function(e) {
e.preventDefault();
var that = $(this);
var new_value = that.text() === 'Y' ? 'N' : 'Y';
exec_json('spamfilter.procSpamfilterAdminUpdateDeniedWord', {
word: that.data('word'),
except_member: new_value
}, function() {
that.text(new_value);
});
});
$('.denied_word_toggle_filter_html').on('click', function(e) {
e.preventDefault();
var that = $(this);
var new_value = that.text() === 'Y' ? 'N' : 'Y';
exec_json('spamfilter.procSpamfilterAdminUpdateDeniedWord', {
word: that.data('word'),
filter_html: new_value
}, function() {
that.text(new_value);
});
});
});