PluginProbe
User Submitted Posts – Enable Users to Submit Posts from the Front End / 20260110
User Submitted Posts – Enable Users to Submit Posts from the Front End v20260110
20260916 20260810 20260608 20230806 20230809 20230811 20230901 20230902 20230914 20231102 20240319 20240516 20240703 20241026 20250327 20250329 20251121 20251210 20260110 20260113 20260207 20260217 20260407 20260422 trunk All 59 releases
user-submitted-posts / recaptcha / ReCaptcha / RequestMethod / Socket.php

Socket.php in User Submitted Posts – Enable Users to Submit Posts from the Front End 20260110, at recaptcha/ReCaptcha/RequestMethod/Socket.php

113 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This is a PHP library that handles calling reCAPTCHA.
4 *
5 * BSD 3-Clause License
6 * @copyright (c) 2019, Google Inc.
7 * @link https://www.google.com/recaptcha
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice, this
13 * list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 namespace ReCaptcha\RequestMethod;
36
37 /**
38 * Convenience wrapper around native socket and file functions to allow for
39 * mocking.
40 */
41 class Socket
42 {
43 private $handle = null;
44
45 /**
46 * fsockopen
47 *
48 * @see http://php.net/fsockopen
49 * @param string $hostname
50 * @param int $port
51 * @param int $errno
52 * @param string $errstr
53 * @param float $timeout
54 * @return resource
55 */
56 public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null)
57 {
58 $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout));
59
60 if ($this->handle != false && $errno === 0 && $errstr === '') {
61 return $this->handle;
62 }
63 return false;
64 }
65
66 /**
67 * fwrite
68 *
69 * @see http://php.net/fwrite
70 * @param string $string
71 * @param int $length
72 * @return int | bool
73 */
74 public function fwrite($string, $length = null)
75 {
76 return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length));
77 }
78
79 /**
80 * fgets
81 *
82 * @see http://php.net/fgets
83 * @param int $length
84 * @return string
85 */
86 public function fgets($length = null)
87 {
88 return fgets($this->handle, $length);
89 }
90
91 /**
92 * feof
93 *
94 * @see http://php.net/feof
95 * @return bool
96 */
97 public function feof()
98 {
99 return feof($this->handle);
100 }
101
102 /**
103 * fclose
104 *
105 * @see http://php.net/fclose
106 * @return bool
107 */
108 public function fclose()
109 {
110 return fclose($this->handle);
111 }
112 }
113