Помогите пожалуйста с упраение кода: Код (PHP): [code]<?php $tools = array(); define('ROOT', dirname(__FILE__) . '/'); define('LANG', 'ru_RU'); define('TMP_NAME', 'Default'); function router(){ if ($_SERVER['REQUEST_URI'] == "/") { $module = 'option'; $page = 'index'; } else { $URL_Path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $URL_Parts = explode('/', trim($URL_Path, ' /')); $module = array_shift($URL_Parts); $page = array_shift($URL_Parts); if (!empty($module)) { $param = array(); for ($i = 0; $i < count($URL_Parts); $i++) { $param[$URL_Parts[$i]] = $URL_Parts[++$i]; } } } define('MODULE',$module); define('PAGE',$page); if(MODULE == "option"){ $option = ROOT.'location/'.PAGE.'.class.php'; if(!empty($page)){ require_once $option; $view = new $page; $view = $view->getBody(); echo $view; }else{ echo "home page"; } } elseif(MODULE == "admin"){ echo "admin"; } elseif(MODULE == "404"){ echo "404"; } else{ echo "page"; } } function loadTool($name, $sub_dir = '') { global $tools; if (in_array($name, $tools)) return; $tools[] = $name; require( MCR_ROOT . 'system/' . $sub_dir . $name); } abstract class Core { public function __construct(){ } private function ReplaceStringContent($tmp_content){ return str_replace("{content}",$this->getContent(), $tmp_content); } private function ReplaceString($tmp_content){ preg_match_all("/{file=(.*)}/",$tmp_content, $array_result); for($i=0;$i < count($array_result[0]);$i++){ $path_include = ROOT."/templates/".TMP_NAME."/".$array_result[1][$i].".tpl"; if(file_exists($path_include)){ $content_file = file_get_contents($path_include); $tmp_content = str_replace($array_result[0][$i],$content_file,$tmp_content); } } return $tmp_content; } function getRoot(){ return 'templates/'.TMP_NAME.'/'; } private function ReplaceStringRoot($tmp_content){ return str_replace("{root}",$this->getRoot(), $tmp_content); } private function ReplaceStringTitle($tmp_content){ return str_replace("{title}",$this->getTitle(), $tmp_content); } private function ReplaceStringSN($tmp_content){ return str_replace("{site_name}",SITE_NAME, $tmp_content); } private function ReplaceStringLogin($tmp_content){ if(isset($_SESSION['login'])){ $tmp_content = str_replace("{login}",$_SESSION['login'], $tmp_content); } return $tmp_content; } private function ReplaceStringMenu($tmp_content){ return str_replace("{menu}",$this->menu(),$tmp_content); } private function ReplaceStringlogged($tmp_content){ if(isset($_SESSION['login'])){ preg_match_all("/{is_notlogged}(.*){\/is_notlogged}/s",$tmp_content,$logged); $tmp_content = str_replace($logged[0],"",$tmp_content); $tmp_content = str_replace("{is_logged}","",$tmp_content); $tmp_content = str_replace("{/is_logged}","",$tmp_content); }else{ preg_match_all("/{is_logged}(.*){\/is_logged}/s",$tmp_content,$logged); $tmp_content = str_replace($logged[0],"",$tmp_content); $tmp_content = str_replace("{is_notlogged}","",$tmp_content); $tmp_content = str_replace("{/is_notlogged}","",$tmp_content); } return $tmp_content; } private function ReplaceStringPage($tmp_content){ preg_match("/{page=([a-z,]+)?}([^{}]+){\/page}/i",$tmp_content,$m); if(!empty($m)){ if(!isset($_GET['page'])){ if(isset($_GET['option']) == in_array($_GET['option'],explode(',', $m[1]))){ $tmp_content = str_replace("{page=".$m[1]."}","",$tmp_content); $tmp_content = str_replace("{/page}","",$tmp_content); }else{ $tmp_content = str_replace($m[0],"",$tmp_content); } }else{ $tmp_content = str_replace($m[0],"",$tmp_content); } } return $tmp_content; } private function ReplaceStringHomePage($tmp_content){ preg_match("/{homepage}([^{}]+){\/homepage}/i",$tmp_content,$m); if(!empty($m)){ if(isset($_GET['option'])){ if($_GET['option'] == "index" || $_GET['option'] == "category" || $_GET['option'] == "page" || $_GET['option'] == "search"){ $tmp_content = str_replace("{homepage}","",$tmp_content); $tmp_content = str_replace("{/homepage}","",$tmp_content); }else{ $tmp_content = str_replace($m,"",$tmp_content); } }else{ $tmp_content = str_replace($m,"",$tmp_content); } } return $tmp_content; } private function ReplaceStringGroup($tmp_content){ //preg_match_all("/{group=(.*)}/d",$tmp_content,$gr); //preg_match_all($gr[0]."/(.*){\/group}/s",$tmp_content,$group); preg_match('/{group=(\d+)}(.*){\/group}/s', $tmp_content, $m); if(!empty($m)){ if(isset($_SESSION['login'])){ $user=$_SESSION['login']; global $mysqli; $groups = $mysqli->query("SELECT group_id FROM users WHERE login = '$user'"); $groups = $groups->fetch_assoc(); if($groups['group_id'] < $m[1]+1){ $tmp_content = str_replace("{group=".$m[1]."}","",$tmp_content); $tmp_content = str_replace("{/group}","",$tmp_content); }else{ $tmp_content = str_replace($m[0],"",$tmp_content); } }else{ $tmp_content = str_replace($m[0],"",$tmp_content); } } return $tmp_content; } private function ReplaceStringNotGroup($tmp_content){ preg_match('/{notgroup=(\d+)}(.*){\/notgroup}/s', $tmp_content, $m); if(!empty($m)){ if(isset($_SESSION['login'])){ $user=$_SESSION['login']; global $mysqli; $groups = $mysqli->query("SELECT group_id FROM users WHERE login = '$user'"); $groups = $groups->fetch_assoc(); if($groups['group_id'] > $m[1]+1){ $tmp_content = str_replace("{notgroup=".$m[1]."}","",$tmp_content); $tmp_content = str_replace("{/notgroup}","",$tmp_content); }else{ $tmp_content = str_replace($m[0],"",$tmp_content); } }else{ $tmp_content = str_replace($m,"",$tmp_content); } } return $tmp_content; } private function ReplaceStringError($tmp_content){ preg_match('/{error}/', $tmp_content, $m); if(isset($_POST['error'])){ return str_replace($m[0],$_POST['error'],$tmp_content); }else{ return str_replace($m[0],"",$tmp_content); } } public function getBody() { $tmp_url = ROOT.'templates/'.TMP_NAME.'/main.tpl'; if(file_exists($tmp_url)){ $tmp = file_get_contents($tmp_url); $tmp = $this ->ReplaceString($tmp); $tmp = $this ->ReplaceString($tmp); $tmp = $this ->ReplaceStringTitle($tmp); $tmp = $this ->ReplaceStringSN($tmp); $tmp = $this ->ReplaceStringContent($tmp); $tmp = $this ->ReplaceStringRoot($tmp); //$tmp = $this->ReplaceStringMenu($tmp); $tmp = $this->ReplaceStringPage($tmp); $tmp = $this->ReplaceStringGroup($tmp); $tmp = $this ->ReplaceStringNotGroup($tmp); $tmp = $this->ReplaceStringHomePage($tmp); $tmp = $this->ReplaceStringError($tmp); $tmp = $this ->ReplaceStringlogged($tmp); $tmp = $this ->ReplaceStringLogin($tmp); return $tmp; //file_put_contents($save, $tmp); //require_once $save; //unlink($save); }else{ throw new Exception("Шаблон не найден или не существует"); } } abstract function getContent(); abstract function getTitle(); } ?> [/code] {/code}