@@ -32,11 +32,11 @@ |
||
| 32 | 32 | interface RequestMethod |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Submit the request with the specified parameters. |
|
| 37 | - * |
|
| 38 | - * @param RequestParameters $params Request parameters |
|
| 39 | - * @return string Body of the reCAPTCHA response |
|
| 40 | - */ |
|
| 41 | - public function submit(RequestParameters $params); |
|
| 35 | + /** |
|
| 36 | + * Submit the request with the specified parameters. |
|
| 37 | + * |
|
| 38 | + * @param RequestParameters $params Request parameters |
|
| 39 | + * @return string Body of the reCAPTCHA response |
|
| 40 | + */ |
|
| 41 | + public function submit(RequestParameters $params); |
|
| 42 | 42 | } |
@@ -36,53 +36,53 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class CurlPost implements RequestMethod |
| 38 | 38 | { |
| 39 | - /** |
|
| 40 | - * URL to which requests are sent via cURL. |
|
| 41 | - * @const string |
|
| 42 | - */ |
|
| 43 | - const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 39 | + /** |
|
| 40 | + * URL to which requests are sent via cURL. |
|
| 41 | + * @const string |
|
| 42 | + */ |
|
| 43 | + const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Curl connection to the reCAPTCHA service |
|
| 47 | - * @var Curl |
|
| 48 | - */ |
|
| 49 | - private $curl; |
|
| 45 | + /** |
|
| 46 | + * Curl connection to the reCAPTCHA service |
|
| 47 | + * @var Curl |
|
| 48 | + */ |
|
| 49 | + private $curl; |
|
| 50 | 50 | |
| 51 | - public function __construct(Curl $curl = null) |
|
| 52 | - { |
|
| 53 | - if (!is_null($curl)) { |
|
| 54 | - $this->curl = $curl; |
|
| 55 | - } else { |
|
| 56 | - $this->curl = new Curl(); |
|
| 57 | - } |
|
| 58 | - } |
|
| 51 | + public function __construct(Curl $curl = null) |
|
| 52 | + { |
|
| 53 | + if (!is_null($curl)) { |
|
| 54 | + $this->curl = $curl; |
|
| 55 | + } else { |
|
| 56 | + $this->curl = new Curl(); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Submit the cURL request with the specified parameters. |
|
| 62 | - * |
|
| 63 | - * @param RequestParameters $params Request parameters |
|
| 64 | - * @return string Body of the reCAPTCHA response |
|
| 65 | - */ |
|
| 66 | - public function submit(RequestParameters $params) |
|
| 67 | - { |
|
| 68 | - $handle = $this->curl->init(self::SITE_VERIFY_URL); |
|
| 60 | + /** |
|
| 61 | + * Submit the cURL request with the specified parameters. |
|
| 62 | + * |
|
| 63 | + * @param RequestParameters $params Request parameters |
|
| 64 | + * @return string Body of the reCAPTCHA response |
|
| 65 | + */ |
|
| 66 | + public function submit(RequestParameters $params) |
|
| 67 | + { |
|
| 68 | + $handle = $this->curl->init(self::SITE_VERIFY_URL); |
|
| 69 | 69 | |
| 70 | - $options = array( |
|
| 71 | - CURLOPT_POST => true, |
|
| 72 | - CURLOPT_POSTFIELDS => $params->toQueryString(), |
|
| 73 | - CURLOPT_HTTPHEADER => array( |
|
| 74 | - 'Content-Type: application/x-www-form-urlencoded' |
|
| 75 | - ), |
|
| 76 | - CURLINFO_HEADER_OUT => false, |
|
| 77 | - CURLOPT_HEADER => false, |
|
| 78 | - CURLOPT_RETURNTRANSFER => true, |
|
| 79 | - CURLOPT_SSL_VERIFYPEER => true |
|
| 80 | - ); |
|
| 81 | - $this->curl->setoptArray($handle, $options); |
|
| 70 | + $options = array( |
|
| 71 | + CURLOPT_POST => true, |
|
| 72 | + CURLOPT_POSTFIELDS => $params->toQueryString(), |
|
| 73 | + CURLOPT_HTTPHEADER => array( |
|
| 74 | + 'Content-Type: application/x-www-form-urlencoded' |
|
| 75 | + ), |
|
| 76 | + CURLINFO_HEADER_OUT => false, |
|
| 77 | + CURLOPT_HEADER => false, |
|
| 78 | + CURLOPT_RETURNTRANSFER => true, |
|
| 79 | + CURLOPT_SSL_VERIFYPEER => true |
|
| 80 | + ); |
|
| 81 | + $this->curl->setoptArray($handle, $options); |
|
| 82 | 82 | |
| 83 | - $response = $this->curl->exec($handle); |
|
| 84 | - $this->curl->close($handle); |
|
| 83 | + $response = $this->curl->exec($handle); |
|
| 84 | + $this->curl->close($handle); |
|
| 85 | 85 | |
| 86 | - return $response; |
|
| 87 | - } |
|
| 86 | + return $response; |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -34,37 +34,37 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class Post implements RequestMethod |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * URL to which requests are POSTed. |
|
| 39 | - * @const string |
|
| 40 | - */ |
|
| 41 | - const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 37 | + /** |
|
| 38 | + * URL to which requests are POSTed. |
|
| 39 | + * @const string |
|
| 40 | + */ |
|
| 41 | + const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Submit the POST request with the specified parameters. |
|
| 45 | - * |
|
| 46 | - * @param RequestParameters $params Request parameters |
|
| 47 | - * @return string Body of the reCAPTCHA response |
|
| 48 | - */ |
|
| 49 | - public function submit(RequestParameters $params) |
|
| 50 | - { |
|
| 51 | - /** |
|
| 52 | - * PHP 5.6.0 changed the way you specify the peer name for SSL context options. |
|
| 53 | - * Using "CN_name" will still work, but it will raise deprecated errors. |
|
| 54 | - */ |
|
| 55 | - $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; |
|
| 56 | - $options = array( |
|
| 57 | - 'http' => array( |
|
| 58 | - 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
|
| 59 | - 'method' => 'POST', |
|
| 60 | - 'content' => $params->toQueryString(), |
|
| 61 | - // Force the peer to validate (not needed in 5.6.0+, but still works |
|
| 62 | - 'verify_peer' => true, |
|
| 63 | - // Force the peer validation to use www.google.com |
|
| 64 | - $peer_key => 'www.google.com', |
|
| 65 | - ), |
|
| 66 | - ); |
|
| 67 | - $context = stream_context_create($options); |
|
| 68 | - return file_get_contents(self::SITE_VERIFY_URL, false, $context); |
|
| 69 | - } |
|
| 43 | + /** |
|
| 44 | + * Submit the POST request with the specified parameters. |
|
| 45 | + * |
|
| 46 | + * @param RequestParameters $params Request parameters |
|
| 47 | + * @return string Body of the reCAPTCHA response |
|
| 48 | + */ |
|
| 49 | + public function submit(RequestParameters $params) |
|
| 50 | + { |
|
| 51 | + /** |
|
| 52 | + * PHP 5.6.0 changed the way you specify the peer name for SSL context options. |
|
| 53 | + * Using "CN_name" will still work, but it will raise deprecated errors. |
|
| 54 | + */ |
|
| 55 | + $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; |
|
| 56 | + $options = array( |
|
| 57 | + 'http' => array( |
|
| 58 | + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
|
| 59 | + 'method' => 'POST', |
|
| 60 | + 'content' => $params->toQueryString(), |
|
| 61 | + // Force the peer to validate (not needed in 5.6.0+, but still works |
|
| 62 | + 'verify_peer' => true, |
|
| 63 | + // Force the peer validation to use www.google.com |
|
| 64 | + $peer_key => 'www.google.com', |
|
| 65 | + ), |
|
| 66 | + ); |
|
| 67 | + $context = stream_context_create($options); |
|
| 68 | + return file_get_contents(self::SITE_VERIFY_URL, false, $context); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -36,86 +36,86 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class SocketPost implements RequestMethod |
| 38 | 38 | { |
| 39 | - /** |
|
| 40 | - * reCAPTCHA service host. |
|
| 41 | - * @const string |
|
| 42 | - */ |
|
| 43 | - const RECAPTCHA_HOST = 'www.google.com'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @const string reCAPTCHA service path |
|
| 47 | - */ |
|
| 48 | - const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @const string Bad request error |
|
| 52 | - */ |
|
| 53 | - const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @const string Bad response error |
|
| 57 | - */ |
|
| 58 | - const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Socket to the reCAPTCHA service |
|
| 62 | - * @var Socket |
|
| 63 | - */ |
|
| 64 | - private $socket; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Constructor |
|
| 68 | - * |
|
| 69 | - * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
| 70 | - */ |
|
| 71 | - public function __construct(Socket $socket = null) |
|
| 72 | - { |
|
| 73 | - if (!is_null($socket)) { |
|
| 74 | - $this->socket = $socket; |
|
| 75 | - } else { |
|
| 76 | - $this->socket = new Socket(); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Submit the POST request with the specified parameters. |
|
| 82 | - * |
|
| 83 | - * @param RequestParameters $params Request parameters |
|
| 84 | - * @return string Body of the reCAPTCHA response |
|
| 85 | - */ |
|
| 86 | - public function submit(RequestParameters $params) |
|
| 87 | - { |
|
| 88 | - $errno = 0; |
|
| 89 | - $errstr = ''; |
|
| 90 | - |
|
| 91 | - if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) { |
|
| 92 | - return self::BAD_REQUEST; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $content = $params->toQueryString(); |
|
| 96 | - |
|
| 97 | - $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
| 98 | - $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
| 99 | - $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
| 100 | - $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
| 101 | - $request .= "Connection: close\r\n\r\n"; |
|
| 102 | - $request .= $content . "\r\n\r\n"; |
|
| 103 | - |
|
| 104 | - $this->socket->fwrite($request); |
|
| 105 | - $response = ''; |
|
| 106 | - |
|
| 107 | - while (!$this->socket->feof()) { |
|
| 108 | - $response .= $this->socket->fgets(4096); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $this->socket->fclose(); |
|
| 112 | - |
|
| 113 | - if (0 !== strpos($response, 'HTTP/1.1 200 OK')) { |
|
| 114 | - return self::BAD_RESPONSE; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $parts = preg_split("#\n\s*\n#Uis", $response); |
|
| 118 | - |
|
| 119 | - return $parts[1]; |
|
| 120 | - } |
|
| 39 | + /** |
|
| 40 | + * reCAPTCHA service host. |
|
| 41 | + * @const string |
|
| 42 | + */ |
|
| 43 | + const RECAPTCHA_HOST = 'www.google.com'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @const string reCAPTCHA service path |
|
| 47 | + */ |
|
| 48 | + const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @const string Bad request error |
|
| 52 | + */ |
|
| 53 | + const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @const string Bad response error |
|
| 57 | + */ |
|
| 58 | + const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Socket to the reCAPTCHA service |
|
| 62 | + * @var Socket |
|
| 63 | + */ |
|
| 64 | + private $socket; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Constructor |
|
| 68 | + * |
|
| 69 | + * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
| 70 | + */ |
|
| 71 | + public function __construct(Socket $socket = null) |
|
| 72 | + { |
|
| 73 | + if (!is_null($socket)) { |
|
| 74 | + $this->socket = $socket; |
|
| 75 | + } else { |
|
| 76 | + $this->socket = new Socket(); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Submit the POST request with the specified parameters. |
|
| 82 | + * |
|
| 83 | + * @param RequestParameters $params Request parameters |
|
| 84 | + * @return string Body of the reCAPTCHA response |
|
| 85 | + */ |
|
| 86 | + public function submit(RequestParameters $params) |
|
| 87 | + { |
|
| 88 | + $errno = 0; |
|
| 89 | + $errstr = ''; |
|
| 90 | + |
|
| 91 | + if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) { |
|
| 92 | + return self::BAD_REQUEST; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $content = $params->toQueryString(); |
|
| 96 | + |
|
| 97 | + $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
| 98 | + $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
| 99 | + $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
| 100 | + $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
| 101 | + $request .= "Connection: close\r\n\r\n"; |
|
| 102 | + $request .= $content . "\r\n\r\n"; |
|
| 103 | + |
|
| 104 | + $this->socket->fwrite($request); |
|
| 105 | + $response = ''; |
|
| 106 | + |
|
| 107 | + while (!$this->socket->feof()) { |
|
| 108 | + $response .= $this->socket->fgets(4096); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $this->socket->fclose(); |
|
| 112 | + |
|
| 113 | + if (0 !== strpos($response, 'HTTP/1.1 200 OK')) { |
|
| 114 | + return self::BAD_RESPONSE; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $parts = preg_split("#\n\s*\n#Uis", $response); |
|
| 118 | + |
|
| 119 | + return $parts[1]; |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -31,72 +31,72 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class Response |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * Succes or failure. |
|
| 36 | - * @var boolean |
|
| 37 | - */ |
|
| 38 | - private $success = false; |
|
| 34 | + /** |
|
| 35 | + * Succes or failure. |
|
| 36 | + * @var boolean |
|
| 37 | + */ |
|
| 38 | + private $success = false; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Error code strings. |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - private $errorCodes = array(); |
|
| 40 | + /** |
|
| 41 | + * Error code strings. |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + private $errorCodes = array(); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Build the response from the expected JSON returned by the service. |
|
| 48 | - * |
|
| 49 | - * @param string $json |
|
| 50 | - * @return \ReCaptcha\Response |
|
| 51 | - */ |
|
| 52 | - public static function fromJson($json) |
|
| 53 | - { |
|
| 54 | - $responseData = json_decode($json, true); |
|
| 46 | + /** |
|
| 47 | + * Build the response from the expected JSON returned by the service. |
|
| 48 | + * |
|
| 49 | + * @param string $json |
|
| 50 | + * @return \ReCaptcha\Response |
|
| 51 | + */ |
|
| 52 | + public static function fromJson($json) |
|
| 53 | + { |
|
| 54 | + $responseData = json_decode($json, true); |
|
| 55 | 55 | |
| 56 | - if (!$responseData) { |
|
| 57 | - return new Response(false, array('invalid-json')); |
|
| 58 | - } |
|
| 56 | + if (!$responseData) { |
|
| 57 | + return new Response(false, array('invalid-json')); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - if (isset($responseData['success']) && $responseData['success'] == true) { |
|
| 61 | - return new Response(true); |
|
| 62 | - } |
|
| 60 | + if (isset($responseData['success']) && $responseData['success'] == true) { |
|
| 61 | + return new Response(true); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
|
| 65 | - return new Response(false, $responseData['error-codes']); |
|
| 66 | - } |
|
| 64 | + if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
|
| 65 | + return new Response(false, $responseData['error-codes']); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return new Response(false); |
|
| 69 | - } |
|
| 68 | + return new Response(false); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Constructor. |
|
| 73 | - * |
|
| 74 | - * @param boolean $success |
|
| 75 | - * @param array $errorCodes |
|
| 76 | - */ |
|
| 77 | - public function __construct($success, array $errorCodes = array()) |
|
| 78 | - { |
|
| 79 | - $this->success = $success; |
|
| 80 | - $this->errorCodes = $errorCodes; |
|
| 81 | - } |
|
| 71 | + /** |
|
| 72 | + * Constructor. |
|
| 73 | + * |
|
| 74 | + * @param boolean $success |
|
| 75 | + * @param array $errorCodes |
|
| 76 | + */ |
|
| 77 | + public function __construct($success, array $errorCodes = array()) |
|
| 78 | + { |
|
| 79 | + $this->success = $success; |
|
| 80 | + $this->errorCodes = $errorCodes; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Is success? |
|
| 85 | - * |
|
| 86 | - * @return boolean |
|
| 87 | - */ |
|
| 88 | - public function isSuccess() |
|
| 89 | - { |
|
| 90 | - return $this->success; |
|
| 91 | - } |
|
| 83 | + /** |
|
| 84 | + * Is success? |
|
| 85 | + * |
|
| 86 | + * @return boolean |
|
| 87 | + */ |
|
| 88 | + public function isSuccess() |
|
| 89 | + { |
|
| 90 | + return $this->success; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Get error codes. |
|
| 95 | - * |
|
| 96 | - * @return array |
|
| 97 | - */ |
|
| 98 | - public function getErrorCodes() |
|
| 99 | - { |
|
| 100 | - return $this->errorCodes; |
|
| 101 | - } |
|
| 93 | + /** |
|
| 94 | + * Get error codes. |
|
| 95 | + * |
|
| 96 | + * @return array |
|
| 97 | + */ |
|
| 98 | + public function getErrorCodes() |
|
| 99 | + { |
|
| 100 | + return $this->errorCodes; |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | class EventNew_Notify_Background extends SMF_BackgroundTask |
| 21 | 21 | { |
| 22 | 22 | /** |
| 23 | - * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
| 23 | + * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
| 24 | 24 | * @return bool Always returns true |
| 25 | 25 | */ |
| 26 | 26 | public function execute() |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | 'content_action' => empty($this->_details['sender_id']) ? 'new_guest' : 'new', |
| 82 | 82 | 'is_read' => 0, |
| 83 | 83 | 'extra' => json_encode( |
| 84 | - array( |
|
| 85 | - "event_id" => $this->_details['event_id'], |
|
| 84 | + array( |
|
| 85 | + "event_id" => $this->_details['event_id'], |
|
| 86 | 86 | "event_title" => $this->_details['event_title'] |
| 87 | 87 | ) |
| 88 | 88 | ), |
@@ -82,7 +82,7 @@ |
||
| 82 | 82 | |
| 83 | 83 | // The helper is crucial. Include it first thing. |
| 84 | 84 | if (!file_exists($upgrade_path . '/upgrade-helper.php')) |
| 85 | - die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
|
| 85 | + die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
|
| 86 | 86 | |
| 87 | 87 | require_once($upgrade_path . '/upgrade-helper.php'); |
| 88 | 88 | |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | public $headers; |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * Start the curl object |
|
| 98 | - * - allow for user override values |
|
| 99 | - * |
|
| 100 | - * @param array $options An array of cURL options |
|
| 101 | - * @param int $max_redirect Maximum number of redirects |
|
| 102 | - */ |
|
| 97 | + * Start the curl object |
|
| 98 | + * - allow for user override values |
|
| 99 | + * |
|
| 100 | + * @param array $options An array of cURL options |
|
| 101 | + * @param int $max_redirect Maximum number of redirects |
|
| 102 | + */ |
|
| 103 | 103 | public function __construct($options = array(), $max_redirect = 3) |
| 104 | 104 | { |
| 105 | 105 | // Initialize class variables |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | - * Main calling function, |
|
| 112 | - * - will request the page data from a given $url |
|
| 113 | - * - optionally will post data to the page form if post data is supplied |
|
| 114 | - * - passed arrays will be converted to a post string joined with &'s |
|
| 115 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 116 | - * |
|
| 117 | - * @param string $url the site we are going to fetch |
|
| 118 | - * @param array $post_data any post data as form name => value |
|
| 119 | - * @return object An instance of the curl_fetch_web_data class |
|
| 120 | - */ |
|
| 111 | + * Main calling function, |
|
| 112 | + * - will request the page data from a given $url |
|
| 113 | + * - optionally will post data to the page form if post data is supplied |
|
| 114 | + * - passed arrays will be converted to a post string joined with &'s |
|
| 115 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 116 | + * |
|
| 117 | + * @param string $url the site we are going to fetch |
|
| 118 | + * @param array $post_data any post data as form name => value |
|
| 119 | + * @return object An instance of the curl_fetch_web_data class |
|
| 120 | + */ |
|
| 121 | 121 | public function get_url_data($url, $post_data = array()) |
| 122 | 122 | { |
| 123 | 123 | // POSTing some data perhaps? |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | - * Makes the actual cURL call |
|
| 138 | - * - stores responses (url, code, error, headers, body) in the response array |
|
| 139 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 140 | - * |
|
| 141 | - * @param string $url The site to fetch |
|
| 142 | - * @param bool $redirect Whether or not this was a redirect request |
|
| 143 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | - */ |
|
| 137 | + * Makes the actual cURL call |
|
| 138 | + * - stores responses (url, code, error, headers, body) in the response array |
|
| 139 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 140 | + * |
|
| 141 | + * @param string $url The site to fetch |
|
| 142 | + * @param bool $redirect Whether or not this was a redirect request |
|
| 143 | + * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | + */ |
|
| 145 | 145 | private function curl_request($url, $redirect = false) |
| 146 | 146 | { |
| 147 | 147 | // we do have a url I hope |
@@ -193,12 +193,12 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Used if being redirected to ensure we have a fully qualified address |
|
| 197 | - * |
|
| 198 | - * @param string $last_url The URL we went to |
|
| 199 | - * @param string $new_url The URL we were redirected to |
|
| 200 | - * @return string The new URL that was in the HTTP header |
|
| 201 | - */ |
|
| 196 | + * Used if being redirected to ensure we have a fully qualified address |
|
| 197 | + * |
|
| 198 | + * @param string $last_url The URL we went to |
|
| 199 | + * @param string $new_url The URL we were redirected to |
|
| 200 | + * @return string The new URL that was in the HTTP header |
|
| 201 | + */ |
|
| 202 | 202 | private function get_redirect_url($last_url = '', $new_url = '') |
| 203 | 203 | { |
| 204 | 204 | // Get the elements for these urls |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | - * Used to return the results to the calling program |
|
| 220 | - * - called as ->result() will return the full final array |
|
| 221 | - * - called as ->result('body') to just return the page source of the result |
|
| 222 | - * |
|
| 223 | - * @param string $area Used to return an area such as body, header, error |
|
| 224 | - * @return string The response |
|
| 225 | - */ |
|
| 219 | + * Used to return the results to the calling program |
|
| 220 | + * - called as ->result() will return the full final array |
|
| 221 | + * - called as ->result('body') to just return the page source of the result |
|
| 222 | + * |
|
| 223 | + * @param string $area Used to return an area such as body, header, error |
|
| 224 | + * @return string The response |
|
| 225 | + */ |
|
| 226 | 226 | public function result($area = '') |
| 227 | 227 | { |
| 228 | 228 | $max_result = count($this->response) - 1; |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | - * Will return all results from all loops (redirects) |
|
| 239 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 240 | - * - Call as ->result_raw() for everything. |
|
| 241 | - * |
|
| 242 | - * @param string $response_number Which response we want to get |
|
| 243 | - * @return array|string The entire response array or just the specified response |
|
| 244 | - */ |
|
| 238 | + * Will return all results from all loops (redirects) |
|
| 239 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 240 | + * - Call as ->result_raw() for everything. |
|
| 241 | + * |
|
| 242 | + * @param string $response_number Which response we want to get |
|
| 243 | + * @return array|string The entire response array or just the specified response |
|
| 244 | + */ |
|
| 245 | 245 | public function result_raw($response_number = '') |
| 246 | 246 | { |
| 247 | 247 | if (!is_numeric($response_number)) |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
| 257 | - * Takes supplied POST data and url encodes it |
|
| 258 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 259 | - * - drops vars with @ since we don't support sending files (uploading) |
|
| 260 | - * |
|
| 261 | - * @param array|string $post_data The raw POST data |
|
| 262 | - * @return string A string of post data |
|
| 263 | - */ |
|
| 257 | + * Takes supplied POST data and url encodes it |
|
| 258 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 259 | + * - drops vars with @ since we don't support sending files (uploading) |
|
| 260 | + * |
|
| 261 | + * @param array|string $post_data The raw POST data |
|
| 262 | + * @return string A string of post data |
|
| 263 | + */ |
|
| 264 | 264 | private function build_post_data($post_data) |
| 265 | 265 | { |
| 266 | 266 | if (is_array($post_data)) |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | - * Sets the final cURL options for the current call |
|
| 283 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 284 | - * - sets the callback function now that $this is existing |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 282 | + * Sets the final cURL options for the current call |
|
| 283 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 284 | + * - sets the callback function now that $this is existing |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | 287 | private function set_options() |
| 288 | 288 | { |
| 289 | 289 | // Callback to parse the returned headers, if any |
@@ -308,12 +308,12 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 312 | - * - resets the cURL options for the loop, sets the referrer flag |
|
| 313 | - * |
|
| 314 | - * @param string $target_url The URL we want to redirect to |
|
| 315 | - * @param string $referer_url The URL that we're redirecting from |
|
| 316 | - */ |
|
| 311 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 312 | + * - resets the cURL options for the loop, sets the referrer flag |
|
| 313 | + * |
|
| 314 | + * @param string $target_url The URL we want to redirect to |
|
| 315 | + * @param string $referer_url The URL that we're redirecting from |
|
| 316 | + */ |
|
| 317 | 317 | private function redirect($target_url, $referer_url) |
| 318 | 318 | { |
| 319 | 319 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
| 326 | - * Callback function to parse returned headers |
|
| 327 | - * - lowercases everything to make it consistent |
|
| 328 | - * |
|
| 329 | - * @param type $cr Not sure what this is used for? |
|
| 330 | - * @param string $header The header |
|
| 331 | - * @return int The length of the header |
|
| 332 | - */ |
|
| 326 | + * Callback function to parse returned headers |
|
| 327 | + * - lowercases everything to make it consistent |
|
| 328 | + * |
|
| 329 | + * @param type $cr Not sure what this is used for? |
|
| 330 | + * @param string $header The header |
|
| 331 | + * @return int The length of the header |
|
| 332 | + */ |
|
| 333 | 333 | private function header_callback($cr, $header) |
| 334 | 334 | { |
| 335 | 335 | $_header = trim($header); |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | { |
| 838 | 838 | uasort($loaded_attachments, function($a, $b) { |
| 839 | 839 | if ($a['filesize'] == $b['filesize']) |
| 840 | - return 0; |
|
| 840 | + return 0; |
|
| 841 | 841 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
| 842 | 842 | }); |
| 843 | 843 | } |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | { |
| 1243 | 1243 | uasort($loaded_attachments, function($a, $b) { |
| 1244 | 1244 | if ($a['filesize'] == $b['filesize']) |
| 1245 | - return 0; |
|
| 1245 | + return 0; |
|
| 1246 | 1246 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
| 1247 | 1247 | }); |
| 1248 | 1248 | } |