*/
// Must be run from within DokuWiki
if (!defined('DOKU_INC')) die();
/**
* Fork inc/template.php
*/
function custom_toc()
{
global $TOC;
global $ACT;
global $ID;
global $REV;
global $INFO;
global $conf;
global $lang;
$toc = array();
if(is_array($TOC)){
// if a TOC was prepared in global scope, always use it
$toc = $TOC;
}elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){
// get TOC from metadata, render if neccessary
$meta = p_get_metadata($ID, false, true);
if(isset($meta['internal']['toc'])){
$tocok = $meta['internal']['toc'];
}else{
$tocok = true;
}
$toc = $meta['description']['tableofcontents'];
if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']){
$toc = array();
}
}elseif($ACT == 'admin'){
// try to load admin plugin TOC FIXME: duplicates code from tpl_admin
$plugin = null;
if (!empty($_REQUEST['page'])) {
$pluginlist = plugin_list('admin');
if (in_array($_REQUEST['page'], $pluginlist)) {
// attempt to load the plugin
$plugin =& plugin_load('admin',$_REQUEST['page']);
}
}
if ( ($plugin !== null) &&
(!$plugin->forAdminOnly() || $INFO['isadmin']) ){
$toc = $plugin->getTOC();
$TOC = $toc; // avoid later rebuild
}
}
trigger_event('TPL_TOC_RENDER', $toc, NULL, false);
if( !empty( $toc ) ){
echo DOKU_LF, '', $lang['toc'], '
';
$level = 0;
foreach( $toc as $item )
{
if( $item['level'] > $level ){
//open new list
for($i=0; $i<($item['level'] - $level); $i++){
if ($i) echo "\n";
}
}elseif( $item['level'] < $level ){
//close last item
echo "