You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

131 lines
3.4 KiB

  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. * @return void
  24. * @author Andreas Gohr <andi@splitbrain.org>
  25. *
  26. */
  27. public function show()
  28. {
  29. // print intro
  30. echo p_locale_xhtml('index');
  31. echo $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 = [];
  49. search($data, $conf['datadir'], 'search_index', ['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. * @param array $item
  60. * @return string
  61. * @author Andreas Gohr <andi@splitbrain.org>
  62. *
  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. * @param array $item
  92. * @return string html
  93. * @author Andreas Gohr <andi@splitbrain.org>
  94. *
  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. }