Loading...   


	/* Used for Table of Contents Bulletted list */
	function buildMenu($aMenu) {
		$sHMTL .= '<ul>';
		foreach($aMenu as $mKey => $mValue) {
			if(is_array($mValue)) {
				$sHMTL .= sprintf( '<li><a href="#%s" hrefg="#%s" class="glide">%s</a> %s</li>', TOASCII(HR_Desc_To_URL($mKey)), TOASCII(HR_Desc_To_URL($mKey)), $mKey, buildMenu($mValue) );
			}
			else {
				$sHMTL .= sprintf('<li><a href="%s" hrefg="%s" class="glide">%s</a></li>', $mValue, $mValue, $mKey );
			}
		}
		$sHMTL .= '</ul>';
		return $sHMTL;
	}  
	
	function SpitTOC($TOC){
		$iter = 0; $stage = 0;
		while($TOC[$iter]){
			$Depth = $TOC[$iter][1]; /* Get current item Depth in Iteration... */
			if(isset($TOC[($iter + 1)][1])){ $F_Depth = $TOC[($iter + 1)][1]; } /* Depth of the next item, after the current */
			$ItemName = $TOC[$iter][0];
			/* Break out ToC Depths and declare them into stages...
				This will automatically take in the Header parsings of the page and auto format them in a nested tree and return an array
					for the list output...
				This could probably be done cleaner, if you know how to make it prettier let me know...
			*/
			if($stage == 5){
				$Lev_6 = $ItemName; #::: Set Level 6 Link Name and Key
				if(!is_array($TOCMenu[$Lev_1][$Lev_2][$Lev_3][$Lev_4][$Lev_5])){  $TOCMenu[$Lev_1][$Lev_2][$Lev_3][$Lev_4][$Lev_5] = array(); }
				$TOCMenu[$Lev_1][$Lev_2][$Lev_3][$Lev_4][$Lev_5][$Lev_6] = '#' . TOASCII(HR_Desc_To_URL($ItemName)); /* Push Items... */
				if($F_Depth > $Depth){ $stage++; }
				else if($F_Depth < $Depth){ $stage = 0; }
			}
			else if($stage == 4){
				$Lev_5 = $ItemName; #::: Set Level 5 Link Name and Key
				if(!is_array($TOCMenu[$Lev_1][$Lev_2][$Lev_3][$Lev_4])){  $TOCMenu[$Lev_1][$Lev_2][$Lev_3][$Lev_4] = array(); }
				$TOCMenu[$Lev_1][$Lev_2][$Lev_3][$Lev_4][$Lev_5] = '#' . TOASCII(HR_Desc_To_URL($ItemName)); /* Push Items... */
				if($F_Depth > $Depth){ $stage++; }
				else if($F_Depth < $Depth){ $stage = 0; }
			}
			else if($stage == 3){
				$Lev_4 = $ItemName; #::: Set Level 4 Link Name and Key
				if(!is_array($TOCMenu[$Lev_1][$Lev_2][$Lev_3])){  $TOCMenu[$Lev_1][$Lev_2][$Lev_3] = array(); }
				$TOCMenu[$Lev_1][$Lev_2][$Lev_3][$Lev_4] = '#' . TOASCII(HR_Desc_To_URL($ItemName)); /* Push Items... */
				if($F_Depth > $Depth){ $stage++; }
				else if($F_Depth < $Depth){ $stage = 0; }
			}
			else if($stage == 2){
				$Lev_3 = $ItemName; #::: Set Level 3 Link Name and Key
				if(!is_array($TOCMenu[$Lev_1][$Lev_2])){  $TOCMenu[$Lev_1][$Lev_2] = array(); }
				$TOCMenu[$Lev_1][$Lev_2][$Lev_3] = '#' . TOASCII(HR_Desc_To_URL($ItemName)); /* Push Items... */
				if($F_Depth > $Depth){ $stage++; }
				else if($F_Depth < $Depth){ $stage = 0; }
			}
			else if($stage == 1){
				$Lev_2 = $ItemName; #::: Set Level 2 Link Name and Key
				if(!is_array($TOCMenu[$Lev_1])){  $TOCMenu[$Lev_1] = array(); }
				$TOCMenu[$Lev_1][$Lev_2] = '#' . TOASCII(HR_Desc_To_URL($ItemName)); /* Push Items... */
				if($F_Depth > $Depth){ $stage++; }
				else if($F_Depth < $Depth){ $stage = 0; }
			}
			else if($stage == 0){ 
				$Lev_2 = $Lev_3 = $Lev_4 = $Lev_5 = $Lev_6 = ''; /* Clear out the stage variables... */
				$Lev_1 = $ItemName;
				$TOCMenu[$Lev_1] = '#' . TOASCII(HR_Desc_To_URL($ItemName)); /* Push Items... */
				if($F_Depth > $Depth){ $stage++; }
				else if($F_Depth < $Depth){ $stage = 0; }
			}
			# echo $TOC[$iter][0] . ' ' . $TOC[$iter][1] . '<br>';
			$iter++;
		}
		# echo '<hr>';
		return $TOCMenu;
	}
	/* Build Table of Contents... */
	$data = explode("\n", $Content); $TOC = array(); $n = 0;
	foreach($data as $line) {
		if(preg_match('/<h1>|<h2>|<h3>|<h4>|<h5>|<h6>/i', $line)){
			preg_match_all("/<h1>(.*?)<\/h1>/", $line, $matches);  foreach ($matches[1] as $v => $k){ $TOC[$n] = array(strip_tags($k), 1); $n++; $line2 = str_replace('<h1>', '<div id="' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '" style="display:inline;" class="anchor">*</div><h1 id="ac_' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '">', $line); $Content = str_replace($line, $line2, $Content); } 
			preg_match_all("/<h2>(.*?)<\/h2>/", $line, $matches);  foreach ($matches[1] as $v => $k){ $TOC[$n] = array(strip_tags($k), 2); $n++; $line2 = str_replace('<h2>', '<div id="' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '" style="display:inline;" class="anchor">*</div><h2 id="ac_' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '">', $line); $Content = str_replace($line, $line2, $Content); }
			preg_match_all("/<h3>(.*?)<\/h3>/", $line, $matches);  foreach ($matches[1] as $v => $k){ $TOC[$n] = array(strip_tags($k), 3); $n++; $line2 = str_replace('<h3>', '<div id="' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '" style="display:inline;" class="anchor">*</div><h3 id="ac_' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '">', $line); $Content = str_replace($line, $line2, $Content); }
			preg_match_all("/<h4>(.*?)<\/h4>/", $line, $matches);  foreach ($matches[1] as $v => $k){ $TOC[$n] = array(strip_tags($k), 4); $n++; $line2 = str_replace('<h4>', '<div id="' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '" style="display:inline;" class="anchor">*</div><h4 id="ac_' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '">', $line); $Content = str_replace($line, $line2, $Content); }
			preg_match_all("/<h5>(.*?)<\/h5>/", $line, $matches);  foreach ($matches[1] as $v => $k){ $TOC[$n] = array(strip_tags($k), 5); $n++; $line2 = str_replace('<h5>', '<div id="' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '" style="display:inline;" class="anchor">*</div><h5 id="ac_' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '">', $line); $Content = str_replace($line, $line2, $Content); }
			preg_match_all("/<h6>(.*?)<\/h6>/", $line, $matches);  foreach ($matches[1] as $v => $k){ $TOC[$n] = array(strip_tags($k), 6); $n++; $line2 = str_replace('<h6>', '<div id="' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '" style="display:inline;" class="anchor">*</div><h6 id="ac_' .  TOASCII(HR_Desc_To_URL(strip_tags($k))) . '">', $line); $Content = str_replace($line, $line2, $Content); }
		}
	}
	$TOCMenu = array();
	$iter = 0;
	$TOCMenu = SpitTOC($TOC);
	
	if($n > 0){
		$TOCOP = buildMenu($TOCMenu);
	}
	/* End TOC */
	
	

Raw Paste Data