|
Revision 779, 1.4 KB
(checked in by michiel, 7 months ago)
|
|
move captcha stuff to a plugin
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | Class mvblog_captcha extends MvBlog_plugin implements MvBlog_pluginiface { |
|---|
| 3 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | public function deactivate() { |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | public function show_captcha() { |
|---|
| 31 | |
|---|
| 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 | |
|---|
| 40 | $output .= "<input type=\"hidden\" name=\"caphid\" value=\"".md5($txt)."\" />\n"; |
|---|
| 41 | $output .= "<input type=\"text\" name=\"captcha\" style=\"width: 60px;\" /> ".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 | ?> |
|---|