|
@@ -815,7 +815,7 @@ function ModifyModerationSettings($return_config = false)
|
|
*/
|
|
*/
|
|
function ModifySpamSettings($return_config = false)
|
|
function ModifySpamSettings($return_config = false)
|
|
{
|
|
{
|
|
- global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc;
|
|
+ global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc, $language;
|
|
|
|
|
|
|
|
|
|
$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
|
|
$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
|
|
@@ -848,25 +848,58 @@ function ModifySpamSettings($return_config = false)
|
|
if ($return_config)
|
|
if ($return_config)
|
|
return $config_vars;
|
|
return $config_vars;
|
|
|
|
|
|
-
|
|
+
|
|
|
|
+ getLanguages();
|
|
|
|
+ $context['qa_languages'] = array();
|
|
|
|
+ foreach ($context['languages'] as $lang_id => $lang)
|
|
|
|
+ {
|
|
|
|
+ $lang_id = strtr($lang_id, array('-utf8' => ''));
|
|
|
|
+ $lang['name'] = strtr($lang['name'], array('-utf8' => ''));
|
|
|
|
+ $context['qa_languages'][$lang_id] = $lang;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
$context['question_answers'] = array();
|
|
$context['question_answers'] = array();
|
|
$request = $smcFunc['db_query']('', '
|
|
$request = $smcFunc['db_query']('', '
|
|
- SELECT id_comment, body AS question, recipient_name AS answer
|
|
+ SELECT id_question, lngfile, question, answers
|
|
- FROM {db_prefix}log_comments
|
|
+ FROM {db_prefix}qanda'
|
|
- WHERE comment_type = {string:ver_test}',
|
|
|
|
- array(
|
|
|
|
- 'ver_test' => 'ver_test',
|
|
|
|
- )
|
|
|
|
);
|
|
);
|
|
while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
{
|
|
{
|
|
- $context['question_answers'][$row['id_comment']] = array(
|
|
+ $lang = strtr($row['lngfile'], array('-utf8' => ''));
|
|
- 'id' => $row['id_comment'],
|
|
+ $context['question_answers'][$row['id_question']] = array(
|
|
|
|
+ 'lngfile' => $lang,
|
|
'question' => $row['question'],
|
|
'question' => $row['question'],
|
|
- 'answer' => $row['answer'],
|
|
+ 'answers' => unserialize($row['answers']),
|
|
);
|
|
);
|
|
|
|
+ $context['qa_by_lang'][$lang][] = $row['id_question'];
|
|
}
|
|
}
|
|
- $smcFunc['db_free_result']($request);
|
|
+
|
|
|
|
+
|
|
|
|
+ addInlineJavascript('
|
|
|
|
+ var nextrow = ' . (!empty($context['question_answers']) ? max(array_keys($context['question_answers'])) + 1 : 1) . ';
|
|
|
|
+ $(".qa_link a").click(function() {
|
|
|
|
+ var id = $(this).parent().attr("id").substring(6);
|
|
|
|
+ $("#qa_fs_" + id).show();
|
|
|
|
+ $(this).parent().hide();
|
|
|
|
+ });
|
|
|
|
+ $(".qa_fieldset legend a").click(function() {
|
|
|
|
+ var id = $(this).closest("fieldset").attr("id").substring(6);
|
|
|
|
+ $("#qa_dt_" + id).show();
|
|
|
|
+ $(this).closest("fieldset").hide();
|
|
|
|
+ });
|
|
|
|
+ $(".qa_add_question a").click(function() {
|
|
|
|
+ var id = $(this).closest("fieldset").attr("id").substring(6);
|
|
|
|
+ $(\'<dt><input type="text" name="question[\' + id + \'][\' + nextrow + \']" value="" size="50" class="input_text verification_question" /></dt><dd><input type="text" name="answer[\' + id + \'][\' + nextrow + \'][]" value="" size="50" class="input_text verification_answer" / ><div class="qa_add_answer"><a href="javascript:void(0);" onclick="return addAnswer(this);">[ \' + ' . JavaScriptEscape($txt['setup_verification_add_answer']) . ' + \' ]</a></div></dd>\').insertBefore($(this).parent());
|
|
|
|
+ nextrow++;
|
|
|
|
+ });
|
|
|
|
+ function addAnswer(obj)
|
|
|
|
+ {
|
|
|
|
+ var attr = $(obj).closest("dd").find(".verification_answer:last").attr("name");
|
|
|
|
+ $(\'<input type="text" name="\' + attr + \'" value="" size="50" class="input_text verification_answer" />\').insertBefore($(obj).closest("div"));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ $("#qa_dt_' . $language . ' a").click();', true);
|
|
|
|
|
|
|
|
|
|
if (isset($_GET['save']))
|
|
if (isset($_GET['save']))
|
|
@@ -886,71 +919,124 @@ function ModifySpamSettings($return_config = false)
|
|
$save_vars[] = array('text', 'pm_spam_settings');
|
|
$save_vars[] = array('text', 'pm_spam_settings');
|
|
|
|
|
|
|
|
|
|
- $questionInserts = array();
|
|
+ $changes = array(
|
|
- $count_questions = 0;
|
|
+ 'insert' => array(),
|
|
- foreach ($_POST['question'] as $id => $question)
|
|
+ 'replace' => array(),
|
|
|
|
+ 'delete' => array(),
|
|
|
|
+ );
|
|
|
|
+ $qs_per_lang = array();
|
|
|
|
+ foreach ($context['qa_languages'] as $lang_id => $dummy)
|
|
{
|
|
{
|
|
- $question = trim($smcFunc['htmlspecialchars']($question, ENT_COMPAT, $context['character_set']));
|
|
+
|
|
- $answer = trim($smcFunc['strtolower']($smcFunc['htmlspecialchars']($_POST['answer'][$id], ENT_COMPAT, $context['character_set'])));
|
|
+ if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
|
|
-
|
|
+ $changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
|
|
-
|
|
+
|
|
- if (isset($context['question_answers'][$id]))
|
|
+
|
|
|
|
+ if (!empty($context['qa_by_lang'][$lang_id]))
|
|
|
|
+ foreach ($context['qa_by_lang'][$lang_id] as $q_id)
|
|
|
|
+ if (empty($_POST['question'][$lang_id][$q_id]))
|
|
|
|
+ $changes['delete'][] = $q_id;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ foreach ($_POST['question'][$lang_id] as $q_id => $question)
|
|
{
|
|
{
|
|
- $count_questions++;
|
|
+
|
|
-
|
|
+ $q_id = (int) $q_id;
|
|
- if ($context['question_answers'][$id]['question'] != $question || $context['question_answers'][$id]['answer'] != $answer)
|
|
+ if ($q_id <= 0)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (empty($question) || trim($question) == '')
|
|
{
|
|
{
|
|
- if ($question == '' || $answer == '')
|
|
+ if (isset($context['question_answers'][$q_id]))
|
|
- {
|
|
+ $changes['delete'][] = $q_id;
|
|
- $smcFunc['db_query']('', '
|
|
+ continue;
|
|
- DELETE FROM {db_prefix}log_comments
|
|
|
|
- WHERE comment_type = {string:ver_test}
|
|
|
|
- AND id_comment = {int:id}',
|
|
|
|
- array(
|
|
|
|
- 'id' => $id,
|
|
|
|
- 'ver_test' => 'ver_test',
|
|
|
|
- )
|
|
|
|
- );
|
|
|
|
- $count_questions--;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- $request = $smcFunc['db_query']('', '
|
|
|
|
- UPDATE {db_prefix}log_comments
|
|
|
|
- SET body = {string:question}, recipient_name = {string:answer}
|
|
|
|
- WHERE comment_type = {string:ver_test}
|
|
|
|
- AND id_comment = {int:id}',
|
|
|
|
- array(
|
|
|
|
- 'id' => $id,
|
|
|
|
- 'ver_test' => 'ver_test',
|
|
|
|
- 'question' => $question,
|
|
|
|
- 'answer' => $answer,
|
|
|
|
- )
|
|
|
|
- );
|
|
|
|
}
|
|
}
|
|
|
|
+ $question = $smcFunc['htmlspecialchars'](trim($question));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
|
|
|
|
+ {
|
|
|
|
+ if (isset($context['question_answers'][$q_id]))
|
|
|
|
+ $changes['delete'][] = $q_id;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $answers = array();
|
|
|
|
+ foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
|
|
|
|
+ if (!empty($answer) && trim($answer) !== '')
|
|
|
|
+ $answers[] = $smcFunc['htmlspecialchars'](trim($answer));
|
|
|
|
+ if (empty($answers))
|
|
|
|
+ {
|
|
|
|
+ if (isset($context['question_answers'][$q_id]))
|
|
|
|
+ $changes['delete'][] = $q_id;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ $answers = serialize($answers);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (!isset($context['question_answers'][$q_id]))
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ $changes['insert'][] = array($lang_id, $question, $answers);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
|
|
|
|
+ $changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!isset($qs_per_lang[$lang_id]))
|
|
|
|
+ $qs_per_lang[$lang_id] = 0;
|
|
|
|
+ $qs_per_lang[$lang_id]++;
|
|
}
|
|
}
|
|
-
|
|
+ }
|
|
- elseif ($question != '' && $answer != '')
|
|
+
|
|
|
|
+
|
|
|
|
+ if (!empty($changes['delete']))
|
|
|
|
+ {
|
|
|
|
+ $smcFunc['db_query']('', '
|
|
|
|
+ DELETE FROM {db_prefix}qanda
|
|
|
|
+ WHERE id_question IN ({array_int:questions})',
|
|
|
|
+ array(
|
|
|
|
+ 'questions' => $changes['delete'],
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!empty($changes['replace']))
|
|
|
|
+ {
|
|
|
|
+ foreach ($changes['replace'] as $q_id => $question)
|
|
{
|
|
{
|
|
- $questionInserts[] = array(
|
|
+ $smcFunc['db_query']('', '
|
|
- 'comment_type' => 'ver_test',
|
|
+ UPDATE {db_prefix}qanda
|
|
- 'body' => $question,
|
|
+ SET lngfile = {string:lngfile},
|
|
- 'recipient_name' => $answer,
|
|
+ question = {string:question},
|
|
|
|
+ answers = {string:answers}
|
|
|
|
+ WHERE id_question = {int:id_question}',
|
|
|
|
+ array(
|
|
|
|
+ 'id_question' => $q_id,
|
|
|
|
+ 'lngfile' => $question['lngfile'],
|
|
|
|
+ 'question' => $question['question'],
|
|
|
|
+ 'answers' => $question['answers'],
|
|
|
|
+ )
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+ if (!empty($changes['insert']))
|
|
- if (!empty($questionInserts))
|
|
|
|
{
|
|
{
|
|
- $smcFunc['db_insert']('',
|
|
+ $smcFunc['db_insert']('insert',
|
|
- '{db_prefix}log_comments',
|
|
+ '{db_prefix}qanda',
|
|
- array('comment_type' => 'string', 'body' => 'string-65535', 'recipient_name' => 'string-80'),
|
|
+ array('lngfile' => 'string-50', 'question' => 'string-255', 'answers' => 'string-65534'),
|
|
- $questionInserts,
|
|
+ $changes['insert'],
|
|
- array('id_comment')
|
|
+ array('id_question')
|
|
);
|
|
);
|
|
- $count_questions++;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ $count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
|
|
if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
|
|
if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
|
|
$_POST['qa_verification_number'] = $count_questions;
|
|
$_POST['qa_verification_number'] = $count_questions;
|
|
|
|
|
|
@@ -959,7 +1045,7 @@ function ModifySpamSettings($return_config = false)
|
|
|
|
|
|
saveDBSettings($save_vars);
|
|
saveDBSettings($save_vars);
|
|
|
|
|
|
- cache_put_data('verificationQuestionIds', null, 300);
|
|
+ cache_put_data('verificationQuestions', null, 300);
|
|
|
|
|
|
redirectexit('action=admin;area=securitysettings;sa=spam');
|
|
redirectexit('action=admin;area=securitysettings;sa=spam');
|
|
}
|
|
}
|