includes/captcha/plugins/phpbb_captcha_gd_plugin.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/captcha/plugins/phpbb_captcha_gd_plugin.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,165 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package VC
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2006, 2008 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* Placeholder for autoload
    1.24 +*/
    1.25 +if (!class_exists('phpbb_default_captcha'))
    1.26 +{
    1.27 +	include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
    1.28 +}
    1.29 +
    1.30 +/**
    1.31 +* @package VC
    1.32 +*/
    1.33 +class phpbb_captcha_gd extends phpbb_default_captcha
    1.34 +{
    1.35 +
    1.36 +	var $captcha_vars = array(
    1.37 +		'captcha_gd_x_grid'				=> 'CAPTCHA_GD_X_GRID',
    1.38 +		'captcha_gd_y_grid'				=> 'CAPTCHA_GD_Y_GRID',
    1.39 +		'captcha_gd_foreground_noise'	=> 'CAPTCHA_GD_FOREGROUND_NOISE',
    1.40 +//		'captcha_gd'					=> 'CAPTCHA_GD_PREVIEWED',
    1.41 +		'captcha_gd_wave'				=> 'CAPTCHA_GD_WAVE',
    1.42 +		'captcha_gd_3d_noise'			=> 'CAPTCHA_GD_3D_NOISE',
    1.43 +		'captcha_gd_fonts'				=> 'CAPTCHA_GD_FONTS',
    1.44 +	);
    1.45 +
    1.46 +	function phpbb_captcha_gd()
    1.47 +	{
    1.48 +		global $phpbb_root_path, $phpEx;
    1.49 +
    1.50 +		if (!class_exists('captcha'))
    1.51 +		{
    1.52 +			include($phpbb_root_path . 'includes/captcha/captcha_gd.' . $phpEx);
    1.53 +		}
    1.54 +	}
    1.55 +
    1.56 +	function &get_instance()
    1.57 +	{
    1.58 +		$instance =& new phpbb_captcha_gd();
    1.59 +		return $instance;
    1.60 +	}
    1.61 +
    1.62 +	function is_available()
    1.63 +	{
    1.64 +		global $phpbb_root_path, $phpEx;
    1.65 +
    1.66 +		if (@extension_loaded('gd'))
    1.67 +		{
    1.68 +			return true;
    1.69 +		}
    1.70 +
    1.71 +		if (!function_exists('can_load_dll'))
    1.72 +		{
    1.73 +			include($phpbb_root_path . 'includes/functions_install.' . $phpEx);
    1.74 +		}
    1.75 +
    1.76 +		return can_load_dll('gd');
    1.77 +	}
    1.78 +
    1.79 +	/**
    1.80 +	*  API function
    1.81 +	*/
    1.82 +	function has_config()
    1.83 +	{
    1.84 +		return true;
    1.85 +	}
    1.86 +
    1.87 +	function get_name()
    1.88 +	{
    1.89 +		return 'CAPTCHA_GD';
    1.90 +	}
    1.91 +
    1.92 +	function get_class_name()
    1.93 +	{
    1.94 +		return 'phpbb_captcha_gd';
    1.95 +	}
    1.96 +
    1.97 +	function acp_page($id, &$module)
    1.98 +	{
    1.99 +		global $db, $user, $auth, $template;
   1.100 +		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
   1.101 +
   1.102 +		$user->add_lang('acp/board');
   1.103 +
   1.104 +		$config_vars = array(
   1.105 +			'enable_confirm'		=> 'REG_ENABLE',
   1.106 +			'enable_post_confirm'	=> 'POST_ENABLE',
   1.107 +			'confirm_refresh'		=> 'CONFIRM_REFRESH',
   1.108 +			'captcha_gd'			=> 'CAPTCHA_GD',
   1.109 +		);
   1.110 +
   1.111 +		$module->tpl_name = 'captcha_gd_acp';
   1.112 +		$module->page_title = 'ACP_VC_SETTINGS';
   1.113 +		$form_key = 'acp_captcha';
   1.114 +		add_form_key($form_key);
   1.115 +
   1.116 +		$submit = request_var('submit', '');
   1.117 +
   1.118 +		if ($submit && check_form_key($form_key))
   1.119 +		{
   1.120 +			$captcha_vars = array_keys($this->captcha_vars);
   1.121 +			foreach ($captcha_vars as $captcha_var)
   1.122 +			{
   1.123 +				$value = request_var($captcha_var, 0);
   1.124 +				if ($value >= 0)
   1.125 +				{
   1.126 +					set_config($captcha_var, $value);
   1.127 +				}
   1.128 +			}
   1.129 +
   1.130 +			add_log('admin', 'LOG_CONFIG_VISUAL');
   1.131 +			trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action));
   1.132 +		}
   1.133 +		else if ($submit)
   1.134 +		{
   1.135 +			trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action));
   1.136 +		}
   1.137 +		else
   1.138 +		{
   1.139 +			foreach ($this->captcha_vars as $captcha_var => $template_var)
   1.140 +			{
   1.141 +				$var = (isset($_REQUEST[$captcha_var])) ? request_var($captcha_var, 0) : $config[$captcha_var];
   1.142 +				$template->assign_var($template_var, $var);
   1.143 +			}
   1.144 +
   1.145 +			$template->assign_vars(array(
   1.146 +				'CAPTCHA_PREVIEW'	=> $this->get_demo_template($id),
   1.147 +				'CAPTCHA_NAME'		=> $this->get_class_name(),
   1.148 +				'U_ACTION'			=> $module->u_action,
   1.149 +			));
   1.150 +		}
   1.151 +	}
   1.152 +
   1.153 +	function execute_demo()
   1.154 +	{
   1.155 +		global $config;
   1.156 +
   1.157 +		$config_old = $config;
   1.158 +		foreach ($this->captcha_vars as $captcha_var => $template_var)
   1.159 +		{
   1.160 +				$config[$captcha_var] = request_var($captcha_var, (int) $config[$captcha_var]);
   1.161 +		}
   1.162 +		parent::execute_demo();
   1.163 +		$config = $config_old;
   1.164 +	}
   1.165 +
   1.166 +}
   1.167 +
   1.168 +?>
   1.169 \ No newline at end of file