aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/captcha/plugins/captcha_abstract.php
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2008-09-22 17:51:43 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2008-09-22 17:51:43 +0000
commitaa9dbcec3c95efda6b3087c4bc6a48a0cef48774 (patch)
tree55da5b5b2da384919b8f315bbb54c1dd002e0de4 /phpBB/includes/captcha/plugins/captcha_abstract.php
parent08428f8fa133c43c05066ff0e307abe01d943fa0 (diff)
downloadforums-aa9dbcec3c95efda6b3087c4bc6a48a0cef48774.tar
forums-aa9dbcec3c95efda6b3087c4bc6a48a0cef48774.tar.gz
forums-aa9dbcec3c95efda6b3087c4bc6a48a0cef48774.tar.bz2
forums-aa9dbcec3c95efda6b3087c4bc6a48a0cef48774.tar.xz
forums-aa9dbcec3c95efda6b3087c4bc6a48a0cef48774.zip
short php open tags should not be used. :) A lot of users (including myself) do not allow them.
git-svn-id: file:///svn/phpbb/trunk@8907 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/captcha/plugins/captcha_abstract.php')
-rw-r--r--phpBB/includes/captcha/plugins/captcha_abstract.php91
1 files changed, 46 insertions, 45 deletions
diff --git a/phpBB/includes/captcha/plugins/captcha_abstract.php b/phpBB/includes/captcha/plugins/captcha_abstract.php
index a3ed706aeb..1b511b9c49 100644
--- a/phpBB/includes/captcha/plugins/captcha_abstract.php
+++ b/phpBB/includes/captcha/plugins/captcha_abstract.php
@@ -1,8 +1,8 @@
-<?
+<?php
/**
*
* @package VC
-* @version $Id: $
+* @version $Id$
* @copyright (c) 2006 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
@@ -33,33 +33,33 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
function init($type)
{
global $config, $db, $user;
-
+
// read input
$this->confirm_id = request_var('confirm_id', '');
$this->confirm_code = request_var('confirm_code', '');
$this->type = (int) $type;
-
+
if (!strlen($this->confirm_id))
{
// we have no confirm ID, better get ready to display something
$this->generate_code();
}
}
-
+
function execute_demo()
{
global $user;
-
+
$this->code = gen_rand_string(mt_rand(5, 8));
$this->seed = hexdec(substr(unique_id(), 4, 10));
-
+
// compute $seed % 0x7fffffff
$this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
-
+
captcha::execute($this->code, $this->seed);
}
-
-
+
+
function execute()
{
if (empty($this->code))
@@ -72,28 +72,28 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
}
captcha::execute($this->code, $this->seed);
}
-
-
+
+
function get_template()
{
global $config, $user, $template;
-
+
$template->set_filenames(array(
'captcha' => 'captcha_default.html')
);
-
+
$template->assign_vars(array(
'CONFIRM_IMAGE' => append_sid('ucp', 'mode=confirm&amp;confirm_id=' . $this->confirm_id . '&amp;type=' . $this->type),
'CONFIRM_ID' => $this->confirm_id,
));
-
+
return $template->assign_display('captcha');
}
-
+
function get_demo_template($id)
{
global $config, $user, $template;
-
+
$template->set_filenames(array(
'captcha_demo' => 'captcha_default_acp_demo.html')
);
@@ -102,14 +102,14 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
'CONFIRM_IMAGE' => append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, 'captcha_demo=1&amp;mode=visual&amp;i=' . $id . '&amp;select_captcha=' . $this->get_class_name()),
'CONFIRM_ID' => $this->confirm_id,
));
-
+
return $template->assign_display('captcha_demo');
}
-
+
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)
{
@@ -118,7 +118,7 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
$hidden_fields['confirm_id'] = $this->confirm_id;
return $hidden_fields;
}
-
+
static function garbage_collect($type)
{
global $db, $config;
@@ -148,23 +148,23 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
}
$db->sql_freeresult($result);
}
-
+
function uninstall()
{
self::garbage_collect(0);
}
-
+
function install()
{
return;
}
-
+
function validate()
{
global $config, $db, $user;
-
+
$this->confirm_code = request_var('confirm_code', '');
-
+
if (!$this->confirm_id)
{
$error = $user->lang['CONFIRM_CODE_WRONG'];
@@ -181,7 +181,7 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
$error = $user->lang['CONFIRM_CODE_WRONG'];
}
}
-
+
if (strlen($error))
{
// okay, inorect answer. Let's ask a new question
@@ -193,15 +193,15 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
return false;
}
}
-
-
+
+
/**
* The old way to generate code, suitable for GD and non-GD. Resets the internal state.
*/
protected function generate_code()
{
global $db, $user;
-
+
$this->code = gen_rand_string(mt_rand(5, 8));
$this->confirm_id = md5(unique_id($user->ip));
$this->seed = hexdec(substr(unique_id(), 4, 10));
@@ -218,9 +218,9 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
);
$db->sql_query($sql);
}
-
+
/**
- * Look up everything we need for painting&checking.
+ * Look up everything we need for painting&checking.
*/
protected function load_code()
{
@@ -240,13 +240,13 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
return true;
}
return false;
-
+
}
-
+
protected function check_code()
{
global $db;
-
+
if (empty($this->code))
{
if (!$this->load_code())
@@ -256,22 +256,22 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
}
return (strcasecmp($this->code, $this->confirm_code) === 0);
}
-
+
protected function delete_code()
{
global $db, $user;
-
+
$sql = 'DELETE FROM ' . 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()
{
global $db, $user;
-
+
$sql = 'SELECT COUNT(session_id) AS attempts
FROM ' . CONFIRM_TABLE . "
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
@@ -279,23 +279,24 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
$result = $db->sql_query($sql);
$attempts = (int) $db->sql_fetchfield('attempts');
$db->sql_freeresult($result);
-
+
return $attempts;
}
-
-
+
+
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->generate_code();
}
-
+
}
+?> \ No newline at end of file