Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

recaptcha.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 4.92 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\captcha\plugins;
015   
016  class recaptcha extends captcha_abstract
017  {
018      var $recaptcha_server = 'http://www.google.com/recaptcha/api';
019      var $recaptcha_server_secure = 'https://www.google.com/recaptcha/api'; // class constants :(
020   
021      var $response;
022   
023      /**
024      * Constructor
025      */
026      public function __construct()
027      {
028          global $request;
029          $this->recaptcha_server = $request->is_secure() ? $this->recaptcha_server_secure : $this->recaptcha_server;
030      }
031   
032      function init($type)
033      {
034          global $user, $request;
035   
036          $user->add_lang('captcha_recaptcha');
037          parent::init($type);
038          $this->response = $request->variable('g-recaptcha-response', '');
039      }
040   
041      public function is_available()
042      {
043          global $config, $user;
044          $user->add_lang('captcha_recaptcha');
045          return (isset($config['recaptcha_pubkey']) && !empty($config['recaptcha_pubkey']));
046      }
047   
048      /**
049      *  API function
050      */
051      function has_config()
052      {
053          return true;
054      }
055   
056      static public function get_name()
057      {
058          return 'CAPTCHA_RECAPTCHA';
059      }
060   
061      /**
062      * This function is implemented because required by the upper class, but is never used for reCaptcha.
063      */
064      function get_generator_class()
065      {
066          throw new \Exception('No generator class given.');
067      }
068   
069      function acp_page($id, &$module)
070      {
071          global $config, $template, $user, $phpbb_log, $request;
072   
073          $captcha_vars = array(
074              'recaptcha_pubkey'                => 'RECAPTCHA_PUBKEY',
075              'recaptcha_privkey'                => 'RECAPTCHA_PRIVKEY',
076          );
077   
078          $module->tpl_name = 'captcha_recaptcha_acp';
079          $module->page_title = 'ACP_VC_SETTINGS';
080          $form_key = 'acp_captcha';
081          add_form_key($form_key);
082   
083          $submit = $request->variable('submit', '');
084   
085          if ($submit && check_form_key($form_key))
086          {
087              $captcha_vars = array_keys($captcha_vars);
088              foreach ($captcha_vars as $captcha_var)
089              {
090                  $value = $request->variable($captcha_var, '');
091                  if ($value)
092                  {
093                      $config->set($captcha_var, $value);
094                  }
095              }
096   
097              $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_VISUAL');
098              trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action));
099          }
100          else if ($submit)
101          {
102              trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action));
103          }
104          else
105          {
106              foreach ($captcha_vars as $captcha_var => $template_var)
107              {
108                  $var = (isset($_REQUEST[$captcha_var])) ? $request->variable($captcha_var, '') : ((isset($config[$captcha_var])) ? $config[$captcha_var] : '');
109                  $template->assign_var($template_var, $var);
110              }
111   
112              $template->assign_vars(array(
113                  'CAPTCHA_PREVIEW'    => $this->get_demo_template($id),
114                  'CAPTCHA_NAME'        => $this->get_service_name(),
115                  'U_ACTION'            => $module->u_action,
116              ));
117   
118          }
119      }
120   
121      // not needed
122      function execute_demo()
123      {
124      }
125   
126      // not needed
127      function execute()
128      {
129      }
130   
131      function get_template()
132      {
133          global $config, $user, $template, $phpbb_root_path, $phpEx;
134   
135          if ($this->is_solved())
136          {
137              return false;
138          }
139          else
140          {
141              $contact_link = phpbb_get_board_contact_link($config, $phpbb_root_path, $phpEx);
142              $explain = $user->lang(($this->type != CONFIRM_POST) ? 'CONFIRM_EXPLAIN' : 'POST_CONFIRM_EXPLAIN', '<a href="' . $contact_link . '">', '</a>');
143   
144              $template->assign_vars(array(
145                  'RECAPTCHA_SERVER'            => $this->recaptcha_server,
146                  'RECAPTCHA_PUBKEY'            => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '',
147                  'S_RECAPTCHA_AVAILABLE'        => self::is_available(),
148                  'S_CONFIRM_CODE'            => true,
149                  'S_TYPE'                    => $this->type,
150                  'L_CONFIRM_EXPLAIN'            => $explain,
151              ));
152   
153              return 'captcha_recaptcha.html';
154          }
155      }
156   
157      function get_demo_template($id)
158      {
159          return $this->get_template();
160      }
161   
162      function get_hidden_fields()
163      {
164          $hidden_fields = array();
165   
166          // this is required for posting.php - otherwise we would forget about the captcha being already solved
167          if ($this->solved)
168          {
169              $hidden_fields['confirm_code'] = $this->code;
170          }
171          $hidden_fields['confirm_id'] = $this->confirm_id;
172          return $hidden_fields;
173      }
174   
175      function uninstall()
176      {
177          $this->garbage_collect(0);
178      }
179   
180      function install()
181      {
182          return;
183      }
184   
185      function validate()
186      {
187          if (!parent::validate())
188          {
189              return false;
190          }
191          else
192          {
193              return $this->recaptcha_check_answer();
194          }
195      }
196   
197      /**
198      * Calls an HTTP POST function to verify if the user's guess was correct
199      *
200      * @return bool|string Returns false on success or error string on failure.
201      */
202      function recaptcha_check_answer()
203      {
204          global $config, $user;
205   
206          //discard spam submissions
207          if ($this->response == null || strlen($this->response) == 0)
208          {
209              return $user->lang['RECAPTCHA_INCORRECT'];
210          }
211   
212          $recaptcha = new \ReCaptcha\ReCaptcha($config['recaptcha_privkey']);
213          $result = $recaptcha->verify($this->response, $user->ip);
214   
215          if ($result->isSuccess())
216          {
217              $this->solved = true;
218              return false;
219          }
220          else
221          {
222              return $user->lang['RECAPTCHA_INCORRECT'];
223          }
224      }
225  }
226