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