1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/acp/acp_captcha.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,148 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*/
1.12 +
1.13 +/**
1.14 +* @ignore
1.15 +*/
1.16 +if (!defined('IN_PHPBB'))
1.17 +{
1.18 + exit;
1.19 +}
1.20 +
1.21 +/**
1.22 +* @package acp
1.23 +*/
1.24 +class acp_captcha
1.25 +{
1.26 + var $u_action;
1.27 +
1.28 + function main($id, $mode)
1.29 + {
1.30 + global $db, $user, $auth, $template;
1.31 + global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
1.32 +
1.33 + $user->add_lang('acp/board');
1.34 +
1.35 + include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
1.36 + $captchas = phpbb_captcha_factory::get_captcha_types();
1.37 +
1.38 + $selected = request_var('select_captcha', $config['captcha_plugin']);
1.39 + $selected = (isset($captchas['available'][$selected]) || isset($captchas['unavailable'][$selected])) ? $selected : $config['captcha_plugin'];
1.40 + $configure = request_var('configure', false);
1.41 +
1.42 +
1.43 + // Oh, they are just here for the view
1.44 + if (isset($_GET['captcha_demo']))
1.45 + {
1.46 + $this->deliver_demo($selected);
1.47 + }
1.48 +
1.49 + // Delegate
1.50 + if ($configure)
1.51 + {
1.52 + $config_captcha =& phpbb_captcha_factory::get_instance($selected);
1.53 + $config_captcha->acp_page($id, $this);
1.54 + }
1.55 + else
1.56 + {
1.57 + $config_vars = array(
1.58 + 'enable_confirm' => array('tpl' => 'REG_ENABLE', 'default' => false),
1.59 + 'enable_post_confirm' => array('tpl' => 'POST_ENABLE', 'default' => false),
1.60 + 'confirm_refresh' => array('tpl' => 'CONFIRM_REFRESH', 'default' => false),
1.61 + 'max_reg_attempts' => array('tpl' => 'REG_LIMIT', 'default' => 0),
1.62 + 'max_login_attempts' => array('tpl' => 'MAX_LOGIN_ATTEMPTS', 'default' => 0),
1.63 + );
1.64 +
1.65 + $this->tpl_name = 'acp_captcha';
1.66 + $this->page_title = 'ACP_VC_SETTINGS';
1.67 + $form_key = 'acp_captcha';
1.68 + add_form_key($form_key);
1.69 +
1.70 + $submit = request_var('main_submit', false);
1.71 +
1.72 + if ($submit && check_form_key($form_key))
1.73 + {
1.74 + foreach ($config_vars as $config_var => $options)
1.75 + {
1.76 + set_config($config_var, request_var($config_var, $options['default']));
1.77 + }
1.78 +
1.79 + if ($selected !== $config['captcha_plugin'])
1.80 + {
1.81 + // sanity check
1.82 + if (isset($captchas['available'][$selected]))
1.83 + {
1.84 + $old_captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
1.85 + $old_captcha->uninstall();
1.86 +
1.87 + set_config('captcha_plugin', $selected);
1.88 + $new_captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
1.89 + $new_captcha->install();
1.90 +
1.91 + add_log('admin', 'LOG_CONFIG_VISUAL');
1.92 + }
1.93 + else
1.94 + {
1.95 + trigger_error($user->lang['CAPTCHA_UNAVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
1.96 + }
1.97 + }
1.98 + trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
1.99 + }
1.100 + else if ($submit)
1.101 + {
1.102 + trigger_error($user->lang['FORM_INVALID'] . adm_back_link(), E_USER_WARNING);
1.103 + }
1.104 + else
1.105 + {
1.106 + $captcha_select = '';
1.107 + foreach ($captchas['available'] as $value => $title)
1.108 + {
1.109 + $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
1.110 + $captcha_select .= '<option value="' . $value . '"' . $current . '>' . $user->lang[$title] . '</option>';
1.111 + }
1.112 +
1.113 + foreach ($captchas['unavailable'] as $value => $title)
1.114 + {
1.115 + $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
1.116 + $captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option">' . $user->lang[$title] . '</option>';
1.117 + }
1.118 +
1.119 + $demo_captcha =& phpbb_captcha_factory::get_instance($selected);
1.120 +
1.121 + foreach ($config_vars as $config_var => $options)
1.122 + {
1.123 + $template->assign_var($options['tpl'], (isset($_POST[$config_var])) ? request_var($config_var, $options['default']) : $config[$config_var]) ;
1.124 + }
1.125 +
1.126 + $template->assign_vars(array(
1.127 + 'CAPTCHA_PREVIEW_TPL' => $demo_captcha->get_demo_template($id),
1.128 + 'S_CAPTCHA_HAS_CONFIG' => $demo_captcha->has_config(),
1.129 + 'CAPTCHA_SELECT' => $captcha_select,
1.130 + ));
1.131 + }
1.132 + }
1.133 + }
1.134 +
1.135 + /**
1.136 + * Entry point for delivering image CAPTCHAs in the ACP.
1.137 + */
1.138 + function deliver_demo($selected)
1.139 + {
1.140 + global $db, $user, $config;
1.141 +
1.142 + $captcha =& phpbb_captcha_factory::get_instance($selected);
1.143 + $captcha->init(CONFIRM_REG);
1.144 + $captcha->execute_demo();
1.145 +
1.146 + garbage_collection();
1.147 + exit_handler();
1.148 + }
1.149 +}
1.150 +
1.151 +?>
1.152 \ No newline at end of file