1    <?php
2    /**
3     * Autostart Plugin: Redirects to the namespace's start page if available
4     *
5     * @author Jesús A. Álvarez <zydeco@namedfork.net>
6     */
7
8    if (!defined('DOKU_INC')) die();
9    if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
10    require_once (DOKU_PLUGIN . 'action.php');
11
12    class action_plugin_autostart extends DokuWiki_Action_Plugin
13    {
14        function getInfo() {
15            return array (
16                'author' => 'Jesús A. Álvarez',
17                'email' => 'zydeco@namedfork.net',
18                'date' => '2020-11-15',
19                'name' => 'Autostart Plugin',
20                'desc' => "Redirect from the namespace's name to its start page",
21                'url' => 'https://www.dokuwiki.org/plugin:autostart',
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(Doku_Event_Handler $controller) {
33            $controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'preprocess', array ());
34        }
35
36        function preprocess(Doku_Event $event, $param) {
37            global $conf;
38            global $ID;
39            //if (!$this->page_exists($ID) && $event->data == 'show')
40            if (!$this->page_exists($ID))
41            {
42                if($this->page_exists($ID.':'.$conf['start']))
43                    // start page inside namespace
44                    $id = $ID.':'.$conf['start'];
45                elseif($this->page_exists($ID.':'.noNS(cleanID($ID))))
46                    // page named like the NS inside the NS
47                    $id = $ID.':'.noNS(cleanID($ID));
48                if ($id) header('Location: ' . wl($id,'',true));
49            }
50        }
51
52    }
53
54
55