-
Notifications
You must be signed in to change notification settings - Fork 10
/
action.php
72 lines (62 loc) · 2.32 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
<?php
use dokuwiki\Form\Form;
/**
* Encrypted Passwords Plugin: Store encrypted passwords with syntax <decrypt></decrypt>
*
* @license GPL2 (http://www.gnu.org/licenses/gpl.html)
* @author Wolfgang Reszel <reszel@werbeagentur-willers.de>
*/
class action_plugin_encryptedpasswords extends DokuWiki_Action_Plugin
{
/**
* Register its handlers with the DokuWiki's event controller
*/
public function register(Doku_Event_Handler $controller)
{
$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handleToolbar');
$controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'disableAutoDraft');
// legacy support
$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'disableAutoDraft');
}
/**
* Adds toolbar button
*/
public function handleToolbar(Doku_Event $event, $param)
{
$event->data[] = array(
'type' => 'encryptButtonClick',
'title' => $this->getLang('toolbar_icon_title'),
'icon' => DOKU_REL.'lib/plugins/encryptedpasswords/encrypt.png',
);
}
/**
* Disable auto draft saving
*/
public function disableAutoDraft(Doku_Event $event, $param)
{
global $conf;
$form =& $event->data;
if (is_a($form, Form::class) // $event->name is 'FORM_EDIT_OUTPUT'
&& ($pos = $form->findPositionByAttribute('id', 'wiki__text')) !== false
) {
// applicable to DW development snapshot 2020-10-13 or later
$wikitext = $form->getElementAt($pos)->val();
} elseif (is_a($form, 'Doku_Form') // $event->name == 'HTML_EDITFORM_OUTPUT'
&& ($pos = $form->findElementByType('wikitext')) !== false
) {
// applicable to DW release 2020-07-29 "Hogfather" and older
$textarea = $form->getElementAt($pos);
$wikitext = $textarea['_text'];
} else {
return;
}
// check <decrypt></decriprt> used in wiki text
$ptn = '#<decrypt>[\s\S]*?</decrypt>#';
if (preg_match($ptn, $wikitext) && $conf['usedraft']) {
$conf['usedraft'] = 0;
if ($this->getConf('notify')) {
msg($this->getPluginName().': '.$this->getLang('msg_AutoDraftDisabled'), 2);
}
}
}
}