1 | <?php namespace Arcanedev\NoCaptcha; |
||
15 | class NoCaptchaV2 extends AbstractNoCaptcha |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Properties |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | /** |
||
23 | * Decides if we've already loaded the script file or not. |
||
24 | * |
||
25 | * @param bool |
||
26 | */ |
||
27 | protected $scriptLoaded = false; |
||
28 | |||
29 | /* ----------------------------------------------------------------- |
||
30 | | Getters & Setters |
||
31 | | ----------------------------------------------------------------- |
||
32 | */ |
||
33 | |||
34 | /** |
||
35 | * Get script source link. |
||
36 | * |
||
37 | * @param string|null $callbackName |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | 20 | private function getScriptSrc($callbackName = null) |
|
55 | |||
56 | /* ----------------------------------------------------------------- |
||
57 | | Main Methods |
||
58 | | ----------------------------------------------------------------- |
||
59 | */ |
||
60 | |||
61 | /** |
||
62 | * Display Captcha. |
||
63 | * |
||
64 | * @param string|null $name |
||
65 | * @param array $attributes |
||
66 | * |
||
67 | * @return \Arcanedev\Html\Elements\Div |
||
68 | */ |
||
69 | 76 | public function display($name = null, array $attributes = []) |
|
76 | |||
77 | /** |
||
78 | * Display image Captcha. |
||
79 | * |
||
80 | * @param string|null $name |
||
81 | * @param array $attributes |
||
82 | * |
||
83 | * @return \Arcanedev\Html\Elements\Div |
||
84 | */ |
||
85 | 12 | public function image($name = null, array $attributes = []) |
|
92 | |||
93 | /** |
||
94 | * Display audio Captcha. |
||
95 | * |
||
96 | * @param string|null $name |
||
97 | * @param array $attributes |
||
98 | * |
||
99 | * @return \Arcanedev\Html\Elements\Div |
||
100 | */ |
||
101 | 12 | public function audio($name = null, array $attributes = []) |
|
108 | |||
109 | /** |
||
110 | * Display an invisible Captcha (bind the challenge to a button). |
||
111 | * |
||
112 | * @param string $value |
||
113 | * @param array $attributes |
||
114 | * |
||
115 | * @return \Arcanedev\Html\Elements\Button |
||
116 | */ |
||
117 | 4 | public function button($value, array $attributes = []) |
|
124 | |||
125 | /** |
||
126 | * Get script tag. |
||
127 | * |
||
128 | * @param string|null $callbackName |
||
129 | * |
||
130 | * @return \Illuminate\Support\HtmlString |
||
131 | */ |
||
132 | 20 | public function script($callbackName = null) |
|
143 | |||
144 | /** |
||
145 | * Get the NoCaptcha API Script. |
||
146 | * |
||
147 | * @return \Illuminate\Support\HtmlString |
||
148 | */ |
||
149 | 4 | public function getApiScript() |
|
191 | |||
192 | /** |
||
193 | * Get script tag with a callback function. |
||
194 | * |
||
195 | * @param array $captchas |
||
196 | * @param string $callbackName |
||
197 | * |
||
198 | * @return \Illuminate\Support\HtmlString |
||
199 | */ |
||
200 | 4 | public function scriptWithCallback(array $captchas, $callbackName = 'captchaRenderCallback') |
|
218 | |||
219 | /** |
||
220 | * Rendering captchas with callback function. |
||
221 | * |
||
222 | * @param array $captchas |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | 4 | private function renderCaptchas(array $captchas) |
|
232 | |||
233 | /* ----------------------------------------------------------------- |
||
234 | | Check Methods |
||
235 | | ----------------------------------------------------------------- |
||
236 | */ |
||
237 | |||
238 | /** |
||
239 | * Check if callback is not empty. |
||
240 | * |
||
241 | * @param string|null $callbackName |
||
242 | * |
||
243 | * @return bool |
||
244 | */ |
||
245 | 20 | private function hasCallbackName($callbackName) |
|
249 | |||
250 | /* ----------------------------------------------------------------- |
||
251 | | Other Methods |
||
252 | | ----------------------------------------------------------------- |
||
253 | */ |
||
254 | |||
255 | /** |
||
256 | * Parse the response. |
||
257 | * |
||
258 | * @param string $json |
||
259 | * |
||
260 | * @return \Arcanedev\NoCaptcha\Utilities\AbstractResponse|mixed |
||
261 | */ |
||
262 | 12 | protected function parseResponse($json) |
|
266 | |||
267 | /** |
||
268 | * Prepare the attributes. |
||
269 | * |
||
270 | * @param array $attributes |
||
271 | * |
||
272 | * @return array |
||
273 | */ |
||
274 | 68 | private function prepareAttributes(array $attributes) |
|
288 | |||
289 | /** |
||
290 | * Check the `data-*` attribute. |
||
291 | * |
||
292 | * @param array $attributes |
||
293 | * @param string $name |
||
294 | * @param array $supported |
||
295 | * @param string $default |
||
296 | */ |
||
297 | 68 | private static function checkDataAttribute(array &$attributes, $name, array $supported, $default) |
|
309 | |||
310 | /** |
||
311 | * Prepare the name and id attributes. |
||
312 | * |
||
313 | * @param string|null $name |
||
314 | * |
||
315 | * @return array |
||
316 | * |
||
317 | * @throws \Arcanedev\NoCaptcha\Exceptions\InvalidArgumentException |
||
318 | */ |
||
319 | 76 | protected static function prepareNameAttribute($name) |
|
332 | } |
||
333 |