1<?php 2 3namespace dokuwiki\Ui; 4 5use dokuwiki\Extension\Event; 6use dokuwiki\Form\Form; 7 8/** 9 * DokuWiki Index Interface 10 * 11 * @package dokuwiki\Ui 12 */ 13class Index extends Ui 14{ 15 protected $ns; 16 17 /** 18 * Index Ui constructor 19 * 20 * @param string $ns namespace 21 */ 22 public function __construct($ns = '') 23 { 24 $this->ns = $ns; 25 } 26 27 28 /** 29 * Display page index 30 * 31 * @author Andreas Gohr <andi@splitbrain.org> 32 * 33 * @return void 34 */ 35 public function show() 36 { 37 global $conf; 38 global $ID; 39 40 $ns = cleanID($this->ns); 41 if (empty($ns)){ 42 $ns = getNS($ID); 43 if ($ns === false) $ns = ''; 44 } 45 $ns = utf8_encodeFN(str_replace(':', '/', $ns)); 46 47 // print intro 48 print p_locale_xhtml('index'); 49 50 print '<div id="index__tree" class="index__tree">'; 51 52 $data = array(); 53 search($data, $conf['datadir'], 'search_index', array('ns' => $ns)); 54 print html_buildlist($data, 'idx', [$this,'formatListItem'], [$this,'tagListItem']); 55 56 print '</div>'.DOKU_LF; 57 } 58 59 /** 60 * Index item formatter 61 * 62 * User function for html_buildlist() 63 * 64 * @author Andreas Gohr <andi@splitbrain.org> 65 * 66 * @param array $item 67 * @return string 68 */ 69 public function formatListItem($item) // RENAMED from html_list_index() 70 { 71 global $ID, $conf; 72 73 // prevent searchbots needlessly following links 74 $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : ''; 75 76 $html = ''; 77 $base = ':'.$item['id']; 78 $base = substr($base, strrpos($base,':') +1); 79 if ($item['type'] == 'd') { 80 // FS#2766, no need for search bots to follow namespace links in the index 81 $link = wl($ID, 'idx='. rawurlencode($item['id'])); 82 $html .= '<a href="'. $link .'" title="'. $item['id'] .'" class="idx_dir"' . $nofollow .'><strong>'; 83 $html .= $base; 84 $html .= '</strong></a>'; 85 } else { 86 // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605 87 $html .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id'])); 88 } 89 return $html; 90 } 91 92 /** 93 * Index List item 94 * 95 * This user function is used in html_buildlist to build the 96 * <li> tags for namespaces when displaying the page index 97 * it gives different classes to opened or closed "folders" 98 * 99 * @author Andreas Gohr <andi@splitbrain.org> 100 * 101 * @param array $item 102 * @return string html 103 */ 104 public function tagListItem($item) // RENAMED from html_li_index() 105 { 106 global $INFO; 107 global $ACT; 108 109 $class = ''; 110 $id = ''; 111 112 if ($item['type'] == 'f') { 113 // scroll to the current item 114 if (isset($INFO) && $item['id'] == $INFO['id'] && $ACT == 'index') { 115 $id = ' id="scroll__here"'; 116 $class = ' bounce'; 117 } 118 return '<li class="level'.$item['level'].$class.'" '.$id.'>'; 119 } elseif ($item['open']) { 120 return '<li class="open">'; 121 } else { 122 return '<li class="closed">'; 123 } 124 } 125 126} 127