includes/acp/acp_captcha.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Wed, 07 Mar 2012 16:41:10 +0400
changeset 0 ceef6d64c21d
permissions -rw-r--r--
Added phpBB-3.0.10
     1 <?php
     2 /**
     3 *
     4 * @package acp
     5 * @version $Id$
     6 * @copyright (c) 2005 phpBB Group
     7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
     8 */
     9 
    10 /**
    11 * @ignore
    12 */
    13 if (!defined('IN_PHPBB'))
    14 {
    15 	exit;
    16 }
    17 
    18 /**
    19 * @package acp
    20 */
    21 class acp_captcha
    22 {
    23 	var $u_action;
    24 
    25 	function main($id, $mode)
    26 	{
    27 		global $db, $user, $auth, $template;
    28 		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
    29 
    30 		$user->add_lang('acp/board');
    31 
    32 		include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
    33 		$captchas = phpbb_captcha_factory::get_captcha_types();
    34 
    35 		$selected = request_var('select_captcha', $config['captcha_plugin']);
    36 		$selected = (isset($captchas['available'][$selected]) || isset($captchas['unavailable'][$selected])) ? $selected : $config['captcha_plugin'];
    37 		$configure = request_var('configure', false);
    38 
    39 
    40 		// Oh, they are just here for the view
    41 		if (isset($_GET['captcha_demo']))
    42 		{
    43 			$this->deliver_demo($selected);
    44 		}
    45 
    46 		// Delegate
    47 		if ($configure)
    48 		{
    49 			$config_captcha =& phpbb_captcha_factory::get_instance($selected);
    50 			$config_captcha->acp_page($id, $this);
    51 		}
    52 		else
    53 		{
    54 			$config_vars = array(
    55 				'enable_confirm'		=> array('tpl' => 'REG_ENABLE', 'default' => false),
    56 				'enable_post_confirm'	=> array('tpl' => 'POST_ENABLE', 'default' => false),
    57 				'confirm_refresh'		=> array('tpl' => 'CONFIRM_REFRESH', 'default' => false),
    58 				'max_reg_attempts'		=> array('tpl' => 'REG_LIMIT', 'default' => 0),
    59 				'max_login_attempts'		=> array('tpl' => 'MAX_LOGIN_ATTEMPTS', 'default' => 0),
    60 			);
    61 
    62 			$this->tpl_name = 'acp_captcha';
    63 			$this->page_title = 'ACP_VC_SETTINGS';
    64 			$form_key = 'acp_captcha';
    65 			add_form_key($form_key);
    66 
    67 			$submit = request_var('main_submit', false);
    68 
    69 			if ($submit && check_form_key($form_key))
    70 			{
    71 				foreach ($config_vars as $config_var => $options)
    72 				{
    73 					set_config($config_var, request_var($config_var, $options['default']));
    74 				}
    75 
    76 				if ($selected !== $config['captcha_plugin'])
    77 				{
    78 					// sanity check
    79 					if (isset($captchas['available'][$selected]))
    80 					{
    81 						$old_captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
    82 						$old_captcha->uninstall();
    83 
    84 						set_config('captcha_plugin', $selected);
    85 						$new_captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
    86 						$new_captcha->install();
    87 
    88 						add_log('admin', 'LOG_CONFIG_VISUAL');
    89 					}
    90 					else
    91 					{
    92 						trigger_error($user->lang['CAPTCHA_UNAVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
    93 					}
    94 				}
    95 				trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
    96 			}
    97 			else if ($submit)
    98 			{
    99 				trigger_error($user->lang['FORM_INVALID'] . adm_back_link(), E_USER_WARNING);
   100 			}
   101 			else
   102 			{
   103 				$captcha_select = '';
   104 				foreach ($captchas['available'] as $value => $title)
   105 				{
   106 					$current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
   107 					$captcha_select .= '<option value="' . $value . '"' . $current . '>' . $user->lang[$title] . '</option>';
   108 				}
   109 
   110 				foreach ($captchas['unavailable'] as $value => $title)
   111 				{
   112 					$current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
   113 					$captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option">' . $user->lang[$title] . '</option>';
   114 				}
   115 
   116 				$demo_captcha =& phpbb_captcha_factory::get_instance($selected);
   117 
   118 				foreach ($config_vars as $config_var => $options)
   119 				{
   120 					$template->assign_var($options['tpl'], (isset($_POST[$config_var])) ? request_var($config_var, $options['default']) : $config[$config_var]) ;
   121 				}
   122 
   123 				$template->assign_vars(array(
   124 					'CAPTCHA_PREVIEW_TPL'	=> $demo_captcha->get_demo_template($id),
   125 					'S_CAPTCHA_HAS_CONFIG'	=> $demo_captcha->has_config(),
   126 					'CAPTCHA_SELECT'		=> $captcha_select,
   127 				));
   128 			}
   129 		}
   130 	}
   131 
   132 	/**
   133 	* Entry point for delivering image CAPTCHAs in the ACP.
   134 	*/
   135 	function deliver_demo($selected)
   136 	{
   137 		global $db, $user, $config;
   138 
   139 		$captcha =& phpbb_captcha_factory::get_instance($selected);
   140 		$captcha->init(CONFIRM_REG);
   141 		$captcha->execute_demo();
   142 
   143 		garbage_collection();
   144 		exit_handler();
   145 	}
   146 }
   147 
   148 ?>