<?
function menulink($name) {
$name= str_replace( ".dat", "",$name);
return strtolower(trim($name));
}
function makepermalink($thisurl) {
$thisurl=str_replace ( " ", "_", $thisurl);
$thisurl = preg_replace("/[^a-z0-9-_]/i","",$thisurl);
return strtolower(trim($thisurl));
}
function linkator($level, $sitetitle) {
	if (!empty($sitetitle)) { if ($level=='') {$lnav = "<a href=\"/\">Главная</a> - ".$sitetitle."";
                                        } else { $d='articles/';
	$dir = opendir($d);
	while ($f = readdir($dir)) {
 				$thefile=$level . ".dat";
 				$pos = strpos($f, $thefile);
 				if ($pos === false) {
	 			} else {
				$myFile = 'articles/' . $thefile;
				$fh = fopen($myFile, 'r');
				$data = fread($fh, filesize($myFile));
				fclose($fh);
       $text = explode("<!-- Kan_title -->",$data);
       $tlevel=$text[1];

				break;
  			}
	}
        $lnav = "<a href=\"/\">Главная</a> - <a href=\"/".$level.".html\">$tlevel</a> - ".$sitetitle."";}
        }
	return $lnav;
}
function pagecount() {
$d="../articles/";
	$dir = opendir($d);
	while ($f = readdir($dir)) {
       @$contentcenter = $contentcenter+1;
	} 
$contentcenter=$contentcenter-3;
return $contentcenter; 
}

function myconfig($findwhat) {
 $d="./engine/";
	$dir = opendir($d);
	while ($f = readdir($dir)) {
 				$thefile="config.php";
 				$pos = strpos($f, $thefile);
 				if ($pos === false) {

	 			} else {
				
				$myFile = 'engine/' . $thefile;

				$fh = fopen($myFile, 'r');
				$data = fread($fh, filesize($myFile));
				fclose($fh);

				switch ($findwhat) {
				case "template":
   					 $text = explode("<!-- Kan_template -->",$data);
   					 break;
				case "index":
   					 $text = explode("<!-- Kan_index -->",$data);
   					 break;
			  case "sitename":
   					 $text = explode("<!-- Kan_name -->",$data);
   					 break;
						 }

       @$contentcenter .=  trim($text[1]);
			 
			 }
	} 
return $contentcenter; 
}

function adminmyconfig($findwhat) { 

 $d="../engine/";
	$dir = opendir($d);
	while ($f = readdir($dir)) {
 				$thefile="config.php";
 				$pos = strpos($f, $thefile);
 				if ($pos === false) {

	 			} else {
				
				$myFile = "../engine/" . $thefile;

				$fh = fopen($myFile, 'r');
				$data = fread($fh, filesize($myFile));
				fclose($fh);

				switch ($findwhat) {
				case "template":
   					 $text = explode("<!-- Kan_template -->",$data);
   					 break;
				case "index":
   					 $text = explode("<!-- Kan_index -->",$data);
   					 break;
			  case "sitename":
   					 $text = explode("<!-- Kan_name -->",$data);
   					 break;
						 }

       @$contentcenter .=  trim($text[1]);
			 
			 }
	} 
return $contentcenter; 
}
?>