Skip to content

Commit

Permalink
feat(): Support for osTickets 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMarquezF committed Oct 18, 2022
1 parent e4aaac1 commit 9cd5ce5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion recaptchav2/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getOptions() {
))
);
}
function pre_save($config, &$errors) {
function pre_save(&$config, &$errors) {
// Todo: verify key
if (!function_exists('curl_init')) {
Messages::error('CURL extension is required');
Expand Down
2 changes: 1 addition & 1 deletion recaptchav2/plugin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
return array(
'id' => 'recaptcha',
'version' => '0.1',
'version' => '0.2',
'name' => 'Recaptcha',
'author' => 'David Márquez',
'description' => 'Provides google recaptcha v2 as a form field type to avoid spam',
Expand Down
19 changes: 9 additions & 10 deletions recaptchav2/recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@

class reCaptchaField extends FormField
{
static $g_site_key;
static $g_secret_key;

static $widget = 'reCaptchaWidget';
static $plugin_config;
function getPluginConfig()
{
return static::$plugin_config;
}

function validateEntry($value)
{
parent::validateEntry($value);

$config = $this->getPluginConfig()->getInfo();
if (count(parent::errors()) === 0) {
$response = json_decode(file_get_contents('https://www.recaptcha.net/recaptcha/api/siteverify?secret=' . $config['g-secret-key'] . '&response=' . $value));
$response = json_decode(file_get_contents('https://www.recaptcha.net/recaptcha/api/siteverify?secret=' . self::$g_secret_key . '&response=' . $value));

if ($response == FALSE) {
$this->addError('Unable to communicate with the reCaptcha server');
Expand Down Expand Up @@ -65,11 +63,11 @@ class reCaptchaWidget extends Widget
{
function render()
{
# Form field config
$fconfig = $this->field->getConfiguration();
$pconfig = $this->field->getPluginConfig()->getInfo();

?>
<div id="<?php echo $this->id; ?>" style="display:flex;justify-content:center;" class="g-recaptcha" data-sitekey="<?php echo $pconfig['g-site-key']; ?>" data-theme="<?php echo $fconfig['theme'] ?: 'light'; ?>" data-type="<?php echo $fconfig['type'] ?: 'image'; ?>" data-size="<?php echo $fconfig['size'] ?: 'normal'; ?>"></div>
<div id="<?php echo $this->id; ?>" style="display:flex;justify-content:center;" class="g-recaptcha" data-sitekey="<?php echo reCaptchaField::$g_site_key; ?>" data-theme="<?php echo $fconfig['theme'] ?: 'light'; ?>" data-type="<?php echo $fconfig['type'] ?: 'image'; ?>" data-size="<?php echo $fconfig['size'] ?: 'normal'; ?>"></div>
<script src="https://www.recaptcha.net/recaptcha/api.js" type="application/javascript" async defer></script>
<?php
}
Expand All @@ -88,7 +86,8 @@ class GoogleRecaptchaV2 extends Plugin
var $config_class = "GoogleRecaptchaV2Config";
function bootstrap()
{
reCaptchaField::$plugin_config = $this->getConfig();
$config = $this->getConfig();
reCaptchaField::$g_site_key = $config->get('g-site-key');
FormField::addFieldTypes(__('Verification'), function () {
return array(
'recaptcha' => array('Google reCAPTCHA', 'reCaptchaField')
Expand Down

0 comments on commit 9cd5ce5

Please sign in to comment.