reCAPTCHA support

This commit is contained in:
Tom Slominski
2013-11-02 18:19:38 +00:00
parent c97d882872
commit e898da7e6c
4 changed files with 37 additions and 16 deletions

View File

@@ -5,7 +5,7 @@ require_once( dirname(__FILE__).'/includes/load-yourls.php' );
// Ask for Infinity Squared settings // Ask for Infinity Squared settings
include( dirname(__FILE__).'/public/config.php' ); include( dirname(__FILE__).'/public/config.php' );
class ISQ { public static $general = array(), $links = array(), $social = array(); } class ISQ { public static $general = array(), $links = array(), $social = array(), $recaptcha = array(); }
// Load translations // Load translations
function isq_load_textdomain() { function isq_load_textdomain() {
@@ -27,6 +27,9 @@ if ( $message = $url. yourls__( 'added to database', 'isq_translation') ) {
} elseif ( $message = yourls__( 'This URL is a short URL', 'isq_translation') ) { } elseif ( $message = yourls__( 'This URL is a short URL', 'isq_translation') ) {
$error = $genericerror . '<p class="error">' . yourls__( 'You cannot shorten a short URL!', 'isq_translation') . '</p>'; $error = $genericerror . '<p class="error">' . yourls__( 'You cannot shorten a short URL!', 'isq_translation') . '</p>';
} }
// Load reCAPTCHA
require_once('public/recaptchalib.php');
?> ?>
<html> <html>
@@ -65,6 +68,11 @@ if ( $message = $url. yourls__( 'added to database', 'isq_translation') ) {
{lang: "en-GB"} {lang: "en-GB"}
</script> </script>
<?php } ?> <?php } ?>
<script type="text/javascript"><!-- reCAPTCHA -->
var RecaptchaOptions = {
theme : 'clean'
};
</script>
<?php if (!empty(ISQ::$general['clipboard'])) { ?> <?php if (!empty(ISQ::$general['clipboard'])) { ?>
<script type="text/javascript" src="js/jquery.zclip.min.js"></script> <script type="text/javascript" src="js/jquery.zclip.min.js"></script>
<script> <script>

View File

@@ -6,7 +6,8 @@
<p><label for="url" title="<?php yourls_e( 'Paste the long URL here', 'isq_translation'); ?>"><?php yourls_e( 'Long URL (required):', 'isq_translation'); ?></label> <input type="text" id="url" class="right" name="url" /></p> <p><label for="url" title="<?php yourls_e( 'Paste the long URL here', 'isq_translation'); ?>"><?php yourls_e( 'Long URL (required):', 'isq_translation'); ?></label> <input type="text" id="url" class="right" name="url" /></p>
<p><label for="keyword" title="<?php yourls_e( 'A keyword replaces the default short string', 'isq_translation'); ?>"><?php yourls_e( 'Custom keyword:', 'isq_translation'); ?></label> <input type="text" id="keyword" class="right" name="keyword" /></p> <p><label for="keyword" title="<?php yourls_e( 'A keyword replaces the default short string', 'isq_translation'); ?>"><?php yourls_e( 'Custom keyword:', 'isq_translation'); ?></label> <input type="text" id="keyword" class="right" name="keyword" /></p>
<p><label for="title" title="<?php yourls_e( 'Optional title used when sharing a link from YOURLS', 'isq_translation'); ?>"><?php yourls_e( 'Optional title:', 'isq_translation'); ?></label> <input type="text" id="title" class="right" name="title" /></p> <p><label for="title" title="<?php yourls_e( 'Optional title used when sharing a link from YOURLS', 'isq_translation'); ?>"><?php yourls_e( 'Optional title:', 'isq_translation'); ?></label> <input type="text" id="title" class="right" name="title" /></p>
<p><label for="antispam" title="<?php yourls_e( 'This is an antispam check. Sorry, we have to do this to prevent the database being overrun by bots!', 'isq_translation'); ?>"><?php yourls_e( 'reCAPTCHA', 'isq_translation'); ?></label> <span class="right"></span></p> <p><label for="antispam" title="<?php yourls_e( 'This is an antispam check. Sorry, we have to do this to prevent the database being overrun by bots!', 'isq_translation'); ?>"><?php yourls_e( 'reCAPTCHA', 'isq_translation'); ?></label> <span class="right"><?php echo recaptcha_get_html(ISQ::$recaptcha['public']); ?></span></p>
<p><input type="submit" value="<?php yourls_e( 'Shorten', 'isq_translation'); ?>" /></p> <p><input type="submit" value="<?php yourls_e( 'Shorten', 'isq_translation'); ?>" /></p>
</form> </form>

View File

@@ -43,4 +43,11 @@ ISQ::$social = array(
'plus' => 1, 'plus' => 1,
'linkedin' => 1 'linkedin' => 1
); );
// reCAPTCHA API keys
// Get yourls from https://www.google.com/recaptcha/admin
ISQ::$recaptcha = array(
'public' => '',
'private' => ''
);
?> ?>

View File

@@ -1,20 +1,6 @@
<?php <?php
include('header.php'); include('header.php');
// antispam
// if ( isset($_POST['antispam']) && $_POST['antispam'] != user ) {
// exit('<p class="error">' . yourls__( 'Antispam check failed!', 'isq_translation') . '</p>');
// }
$url = yourls_sanitize_url( $_REQUEST['url'] );
$keyword = isset( $_REQUEST['keyword'] ) ? yourls_sanitize_keyword( $_REQUEST['keyword'] ): '' ;
$title = isset( $_REQUEST['title'] ) ? yourls_sanitize_title( $_REQUEST['title'] ) : '' ;
$return = yourls_add_new_link( $url, $keyword, $title );
$shorturl = isset( $return['shorturl'] ) ? $return['shorturl'] : '';
$message = isset( $return['message'] ) ? $return['message'] : '';
$title = isset( $return['title'] ) ? $return['title'] : '';
// Stop here if bookmarklet with a JSON callback function ("instant" bookmarklets) -- code from YOURLS // Stop here if bookmarklet with a JSON callback function ("instant" bookmarklets) -- code from YOURLS
if( isset( $_GET['jsonp'] ) && $_GET['jsonp'] == 'yourls' ) { if( isset( $_GET['jsonp'] ) && $_GET['jsonp'] == 'yourls' ) {
$short = $return['shorturl'] ? $return['shorturl'] : ''; $short = $return['shorturl'] ? $return['shorturl'] : '';
@@ -25,6 +11,25 @@ if( isset( $_GET['jsonp'] ) && $_GET['jsonp'] == 'yourls' ) {
die(); die();
} }
$resp = recaptcha_check_answer (ISQ::$recaptcha['private'],
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ( '<p class="error" title="' . $resp->error . '">' . yourls__( 'The reCAPTCHA wasn\'t entered correctly. Go back and try it again.', 'isq_translation' ) . '</p></div></div>' );
}
$url = yourls_sanitize_url( $_REQUEST['url'] );
$keyword = isset( $_REQUEST['keyword'] ) ? yourls_sanitize_keyword( $_REQUEST['keyword'] ): '' ;
$title = isset( $_REQUEST['title'] ) ? yourls_sanitize_title( $_REQUEST['title'] ) : '' ;
$return = yourls_add_new_link( $url, $keyword, $title );
$shorturl = isset( $return['shorturl'] ) ? $return['shorturl'] : '';
$message = isset( $return['message'] ) ? $return['message'] : '';
$title = isset( $return['title'] ) ? $return['title'] : '';
?> ?>
<!-- Error reporting --> <!-- Error reporting -->