Skip to content

Commit

Permalink
Ui\Index class replaces html_index()
Browse files Browse the repository at this point in the history
  • Loading branch information
ssahara committed Jul 10, 2020
1 parent 09f440d commit 0fb48f9
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 5 deletions.
14 changes: 9 additions & 5 deletions inc/Action/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@

namespace dokuwiki\Action;

use dokuwiki\Ui;

/**
* Class Index
*
* Show the human readable sitemap. Do not confuse with Sitemap
*
* @package dokuwiki\Action
*/
class Index extends AbstractAction {

class Index extends AbstractAction
{
/** @inheritdoc */
public function minimumPermission() {
public function minimumPermission()
{
return AUTH_NONE;
}

/** @inheritdoc */
public function tplContent() {
public function tplContent()
{
global $IDX;
html_index($IDX);
(new Ui\Index)->show($IDX);
}

}
114 changes: 114 additions & 0 deletions inc/Ui/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace dokuwiki\Ui;

use dokuwiki\Extension\Event;
use dokuwiki\Form\Form;

/**
* DokuWiki Index Insterface
*
* @package dokuwiki\Ui
*/
class Index extends Ui
{
/**
* Display page index
*
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param string $ns
* @return void
*/
public function show($ns = '')
{
global $conf;
global $ID;

$ns = cleanID($ns);
if (empty($ns)){
$ns = getNS($ID);
if ($ns === false) $ns = '';
}
$ns = utf8_encodeFN(str_replace(':', '/', $ns));

// print intro
print p_locale_xhtml('index');

print '<div id="index__tree" class="index__tree">';

$data = array();
search($data, $conf['datadir'], 'search_index', array('ns' => $ns));
print html_buildlist($data, 'idx', [$this,'html_list_index'], [$this,'html_li_index']);

print '</div>'.DOKU_LF;
}

/**
* Index item formatter
*
* User function for html_buildlist()
*
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param array $item
* @return string
*/
public function html_list_index($item)
{
global $ID, $conf;

// prevent searchbots needlessly following links
$nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : '';

$html = '';
$base = ':'.$item['id'];
$base = substr($base, strrpos($base,':') +1);
if ($item['type'] == 'd') {
// FS#2766, no need for search bots to follow namespace links in the index
$link = wl($ID, 'idx='. rawurlencode($item['id']));
$html .= '<a href="'. $link .'" title="'. $item['id'] .'" class="idx_dir"' . $nofollow .'><strong>';
$html .= $base;
$html .= '</strong></a>';
} else {
// default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
$html .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
}
return $html;
}

/**
* Index List item
*
* This user function is used in html_buildlist to build the
* <li> tags for namespaces when displaying the page index
* it gives different classes to opened or closed "folders"
*
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param array $item
* @return string html
*/
public function html_li_index($item)
{
global $INFO;
global $ACT;

$class = '';
$id = '';

if ($item['type'] == 'f') {
// scroll to the current item
if (isset($INFO) && $item['id'] == $INFO['id'] && $ACT == 'index') {
$id = ' id="scroll__here"';
$class = ' bounce';
}
return '<li class="level'.$item['level'].$class.'" '.$id.'>';
} elseif ($item['open']) {
return '<li class="open">';
} else {
return '<li class="closed">';
}
}

}

0 comments on commit 0fb48f9

Please sign in to comment.