1<?php 2/** 3 * 4 * 5 * @author Michael Große <grosse@cosmocode.de> 6 */ 7 8if(!defined('DOKU_INC')) die(); 9 10/** 11 * Class action_plugin_farmer_pluginSettings 12 */ 13class action_plugin_farmer_startup extends DokuWiki_Action_Plugin { 14 15 /** 16 * plugin should use this method to register its handlers with the DokuWiki's event controller 17 * 18 * @param Doku_Event_Handler $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER 19 * 20 */ 21 public function register(Doku_Event_Handler $controller) { 22 $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'before_start'); 23 } 24 25 26 public function before_start(Doku_Event $event, $param) { 27 if(!isset($GLOBALS['FARMCORE'])) return; 28 global $FARMCORE; 29 30 if($FARMCORE->wasNotfound()) $this->handleNotFound(); 31 } 32 33 /** 34 * Handles the animal not found case 35 * 36 * Will abort the current script unless the farmer is wanted 37 */ 38 protected function handleNotFound() { 39 global $FARMCORE; 40 global $conf; 41 global $lang; 42 $config = $FARMCORE->getConfig(); 43 $show = $config['notfound']['show']; 44 $url = $config['notfound']['url']; 45 if($show == 'farmer') return; 46 47 if($show == '404' || $show == 'list') { 48 http_status(404); 49 $body = $this->locale_xhtml('notfound_'.$show); 50 $title = '404'; 51 if($show == 'list') { 52 $body .= $this->animalList(); 53 } 54 55 include __DIR__ . '/../template.php'; 56 exit; 57 } 58 59 if($show == 'redirect' && $url) { 60 send_redirect($url); 61 } 62 } 63 64 /** 65 * Retrun a HTML list of animals 66 * 67 * @return string 68 */ 69 protected function animalList() { 70 /** @var helper_plugin_farmer $helper */ 71 $helper = plugin_load('helper', 'farmer'); 72 global $FARMCORE; 73 74 $html = '<ul>'; 75 $animals = $helper->getAllAnimals(); 76 foreach($animals as $animal) { 77 if($FARMCORE->isHostbased()) { 78 $link = '//:'.$animal.'/'; 79 } else { 80 $link = DOKU_BASE.'!'.$animal.'/'; 81 } 82 83 $html .= '<li><div class="li"><a href="'.$link.'">'.hsc($animal).'</a></div></li>'; 84 } 85 $html .= '</ul>'; 86 return $html; 87 } 88 89} 90 91