phpBB

Code Changes

File: phpbb/captcha/plugins/qa.php

  Unmodified   Added   Modified   Removed
Line 58Line 58
	*/
function init($type)
{

	*/
function init($type)
{

		global $config, $db, $user;

		global $config, $db, $user, $request;


// load our language file
$user->add_lang('captcha_qa');

// read input


// load our language file
$user->add_lang('captcha_qa');

// read input

		$this->confirm_id = request_var('qa_confirm_id', '');
$this->answer = utf8_normalize_nfc(request_var('qa_answer', '', true));

		$this->confirm_id = $request->variable('qa_confirm_id', '');
$this->answer = $request->variable('qa_answer', '', true);


$this->type = (int) $type;
$this->question_lang = $user->lang_name;


$this->type = (int) $type;
$this->question_lang = $user->lang_name;

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 113Line 135
	*/
public function is_installed()
{

	*/
public function is_installed()
{

		global $db;

		global $phpbb_container;





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

		$db_tool = $phpbb_container->get('dbal.tools');


return $db_tool->sql_table_exists($this->table_captcha_questions);
}


return $db_tool->sql_table_exists($this->table_captcha_questions);
}

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 306Line 334
	*/
function install()
{

	*/
function install()
{

		global $db;

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

		global $phpbb_container;







 
		$db_tool = $phpbb_container->get('dbal.tools');

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

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

Line 364Line 391
	*/
function validate()
{

	*/
function validate()
{

		global $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 542Line 571
	*/
function check_answer()
{

	*/
function check_answer()
{

		global $db;

		global $db, $request;





		$answer = ($this->question_strict) ? utf8_normalize_nfc(request_var('qa_answer', '', true)) : utf8_clean_string(utf8_normalize_nfc(request_var('qa_answer', '', true)));

		$answer = ($this->question_strict) ? $request->variable('qa_answer', '', true) : utf8_clean_string($request->variable('qa_answer', '', true));


$sql = 'SELECT answer_text
FROM ' . $this->table_captcha_answers . '


$sql = 'SELECT answer_text
FROM ' . $this->table_captcha_answers . '

Line 596Line 625
	*/
function is_solved()
{

	*/
function is_solved()
{

		if (request_var('qa_answer', false) && $this->solved === 0)



		global $request;

if ($request->variable('qa_answer', false) && $this->solved === 0)

		{
$this->validate();
}

		{
$this->validate();
}

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

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

		global $user, $template;
global $config;

		global $config, $request, $phpbb_log, $template, $user;



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


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

Line 625Line 655
		$form_key = 'acp_captcha';
add_form_key($form_key);


		$form_key = 'acp_captcha';
add_form_key($form_key);


		$submit = request_var('submit', false);
$question_id = request_var('question_id', 0);
$action = request_var('action', '');

		$submit = $request->variable('submit', false);
$question_id = $request->variable('question_id', 0);
$action = $request->variable('action', '');


// we have two pages, so users might want to navigate from one to the other
$list_url = $module->u_action . "&configure=1&select_captcha=" . $this->get_service_name();


// we have two pages, so users might want to navigate from one to the other
$list_url = $module->u_action . "&configure=1&select_captcha=" . $this->get_service_name();

Line 732Line 762
						$this->acp_add_question($question_input);
}


						$this->acp_add_question($question_input);
}


					add_log('admin', 'LOG_CONFIG_VISUAL');

					$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_VISUAL');

					trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($list_url));
}
}

					trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($list_url));
}
}

Line 818Line 848
	*/
function acp_get_question_input()
{

	*/
function acp_get_question_input()
{

		$answers = utf8_normalize_nfc(request_var('answers', '', true));



		global $request;

$answers = $request->variable('answers', '', true);


// Convert answers into array and filter if answers are set
if (strlen($answers))


// Convert answers into array and filter if answers are set
if (strlen($answers))

Line 829Line 861
		}

$question = array(

		}

$question = array(

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

			'question_text'	=> $request->variable('question_text', '', true),
'strict' => $request->variable('strict', false),
'lang_iso' => $request->variable('lang_iso', ''),

			'answers'		=> $answers,
);
return $question;

			'answers'		=> $answers,
);
return $question;