1<?php 2 3use dokuwiki\Extension\ActionPlugin; 4use dokuwiki\Extension\EventHandler; 5use dokuwiki\Extension\Event; 6 7/** 8* Autostart Plugin: Redirects to the namespace's start page if available 9* 10* @author Jesús A. Álvarez <zydeco@namedfork.net> 11*/ 12 13 14class action_plugin_autostart extends ActionPlugin 15{ 16 17 public function page_exists($id) { 18 if (function_exists('page_exists')) 19 return page_exists($id); 20 else 21 return @file_exists(wikiFN($id)); 22 } 23 24 public function register(EventHandler $controller) 25 { 26 $controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'preprocess', array ()); 27 } 28 29 public function preprocess(Event $event, $param) 30 { 31 global $conf; 32 global $ID; 33 if (!$this->page_exists($ID)) { 34 if($this->page_exists($ID.':'.$conf['start'])) 35 // start page inside namespace 36 $id = $ID.':'.$conf['start']; 37 elseif($this->page_exists($ID.':'.noNS(cleanID($ID)))) 38 // page named like the NS inside the NS 39 $id = $ID.':'.noNS(cleanID($ID)); 40 if ($id) header('Location: ' . wl($id,'',true)); 41 } 42 } 43 44} 45 46 47