1<?php
2/**
3 * brj404: redirect to not found page, if u not admin
4 *
5 * @author Roman Y. Bogdanov <sam@brj.pp.ru>
6 */
7
8if (!defined('DOKU_INC')) die();
9if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
10require_once (DOKU_PLUGIN . 'action.php');
11
12class action_plugin_brj404 extends DokuWiki_Action_Plugin
13{
14    function getInfo() {
15        return array (
16            'author' => 'Roman Y. Bogdanov',
17            'email' => 'sam@brj.pp.ru',
18            'date' => '13-03-2015',
19            'name' => 'brj404 Plugin',
20            'desc' => "Redirect to notfound namespace",
21            'url' => 'https://www.dokuwiki.org/plugin:brj404',
22        );
23    }
24
25    function page_exists($id) {
26        if (function_exists('page_exists'))
27            return page_exists($id);
28        else
29            return @file_exists(wikiFN($id));
30    }
31
32    function register(&$controller) {
33        $controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'preprocess', array ());
34    }
35
36    function preprocess(& $event, $param) {
37        global $INFO;
38        global $auth;
39        global $conf;
40        global $ID;
41        if ($INFO['isadmin']) return;
42        if (!$this->page_exists($ID) && $event->data == 'show')
43        {
44	$id = $this->GetConf('idnamespace');
45        header('Location: ' . wl($id,'',true));
46        }
47}
48}
49