Giving users the option not to use reCAPTCHA. If you don't input reCAPTCHA keys, basic spam protection will be enabled, even though its less effective.

This commit is contained in:
Tom Slominski
2015-03-08 15:30:54 +00:00
parent 9ba1309746
commit 0f2e159382
4 changed files with 39 additions and 11 deletions

View File

@@ -31,11 +31,23 @@ $title = isset( $_REQUEST['title'] ) ? yourls_sanitize_title( $_REQUEST['title
</div> </div>
<?php
if ( !empty(ISQ::$recaptcha['sitekey']) && !empty(ISQ::$recaptcha['secret']) ) {
?>
<div class="form-item recaptcha-container"> <div class="form-item recaptcha-container">
<p><label class="primary" title=""><?php yourls_e( 'Verification', 'isq_translation'); ?></label></p> <p><label class="primary" title=""><?php yourls_e( 'Verification', 'isq_translation'); ?></label></p>
<p><label class="secondary"><?php yourls_e( 'reCAPTCHA verification used to ensure you are not a bot.', 'isq_translation'); ?></label></p> <p><label class="secondary"><?php yourls_e( 'reCAPTCHA verification used to ensure you are not a bot.', 'isq_translation'); ?></label></p>
<div class="g-recaptcha" data-sitekey="<?php echo ISQ::$recaptcha['sitekey']; ?>"></div> <div class="g-recaptcha" data-sitekey="<?php echo ISQ::$recaptcha['sitekey']; ?>"></div>
</div> </div>
<?php
} else {
?>
<div class="hidden">
<input type="hidden" name="basic_antispam">
</div>
<?php
}
?>
<div class="form-item submit-container"> <div class="form-item submit-container">
<input type="submit" class="button" value="<?php yourls_e( 'Shorten', 'isq_translation'); ?>"> <input type="submit" class="button" value="<?php yourls_e( 'Shorten', 'isq_translation'); ?>">

View File

@@ -40,6 +40,8 @@ ISQ::$social = array(
// reCAPTCHA API KEYS // reCAPTCHA API KEYS
// Get yourls from https://www.google.com/recaptcha/admin // Get yourls from https://www.google.com/recaptcha/admin
// If you don't want to use reCAPTCHA, that's cool. Leave this empty, and basic
// antispam protection will be provided.
ISQ::$recaptcha = array( ISQ::$recaptcha = array(
'sitekey' => '', 'sitekey' => '',
'secret' => '' 'secret' => ''

View File

@@ -48,6 +48,10 @@ a, a:visited {
box-shadow: 0 0 3px 0 #CCC; box-shadow: 0 0 3px 0 #CCC;
} }
.hidden {
display: none;
}
/* Header */ /* Header */
.site-header { .site-header {
margin: 0 auto; margin: 0 auto;

View File

@@ -3,14 +3,24 @@ $dependencies = array( 'ZeroClipboard' );
include('header.php'); include('header.php');
function display_error($message) {
echo '<div class="content"><p class="error">' . $message . '</p></div>';
include('footer.php');
die();
}
if ( !empty(ISQ::$recaptcha['sitekey']) && !empty(ISQ::$recaptcha['secret']) ) {
$recaptcha_data = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . ISQ::$recaptcha['secret'] . '&response=' . $_REQUEST['g-recaptcha-response']); $recaptcha_data = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . ISQ::$recaptcha['secret'] . '&response=' . $_REQUEST['g-recaptcha-response']);
$recaptcha_json = json_decode($recaptcha_data, TRUE); $recaptcha_json = json_decode($recaptcha_data, TRUE);
// What happens when the CAPTCHA was completed incorrectly // What happens when the CAPTCHA was completed incorrectly
if ( $recaptcha_json['success'] != 'true' ) { if ( $recaptcha_json['success'] != 'true' ) {
echo '<div class="content"><p class="error">' . yourls__( 'Are you a bot? Google certainly thinks so. Please go back and try again.', 'isq_translation' ) . '</p></div>'; display_error( yourls__( 'Are you a bot? Google certainly thinks you are. Please go back and try again.', 'isq_translation' ) );
include('footer.php'); }
die(); } else {
if ( $_REQUEST['basic_antispam'] != "" ) {
display_error( yourls__( 'Are you a bot? The verification was not completed successfully. Please go back and try again.', 'isq_translation' ) );
}
} }
$url = isset( $_REQUEST['url'] ) ? yourls_sanitize_url( $_REQUEST['url'] ) : ''; $url = isset( $_REQUEST['url'] ) ? yourls_sanitize_url( $_REQUEST['url'] ) : '';