1a646d519SAndreas Gohr<?php 21da41c8bSAndreas Gohr 31da41c8bSAndreas Gohruse dokuwiki\Extension\ActionPlugin; 41da41c8bSAndreas Gohruse dokuwiki\Extension\EventHandler; 51da41c8bSAndreas Gohruse dokuwiki\Extension\Event; 61da41c8bSAndreas Gohr 7a646d519SAndreas Gohr/** 80a5d2da2SAndreas Gohr * DokuWiki Plugin farmer (Action Component) 9a646d519SAndreas Gohr * 101da41c8bSAndreas Gohr * Handles Farm mechanisms on DokuWiki startup 111da41c8bSAndreas Gohr * 120a5d2da2SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 13a646d519SAndreas Gohr * @author Michael Große <grosse@cosmocode.de> 140a5d2da2SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 15a646d519SAndreas Gohr */ 161da41c8bSAndreas Gohrclass action_plugin_farmer_startup extends ActionPlugin 171da41c8bSAndreas Gohr{ 18b96c66ccSAndreas Gohr /** @var helper_plugin_farmer */ 19b96c66ccSAndreas Gohr protected $helper; 20b96c66ccSAndreas Gohr 21b96c66ccSAndreas Gohr /** 22b96c66ccSAndreas Gohr * action_plugin_farmer_startup constructor. 23b96c66ccSAndreas Gohr */ 241da41c8bSAndreas Gohr public function __construct() 251da41c8bSAndreas Gohr { 26b96c66ccSAndreas Gohr $this->helper = plugin_load('helper', 'farmer'); 27b96c66ccSAndreas Gohr } 28b96c66ccSAndreas Gohr 29a646d519SAndreas Gohr /** 30a646d519SAndreas Gohr * plugin should use this method to register its handlers with the DokuWiki's event controller 31a646d519SAndreas Gohr * 321da41c8bSAndreas Gohr * @param EventHandler $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER 33a646d519SAndreas Gohr */ 341da41c8bSAndreas Gohr public function register(EventHandler $controller) 351da41c8bSAndreas Gohr { 361da41c8bSAndreas Gohr $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handleStartUp'); 37a646d519SAndreas Gohr } 38a646d519SAndreas Gohr 391da41c8bSAndreas Gohr /** 401da41c8bSAndreas Gohr * Handle the startup event 411da41c8bSAndreas Gohr * 421da41c8bSAndreas Gohr * @param Event $event 431da41c8bSAndreas Gohr * @param $param 441da41c8bSAndreas Gohr */ 451da41c8bSAndreas Gohr public function handleStartUp(Event $event, $param) 461da41c8bSAndreas Gohr { 47b96c66ccSAndreas Gohr if ($this->helper->wasNotfound()) $this->handleNotFound(); 48a646d519SAndreas Gohr } 49a646d519SAndreas Gohr 50a646d519SAndreas Gohr /** 51a646d519SAndreas Gohr * Handles the animal not found case 52a646d519SAndreas Gohr * 53a646d519SAndreas Gohr * Will abort the current script unless the farmer is wanted 54a646d519SAndreas Gohr */ 551da41c8bSAndreas Gohr protected function handleNotFound() 561da41c8bSAndreas Gohr { 57b96c66ccSAndreas Gohr /** @noinspection PhpUnusedLocalVariableInspection */ 58b96c66ccSAndreas Gohr global $conf, $lang; 59b96c66ccSAndreas Gohr $config = $this->helper->getConfig(); 60a646d519SAndreas Gohr $show = $config['notfound']['show']; 61a646d519SAndreas Gohr $url = $config['notfound']['url']; 62a646d519SAndreas Gohr if ($show == 'farmer') return; 63a646d519SAndreas Gohr 64*0ab101c1SAnna Dabrowska if ($show == 'error404' || $show == 'list') { 65a646d519SAndreas Gohr http_status(404); 66a646d519SAndreas Gohr $body = $this->locale_xhtml('notfound_' . $show); 67b96c66ccSAndreas Gohr /** @noinspection PhpUnusedLocalVariableInspection */ 68a646d519SAndreas Gohr $title = '404'; 69a646d519SAndreas Gohr if ($show == 'list') { 70b96c66ccSAndreas Gohr /** @noinspection PhpUnusedLocalVariableInspection */ 71a646d519SAndreas Gohr $body .= $this->animalList(); 72a646d519SAndreas Gohr } 73a646d519SAndreas Gohr 74f31951d4SAndreas Gohr include __DIR__ . '/../includes/template.php'; 75a646d519SAndreas Gohr exit; 76a646d519SAndreas Gohr } 77a646d519SAndreas Gohr 78a646d519SAndreas Gohr if ($show == 'redirect' && $url) { 79a646d519SAndreas Gohr send_redirect($url); 80a646d519SAndreas Gohr } 81a646d519SAndreas Gohr } 82a646d519SAndreas Gohr 83a646d519SAndreas Gohr /** 84a646d519SAndreas Gohr * Retrun a HTML list of animals 85a646d519SAndreas Gohr * 86a646d519SAndreas Gohr * @return string 87a646d519SAndreas Gohr */ 881da41c8bSAndreas Gohr protected function animalList() 891da41c8bSAndreas Gohr { 90a646d519SAndreas Gohr $html = '<ul>'; 91b96c66ccSAndreas Gohr $animals = $this->helper->getAllAnimals(); 92a646d519SAndreas Gohr foreach ($animals as $animal) { 93c4c8e953SAndreas Gohr $link = $this->helper->getAnimalURL($animal); 94a646d519SAndreas Gohr $html .= '<li><div class="li"><a href="' . $link . '">' . hsc($animal) . '</a></div></li>'; 95a646d519SAndreas Gohr } 96a646d519SAndreas Gohr $html .= '</ul>'; 97a646d519SAndreas Gohr return $html; 98a646d519SAndreas Gohr } 99a646d519SAndreas Gohr} 100