Clean up insertWord()

This commit is contained in:
Kijin Sung 2016-12-13 20:05:01 +09:00
parent 6ecdd499e4
commit 0af94a2275
2 changed files with 30 additions and 14 deletions

View file

@ -114,27 +114,38 @@ class spamfilterAdminController extends spamfilter
*/
function insertWord($word_list)
{
$word_list = str_replace("\r","",$word_list);
$word_list = explode("\n",$word_list);
foreach($word_list as $word)
if (!is_array($word_list))
{
if(!preg_match("/^(.{2,40}[\r\n]+)*.{2,40}$/", $word))
$word_list = array_map('trim', explode("\n", $word_list));
}
$fail_list = '';
$output = null;
foreach ($word_list as $word)
{
if ($word === '')
{
continue;
}
if (mb_strlen($word, 'UTF-8') < 2 || mb_strlen($word, 'UTF-8') > 40)
{
return new Object(-1, 'msg_invalid');
}
}
$fail_word = '';
foreach($word_list as $word)
{
$args = new stdClass;
if(trim($word)) $args->word = $word;
$args->word = $word;
$output = executeQuery('spamfilter.insertDeniedWord', $args);
if(!$output->toBool()) $fail_word .= $word.'<br />';
if (!$output->toBool())
{
$fail_list .= $args->word . '<br />';
}
}
if ($output)
{
$output->add('fail_list', $fail_list);
}
$output->add('fail_list',$fail_word);
return $output;
}

View file

@ -173,6 +173,11 @@ class spamfilterController extends spamfilter
foreach ($ipaddress_list as $ipaddress)
{
if ($ipaddress === '')
{
continue;
}
$args = new stdClass;
if (preg_match('@^(.+?)(?://|#)(.*)$@', $ipaddress, $matches))
{