*/ // must be run within DokuWiki if(!defined('DOKU_INC')) die(); class syntax_plugin_simplewikipagetree extends DokuWiki_Syntax_Plugin { private $startFile = false; public function getType() { return 'substition'; } public function getSort() { return 32; } public function connectTo($mode) { $this->Lexer->addSpecialPattern('',$mode,'plugin_simplewikipagetree'); } public function handle($match, $state, $pos, Doku_Handler $handler) { return array($match, $state, $pos); } public function render($mode, Doku_Renderer $renderer, $data) { // $data is what the function handle return'ed. if($mode == 'xhtml'){ /** @var Doku_Renderer_xhtml $renderer */ $renderer->doc = ''; $renderer->doc .= ''; $renderer->doc .= $this::renderPageTree('data/pages',true); return true; } return false; } private function renderPageTree($path, $root=false){ global $INFO; $out .= 'startFile == true) or $file == 'sidebar.txt'){ continue; } $filepath = $path.'/'.$file; // skip if this is a text-file and a folder with the same name exists if($this->startFile == false){ $path_parts = pathinfo($filepath); if(is_dir($path_parts['dirname'].'/'.$path_parts['filename']) && $path_parts['dirname'] && $path_parts['extension'] == 'txt'){ continue; } } $id = $this->getID($filepath); // skip start-page if($id == 'start'){ continue; } // skip entry if user has no view permissions //// Todo: Display file instead of folders if there are no files with view persmission inside folder //// Todo: Fix problem with hirarchies $info = basicinfo($id); if($info['perm'] == 0){ continue; } if(is_dir($filepath)){ if($id == substr($INFO['id'],0,strlen($id))){ $out .= '
  • '; }else{ $out .= '
  • '; } }else{ $out .= '
  • '; } $out .= '
    '; $activeInjection = ''; if($this->isActive($filepath)){ $activeInjection = ' class="active" '; } $out .= ''; $out .= $this->getTitle($filepath); $out .= ''; if(is_dir($filepath)){ $out .= $this->renderPageTree($filepath); } $out .= '
  • '; } $out .= ''; return $out; } private function getID($filepath){ $id = str_replace('data/pages/','',$filepath); $id = str_replace('/',':',$id); $id = str_replace('.txt','',$id); return $id; } private function getTitle($filepath){ $id = $this->getID($filepath); // only if start page should be displayed if($this->startFile == true){ if(is_dir($filepath)){ $id .= ':start'; } } $title = p_get_first_heading($id); if($title == ''){ $title = end(explode(':',$id)); // return last part of id without "start" if it is a dir if(is_dir($filepath)){ $title = end(explode(':',$this->getID($filepath))); } } return $title; } private function getURL($filepath){ global $conf; $url = $this->getID($filepath); // only if start page should be displayed if($this->startFile == true){ if(is_dir($filepath)){ $url .= ':start'; } } if($conf['useslash'] == 1){ $url = str_replace(":","/",$url); } $url = DOKU_REL.$url; return $url; } private function isActive($filepath){ global $INFO; $id = $this->getID($filepath); if(is_dir($filepath)){ $id .= ':start'; } if($id == $INFO['id'] ){ return true; } return false; } }