Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table of Contents processor

Status
Not open for further replies.

gratemyl

Programmer
Jul 30, 2005
10
0
0
NL
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:

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>";

?>
note: i already made some modifications
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
 
Do you have a specific question or particular concept you need help with?
This forum will help you with such questions, however, it is not meant to write or modify code for you. If you encounter trouble with rewriting code and specific questions come up, please post them.
 
well, this code is meant to sort out all titles e.g.

==heading==
===heading===
====heading====

and i would like an eplanation, and maybe some help as to where the ='s are being searched for
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top