1 | <?php namespace Arcanedev\NoCaptcha; |
||
13 | class NoCaptchaV2 extends AbstractNoCaptcha |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Properties |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | /** |
||
21 | * Decides if we've already loaded the script file or not. |
||
22 | * |
||
23 | * @param bool |
||
24 | */ |
||
25 | protected $scriptLoaded = false; |
||
26 | |||
27 | /** |
||
28 | * noCaptcha Attributes |
||
29 | * |
||
30 | * @var \Arcanedev\NoCaptcha\Utilities\Attributes |
||
31 | */ |
||
32 | protected $attributes; |
||
33 | |||
34 | /* ----------------------------------------------------------------- |
||
35 | | Constructor |
||
36 | | ----------------------------------------------------------------- |
||
37 | */ |
||
38 | |||
39 | /** |
||
40 | * NoCaptcha constructor. |
||
41 | * |
||
42 | * @param string $secret |
||
43 | * @param string $siteKey |
||
44 | * @param string|null $lang |
||
45 | * @param array $attributes |
||
46 | */ |
||
47 | 128 | public function __construct($secret, $siteKey, $lang = null, array $attributes = []) |
|
53 | |||
54 | /* ----------------------------------------------------------------- |
||
55 | | Getters & Setters |
||
56 | | ----------------------------------------------------------------- |
||
57 | */ |
||
58 | |||
59 | /** |
||
60 | * Get script source link. |
||
61 | * |
||
62 | * @param string|null $callbackName |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | 20 | private function getScriptSrc($callbackName = null) |
|
80 | |||
81 | /** |
||
82 | * Set noCaptcha Attributes. |
||
83 | * |
||
84 | * @param \Arcanedev\NoCaptcha\Utilities\Attributes $attributes |
||
85 | * |
||
86 | * @return self |
||
87 | */ |
||
88 | 128 | public function setAttributes(Attributes $attributes) |
|
94 | |||
95 | /* ----------------------------------------------------------------- |
||
96 | | Main Methods |
||
97 | | ----------------------------------------------------------------- |
||
98 | */ |
||
99 | |||
100 | /** |
||
101 | * Display Captcha. |
||
102 | * |
||
103 | * @param string|null $name |
||
104 | * @param array $attributes |
||
105 | * |
||
106 | * @return \Illuminate\Support\HtmlString |
||
107 | */ |
||
108 | 76 | public function display($name = null, array $attributes = []) |
|
117 | |||
118 | /** |
||
119 | * Display image Captcha. |
||
120 | * |
||
121 | * @param string|null $name |
||
122 | * @param array $attributes |
||
123 | * |
||
124 | * @return \Illuminate\Support\HtmlString |
||
125 | */ |
||
126 | 12 | public function image($name = null, array $attributes = []) |
|
132 | |||
133 | /** |
||
134 | * Display audio Captcha. |
||
135 | * |
||
136 | * @param string|null $name |
||
137 | * @param array $attributes |
||
138 | * |
||
139 | * @return \Illuminate\Support\HtmlString |
||
140 | */ |
||
141 | 12 | public function audio($name = null, array $attributes = []) |
|
147 | /** |
||
148 | * Display an invisible Captcha (bind the challenge to a button). |
||
149 | * |
||
150 | * @param string $value |
||
151 | * @param array $attributes |
||
152 | * |
||
153 | * @return \Illuminate\Support\HtmlString |
||
154 | */ |
||
155 | 4 | public function button($value, array $attributes = []) |
|
165 | |||
166 | /** |
||
167 | * Get script tag. |
||
168 | * |
||
169 | * @param string|null $callbackName |
||
170 | * |
||
171 | * @return \Illuminate\Support\HtmlString |
||
172 | */ |
||
173 | 20 | public function script($callbackName = null) |
|
184 | |||
185 | /** |
||
186 | * Get the NoCaptcha API Script. |
||
187 | * |
||
188 | * @return \Illuminate\Support\HtmlString |
||
189 | */ |
||
190 | 4 | public function getApiScript() |
|
232 | |||
233 | /** |
||
234 | * Get script tag with a callback function. |
||
235 | * |
||
236 | * @param array $captchas |
||
237 | * @param string $callbackName |
||
238 | * |
||
239 | * @return \Illuminate\Support\HtmlString |
||
240 | */ |
||
241 | 4 | public function scriptWithCallback(array $captchas, $callbackName = 'captchaRenderCallback') |
|
258 | |||
259 | /** |
||
260 | * Rendering captchas with callback function. |
||
261 | * |
||
262 | * @param array $captchas |
||
263 | * |
||
264 | * @return string |
||
265 | */ |
||
266 | 4 | private function renderCaptchas(array $captchas) |
|
272 | |||
273 | /* ----------------------------------------------------------------- |
||
274 | | Check Methods |
||
275 | | ----------------------------------------------------------------- |
||
276 | */ |
||
277 | |||
278 | /** |
||
279 | * Check if callback is not empty. |
||
280 | * |
||
281 | * @param string|null $callbackName |
||
282 | * |
||
283 | * @return bool |
||
284 | */ |
||
285 | 20 | private function hasCallbackName($callbackName) |
|
289 | |||
290 | /* ----------------------------------------------------------------- |
||
291 | | Other Methods |
||
292 | | ----------------------------------------------------------------- |
||
293 | */ |
||
294 | |||
295 | /** |
||
296 | * Parse the response. |
||
297 | * |
||
298 | * @param string $json |
||
299 | * |
||
300 | * @return \Arcanedev\NoCaptcha\Utilities\AbstractResponse|mixed |
||
301 | */ |
||
302 | 12 | protected function parseResponse($json) |
|
306 | } |
||
307 |