phpBB

Code Changes

File: phpbb/captcha/plugins/qa.php

  Unmodified   Added   Modified   Removed
Line 95Line 95

while ($row = $db->sql_fetchrow($result))
{


while ($row = $db->sql_fetchrow($result))
{

 
				$this->question_ids[$row['question_id']] = $row['question_id'];
}
$db->sql_freeresult($result);
}

// final fallback to any language
if (!sizeof($this->question_ids))
{
$this->question_lang = '';

$sql = 'SELECT q.question_id, q.lang_iso
FROM ' . $this->table_captcha_questions . ' q, ' . $this->table_captcha_answers . ' a
WHERE q.question_id = a.question_id
GROUP BY lang_iso';
$result = $db->sql_query($sql, 7200);

while ($row = $db->sql_fetchrow($result))
{
if (empty($this->question_lang))
{
$this->question_lang = $row['lang_iso'];
}

				$this->question_ids[$row['question_id']] = $row['question_id'];
}
$db->sql_freeresult($result);

				$this->question_ids[$row['question_id']] = $row['question_id'];
}
$db->sql_freeresult($result);

Line 125Line 147
	*/
public function is_available()
{

	*/
public function is_available()
{

		global $config, $db, $phpbb_root_path, $phpEx, $user;

		global $config, $db, $user;


// load language file for pretty display in the ACP dropdown
$user->add_lang('captcha_qa');


// load language file for pretty display in the ACP dropdown
$user->add_lang('captcha_qa');

Line 198Line 220
	*/
function get_template()
{

	*/
function get_template()
{

		global $template;

		global $phpbb_log, $template, $user;


if ($this->is_solved())
{


if ($this->is_solved())
{

 
			return false;
}
else if (empty($this->question_text) || !count($this->question_ids))
{
/** @var \phpbb\log\log_interface $phpbb_log */
$phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_ERROR_CAPTCHA', time(), array($user->lang('CONFIRM_QUESTION_MISSING')));

			return false;
}
else
{
$template->assign_vars(array(

			return false;
}
else
{
$template->assign_vars(array(

				'QA_CONFIRM_QUESTION'		=> $this->question_text,
'QA_CONFIRM_ID' => $this->confirm_id,
'S_CONFIRM_CODE' => true,
'S_TYPE' => $this->type,

				'QA_CONFIRM_QUESTION'	=> $this->question_text,
'QA_CONFIRM_ID' => $this->confirm_id,
'S_CONFIRM_CODE' => true,
'S_TYPE' => $this->type,

			));

return 'captcha_qa.html';

			));

return 'captcha_qa.html';

Line 263Line 291
	*/
function garbage_collect($type = 0)
{

	*/
function garbage_collect($type = 0)
{

		global $db, $config;

		global $db;


$sql = 'SELECT c.confirm_id
FROM ' . $this->table_qa_confirm . ' c


$sql = 'SELECT c.confirm_id
FROM ' . $this->table_qa_confirm . ' c

Line 309Line 337
		global $db;

$db_tool = new \phpbb\db\tools($db);

		global $db;

$db_tool = new \phpbb\db\tools($db);


$tables = array($this->table_captcha_questions, $this->table_captcha_answers, $this->table_qa_confirm);

 

$schemas = array(
$this->table_captcha_questions => array (


$schemas = array(
$this->table_captcha_questions => array (

Line 352Line 378
				),
);


				),
);


		foreach($schemas as $table => $schema)

		foreach ($schemas as $table => $schema)

		{
if (!$db_tool->sql_table_exists($table))
{

		{
if (!$db_tool->sql_table_exists($table))
{

Line 366Line 392
	*/
function validate()
{

	*/
function validate()
{

		global $config, $db, $user;

		global $phpbb_log, $user;


$error = '';

if (!sizeof($this->question_ids))
{


$error = '';

if (!sizeof($this->question_ids))
{

			return false;



			/** @var \phpbb\log\log_interface $phpbb_log */
$phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_ERROR_CAPTCHA', time(), array($user->lang('CONFIRM_QUESTION_MISSING')));
return $user->lang('CONFIRM_QUESTION_MISSING');

		}

if (!$this->confirm_id)

		}

if (!$this->confirm_id)

Line 414Line 442

if (!sizeof($this->question_ids))
{


if (!sizeof($this->question_ids))
{

			return false;

			return;

		}
$this->confirm_id = md5(unique_id($user->ip));
$this->question = (int) array_rand($this->question_ids);

		}
$this->confirm_id = md5(unique_id($user->ip));
$this->question = (int) array_rand($this->question_ids);

Line 440Line 468

if (!sizeof($this->question_ids))
{


if (!sizeof($this->question_ids))
{

			return false;

			return;

		}

$this->question = (int) array_rand($this->question_ids);

		}

$this->question = (int) array_rand($this->question_ids);

Line 611Line 639
	*/
function acp_page($id, &$module)
{

	*/
function acp_page($id, &$module)
{

		global $db, $user, $auth, $template;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;

		global $user, $template;
global $config;


$user->add_lang('acp/board');
$user->add_lang('captcha_qa');


$user->add_lang('acp/board');
$user->add_lang('captcha_qa');

Line 674Line 702
		else
{
// okay, show the editor

		else
{
// okay, show the editor

			$error = false;
$input_question = request_var('question_text', '', true);
$input_answers = request_var('answers', '', true);
$input_lang = request_var('lang_iso', '', true);
$input_strict = request_var('strict', false);

			$question_input = $this->acp_get_question_input();





			$langs = $this->get_languages();

foreach ($langs as $lang => $entry)

			$langs = $this->get_languages();

foreach ($langs as $lang => $entry)

Line 697Line 721
			{
if ($question = $this->acp_get_question_data($question_id))
{

			{
if ($question = $this->acp_get_question_data($question_id))
{

					$answers = (isset($input_answers[$lang])) ? $input_answers[$lang] : implode("\n", $question['answers']);


 
					$template->assign_vars(array(

					$template->assign_vars(array(

						'QUESTION_TEXT'		=> ($input_question) ? $input_question : $question['question_text'],
'LANG_ISO' => ($input_lang) ? $input_lang : $question['lang_iso'],
'STRICT' => (isset($_REQUEST['strict'])) ? $input_strict : $question['strict'],
'ANSWERS' => $answers,

						'QUESTION_TEXT'		=> ($question_input['question_text']) ? $question_input['question_text'] : $question['question_text'],
'LANG_ISO' => ($question_input['lang_iso']) ? $question_input['lang_iso'] : $question['lang_iso'],
'STRICT' => (isset($_REQUEST['strict'])) ? $question_input['strict'] : $question['strict'],
'ANSWERS' => implode("\n", $question['answers']),

					));
}
else

					));
}
else

Line 714Line 736
			else
{
$template->assign_vars(array(

			else
{
$template->assign_vars(array(

					'QUESTION_TEXT'		=> $input_question,
'LANG_ISO' => $input_lang,
'STRICT' => $input_strict,
'ANSWERS' => $input_answers,

					'QUESTION_TEXT'		=> $question_input['question_text'],
'LANG_ISO' => $question_input['lang_iso'],
'STRICT' => $question_input['strict'],
'ANSWERS' => (is_array($question_input['answers'])) ? implode("\n", $question_input['answers']) : '',

				));
}

if ($submit && check_form_key($form_key))
{

				));
}

if ($submit && check_form_key($form_key))
{

				$data = $this->acp_get_question_input();

if (!$this->validate_input($data))

				if (!$this->validate_input($question_input))



				{
$template->assign_vars(array(
'S_ERROR' => true,

				{
$template->assign_vars(array(
'S_ERROR' => true,

Line 735Line 755
				{
if ($question_id)
{

				{
if ($question_id)
{

						$this->acp_update_question($data, $question_id);

						$this->acp_update_question($question_input, $question_id);

					}
else
{

					}
else
{

						$this->acp_add_question($data);

						$this->acp_add_question($question_input);

					}

add_log('admin', 'LOG_CONFIG_VISUAL');

					}

add_log('admin', 'LOG_CONFIG_VISUAL');

Line 819Line 839

return $question;
}


return $question;
}

 

return false;

	}

/**

	}

/**

Line 827Line 849
	function acp_get_question_input()
{
$answers = utf8_normalize_nfc(request_var('answers', '', true));

	function acp_get_question_input()
{
$answers = utf8_normalize_nfc(request_var('answers', '', true));

 

// Convert answers into array and filter if answers are set
if (strlen($answers))
{
$answers = array_filter(array_map('trim', explode("\n", $answers)), function ($value) {
return $value !== '';
});
}


		$question = array(
'question_text' => request_var('question_text', '', true),
'strict' => request_var('strict', false),
'lang_iso' => request_var('lang_iso', ''),

		$question = array(
'question_text' => request_var('question_text', '', true),
'strict' => request_var('strict', false),
'lang_iso' => request_var('lang_iso', ''),

			'answers'		=> (strlen($answers)) ? explode("\n", $answers) : '',

			'answers'		=> $answers,

		);

		);



 
		return $question;
}


		return $question;
}