Skip to content

Commit e8189c8

Browse files
committed
First release on GitHub
0 parents  commit e8189c8

File tree

38 files changed

+1789
-0
lines changed

38 files changed

+1789
-0
lines changed

.php_cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
if (PHP_SAPI !== 'cli') {
4+
die('This script supports command line usage only. Please check your command.');
5+
}
6+
7+
$finder = PhpCsFixer\Finder::create()
8+
->exclude('Configuration')
9+
->exclude('Documentation')
10+
->exclude('Resources')
11+
->in(__DIR__)
12+
;
13+
14+
return PhpCsFixer\Config::create()
15+
->setUsingCache(false)
16+
->setRiskyAllowed(true)
17+
->setRules(array(
18+
'@PSR2' => true,
19+
'blank_line_after_opening_tag' => true,
20+
'blank_line_before_return' => true,
21+
'method_separation' => true,
22+
'no_empty_comment' => true,
23+
'no_empty_phpdoc' => true,
24+
'phpdoc_add_missing_param_annotation' => true,
25+
'phpdoc_align' => true,
26+
'phpdoc_annotation_without_dot' => true,
27+
'phpdoc_indent' => true,
28+
'phpdoc_inline_tag' => true,
29+
'phpdoc_no_access' => true,
30+
'phpdoc_no_alias_tag' => true,
31+
'phpdoc_no_empty_return' => true,
32+
'phpdoc_no_package' => true,
33+
'phpdoc_no_useless_inheritdoc' => true,
34+
'phpdoc_order' => true,
35+
'phpdoc_return_self_reference' => true,
36+
'phpdoc_scalar' => true,
37+
'phpdoc_separation' => true,
38+
'phpdoc_single_line_var_spacing' => true,
39+
'phpdoc_summary' => true,
40+
'phpdoc_to_comment' => true,
41+
'phpdoc_trim' => true,
42+
'phpdoc_types' => true,
43+
'phpdoc_var_without_name' => true,
44+
'space_after_semicolon' => true,
45+
'standardize_not_equals' => true
46+
))
47+
->setFinder($finder)
48+
;

