<?php
	/** SEO **/
		$requri = explode("/", $_SERVER['REQUEST_URI']);
		$pieces = explode( '-fb-', $article );
		$article=$pieces[0];
		$article=$requri[count($requri)-1];
		$pieces = explode( '?', $article );
		$article=$pieces[0];
		$url="http://".$_SERVER['SERVER_NAME'].$_SERVER["PHP_SELF"];
		$urlparts=explode('index', $url);
		$firstparturl= $urlparts[0];
	/** SEO **/

	/*** read page content, build variables: $titel, $meta, $text...***/
		/*** read entry***/
		$file=$article;
		if ($file==$index or (empty($file))){$file="Startseite";$start=1;}
		$Pfad= "$Pfaddaten/$file.dat";$datei = fopen($Pfad, "r");$savethetext=fread($datei, filesize($Pfad));fclose($datei);
		$arrayseite = explode ("---///___", $savethetext);
		$titel= $arrayseite[0];
		$meta= $arrayseite[1];
		$text= str_replace("../image/", $firstparturl. "image/",$arrayseite[2]);
		$text= str_replace("../download/", $firstparturl. "download/",$text);

		/*** read entry***/
		$file="dat_menu_file";
		$Pfad= "$Pfaddaten/$file.dat";$datei = fopen($Pfad, "r");$savethetext=fread($datei, filesize($Pfad));fclose($datei);
		$arrayseite = explode ("---///___", $savethetext);
		$menuarray=explode ("\n",$arrayseite[2]);
	/*** ... read page content, build variables: $titel, $meta, $text: $titel, $meta, $text ***/


	/*** read site-navigation, build variables: $mainmenu , $submenu ,$backlink ...***/
		$backlink="<a href=".$firstparturl.">Home</a>";

	//Backlinks and levels
		for ($i=0; $i<count($menuarray);$i++){
		$this_level=strlen(str_replace(trim($menuarray[$i]), "",chop($menuarray[$i])));
		$menulevel[$i]=$this_level+1; //remember level
		$menuback[$this_level]=$menuarray[$i];
		$menuarray[$i]=preg_replace("/\r|\n/s", "", $menuarray[$i]);

		//Backlinks
		if (trim($article)==trim(encodeurl($menuarray[$i])))
		{
			$level=$this_level+1;$start_sub_menu=$new_sub_begin;$me=$i;
			for ($e=0; $e<count($menuback);$e++){if ($this_level>$e) if (!empty($menuback[$e])){$backlink=$backlink." / <a href=".  $firstparturl. $index. "/". encodeurl($menuback[$e]).">".$menuback[$e]. "</a>";$menuforlevel[$level]=$menuback[$e];}}
			$backlink=$backlink." / ". $menuarray[$i];$menuforlevel[$level+1]=$menuarray[$i];
		}				
		//Backlinks
		}
	/*** ...read site-navigation, build variables:$backlink***/

if (empty($level))$level=0;

function loadcontent($file)
{global $Pfaddaten,$Pfad,$datei,$firstparturl;
$Pfad= "$Pfaddaten/$file.dat";$datei = fopen($Pfad, "r");$savethetext=fread($datei, filesize($Pfad));fclose($datei);$arrayseite = explode ("---///___", $savethetext);$text2= str_replace("../image/", $firstparturl. "/image/",$arrayseite[2]);
return $text2;
}

function buildmenu($start_level, $end_level, $end_this, $limit = '0', $picture = '0')
{global $menuarray,$menulevel,$article,$level,$firstparturl,$index, $me;$limitcount=$limit;
if ($start_level==1)$start_level=0;
	for ($i=0; $i<=count($menuarray);$i++)
		{
			for ($e=$i-1; $e>=$stop;$e--) if ($menulevel[$e]<$menulevel[$i]) {$stop=$i;} //speichert in $e+1 das vorhergehende Menu
			$stop=count($menuarray);for ($f=$i+1; $f<=$stop;$f++){if ($menulevel[$f]<$menulevel[$i]) $stop=$i;}$stop=0; //speichert in $f-1 das Ende des Submenues ($f-1 ist bereits das andere Menü
			//echo  "p", $e+1, " e", $f-1, " ",$i, "x", $menulevel[$i], " - ",$menuarray[$i];
			if ($menulevel[$i]>$start_level and $menulevel[$i]<=$end_level) $enable=1; else $enable=0;
			if (empty($end_this) or ($end_this>=$menulevel[$i])) {if (($e < $me) and ($f-1 >$me)) $enable=1;} //enabled selected menues
			if ($start_level>1) if ($menulevel[$i]<$start_level) $enable=0; 
			
			if ($enable==1 and strlen(trim($menuarray[$i]))>0)					
				{$limit--;
				if ($limitcount==0 or $limit >= 0)
					{
					if(file_exists("image/". encodeurl($menuarray[$i])."-1-150.jpg") and $picture==1) $picture_load= "<img src=\"".$firstparturl."image/". encodeurl($menuarray[$i])."-1-150.jpg\" width=\"150\" alt=\"".trim($menuarray[$i])."\"> ";else $picture_load="";
						$trimit=trim($menuarray[$i]);
						if ($trimit{0}!="'")
						{
						if ($article==encodeurl($menuarray[$i]))
				 		$mainmenu= "$mainmenu <li class=\"level_$menulevel[$i]"."_". $start_level.$end_level.$end_this."\"><a href=\"".$firstparturl. $index. "/". encodeurl($menuarray[$i])."\" id=\"mainmenu_active\">".$picture_load.trim($menuarray[$i]). "</a></li>\n";
						else 
						$mainmenu= "$mainmenu <li class=\"level_$menulevel[$i]"."_". $start_level.$end_level.$end_this."\"><a href=\"".$firstparturl. $index. "/". encodeurl($menuarray[$i])."\" id=\"mainmenu_link\">".$picture_load.trim($menuarray[$i]). "</a></li>\n";			
						}
					}				
				}			
		}
return $mainmenu;
}


?>
