1<?php 2 3use dokuwiki\Extension\ActionPlugin; 4use dokuwiki\Extension\EventHandler; 5use dokuwiki\Extension\Event; 6 7/** 8 * DokuWiki Plugin encryptedpasswords (Action Component) 9 * 10 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 11 */ 12class action_plugin_encryptedpasswords extends ActionPlugin 13{ 14 /** @inheritDoc */ 15 public function register(EventHandler $controller) 16 { 17 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handleDokuWikiStarted'); 18 $controller->register_hook('DRAFT_SAVE', 'BEFORE', $this, 'handleDraftSave'); 19 } 20 21 /** 22 * Add timeout parameter to JSINFO 23 * 24 * @param Event $event event object by reference 25 * @param mixed $param optional parameter passed when event was registered 26 * @return void 27 */ 28 public function handleDokuWikiStarted(Event $event, $param) 29 { 30 global $JSINFO; 31 $JSINFO['plugins']['encryptedpasswords']['timeout'] = $this->getConf('reload_seconds'); 32 } 33 34 /** 35 * Remove any unencrypted passwords from the drafts 36 * 37 * @param Event $event event object by reference 38 * @param mixed $param optional parameter passed when event was registered 39 * @return void 40 */ 41 public function handleDraftSave(Event $event, $param) 42 { 43 $re = '/<encrypt>.*?(<\/encrypt>)/s'; 44 $repl = $this->getLang('draftreplace'); 45 46 $event->data['prefix'] = preg_replace($re, $repl, $event->data['prefix']); 47 $event->data['suffix'] = preg_replace($re, $repl, $event->data['suffix']); 48 $event->data['text'] = preg_replace($re, $repl, $event->data['text']); 49 } 50} 51