From 0f2e159382224341f407974097de57c5d0015cec Mon Sep 17 00:00:00 2001 From: Tom Slominski Date: Sun, 8 Mar 2015 15:30:54 +0000 Subject: [PATCH] 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. --- index.php | 22 +++++++++++++++++----- public/config-sample.php | 2 ++ public/style.css | 4 ++++ result.php | 22 ++++++++++++++++------ 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index b24ae95..d0e4ea3 100644 --- a/index.php +++ b/index.php @@ -31,11 +31,23 @@ $title = isset( $_REQUEST['title'] ) ? yourls_sanitize_title( $_REQUEST['title -
-

-

-
-
+ +
+

+

+
+
+ + +
diff --git a/public/config-sample.php b/public/config-sample.php index 3388bc4..475fbe3 100644 --- a/public/config-sample.php +++ b/public/config-sample.php @@ -40,6 +40,8 @@ ISQ::$social = array( // reCAPTCHA API KEYS // 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( 'sitekey' => '', 'secret' => '' diff --git a/public/style.css b/public/style.css index 10e956a..f8f7743 100644 --- a/public/style.css +++ b/public/style.css @@ -48,6 +48,10 @@ a, a:visited { box-shadow: 0 0 3px 0 #CCC; } +.hidden { + display: none; +} + /* Header */ .site-header { margin: 0 auto; diff --git a/result.php b/result.php index 079b809..a3383ca 100644 --- a/result.php +++ b/result.php @@ -3,16 +3,26 @@ $dependencies = array( 'ZeroClipboard' ); include('header.php'); -$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); - -// What happens when the CAPTCHA was completed incorrectly -if ($recaptcha_json['success'] != 'true') { - echo '

' . yourls__( 'Are you a bot? Google certainly thinks so. Please go back and try again.', 'isq_translation' ) . '

'; +function display_error($message) { + echo '

' . $message . '

'; 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_json = json_decode($recaptcha_data, TRUE); + + // What happens when the CAPTCHA was completed incorrectly + if ( $recaptcha_json['success'] != 'true' ) { + display_error( yourls__( 'Are you a bot? Google certainly thinks you are. Please go back and try again.', 'isq_translation' ) ); + } +} 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'] ) : ''; $keyword = isset( $_REQUEST['keyword'] ) ? yourls_sanitize_keyword( $_REQUEST['keyword'] ) : '' ; $title = isset( $_REQUEST['title'] ) ? yourls_sanitize_title( $_REQUEST['title'] ) : '' ;