I am working on a site management system (like a CMS, but better ;-)), and i am including a tag {{toc}} for automatic creation of a table of contents. i took this code from WackoWiki, and i would like to alter it to be callable from my main script:
note: i already made some modifications
thanks for any help
Code:
<?php
//toc.php
$page = ""; $ppage="";
$context = $this->tag;
$_page = $this->page;
$link = "";
$from = "h2";
$to = "h9";
$start_depth = $from{1};
$end_depth = $to{1};
// 3. output
print "<fieldset>";
print "<legend><strong> ".-->TITLE<--." </strong></legend>";
$toc = $this->BuildToc( $context, $start_depth, $end_depth, $numerate, $link );
{ // ---------------------- toc numeration ------------------------
$toc_len = sizeof($toc);
$numbers = array(); $depth = 0;
for($i=0;$i<$toc_len;$i++)
if ($toc[$i][2] < 66666)
{
$toc[$i][4] = $toc[$i][2]-$start_depth+1;
}
$this->tocs[ $context ] = &$toc;
if (!$ppage) { $this->post_wacko_toc = &$toc; $this->post_wacko_action["toc"] = 1; }
}
foreach( $toc as $v )
if ($v[4])
{
echo '<div class="toc'.$v[4].'">';
echo '<a href="'.$v[3].'#'.$v[0].'">'.strip_tags($v[1]).'</a>';
echo '</div>';
}
print "</fieldset>";
?>
Code:
//code found in another file, referenced BuildToc function:
function BuildToc( $tag, $from, $to, $num, $link=-1 )
{
if (isset($this->tocs[ $tag ])) return $this->tocs[ $tag ];
$page = -->DATA<--;
if ($link === -1)
$_link = ($this->page["tag"] != $page["tag"])?$this->Href("",$page["tag"]):"";
else $_link = $link;
$toc = explode( "<poloskuns,row>", $page["body_toc"] );
foreach($toc as $k=>$v)
$toc[$k] = explode("<poloskuns,col>", $v);
$_toc = array();
foreach($toc as $k=>$v)
if ($v[2] == 99999)
{
if (!in_array($v[0],$this->toc_context))
if (!($v[0] == $this->tag))
{
array_push($this->toc_context, $v[0]);
$_toc = array_merge( $_toc, $this->BuildToc( $v[0], $from, $to, $num, $link ) );
array_pop($this->toc_context);
}
}
else
if ($v[2] == 77777)
{
$toc[$k][3] = $_link;
$_toc[] = &$toc[$k];
}
else
if (($v[2] >= $from) && ($v[2] <= $to))
{
$toc[$k][3] = $_link;
$_toc[] = &$toc[$k];
$toc[$k][1] = $this->Format($toc[$k][1], "post_wacko");
}
$this->tocs[ $tag ] = $_toc;
return $_toc;
}
thanks for any help