From ba0d8b5a55ae69e228f303c01ba0fe2f545489ee Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Sat, 18 Jul 2009 23:37:09 +0000 Subject: Initial commit for the QA captcha. Needs language & style finetuning and bug searching & fixing git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9786 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 758 +++++++++++++++++++++ 1 file changed, 758 insertions(+) create mode 100755 phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php new file mode 100755 index 0000000000..fe8a14c70f --- /dev/null +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -0,0 +1,758 @@ +add_lang('captcha_qa'); + // read input + $this->confirm_id = request_var('confirm_id', ''); + $this->answer = request_var('answer', ''); + + $this->type = (int) $type; + $this->question_lang = $user->data['user_lang']; + + $sql = 'SELECT question_id FROM ' . QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($user->data['user_lang']) . '\''; + $result = $db->sql_query($sql, 3600); + while ($row = $db->sql_fetchrow($result)) + { + $this->question_ids[$row['question_id']] = $row['question_id']; + } + $db->sql_freeresult($result); + if (!sizeof($this->question_ids)) + { + $this->question_lang = $config['default_lang']; + $sql = 'SELECT question_id FROM ' . QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($config['default_lang']) . '\''; + $result = $db->sql_query($sql, 7200); + while ($row = $db->sql_fetchrow($result)) + { + $this->question_ids[$row['question_id']] = $row['question_id']; + } + $db->sql_freeresult($result); + } + + if (!strlen($this->confirm_id) || !$this->load_answer()) + { + // we have no confirm ID, better get ready to display something + $this->select_question(); + } + } + + + function &get_instance() + { + $instance =& new phpbb_captcha_qa(); + return $instance; + } + + + function is_installed() + { + global $db, $phpbb_root_path, $phpEx; + + if (!class_exists('phpbb_db_tools')) + { + include("$phpbb_root_path/includes/db/db_tools.$phpEx"); + } + $db_tool = new phpbb_db_tools($db); + if (!$db_tool->sql_table_exists(QUESTIONS_TABLE)) + { + return false; + } + } + + function is_available() + { + global $config, $db, $phpbb_root_path, $phpEx, $user; + + $user->add_lang('captcha_qa'); + + if (self::is_installed()) + { + return false; + } + $sql = 'SELECT COUNT(question_id) as count FROM ' . QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($config['default_lang']) . '\''; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + return ((bool) $row['count']); + } + + function get_name() + { + return 'CAPTCHA_QA'; + } + + function get_class_name() + { + return 'phpbb_captcha_qa'; + } + + + function execute_demo() + { + } + + function execute() + { + } + + function get_template() + { + global $config, $user, $template, $phpEx, $phpbb_root_path; + + $template->assign_vars(array( + 'CONFIRM_QUESTION' => $this->question_text, + 'CONFIRM_ID' => $this->confirm_id, + 'S_CONFIRM_CODE' => true, + 'S_TYPE' => $this->type, + )); + + return 'captcha_qa.html'; + } + + function get_demo_template($id) + { + return 'captcha_qa_acp_demo.html'; + } + + function get_hidden_fields() + { + $hidden_fields = array(); + + // this is required - otherwise we would forget about the captcha being already solved + if ($this->solved) + { + $hidden_fields['answer'] = $this->answer; + } + $hidden_fields['confirm_id'] = $this->confirm_id; + return $hidden_fields; + } + + function garbage_collect($type) + { + global $db, $config; + + $sql = 'SELECT DISTINCT c.session_id + FROM ' . QA_CONFIRM_TABLE . ' c + LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id) + WHERE s.session_id IS NULL' . + ((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type); + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $sql_in = array(); + do + { + $sql_in[] = (string) $row['session_id']; + } + while ($row = $db->sql_fetchrow($result)); + + if (sizeof($sql_in)) + { + $sql = 'DELETE FROM ' . QA_CONFIRM_TABLE . ' + WHERE ' . $db->sql_in_set('session_id', $sql_in); + $db->sql_query($sql); + } + } + $db->sql_freeresult($result); + } + + function uninstall() + { + $this->garbage_collect(0); + } + + function install() + { + global $db, $phpbb_root_path, $phpEx; + + if (!class_exists('phpbb_db_tools')) + { + include("$phpbb_root_path/includes/db/db_tools.$phpEx"); + } + $db_tool = new phpbb_db_tools($db); + $tables = array(QUESTIONS_TABLE, ANSWERS_TABLE, QA_CONFIRM_TABLE); + + $schemas = array( + QUESTIONS_TABLE => array ( + 'COLUMNS' => array( + 'question_id' => array('UINT', Null, 'auto_increment'), + 'strict' => array('BOOL', 0), + 'lang_id' => array('UINT', 0), + 'lang_iso' => array('VCHAR:30', 0), + 'question_text' => array('TEXT', 0), + ), + 'PRIMARY_KEY' => 'question_id', + 'KEYS' => array( + 'question_id' => array('INDEX', array('question_id', 'language_iso')), + ), + ), + ANSWERS_TABLE => array ( + 'COLUMNS' => array( + 'question_id' => array('UINT', 0), + 'answer_text' => array('TEXT', 0), + ), + 'KEYS' => array( + 'question_id' => array('INDEX', 'question_id'), + ), + ), + QA_CONFIRM_TABLE => array ( + 'COLUMNS' => array( + 'session_id' => array('CHAR:32', ''), + 'confirm_id' => array('CHAR:32', ''), + 'lang_iso' => array('VCHAR:30', 0), + 'question_id' => array('UINT', 0), + 'attempts' => array('UINT', 0), + 'confirm_type' => array('USINT', 0), + ), + 'KEYS' => array( + 'confirm_id' => array('INDEX', 'confirm_id'), + 'lookup' => array('INDEX', array('confirm_id', 'session_id', 'lang_iso')), + ), + 'PRIMARY_KEY' => 'confirm_id', + ), + ); + + + foreach($schemas as $table => $schema) + { + if (!$db_tool->sql_table_exists($table)) + { + $db_tool->sql_create_table($table, $schema); + } + } + } + + + function validate() + { + global $config, $db, $user; + + $error = ''; + if (!$this->confirm_id) + { + $error = $user->lang['CONFIRM_QUESTION_WRONG']; + } + else + { + if ($this->check_answer()) + { + // $this->delete_code(); commented out to allow posting.php to repeat the question + $this->solved = true; + } + else + { + $error = $user->lang['CONFIRM_QUESTION_WRONG']; + } + } + + if (strlen($error)) + { + // okay, incorrect answer. Let's ask a new question. + $this->new_attempt(); + return $error; + } + else + { + return false; + } + } + + /** + * Select a question + */ + function select_question() + { + global $db, $user; + + $this->confirm_id = md5(unique_id($user->ip)); + $this->question = (int) array_rand($this->question_ids); + + $sql = 'INSERT INTO ' . QA_CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'confirm_id' => (string) $this->confirm_id, + 'session_id' => (string) $user->session_id, + 'lang_iso' => (string) $this->question_lang, + 'confirm_type' => (int) $this->type, + 'question_id' => (int) $this->question, + )); + $db->sql_query($sql); + $this->load_answer(); + + } + + /** + * New Question, if desired. + */ + function reselect_question() + { + global $db, $user; + + $this->question = (int) array_rand($this->question_ids); + $this->solved = 0; + // compute $seed % 0x7fffffff + + $sql = 'UPDATE ' . QA_CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( + 'question' => (int) $this->question,)) . ' + WHERE + confirm_id = \'' . $db->sql_escape($this->confirm_id) . '\' + AND session_id = \'' . $db->sql_escape($user->session_id) . '\''; + $db->sql_query($sql); + $this->load_answer(); + } + + /** + * New Question, if desired. + */ + function new_attempt() + { + global $db, $user; + + $this->question = (int) array_rand($this->question_ids); + $this->solved = 0; + // compute $seed % 0x7fffffff + + $sql = 'UPDATE ' . QA_CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( + 'question_id' => (int) $this->question)) . ', + attempts = attempts + 1 + WHERE + confirm_id = \'' . $db->sql_escape($this->confirm_id) . '\' + AND session_id = \'' . $db->sql_escape($user->session_id) . '\''; + $db->sql_query($sql); + $this->load_answer(); + } + + /** + * Look up everything we need. + */ + function load_answer() + { + global $db, $user; + + $sql = 'SELECT con.question_id, attempts, question_text, strict + FROM ' . QA_CONFIRM_TABLE . ' con, ' . QUESTIONS_TABLE . " 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) . "' + AND qes.lang_iso = '" . $db->sql_escape($this->question_lang) . "' + AND confirm_type = " . $this->type; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($row) + { + $this->question = $row['question_id']; + + $this->attempts = $row['attempts']; + $this->question_strict = $row['strict']; + $this->question_text = $row['question_text']; + return true; + } + return false; + } + + function check_answer() + { + global $db; + + $answer = ($this->question_strict) ? request_var('answer', '') : utf8_clean_string(request_var('answer', '')); + + $sql = 'SELECT answer_text + FROM ' . ANSWERS_TABLE . ' + WHERE question_id = ' . (int) $this->question; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $solution = ($this->question_strict) ? $row['answer_text'] : utf8_clean_string($row['answer_text'] ); + if ($solution === $answer) + { + $this->solved = true; + break; + } + } + $db->sql_freeresult($result); + return $this->solved; + } + + function delete_code() + { + global $db, $user; + + $sql = 'DELETE FROM ' . QA_CONFIRM_TABLE . " + WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "' + AND session_id = '" . $db->sql_escape($user->session_id) . "' + AND confirm_type = " . $this->type; + $db->sql_query($sql); + } + + function get_attempt_count() + { + return $this->attempts; + } + + function reset() + { + global $db, $user; + + $sql = 'DELETE FROM ' . QA_CONFIRM_TABLE . " + WHERE session_id = '" . $db->sql_escape($user->session_id) . "' + AND confirm_type = " . (int) $this->type; + $db->sql_query($sql); + + // we leave the class usable by generating a new question + $this->generate_code(); + } + + function is_solved() + { + if (request_var('answer', false) && $this->solved === 0) + { + $this->validate(); + } + return (bool) $this->solved; + } + + function acp_page($id, &$module) + { + global $db, $user, $auth, $template; + global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; + + $user->add_lang('acp/board'); + $user->add_lang('captcha_qa'); + + if (!$this->is_installed()) + { + $this->install(); + } + $module->tpl_name = 'captcha_qa_acp'; + $module->page_title = 'ACP_VC_SETTINGS'; + $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', ''); + + + $template->assign_vars(array( + 'U_ACTION' => $module->u_action, + 'QUESTION_ID' => $question_id , + 'CLASS' => $this->get_class_name(), + )); + + if (!$question_id && $action != 'add') + { + $this->acp_question_list($module); + } + else if ($question_id && $action == 'delete') + { + if (confirm_box(true)) + { + $this->acp_delete_question($question_id); + trigger_error($user->lang['QUESTION_DELETED'] . adm_back_link($module->u_action)); + } + else + { + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( + 'question_id' => $question_id, + 'action' => $action, + 'configure' => 1, + 'select_captcha' => $this->get_class_name(), + )) + ); + } + } + else + { + + $error = false; + $input_question = request_var('question_text', ''); + $input_answers = request_var('answers', ''); + $input_lang = request_var('lang_iso', ''); + $input_strict = request_var('strict', false); + $langs = $this->get_languages(); + foreach ($langs as $lang => $entry) + { + $template->assign_block_vars('langs', array( + 'ISO' => $lang, + 'NAME' => $entry['name'], + )); + } + + if ($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( + '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, + )); + } + else + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action)); + } + } + else + { + + $template->assign_vars(array( + 'QUESTION_TEXT' => $input_question, + 'LANG_ISO' => $input_lang, + 'STRICT' => $input_strict, + 'ANSWERS' => $input_answers, + )); + } + + if ($submit && check_form_key($form_key)) + { + $data = $this->acp_get_question_input(); + if (!$this->validate_input($data)) + { + $template->assign_vars(array( + 'S_ERROR' => true, + )); + } + else + { + if ($question_id) + { + $this->acp_update_question($data, $question_id); + } + else + { + $this->acp_add_question($data); + } + + trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action . "&configure=1&select_captcha=" . $this->get_class_name())); + } + } + else if ($submit) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action)); + } + } + } + + function acp_question_list(&$module) + { + global $db, $template; + + $sql = 'SELECT * FROM ' . QUESTIONS_TABLE . ' WHERE 1'; + $result = $db->sql_query($sql); + $template->assign_vars(array( + 'S_LIST' => true, + )); + + while($row = $db->sql_fetchrow($result)) + { + $url = $module->u_action . "&question_id={$row['question_id']}&configure=1&select_captcha=" . $this->get_class_name() . "&"; + + $template->assign_block_vars('questions', array( + 'QUESTION_TEXT' => $row['question_text'], + 'QUESTION_ID' => $row['question_id'], + 'QUESTION_LANG' => $row['lang_iso'], + 'U_DELETE' => "{$url}action=delete", + 'U_EDIT' => "{$url}action=edit", + )); + } + $db->sql_freeresult($result); + } + + function acp_get_question_data($question_id) + { + global $db; + + + if ($question_id) + { + $sql = 'SELECT * FROM ' . QUESTIONS_TABLE . ' WHERE question_id = ' . $question_id; + $result = $db->sql_query($sql); + if ($row = $db->sql_fetchrow($result)) + { + $question = $row; + } + else + { + $db->sql_freeresult($result); + return false; + } + $question['answers'] = array(); + $sql = 'SELECT * FROM ' . ANSWERS_TABLE . ' WHERE question_id = ' . $question_id; + $result = $db->sql_query($sql); + while($row = $db->sql_fetchrow($result)) + { + $question['answers'][] = $row['answer_text']; + } + $db->sql_freeresult($result); + return $question; + } + + } + + + function acp_get_question_input() + { + global $db; + + $question = array( + 'question_text' => request_var('question_text', ''), + 'strict' => request_var('strict', false), + 'lang_iso' => request_var('lang_iso', ''), + 'answers' => explode("\n", request_var('answers', '')), + ); + + return $question; + } + + + + function acp_update_question($data, $question_id) + { + global $db; + + $sql = "DELETE FROM " . ANSWERS_TABLE . " WHERE question_id = $question_id"; + $db->sql_query($sql); + $langs = $this->get_languages(); + $question_ary = $data; + $question_ary['lang_id'] = $langs[$question_ary['lang_iso']]['id']; + unset($question_ary['answers']); + $sql = "UPDATE " . QUESTIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $question_ary) . " + WHERE question_id = $question_id"; + $db->sql_query($sql); + $this->acp_insert_answers($data, $question_id); + } + + function acp_add_question($data) + { + global $db; + + $langs = $this->get_languages(); + $question_ary = $data; + + $question_ary['lang_id'] = $langs[$data['lang_iso']]['id']; + unset($question_ary['answers']); + $sql = "INSERT INTO " . QUESTIONS_TABLE . $db->sql_build_array('INSERT', $question_ary); + $db->sql_query($sql); + $question_id = $db->sql_nextid(); + $this->acp_insert_answers($data, $question_id); + } + + function acp_insert_answers($data, $question_id) + { + global $db; + + foreach($data['answers'] as $answer) + { + $answer_ary = array( + 'question_id' => $question_id, + 'answer_text' => $answer, + ); + $sql = "INSERT INTO " . ANSWERS_TABLE . $db->sql_build_array('INSERT', $answer_ary); + $db->sql_query($sql); + } + } + + + + function acp_delete_question($question_id) + { + global $db; + + $tables = array(QUESTIONS_TABLE, ANSWERS_TABLE); + foreach($tables as $table) + { + $sql = "DELETE FROM $table WHERE question_id = $question_id"; + $db->sql_query($sql); + } + } + + + function validate_input($question_data) + { + $langs = $this->get_languages(); + if (!isset($question_data['lang_iso']) || + !isset($question_data['question_text']) || + !isset($question_data['strict']) || + !isset($question_data['answers'])) + { + return false; + } + if (!isset($langs[$question_data['lang_iso']]) || + !$question_data['question_text'] || + !sizeof($question_data['answers'])) + { + return false; + } + + return true; + } + + function get_languages() + { + global $db; + + $langs = array(); + $sql = 'SELECT * FROM ' . LANG_TABLE . ' WHERE 1'; + $result = $db->sql_query($sql); + while($row = $db->sql_fetchrow($result)) + { + $langs[$row['lang_iso']] = array( + 'name' => $row['lang_local_name'], + 'id' => $row['lang_id'], + ); + } + $db->sql_freeresult($result); + return $langs; + } + +} + +?> \ No newline at end of file -- cgit v1.2.1 From 08a7255c8eb517a2b536e7be1f198619a30c7f69 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Sat, 18 Jul 2009 23:39:45 +0000 Subject: Initial commit for the QA captcha. Needs language & style finetuning and bug searching & fixing git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9787 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php old mode 100755 new mode 100644 -- cgit v1.2.1 From 45e127fc64bd6876aedd77e4d28d74a547baae04 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Sun, 19 Jul 2009 09:51:25 +0000 Subject: First round of fixes git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9793 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index fe8a14c70f..bcb1370a1b 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -97,10 +97,7 @@ class phpbb_captcha_qa include("$phpbb_root_path/includes/db/db_tools.$phpEx"); } $db_tool = new phpbb_db_tools($db); - if (!$db_tool->sql_table_exists(QUESTIONS_TABLE)) - { - return false; - } + return $db_tool->sql_table_exists(QUESTIONS_TABLE); } function is_available() @@ -109,7 +106,7 @@ class phpbb_captcha_qa $user->add_lang('captcha_qa'); - if (self::is_installed()) + if (!self::is_installed()) { return false; } -- cgit v1.2.1 From a8c759a033195431b35137987fed2d0a556c6a1a Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Sun, 19 Jul 2009 09:51:50 +0000 Subject: First round of fixes git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9794 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index bcb1370a1b..1992117e09 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -225,7 +225,7 @@ class phpbb_captcha_qa ), 'PRIMARY_KEY' => 'question_id', 'KEYS' => array( - 'question_id' => array('INDEX', array('question_id', 'language_iso')), + 'question_id' => array('INDEX', array('question_id', 'lang_iso')), ), ), ANSWERS_TABLE => array ( -- cgit v1.2.1 From ff60fc9c1e6565eb12f4c8f4591c5cafc012bfb7 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Mon, 20 Jul 2009 10:22:13 +0000 Subject: fixing back links git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9801 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 1992117e09..d6ef8f50b1 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -474,6 +474,7 @@ class phpbb_captcha_qa $question_id = request_var('question_id', 0); $action = request_var('action', ''); + $list_url = $module->u_action . "&configure=1&select_captcha=" . $this->get_class_name(); $template->assign_vars(array( 'U_ACTION' => $module->u_action, @@ -490,7 +491,7 @@ class phpbb_captcha_qa if (confirm_box(true)) { $this->acp_delete_question($question_id); - trigger_error($user->lang['QUESTION_DELETED'] . adm_back_link($module->u_action)); + trigger_error($user->lang['QUESTION_DELETED'] . adm_back_link($list_url)); } else { @@ -520,6 +521,9 @@ class phpbb_captcha_qa )); } + $template->assign_vars(array( + 'U_LIST' => $list_url, + )); if ($question_id) { if ($question = $this->acp_get_question_data($question_id)) @@ -534,7 +538,7 @@ class phpbb_captcha_qa } else { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action)); + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($list_url)); } } else @@ -568,12 +572,12 @@ class phpbb_captcha_qa $this->acp_add_question($data); } - trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action . "&configure=1&select_captcha=" . $this->get_class_name())); + trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($list_url)); } } else if ($submit) { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action)); + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($list_url)); } } } -- cgit v1.2.1 From 04b948c5fd8e7bf8be35c1cedf9bdab1f309e0cb Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Mon, 20 Jul 2009 10:42:27 +0000 Subject: cleaning git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9803 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 133 ++++++++++++++++++--- 1 file changed, 116 insertions(+), 17 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index d6ef8f50b1..fdbbf1d218 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -24,6 +24,7 @@ define('QA_CONFIRM_TABLE', $table_prefix . 'qa_confirm'); /** +* And now to something completely different. Let's make a captcha without extending the abstract class. * QA CAPTCHA sample implementation * * @package VC @@ -39,9 +40,12 @@ class phpbb_captcha_qa var $question_strict; var $attempts = 0; var $type; + // dirty trick: 0 is false, but can still encode that the captcha is not yet validated var $solved = 0; - var $captcha_vars = false; + /** + * @param int $type as per the CAPTCHA API docs, the type + */ function init($type) { global $config, $db, $user; @@ -53,7 +57,8 @@ class phpbb_captcha_qa $this->type = (int) $type; $this->question_lang = $user->data['user_lang']; - + // 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 ' . QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($user->data['user_lang']) . '\''; $result = $db->sql_query($sql, 3600); while ($row = $db->sql_fetchrow($result)) @@ -61,6 +66,7 @@ class phpbb_captcha_qa $this->question_ids[$row['question_id']] = $row['question_id']; } $db->sql_freeresult($result); + // fallback to the board default lang if (!sizeof($this->question_ids)) { $this->question_lang = $config['default_lang']; @@ -73,21 +79,26 @@ class phpbb_captcha_qa $db->sql_freeresult($result); } + // okay, if there is a confirm_id, we try to load that confirm's state if (!strlen($this->confirm_id) || !$this->load_answer()) { - // we have no confirm ID, better get ready to display something + // we have no valid confirm ID, better get ready to ask something $this->select_question(); } } - + /** + * API function + */ function &get_instance() { $instance =& new phpbb_captcha_qa(); return $instance; } - + /** + * See if the captcha has created its tables. + */ function is_installed() { global $db, $phpbb_root_path, $phpEx; @@ -100,6 +111,9 @@ class phpbb_captcha_qa return $db_tool->sql_table_exists(QUESTIONS_TABLE); } + /** + * API function - for the captcha to be available, it must have installed itself and there has to be at least one question in the board's default lang + */ function is_available() { global $config, $db, $phpbb_root_path, $phpEx, $user; @@ -117,28 +131,43 @@ class phpbb_captcha_qa return ((bool) $row['count']); } + /** + * API function + */ function get_name() { return 'CAPTCHA_QA'; } + /** + * API function + */ function get_class_name() { return 'phpbb_captcha_qa'; } + /** + * API function - not needed as we don't display an image + */ function execute_demo() { } + /** + * API function - not needed as we don't display an image + */ function execute() { } + /** + * API function - send the question to the template + */ function get_template() { - global $config, $user, $template, $phpEx, $phpbb_root_path; + global $template; $template->assign_vars(array( 'CONFIRM_QUESTION' => $this->question_text, @@ -150,11 +179,17 @@ class phpbb_captcha_qa return 'captcha_qa.html'; } - function get_demo_template($id) + /** + * API function - we just display a mockup so that the captcha doesn't need to be installed + */ + function get_demo_template() { return 'captcha_qa_acp_demo.html'; } + /** + * API function + */ function get_hidden_fields() { $hidden_fields = array(); @@ -168,6 +203,9 @@ class phpbb_captcha_qa return $hidden_fields; } + /** + * API function + */ function garbage_collect($type) { global $db, $config; @@ -198,11 +236,17 @@ class phpbb_captcha_qa $db->sql_freeresult($result); } + /** + * API function - we don't drop the tables here, as that would cause the loss of all entered questions. + */ function uninstall() { $this->garbage_collect(0); } + /** + * API function - set up shop + */ function install() { global $db, $phpbb_root_path, $phpEx; @@ -226,6 +270,7 @@ class phpbb_captcha_qa 'PRIMARY_KEY' => 'question_id', 'KEYS' => array( 'question_id' => array('INDEX', array('question_id', 'lang_iso')), + 'lang_iso' => array('INDEX', 'lang_iso'), ), ), ANSWERS_TABLE => array ( @@ -254,7 +299,6 @@ class phpbb_captcha_qa ), ); - foreach($schemas as $table => $schema) { if (!$db_tool->sql_table_exists($table)) @@ -265,6 +309,9 @@ class phpbb_captcha_qa } + /** + * API function - see what has to be done to validate + */ function validate() { global $config, $db, $user; @@ -342,12 +389,13 @@ class phpbb_captcha_qa } /** - * New Question, if desired. + * Wrong answer, so we increase the attempts and use a different question. */ function new_attempt() { global $db, $user; + // yah, I would prefer a stronger rand, but this should work $this->question = (int) array_rand($this->question_ids); $this->solved = 0; // compute $seed % 0x7fffffff @@ -363,7 +411,7 @@ class phpbb_captcha_qa } /** - * Look up everything we need. + * Look up everything we need and populate the instance variables. */ function load_answer() { @@ -392,6 +440,9 @@ class phpbb_captcha_qa return false; } + /** + * The actual validation + */ function check_answer() { global $db; @@ -415,6 +466,9 @@ class phpbb_captcha_qa return $this->solved; } + /** + * API function - clean the entry + */ function delete_code() { global $db, $user; @@ -426,11 +480,17 @@ class phpbb_captcha_qa $db->sql_query($sql); } + /** + * API function + */ function get_attempt_count() { return $this->attempts; } + /** + * API function + */ function reset() { global $db, $user; @@ -443,7 +503,10 @@ class phpbb_captcha_qa // we leave the class usable by generating a new question $this->generate_code(); } - + + /** + * API function + */ function is_solved() { if (request_var('answer', false) && $this->solved === 0) @@ -453,6 +516,10 @@ class phpbb_captcha_qa return (bool) $this->solved; } + + /** + * API function - The ACP backend, this marks the end of the easy methods + */ function acp_page($id, &$module) { global $db, $user, $auth, $template; @@ -474,6 +541,7 @@ class phpbb_captcha_qa $question_id = request_var('question_id', 0); $action = request_var('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_class_name(); $template->assign_vars(array( @@ -481,7 +549,8 @@ class phpbb_captcha_qa 'QUESTION_ID' => $question_id , 'CLASS' => $this->get_class_name(), )); - + + // show the list? if (!$question_id && $action != 'add') { $this->acp_question_list($module); @@ -506,7 +575,7 @@ class phpbb_captcha_qa } else { - + // okay, show the editor $error = false; $input_question = request_var('question_text', ''); $input_answers = request_var('answers', ''); @@ -582,6 +651,10 @@ class phpbb_captcha_qa } } + + /** + * This handles the list overview + */ function acp_question_list(&$module) { global $db, $template; @@ -606,7 +679,10 @@ class phpbb_captcha_qa } $db->sql_freeresult($result); } - + + /** + * Grab a question and bring it into a format the editor understands + */ function acp_get_question_data($question_id) { global $db; @@ -639,6 +715,9 @@ class phpbb_captcha_qa } + /** + * Grab a question from input and bring it into a format the editor understands + */ function acp_get_question_input() { global $db; @@ -653,12 +732,15 @@ class phpbb_captcha_qa return $question; } - - + /** + * Update a question. + * param mixed $data : an array as created from acp_get_question_input or acp_get_question_data + */ function acp_update_question($data, $question_id) { global $db; + // easier to delete all answers than to figure out which to update $sql = "DELETE FROM " . ANSWERS_TABLE . " WHERE question_id = $question_id"; $db->sql_query($sql); $langs = $this->get_languages(); @@ -671,6 +753,10 @@ class phpbb_captcha_qa $this->acp_insert_answers($data, $question_id); } + /** + * Insert a question. + * param mixed $data : an array as created from acp_get_question_input or acp_get_question_data + */ function acp_add_question($data) { global $db; @@ -686,6 +772,10 @@ class phpbb_captcha_qa $this->acp_insert_answers($data, $question_id); } + /** + * Insert the answers. + * param mixed $data : an array as created from acp_get_question_input or acp_get_question_data + */ function acp_insert_answers($data, $question_id) { global $db; @@ -702,7 +792,9 @@ class phpbb_captcha_qa } - + /** + * Delete a question. + */ function acp_delete_question($question_id) { global $db; @@ -716,6 +808,10 @@ class phpbb_captcha_qa } + /** + * Check if the entered data can be inserted/used + * param mixed $data : an array as created from acp_get_question_input or acp_get_question_data + */ function validate_input($question_data) { $langs = $this->get_languages(); @@ -736,6 +832,9 @@ class phpbb_captcha_qa return true; } + /** + * List the installed language packs + */ function get_languages() { global $db; -- cgit v1.2.1 From 783da3064a2a4e7163230b75cacb6ef7073493dc Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Mon, 20 Jul 2009 18:27:26 +0000 Subject: rename variables to avoid name clashes in aggregating plugins git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9808 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index fdbbf1d218..cd5ee8c91d 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -50,10 +50,11 @@ class phpbb_captcha_qa { global $config, $db, $user; + // load our language file $user->add_lang('captcha_qa'); // read input - $this->confirm_id = request_var('confirm_id', ''); - $this->answer = request_var('answer', ''); + $this->confirm_id = request_var('qa_confirm_id', ''); + $this->answer = request_var('qa_answer', ''); $this->type = (int) $type; $this->question_lang = $user->data['user_lang']; @@ -118,6 +119,7 @@ class phpbb_captcha_qa { global $config, $db, $phpbb_root_path, $phpEx, $user; + // load language file for pretty display in the ACP dropdown $user->add_lang('captcha_qa'); if (!self::is_installed()) @@ -170,8 +172,8 @@ class phpbb_captcha_qa global $template; $template->assign_vars(array( - 'CONFIRM_QUESTION' => $this->question_text, - 'CONFIRM_ID' => $this->confirm_id, + 'QA_CONFIRM_QUESTION' => $this->question_text, + 'QA_CONFIRM_ID' => $this->confirm_id, 'S_CONFIRM_CODE' => true, 'S_TYPE' => $this->type, )); @@ -197,9 +199,9 @@ class phpbb_captcha_qa // this is required - otherwise we would forget about the captcha being already solved if ($this->solved) { - $hidden_fields['answer'] = $this->answer; + $hidden_fields['qa_answer'] = $this->answer; } - $hidden_fields['confirm_id'] = $this->confirm_id; + $hidden_fields['qa_confirm_id'] = $this->confirm_id; return $hidden_fields; } @@ -447,7 +449,7 @@ class phpbb_captcha_qa { global $db; - $answer = ($this->question_strict) ? request_var('answer', '') : utf8_clean_string(request_var('answer', '')); + $answer = ($this->question_strict) ? request_var('qa_answer', '') : utf8_clean_string(request_var('qa_answer', '')); $sql = 'SELECT answer_text FROM ' . ANSWERS_TABLE . ' @@ -509,7 +511,7 @@ class phpbb_captcha_qa */ function is_solved() { - if (request_var('answer', false) && $this->solved === 0) + if (request_var('qa_answer', false) && $this->solved === 0) { $this->validate(); } -- cgit v1.2.1 From c04626fa4db74dd5effda4574616460d919bedb9 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Wed, 22 Jul 2009 10:42:01 +0000 Subject: index for GC git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9826 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index cd5ee8c91d..c8951cd167 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -294,7 +294,7 @@ class phpbb_captcha_qa 'confirm_type' => array('USINT', 0), ), 'KEYS' => array( - 'confirm_id' => array('INDEX', 'confirm_id'), + 'session_id' => array('INDEX', 'session_id'), 'lookup' => array('INDEX', array('confirm_id', 'session_id', 'lang_iso')), ), 'PRIMARY_KEY' => 'confirm_id', -- cgit v1.2.1 From 2dfd327828a5f6387ea051aa9e588f39249ed059 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Wed, 22 Jul 2009 10:57:56 +0000 Subject: index for GC git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9827 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index c8951cd167..7367816ae8 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -271,7 +271,6 @@ class phpbb_captcha_qa ), 'PRIMARY_KEY' => 'question_id', 'KEYS' => array( - 'question_id' => array('INDEX', array('question_id', 'lang_iso')), 'lang_iso' => array('INDEX', 'lang_iso'), ), ), -- cgit v1.2.1 From 63dc25e5b4596d0f00e4f1dff7fb232141e5227c Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Mon, 27 Jul 2009 06:15:47 +0000 Subject: #48685 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9865 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 7367816ae8..0a0a9f9211 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -54,7 +54,7 @@ class phpbb_captcha_qa $user->add_lang('captcha_qa'); // read input $this->confirm_id = request_var('qa_confirm_id', ''); - $this->answer = request_var('qa_answer', ''); + $this->answer = request_var('qa_answer', '', true); $this->type = (int) $type; $this->question_lang = $user->data['user_lang']; @@ -448,7 +448,7 @@ class phpbb_captcha_qa { global $db; - $answer = ($this->question_strict) ? request_var('qa_answer', '') : utf8_clean_string(request_var('qa_answer', '')); + $answer = ($this->question_strict) ? request_var('qa_answer', '', true) : utf8_clean_string(request_var('qa_answer', '', true)); $sql = 'SELECT answer_text FROM ' . ANSWERS_TABLE . ' @@ -578,9 +578,9 @@ class phpbb_captcha_qa { // okay, show the editor $error = false; - $input_question = request_var('question_text', ''); - $input_answers = request_var('answers', ''); - $input_lang = request_var('lang_iso', ''); + $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); $langs = $this->get_languages(); foreach ($langs as $lang => $entry) @@ -724,10 +724,10 @@ class phpbb_captcha_qa global $db; $question = array( - 'question_text' => request_var('question_text', ''), + 'question_text' => request_var('question_text', '', true), 'strict' => request_var('strict', false), 'lang_iso' => request_var('lang_iso', ''), - 'answers' => explode("\n", request_var('answers', '')), + 'answers' => explode("\n", request_var('answers', '', true)), ); return $question; -- cgit v1.2.1 From a0acfb6a3fce9a547d19c28ac99654275152ac98 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Mon, 27 Jul 2009 11:39:28 +0000 Subject: Minor captcha API change - disable display of plugin by returning false in get_template. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9869 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 0a0a9f9211..1b34f26bfa 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -171,14 +171,21 @@ class phpbb_captcha_qa { global $template; - $template->assign_vars(array( - 'QA_CONFIRM_QUESTION' => $this->question_text, - 'QA_CONFIRM_ID' => $this->confirm_id, - 'S_CONFIRM_CODE' => true, - 'S_TYPE' => $this->type, - )); + if ($this->is_solved()) + { + 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, + )); - return 'captcha_qa.html'; + return 'captcha_qa.html'; + } } /** -- cgit v1.2.1 From fc4aaa3f5a32d8d7295197f15b2b9355b851342a Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Tue, 28 Jul 2009 07:05:17 +0000 Subject: #48735 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9877 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 1b34f26bfa..4836d7906f 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -32,7 +32,6 @@ define('QA_CONFIRM_TABLE', $table_prefix . 'qa_confirm'); class phpbb_captcha_qa { var $confirm_id; - var $confirm_code; var $answer; var $question_ids; var $question_text; @@ -509,7 +508,7 @@ class phpbb_captcha_qa $db->sql_query($sql); // we leave the class usable by generating a new question - $this->generate_code(); + $this->select_question(); } /** -- cgit v1.2.1 From 49625a2aec3f1fbc83952d9d7ba207995120a436 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 29 Jul 2009 22:59:51 +0000 Subject: Props. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9891 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 4836d7906f..76e5a3163c 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -2,7 +2,7 @@ /** * * @package VC -* @version $Id: captcha_abstract.php 9709 2009-06-30 14:23:16Z Kellanved $ +* @version $Id$ * @copyright (c) 2006, 2008 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * -- cgit v1.2.1 From af213166f36f3e71e4f3387827629fea5d190711 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Wed, 12 Aug 2009 19:57:34 +0000 Subject: some fixes git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9967 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 76e5a3163c..9b05f25dd3 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -121,7 +121,7 @@ class phpbb_captcha_qa // load language file for pretty display in the ACP dropdown $user->add_lang('captcha_qa'); - if (!self::is_installed()) + if (!phpbb_captcha_qa::is_installed()) { return false; } @@ -273,7 +273,7 @@ class phpbb_captcha_qa 'strict' => array('BOOL', 0), 'lang_id' => array('UINT', 0), 'lang_iso' => array('VCHAR:30', 0), - 'question_text' => array('TEXT', 0), + 'question_text' => array('TEXT_UNI', ''), ), 'PRIMARY_KEY' => 'question_id', 'KEYS' => array( @@ -283,7 +283,7 @@ class phpbb_captcha_qa ANSWERS_TABLE => array ( 'COLUMNS' => array( 'question_id' => array('UINT', 0), - 'answer_text' => array('TEXT', 0), + 'answer_text' => array('STEXT_UNI', ''), ), 'KEYS' => array( 'question_id' => array('INDEX', 'question_id'), -- cgit v1.2.1 From 929fd29ce13ad42235b58f327b694a00780ebe5e Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Wed, 12 Aug 2009 22:03:14 +0000 Subject: some fixes git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9968 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 9b05f25dd3..cdbb7ea864 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -272,7 +272,7 @@ class phpbb_captcha_qa 'question_id' => array('UINT', Null, 'auto_increment'), 'strict' => array('BOOL', 0), 'lang_id' => array('UINT', 0), - 'lang_iso' => array('VCHAR:30', 0), + 'lang_iso' => array('VCHAR:30', ''), 'question_text' => array('TEXT_UNI', ''), ), 'PRIMARY_KEY' => 'question_id', @@ -293,7 +293,7 @@ class phpbb_captcha_qa 'COLUMNS' => array( 'session_id' => array('CHAR:32', ''), 'confirm_id' => array('CHAR:32', ''), - 'lang_iso' => array('VCHAR:30', 0), + 'lang_iso' => array('VCHAR:30', ''), 'question_id' => array('UINT', 0), 'attempts' => array('UINT', 0), 'confirm_type' => array('USINT', 0), -- cgit v1.2.1 From 918e66758795f744092fce2d423f6d43bb00b7c0 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Fri, 14 Aug 2009 10:00:30 +0000 Subject: #49675 #49655 - ATTENTION: small captcha API change git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9975 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 66 +++++++++++++--------- 1 file changed, 38 insertions(+), 28 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index cdbb7ea864..84730a738c 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -17,9 +17,9 @@ if (!defined('IN_PHPBB')) } global $table_prefix; -define('QUESTIONS_TABLE', $table_prefix . 'captcha_questions'); -define('ANSWERS_TABLE', $table_prefix . 'captcha_answers'); -define('QA_CONFIRM_TABLE', $table_prefix . 'qa_confirm'); +define('CAPTCHA_QUESTIONS_TABLE', $table_prefix . 'captcha_questions'); +define('CAPTCHA_ANSWERS_TABLE', $table_prefix . 'captcha_answers'); +define('CAPTCHA_QA_CONFIRM_TABLE', $table_prefix . 'qa_confirm'); @@ -59,7 +59,7 @@ class phpbb_captcha_qa $this->question_lang = $user->data['user_lang']; // 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 ' . QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($user->data['user_lang']) . '\''; + $sql = 'SELECT question_id FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($user->data['user_lang']) . '\''; $result = $db->sql_query($sql, 3600); while ($row = $db->sql_fetchrow($result)) { @@ -70,7 +70,7 @@ class phpbb_captcha_qa if (!sizeof($this->question_ids)) { $this->question_lang = $config['default_lang']; - $sql = 'SELECT question_id FROM ' . QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($config['default_lang']) . '\''; + $sql = 'SELECT question_id FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($config['default_lang']) . '\''; $result = $db->sql_query($sql, 7200); while ($row = $db->sql_fetchrow($result)) { @@ -108,7 +108,7 @@ class phpbb_captcha_qa include("$phpbb_root_path/includes/db/db_tools.$phpEx"); } $db_tool = new phpbb_db_tools($db); - return $db_tool->sql_table_exists(QUESTIONS_TABLE); + return $db_tool->sql_table_exists(CAPTCHA_QUESTIONS_TABLE); } /** @@ -125,13 +125,23 @@ class phpbb_captcha_qa { return false; } - $sql = 'SELECT COUNT(question_id) as count FROM ' . QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($config['default_lang']) . '\''; + $sql = 'SELECT COUNT(question_id) as count FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($config['default_lang']) . '\''; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); return ((bool) $row['count']); } + + /** + * API function + */ + function has_config() + { + return true; + } + + /** * API function */ @@ -219,7 +229,7 @@ class phpbb_captcha_qa global $db, $config; $sql = 'SELECT DISTINCT c.session_id - FROM ' . QA_CONFIRM_TABLE . ' c + FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' c LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id) WHERE s.session_id IS NULL' . ((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type); @@ -236,7 +246,7 @@ class phpbb_captcha_qa if (sizeof($sql_in)) { - $sql = 'DELETE FROM ' . QA_CONFIRM_TABLE . ' + $sql = 'DELETE FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' WHERE ' . $db->sql_in_set('session_id', $sql_in); $db->sql_query($sql); } @@ -264,10 +274,10 @@ class phpbb_captcha_qa include("$phpbb_root_path/includes/db/db_tools.$phpEx"); } $db_tool = new phpbb_db_tools($db); - $tables = array(QUESTIONS_TABLE, ANSWERS_TABLE, QA_CONFIRM_TABLE); + $tables = array(CAPTCHA_QUESTIONS_TABLE, CAPTCHA_ANSWERS_TABLE, CAPTCHA_QA_CONFIRM_TABLE); $schemas = array( - QUESTIONS_TABLE => array ( + CAPTCHA_QUESTIONS_TABLE => array ( 'COLUMNS' => array( 'question_id' => array('UINT', Null, 'auto_increment'), 'strict' => array('BOOL', 0), @@ -280,7 +290,7 @@ class phpbb_captcha_qa 'lang_iso' => array('INDEX', 'lang_iso'), ), ), - ANSWERS_TABLE => array ( + CAPTCHA_ANSWERS_TABLE => array ( 'COLUMNS' => array( 'question_id' => array('UINT', 0), 'answer_text' => array('STEXT_UNI', ''), @@ -289,7 +299,7 @@ class phpbb_captcha_qa 'question_id' => array('INDEX', 'question_id'), ), ), - QA_CONFIRM_TABLE => array ( + CAPTCHA_QA_CONFIRM_TABLE => array ( 'COLUMNS' => array( 'session_id' => array('CHAR:32', ''), 'confirm_id' => array('CHAR:32', ''), @@ -363,7 +373,7 @@ class phpbb_captcha_qa $this->confirm_id = md5(unique_id($user->ip)); $this->question = (int) array_rand($this->question_ids); - $sql = 'INSERT INTO ' . QA_CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array( + $sql = 'INSERT INTO ' . CAPTCHA_QA_CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array( 'confirm_id' => (string) $this->confirm_id, 'session_id' => (string) $user->session_id, 'lang_iso' => (string) $this->question_lang, @@ -386,7 +396,7 @@ class phpbb_captcha_qa $this->solved = 0; // compute $seed % 0x7fffffff - $sql = 'UPDATE ' . QA_CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( + $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( 'question' => (int) $this->question,)) . ' WHERE confirm_id = \'' . $db->sql_escape($this->confirm_id) . '\' @@ -407,7 +417,7 @@ class phpbb_captcha_qa $this->solved = 0; // compute $seed % 0x7fffffff - $sql = 'UPDATE ' . QA_CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( + $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( 'question_id' => (int) $this->question)) . ', attempts = attempts + 1 WHERE @@ -425,7 +435,7 @@ class phpbb_captcha_qa global $db, $user; $sql = 'SELECT con.question_id, attempts, question_text, strict - FROM ' . QA_CONFIRM_TABLE . ' con, ' . QUESTIONS_TABLE . " qes + FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' con, ' . CAPTCHA_QUESTIONS_TABLE . " 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) . "' @@ -457,7 +467,7 @@ class phpbb_captcha_qa $answer = ($this->question_strict) ? request_var('qa_answer', '', true) : utf8_clean_string(request_var('qa_answer', '', true)); $sql = 'SELECT answer_text - FROM ' . ANSWERS_TABLE . ' + FROM ' . CAPTCHA_ANSWERS_TABLE . ' WHERE question_id = ' . (int) $this->question; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -480,7 +490,7 @@ class phpbb_captcha_qa { global $db, $user; - $sql = 'DELETE FROM ' . QA_CONFIRM_TABLE . " + $sql = 'DELETE FROM ' . CAPTCHA_QA_CONFIRM_TABLE . " WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "' AND session_id = '" . $db->sql_escape($user->session_id) . "' AND confirm_type = " . $this->type; @@ -502,7 +512,7 @@ class phpbb_captcha_qa { global $db, $user; - $sql = 'DELETE FROM ' . QA_CONFIRM_TABLE . " + $sql = 'DELETE FROM ' . CAPTCHA_QA_CONFIRM_TABLE . " WHERE session_id = '" . $db->sql_escape($user->session_id) . "' AND confirm_type = " . (int) $this->type; $db->sql_query($sql); @@ -666,7 +676,7 @@ class phpbb_captcha_qa { global $db, $template; - $sql = 'SELECT * FROM ' . QUESTIONS_TABLE . ' WHERE 1'; + $sql = 'SELECT * FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE 1'; $result = $db->sql_query($sql); $template->assign_vars(array( 'S_LIST' => true, @@ -697,7 +707,7 @@ class phpbb_captcha_qa if ($question_id) { - $sql = 'SELECT * FROM ' . QUESTIONS_TABLE . ' WHERE question_id = ' . $question_id; + $sql = 'SELECT * FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE question_id = ' . $question_id; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { @@ -709,7 +719,7 @@ class phpbb_captcha_qa return false; } $question['answers'] = array(); - $sql = 'SELECT * FROM ' . ANSWERS_TABLE . ' WHERE question_id = ' . $question_id; + $sql = 'SELECT * FROM ' . CAPTCHA_ANSWERS_TABLE . ' WHERE question_id = ' . $question_id; $result = $db->sql_query($sql); while($row = $db->sql_fetchrow($result)) { @@ -748,13 +758,13 @@ class phpbb_captcha_qa global $db; // easier to delete all answers than to figure out which to update - $sql = "DELETE FROM " . ANSWERS_TABLE . " WHERE question_id = $question_id"; + $sql = "DELETE FROM " . CAPTCHA_ANSWERS_TABLE . " WHERE question_id = $question_id"; $db->sql_query($sql); $langs = $this->get_languages(); $question_ary = $data; $question_ary['lang_id'] = $langs[$question_ary['lang_iso']]['id']; unset($question_ary['answers']); - $sql = "UPDATE " . QUESTIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $question_ary) . " + $sql = "UPDATE " . CAPTCHA_QUESTIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $question_ary) . " WHERE question_id = $question_id"; $db->sql_query($sql); $this->acp_insert_answers($data, $question_id); @@ -773,7 +783,7 @@ class phpbb_captcha_qa $question_ary['lang_id'] = $langs[$data['lang_iso']]['id']; unset($question_ary['answers']); - $sql = "INSERT INTO " . QUESTIONS_TABLE . $db->sql_build_array('INSERT', $question_ary); + $sql = "INSERT INTO " . CAPTCHA_QUESTIONS_TABLE . $db->sql_build_array('INSERT', $question_ary); $db->sql_query($sql); $question_id = $db->sql_nextid(); $this->acp_insert_answers($data, $question_id); @@ -793,7 +803,7 @@ class phpbb_captcha_qa 'question_id' => $question_id, 'answer_text' => $answer, ); - $sql = "INSERT INTO " . ANSWERS_TABLE . $db->sql_build_array('INSERT', $answer_ary); + $sql = "INSERT INTO " . CAPTCHA_ANSWERS_TABLE . $db->sql_build_array('INSERT', $answer_ary); $db->sql_query($sql); } } @@ -806,7 +816,7 @@ class phpbb_captcha_qa { global $db; - $tables = array(QUESTIONS_TABLE, ANSWERS_TABLE); + $tables = array(CAPTCHA_QUESTIONS_TABLE, CAPTCHA_ANSWERS_TABLE); foreach($tables as $table) { $sql = "DELETE FROM $table WHERE question_id = $question_id"; -- cgit v1.2.1 From bc57fdc01ce6c1a9275f16a0791c60dbc0b449b7 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Sat, 15 Aug 2009 16:10:13 +0000 Subject: #49755 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9992 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 84730a738c..7dd5233045 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -676,7 +676,7 @@ class phpbb_captcha_qa { global $db, $template; - $sql = 'SELECT * FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE 1'; + $sql = 'SELECT * FROM ' . CAPTCHA_QUESTIONS_TABLE; $result = $db->sql_query($sql); $template->assign_vars(array( 'S_LIST' => true, @@ -857,7 +857,7 @@ class phpbb_captcha_qa global $db; $langs = array(); - $sql = 'SELECT * FROM ' . LANG_TABLE . ' WHERE 1'; + $sql = 'SELECT * FROM ' . LANG_TABLE; $result = $db->sql_query($sql); while($row = $db->sql_fetchrow($result)) { -- cgit v1.2.1 From 0393a6232b5aa2b8764c50b40e2cb8b7b0803302 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 15 Aug 2009 19:56:45 +0000 Subject: - #49775 - Some coding guidelines fixes git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9993 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 101 +++++++++++++-------- 1 file changed, 65 insertions(+), 36 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 7dd5233045..adc0811a57 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -676,15 +676,17 @@ class phpbb_captcha_qa { global $db, $template; - $sql = 'SELECT * FROM ' . CAPTCHA_QUESTIONS_TABLE; + $sql = 'SELECT * + FROM ' . CAPTCHA_QUESTIONS_TABLE; $result = $db->sql_query($sql); + $template->assign_vars(array( - 'S_LIST' => true, + 'S_LIST' => true, )); - while($row = $db->sql_fetchrow($result)) + while ($row = $db->sql_fetchrow($result)) { - $url = $module->u_action . "&question_id={$row['question_id']}&configure=1&select_captcha=" . $this->get_class_name() . "&"; + $url = $module->u_action . "&question_id={$row['question_id']}&configure=1&select_captcha=" . $this->get_class_name() . '&'; $template->assign_block_vars('questions', array( 'QUESTION_TEXT' => $row['question_text'], @@ -704,31 +706,35 @@ class phpbb_captcha_qa { global $db; - if ($question_id) { - $sql = 'SELECT * FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE question_id = ' . $question_id; + $sql = 'SELECT * + FROM ' . CAPTCHA_QUESTIONS_TABLE . ' + WHERE question_id = ' . $question_id; $result = $db->sql_query($sql); - if ($row = $db->sql_fetchrow($result)) - { - $question = $row; - } - else + $question = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$question) { - $db->sql_freeresult($result); return false; } + $question['answers'] = array(); - $sql = 'SELECT * FROM ' . CAPTCHA_ANSWERS_TABLE . ' WHERE question_id = ' . $question_id; + + $sql = 'SELECT * + FROM ' . CAPTCHA_ANSWERS_TABLE . ' + WHERE question_id = ' . $question_id; $result = $db->sql_query($sql); - while($row = $db->sql_fetchrow($result)) + + while ($row = $db->sql_fetchrow($result)) { $question['answers'][] = $row['answer_text']; } $db->sql_freeresult($result); + return $question; } - } @@ -737,15 +743,13 @@ class phpbb_captcha_qa */ function acp_get_question_input() { - global $db; - $question = array( 'question_text' => request_var('question_text', '', true), 'strict' => request_var('strict', false), 'lang_iso' => request_var('lang_iso', ''), 'answers' => explode("\n", request_var('answers', '', true)), ); - + return $question; } @@ -755,19 +759,25 @@ class phpbb_captcha_qa */ function acp_update_question($data, $question_id) { - global $db; + global $db, $cache; // 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 ' . CAPTCHA_ANSWERS_TABLE . " WHERE question_id = $question_id"; $db->sql_query($sql); + $langs = $this->get_languages(); $question_ary = $data; $question_ary['lang_id'] = $langs[$question_ary['lang_iso']]['id']; unset($question_ary['answers']); - $sql = "UPDATE " . CAPTCHA_QUESTIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $question_ary) . " - WHERE question_id = $question_id"; + + $sql = 'UPDATE ' . CAPTCHA_QUESTIONS_TABLE . ' + 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', CAPTCHA_QUESTIONS_TABLE); } /** @@ -776,17 +786,22 @@ class phpbb_captcha_qa */ function acp_add_question($data) { - global $db; + global $db, $cache; $langs = $this->get_languages(); $question_ary = $data; $question_ary['lang_id'] = $langs[$data['lang_iso']]['id']; unset($question_ary['answers']); - $sql = "INSERT INTO " . CAPTCHA_QUESTIONS_TABLE . $db->sql_build_array('INSERT', $question_ary); + + $sql = 'INSERT INTO ' . CAPTCHA_QUESTIONS_TABLE . $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', CAPTCHA_QUESTIONS_TABLE); } /** @@ -795,17 +810,20 @@ class phpbb_captcha_qa */ function acp_insert_answers($data, $question_id) { - global $db; + global $db, $cache; - foreach($data['answers'] as $answer) + foreach ($data['answers'] as $answer) { $answer_ary = array( 'question_id' => $question_id, 'answer_text' => $answer, ); - $sql = "INSERT INTO " . CAPTCHA_ANSWERS_TABLE . $db->sql_build_array('INSERT', $answer_ary); + + $sql = 'INSERT INTO ' . CAPTCHA_ANSWERS_TABLE . $db->sql_build_array('INSERT', $answer_ary); $db->sql_query($sql); } + + $cache->destroy('sql', CAPTCHA_ANSWERS_TABLE); } @@ -814,14 +832,18 @@ class phpbb_captcha_qa */ function acp_delete_question($question_id) { - global $db; - + global $db, $cache; + $tables = array(CAPTCHA_QUESTIONS_TABLE, CAPTCHA_ANSWERS_TABLE); - foreach($tables as $table) + + foreach ($tables as $table) { - $sql = "DELETE FROM $table WHERE question_id = $question_id"; + $sql = "DELETE FROM $table + WHERE question_id = $question_id"; $db->sql_query($sql); } + + $cache->destroy('sql', $tables); } @@ -832,6 +854,7 @@ class phpbb_captcha_qa function validate_input($question_data) { $langs = $this->get_languages(); + if (!isset($question_data['lang_iso']) || !isset($question_data['question_text']) || !isset($question_data['strict']) || @@ -839,13 +862,14 @@ class phpbb_captcha_qa { return false; } + if (!isset($langs[$question_data['lang_iso']]) || !$question_data['question_text'] || !sizeof($question_data['answers'])) { return false; } - + return true; } @@ -855,18 +879,23 @@ class phpbb_captcha_qa function get_languages() { global $db; - + $langs = array(); - $sql = 'SELECT * FROM ' . LANG_TABLE; + + $sql = 'SELECT * + FROM ' . LANG_TABLE; + $result = $db->sql_query($sql); - while($row = $db->sql_fetchrow($result)) + + while ($row = $db->sql_fetchrow($result)) { $langs[$row['lang_iso']] = array( 'name' => $row['lang_local_name'], - 'id' => $row['lang_id'], + 'id' => (int) $row['lang_id'], ); } $db->sql_freeresult($result); + return $langs; } -- cgit v1.2.1 From 6cc55a3436ea81482d0d2462b400e2b66274660d Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Sun, 16 Aug 2009 21:07:11 +0000 Subject: don't pick a new question without an explicit reset call git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9997 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index adc0811a57..35f42848b3 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -354,7 +354,8 @@ class phpbb_captcha_qa if (strlen($error)) { // okay, incorrect answer. Let's ask a new question. - $this->new_attempt(); + // $this->new_attempt(); + $this->solved = false; return $error; } else @@ -433,7 +434,7 @@ class phpbb_captcha_qa function load_answer() { global $db, $user; - + $sql = 'SELECT con.question_id, attempts, question_text, strict FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' con, ' . CAPTCHA_QUESTIONS_TABLE . " qes WHERE con.question_id = qes.question_id -- cgit v1.2.1 From ba3e0831ea90cdf2fa740088162e57221107748c Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Sun, 16 Aug 2009 21:11:17 +0000 Subject: erm, on the contrary; can that reset call git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9998 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 35f42848b3..511706bb93 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -354,7 +354,7 @@ class phpbb_captcha_qa if (strlen($error)) { // okay, incorrect answer. Let's ask a new question. - // $this->new_attempt(); + $this->new_attempt(); $this->solved = false; return $error; } -- cgit v1.2.1 From 46e66c04011288a79ffb6232e4ccecb20240f2ce Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 3 Sep 2009 12:45:46 +0000 Subject: Some cleanup. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10091 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 175 ++++++++++++--------- 1 file changed, 97 insertions(+), 78 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 511706bb93..d71a781ae7 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -17,12 +17,11 @@ if (!defined('IN_PHPBB')) } global $table_prefix; + define('CAPTCHA_QUESTIONS_TABLE', $table_prefix . 'captcha_questions'); define('CAPTCHA_ANSWERS_TABLE', $table_prefix . 'captcha_answers'); define('CAPTCHA_QA_CONFIRM_TABLE', $table_prefix . 'qa_confirm'); - - /** * And now to something completely different. Let's make a captcha without extending the abstract class. * QA CAPTCHA sample implementation @@ -51,27 +50,37 @@ class phpbb_captcha_qa // load our language file $user->add_lang('captcha_qa'); + // read input $this->confirm_id = request_var('qa_confirm_id', ''); $this->answer = request_var('qa_answer', '', true); $this->type = (int) $type; $this->question_lang = $user->data['user_lang']; + // 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 ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($user->data['user_lang']) . '\''; + $sql = 'SELECT question_id + FROM ' . CAPTCHA_QUESTIONS_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'"; $result = $db->sql_query($sql, 3600); + while ($row = $db->sql_fetchrow($result)) { $this->question_ids[$row['question_id']] = $row['question_id']; } $db->sql_freeresult($result); + // fallback to the board default lang if (!sizeof($this->question_ids)) { $this->question_lang = $config['default_lang']; - $sql = 'SELECT question_id FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($config['default_lang']) . '\''; + + $sql = 'SELECT question_id + FROM ' . CAPTCHA_QUESTIONS_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; $result = $db->sql_query($sql, 7200); + while ($row = $db->sql_fetchrow($result)) { $this->question_ids[$row['question_id']] = $row['question_id']; @@ -93,6 +102,7 @@ class phpbb_captcha_qa function &get_instance() { $instance =& new phpbb_captcha_qa(); + return $instance; } @@ -108,31 +118,35 @@ class phpbb_captcha_qa include("$phpbb_root_path/includes/db/db_tools.$phpEx"); } $db_tool = new phpbb_db_tools($db); + return $db_tool->sql_table_exists(CAPTCHA_QUESTIONS_TABLE); } - + /** * API function - for the captcha to be available, it must have installed itself and there has to be at least one question in the board's default lang */ function is_available() { global $config, $db, $phpbb_root_path, $phpEx, $user; - + // load language file for pretty display in the ACP dropdown $user->add_lang('captcha_qa'); - + if (!phpbb_captcha_qa::is_installed()) { return false; } - $sql = 'SELECT COUNT(question_id) as count FROM ' . CAPTCHA_QUESTIONS_TABLE . ' WHERE lang_iso = \'' . $db->sql_escape($config['default_lang']) . '\''; + + $sql = 'SELECT COUNT(question_id) as count + FROM ' . CAPTCHA_QUESTIONS_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + return ((bool) $row['count']); } - /** * API function */ @@ -141,7 +155,6 @@ class phpbb_captcha_qa return true; } - /** * API function */ @@ -158,7 +171,6 @@ class phpbb_captcha_qa return 'phpbb_captcha_qa'; } - /** * API function - not needed as we don't display an image */ @@ -179,7 +191,7 @@ class phpbb_captcha_qa function get_template() { global $template; - + if ($this->is_solved()) { return false; @@ -218,6 +230,7 @@ class phpbb_captcha_qa $hidden_fields['qa_answer'] = $this->answer; } $hidden_fields['qa_confirm_id'] = $this->confirm_id; + return $hidden_fields; } @@ -230,7 +243,8 @@ class phpbb_captcha_qa $sql = 'SELECT DISTINCT c.session_id FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' c - LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id) + LEFT JOIN ' . SESSIONS_TABLE . ' s + ON (c.session_id = s.session_id) WHERE s.session_id IS NULL' . ((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type); $result = $db->sql_query($sql); @@ -238,6 +252,7 @@ class phpbb_captcha_qa if ($row = $db->sql_fetchrow($result)) { $sql_in = array(); + do { $sql_in[] = (string) $row['session_id']; @@ -274,8 +289,9 @@ class phpbb_captcha_qa include("$phpbb_root_path/includes/db/db_tools.$phpEx"); } $db_tool = new phpbb_db_tools($db); + $tables = array(CAPTCHA_QUESTIONS_TABLE, CAPTCHA_ANSWERS_TABLE, CAPTCHA_QA_CONFIRM_TABLE); - + $schemas = array( CAPTCHA_QUESTIONS_TABLE => array ( 'COLUMNS' => array( @@ -315,7 +331,7 @@ class phpbb_captcha_qa 'PRIMARY_KEY' => 'confirm_id', ), ); - + foreach($schemas as $table => $schema) { if (!$db_tool->sql_table_exists($table)) @@ -325,15 +341,15 @@ class phpbb_captcha_qa } } - /** * API function - see what has to be done to validate */ function validate() { global $config, $db, $user; - + $error = ''; + if (!$this->confirm_id) { $error = $user->lang['CONFIRM_QUESTION_WRONG']; @@ -356,6 +372,7 @@ class phpbb_captcha_qa // okay, incorrect answer. Let's ask a new question. $this->new_attempt(); $this->solved = false; + return $error; } else @@ -373,17 +390,17 @@ class phpbb_captcha_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( - 'confirm_id' => (string) $this->confirm_id, - 'session_id' => (string) $user->session_id, - 'lang_iso' => (string) $this->question_lang, - 'confirm_type' => (int) $this->type, - 'question_id' => (int) $this->question, + 'confirm_id' => (string) $this->confirm_id, + 'session_id' => (string) $user->session_id, + 'lang_iso' => (string) $this->question_lang, + 'confirm_type' => (int) $this->type, + 'question_id' => (int) $this->question, )); $db->sql_query($sql); - $this->load_answer(); + $this->load_answer(); } /** @@ -395,14 +412,13 @@ class phpbb_captcha_qa $this->question = (int) array_rand($this->question_ids); $this->solved = 0; - // compute $seed % 0x7fffffff - $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( - 'question' => (int) $this->question,)) . ' - WHERE - confirm_id = \'' . $db->sql_escape($this->confirm_id) . '\' - AND session_id = \'' . $db->sql_escape($user->session_id) . '\''; + $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . ' + SET question_id = ' . (int) $this->question . " + WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' + AND session_id = '" . $db->sql_escape($user->session_id) . "'"; $db->sql_query($sql); + $this->load_answer(); } @@ -416,15 +432,14 @@ class phpbb_captcha_qa // yah, I would prefer a stronger rand, but this should work $this->question = (int) array_rand($this->question_ids); $this->solved = 0; - // compute $seed % 0x7fffffff - - $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( - 'question_id' => (int) $this->question)) . ', - attempts = attempts + 1 - WHERE - confirm_id = \'' . $db->sql_escape($this->confirm_id) . '\' - AND session_id = \'' . $db->sql_escape($user->session_id) . '\''; + + $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . ' + SET question_id = ' . (int) $this->question . ", + attempts = attempts + 1 + WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' + AND session_id = '" . $db->sql_escape($user->session_id) . "'"; $db->sql_query($sql); + $this->load_answer(); } @@ -434,7 +449,7 @@ class phpbb_captcha_qa function load_answer() { global $db, $user; - + $sql = 'SELECT con.question_id, attempts, question_text, strict FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' con, ' . CAPTCHA_QUESTIONS_TABLE . " qes WHERE con.question_id = qes.question_id @@ -453,8 +468,10 @@ class phpbb_captcha_qa $this->attempts = $row['attempts']; $this->question_strict = $row['strict']; $this->question_text = $row['question_text']; + return true; } + return false; } @@ -464,23 +481,27 @@ class phpbb_captcha_qa function check_answer() { global $db; - + $answer = ($this->question_strict) ? request_var('qa_answer', '', true) : utf8_clean_string(request_var('qa_answer', '', true)); - + $sql = 'SELECT answer_text - FROM ' . CAPTCHA_ANSWERS_TABLE . ' - WHERE question_id = ' . (int) $this->question; + FROM ' . CAPTCHA_ANSWERS_TABLE . ' + WHERE question_id = ' . (int) $this->question; $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $solution = ($this->question_strict) ? $row['answer_text'] : utf8_clean_string($row['answer_text'] ); + $solution = ($this->question_strict) ? $row['answer_text'] : utf8_clean_string($row['answer_text']); + if ($solution === $answer) { $this->solved = true; + break; } } $db->sql_freeresult($result); + return $this->solved; } @@ -531,10 +552,10 @@ class phpbb_captcha_qa { $this->validate(); } + return (bool) $this->solved; } - - + /** * API function - The ACP backend, this marks the end of the easy methods */ @@ -550,6 +571,7 @@ class phpbb_captcha_qa { $this->install(); } + $module->tpl_name = 'captcha_qa_acp'; $module->page_title = 'ACP_VC_SETTINGS'; $form_key = 'acp_captcha'; @@ -558,14 +580,14 @@ class phpbb_captcha_qa $submit = request_var('submit', false); $question_id = request_var('question_id', 0); $action = request_var('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_class_name(); - + $template->assign_vars(array( - 'U_ACTION' => $module->u_action, - 'QUESTION_ID' => $question_id , - 'CLASS' => $this->get_class_name(), + 'U_ACTION' => $module->u_action, + 'QUESTION_ID' => $question_id , + 'CLASS' => $this->get_class_name(), )); // show the list? @@ -578,6 +600,7 @@ class phpbb_captcha_qa if (confirm_box(true)) { $this->acp_delete_question($question_id); + trigger_error($user->lang['QUESTION_DELETED'] . adm_back_link($list_url)); } else @@ -600,6 +623,7 @@ class phpbb_captcha_qa $input_lang = request_var('lang_iso', '', true); $input_strict = request_var('strict', false); $langs = $this->get_languages(); + foreach ($langs as $lang => $entry) { $template->assign_block_vars('langs', array( @@ -607,15 +631,17 @@ class phpbb_captcha_qa 'NAME' => $entry['name'], )); } - + $template->assign_vars(array( - 'U_LIST' => $list_url, + 'U_LIST' => $list_url, )); + if ($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( 'QUESTION_TEXT' => ($input_question) ? $input_question : $question['question_text'], 'LANG_ISO' => ($input_lang) ? $input_lang : $question['lang_iso'], @@ -630,18 +656,18 @@ class phpbb_captcha_qa } else { - $template->assign_vars(array( - 'QUESTION_TEXT' => $input_question, - 'LANG_ISO' => $input_lang, - 'STRICT' => $input_strict, - 'ANSWERS' => $input_answers, + 'QUESTION_TEXT' => $input_question, + 'LANG_ISO' => $input_lang, + 'STRICT' => $input_strict, + 'ANSWERS' => $input_answers, )); } - + if ($submit && check_form_key($form_key)) { $data = $this->acp_get_question_input(); + if (!$this->validate_input($data)) { $template->assign_vars(array( @@ -658,7 +684,7 @@ class phpbb_captcha_qa { $this->acp_add_question($data); } - + trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($list_url)); } } @@ -668,7 +694,6 @@ class phpbb_captcha_qa } } } - /** * This handles the list overview @@ -676,7 +701,7 @@ class phpbb_captcha_qa function acp_question_list(&$module) { global $db, $template; - + $sql = 'SELECT * FROM ' . CAPTCHA_QUESTIONS_TABLE; $result = $db->sql_query($sql); @@ -688,7 +713,7 @@ class phpbb_captcha_qa while ($row = $db->sql_fetchrow($result)) { $url = $module->u_action . "&question_id={$row['question_id']}&configure=1&select_captcha=" . $this->get_class_name() . '&'; - + $template->assign_block_vars('questions', array( 'QUESTION_TEXT' => $row['question_text'], 'QUESTION_ID' => $row['question_id'], @@ -737,8 +762,7 @@ class phpbb_captcha_qa return $question; } } - - + /** * Grab a question from input and bring it into a format the editor understands */ @@ -780,7 +804,7 @@ class phpbb_captcha_qa $cache->destroy('sql', CAPTCHA_QUESTIONS_TABLE); } - + /** * Insert a question. * param mixed $data : an array as created from acp_get_question_input or acp_get_question_data @@ -795,7 +819,7 @@ class phpbb_captcha_qa $question_ary['lang_id'] = $langs[$data['lang_iso']]['id']; unset($question_ary['answers']); - $sql = 'INSERT INTO ' . CAPTCHA_QUESTIONS_TABLE . $db->sql_build_array('INSERT', $question_ary); + $sql = 'INSERT INTO ' . CAPTCHA_QUESTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $question_ary); $db->sql_query($sql); $question_id = $db->sql_nextid(); @@ -804,7 +828,7 @@ class phpbb_captcha_qa $cache->destroy('sql', CAPTCHA_QUESTIONS_TABLE); } - + /** * Insert the answers. * param mixed $data : an array as created from acp_get_question_input or acp_get_question_data @@ -812,7 +836,7 @@ class phpbb_captcha_qa function acp_insert_answers($data, $question_id) { global $db, $cache; - + foreach ($data['answers'] as $answer) { $answer_ary = array( @@ -820,13 +844,12 @@ class phpbb_captcha_qa 'answer_text' => $answer, ); - $sql = 'INSERT INTO ' . CAPTCHA_ANSWERS_TABLE . $db->sql_build_array('INSERT', $answer_ary); + $sql = 'INSERT INTO ' . CAPTCHA_ANSWERS_TABLE . ' ' . $db->sql_build_array('INSERT', $answer_ary); $db->sql_query($sql); } $cache->destroy('sql', CAPTCHA_ANSWERS_TABLE); } - /** * Delete a question. @@ -846,8 +869,7 @@ class phpbb_captcha_qa $cache->destroy('sql', $tables); } - - + /** * Check if the entered data can be inserted/used * param mixed $data : an array as created from acp_get_question_input or acp_get_question_data @@ -873,7 +895,7 @@ class phpbb_captcha_qa return true; } - + /** * List the installed language packs */ @@ -881,13 +903,11 @@ class phpbb_captcha_qa { global $db; - $langs = array(); - $sql = 'SELECT * FROM ' . LANG_TABLE; - $result = $db->sql_query($sql); + $langs = array(); while ($row = $db->sql_fetchrow($result)) { $langs[$row['lang_iso']] = array( @@ -899,7 +919,6 @@ class phpbb_captcha_qa return $langs; } - } ?> \ No newline at end of file -- cgit v1.2.1 From 19086ba57289be4101131095aeeb615de2bc5639 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 3 Sep 2009 13:56:03 +0000 Subject: Some rewording, some typo fixes, some whitespace changes. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10093 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index d71a781ae7..15ad18ba87 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -95,7 +95,7 @@ class phpbb_captcha_qa $this->select_question(); } } - + /** * API function */ @@ -442,7 +442,7 @@ class phpbb_captcha_qa $this->load_answer(); } - + /** * Look up everything we need and populate the instance variables. */ @@ -812,7 +812,7 @@ class phpbb_captcha_qa function acp_add_question($data) { global $db, $cache; - + $langs = $this->get_languages(); $question_ary = $data; -- cgit v1.2.1 From 02b2cced5ae562145288a0dbe2bd534bf4f41b7f Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 7 Sep 2009 11:57:58 +0000 Subject: beautify q&a captcha a bit (only slightly) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10116 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 88 +++++++++++----------- 1 file changed, 44 insertions(+), 44 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 15ad18ba87..6f53e8c5ad 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -48,7 +48,7 @@ class phpbb_captcha_qa { global $config, $db, $user; - // load our language file + // load our language file $user->add_lang('captcha_qa'); // read input @@ -62,7 +62,7 @@ class phpbb_captcha_qa // try the user's lang first $sql = 'SELECT question_id FROM ' . CAPTCHA_QUESTIONS_TABLE . " - WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'"; + WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'"; $result = $db->sql_query($sql, 3600); while ($row = $db->sql_fetchrow($result)) @@ -78,7 +78,7 @@ class phpbb_captcha_qa $sql = 'SELECT question_id FROM ' . CAPTCHA_QUESTIONS_TABLE . " - WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; $result = $db->sql_query($sql, 7200); while ($row = $db->sql_fetchrow($result)) @@ -139,7 +139,7 @@ class phpbb_captcha_qa $sql = 'SELECT COUNT(question_id) as count FROM ' . CAPTCHA_QUESTIONS_TABLE . " - WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -283,7 +283,7 @@ class phpbb_captcha_qa function install() { global $db, $phpbb_root_path, $phpEx; - + if (!class_exists('phpbb_db_tools')) { include("$phpbb_root_path/includes/db/db_tools.$phpEx"); @@ -294,41 +294,41 @@ class phpbb_captcha_qa $schemas = array( CAPTCHA_QUESTIONS_TABLE => array ( - 'COLUMNS' => array( - 'question_id' => array('UINT', Null, 'auto_increment'), - 'strict' => array('BOOL', 0), - 'lang_id' => array('UINT', 0), - 'lang_iso' => array('VCHAR:30', ''), - 'question_text' => array('TEXT_UNI', ''), - ), - 'PRIMARY_KEY' => 'question_id', - 'KEYS' => array( - 'lang_iso' => array('INDEX', 'lang_iso'), - ), + 'COLUMNS' => array( + 'question_id' => array('UINT', Null, 'auto_increment'), + 'strict' => array('BOOL', 0), + 'lang_id' => array('UINT', 0), + 'lang_iso' => array('VCHAR:30', ''), + 'question_text' => array('TEXT_UNI', ''), + ), + 'PRIMARY_KEY' => 'question_id', + 'KEYS' => array( + 'lang_iso' => array('INDEX', 'lang_iso'), + ), ), CAPTCHA_ANSWERS_TABLE => array ( - 'COLUMNS' => array( - 'question_id' => array('UINT', 0), - 'answer_text' => array('STEXT_UNI', ''), - ), - 'KEYS' => array( - 'question_id' => array('INDEX', 'question_id'), - ), + 'COLUMNS' => array( + 'question_id' => array('UINT', 0), + 'answer_text' => array('STEXT_UNI', ''), + ), + 'KEYS' => array( + 'question_id' => array('INDEX', 'question_id'), + ), ), CAPTCHA_QA_CONFIRM_TABLE => array ( - 'COLUMNS' => array( - 'session_id' => array('CHAR:32', ''), - 'confirm_id' => array('CHAR:32', ''), - 'lang_iso' => array('VCHAR:30', ''), - 'question_id' => array('UINT', 0), - 'attempts' => array('UINT', 0), - 'confirm_type' => array('USINT', 0), - ), - 'KEYS' => array( - 'session_id' => array('INDEX', 'session_id'), - 'lookup' => array('INDEX', array('confirm_id', 'session_id', 'lang_iso')), - ), - 'PRIMARY_KEY' => 'confirm_id', + 'COLUMNS' => array( + 'session_id' => array('CHAR:32', ''), + 'confirm_id' => array('CHAR:32', ''), + 'lang_iso' => array('VCHAR:30', ''), + 'question_id' => array('UINT', 0), + 'attempts' => array('UINT', 0), + 'confirm_type' => array('USINT', 0), + ), + 'KEYS' => array( + 'session_id' => array('INDEX', 'session_id'), + 'lookup' => array('INDEX', array('confirm_id', 'session_id', 'lang_iso')), + ), + 'PRIMARY_KEY' => 'confirm_id', ), ); @@ -415,7 +415,7 @@ class phpbb_captcha_qa $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . ' SET question_id = ' . (int) $this->question . " - WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' + WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' AND session_id = '" . $db->sql_escape($user->session_id) . "'"; $db->sql_query($sql); @@ -436,7 +436,7 @@ class phpbb_captcha_qa $sql = 'UPDATE ' . CAPTCHA_QA_CONFIRM_TABLE . ' SET question_id = ' . (int) $this->question . ", attempts = attempts + 1 - WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' + WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' AND session_id = '" . $db->sql_escape($user->session_id) . "'"; $db->sql_query($sql); @@ -451,7 +451,7 @@ class phpbb_captcha_qa global $db, $user; $sql = 'SELECT con.question_id, attempts, question_text, strict - FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' con, ' . CAPTCHA_QUESTIONS_TABLE . " qes + FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' con, ' . CAPTCHA_QUESTIONS_TABLE . " 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) . "' @@ -520,7 +520,7 @@ class phpbb_captcha_qa } /** - * API function + * API function */ function get_attempt_count() { @@ -528,7 +528,7 @@ class phpbb_captcha_qa } /** - * API function + * API function */ function reset() { @@ -544,7 +544,7 @@ class phpbb_captcha_qa } /** - * API function + * API function */ function is_solved() { @@ -815,7 +815,7 @@ class phpbb_captcha_qa $langs = $this->get_languages(); $question_ary = $data; - + $question_ary['lang_id'] = $langs[$data['lang_iso']]['id']; unset($question_ary['answers']); @@ -862,7 +862,7 @@ class phpbb_captcha_qa foreach ($tables as $table) { - $sql = "DELETE FROM $table + $sql = "DELETE FROM $table WHERE question_id = $question_id"; $db->sql_query($sql); } -- cgit v1.2.1