diff --git a/action.php b/action.php index 15791f9..7a42441 100644 --- a/action.php +++ b/action.php @@ -290,6 +290,7 @@ function _indexmenu_list_toc($item) { * @author Samuele Tognini * @author Andreas Gohr * @author Rene Hadler + * @author Ekkart Kleinod */ function print_index($ns) { require_once(DOKU_PLUGIN.'indexmenu/syntax/indexmenu.php'); @@ -301,6 +302,7 @@ function print_index($ns) { $data = array(); $skipfile = array(); $skipns = array(); + $maxcount = 0; if($_REQUEST['max'] > 0) { $max = $_REQUEST['max']; @@ -333,6 +335,10 @@ function print_index($ns) { $skipns[$index] = substr($skipn, 1); } + if($_REQUEST['maxcount'] > 0) { + $maxcount = $_REQUEST['maxcount']; + } + $opts = array( 'level' => $level, 'nons' => $_REQUEST['nons'], @@ -351,6 +357,11 @@ function print_index($ns) { search($data, $conf['datadir'], array($idxm, '_search_index'), $opts, $fsdir); } + if($maxcount > 0) { + // reduce items in array to maxcount, preserving keys + $data = array_slice($data, 0, $maxcount, true); + } + $out = ''; if($_REQUEST['nojs']) { require_once(DOKU_INC.'inc/html.php'); @@ -358,7 +369,7 @@ function print_index($ns) { $out .= preg_replace('/
    (.*)<\/ul>/s', "$1", $out_tmp); } else { $nodes = $idxm->_jsnodes($data, '', 0); - $out = "ajxnodes = ["; + $out .= "ajxnodes = ["; $out .= rtrim($nodes[0], ","); $out .= "];"; } diff --git a/lang/de-informal/lang.php b/lang/de-informal/lang.php index 8f88593..9fdca22 100644 --- a/lang/de-informal/lang.php +++ b/lang/de-informal/lang.php @@ -2,7 +2,7 @@ /** * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * + * * @author Thomas Templin * @author Dana */ @@ -52,6 +52,7 @@ $lang['js']['nons'] = 'Nur Seiten zeigen'; $lang['js']['nopg'] = 'Nur Namensräume zeigen'; $lang['js']['max'] = 'Wieviele Ebenen sollen mit Ajax geholt werden, wenn ein Knoten geöffnet wird? Außerdem: wieviele Unterebenen unterhalb dieser Ebene sollen mit Ajax geholt werden anstatt während des Seitenaufbaus?'; +$lang['js']['maxcount'] = 'Wieviele Seiten sollen angezeigt werden?'; $lang['js']['maxjs'] = 'Wieviele Ebenen sollen im Browser statt auf dem Server gerendert werden, wenn ein Knoten geöffnet wird?'; $lang['js']['id'] = 'Benutzerspezifische Cookie-ID f¨r dieses indexmenu'; $lang['js']['insert'] = 'Indexmenu einf¨gen'; diff --git a/lang/de/lang.php b/lang/de/lang.php index 0c4842d..799b38f 100644 --- a/lang/de/lang.php +++ b/lang/de/lang.php @@ -2,7 +2,7 @@ /** * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * + * * @author Fabian Pfannes * @author Dennis Plöger * @author Kilian Maier @@ -55,6 +55,7 @@ $lang['js']['nons'] = 'Nur Seiten zeigen'; $lang['js']['nopg'] = 'Nur Namensräume zeigen'; $lang['js']['max'] = 'Wieviele Ebenen sollen mit AJAX geholt werden, wenn ein Knoten geöffnet wird? Außerdem: wieviele Unterebenen unterhalb dieser Ebene sollen mit AJAX geholt werden anstatt während des Seitenaufbaus?'; +$lang['js']['maxcount'] = 'Wieviele Seiten sollen angezeigt werden?'; $lang['js']['maxjs'] = 'Wieviele Ebenen sollen im Browser statt auf dem Server gerendert werden, wenn ein Knoten geöffnet wird?'; $lang['js']['id'] = 'Benutzerspezifische Cookie-ID für dieses Indexmenu'; $lang['js']['insert'] = 'Indexmenu einfügen'; diff --git a/lang/en/lang.php b/lang/en/lang.php index 4735439..856c1dd 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -53,6 +53,7 @@ $lang['js']['nons'] = 'Show only pages'; $lang['js']['nopg'] = 'Show only namespaces'; $lang['js']['max'] = 'How many levels to render with ajax when a node is opened. Additional are how many sublevels below that level are retrieved with AJAX instead of in one go. '; +$lang['js']['maxcount'] = 'How many pages to show?'; $lang['js']['maxjs'] = 'How many levels to render in the client browser when a node is opened'; $lang['js']['id'] = 'Self defined cookie id for this indexmenu'; $lang['js']['insert'] = 'Insert indexmenu'; diff --git a/syntax/indexmenu.php b/syntax/indexmenu.php index 4aa5fd8..8c510b3 100644 --- a/syntax/indexmenu.php +++ b/syntax/indexmenu.php @@ -55,6 +55,9 @@ public function connectTo($mode) { /** * Handler to prepare matched data for the rendering process * + * @author Samuele Tognini + * @author Ekkart Kleinod + * * @param string $match The text matched by the patterns * @param int $state The lexer state for the match * @param int $pos The character position of the matched text @@ -71,6 +74,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { $nss = array(); $skipns = array(); $skipfile = array(); + $maxcount = 0; $defaultsstr = $this->getConf('defaultoptions'); $defaults = explode(' ', $defaultsstr); @@ -236,6 +240,12 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { $jsajax .= "&skipfile=" . utf8_encodeFN(($action == '+' ? '+' : '=') . $sf[1]); } + // check maxcount option + if($maxcountvalue = $this->getOption($defaultsstr, $optsstr, '/maxcount#(\d+)/u')) { + $maxcount = $maxcountvalue; + } + + //js options $js_opts = compact('theme', 'identifier', 'nocookie', 'navbar', 'noscroll', 'maxjs', 'notoc', 'jsajax', 'context', 'nomenu'); @@ -258,7 +268,8 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { 'headpage' => $this->getConf('headpage'), 'hide_headpage' => $this->getConf('hide_headpage') ), - $hsort + $hsort, + $maxcount ); } @@ -380,6 +391,7 @@ public function render($mode, Doku_Renderer $renderer, $data) { * * This function is a simple hack of Dokuwiki @see html_index($ns) * @author Andreas Gohr + * @author Ekkart Kleinod * * @param array $myns the options for indexmenu * @return bool|string return html for a nojs index and when enabled the js rendered index, otherwise false @@ -394,6 +406,7 @@ private function _indexmenu($myns) { $this->nsort = $myns[5]; $opts = $myns[6]; //level, nons, nopg, nss, max, js, skip_index, skip_file, headpage, hide_headpage $this->hsort = $myns[7]; + $this->maxcount = $myns[8]; $data = array(); $js_name = "indexmenu_".$js_opts['identifier']; $fsdir = "/".utf8_encodeFN(str_replace(':', '/', $ns)); @@ -402,6 +415,12 @@ private function _indexmenu($myns) { } else { search($data, $conf['datadir'], array($this, '_search_index'), $opts, $fsdir); } + + if($this->maxcount > 0) { + // reduce items in array to maxcount, preserving keys + $data = array_slice($data, 0, $this->maxcount, true); + } + if(!$data) return false; // javascript index @@ -965,4 +984,4 @@ private function _setorder($item) { if($sort === false) $sort = noNS($item['id']); return $sort; } -} //Indexmenu class end +} //Indexmenu class end