xref: /plugin/notfound/action.php (revision c348a0f4e577651965f27d25ff4068c5c4d68809)
1*c348a0f4SAndreas Gohr<?php
2*c348a0f4SAndreas Gohrif(!defined('DOKU_INC')) die();
3*c348a0f4SAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4*c348a0f4SAndreas Gohrrequire_once(DOKU_PLUGIN.'action.php');
5*c348a0f4SAndreas Gohr
6*c348a0f4SAndreas Gohr
7*c348a0f4SAndreas Gohrclass action_plugin_notfound extends DokuWiki_Action_Plugin {
8*c348a0f4SAndreas Gohr
9*c348a0f4SAndreas Gohr
10*c348a0f4SAndreas Gohr    function getInfo(){
11*c348a0f4SAndreas Gohr        return confToHash(dirname(__FILE__).'/info.txt');
12*c348a0f4SAndreas Gohr    }
13*c348a0f4SAndreas Gohr
14*c348a0f4SAndreas Gohr
15*c348a0f4SAndreas Gohr    function register(&$controller) {
16*c348a0f4SAndreas Gohr        $controller->register_hook('ACTION_ACT_PREPROCESS','BEFORE', $this, '_check404');
17*c348a0f4SAndreas Gohr        $controller->register_hook('TPL_CONTENT_DISPLAY','BEFORE', $this, '_show404');
18*c348a0f4SAndreas Gohr    }
19*c348a0f4SAndreas Gohr
20*c348a0f4SAndreas Gohr
21*c348a0f4SAndreas Gohr    function _check404(&$event , $param) {
22*c348a0f4SAndreas Gohr        if($event->data != 'show') return false;
23*c348a0f4SAndreas Gohr        global $INFO;
24*c348a0f4SAndreas Gohr        if($INFO['exists']) return false;
25*c348a0f4SAndreas Gohr
26*c348a0f4SAndreas Gohr        $event->data = 'notfound';
27*c348a0f4SAndreas Gohr        $event->stopPropagation();
28*c348a0f4SAndreas Gohr        $event->preventDefault();
29*c348a0f4SAndreas Gohr        return true;
30*c348a0f4SAndreas Gohr    }
31*c348a0f4SAndreas Gohr
32*c348a0f4SAndreas Gohr    function _show404(&$event, $param) {
33*c348a0f4SAndreas Gohr        global $ACT;
34*c348a0f4SAndreas Gohr        if($ACT != 'notfound') return false;
35*c348a0f4SAndreas Gohr        $event->stopPropagation();
36*c348a0f4SAndreas Gohr        $event->preventDefault();
37*c348a0f4SAndreas Gohr
38*c348a0f4SAndreas Gohr        global $ID;
39*c348a0f4SAndreas Gohr        $oldid = $ID;
40*c348a0f4SAndreas Gohr        $ID = $this->getConf('404page');
41*c348a0f4SAndreas Gohr        echo p_wiki_xhtml($ID,'',false);
42*c348a0f4SAndreas Gohr        $ID = $oldid;
43*c348a0f4SAndreas Gohr        $ACT='show';
44*c348a0f4SAndreas Gohr
45*c348a0f4SAndreas Gohr        return true;
46*c348a0f4SAndreas Gohr    }
47*c348a0f4SAndreas Gohr}
48