X-Git-Url: https://git.toastfreeware.priv.at/toast/cookiecaptcha.git/blobdiff_plain/152f5e39e0ad8115470ee380e567a3ea31db6f1b..2c56bd06f00f0893b6703d36d80cf9c664878ba6:/MathCaptcha.class.php diff --git a/MathCaptcha.class.php b/MathCaptcha.class.php index 01d6391..9b9cde2 100644 --- a/MathCaptcha.class.php +++ b/MathCaptcha.class.php @@ -3,21 +3,30 @@ class MathCaptcha extends SimpleCaptcha { /** Validate a captcha response */ - function keyMatch( $req, $info ) { - return (int)$req->getVal( 'wpCaptchaAnswer' ) == (int)$info['answer']; + function keyMatch( $answer, $info ) { + return (int)$answer == (int)$info['answer']; } - + + function addCaptchaAPI( &$resultArr ) { + list( $sum, $answer ) = $this->pickSum(); + $index = $this->storeCaptcha( array( 'answer' => $answer ) ); + $resultArr['captcha']['type'] = 'math'; + $resultArr['captcha']['mime'] = 'text/tex'; + $resultArr['captcha']['id'] = $index; + $resultArr['captcha']['question'] = $sum; + } + /** Produce a nice little form */ function getForm() { list( $sum, $answer ) = $this->pickSum(); $index = $this->storeCaptcha( array( 'answer' => $answer ) ); - + $form = ''; - $form .= '
' . $this->fetchMath( $sum ) . '' . wfInput( 'wpCaptchaAnswer', false, false, array( 'tabindex' => '1' ) ) . '
'; - $form .= wfHidden( 'wpCaptchaId', $index ); + $form .= '' . Xml::input( 'wpCaptchaWord', false, false, array( 'tabindex' => '1' ) ) . ''; + $form .= Xml::hidden( 'wpCaptchaId', $index ); return $form; } - + /** Pick a random sum */ function pickSum() { $a = mt_rand( 0, 100 ); @@ -27,14 +36,12 @@ class MathCaptcha extends SimpleCaptcha { $ans = $op == '+' ? ( $a + $b ) : ( $a - $b ); return array( $sum, $ans ); } - + /** Fetch the math */ function fetchMath( $sum ) { $math = new MathRenderer( $sum ); $math->setOutputMode( MW_MATH_PNG ); $html = $math->render(); - return preg_replace( '/alt=".*"/', '', $html ); + return preg_replace( '/alt=".*?"/', '', $html ); } - } -?>