|
From: Chris S. <too...@ph...> - 2009-08-15 19:57:33
|
Author: toonarmy
Date: Sat Aug 15 20:56:45 2009
New Revision: 9993
Log:
- #49775
- Some coding guidelines fixes
Modified:
branches/phpBB-3_0_0/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
Modified: branches/phpBB-3_0_0/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
==============================================================================
*** branches/phpBB-3_0_0/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php (original)
--- branches/phpBB-3_0_0/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php Sat Aug 15 20:56:45 2009
***************
*** 676,690 ****
{
global $db, $template;
! $sql = 'SELECT * FROM ' . CAPTCHA_QUESTIONS_TABLE;
$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'],
--- 676,692 ----
{
global $db, $template;
! $sql = 'SELECT *
! FROM ' . CAPTCHA_QUESTIONS_TABLE;
$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'],
***************
*** 704,734 ****
{
global $db;
-
if ($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
{
- $db->sql_freeresult($result);
return false;
}
$question['answers'] = array();
! $sql = 'SELECT * FROM ' . CAPTCHA_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;
}
-
}
--- 706,740 ----
{
global $db;
if ($question_id)
{
! $sql = 'SELECT *
! FROM ' . CAPTCHA_QUESTIONS_TABLE . '
! WHERE question_id = ' . $question_id;
$result = $db->sql_query($sql);
! $question = $db->sql_fetchrow($result);
! $db->sql_freeresult($result);
!
! if (!$question)
{
return false;
}
+
$question['answers'] = array();
!
! $sql = 'SELECT *
! FROM ' . CAPTCHA_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;
}
}
***************
*** 737,751 ****
*/
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;
}
--- 743,755 ----
*/
function acp_get_question_input()
{
$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,773 ****
*/
function acp_update_question($data, $question_id)
{
! global $db;
// easier to delete all answers than to figure out which to update
! $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";
$db->sql_query($sql);
$this->acp_insert_answers($data, $question_id);
}
/**
--- 759,783 ----
*/
function acp_update_question($data, $question_id)
{
! 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";
$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";
$db->sql_query($sql);
+
$this->acp_insert_answers($data, $question_id);
+
+ $cache->destroy('sql', CAPTCHA_QUESTIONS_TABLE);
}
/**
***************
*** 776,792 ****
*/
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 " . 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);
}
/**
--- 786,807 ----
*/
function acp_add_question($data)
{
! 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);
$db->sql_query($sql);
+
$question_id = $db->sql_nextid();
+
$this->acp_insert_answers($data, $question_id);
+
+ $cache->destroy('sql', CAPTCHA_QUESTIONS_TABLE);
}
/**
***************
*** 795,811 ****
*/
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 " . CAPTCHA_ANSWERS_TABLE . $db->sql_build_array('INSERT', $answer_ary);
$db->sql_query($sql);
}
}
--- 810,829 ----
*/
function acp_insert_answers($data, $question_id)
{
! global $db, $cache;
! 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);
$db->sql_query($sql);
}
+
+ $cache->destroy('sql', CAPTCHA_ANSWERS_TABLE);
}
***************
*** 814,827 ****
*/
function acp_delete_question($question_id)
{
! global $db;
!
$tables = array(CAPTCHA_QUESTIONS_TABLE, CAPTCHA_ANSWERS_TABLE);
! foreach($tables as $table)
{
! $sql = "DELETE FROM $table WHERE question_id = $question_id";
$db->sql_query($sql);
}
}
--- 832,849 ----
*/
function acp_delete_question($question_id)
{
! global $db, $cache;
!
$tables = array(CAPTCHA_QUESTIONS_TABLE, CAPTCHA_ANSWERS_TABLE);
!
! foreach ($tables as $table)
{
! $sql = "DELETE FROM $table
! WHERE question_id = $question_id";
$db->sql_query($sql);
}
+
+ $cache->destroy('sql', $tables);
}
***************
*** 832,837 ****
--- 854,860 ----
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,851 ****
{
return false;
}
if (!isset($langs[$question_data['lang_iso']]) ||
!$question_data['question_text'] ||
!sizeof($question_data['answers']))
{
return false;
}
!
return true;
}
--- 862,875 ----
{
return false;
}
+
if (!isset($langs[$question_data['lang_iso']]) ||
!$question_data['question_text'] ||
!sizeof($question_data['answers']))
{
return false;
}
!
return true;
}
***************
*** 855,872 ****
function get_languages()
{
global $db;
!
$langs = array();
! $sql = 'SELECT * FROM ' . LANG_TABLE;
$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;
}
--- 879,901 ----
function get_languages()
{
global $db;
!
$langs = array();
!
! $sql = 'SELECT *
! FROM ' . LANG_TABLE;
!
$result = $db->sql_query($sql);
!
! while ($row = $db->sql_fetchrow($result))
{
$langs[$row['lang_iso']] = array(
'name' => $row['lang_local_name'],
! 'id' => (int) $row['lang_id'],
);
}
$db->sql_freeresult($result);
+
return $langs;
}
|