Skip to content
Snippets Groups Projects
Commit 8448563a authored by Liam Morland's avatar Liam Morland
Browse files

Fix coding standards

parent 45bf6991
No related branches found
No related merge requests found
<?php
/**
* @file recaptcha-widget-noscript.tpl.php
* @file
* Default theme implementation to present the reCAPTCHA noscript code.
*
* Available variables:
......
......@@ -25,16 +25,16 @@ function recaptcha_uninstall() {
*/
function recaptcha_update_7200() {
// Migrate the public key to site key.
// Upgrade from 6.x-2.x to 7.x-2.x
// Upgrade from 6.x-2.x to 7.x-2.x.
$site_key = variable_get('recaptcha_site_key', '');
// Upgrade from 7.x-1.x to 7.x-2.x
// Upgrade from 7.x-1.x to 7.x-2.x.
$public_key = variable_get('recaptcha_public_key', $site_key);
variable_set('recaptcha_site_key', $public_key);
variable_del('recaptcha_public_key');
// Upgrade from 6.x-2.x to 7.x-2.x
// Upgrade from 6.x-2.x to 7.x-2.x.
$secret_key = variable_get('recaptcha_secret_key', '');
// Upgrade from 7.x-1.x to 7.x-2.x
// Upgrade from 7.x-1.x to 7.x-2.x.
$private_key = variable_get('recaptcha_private_key', $secret_key);
variable_set('recaptcha_secret_key', $private_key);
variable_del('recaptcha_private_key');
......@@ -47,7 +47,7 @@ function recaptcha_update_7200() {
'clean' => 'light',
'custom' => 'light',
);
// Upgrade from 6.x-2.x to 7.x-2.x
// Upgrade from 6.x-2.x to 7.x-2.x.
$recaptcha_themes += array(
'light' => 'light',
'dark' => 'dark',
......@@ -70,7 +70,7 @@ function recaptcha_update_7200() {
// - recaptcha_mailhide_public_key
// - recaptcha_mailhide_public_key_*
// - recaptcha_mailhide_private_key
// - recaptcha_mailhide_private_key_*
// - recaptcha_mailhide_private_key_*.
db_delete('variable')
->condition('name', 'recaptcha_mailhide_%', 'LIKE')
->execute();
......
......@@ -11,6 +11,9 @@ require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/RequestParameters
require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/Response.php';
require_once dirname(__FILE__) . '/src/ReCaptcha/RequestMethod/Drupal7Post.php';
use ReCaptcha\ReCaptcha;
use ReCaptcha\RequestMethod\Drupal7Post;
/**
* Implements hook_help().
*/
......@@ -109,7 +112,7 @@ function recaptcha_captcha($op, $captcha_type = '') {
$variables = array(
'sitekey' => $recaptcha_site_key,
'language' => $language->language,
'recaptcha_src_fallback' => $recaptcha_src_fallback
'recaptcha_src_fallback' => $recaptcha_src_fallback,
);
$noscript = theme('recaptcha_widget_noscript', array('widget' => $variables));
}
......@@ -130,13 +133,30 @@ function recaptcha_captcha($op, $captcha_type = '') {
'#suffix' => $noscript,
);
// @todo: #1664602: D7 does not yet support "async" in drupal_add_js().
// drupal_add_js(url('https://www.google.com/recaptcha/api.js', array('query' => array('hl' => $language->language), 'absolute' => TRUE)), array('defer' => TRUE, 'async' => TRUE, 'type' => 'external'));
// @todo #1664602: D7 does not yet support "async" in drupal_add_js().
// drupal_add_js(
// url(
// 'https://www.google.com/recaptcha/api.js',
// array(
// 'query' => array(
// 'hl' => $language->language
// ),
// 'absolute' => TRUE),
// ),
// array('defer' => TRUE, 'async' => TRUE, 'type' => 'external')
// );
$data = array(
'#tag' => 'script',
'#value' => '',
'#attributes' => array(
'src' => url($recaptcha_src, array('query' => array('hl' => $language->language), 'absolute' => TRUE)),
'src' => url(
$recaptcha_src,
array(
'query' => array(
'hl' => $language->language,
),
'absolute' => TRUE),
),
'async' => 'async',
'defer' => 'defer',
),
......@@ -162,7 +182,7 @@ function recaptcha_captcha_validation($solution, $response, $element, $form_stat
}
// Use drupal_http_request() to circumvent all issues with the Google library.
$recaptcha = new \ReCaptcha\ReCaptcha($recaptcha_secret_key, new \ReCaptcha\RequestMethod\Drupal7Post());
$recaptcha = new ReCaptcha($recaptcha_secret_key, new Drupal7Post());
// Ensures the hostname matches. Required if "Domain Name Validation" is
// disabled for credentials.
......@@ -223,5 +243,12 @@ function recaptcha_captcha_validation($solution, $response, $element, $form_stat
function template_preprocess_recaptcha_widget_noscript(&$variables) {
$variables['sitekey'] = check_plain($variables['widget']['sitekey']);
$variables['language'] = check_plain($variables['widget']['language']);
$variables['url'] = check_url(url($variables['widget']['recaptcha_src_fallback'], array('query' => array('k' => $variables['widget']['sitekey'], 'hl' => $variables['widget']['language']), 'absolute' => TRUE)));
$options = array(
'query' => array(
'k' => $variables['widget']['sitekey'],
'hl' => $variables['widget']['language'],
),
'absolute' => TRUE,
);
$variables['url'] = check_url(url($variables['widget']['recaptcha_src_fallback'], $options));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment