1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl2.html)
4 * @author     Adrian Schlegel <adrian.schlegel@liip.ch>
5 *
6 */
7
8if(!defined('DOKU_INC')) die();
9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10require_once(dirname(__FILE__).'/lib/recaptchalib.php');
11
12class helper_plugin_recaptcha extends DokuWiki_Plugin {
13
14    /**
15     * Check if the reCAPTCHA should be used. Always check this before using the methods below.
16     *
17     * @return bool true when the reCAPTCHA should be used
18     */
19    function isEnabled(){
20        if(!$this->getConf('forusers') && $_SERVER['REMOTE_USER']) return false;
21        return true;
22    }
23
24    /**
25     * check the validity of the recaptcha
26     *
27     * @return obj (@see ReCaptchaResponse)
28     */
29    function check() {
30        // Check the recaptcha answer and only submit if correct
31        $resp = recaptcha_check_answer ($this->getConf('privatekey'),
32            $_SERVER["REMOTE_ADDR"],
33            $_POST["recaptcha_challenge_field"],
34            $_POST["recaptcha_response_field"]);
35
36        return $resp;
37    }
38
39
40    /**
41     * return the html code for the recaptcha block
42     * @param  boolean $use_ssl
43     * @return string
44     */
45    function getHTML($use_ssl = false) {
46        return recaptcha_get_html($this->getConf('publickey'), null, $use_ssl);
47    }
48}
49