-
Notifications
You must be signed in to change notification settings - Fork 32
/
action.php
88 lines (83 loc) · 2.52 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Registration spam prevention.
*
* @license GPL 3 (http://www.gnu.org/licenses/gpl.html)
* @author Christoph M. Becker <cmb@php.net>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
/**
* The action class which is automatically instantiated by DokuWiki.
*
* @link https://www.dokuwiki.org/devel:action_plugins
*/
class action_plugin_phpreg extends DokuWiki_Action_Plugin
{
/**
* Registers event handlers.
*
* @param Doku_Event_Handler $controller DokuWiki's event controller object.
*
* @return not required
*/
public function register(Doku_Event_Handler $controller)
{
$controller->register_hook(
'HTML_REGISTERFORM_OUTPUT',
'BEFORE',
$this,
'handle_registerform_output'
);
$controller->register_hook(
'ACTION_ACT_PREPROCESS',
'BEFORE',
$this,
'handle_act_preprocess',
array()
);
}
/**
* custom event handler
*
* @param Doku_Event $event event object by reference
* @param mixed $param the parameters passed to register_hook when this
* handler was registered
*
* @return not required
*/
public function handle_registerform_output(Doku_Event &$event, $param)
{
$pos = $event->data->findElementByAttribute('type', 'submit');
if (!$pos) return;
$spam = isset($_POST['spam']) ? $_POST['spam'] : '';
$out = form_makeTextField(
'spam', $spam,
'To which email address do you have to send an email to now?',
'', 'block', array('size' => '50')
);
$event->data->insertElement($pos, $out);
}
/**
* Checks the spam-prevention.
*
* @param Doku_Event $event event object by reference
* @param mixed $param the parameters passed to register_hook when this
* handler was registered
*
* @return not required
*/
public function handle_act_preprocess(Doku_Event &$event, $param)
{
$act = $event->data;
if ($act != 'register' || !isset($_POST['save'])) {
return;
}
$spam = isset($_POST['spam']) ? $_POST['spam'] : '';
$spam = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $spam));
if ($spam != 'internals@lists.php.net') {
msg("That wasn't the answer we were expecting", -1);
$_POST['save'] = false;
}
}
}