1<?php 2 3use dokuwiki\Extension\ActionPlugin; 4use dokuwiki\Extension\EventHandler; 5use dokuwiki\Extension\Event; 6 7/** 8 * Display Fortune cookies 9 * 10 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 11 * @author Andreas Gohr <andi@splitbrain.org> 12 */ 13class action_plugin_xfortune extends ActionPlugin 14{ 15 /** @inheritdoc */ 16 public function register(EventHandler $controller) 17 { 18 $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjaxCallUnknown'); 19 $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handleClaim'); 20 } 21 22 /** 23 * Handle the ajax call 24 * 25 * @param Event $event 26 * @param $param 27 */ 28 public function handleAjaxCallUnknown(Event $event, $param) 29 { 30 if ($event->data != 'plugin_xfortune') return; 31 $event->preventDefault(); 32 $event->stopPropagation(); 33 global $INPUT; 34 echo helper_plugin_xfortune::getCookieHTML($INPUT->str('cookie')); 35 } 36 37 /** 38 * Set a small cookie as tagline 39 * 40 * @param Event $event 41 * @param $param 42 */ 43 public function handleClaim(Event $event, $param) 44 { 45 if ($this->getConf('claim') === '') return; 46 global $conf; 47 48 $cookie = helper_plugin_xfortune::getCookieHTML($this->getConf('claim'), 2, 130); 49 $conf['tagline'] = $cookie; 50 } 51} 52