-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Matteo-Peronnet/add-recaptcha
Add recaptcha
- Loading branch information
Showing
18 changed files
with
821 additions
and
478 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
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,20 @@ | ||
<?php | ||
|
||
namespace Victoire\Widget\FormBundle\Helper; | ||
|
||
class RecaptchaHelper | ||
{ | ||
private $recaptchaPublicKey; | ||
private $recaptchaPrivateKey; | ||
|
||
public function __construct($recaptchaPublicKey, $recaptchaPrivateKey) | ||
{ | ||
$this->recaptchaPublicKey = $recaptchaPublicKey; | ||
$this->recaptchaPrivateKey = $recaptchaPrivateKey; | ||
} | ||
|
||
public function canUseReCaptcha() | ||
{ | ||
return $this->recaptchaPublicKey && $this->recaptchaPrivateKey; | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
namespace Victoire\Widget\FormBundle\Resolver; | ||
|
||
use Victoire\Bundle\WidgetBundle\Model\Widget; | ||
use Victoire\Bundle\WidgetBundle\Resolver\BaseWidgetContentResolver; | ||
use Victoire\Widget\FormBundle\Entity\WidgetForm; | ||
use Victoire\Widget\FormBundle\Helper\RecaptchaHelper; | ||
|
||
class WidgetFormContentResolver extends BaseWidgetContentResolver | ||
{ | ||
protected $recaptchaPublicKey; | ||
protected $recaptchaHelper; | ||
|
||
public function __construct($recaptchaPublicKey, RecaptchaHelper $recaptchaHelper) | ||
{ | ||
$this->recaptchaPublicKey = $recaptchaPublicKey; | ||
$this->recaptchaHelper = $recaptchaHelper; | ||
} | ||
|
||
/** | ||
* Get the static content of the widget. | ||
* | ||
* @param Widget $widget | ||
* | ||
* @return string | ||
*/ | ||
public function getWidgetStaticContent(Widget $widget) | ||
{ | ||
$parameters = parent::getWidgetStaticContent($widget); | ||
|
||
return $this->addRecaptchaKey($widget, $parameters); | ||
} | ||
|
||
/** | ||
* Get the business entity content. | ||
* | ||
* @param Widget $widget | ||
* | ||
* @return string | ||
*/ | ||
public function getWidgetBusinessEntityContent(Widget $widget) | ||
{ | ||
$parameters = parent::getWidgetStaticContent($widget); | ||
|
||
return $this->addRecaptchaKey($widget, $parameters); | ||
} | ||
|
||
/** | ||
* Get the content of the widget by the entity linked to it. | ||
* | ||
* @param Widget $widget | ||
* | ||
* @return string | ||
*/ | ||
public function getWidgetEntityContent(Widget $widget) | ||
{ | ||
$parameters = parent::getWidgetStaticContent($widget); | ||
|
||
return $this->addRecaptchaKey($widget, $parameters); | ||
} | ||
|
||
/** | ||
* Get the content of the widget for the query mode. | ||
* | ||
* @param Widget $widget | ||
* | ||
* @return string | ||
*/ | ||
public function getWidgetQueryContent(Widget $widget) | ||
{ | ||
$parameters = parent::getWidgetStaticContent($widget); | ||
|
||
return $this->addRecaptchaKey($widget, $parameters); | ||
} | ||
|
||
protected function addRecaptchaKey(WidgetForm $widget, array $parameters) | ||
{ | ||
if ($widget->isRecaptcha() && $this->recaptchaHelper->canUseReCaptcha()) { | ||
return array_merge($parameters, ['recaptcha_public_key' => $this->recaptchaPublicKey]); | ||
} | ||
|
||
return $parameters; | ||
} | ||
} |
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,6 @@ | ||
.g-recaptcha { | ||
transform:scale(0.90); | ||
-webkit-transform: scale(0.90); | ||
transform-origin:0 0; | ||
-webkit-transform-origin:0 0; | ||
} |
Oops, something went wrong.