aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/captcha
diff options
context:
space:
mode:
authorTristan Darricau <github@nicofuma.fr>2014-08-10 13:15:07 +0200
committerTristan Darricau <github@nicofuma.fr>2014-08-11 01:16:35 +0200
commite889b8f9318ab8e6324f6d5ca4fedc08ce418c8f (patch)
treebe5e665be6b56f59f4c8498c6621415fe6a99170 /phpBB/phpbb/captcha
parent02f3b74e8a7259560f48b6fdf06c3bbd8aa09dbb (diff)
downloadforums-e889b8f9318ab8e6324f6d5ca4fedc08ce418c8f.tar
forums-e889b8f9318ab8e6324f6d5ca4fedc08ce418c8f.tar.gz
forums-e889b8f9318ab8e6324f6d5ca4fedc08ce418c8f.tar.bz2
forums-e889b8f9318ab8e6324f6d5ca4fedc08ce418c8f.tar.xz
forums-e889b8f9318ab8e6324f6d5ca4fedc08ce418c8f.zip
[ticket/11854] Remove constants and use DI for QA tables
PHPBB3-11854
Diffstat (limited to 'phpBB/phpbb/captcha')
-rw-r--r--phpBB/phpbb/captcha/plugins/qa.php78
1 files changed, 48 insertions, 30 deletions
diff --git a/phpBB/phpbb/captcha/plugins/qa.php b/phpBB/phpbb/captcha/plugins/qa.php
index 3d8112e0f0..c0bcf86531 100644
--- a/phpBB/phpbb/captcha/plugins/qa.php
+++ b/phpBB/phpbb/captcha/plugins/qa.php
@@ -30,6 +30,24 @@ class qa
// dirty trick: 0 is false, but can still encode that the captcha is not yet validated
var $solved = 0;
+ protected $table_captcha_questions;
+ protected $table_captcha_answers;
+ protected $table_qa_confirm;
+
+ /**
+ * Constructor
+ *
+ * @param string $table_captcha_questions
+ * @param string $table_captcha_answers
+ * @param string $table_qa_confirm
+ */
+ function __construct($table_captcha_questions, $table_captcha_answers, $table_qa_confirm)
+ {
+ $this->table_captcha_questions = $table_captcha_questions;
+ $this->table_captcha_answers = $table_captcha_answers;
+ $this->table_qa_confirm = $table_qa_confirm;
+ }
+
/**
* @param int $type as per the CAPTCHA API docs, the type
*/
@@ -50,7 +68,7 @@ class qa
// we need all defined questions - shouldn't be too many, so we can just grab them
// try the user's lang first
$sql = 'SELECT question_id
- FROM ' . $table_prefix . 'captcha_questions' . "
+ FROM ' . $this->table_captcha_questions . "
WHERE lang_iso = '" . $db->sql_escape($user->lang_name) . "'";
$result = $db->sql_query($sql, 3600);
@@ -66,7 +84,7 @@ class qa
$this->question_lang = $config['default_lang'];
$sql = 'SELECT question_id
- FROM ' . $table_prefix . 'captcha_questions' . "
+ FROM ' . $this->table_captcha_questions . "
WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
$result = $db->sql_query($sql, 7200);
@@ -94,7 +112,7 @@ class qa
$db_tool = new \phpbb\db\tools($db);
- return $db_tool->sql_table_exists($table_prefix . 'captcha_questions');
+ return $db_tool->sql_table_exists($this->table_captcha_questions);
}
/**
@@ -113,7 +131,7 @@ class qa
}
$sql = 'SELECT COUNT(question_id) AS question_count
- FROM ' . $table_prefix . 'captcha_questions' . "
+ FROM ' . $this->table_captcha_questions . "
WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
@@ -194,7 +212,7 @@ class qa
if ($this->is_available())
{
$sql = 'SELECT question_text
- FROM ' . $table_prefix . 'captcha_questions' . "
+ FROM ' . $this->table_captcha_questions . "
WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
$result = $db->sql_query_limit($sql, 1);
if ($row = $db->sql_fetchrow($result))
@@ -233,7 +251,7 @@ class qa
global $db, $config;
$sql = 'SELECT c.confirm_id
- FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' c
+ FROM ' . $this->table_qa_confirm . ' c
LEFT JOIN ' . SESSIONS_TABLE . ' s
ON (c.session_id = s.session_id)
WHERE s.session_id IS NULL' .
@@ -252,7 +270,7 @@ class qa
if (sizeof($sql_in))
{
- $sql = 'DELETE FROM ' . CAPTCHA_QA_CONFIRM_TABLE . '
+ $sql = 'DELETE FROM ' . $this->table_qa_confirm . '
WHERE ' . $db->sql_in_set('confirm_id', $sql_in);
$db->sql_query($sql);
}
@@ -277,10 +295,10 @@ class qa
$db_tool = new \phpbb\db\tools($db);
- $tables = array($table_prefix . 'captcha_questions', CAPTCHA_ANSWERS_TABLE, CAPTCHA_QA_CONFIRM_TABLE);
+ $tables = array($this->table_captcha_questions, $this->table_captcha_answers, $this->table_qa_confirm);
$schemas = array(
- $table_prefix . 'captcha_questions' => array (
+ $this->table_captcha_questions => array (
'COLUMNS' => array(
'question_id' => array('UINT', null, 'auto_increment'),
'strict' => array('BOOL', 0),
@@ -293,7 +311,7 @@ class qa
'lang' => array('INDEX', 'lang_iso'),
),
),
- CAPTCHA_ANSWERS_TABLE => array (
+ $this->table_captcha_answers => array (
'COLUMNS' => array(
'question_id' => array('UINT', 0),
'answer_text' => array('STEXT_UNI', ''),
@@ -302,7 +320,7 @@ class qa
'qid' => array('INDEX', 'question_id'),
),
),
- CAPTCHA_QA_CONFIRM_TABLE => array (
+ $this->table_qa_confirm => array (
'COLUMNS' => array(
'session_id' => array('CHAR:32', ''),
'confirm_id' => array('CHAR:32', ''),
@@ -386,7 +404,7 @@ class qa
$this->confirm_id = md5(unique_id($user->ip));
$this->question = (int) array_rand($this->question_ids);
- $sql = 'INSERT INTO ' . CAPTCHA_QA_CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
+ $sql = 'INSERT INTO ' . $this->table_qa_confirm . ' ' . $db->sql_build_array('INSERT', array(
'confirm_id' => (string) $this->confirm_id,
'session_id' => (string) $user->session_id,
'lang_iso' => (string) $this->question_lang,
@@ -413,7 +431,7 @@ class qa
$this->question = (int) array_rand($this->question_ids);
$this->solved = 0;
- $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . '
+ $sql = 'UPDATE ' . $this->table_qa_confirm . '
SET question_id = ' . (int) $this->question . "
WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "'
AND session_id = '" . $db->sql_escape($user->session_id) . "'";
@@ -433,7 +451,7 @@ class qa
$this->question = (int) array_rand($this->question_ids);
$this->solved = 0;
- $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . '
+ $sql = 'UPDATE ' . $this->table_qa_confirm . '
SET question_id = ' . (int) $this->question . ",
attempts = attempts + 1
WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "'
@@ -452,7 +470,7 @@ class qa
global $db, $user;
$sql = 'SELECT confirm_id
- FROM ' . CAPTCHA_QA_CONFIRM_TABLE . "
+ FROM ' . $this->table_qa_confirm . "
WHERE
session_id = '" . $db->sql_escape($user->session_id) . "'
AND lang_iso = '" . $db->sql_escape($this->question_lang) . "'
@@ -482,7 +500,7 @@ class qa
}
$sql = 'SELECT con.question_id, attempts, question_text, strict
- FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' con, ' . $table_prefix . 'captcha_questions' . " qes
+ FROM ' . $this->table_qa_confirm . ' con, ' . $this->table_captcha_questions . " qes
WHERE con.question_id = qes.question_id
AND confirm_id = '" . $db->sql_escape($this->confirm_id) . "'
AND session_id = '" . $db->sql_escape($user->session_id) . "'
@@ -516,7 +534,7 @@ class qa
$answer = ($this->question_strict) ? utf8_normalize_nfc(request_var('qa_answer', '', true)) : utf8_clean_string(utf8_normalize_nfc(request_var('qa_answer', '', true)));
$sql = 'SELECT answer_text
- FROM ' . CAPTCHA_ANSWERS_TABLE . '
+ FROM ' . $this->table_captcha_answers . '
WHERE question_id = ' . (int) $this->question;
$result = $db->sql_query($sql);
@@ -551,7 +569,7 @@ class qa
{
global $db, $user;
- $sql = 'DELETE FROM ' . CAPTCHA_QA_CONFIRM_TABLE . "
+ $sql = 'DELETE FROM ' . $this->table_qa_confirm . "
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . (int) $this->type;
$db->sql_query($sql);
@@ -728,7 +746,7 @@ class qa
global $db, $template, $table_prefix;
$sql = 'SELECT *
- FROM ' . $table_prefix . 'captcha_questions';
+ FROM ' . $this->table_captcha_questions;
$result = $db->sql_query($sql);
$template->assign_vars(array(
@@ -760,7 +778,7 @@ class qa
if ($question_id)
{
$sql = 'SELECT *
- FROM ' . $table_prefix . 'captcha_questions' . '
+ FROM ' . $this->table_captcha_questions . '
WHERE question_id = ' . $question_id;
$result = $db->sql_query($sql);
$question = $db->sql_fetchrow($result);
@@ -774,7 +792,7 @@ class qa
$question['answers'] = array();
$sql = 'SELECT *
- FROM ' . CAPTCHA_ANSWERS_TABLE . '
+ FROM ' . $this->table_captcha_answers . '
WHERE question_id = ' . $question_id;
$result = $db->sql_query($sql);
@@ -813,7 +831,7 @@ class qa
global $db, $cache, $table_prefix;
// easier to delete all answers than to figure out which to update
- $sql = 'DELETE FROM ' . CAPTCHA_ANSWERS_TABLE . " WHERE question_id = $question_id";
+ $sql = 'DELETE FROM ' . $this->table_captcha_answers . " WHERE question_id = $question_id";
$db->sql_query($sql);
$langs = $this->get_languages();
@@ -821,14 +839,14 @@ class qa
$question_ary['lang_id'] = $langs[$question_ary['lang_iso']]['id'];
unset($question_ary['answers']);
- $sql = 'UPDATE ' . $table_prefix . 'captcha_questions' . '
+ $sql = 'UPDATE ' . $this->table_captcha_questions . '
SET ' . $db->sql_build_array('UPDATE', $question_ary) . "
WHERE question_id = $question_id";
$db->sql_query($sql);
$this->acp_insert_answers($data, $question_id);
- $cache->destroy('sql', $table_prefix . 'captcha_questions');
+ $cache->destroy('sql', $this->table_captcha_questions);
}
/**
@@ -845,14 +863,14 @@ class qa
$question_ary['lang_id'] = $langs[$data['lang_iso']]['id'];
unset($question_ary['answers']);
- $sql = 'INSERT INTO ' . $table_prefix . 'captcha_questions' . ' ' . $db->sql_build_array('INSERT', $question_ary);
+ $sql = 'INSERT INTO ' . $this->table_captcha_questions . ' ' . $db->sql_build_array('INSERT', $question_ary);
$db->sql_query($sql);
$question_id = $db->sql_nextid();
$this->acp_insert_answers($data, $question_id);
- $cache->destroy('sql', $table_prefix . 'captcha_questions');
+ $cache->destroy('sql', $this->table_captcha_questions);
}
/**
@@ -870,11 +888,11 @@ class qa
'answer_text' => $answer,
);
- $sql = 'INSERT INTO ' . CAPTCHA_ANSWERS_TABLE . ' ' . $db->sql_build_array('INSERT', $answer_ary);
+ $sql = 'INSERT INTO ' . $this->table_captcha_answers . ' ' . $db->sql_build_array('INSERT', $answer_ary);
$db->sql_query($sql);
}
- $cache->destroy('sql', CAPTCHA_ANSWERS_TABLE);
+ $cache->destroy('sql', $this->table_captcha_answers);
}
/**
@@ -884,7 +902,7 @@ class qa
{
global $db, $cache, $table_prefix;
- $tables = array($table_prefix . 'captcha_questions', CAPTCHA_ANSWERS_TABLE);
+ $tables = array($this->table_captcha_questions, $this->table_captcha_answers);
foreach ($tables as $table)
{
@@ -959,7 +977,7 @@ class qa
if ($question_id)
{
$sql = 'SELECT question_id
- FROM ' . $table_prefix . 'captcha_questions' . "
+ FROM ' . $this->table_captcha_questions . "
WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'
AND question_id <> " . (int) $question_id;
$result = $db->sql_query_limit($sql, 1);