-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christopher Mühl
committed
May 24, 2019
1 parent
05ac27f
commit 310e861
Showing
17 changed files
with
229 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_DCA']['tl_content']['palettes']['backgroundrecaptcha'] = '{type_legend},type;{description_legend},recaptcha_action;{invisible_legend:hide},invisible,start,stop;'; | ||
|
||
$GLOBALS['TL_DCA']['tl_content']['fields'] += [ | ||
'recaptcha_action' => [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_content']['recaptcha_action'], | ||
'exclude' => true, | ||
'inputType' => 'text', | ||
'eval' => ['tl_class' => 'w50', 'required' => true], | ||
'sql' => 'VARCHAR(120) NOT NULL', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_DCA']['tl_form_field']['fields']['recaptcha3_threshold'] = [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_threshold'], | ||
'inputType' => 'text', | ||
'sql' => "varchar(8) unsigned NOT NULL default '0'", | ||
'eval' => ['tl_class' => 'w50'] | ||
]; | ||
$GLOBALS['TL_DCA']['tl_form_field']['fields'] += [ | ||
'recaptch3_threshold' => [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_threshold'], | ||
'inputType' => 'text', | ||
'sql' => "varchar(8) unsigned NOT NULL default ''", | ||
'eval' => ['tl_class' => 'w50 clr'], | ||
], | ||
'recaptcha3_action' => [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_action'], | ||
'inputType' => 'text', | ||
'sql' => "varchar(120) unsigned NOT NULL default ''", | ||
'eval' => ['tl_class' => 'w50'] | ||
], | ||
]; | ||
|
||
if (Config::get('recaptchaType') != 'recaptcha3') return; | ||
|
||
$GLOBALS['TL_DCA']['tl_form_field']['palettes']['captcha'] = str_replace(',type,label', ',type,label,recaptcha3_threshold,recaptcha3_action', $GLOBALS['TL_DCA']['tl_form_field']['palettes']['captcha']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,42 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_DCA']['tl_settings']['fields']['recaptchaType'] = [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['recaptchaType'], | ||
'inputType' => 'select', | ||
'options_callback' => function () | ||
{ | ||
return [ | ||
'invisible' => 'reCAPTCHA v2: Invisible', | ||
'recaptcha2' => 'reCAPTCHA v2: Checkbox', | ||
'recaptcha3' => 'reCAPTCHA v3', | ||
]; | ||
}, | ||
'eval' => ['chosen' => true, 'submitOnChange' => true] | ||
]; | ||
$palette = $GLOBALS['TL_DCA']['tl_settings']['palettes']; | ||
$palette = isset($palette['default']) ? $palette['default'] : $palette; | ||
|
||
$GLOBALS['TL_DCA']['tl_settings']['fields']['recaptchaPublicKey'] = [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['recaptchaPublicKey'], | ||
'inputType' => 'text', | ||
'eval' => ['tl_class' => 'w50'] | ||
]; | ||
$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] = str_replace('{files_legend', '{recaptcha_legend},recaptchaType,recaptchaPublicKey,recaptchaPrivateKey;{files_legend', $palette); | ||
$GLOBALS['TL_DCA']['tl_settings']['palettes']['recaptcha3'] = str_replace('{files_legend', '{recaptcha_legend},recaptchaType,recaptcha3GlobalThreshold,recaptchaPublicKey,recaptchaPrivateKey;{files_legend', $palette); | ||
|
||
$GLOBALS['TL_DCA']['tl_settings']['fields']['recaptchaPrivateKey'] = [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['recaptchaPrivateKey'], | ||
'inputType' => 'text', | ||
'eval' => ['tl_class' => 'w50'] | ||
]; | ||
$GLOBALS['TL_DCA']['tl_settings']['palettes']['__selector__'][] = 'recaptchaType'; | ||
|
||
$GLOBALS['TL_DCA']['tl_settings']['fields']['recaptcha3GlobalThreshold'] = [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['recaptcha3GlobalThreshold'], | ||
'inputType' => 'text', | ||
'default' => '0.5', | ||
'eval' => ['tl_class' => 'w50'] | ||
]; | ||
|
||
$GLOBALS['TL_DCA']['tl_settings']['palettes'] = str_replace('{files_legend', '{recaptcha_legend},recaptchaType,recaptchaPublicKey,recaptchaPrivateKey;{files_legend', $GLOBALS['TL_DCA']['tl_settings']['palettes']); | ||
$GLOBALS['TL_DCA']['tl_settings']['fields'] += [ | ||
'recaptchaType' => [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['recaptchaType'], | ||
'inputType' => 'select', | ||
'options_callback' => function () | ||
{ | ||
return [ | ||
'invisible' => 'reCAPTCHA v2: Invisible', | ||
'recaptcha2' => 'reCAPTCHA v2: Checkbox', | ||
'recaptcha3' => 'reCAPTCHA v3', | ||
]; | ||
}, | ||
'eval' => ['tl_class' => 'w50', 'chosen' => true, 'submitOnChange' => true], | ||
], | ||
'recaptchaPublicKey' => [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['recaptchaPublicKey'], | ||
'inputType' => 'text', | ||
'eval' => ['tl_class' => 'w50 clr'], | ||
], | ||
'recaptchaPrivateKey' => [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['recaptchaPrivateKey'], | ||
'inputType' => 'text', | ||
'eval' => ['tl_class' => 'w50'], | ||
], | ||
'recaptcha3GlobalThreshold' => [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['recaptcha3GlobalThreshold'], | ||
'inputType' => 'text', | ||
'default' => '0.5', | ||
'eval' => ['tl_class' => 'w50'], | ||
], | ||
]; |
38 changes: 38 additions & 0 deletions
38
src/Resources/contao/elements/ContentBackgroundRecaptcha.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Contao; | ||
|
||
class ContentBackgroundRecaptcha extends ContentElement | ||
{ | ||
protected $strTemplate = 'ce_background_recaptcha'; | ||
|
||
protected function compile() | ||
{ | ||
if (TL_MODE == 'BE') { | ||
$this->generateBackendOutput(); | ||
} else { | ||
$this->generateFrontendOutput(); | ||
} | ||
} | ||
|
||
protected function generateBackendOutput() | ||
{ | ||
$this->strTemplate = 'be_wildcard'; | ||
$this->Template = new BackendTemplate($this->strTemplate); | ||
|
||
if (Config::get('recaptchaType') == 'recaptcha3') { | ||
$actionString = $GLOBALS['TL_LANG']['tl_content']['recaptcha_action'][0]; | ||
$this->Template->wildcard = '<strong>' . $actionString . ':</strong> ' . $this->recaptcha_action; | ||
} else { | ||
$this->Template->wildcard = '<span style="color:red;">' . $GLOBALS['TL_LANG']['tl_content']['recaptcha_wrong_type'] . '</span>'; | ||
} | ||
} | ||
|
||
protected function generateFrontendOutput() | ||
{ | ||
$this->Template->id = $this->id; | ||
$this->Template->recaptchaType = Config::get('recaptchaType'); | ||
$this->Template->publicKey = Config::get('recaptchaPublicKey'); | ||
$this->Template->action = $this->recaptcha_action; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_LANG']['ERR']['recaptcha'] = "reCAPTCHA konnte nicht bestätigen, dass Sie kein Roboter sind. Bitte versuchen Sie es noch einmal."; | ||
|
||
$GLOBALS['TL_LANG']['CTE']['miscellaneous'] = "Verschiedenes"; | ||
$GLOBALS['TL_LANG']['CTE']['backgroundrecaptcha'][0] = "Hintergrund reCAPTCHA v3"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_LANG']['tl_content']['description_legend'] = "reCAPTCHA Einstellungen"; | ||
$GLOBALS['TL_LANG']['tl_content']['recaptcha_action'][0] = "reCAPTCHA Aktions-Name"; | ||
$GLOBALS['TL_LANG']['tl_content']['recaptcha_wrong_type'] = "Dieses Inhaltselement funktioniert nur, wenn reCAPTCHA v3 ausgewählt ist."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_threshold'][0] = "Score-Minimum"; | ||
$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_threshold'][1] = "reCAPTCHA v3 bewertet Nutzeraktionen mit einem Wert zwischen 0 und 1, wobei 1 für einen sehr wahrscheinlich guten Nutzer und 0 für einen Bot steht. Wenn ein globales Minimum gesetzt wird, muss die Bewertung von Google mindestens diesen Wert erreichen, damit das Captcha als Erfolg gezählt wird."; | ||
|
||
$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_action'][0] = "reCaptcha Aktion"; | ||
$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_action'][1] = "Nutzt als Standardwert das Formularalias."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_LANG']['ERR']['recaptcha'] = "reCAPTCHA could not verify that you're not a robot. Please try again."; | ||
|
||
$GLOBALS['TL_LANG']['CTE']['miscellaneous'] = "Miscellaneous"; | ||
$GLOBALS['TL_LANG']['CTE']['backgroundrecaptcha'][0] = "Background reCAPTCHA v3"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_LANG']['tl_content']['description_legend'] = "reCAPTCHA settings"; | ||
$GLOBALS['TL_LANG']['tl_content']['recaptcha_action'][0] = "reCAPTCHA action name"; | ||
$GLOBALS['TL_LANG']['tl_content']['recaptcha_wrong_type'] = "This content element only works if reCAPTCHA v3 is selected."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_threshold'][0] = "Score threshold"; | ||
$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_threshold'][1] = "reCAPTCHA v3 returns a score, based on which you can decide if a user is likely a bot or a human. A score of 1 most likely resembles a human, a score of 0 is most likely a bot. Any captcha request made has to be above this score to be considered safe."; | ||
|
||
$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_action'][0] = "reCaptcha action"; | ||
$GLOBALS['TL_LANG']['tl_form_field']['recaptcha3_action'][1] = "Will use the form's alias as a default if not overridden here"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php if ($this->recaptchaType != 'recaptcha3') return; ?> | ||
|
||
<script src="https://www.google.com/recaptcha/api.js?onload=onRecaptchaLoadCallbackModule<?= $this->id ?>&render=<?= $this->publicKey ?>" defer async></script> | ||
<script type="text/javascript" defer async> | ||
function onRecaptchaLoadCallbackModule<?= $this->id ?> () { | ||
grecaptcha.execute('<?= $this->publicKey ?>', {action: '<?= $this->action ?>'}) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters