X-Git-Url: https://git.toastfreeware.priv.at/toast/cookiecaptcha.git/blobdiff_plain/2df8abcefffc6cbf5c2f7e38aec90eb581d5967d..bd2fd6676b7154f68f11b3bf73127fe0cbfd9bac:/MathCaptcha.class.php diff --git a/MathCaptcha.class.php b/MathCaptcha.class.php index 66567e0..9b9cde2 100644 --- a/MathCaptcha.class.php +++ b/MathCaptcha.class.php @@ -7,26 +7,26 @@ class MathCaptcha extends SimpleCaptcha { return (int)$answer == (int)$info['answer']; } - function addCaptchaAPI(&$resultArr) { + function addCaptchaAPI( &$resultArr ) { list( $sum, $answer ) = $this->pickSum(); - $index = $this->storeCaptcha( array('answer' => $answer ) ); + $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 ); @@ -36,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 ); } - } -?>