1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2017 - present |
4
|
|
|
* LaravelGoogleRecaptcha - helpers.php |
5
|
|
|
* author: Roberto Belotti - [email protected] |
6
|
|
|
* web : robertobelotti.com, github.com/biscolab |
7
|
|
|
* Initial version created on: 12/9/2018 |
8
|
|
|
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use Biscolab\ReCaptcha\Facades\ReCaptcha; |
12
|
|
|
|
13
|
|
|
if (!function_exists('recaptcha')) { |
14
|
|
|
/** |
15
|
|
|
* @return Biscolab\ReCaptcha\ReCaptchaBuilder|\Biscolab\ReCaptcha\ReCaptchaBuilderV2|\Biscolab\ReCaptcha\ReCaptchaBuilderInvisible|\Biscolab\ReCaptcha\ReCaptchaBuilderV3 |
16
|
|
|
*/ |
17
|
|
|
function recaptcha(): \Biscolab\ReCaptcha\ReCaptchaBuilder |
18
|
|
|
{ |
19
|
|
|
|
20
|
12 |
|
return app('recaptcha'); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* call ReCaptcha::htmlScriptTagJsApi() |
26
|
|
|
* Write script HTML tag in you HTML code |
27
|
|
|
* Insert before </head> tag |
28
|
|
|
* |
29
|
|
|
* @param $config ['form_id'] required if you are using invisible ReCaptcha |
30
|
|
|
*/ |
31
|
|
|
if (!function_exists('htmlScriptTagJsApi')) { |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param array|null $config |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
function htmlScriptTagJsApi(?array $config = []): string |
39
|
|
|
{ |
40
|
|
|
|
41
|
5 |
|
return ReCaptcha::htmlScriptTagJsApi($config); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* call ReCaptcha::htmlFormButton() |
47
|
|
|
* Write HTML <button> tag in your HTML code |
48
|
|
|
* Insert before </form> tag |
49
|
|
|
* |
50
|
|
|
* Warning! Using only with ReCAPTCHA INVISIBLE |
51
|
|
|
* |
52
|
|
|
* @param $buttonInnerHTML What you want to write on the submit button |
53
|
|
|
*/ |
54
|
|
|
if (!function_exists('htmlFormButton')) { |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param null|string $button_label |
58
|
|
|
* @param array|null $properties |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
function htmlFormButton(?string $button_label = 'Submit', ?array $properties = []): string |
63
|
|
|
{ |
64
|
|
|
|
65
|
2 |
|
return ReCaptcha::htmlFormButton($button_label, $properties); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* call ReCaptcha::htmlFormSnippet() |
71
|
|
|
* Write ReCAPTCHA HTML tag in your FORM |
72
|
|
|
* Insert before </form> tag |
73
|
|
|
* |
74
|
|
|
* Warning! Using only with ReCAPTCHA v2 |
75
|
|
|
*/ |
76
|
|
|
if (!function_exists('htmlFormSnippet')) { |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
function htmlFormSnippet(): string |
82
|
|
|
{ |
83
|
|
|
|
84
|
2 |
|
return ReCaptcha::htmlFormSnippet(); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* call ReCaptcha::getFormId() |
90
|
|
|
* return the form ID |
91
|
|
|
* Warning! Using only with ReCAPTCHA invisible |
92
|
|
|
*/ |
93
|
|
|
if (!function_exists('getFormId')) { |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
function getFormId(): string |
99
|
|
|
{ |
100
|
|
|
|
101
|
3 |
|
return ReCaptcha::getFormId(); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* return ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME value ("recaptcha") |
107
|
|
|
* Use V2 (checkbox and invisible) |
108
|
|
|
*/ |
109
|
|
|
if (!function_exists('recaptchaRuleName')) { |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
function recaptchaRuleName(): string |
115
|
|
|
{ |
116
|
|
|
|
117
|
43 |
|
return \Biscolab\ReCaptcha\ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* return ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME value "g-recaptcha-response" |
123
|
|
|
* Use V2 (checkbox and invisible) |
124
|
|
|
*/ |
125
|
|
|
if (!function_exists('recaptchaFieldName')) { |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
function recaptchaFieldName(): string |
131
|
|
|
{ |
132
|
|
|
|
133
|
1 |
|
return \Biscolab\ReCaptcha\ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|