Overview

Namespaces

  • None
  • Quform
    • Traduttore_Registry

Classes

  • Quform
  • Quform_Admin_InsertForm
  • Quform_Admin_Page
  • Quform_Admin_Page_Controller
  • Quform_Admin_Page_Dashboard
  • Quform_Admin_Page_Entries
  • Quform_Admin_Page_Entries_Edit
  • Quform_Admin_Page_Entries_List
  • Quform_Admin_Page_Entries_View
  • Quform_Admin_Page_Factory
  • Quform_Admin_Page_Forms_Add
  • Quform_Admin_Page_Forms_Edit
  • Quform_Admin_Page_Forms_List
  • Quform_Admin_Page_Help
  • Quform_Admin_Page_Preview
  • Quform_Admin_Page_Settings
  • Quform_Admin_Page_Tools
  • Quform_Admin_Page_Tools_ExportEntries
  • Quform_Admin_Page_Tools_ExportForm
  • Quform_Admin_Page_Tools_Home
  • Quform_Admin_Page_Tools_ImportForm
  • Quform_Admin_Page_Tools_Migrate
  • Quform_Admin_Page_Tools_Uninstall
  • Quform_Api
  • Quform_Block
  • Quform_Builder
  • Quform_Captcha
  • Quform_ClassLoader
  • Quform_Confirmation
  • Quform_Container
  • Quform_Dashboard_Widget
  • Quform_Dispatcher
  • Quform_Element
  • Quform_Element_Captcha
  • Quform_Element_Checkbox
  • Quform_Element_Column
  • Quform_Element_Container
  • Quform_Element_Container_Iterator
  • Quform_Element_Date
  • Quform_Element_Email
  • Quform_Element_Factory
  • Quform_Element_Field
  • Quform_Element_File
  • Quform_Element_Group
  • Quform_Element_Hidden
  • Quform_Element_Honeypot
  • Quform_Element_Html
  • Quform_Element_Multi
  • Quform_Element_Multiselect
  • Quform_Element_Name
  • Quform_Element_Page
  • Quform_Element_Password
  • Quform_Element_Radio
  • Quform_Element_Recaptcha
  • Quform_Element_Row
  • Quform_Element_Select
  • Quform_Element_Submit
  • Quform_Element_Text
  • Quform_Element_Textarea
  • Quform_Element_Time
  • Quform_Entry_Controller
  • Quform_Entry_Exporter
  • Quform_Entry_List_Settings
  • Quform_Entry_List_Table
  • Quform_Entry_Processor
  • Quform_Entry_UserSearcher
  • Quform_Filter_Abstract
  • Quform_Filter_Alpha
  • Quform_Filter_AlphaNumeric
  • Quform_Filter_Digits
  • Quform_Filter_Regex
  • Quform_Filter_Static
  • Quform_Filter_StripTags
  • Quform_Filter_Trim
  • Quform_Form
  • Quform_Form_Controller
  • Quform_Form_Exporter
  • Quform_Form_Factory
  • Quform_Form_Importer
  • Quform_Form_Iterator
  • Quform_Form_List_Settings
  • Quform_Form_List_Table
  • Quform_Form_Processor
  • Quform_License
  • Quform_Migrator
  • Quform_NonceRefresher
  • Quform_Notification
  • Quform_Notification_Resender
  • Quform_Options
  • Quform_Permissions
  • Quform_Repository
  • Quform_ScriptLoader
  • Quform_Session
  • Quform_Settings
  • Quform_Shortcode
  • Quform_Themes
  • Quform_TokenReplacer
  • Quform_Toolbar
  • Quform_Translations
  • Quform_Updater
  • Quform_Upgrader
  • Quform_Uploader
  • Quform_Validator_Abstract
  • Quform_Validator_Alpha
  • Quform_Validator_AlphaNumeric
  • Quform_Validator_Array
  • Quform_Validator_Captcha
  • Quform_Validator_Date
  • Quform_Validator_Digits
  • Quform_Validator_Duplicate
  • Quform_Validator_Email
  • Quform_Validator_FileUpload
  • Quform_Validator_GreaterThan
  • Quform_Validator_Honeypot
  • Quform_Validator_Identical
  • Quform_Validator_InArray
  • Quform_Validator_Length
  • Quform_Validator_LessThan
  • Quform_Validator_Recaptcha
  • Quform_Validator_Regex
  • Quform_Validator_Required
  • Quform_Validator_Static
  • Quform_Validator_Time
  • Quform_View
  • Quform_ViewFactory
  • Quform_Widget_Form
  • Quform_Widget_Popup

Interfaces

  • Quform_Attachable
  • Quform_Element_Editable
  • Quform_Filter_Interface
  • Quform_Validator_Interface

Constants

  • Quform\Traduttore_Registry\TRANSIENT_KEY_PLUGIN
  • Quform\Traduttore_Registry\TRANSIENT_KEY_THEME

Functions

  • Quform\Traduttore_Registry\add_project
  • Quform\Traduttore_Registry\clean_translations_cache
  • Quform\Traduttore_Registry\get_available_locales
  • Quform\Traduttore_Registry\get_installed_translations
  • Quform\Traduttore_Registry\get_translations
  • Quform\Traduttore_Registry\register_clean_translations_cache
  • Quform\Traduttore_Registry\sanitize_date
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
  5:  */
  6: class Quform_Element_Recaptcha extends Quform_Element_Field
  7: {
  8:     /**
  9:      * The reCAPTCHA element has a static name
 10:      *
 11:      * @return string
 12:      */
 13:     public function getName()
 14:     {
 15:         $provider = $this->config('provider');
 16: 
 17:         if ($provider == 'hcaptcha') {
 18:             return 'h-captcha-response';
 19:         } elseif ($provider == 'turnstile') {
 20:             return 'cf-turnstile-response';
 21:         }
 22: 
 23:         return 'g-recaptcha-response';
 24:     }
 25: 
 26:     /**
 27:      * Get the classes for the outermost element wrapper
 28:      *
 29:      * @param   array  $context
 30:      * @return  array
 31:      */
 32:     protected function getElementClasses(array $context = array())
 33:     {
 34:         $classes = parent::getElementClasses($context);
 35: 
 36:         if (in_array($this->config('provider'), array('hcaptcha', 'turnstile'), true)) {
 37:             if ($this->config('recaptchaSize') == 'invisible') {
 38:                 $classes[] = 'quform-recaptcha-no-size';
 39:             }
 40:         } else {
 41:             if (($this->config('recaptchaVersion') == 'v3' || $this->config('recaptchaSize') == 'invisible') && $this->config('recaptchaBadge') != 'inline') {
 42:                 $classes[] = 'quform-recaptcha-no-size';
 43:             }
 44:         }
 45: 
 46:         return $classes;
 47:     }
 48: 
 49:     /**
 50:      * Get the HTML for the element label
 51:      *
 52:      * @param   array        $context
 53:      * @param   string|bool  $forAttribute  Set the "for" attribute to the element unique ID
 54:      * @param   bool         $id            Add a unique ID to the label
 55:      * @return  string
 56:      */
 57:     protected function getLabelHtml(array $context = array(), $forAttribute = true, $id = false)
 58:     {
 59:         if ($this->config('recaptchaVersion') == 'v3' || $this->config('recaptchaSize') == 'invisible') {
 60:             return '';
 61:         }
 62: 
 63:         return parent::getLabelHtml($context, false);
 64:     }
 65: 
 66:     /**
 67:      * Get the HTML for the element input wrapper
 68:      *
 69:      * @param   array   $context
 70:      * @return  string
 71:      */
 72:     protected function getInputHtml(array $context = array())
 73:     {
 74:         $output = sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getInputClasses($context))));
 75:         $output .= $this->getFieldHtml();
 76:         $output .= '</div>';
 77: 
 78:         return $output;
 79:     }
 80: 
 81:     /**
 82:      * Get the HTML for the field
 83:      *
 84:      * @param   array   $context
 85:      * @return  string
 86:      */
 87:     protected function getFieldHtml(array $context = array())
 88:     {
 89:         $output = '';
 90: 
 91:         if ($this->config('provider') == 'hcaptcha') {
 92:             if (!Quform::isNonEmptyString($this->config('hcaptchaSiteKey'))) {
 93:                 $output .= esc_html__('To use hCaptcha you must enter the API keys on the Quform settings page.', 'quform');
 94:             } else {
 95:                 $config = array(
 96:                     'sitekey' => $this->config('hcaptchaSiteKey'),
 97:                     'size' => $this->config('recaptchaSize'),
 98:                     'theme' => $this->config('recaptchaTheme'),
 99:                 );
100: 
101:                 $output .= sprintf(
102:                     '<div class="quform-hcaptcha" data-config="%s"></div>',
103:                     Quform::escape(wp_json_encode($config))
104:                 );
105: 
106:                 $output .= sprintf('<noscript>%s</noscript>', esc_html__('Please enable JavaScript to submit this form.', 'quform'));
107: 
108:                 if (!wp_script_is('quform-hcaptcha')) {
109:                     $args = array(
110:                         'onload' => 'QuformHcaptchaLoaded',
111:                         'render' => 'explicit',
112:                         'recaptchacompat' => apply_filters('quform_hcaptcha_recaptcha_compat', false) ? 'on' : 'off'
113:                     );
114: 
115:                     if (Quform::isNonEmptyString($this->config('hcaptchaLang'))) {
116:                         $args['hl'] = urlencode($this->config('hcaptchaLang'));
117:                     }
118: 
119:                     $url = add_query_arg($args, 'https://js.hcaptcha.com/1/api.js');
120: 
121:                     wp_enqueue_script('quform-hcaptcha', $url, array('jquery'), false, true);
122:                     wp_add_inline_script('quform-hcaptcha', 'window.QuformHcaptchaLoaded=function(){window.hcaptcha&&window.jQuery&&jQuery(".quform-hcaptcha").each(function(){var a=jQuery(this),c=a.data("config");a.is(":empty")&&("invisible"===c.size&&(c.callback=function(){a.closest(".quform-form").data("quform").submit()}),a.data("hcaptcha-id",hcaptcha.render(a[0],c)))})};', 'before');
123:                 }
124:             }
125:         } elseif ($this->config('provider') == 'turnstile') {
126:             if (!Quform::isNonEmptyString($this->config('turnstileSiteKey'))) {
127:                 $output .= esc_html__('To use Cloudflare Turnstile you must enter the API keys on the Quform settings page.', 'quform');
128:             } else {
129:                 $config = array(
130:                     'sitekey' => $this->config('turnstileSiteKey'),
131:                     'size' => $this->config('recaptchaSize'),
132:                     'theme' => $this->config('recaptchaTheme'),
133:                 );
134: 
135:                 if (Quform::isNonEmptyString($this->config('turnstileLang'))) {
136:                     $config['language'] = urlencode($this->config('turnstileLang'));
137:                 }
138: 
139:                 $output .= sprintf(
140:                     '<div class="quform-turnstile" data-config="%s"></div>',
141:                     Quform::escape(wp_json_encode($config))
142:                 );
143: 
144:                 $output .= sprintf('<noscript>%s</noscript>', esc_html__('Please enable JavaScript to submit this form.', 'quform'));
145: 
146:                 if (!wp_script_is('quform-turnstile')) {
147:                     $args = array(
148:                         'onload' => 'QuformTurnstileLoaded',
149:                         'render' => 'explicit'
150:                     );
151: 
152:                     if (apply_filters('quform_turnstile_recaptcha_compat', false)) {
153:                         $args['compat'] = 'recaptcha';
154:                     }
155: 
156:                     $url = add_query_arg($args, 'https://challenges.cloudflare.com/turnstile/v0/api.js');
157: 
158:                     wp_enqueue_script('quform-turnstile', $url, array('jquery'), false, true);
159:                     wp_add_inline_script('quform-turnstile', 'window.QuformTurnstileLoaded=function(){window.turnstile&&window.jQuery&&jQuery(".quform-turnstile").each(function(){var t=jQuery(this),i=t.data("config");t.is(":empty")&&t.data("turnstile-id",turnstile.render(t[0],i))})};', 'before');
160:                 }
161:             }
162:         } else {
163:             if (!Quform::isNonEmptyString($this->config('recaptchaSiteKey'))) {
164:                 $output .= esc_html__('To use reCAPTCHA you must enter the API keys on the Quform settings page.', 'quform');
165:             } else {
166:                 $config = array(
167:                     'sitekey' => $this->config('recaptchaSiteKey'),
168:                     '_version' => $this->config('recaptchaVersion'), /* 'version' is reserved */
169:                     'size' => $this->config('recaptchaSize'),
170:                     'type' => $this->config('recaptchaType'),
171:                     'theme' => $this->config('recaptchaTheme'),
172:                     'badge' => $this->config('recaptchaBadge'),
173:                 );
174: 
175:                 $output .= sprintf(
176:                     '<div class="quform-recaptcha" data-config="%s"></div>',
177:                     Quform::escape(wp_json_encode($config))
178:                 );
179: 
180:                 if ($this->config('recaptchaVersion') == 'v3' || $this->config('recaptchaSize') == 'invisible') {
181:                     $output .= sprintf('<noscript>%s</noscript>', esc_html__('Please enable JavaScript to submit this form.', 'quform'));
182:                 } else {
183:                     $output .= '<noscript><div>';
184:                     $output .= '<div style="width: 302px; height: 422px; position: relative;">';
185:                     $output .= '<div style="width: 302px; height: 422px; position: absolute;">';
186:                     $output .= sprintf('<iframe src="%s" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>', esc_url(sprintf('https://www.google.com/recaptcha/api/fallback?k=%s', $this->config('recaptchaSiteKey'))));
187:                     $output .= '</div></div>';
188:                     $output .= '<div style="width: 300px; height: 60px; border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px;">';
189:                     $output .= '<textarea name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; padding: 0px; resize: none;" aria-hidden="true"></textarea>';
190:                     $output .= '</div></div></noscript>';
191:                 }
192: 
193:                 if (!wp_script_is('quform-recaptcha')) {
194:                     $args = array(
195:                         'onload' => 'QuformRecaptchaLoaded',
196:                         'render' => 'explicit'
197:                     );
198: 
199:                     if (Quform::isNonEmptyString($this->config('recaptchaLang'))) {
200:                         $args['hl'] = urlencode($this->config('recaptchaLang'));
201:                     }
202: 
203:                     $url = add_query_arg($args, 'https://www.google.com/recaptcha/api.js');
204: 
205:                     wp_enqueue_script('quform-recaptcha', $url, array('jquery'), false, true);
206:                     wp_add_inline_script('quform-recaptcha', 'window.QuformRecaptchaLoaded=function(){window.grecaptcha&&window.jQuery&&jQuery(".quform-recaptcha").each(function(){var a=jQuery(this),c=a.data("config");a.is(":empty")&&("v2"===c._version&&"invisible"===c.size&&(c.callback=function(){a.closest(".quform-form").data("quform").submit()}),a.data("recaptcha-id",grecaptcha.render(a[0],c)))})};', 'before');
207:                 }
208:             }
209:         }
210: 
211:         return $output;
212:     }
213: 
214:     /**
215:      * Inherit settings from this element into the context
216:      *
217:      * @param   array  $context
218:      * @return  array
219:      */
220:     protected function prepareContext(array $context = array())
221:     {
222:         $context = parent::prepareContext($context);
223: 
224:         // Inside labels are not possible so set it above
225:         if ( ! in_array($context['labelPosition'], array('', 'left'), true)) {
226:             $context['labelPosition'] = '';
227:         }
228: 
229:         // Icon is the only possible tooltip type for this element
230:         $context['tooltipType'] = 'icon';
231: 
232:         return $context;
233:     }
234: 
235:     /**
236:      * Get the default element configuration
237:      *
238:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
239:      * @return  array
240:      */
241:     public static function getDefaultConfig($key = null)
242:     {
243:         $config = apply_filters('quform_default_config_recaptcha', array(
244:             // Basic
245:             'label' => __('Are you human?', 'quform'),
246:             'description' => '',
247:             'descriptionAbove' => '',
248:             'provider' => 'recaptcha',
249:             'recaptchaVersion' => 'v2',
250:             'recaptchaSize' => 'normal',
251:             'recaptchaType' => 'image',
252:             'recaptchaTheme' => 'light',
253:             'recaptchaBadge' => 'bottomright',
254:             'recaptchaLang' => '',
255:             'hcaptchaLang' => '',
256:             'turnstileLang' => '',
257:             'recaptchaThreshold' => '0.5',
258: 
259:             // Styles
260:             'labelIcon' => '',
261:             'customElementClass' => '',
262:             'styles' => array(),
263: 
264:             // Labels
265:             'subLabel' => '',
266:             'subLabelAbove' => '',
267:             'tooltip' => '',
268:             'tooltipType' => 'icon',
269:             'tooltipEvent' => 'inherit',
270:             'labelPosition' => 'inherit',
271:             'labelWidth' => '',
272: 
273:             // Logic
274:             'logicEnabled' => false,
275:             'logicAction' => true,
276:             'logicMatch' => 'all',
277:             'logicRules' => array(),
278: 
279:             // Advanced
280:             'visibility' => '',
281: 
282:             // Translations
283:             'messageRequired' => '',
284:             'messageRecaptchaMissingInputSecret' => '',
285:             'messageRecaptchaInvalidInputSecret' => '',
286:             'messageRecaptchaMissingInputResponse' => '',
287:             'messageRecaptchaInvalidInputResponse' => '',
288:             'messageRecaptchaError' => '',
289:             'messageRecaptchaScoreTooLow' => ''
290:         ));
291: 
292:         $config['type'] = 'recaptcha';
293: 
294:         if (Quform::isNonEmptyString($key)) {
295:             return Quform::get($config, $key);
296:         }
297: 
298:         return $config;
299:     }
300: }
301: 
API documentation generated by ApiGen