confirm_id = request_var('confirm_id', ''); $this->confirm_code = request_var('confirm_code', 0); $this->type = (int) $type; $this->images = array("'pencil'", "'scissors'", "'clock'", "'heart'", "'note'"); $user->add_lang('mods/captcha_fancy_jquery'); // Okay, if there is a confirm_id, we try to load that confirm's state if (!strlen($this->confirm_id) || !$this->load_code()) { // We have no valid confirm ID, better get ready to ask something $this->set_captcha(); } } /** * API Function * */ function &get_instance() { $instance =& new phpbb_fancy_jquery(); return $instance; } /** * API Function * */ function is_available() { global $user; $user->add_lang('mods/captcha_fancy_jquery'); return true; } /** * API Function * */ function get_name() { return 'CAPTCHA_FANCY_JQUERY'; } /** * API Function * */ function get_class_name() { return 'phpbb_fancy_jquery'; } /** * API Function * */ function acp_page($id, &$module) { global $user; trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action)); } /** * API Function * */ function execute_demo() { } /** * API Function * */ function execute() { } /** * API Function * */ function get_template() { global $config, $user, $template, $phpbb_root_path, $phpEx; $explain = $user->lang(($this->type != CONFIRM_POST) ? 'CONFIRM_EXPLAIN' : 'POST_CONFIRM_EXPLAIN', '', ''); $template->assign_vars(array( 'CONFIRM_ID' => $this->confirm_id, 'IMAGES' => implode(', ', $this->images), 'T_IMAGES_PATH' => "{$phpbb_root_path}images/", 'T_THEME_PATH' => "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme', 'U_REQUEST_URL' => append_sid($phpbb_root_path . 'captcha_request.' . $phpEx), 'L_CONFIRM_EXPLAIN' => $explain, 'S_TYPE' => $this->type, )); return 'captcha_fancy_jquery.html'; } /** * API Function * */ function get_demo_template() { global $template, $phpbb_root_path, $user; // Images that will be used in the captcha. We use double and single quotes here because it will get passed into the Javascript. $this->images = array("'pencil'", "'scissors'", "'clock'", "'heart'", "'note'"); $template->assign_vars(array( 'T_IMAGES_PATH' => "{$phpbb_root_path}images/", 'T_THEME_PATH' => "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme', 'T_TEMPLATE_PATH' => "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/template', 'S_TYPE' => $this->type, )); return 'captcha_fancy_jquery_acp.html'; } /** * API function */ function reset() { global $db, $user; $sql = 'DELETE FROM ' . 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->set_captcha(); } /** * API Function * */ function get_hidden_fields() { $hidden_fields = array(); // this is required for postig.php - otherwise we would forget about the captcha being already solved if ($this->solved) { $hidden_fields['confirm_code'] = $this->confirm_code; } $hidden_fields['confirm_id'] = $this->confirm_id; return $hidden_fields; } /** * API Function * */ function uninstall() { $this->garbage_collect(0); } /** * API Function * */ function install() { return; } /** * Validates submitted captcha * * @return bool */ function validate() { global $user; $error = ''; if (!$this->confirm_id) { $error = $user->lang['DRAG_OBJECT_FAILED']; } else { if ($this->check_code()) { // $this->delete_code(); commented out to allow posting.php to repeat the question $this->solved = true; } else { $error = $user->lang['DRAG_OBJECT_FAILED']; } } if (strlen($error)) { // okay, incorrect answer. Let's ask a new question. $this->new_attempt(); return $error; } else { return false; } } /** * New Question, if desired. */ function new_attempt() { global $db, $user; $this->code = mt_rand(0, (sizeof($this->images) - 1)); $this->seed = hexdec(substr(unique_id(), 4, 10)); $this->solved = 0; // compute $seed % 0x7fffffff $this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff); $sql = 'UPDATE ' . CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( 'code' => (string) $this->code, 'seed' => (int) $this->seed)) . " , 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); } /** * Stores data for what we will check. */ function set_captcha() { global $db, $user; $this->code = mt_rand(0, (sizeof($this->images) - 1)); $this->confirm_id = md5(unique_id($user->ip)); $this->seed = hexdec(substr(unique_id(), 4, 10)); $this->solved = 0; // compute $seed % 0x7fffffff $this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff); $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array( 'confirm_id' => (string) $this->confirm_id, 'session_id' => (string) $user->session_id, 'confirm_type' => (int) $this->type, 'code' => (string) $this->code, 'seed' => (int) $this->seed) ); $db->sql_query($sql); } /** * Only used for the AJAX call. * * @return image code * */ function get_code() { $this->confirm_id = request_var('confirm_id', ''); $this->type = request_var('type', 0); $this->load_code(); return $this->code; } } ?>