[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/includes/acp/ -> acp_captcha.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  class acp_captcha
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $user, $template, $phpbb_log, $request;
  29          global $config, $phpbb_container;
  30  
  31          $user->add_lang('acp/board');
  32  
  33          /* @var $factory \phpbb\captcha\factory */
  34          $factory = $phpbb_container->get('captcha.factory');
  35          $captchas = $factory->get_captcha_types();
  36  
  37          $selected = $request->variable('select_captcha', $config['captcha_plugin']);
  38          $selected = (isset($captchas['available'][$selected]) || isset($captchas['unavailable'][$selected])) ? $selected : $config['captcha_plugin'];
  39          $configure = $request->variable('configure', false);
  40  
  41          // Oh, they are just here for the view
  42          if (isset($_GET['captcha_demo']))
  43          {
  44              $this->deliver_demo($selected);
  45          }
  46  
  47          // Delegate
  48          if ($configure)
  49          {
  50              $config_captcha = $factory->get_instance($selected);
  51              $config_captcha->acp_page($id, $this);
  52          }
  53          else
  54          {
  55              $config_vars = array(
  56                  'enable_confirm'        => array(
  57                      'tpl'        => 'REG_ENABLE',
  58                      'default'    => false,
  59                      'validate'    => 'bool',
  60                      'lang'        => 'VISUAL_CONFIRM_REG',
  61                  ),
  62                  'enable_post_confirm'    => array(
  63                      'tpl'        => 'POST_ENABLE',
  64                      'default'    => false,
  65                      'validate'    => 'bool',
  66                      'lang'        => 'VISUAL_CONFIRM_POST',
  67                  ),
  68                  'confirm_refresh'        => array(
  69                      'tpl'        => 'CONFIRM_REFRESH',
  70                      'default'    => false,
  71                      'validate'    => 'bool',
  72                      'lang'        => 'VISUAL_CONFIRM_REFRESH',
  73                  ),
  74                  'max_reg_attempts'        => array(
  75                      'tpl'        => 'REG_LIMIT',
  76                      'default'    => 0,
  77                      'validate'    => 'int:0:99999',
  78                      'lang'        => 'REG_LIMIT',
  79                  ),
  80                  'max_login_attempts'    => array(
  81                      'tpl'        => 'MAX_LOGIN_ATTEMPTS',
  82                      'default'    => 0,
  83                      'validate'    => 'int:0:99999',
  84                      'lang'        => 'MAX_LOGIN_ATTEMPTS',
  85                  ),
  86              );
  87  
  88              $this->tpl_name = 'acp_captcha';
  89              $this->page_title = 'ACP_VC_SETTINGS';
  90              $form_key = 'acp_captcha';
  91              add_form_key($form_key);
  92  
  93              $submit = $request->variable('main_submit', false);
  94              $error = $cfg_array = array();
  95  
  96              if ($submit)
  97              {
  98                  foreach ($config_vars as $config_var => $options)
  99                  {
 100                      $cfg_array[$config_var] = $request->variable($config_var, $options['default']);
 101                  }
 102                  validate_config_vars($config_vars, $cfg_array, $error);
 103  
 104                  if (!check_form_key($form_key))
 105                  {
 106                      $error[] = $user->lang['FORM_INVALID'];
 107                  }
 108                  if ($error)
 109                  {
 110                      $submit = false;
 111                  }
 112              }
 113  
 114              if ($submit)
 115              {
 116                  foreach ($cfg_array as $key => $value)
 117                  {
 118                      $config->set($key, $value);
 119                  }
 120  
 121                  if ($selected !== $config['captcha_plugin'])
 122                  {
 123                      // sanity check
 124                      if (isset($captchas['available'][$selected]))
 125                      {
 126                          $old_captcha = $factory->get_instance($config['captcha_plugin']);
 127                          $old_captcha->uninstall();
 128  
 129                          $config->set('captcha_plugin', $selected);
 130                          $new_captcha = $factory->get_instance($config['captcha_plugin']);
 131                          $new_captcha->install();
 132  
 133                          $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_VISUAL');
 134                      }
 135                      else
 136                      {
 137                          trigger_error($user->lang['CAPTCHA_UNAVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
 138                      }
 139                  }
 140                  trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
 141              }
 142              else
 143              {
 144                  $captcha_select = '';
 145                  foreach ($captchas['available'] as $value => $title)
 146                  {
 147                      $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
 148                      $captcha_select .= '<option value="' . $value . '"' . $current . '>' . $user->lang($title) . '</option>';
 149                  }
 150  
 151                  foreach ($captchas['unavailable'] as $value => $title)
 152                  {
 153                      $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
 154                      $captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option">' . $user->lang($title) . '</option>';
 155                  }
 156  
 157                  $demo_captcha = $factory->get_instance($selected);
 158  
 159                  foreach ($config_vars as $config_var => $options)
 160                  {
 161                      $template->assign_var($options['tpl'], (isset($_POST[$config_var])) ? $request->variable($config_var, $options['default']) : $config[$config_var]) ;
 162                  }
 163  
 164                  $template->assign_vars(array(
 165                      'CAPTCHA_PREVIEW_TPL'    => $demo_captcha->get_demo_template($id),
 166                      'S_CAPTCHA_HAS_CONFIG'    => $demo_captcha->has_config(),
 167                      'CAPTCHA_SELECT'        => $captcha_select,
 168                      'ERROR_MSG'                => implode('<br />', $error),
 169  
 170                      'U_ACTION'                => $this->u_action,
 171                  ));
 172              }
 173          }
 174      }
 175  
 176      /**
 177      * Entry point for delivering image CAPTCHAs in the ACP.
 178      */
 179  	function deliver_demo($selected)
 180      {
 181          global $phpbb_container;
 182  
 183          $captcha = $phpbb_container->get('captcha.factory')->get_instance($selected);
 184          $captcha->init(CONFIRM_REG);
 185          $captcha->execute_demo();
 186  
 187          garbage_collection();
 188          exit_handler();
 189      }
 190  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1