<?php

@$whatpage = preg_replace("/[^a-z0-9-_]/i","",$_REQUEST['whatpage']);
@$subpage = preg_replace("/[^a-z0-9-_]/i","",$_REQUEST['subpage']);
foreach ($_GET as $var => $secvalue) {
   if ((eregi ("<[^>]*script*\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*object*\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*iframe*\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*applet*\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*meta*\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*style*\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*form*\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*img*\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*onmouseover*\"?[^>]*>", $secvalue)) ||
   (eregi ("\([^>]*\"?[^)]*\)", $secvalue)) ||
   (eregi ("\"", $secvalue))) {
      die("BAD YOUR CODE");
      exit;
   }
}
foreach ($_POST as $secvalue) {
   if ((eregi ("<[^>]*script *\"?[^>]*>", $secvalue)) ||
   (eregi ("<[^>]*style*\"?[^>]*>", $secvalue))) {
      die("BAD YOUR CODE");
      exit;
   }
}
include "engine/functions.php";

$template=myconfig("template");
$sitename=myconfig("sitename");

$d='articles/';
$dir = opendir($d);

if (empty($whatpage)) {
	$myFile='articles/main.dat';
} else {
        $myFile="articles/" . $whatpage . ".dat";	
}

$fh = @fopen($myFile, 'r'); 

if (!$fh) {
  $myFile='articles/404.dat';
  $fh = @fopen($myFile, 'r'); 
} 

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

$text = explode("<!-- Kan_title -->",$data);
@$sitetitle=$text[1];
$text = explode("<!-- Kan_content -->",$data);
@$contentcenter .= $text[1];
$text = explode("<!-- Kan_myinclude -->",$data);
@$myinclude .= trim($text[1]);
$text = explode("<!-- Kan_description -->",$data);
@$metadescription .= trim($text[1]);
$text = explode("<!-- Kan_keywords -->",$data);
@$metakeywords .= trim($text[1]);

if (empty($whatpage)) {
	$myFile='articles/main.dat';
        @$lnav = '&nbsp;Добро пожаловать!';
} else {
        $myFile="articles/" . $whatpage . ".dat";	
        @$lnav=linkator($subpage, $sitetitle);
}
include "./templates/$template/template.php";
?>