"); $sonderzeichen = array("&", "", "", "", "", "", "", "", "<", ">"); $page = isset($_GET)&&!empty($_GET["p"])?$_GET["p"]:"0-0"; $VAR = array(); // parse links $file = "./content/links.inc"; $data = file_get_contents($file); $data = htmlentities($data, ENT_NOQUOTES, "ISO-8859-15"); $data = str_replace($htmlzeichen, $sonderzeichen, $data); $links = makeNamedTree($data); // parse menu file $file = "./templates/menu.tpl"; $menu = file($file); foreach($menu as $i => $a) { if(trim($a) == "") { unset($menu[$i]); } } $VAR["menu"] = makeMenu($links["menu"], $menu, $page)."\n"; $VAR["navigation"] = makeMenu($links["navigation"], $menu, $page, 0)."\n"; // parse meta information file $file = "./content/meta.inc"; if(file_exists($file) && is_readable($file)) { $data = file_get_contents($file); } else { $data = ""; } $keys = array("Content-Type", "Language", "Robots", "Description", "DC.Creator", "DC.Subject", "DC.Description", "DC.Date", "DC.Type", "DC.Format", "DC.Identifier", "DC.Rights"); foreach($keys as $key) { $start = strpos($data, "<".$key.">")+strlen("<".$key.">"); $end = strpos($data, "")-$start; $VAR[$key] = substr($data, $start, $end); } // parse content file $file = "./content/".$page.".inc"; if(file_exists($file) && is_readable($file)) { $data = file_get_contents($file); } else { $file = "./content/0-0.inc"; $data = file_get_contents($file); } $keys = array("keywords", "title", "content"); foreach($keys as $key) { $start = strpos($data, "<".$key.">")+strlen("<".$key.">"); $end = strpos($data, "")-$start; $VAR[$key] = substr($data, $start, $end); } // parse template $file = "./templates/main.tpl"; $data = file_get_contents($file); echo parse_template($data, array("VAR"=>$VAR)); ##### FUNCTIONS ##### // create a menu tree from the given LINKS data and the MENU template // @$array the array or tree containing the menu data // @$templates an array of templates for the menu levels // @$request the GET page request // @is_menu not-"0" by default; the function behaves slightly different if "0" // // RETURNS a string containing the complete menu function makeMenu($array, $templates, $request, $is_menu=1) { if(substr($request, -1) == "0") { $request = substr($request, 0, -2); } $str = recMakeMenu($array, 0, "", $templates, $request, $is_menu); return $str; } // internal function better not to call directly function recMakeMenu($array, $level, $str, $templates, $request, $is_menu) { if(!is_array($array)) { return ""; } else { $retval = ""; foreach($array as $key => $value) { if(is_array($value)) { $t = ""; if($level != 0) { if($level > 1) { $t = "-"; } $t .= $key; } $retval .= recMakeMenu($value, $level+1, $str.$t, $templates, $request, $is_menu); } else { if($key*1 != 0) { $t = $level-1; $me = $str."-".$key; } else { $t = $level-2; $me = $str; } if($t > 0) { $parent = substr($me, 0, -2); } else { $parent = $me; } if($is_menu > 0) { $display = 0; if($t == 0) { $display = 1; } else { if($me == $request) { $display = 1; } else { if(strpos($request, $parent) === 0) { $display = 1; } else { if(strpos($request, $me) === 0) { $display = 1; } } } } } else { $display = 1; $t = $key; } if($display > 0) { if(is_array($templates) && isset($templates[$t])) { $template = $templates[$t]; if($me == $request) { $t .= " active"; } $retval .= parse_template($template, array("VAR"=>array("menu-index"=>$str."-".$key, "menu-class"=>"class=\"menu-".$t."\"", "menu-link"=>stripslashes($value)))); } else { $retval .= "NO TEMPLATE AVAILABLE FOR MENU ENTRY '".$me."' (\"".$value."\").\n"; } } } } return $retval; } } // parse html template function parse_template($template, $array) { if(is_array($array)) { foreach($array as $key_name => $val_names) { if(is_array($val_names)) { foreach($val_names as $key => $value) { $template = str_replace("<%".$key_name."['".$key."']%>", $value, $template); } } } } return $template; } // parse structured data into multidimensional array: function makeNamedTree($data) { $array1 = explode("<", trim($data)); $array2 = array(); $links = array(); foreach($array1 as $i => $str) { $str = trim($str); if($str != "") { $array2[] = explode(">", $str); } else { unset($array1[$i]); } } $buffer = array(); $name = ""; foreach($array2 as $index => $chkarray) { if($chkarray[1] == "" && strpos($chkarray[0], "/") !== 0) { $name .= "[\"".$chkarray[0]."\"]"; eval("\$buffer".$name." = array();"); } else if($chkarray[1] == "" && strpos($chkarray[0], "/") === 0) { $name = substr($name, 0, strrpos($name, "[")); } else { $name .= "[\"".$chkarray[0]."\"]"; eval("\$buffer".$name." = \"".addSlashes($chkarray[1])."\";"); } } return $buffer; } ?>