root/trunk/plugins/mvblog_captcha.php

Revision 779, 1.4 KB (checked in by michiel, 7 months ago)

move captcha stuff to a plugin

Line 
1<?php
2Class mvblog_captcha extends MvBlog_plugin implements MvBlog_pluginiface {
3    /* variables */
4    public $name    = "mvblog_captcha";
5    public $author  = "Michiel van Baak";
6    public $license = "GPL";
7    public $website = "http://www.mvblog.org";
8    public $description = "Basic captcha plugin.";
9
10    private $_mvblog;
11
12    /* methods */
13    public function __construct(&$mvblog) {
14        $this->addHook("captcha_output", "show_captcha");
15        $this->addHook("captcha_check", "check_captcha");
16        $this->_mvblog =& $mvblog;
17    }
18
19    public function activate() {
20        /* get data, do whatever is needed on plugin activation */
21    }
22
23    public function deactivate() {
24    }
25
26    /* show_captcha {{{ */
27    /**
28     * Show a captcha and hidden input and user input field
29     */
30    public function show_captcha() {
31        // generate random text string
32        $txt = "";
33        for ($i=0; $i<6; $i++) {
34            $set = array(rand(65,90), rand(97,122));
35            $txt .= chr($set[rand(0,1)]);
36        }
37        $_SESSION["txt"] = $txt;
38        $output = "<img src=\"plugins/mvblog_captcha_files/image.php\">";
39        //create tmp image file
40        $output .= "<input type=\"hidden\" name=\"caphid\" value=\"".md5($txt)."\" />\n";
41        $output .= "<input type=\"text\" name=\"captcha\" style=\"width: 60px;\" />&nbsp;".gettext("Type the text as shown on the left.")."<br /><br />\n";
42        return $output;
43    }
44    /* }}} */
45    public function check_captcha($data) {
46        if ($data["caphid"] == md5($data["captcha"])) {
47            return true;
48        } else {
49            return false;
50        }
51    }
52}
53?>
Note: See TracBrowser for help on using the browser.