Hi Manu,
I was about to offer another solution for discussion, and now I see, you edited your first post and came up with the same idea (preg_match_all() instead of inserting a silly token "§" to explode it afterwards) like me. That really should be the better thing! (And I am pretty sure that we can strip this damn "§" from l() and h() as well.)
My proposal was a complete rewrite of the rfc(), that does not use l() and h() anymore:
Code: Select all
function rfc(){
global $c, $cl, $h, $u, $l, $su, $s, $pth, $tx, $edit, $adm, $cf;
$c = array();
$h = array();
$u = array();
$l = array();
$empty = 0;
$duplicate = 0;
$content = file_get_contents($pth['file']['content']);
$stop = $cf['menu']['levels'];
$pattern = '/(<h([1-'.$stop.'])[^>]*>(.*)<\/h[1-'.$stop.'](.+))(?=(<(h[1-'.$stop.']|\/body).*>))/isU';
preg_match_all($pattern, $content, $pages);
$c = $pages[1];
$cl = count($c);
if ($cl == 0){
$c[] = '<h1>'.$tx['toc']['newpage'].'</h1>';
$h[] = trim(strip_tags($tx['toc']['newpage']));
$u[] = uenc($h[0]);
$l[] = 1;
$s = 0;
return;
}
$l = $pages[2];
$ancestors = array(); /* just a helper for the "url" construction:
* will be filled like this [0] => "Page"
* [1] => "Subpage"
* [2] => "Sub_Subpage" etc.
*/
foreach($pages[3] as $i => $heading){
$temp = trim(strip_tags($heading));
if($temp == ''){
$empty++;
$temp = $tx['toc']['empty']. ' '. $empty;
}
$h[] = $temp;
$ancestors[$l[$i]-1] = uenc($temp);
$ancestors = array_slice($ancestors,0, $l[$i]);
$url = implode($cf['uri']['seperator'], $ancestors);
$u[] = substr($url, 0, $cf['uri']['length']);
}
foreach($u as $i => $url){
if ($su == $u[$i]){$s = $i;} // get index of selected page
for($j = $i + 1; $j < $cl; $j++){ //check for duplicate "urls"
if($u[$j] == $u[$i]){
$duplicate++;
$h[$j] = $tx['toc']['dupl'].' '.$duplicate;
$u[$j] = uenc($h[$j]);
}
}
}
if(!($edit && $adm)){
foreach($c as $i => $j) {
if (cmscript('remove', $j)){$c[$i] = '#CMSimple hide#';}
}
}
}
EDIT 29. June 2010: Changed on line for proper url contruction: "array_slice($ancestors,0, $l[$i]);" => "$ancestors = array_slice($ancestors,0, $l[$i]);"
I don't know, whether l() and h() are used in any plugin. But to keep it safe, they could be simplified to
Code: Select all
function h($n) {
global $h;
return $h[$n];
}
function l($n) {
global $l;
return $l[$n];
}
Would you be so kind to have alook at it?
Martin