@@ -32,74 +32,74 @@ |
||
32 | 32 | */ |
33 | 33 | class Socket |
34 | 34 | { |
35 | - private $handle = null; |
|
35 | + private $handle = null; |
|
36 | 36 | |
37 | - /** |
|
38 | - * fsockopen |
|
39 | - * |
|
40 | - * @see http://php.net/fsockopen |
|
41 | - * @param string $hostname |
|
42 | - * @param int $port |
|
43 | - * @param int $errno |
|
44 | - * @param string $errstr |
|
45 | - * @param float $timeout |
|
46 | - * @return resource |
|
47 | - */ |
|
48 | - public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
49 | - { |
|
50 | - $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout)); |
|
37 | + /** |
|
38 | + * fsockopen |
|
39 | + * |
|
40 | + * @see http://php.net/fsockopen |
|
41 | + * @param string $hostname |
|
42 | + * @param int $port |
|
43 | + * @param int $errno |
|
44 | + * @param string $errstr |
|
45 | + * @param float $timeout |
|
46 | + * @return resource |
|
47 | + */ |
|
48 | + public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
49 | + { |
|
50 | + $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout)); |
|
51 | 51 | |
52 | - if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
53 | - return $this->handle; |
|
54 | - } else { |
|
55 | - return false; |
|
56 | - } |
|
57 | - } |
|
52 | + if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
53 | + return $this->handle; |
|
54 | + } else { |
|
55 | + return false; |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * fwrite |
|
61 | - * |
|
62 | - * @see http://php.net/fwrite |
|
63 | - * @param string $string |
|
64 | - * @param int $length |
|
65 | - * @return int | bool |
|
66 | - */ |
|
67 | - public function fwrite($string, $length = null) |
|
68 | - { |
|
69 | - return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
70 | - } |
|
59 | + /** |
|
60 | + * fwrite |
|
61 | + * |
|
62 | + * @see http://php.net/fwrite |
|
63 | + * @param string $string |
|
64 | + * @param int $length |
|
65 | + * @return int | bool |
|
66 | + */ |
|
67 | + public function fwrite($string, $length = null) |
|
68 | + { |
|
69 | + return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * fgets |
|
74 | - * |
|
75 | - * @see http://php.net/fgets |
|
76 | - * @param int $length |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function fgets($length = null) |
|
80 | - { |
|
81 | - return fgets($this->handle, $length); |
|
82 | - } |
|
72 | + /** |
|
73 | + * fgets |
|
74 | + * |
|
75 | + * @see http://php.net/fgets |
|
76 | + * @param int $length |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function fgets($length = null) |
|
80 | + { |
|
81 | + return fgets($this->handle, $length); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * feof |
|
86 | - * |
|
87 | - * @see http://php.net/feof |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public function feof() |
|
91 | - { |
|
92 | - return feof($this->handle); |
|
93 | - } |
|
84 | + /** |
|
85 | + * feof |
|
86 | + * |
|
87 | + * @see http://php.net/feof |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public function feof() |
|
91 | + { |
|
92 | + return feof($this->handle); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * fclose |
|
97 | - * |
|
98 | - * @see http://php.net/fclose |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function fclose() |
|
102 | - { |
|
103 | - return fclose($this->handle); |
|
104 | - } |
|
95 | + /** |
|
96 | + * fclose |
|
97 | + * |
|
98 | + * @see http://php.net/fclose |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function fclose() |
|
102 | + { |
|
103 | + return fclose($this->handle); |
|
104 | + } |
|
105 | 105 | } |
@@ -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 | } |
@@ -32,43 +32,43 @@ |
||
32 | 32 | class Curl |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @see http://php.net/curl_init |
|
37 | - * @param string $url |
|
38 | - * @return resource cURL handle |
|
39 | - */ |
|
40 | - public function init($url = null) |
|
41 | - { |
|
42 | - return curl_init($url); |
|
43 | - } |
|
35 | + /** |
|
36 | + * @see http://php.net/curl_init |
|
37 | + * @param string $url |
|
38 | + * @return resource cURL handle |
|
39 | + */ |
|
40 | + public function init($url = null) |
|
41 | + { |
|
42 | + return curl_init($url); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @see http://php.net/curl_setopt_array |
|
47 | - * @param resource $ch |
|
48 | - * @param array $options |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - public function setoptArray($ch, array $options) |
|
52 | - { |
|
53 | - return curl_setopt_array($ch, $options); |
|
54 | - } |
|
45 | + /** |
|
46 | + * @see http://php.net/curl_setopt_array |
|
47 | + * @param resource $ch |
|
48 | + * @param array $options |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + public function setoptArray($ch, array $options) |
|
52 | + { |
|
53 | + return curl_setopt_array($ch, $options); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @see http://php.net/curl_exec |
|
58 | - * @param resource $ch |
|
59 | - * @return mixed |
|
60 | - */ |
|
61 | - public function exec($ch) |
|
62 | - { |
|
63 | - return curl_exec($ch); |
|
64 | - } |
|
56 | + /** |
|
57 | + * @see http://php.net/curl_exec |
|
58 | + * @param resource $ch |
|
59 | + * @return mixed |
|
60 | + */ |
|
61 | + public function exec($ch) |
|
62 | + { |
|
63 | + return curl_exec($ch); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @see http://php.net/curl_close |
|
68 | - * @param resource $ch |
|
69 | - */ |
|
70 | - public function close($ch) |
|
71 | - { |
|
72 | - curl_close($ch); |
|
73 | - } |
|
66 | + /** |
|
67 | + * @see http://php.net/curl_close |
|
68 | + * @param resource $ch |
|
69 | + */ |
|
70 | + public function close($ch) |
|
71 | + { |
|
72 | + curl_close($ch); |
|
73 | + } |
|
74 | 74 | } |
@@ -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 | } |
@@ -31,67 +31,67 @@ |
||
31 | 31 | */ |
32 | 32 | class ReCaptcha |
33 | 33 | { |
34 | - /** |
|
35 | - * Version of this client library. |
|
36 | - * @const string |
|
37 | - */ |
|
38 | - const VERSION = 'php_1.1.2'; |
|
34 | + /** |
|
35 | + * Version of this client library. |
|
36 | + * @const string |
|
37 | + */ |
|
38 | + const VERSION = 'php_1.1.2'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Shared secret for the site. |
|
42 | - * @var type string |
|
43 | - */ |
|
44 | - private $secret; |
|
40 | + /** |
|
41 | + * Shared secret for the site. |
|
42 | + * @var type string |
|
43 | + */ |
|
44 | + private $secret; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Method used to communicate with service. Defaults to POST request. |
|
48 | - * @var RequestMethod |
|
49 | - */ |
|
50 | - private $requestMethod; |
|
46 | + /** |
|
47 | + * Method used to communicate with service. Defaults to POST request. |
|
48 | + * @var RequestMethod |
|
49 | + */ |
|
50 | + private $requestMethod; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Create a configured instance to use the reCAPTCHA service. |
|
54 | - * |
|
55 | - * @param string $secret shared secret between site and reCAPTCHA server. |
|
56 | - * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. |
|
57 | - */ |
|
58 | - public function __construct($secret, RequestMethod $requestMethod = null) |
|
59 | - { |
|
60 | - if (empty($secret)) { |
|
61 | - throw new \RuntimeException('No secret provided'); |
|
62 | - } |
|
52 | + /** |
|
53 | + * Create a configured instance to use the reCAPTCHA service. |
|
54 | + * |
|
55 | + * @param string $secret shared secret between site and reCAPTCHA server. |
|
56 | + * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. |
|
57 | + */ |
|
58 | + public function __construct($secret, RequestMethod $requestMethod = null) |
|
59 | + { |
|
60 | + if (empty($secret)) { |
|
61 | + throw new \RuntimeException('No secret provided'); |
|
62 | + } |
|
63 | 63 | |
64 | - if (!is_string($secret)) { |
|
65 | - throw new \RuntimeException('The provided secret must be a string'); |
|
66 | - } |
|
64 | + if (!is_string($secret)) { |
|
65 | + throw new \RuntimeException('The provided secret must be a string'); |
|
66 | + } |
|
67 | 67 | |
68 | - $this->secret = $secret; |
|
68 | + $this->secret = $secret; |
|
69 | 69 | |
70 | - if (!is_null($requestMethod)) { |
|
71 | - $this->requestMethod = $requestMethod; |
|
72 | - } else { |
|
73 | - $this->requestMethod = new RequestMethod\Post(); |
|
74 | - } |
|
75 | - } |
|
70 | + if (!is_null($requestMethod)) { |
|
71 | + $this->requestMethod = $requestMethod; |
|
72 | + } else { |
|
73 | + $this->requestMethod = new RequestMethod\Post(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Calls the reCAPTCHA siteverify API to verify whether the user passes |
|
79 | - * CAPTCHA test. |
|
80 | - * |
|
81 | - * @param string $response The value of 'g-recaptcha-response' in the submitted form. |
|
82 | - * @param string $remoteIp The end user's IP address. |
|
83 | - * @return Response Response from the service. |
|
84 | - */ |
|
85 | - public function verify($response, $remoteIp = null) |
|
86 | - { |
|
87 | - // Discard empty solution submissions |
|
88 | - if (empty($response)) { |
|
89 | - $recaptchaResponse = new Response(false, array('missing-input-response')); |
|
90 | - return $recaptchaResponse; |
|
91 | - } |
|
77 | + /** |
|
78 | + * Calls the reCAPTCHA siteverify API to verify whether the user passes |
|
79 | + * CAPTCHA test. |
|
80 | + * |
|
81 | + * @param string $response The value of 'g-recaptcha-response' in the submitted form. |
|
82 | + * @param string $remoteIp The end user's IP address. |
|
83 | + * @return Response Response from the service. |
|
84 | + */ |
|
85 | + public function verify($response, $remoteIp = null) |
|
86 | + { |
|
87 | + // Discard empty solution submissions |
|
88 | + if (empty($response)) { |
|
89 | + $recaptchaResponse = new Response(false, array('missing-input-response')); |
|
90 | + return $recaptchaResponse; |
|
91 | + } |
|
92 | 92 | |
93 | - $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); |
|
94 | - $rawResponse = $this->requestMethod->submit($params); |
|
95 | - return Response::fromJson($rawResponse); |
|
96 | - } |
|
93 | + $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); |
|
94 | + $rawResponse = $this->requestMethod->submit($params); |
|
95 | + return Response::fromJson($rawResponse); |
|
96 | + } |
|
97 | 97 | } |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * SQLite Cache API class |
@@ -153,8 +154,7 @@ discard block |
||
153 | 154 | if (is_null($dir) || !is_writable($dir)) |
154 | 155 | { |
155 | 156 | $this->cachedir = $cachedir_sqlite; |
156 | - } |
|
157 | - else |
|
157 | + } else |
|
158 | 158 | { |
159 | 159 | $this->cachedir = $dir; |
160 | 160 | } |
@@ -143,7 +143,7 @@ |
||
143 | 143 | * |
144 | 144 | * @param string $dir A valid path |
145 | 145 | * |
146 | - * @return boolean If this was successful or not. |
|
146 | + * @return boolean|null If this was successful or not. |
|
147 | 147 | */ |
148 | 148 | public function setCachedir($dir = null) |
149 | 149 | { |
@@ -110,7 +110,7 @@ |
||
110 | 110 | |
111 | 111 | // Right, image not cached? Simply redirect, then. |
112 | 112 | if (!$this->checkRequest()) |
113 | - redirectexit($request); |
|
113 | + redirectexit($request); |
|
114 | 114 | |
115 | 115 | // Make sure we're serving an image |
116 | 116 | $contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : ''); |
@@ -63,26 +63,31 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function checkRequest() |
65 | 65 | { |
66 | - if (!$this->enabled) |
|
67 | - return false; |
|
66 | + if (!$this->enabled) { |
|
67 | + return false; |
|
68 | + } |
|
68 | 69 | |
69 | 70 | // Try to create the image cache directory if it doesn't exist |
70 | - if (!file_exists($this->cache)) |
|
71 | - if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php')) |
|
71 | + if (!file_exists($this->cache)) { |
|
72 | + if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php')) |
|
72 | 73 | return false; |
74 | + } |
|
73 | 75 | |
74 | - if (empty($_GET['hash']) || empty($_GET['request'])) |
|
75 | - return false; |
|
76 | + if (empty($_GET['hash']) || empty($_GET['request'])) { |
|
77 | + return false; |
|
78 | + } |
|
76 | 79 | |
77 | 80 | $hash = $_GET['hash']; |
78 | 81 | $request = $_GET['request']; |
79 | 82 | |
80 | - if (md5($request . $this->secret) != $hash) |
|
81 | - return false; |
|
83 | + if (md5($request . $this->secret) != $hash) { |
|
84 | + return false; |
|
85 | + } |
|
82 | 86 | |
83 | 87 | // Attempt to cache the request if it doesn't exist |
84 | - if (!$this->isCached($request)) |
|
85 | - return $this->cacheImage($request); |
|
88 | + if (!$this->isCached($request)) { |
|
89 | + return $this->cacheImage($request); |
|
90 | + } |
|
86 | 91 | |
87 | 92 | return true; |
88 | 93 | } |
@@ -103,19 +108,22 @@ discard block |
||
103 | 108 | if (!$cached || time() - $cached['time'] > (5 * 86400)) |
104 | 109 | { |
105 | 110 | @unlink($cached_file); |
106 | - if ($this->checkRequest()) |
|
107 | - $this->serve(); |
|
111 | + if ($this->checkRequest()) { |
|
112 | + $this->serve(); |
|
113 | + } |
|
108 | 114 | redirectexit($request); |
109 | 115 | } |
110 | 116 | |
111 | 117 | // Right, image not cached? Simply redirect, then. |
112 | - if (!$this->checkRequest()) |
|
113 | - redirectexit($request); |
|
118 | + if (!$this->checkRequest()) { |
|
119 | + redirectexit($request); |
|
120 | + } |
|
114 | 121 | |
115 | 122 | // Make sure we're serving an image |
116 | 123 | $contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : ''); |
117 | - if ($contentParts[0] != 'image') |
|
118 | - exit; |
|
124 | + if ($contentParts[0] != 'image') { |
|
125 | + exit; |
|
126 | + } |
|
119 | 127 | |
120 | 128 | header('Content-type: ' . $cached['content_type']); |
121 | 129 | header('Content-length: ' . $cached['size']); |
@@ -161,19 +169,22 @@ discard block |
||
161 | 169 | $request = $curl->get_url_data($request); |
162 | 170 | $response = $request->result(); |
163 | 171 | |
164 | - if (empty($response)) |
|
165 | - return false; |
|
172 | + if (empty($response)) { |
|
173 | + return false; |
|
174 | + } |
|
166 | 175 | |
167 | 176 | $headers = $response['headers']; |
168 | 177 | |
169 | 178 | // Make sure the url is returning an image |
170 | 179 | $contentParts = explode('/', !empty($headers['content-type']) ? $headers['content-type'] : ''); |
171 | - if ($contentParts[0] != 'image') |
|
172 | - return false; |
|
180 | + if ($contentParts[0] != 'image') { |
|
181 | + return false; |
|
182 | + } |
|
173 | 183 | |
174 | 184 | // Validate the filesize |
175 | - if ($response['size'] > ($this->maxSize * 1024)) |
|
176 | - return false; |
|
185 | + if ($response['size'] > ($this->maxSize * 1024)) { |
|
186 | + return false; |
|
187 | + } |
|
177 | 188 | |
178 | 189 | return file_put_contents($dest, json_encode(array( |
179 | 190 | 'content_type' => $headers['content-type'], |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * Display a list of upcoming events, birthdays, and holidays. |
69 | 69 | * |
70 | 70 | * @param string $grid_name The grid name |
71 | - * @return void|bool Returns false if the grid doesn't exist. |
|
71 | + * @return false|null Returns false if the grid doesn't exist. |
|
72 | 72 | */ |
73 | 73 | function template_show_upcoming_list($grid_name) |
74 | 74 | { |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @param string $grid_name The grid name |
240 | 240 | * @param bool $is_mini Is this a mini grid? |
241 | - * @return void|bool Returns false if the grid doesn't exist. |
|
241 | + * @return false|null Returns false if the grid doesn't exist. |
|
242 | 242 | */ |
243 | 243 | function template_show_month_grid($grid_name, $is_mini = false) |
244 | 244 | { |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * Shows a weekly grid |
524 | 524 | * |
525 | 525 | * @param string $grid_name The name of the grid |
526 | - * @return void|bool Returns false if the grid doesn't exist |
|
526 | + * @return false|null Returns false if the grid doesn't exist |
|
527 | 527 | */ |
528 | 528 | function template_show_week_grid($grid_name) |
529 | 529 | { |
@@ -40,16 +40,14 @@ discard block |
||
40 | 40 | ', template_show_upcoming_list('main'), ' |
41 | 41 | </div> |
42 | 42 | '; |
43 | - } |
|
44 | - elseif ($context['calendar_view'] == 'view_week') |
|
43 | + } elseif ($context['calendar_view'] == 'view_week') |
|
45 | 44 | { |
46 | 45 | echo ' |
47 | 46 | <div id="main_grid"> |
48 | 47 | ', template_show_week_grid('main'), ' |
49 | 48 | </div> |
50 | 49 | '; |
51 | - } |
|
52 | - else |
|
50 | + } else |
|
53 | 51 | { |
54 | 52 | echo ' |
55 | 53 | <div id="main_grid"> |
@@ -75,8 +73,9 @@ discard block |
||
75 | 73 | global $context, $scripturl, $txt, $modSettings; |
76 | 74 | |
77 | 75 | // Bail out if we have nothing to work with |
78 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
79 | - return false; |
|
76 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
77 | + return false; |
|
78 | + } |
|
80 | 79 | |
81 | 80 | // Protect programmer sanity |
82 | 81 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
@@ -113,11 +112,13 @@ discard block |
||
113 | 112 | <li class="windowbg"> |
114 | 113 | <b class="event_title">', $event['link'], '</b>'; |
115 | 114 | |
116 | - if ($event['can_edit']) |
|
117 | - echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>'; |
|
115 | + if ($event['can_edit']) { |
|
116 | + echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>'; |
|
117 | + } |
|
118 | 118 | |
119 | - if ($event['can_export']) |
|
120 | - echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>'; |
|
119 | + if ($event['can_export']) { |
|
120 | + echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>'; |
|
121 | + } |
|
121 | 122 | |
122 | 123 | echo ' |
123 | 124 | <br>'; |
@@ -125,14 +126,14 @@ discard block |
||
125 | 126 | if (!empty($event['allday'])) |
126 | 127 | { |
127 | 128 | echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' – <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : ''; |
128 | - } |
|
129 | - else |
|
129 | + } else |
|
130 | 130 | { |
131 | 131 | // Display event info relative to user's local timezone |
132 | 132 | echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> – <time datetime="' . $event['end_iso_gmdate'] . '">'; |
133 | 133 | |
134 | - if ($event['start_date_local'] != $event['end_date_local']) |
|
135 | - echo trim($event['end_date_local']) . ', '; |
|
134 | + if ($event['start_date_local'] != $event['end_date_local']) { |
|
135 | + echo trim($event['end_date_local']) . ', '; |
|
136 | + } |
|
136 | 137 | |
137 | 138 | echo trim($event['end_time_local']); |
138 | 139 | |
@@ -141,23 +142,27 @@ discard block |
||
141 | 142 | { |
142 | 143 | echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">'; |
143 | 144 | |
144 | - if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) |
|
145 | - echo trim($event['start_date_orig']), ', '; |
|
145 | + if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) { |
|
146 | + echo trim($event['start_date_orig']), ', '; |
|
147 | + } |
|
146 | 148 | |
147 | 149 | echo trim($event['start_time_orig']), '</time> – <time datetime="' . $event['end_iso_gmdate'] . '">'; |
148 | 150 | |
149 | - if ($event['start_date_orig'] != $event['end_date_orig']) |
|
150 | - echo trim($event['end_date_orig']) . ', '; |
|
151 | + if ($event['start_date_orig'] != $event['end_date_orig']) { |
|
152 | + echo trim($event['end_date_orig']) . ', '; |
|
153 | + } |
|
151 | 154 | |
152 | 155 | echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)'; |
153 | 156 | } |
154 | 157 | // Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion |
155 | - else |
|
156 | - echo ' ', $event['tz_abbrev'], '</time>'; |
|
158 | + else { |
|
159 | + echo ' ', $event['tz_abbrev'], '</time>'; |
|
160 | + } |
|
157 | 161 | } |
158 | 162 | |
159 | - if (!empty($event['location'])) |
|
160 | - echo '<br>', $event['location']; |
|
163 | + if (!empty($event['location'])) { |
|
164 | + echo '<br>', $event['location']; |
|
165 | + } |
|
161 | 166 | |
162 | 167 | echo ' |
163 | 168 | </li>'; |
@@ -189,8 +194,9 @@ discard block |
||
189 | 194 | |
190 | 195 | $birthdays = array(); |
191 | 196 | |
192 | - foreach ($date as $member) |
|
193 | - $birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>'; |
|
197 | + foreach ($date as $member) { |
|
198 | + $birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>'; |
|
199 | + } |
|
194 | 200 | |
195 | 201 | echo implode(', ', $birthdays); |
196 | 202 | |
@@ -221,8 +227,9 @@ discard block |
||
221 | 227 | $date_local = $date['date_local']; |
222 | 228 | unset($date['date_local']); |
223 | 229 | |
224 | - foreach ($date as $holiday) |
|
225 | - $holidays[] = $holiday . ' (' . $date_local . ')'; |
|
230 | + foreach ($date as $holiday) { |
|
231 | + $holidays[] = $holiday . ' (' . $date_local . ')'; |
|
232 | + } |
|
226 | 233 | } |
227 | 234 | |
228 | 235 | echo implode(', ', $holidays); |
@@ -245,17 +252,19 @@ discard block |
||
245 | 252 | global $context, $settings, $txt, $scripturl, $modSettings; |
246 | 253 | |
247 | 254 | // If the grid doesn't exist, no point in proceeding. |
248 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
249 | - return false; |
|
255 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
256 | + return false; |
|
257 | + } |
|
250 | 258 | |
251 | 259 | // A handy little pointer variable. |
252 | 260 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
253 | 261 | |
254 | 262 | // Some conditions for whether or not we should show the week links *here*. |
255 | - if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) |
|
256 | - $show_week_links = true; |
|
257 | - else |
|
258 | - $show_week_links = false; |
|
263 | + if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) { |
|
264 | + $show_week_links = true; |
|
265 | + } else { |
|
266 | + $show_week_links = false; |
|
267 | + } |
|
259 | 268 | |
260 | 269 | // Assuming that we've not disabled it, show the title block! |
261 | 270 | if (empty($calendar_data['disable_title'])) |
@@ -294,8 +303,9 @@ discard block |
||
294 | 303 | } |
295 | 304 | |
296 | 305 | // Show the controls on main grids |
297 | - if ($is_mini === false) |
|
298 | - template_calendar_top($calendar_data); |
|
306 | + if ($is_mini === false) { |
|
307 | + template_calendar_top($calendar_data); |
|
308 | + } |
|
299 | 309 | |
300 | 310 | // Finally, the main calendar table. |
301 | 311 | echo '<table class="calendar_table">'; |
@@ -306,8 +316,9 @@ discard block |
||
306 | 316 | echo '<tr>'; |
307 | 317 | |
308 | 318 | // If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared! |
309 | - if ($show_week_links === true) |
|
310 | - echo '<th> </th>'; |
|
319 | + if ($show_week_links === true) { |
|
320 | + echo '<th> </th>'; |
|
321 | + } |
|
311 | 322 | |
312 | 323 | // Now, loop through each actual day of the week. |
313 | 324 | foreach ($calendar_data['week_days'] as $day) |
@@ -354,27 +365,29 @@ discard block |
||
354 | 365 | // Additional classes are given for events, holidays, and birthdays. |
355 | 366 | if (!empty($day['events']) && !empty($calendar_data['highlight']['events'])) |
356 | 367 | { |
357 | - if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) |
|
358 | - $classes[] = 'events'; |
|
359 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) |
|
360 | - $classes[] = 'events'; |
|
368 | + if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) { |
|
369 | + $classes[] = 'events'; |
|
370 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) { |
|
371 | + $classes[] = 'events'; |
|
372 | + } |
|
361 | 373 | } |
362 | 374 | if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays'])) |
363 | 375 | { |
364 | - if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) |
|
365 | - $classes[] = 'holidays'; |
|
366 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) |
|
367 | - $classes[] = 'holidays'; |
|
376 | + if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) { |
|
377 | + $classes[] = 'holidays'; |
|
378 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) { |
|
379 | + $classes[] = 'holidays'; |
|
380 | + } |
|
368 | 381 | } |
369 | 382 | if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays'])) |
370 | 383 | { |
371 | - if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) |
|
372 | - $classes[] = 'birthdays'; |
|
373 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) |
|
374 | - $classes[] = 'birthdays'; |
|
384 | + if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) { |
|
385 | + $classes[] = 'birthdays'; |
|
386 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) { |
|
387 | + $classes[] = 'birthdays'; |
|
388 | + } |
|
375 | 389 | } |
376 | - } |
|
377 | - else |
|
390 | + } else |
|
378 | 391 | { |
379 | 392 | // Default Classes (either compact or comfortable and disabled). |
380 | 393 | $classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable'; |
@@ -392,17 +405,19 @@ discard block |
||
392 | 405 | $title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : ''; |
393 | 406 | |
394 | 407 | // The actual day number - be it a link, or just plain old text! |
395 | - if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
|
396 | - echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>'; |
|
397 | - else |
|
398 | - echo '<span class="day_text">', $title_prefix, $day['day'], '</span>'; |
|
408 | + if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) { |
|
409 | + echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>'; |
|
410 | + } else { |
|
411 | + echo '<span class="day_text">', $title_prefix, $day['day'], '</span>'; |
|
412 | + } |
|
399 | 413 | |
400 | 414 | // A lot of stuff, we're not showing on mini-calendars to conserve space. |
401 | 415 | if ($is_mini === false) |
402 | 416 | { |
403 | 417 | // Holidays are always fun, let's show them! |
404 | - if (!empty($day['holidays'])) |
|
405 | - echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>'; |
|
418 | + if (!empty($day['holidays'])) { |
|
419 | + echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>'; |
|
420 | + } |
|
406 | 421 | |
407 | 422 | // Happy Birthday Dear, Member! |
408 | 423 | if (!empty($day['birthdays'])) |
@@ -420,14 +435,16 @@ discard block |
||
420 | 435 | echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', '; |
421 | 436 | |
422 | 437 | // 9...10! Let's stop there. |
423 | - if ($birthday_count == 10 && $use_js_hide) |
|
424 | - // !!TODO - Inline CSS and JavaScript should be moved. |
|
438 | + if ($birthday_count == 10 && $use_js_hide) { |
|
439 | + // !!TODO - Inline CSS and JavaScript should be moved. |
|
425 | 440 | echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, '; |
441 | + } |
|
426 | 442 | |
427 | 443 | ++$birthday_count; |
428 | 444 | } |
429 | - if ($use_js_hide) |
|
430 | - echo '</span>'; |
|
445 | + if ($use_js_hide) { |
|
446 | + echo '</span>'; |
|
447 | + } |
|
431 | 448 | |
432 | 449 | echo '</div>'; |
433 | 450 | } |
@@ -437,8 +454,9 @@ discard block |
||
437 | 454 | { |
438 | 455 | // Sort events by start time (all day events will be listed first) |
439 | 456 | uasort($day['events'], function($a, $b) { |
440 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
441 | - return 0; |
|
457 | + if ($a['start_timestamp'] == $b['start_timestamp']) { |
|
458 | + return 0; |
|
459 | + } |
|
442 | 460 | return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
443 | 461 | }); |
444 | 462 | |
@@ -454,17 +472,19 @@ discard block |
||
454 | 472 | |
455 | 473 | echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">'; |
456 | 474 | |
457 | - if (!empty($event['start_time_local']) && $event['starts_today'] == true) |
|
458 | - echo trim(str_replace(':00 ', ' ', $event['start_time_local'])); |
|
459 | - elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) |
|
460 | - echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local'])); |
|
461 | - elseif (!empty($event['allday'])) |
|
462 | - echo $txt['calendar_allday']; |
|
475 | + if (!empty($event['start_time_local']) && $event['starts_today'] == true) { |
|
476 | + echo trim(str_replace(':00 ', ' ', $event['start_time_local'])); |
|
477 | + } elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) { |
|
478 | + echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local'])); |
|
479 | + } elseif (!empty($event['allday'])) { |
|
480 | + echo $txt['calendar_allday']; |
|
481 | + } |
|
463 | 482 | |
464 | 483 | echo '</span>'; |
465 | 484 | |
466 | - if (!empty($event['location'])) |
|
467 | - echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
485 | + if (!empty($event['location'])) { |
|
486 | + echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
487 | + } |
|
468 | 488 | |
469 | 489 | if ($event['can_edit'] || $event['can_export']) |
470 | 490 | { |
@@ -501,10 +521,11 @@ discard block |
||
501 | 521 | // Otherwise, assuming it's not a mini-calendar, we can show previous / next month days! |
502 | 522 | elseif ($is_mini === false) |
503 | 523 | { |
504 | - if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) |
|
505 | - echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>'; |
|
506 | - elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) |
|
507 | - echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>'; |
|
524 | + if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) { |
|
525 | + echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>'; |
|
526 | + } elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) { |
|
527 | + echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>'; |
|
528 | + } |
|
508 | 529 | } |
509 | 530 | |
510 | 531 | // Close this day and increase var count. |
@@ -530,8 +551,9 @@ discard block |
||
530 | 551 | global $context, $settings, $txt, $scripturl, $modSettings; |
531 | 552 | |
532 | 553 | // We might have no reason to proceed, if the variable isn't there. |
533 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
534 | - return false; |
|
554 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
555 | + return false; |
|
556 | + } |
|
535 | 557 | |
536 | 558 | // Handy pointer. |
537 | 559 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
@@ -567,8 +589,9 @@ discard block |
||
567 | 589 | } |
568 | 590 | |
569 | 591 | // The Month Title + Week Number... |
570 | - if (!empty($calendar_data['week_title'])) |
|
571 | - echo $calendar_data['week_title']; |
|
592 | + if (!empty($calendar_data['week_title'])) { |
|
593 | + echo $calendar_data['week_title']; |
|
594 | + } |
|
572 | 595 | |
573 | 596 | echo ' |
574 | 597 | </h3> |
@@ -607,10 +630,11 @@ discard block |
||
607 | 630 | <tr class="days_wrapper"> |
608 | 631 | <td class="', implode(' ', $classes), ' act_day">'; |
609 | 632 | // Should the day number be a link? |
610 | - if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
|
611 | - echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>'; |
|
612 | - else |
|
613 | - echo $txt['days'][$day['day_of_week']], ' - ', $day['day']; |
|
633 | + if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) { |
|
634 | + echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>'; |
|
635 | + } else { |
|
636 | + echo $txt['days'][$day['day_of_week']], ' - ', $day['day']; |
|
637 | + } |
|
614 | 638 | |
615 | 639 | echo '</td> |
616 | 640 | <td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">'; |
@@ -619,8 +643,9 @@ discard block |
||
619 | 643 | { |
620 | 644 | // Sort events by start time (all day events will be listed first) |
621 | 645 | uasort($day['events'], function($a, $b) { |
622 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
623 | - return 0; |
|
646 | + if ($a['start_timestamp'] == $b['start_timestamp']) { |
|
647 | + return 0; |
|
648 | + } |
|
624 | 649 | return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
625 | 650 | }); |
626 | 651 | |
@@ -632,15 +657,17 @@ discard block |
||
632 | 657 | |
633 | 658 | echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">'; |
634 | 659 | |
635 | - if (!empty($event['start_time_local'])) |
|
636 | - echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' – ' . trim($event['end_time_local']) : ''; |
|
637 | - else |
|
638 | - echo $txt['calendar_allday']; |
|
660 | + if (!empty($event['start_time_local'])) { |
|
661 | + echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' – ' . trim($event['end_time_local']) : ''; |
|
662 | + } else { |
|
663 | + echo $txt['calendar_allday']; |
|
664 | + } |
|
639 | 665 | |
640 | 666 | echo '</span>'; |
641 | 667 | |
642 | - if (!empty($event['location'])) |
|
643 | - echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
668 | + if (!empty($event['location'])) { |
|
669 | + echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
670 | + } |
|
644 | 671 | |
645 | 672 | if (!empty($event_icons_needed)) |
646 | 673 | { |
@@ -677,8 +704,7 @@ discard block |
||
677 | 704 | </div> |
678 | 705 | <br class="clear">'; |
679 | 706 | } |
680 | - } |
|
681 | - else |
|
707 | + } else |
|
682 | 708 | { |
683 | 709 | if (!empty($context['can_post'])) |
684 | 710 | { |
@@ -691,8 +717,9 @@ discard block |
||
691 | 717 | echo '</td> |
692 | 718 | <td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">'; |
693 | 719 | // Show any holidays! |
694 | - if (!empty($day['holidays'])) |
|
695 | - echo implode('<br>', $day['holidays']); |
|
720 | + if (!empty($day['holidays'])) { |
|
721 | + echo implode('<br>', $day['holidays']); |
|
722 | + } |
|
696 | 723 | |
697 | 724 | echo '</td> |
698 | 725 | <td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">'; |
@@ -750,8 +777,7 @@ discard block |
||
750 | 777 | <input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input end" data-type="date"> |
751 | 778 | <input type="submit" class="button_submit" style="float:none" id="view_button" value="', $txt['view'], '"> |
752 | 779 | </form>'; |
753 | - } |
|
754 | - else |
|
780 | + } else |
|
755 | 781 | { |
756 | 782 | echo' |
757 | 783 | <form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '"> |
@@ -793,8 +819,9 @@ discard block |
||
793 | 819 | echo ' |
794 | 820 | <form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">'; |
795 | 821 | |
796 | - if (!empty($context['event']['new'])) |
|
797 | - echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">'; |
|
822 | + if (!empty($context['event']['new'])) { |
|
823 | + echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">'; |
|
824 | + } |
|
798 | 825 | |
799 | 826 | // Start the main table. |
800 | 827 | echo ' |
@@ -844,9 +871,10 @@ discard block |
||
844 | 871 | { |
845 | 872 | echo ' |
846 | 873 | <optgroup label="', $category['name'], '">'; |
847 | - foreach ($category['boards'] as $board) |
|
848 | - echo ' |
|
874 | + foreach ($category['boards'] as $board) { |
|
875 | + echo ' |
|
849 | 876 | <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '', ' ', $board['name'], ' </option>'; |
877 | + } |
|
850 | 878 | echo ' |
851 | 879 | </optgroup>'; |
852 | 880 | } |
@@ -882,9 +910,10 @@ discard block |
||
882 | 910 | <span class="label">', $txt['calendar_timezone'], '</span> |
883 | 911 | <select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>'; |
884 | 912 | |
885 | - foreach ($context['all_timezones'] as $tz => $tzname) |
|
886 | - echo ' |
|
913 | + foreach ($context['all_timezones'] as $tz => $tzname) { |
|
914 | + echo ' |
|
887 | 915 | <option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>'; |
916 | + } |
|
888 | 917 | |
889 | 918 | echo ' |
890 | 919 | </select> |
@@ -899,9 +928,10 @@ discard block |
||
899 | 928 | echo ' |
900 | 929 | <input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">'; |
901 | 930 | // Delete button? |
902 | - if (empty($context['event']['new'])) |
|
903 | - echo ' |
|
931 | + if (empty($context['event']['new'])) { |
|
932 | + echo ' |
|
904 | 933 | <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">'; |
934 | + } |
|
905 | 935 | |
906 | 936 | echo ' |
907 | 937 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
@@ -945,9 +975,10 @@ discard block |
||
945 | 975 | |
946 | 976 | foreach ($context['clockicons'] as $t => $v) |
947 | 977 | { |
948 | - foreach ($v as $i) |
|
949 | - echo ' |
|
978 | + foreach ($v as $i) { |
|
979 | + echo ' |
|
950 | 980 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
981 | + } |
|
951 | 982 | } |
952 | 983 | |
953 | 984 | echo ' |
@@ -972,13 +1003,14 @@ discard block |
||
972 | 1003 | |
973 | 1004 | foreach ($context['clockicons'] as $t => $v) |
974 | 1005 | { |
975 | - foreach ($v as $i) |
|
976 | - echo ' |
|
1006 | + foreach ($v as $i) { |
|
1007 | + echo ' |
|
977 | 1008 | if (', $t, ' >= ', $i, ') |
978 | 1009 | { |
979 | 1010 | turnon.push("', $t, '_', $i, '"); |
980 | 1011 | ', $t, ' -= ', $i, '; |
981 | 1012 | }'; |
1013 | + } |
|
982 | 1014 | } |
983 | 1015 | |
984 | 1016 | echo ' |
@@ -1042,9 +1074,10 @@ discard block |
||
1042 | 1074 | |
1043 | 1075 | foreach ($context['clockicons'] as $t => $v) |
1044 | 1076 | { |
1045 | - foreach ($v as $i) |
|
1046 | - echo ' |
|
1077 | + foreach ($v as $i) { |
|
1078 | + echo ' |
|
1047 | 1079 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
1080 | + } |
|
1048 | 1081 | } |
1049 | 1082 | |
1050 | 1083 | echo ' |
@@ -1061,13 +1094,14 @@ discard block |
||
1061 | 1094 | |
1062 | 1095 | foreach ($context['clockicons'] as $t => $v) |
1063 | 1096 | { |
1064 | - foreach ($v as $i) |
|
1065 | - echo ' |
|
1097 | + foreach ($v as $i) { |
|
1098 | + echo ' |
|
1066 | 1099 | if (', $t, ' >= ', $i, ') |
1067 | 1100 | { |
1068 | 1101 | turnon.push("', $t, '_', $i, '"); |
1069 | 1102 | ', $t, ' -= ', $i, '; |
1070 | 1103 | }'; |
1104 | + } |
|
1071 | 1105 | } |
1072 | 1106 | |
1073 | 1107 | echo ' |
@@ -1126,9 +1160,10 @@ discard block |
||
1126 | 1160 | |
1127 | 1161 | foreach ($context['clockicons'] as $t => $v) |
1128 | 1162 | { |
1129 | - foreach ($v as $i) |
|
1130 | - echo ' |
|
1163 | + foreach ($v as $i) { |
|
1164 | + echo ' |
|
1131 | 1165 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
1166 | + } |
|
1132 | 1167 | } |
1133 | 1168 | |
1134 | 1169 | echo ' |
@@ -1149,13 +1184,14 @@ discard block |
||
1149 | 1184 | |
1150 | 1185 | foreach ($context['clockicons'] as $t => $v) |
1151 | 1186 | { |
1152 | - foreach ($v as $i) |
|
1153 | - echo ' |
|
1187 | + foreach ($v as $i) { |
|
1188 | + echo ' |
|
1154 | 1189 | if (', $t, ' >= ', $i, ') |
1155 | 1190 | { |
1156 | 1191 | turnon.push("', $t, '_', $i, '"); |
1157 | 1192 | ', $t, ' -= ', $i, '; |
1158 | 1193 | }'; |
1194 | + } |
|
1159 | 1195 | } |
1160 | 1196 | |
1161 | 1197 | echo ' |
@@ -437,9 +437,9 @@ discard block |
||
437 | 437 | { |
438 | 438 | // Sort events by start time (all day events will be listed first) |
439 | 439 | uasort($day['events'], function($a, $b) { |
440 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
441 | - return 0; |
|
442 | - return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
440 | + if ($a['start_timestamp'] == $b['start_timestamp']) |
|
441 | + return 0; |
|
442 | + return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
443 | 443 | }); |
444 | 444 | |
445 | 445 | echo ' |
@@ -619,9 +619,9 @@ discard block |
||
619 | 619 | { |
620 | 620 | // Sort events by start time (all day events will be listed first) |
621 | 621 | uasort($day['events'], function($a, $b) { |
622 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
623 | - return 0; |
|
624 | - return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
622 | + if ($a['start_timestamp'] == $b['start_timestamp']) |
|
623 | + return 0; |
|
624 | + return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
625 | 625 | }); |
626 | 626 | |
627 | 627 | foreach ($day['events'] as $event) |