Classes/ErrorCheck/ReCaptcha.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* Class Tx_JhCaptcha_ErrorCheck_ReCaptcha
5+
* EXT:formhandler ErrorCheck for ReCaptcha.
6+
*
7+
* @deprecated TODO remove this if TYPO3 6.2 is deprecated
8+
*/
9+
class Tx_JhCaptcha_ErrorCheck_ReCaptcha extends Tx_Formhandler_AbstractErrorCheck
10+
{
11+
/**
12+
* Checks the ReCaptcha.
13+
*
14+
* @return string
15+
*/
16+
public function check()
17+
{
18+
$checkFailed = '';
19+
if (isset($this->gp[$this->formFieldName])) {
20+
$reCaptchaValidator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Haffner\JhCaptcha\Validation\Validator\ReCaptchaValidator');
21+
// validate the captcha
22+
$result = $reCaptchaValidator->validate($this->gp[$this->formFieldName]);
23+
// check errors
24+
if ($result->getErrors()) {
25+
$checkFailed = $this->getCheckFailed();
26+
}
27+
}
28+
29+
return $checkFailed;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Haffner\JhCaptcha\Validation\ErrorCheck;
4+
5+
/**
6+
* EXT:formhandler ErrorCheck for ReCaptcha.
7+
*/
8+
class ReCaptcha extends \Typoheads\Formhandler\Validator\ErrorCheck\AbstractErrorCheck
9+
{
10+
/**
11+
* Checks the ReCaptcha.
12+
*
13+
* @return string
14+
*/
15+
public function check()
16+
{
17+
$checkFailed = '';
18+
if (isset($this->gp[$this->formFieldName])) {
19+
$reCaptchaValidator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Haffner\JhCaptcha\Validation\Validator\ReCaptchaValidator');
20+
// validate the captcha
21+
$result = $reCaptchaValidator->validate($this->gp[$this->formFieldName]);
22+
// check errors
23+
if ($result->getErrors()) {
24+
$checkFailed = $this->getCheckFailed();
25+
}
26+
}
27+
28+
return $checkFailed;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Haffner\JhCaptcha\Validation\Validator;
4+
5+
abstract class AbstractCaptchaValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
6+
{
7+
8+
/**
9+
* @var array Extension TypoScript
10+
*/
11+
protected $settings;
12+
13+
public function __construct(array $options = array())
14+
{
15+
parent::__construct($options);
16+
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
17+
$configurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface');
18+
$this->settings = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'JhCaptcha');
19+
}
20+
21+
/**
22+
* Validate function for the powermail extension.
23+
*
24+
* @param \In2code\Powermail\Domain\Model\Mail $mail the form field
25+
* @param \In2code\Powermail\Domain\Validator\CustomValidator $customValidator the validator from powermail
26+
*/
27+
abstract public function validateCaptchaInPowermail($mail, $customValidator);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Haffner\JhCaptcha\Validation\Validator;
4+
5+
class ReCaptchaValidator extends \Haffner\JhCaptcha\Validation\Validator\AbstractCaptchaValidator
6+
{
7+
/**
8+
* Check if $value is valid. If it is not valid, needs to add an error
9+
* to Result.
10+
*
11+
* @param mixed $value
12+
*/
13+
protected function isValid($value)
14+
{
15+
$extensionName = 'jh_captcha';
16+
$secret = $this->settings['reCaptcha']['secretKey'];
17+
$url = 'https://www.google.com/recaptcha/api/siteverify';
18+
$apiResponse = json_decode(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($url.'?secret='.$secret.'&response='.$value), true);
19+
if ($apiResponse['success'] == false) {
20+
if (is_array($apiResponse['error-codes'])) {
21+
foreach ($apiResponse['error-codes'] as $errorCode) {
22+
switch ($errorCode) {
23+
case 'missing-input-secret':
24+
$this->addError($this->translateErrorMessage('missingInputSecret', $extensionName), 1426877004);
25+
break;
26+
case 'invalid-input-secret':
27+
$this->addError($this->translateErrorMessage('invalidInputSecret', $extensionName), 1426877455);
28+
break;
29+
case 'missing-input-response':
30+
$this->addError($this->translateErrorMessage('missingInputResponse', $extensionName), 1426877525);
31+
break;
32+
case 'invalid-input-response':
33+
$this->addError($this->translateErrorMessage('invalidInputResponse', $extensionName), 1426877590);
34+
break;
35+
default:
36+
$this->addError($this->translateErrorMessage('defaultError', $extensionName), 1427031929);
37+
}
38+
}
39+
} else {
40+
$this->addError($this->translateErrorMessage('defaultError', $extensionName), 1427031929);
41+
}
42+
}
43+
}
44+
45+
/**
46+
* Validate function for the powermail extension.
47+
*
48+
* @param \In2code\Powermail\Domain\Model\Mail $mail the form field
49+
* @param \In2code\Powermail\Domain\Validator\CustomValidator $customValidator the validator from powermail
50+
*/
51+
public function validateCaptchaInPowermail($mail, $customValidator)
52+
{
53+
foreach ($mail->getAnswers() as $answer) {
54+
if ($answer->getField()->getType() == 'jhcaptcharecaptcha') {
55+
// validate the captcha
56+
$result = $this->validate($answer->getValue());
57+
// set error messages if necessary
58+
$errors = $result->getErrors();
59+
if (!empty($errors)) {
60+
foreach ($errors as $error) {
61+
$customValidator->setErrorAndMessage($answer->getField(), $error->getMessage());
62+
}
63+
}
64+
// remove captcha field from the mail
65+
$mail->removeAnswer($answer);
66+
}
67+
}
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Haffner\JhCaptcha\ViewHelpers;
4+
5+
class ReCaptchaViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
6+
{
7+
8+
/**
9+
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
10+
*/
11+
protected $configurationManager;
12+
13+
/**
14+
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
15+
*/
16+
public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
17+
{
18+
$this->configurationManager = $configurationManager;
19+
}
20+
21+
public function render()
22+
{
23+
$settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'JhCaptcha');
24+
$siteKey = $settings['reCaptcha']['siteKey'];
25+
$theme = $settings['reCaptcha']['theme'];
26+
$type = $settings['reCaptcha']['type'];
27+
$lang = $settings['reCaptcha']['lang'];
28+
$size = $settings['reCaptcha']['size'];
29+
30+
$reCaptchaApi = '<script src="https://www.google.com/recaptcha/api.js?hl='.$lang.'" async defer></script>';
31+
$callBack = '<script type="text/javascript">var captchaCallback = function() { document.getElementById("captchaResponse").value = document.getElementById("g-recaptcha-response").value }</script>';
32+
$reCaptcha = '<div class="g-recaptcha" data-sitekey="'.$siteKey.'" data-theme="'.$theme.
33+
'" data-callback="captchaCallback" data-type="'.$type.'" data-size="'.$size.'"></div>';
34+
35+
if ($siteKey) {
36+
return $reCaptchaApi.$callBack.$reCaptcha;
37+
} else {
38+
return \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('setApiKey', null, null);
39+
}
40+
}
41+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
plugin.tx_jhcaptcha {
3+
settings {
4+
reCaptcha {
5+
# cat=plugin.tx_jhcaptcha/recaptcha; type=options[dark,light]; label=The color theme of the widget
6+
theme = light
7+
# cat=plugin.tx_jhcaptcha/recaptcha; type=options[audio,image]; label=The type of CAPTCHA to serve
8+
type = image
9+
# cat=plugin.tx_jhcaptcha/recaptcha; type=string; label=The language of the widget: See https://developers.google.com/recaptcha/docs/language
10+
lang = en
11+
# cat=plugin.tx_jhcaptcha/recaptcha; type=options[normal,compact]; label=The size of the widget
12+
size = normal
13+
# cat=plugin.tx_jhcaptcha/recaptcha; type=string; label=Site key: See https://www.google.com/recaptcha/admin
14+
siteKey =
15+
# cat=plugin.tx_jhcaptcha/recaptcha; type=string; label=Secret key: See https://www.google.com/recaptcha/admin
16+
secretKey =
17+
}
18+
}
19+
}

Configuration/TypoScript/setup.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
plugin.tx_jhcaptcha {
3+
settings {
4+
reCaptcha {
5+
theme = {$plugin.tx_jhcaptcha.settings.reCaptcha.theme}
6+
type = {$plugin.tx_jhcaptcha.settings.reCaptcha.type}
7+
lang = {$plugin.tx_jhcaptcha.settings.reCaptcha.lang}
8+
size = {$plugin.tx_jhcaptcha.settings.reCaptcha.size}
9+
siteKey = {$plugin.tx_jhcaptcha.settings.reCaptcha.siteKey}
10+
secretKey = {$plugin.tx_jhcaptcha.settings.reCaptcha.secretKey}
11+
}
12+
}
13+
}
14+
15+
plugin.Tx_Formhandler.settings {
16+
markers.jh_captcha_recaptcha = FLUIDTEMPLATE
17+
markers.jh_captcha_recaptcha.file = EXT:jh_captcha/Resources/Private/Partials/Formhandler/ReCaptcha.html
18+
}

Documentation/ChangeLog/Index.rst

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.. ==================================================
2+
.. FOR YOUR INFORMATION
3+
.. --------------------------------------------------
4+
.. -*- coding: utf-8 -*- with BOM.
5+
6+
.. include:: ../Includes.txt
7+
8+
9+
.. _changelog:
10+
11+
ChangeLog
12+
=========
13+
14+
1.3.x
15+
-----
16+
17+
1.3.1
18+
^^^^^
19+
20+
* Support for formhandler 2.3-2.4
21+
* Support for powermail 3.x
22+
* Bugfix formhandler error check (PHP 5.3)
23+
24+
1.3.0
25+
^^^^^
26+
27+
* reCAPTCHA data-size attribute added: https://forge.typo3.org/issues/73642
28+
* composer.json added: https://forge.typo3.org/issues/72675#note-3
29+
30+
1.2.x
31+
-----
32+
33+
1.2.1
34+
^^^^^
35+
36+
* Support for TYPO3 CMS 7.6.x
37+
* Revised documentation
38+
* Comments for Constant Editor added
39+
40+
1.2.0
41+
^^^^^
42+
43+
* Support for formhandler: https://forge.typo3.org/issues/66829
44+
45+
1.1.x
46+
-----
47+
48+
1.1.1
49+
^^^^^
50+
51+
* Support for TYPO3 CMS 7.4.x
52+
* Revised documentation
53+
54+
1.1.0
55+
^^^^^
56+
57+
* Support for powermail: https://forge.typo3.org/issues/66301
58+
* Support for TYPO3 CMS 7.1.x
59+
* Revised documentation
60+
61+
1.0.x
62+
-----
63+
64+
1.0.2
65+
^^^^^
66+
67+
* Bug fix: https://forge.typo3.org/issues/66010
68+
* Corrections in German documentation
69+
* Extension category changed to "Frontend"
70+
71+
1.0.1
72+
^^^^^
73+
74+
* Extension description changed
75+
* Bug fix: https://forge.typo3.org/issues/65968

0 commit comments

Comments
 (0)