Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

Response.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 5.98 KiB


001  <?php
002  /**
003   * This is a PHP library that handles calling reCAPTCHA.
004   *
005   * BSD 3-Clause License
006   * @copyright (c) 2019, Google Inc.
007   * @link https://www.google.com/recaptcha
008   * All rights reserved.
009   *
010   * Redistribution and use in source and binary forms, with or without
011   * modification, are permitted provided that the following conditions are met:
012   * 1. Redistributions of source code must retain the above copyright notice, this
013   *    list of conditions and the following disclaimer.
014   *
015   * 2. Redistributions in binary form must reproduce the above copyright notice,
016   *    this list of conditions and the following disclaimer in the documentation
017   *    and/or other materials provided with the distribution.
018   *
019   * 3. Neither the name of the copyright holder nor the names of its
020   *    contributors may be used to endorse or promote products derived from
021   *    this software without specific prior written permission.
022   *
023   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
024   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
025   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
026   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
027   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
028   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
029   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
030   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
031   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
032   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
033   */
034   
035  namespace ReCaptcha;
036   
037  /**
038   * The response returned from the service.
039   */
040  class Response
041  {
042      /**
043       * Success or failure.
044       * @var boolean
045       */
046      private $success = false;
047   
048      /**
049       * Error code strings.
050       * @var array
051       */
052      private $errorCodes = array();
053   
054      /**
055       * The hostname of the site where the reCAPTCHA was solved.
056       * @var string
057       */
058      private $hostname;
059   
060      /**
061       * Timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
062       * @var string
063       */
064      private $challengeTs;
065   
066      /**
067       * APK package name
068       * @var string
069       */
070      private $apkPackageName;
071   
072      /**
073       * Score assigned to the request
074       * @var float
075       */
076      private $score;
077   
078      /**
079       * Action as specified by the page
080       * @var string
081       */
082      private $action;
083   
084      /**
085       * Build the response from the expected JSON returned by the service.
086       *
087       * @param string $json
088       * @return \ReCaptcha\Response
089       */
090      public static function fromJson($json)
091      {
092          $responseData = json_decode($json, true);
093   
094          if (!$responseData) {
095              return new Response(false, array(ReCaptcha::E_INVALID_JSON));
096          }
097   
098          $hostname = isset($responseData['hostname']) ? $responseData['hostname'] : null;
099          $challengeTs = isset($responseData['challenge_ts']) ? $responseData['challenge_ts'] : null;
100          $apkPackageName = isset($responseData['apk_package_name']) ? $responseData['apk_package_name'] : null;
101          $score = isset($responseData['score']) ? floatval($responseData['score']) : null;
102          $action = isset($responseData['action']) ? $responseData['action'] : null;
103   
104          if (isset($responseData['success']) && $responseData['success'] == true) {
105              return new Response(true, array(), $hostname, $challengeTs, $apkPackageName, $score, $action);
106          }
107   
108          if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
109              return new Response(false, $responseData['error-codes'], $hostname, $challengeTs, $apkPackageName, $score, $action);
110          }
111   
112          return new Response(false, array(ReCaptcha::E_UNKNOWN_ERROR), $hostname, $challengeTs, $apkPackageName, $score, $action);
113      }
114   
115      /**
116       * Constructor.
117       *
118       * @param boolean $success
119       * @param string $hostname
120       * @param string $challengeTs
121       * @param string $apkPackageName
122       * @param float $score
123       * @param string $action
124       * @param array $errorCodes
125       */
126      public function __construct($success, array $errorCodes = array(), $hostname = null, $challengeTs = null, $apkPackageName = null, $score = null, $action = null)
127      {
128          $this->success = $success;
129          $this->hostname = $hostname;
130          $this->challengeTs = $challengeTs;
131          $this->apkPackageName = $apkPackageName;
132          $this->score = $score;
133          $this->action = $action;
134          $this->errorCodes = $errorCodes;
135      }
136   
137      /**
138       * Is success?
139       *
140       * @return boolean
141       */
142      public function isSuccess()
143      {
144          return $this->success;
145      }
146   
147      /**
148       * Get error codes.
149       *
150       * @return array
151       */
152      public function getErrorCodes()
153      {
154          return $this->errorCodes;
155      }
156   
157      /**
158       * Get hostname.
159       *
160       * @return string
161       */
162      public function getHostname()
163      {
164          return $this->hostname;
165      }
166   
167      /**
168       * Get challenge timestamp
169       *
170       * @return string
171       */
172      public function getChallengeTs()
173      {
174          return $this->challengeTs;
175      }
176   
177      /**
178       * Get APK package name
179       *
180       * @return string
181       */
182      public function getApkPackageName()
183      {
184          return $this->apkPackageName;
185      }
186      /**
187       * Get score
188       *
189       * @return float
190       */
191      public function getScore()
192      {
193          return $this->score;
194      }
195   
196      /**
197       * Get action
198       *
199       * @return string
200       */
201      public function getAction()
202      {
203          return $this->action;
204      }
205   
206      public function toArray()
207      {
208          return array(
209              'success' => $this->isSuccess(),
210              'hostname' => $this->getHostname(),
211              'challenge_ts' => $this->getChallengeTs(),
212              'apk_package_name' => $this->getApkPackageName(),
213              'score' => $this->getScore(),
214              'action' => $this->getAction(),
215              'error-codes' => $this->getErrorCodes(),
216          );
217      }
218  }
219