Index.php 3.4 KB

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