-
Notifications
You must be signed in to change notification settings - Fork 4
/
preNoCaptcha.php
47 lines (40 loc) · 1.45 KB
/
preNoCaptcha.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/*
noCaptcha reCpatcha from google, see: https://www.google.com/recaptcha/intro/index.html
This preHook is needed to generate the field for noCaptcha and call the script
It needs the chunk nocaptcha_tpl to be created from the nocaptcha_tpl.html
usage: [[!FormIt? &preHooks=`preNoCaptcha` &ncTheme=`light|dark` &ncName=`other name for placeholder` &ncType=`image|audio` &forceFallback=`0|1` ]]
*/
//initial variables
$output;
$placeholders;
$site_key = $modx->getOption('formit.recaptcha_public_key', null, '');
$theme = $modx->getOption('ncTheme', $scriptProperties, 'light');
$phName = $modx->getOption('ncName', $scriptProperties, 'nocaptcha');
$forceFallback = $modx->getOption('forceFallback', $scriptProperties, 0);
//used when fallback to captcha
$ncType = $modx->getOption('ncType', $scriptProperties, 'image');
if(!empty($site_key)){
//check for force fallback
if($forceFallback==1){
$fallback = '?fallback=true';
}else{
$fallback = '';
}
//set array for placeholders
$placeholders = array(
'site_key' => $site_key,
'theme' => $theme,
'type' => $ncType,
'fallback' => $fallback
);
//get generated chunk
$output = $modx->getChunk('nocaptcha_tpl', $placeholders);
}else{
//display error on form
$output = '<pre>No public or site key given for system-setting formit.recaptcha_public_key</pre>';
}
//output to placeholder
$modx->setPlaceholder($phName,$output);
return true;
?>