Guest User

inedex.php

a guest
Aug 29th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.96 KB | None | 0 0
  1. <?php
  2.  
  3.         //Устанавливаем уровень ошибок и стратуем сессии
  4.  
  5.         error_reporting(E_ALL &~E_NOTICE);
  6.         session_start();
  7.         ob_implicit_flush(0);
  8.        
  9.         //Создаем константы с путями
  10.         define("BASE_DIR", $_SERVER['DOCUMENT_ROOT'] . "/"); //Индексный путь
  11.         define("TPL_DIR", BASE_DIR . "template/"); //Путь к папке с шаблоном
  12.         define("SYS_DIR", BASE_DIR . "system/"); //Путь к системной папке
  13.         define("SYS_KEY", true); //Создаем ключ для того чтоб к чичтемным файлам не обратились на прямую
  14.         $mod = $_GET['mod'];
  15.        
  16.         //Подключаем файлы настроек.
  17.         require SYS_DIR . 'data/db.php';
  18.         require SYS_DIR . 'data/config.php';
  19.    
  20.     //файл соеденения с БД
  21.         require SYS_DIR . 'classes/mysql.class.php';
  22.     //Экземпляр соеденения с БД
  23.             $mysql = new mysql;
  24.    
  25.         //Подключаем файл роутера
  26.         require SYS_DIR . 'router.php';
  27.      
  28.     //Подключаем файлы с классами
  29.         require SYS_DIR . 'classes/template.class.php';
  30.         require SYS_DIR . 'classes/bbcodes.class.php'; 
  31.            
  32.                        
  33.         $router = new router; //Создаем экземпляр роутера
  34.         $template = new template; //Создаем экземпляр класса template
  35.         $bbcode = new BBcode; //Создаем экземпляр класса BBcode
  36.        
  37.        
  38.         $tpl['main'] = ''; //Перемменная с главным шаблоном сайта
  39.            
  40.                 if(isset($_COOKIE['user_hash']))
  41.                 {
  42.                  $hash = htmlspecialchars($_COOKIE['user_hash']);
  43.                  $select_user = $mysql->query("SELECT `id` FROM `users` WHERE `hash`='". $hash ."' and `activation`='1'");
  44.                  if(mysql_num_rows($select_user) > 0)
  45.                  {
  46.                         $group = $router->user_group($_COOKIE['user_hash']);                        
  47.                         if($config['work_site'] == "off")
  48.                         {
  49.                              if($group['view_offsite'] == 0)
  50.                              {
  51.                                     $tpl['main'] = $config['work_offsite_text'];
  52.                              }
  53.                         }
  54.                      $user = true;
  55.                     }
  56.                  else
  57.                  {
  58.                         if($config['work_site'] == "off")
  59.                          {
  60.                              $tpl['main'] = $config['work_offsite_text'];
  61.                         }
  62.                         $user = false;
  63.                  }
  64.                 }        
  65.  
  66.                        
  67.             if(isset($mod))
  68.                 {
  69.                
  70.                  switch($mod)
  71.                      {
  72.                             case "news":
  73.                      require SYS_DIR . 'classes/news.class.php';
  74.                  $news = new news;
  75.                                  $main = $news->view($user);//Модуль показа новостей
  76.                             break;
  77.                            
  78.                             case "category":
  79.                                  $main = $router->category($user,$mysql); //Модуль показа категории
  80.                             break;
  81.                            
  82.                             default:
  83.                                  $main = $router->GetPage($_GET['mod'],$user,$mysql); //Если указан иной модуль то ищем в папке с модулями файл, с таким именем как у модуля
  84.                             break;
  85.                      
  86.                         }
  87.                  
  88.                 }
  89.                 else
  90.                 {
  91.                      $main = $router->index($user);
  92.                 }
  93.        
  94.         define("TPL_SCRIPTS", $router->get_scripts($mod)); 
  95.         define("TPL_DESCRIPTION", $main['description']);
  96.         define("TPL_KEYWORDS", $main['keywords']);
  97.         define("TPL_CONTENT", $main['content']);
  98.         define("TPL_TITLE", $main['title']);
  99.         define("TPL_ARHIV", $template->load_usermodul("arhiv"));
  100.         define("TPL_POPNEWS", $template->load_usermodul("pop_news"));
  101.         define("TPL_LOGIN", $template->load_usermodul("login"));
  102.         define("TPL_SEARCH", $template->load_usermodul("search"));
  103.         define("TPL_POLL", $template->load_usermodul("poll"));
  104.                
  105.         //Создаем массив с кодом для замены блоков в шаблоне
  106.     $tpl_replace = array
  107.                             (                
  108.                                  '{content}'                 => TPL_CONTENT,
  109.                                  '{poll}'                        => TPL_POLL,
  110.                                  '{popnews}'                 => TPL_POPNEWS,
  111.                                  '{search}'                    => TPL_SEARCH,
  112.                                  '{login}'                     => TPL_LOGIN,
  113.                                  '{arhives}'                 => TPL_ARHIV,
  114.                                  '{title}'                     => TPL_TITLE,
  115.                                  '{engine_scripts}'    => TPL_SCRIPTS,
  116.                  '{description}'         => TPL_DESCRIPTION,
  117.                  '{keywords}'                => TPL_KEYWORDS
  118.                                 );
  119.     if(empty($tpl['main']))
  120.         {  
  121.          $tpl['main'] = $template->load_template("main.tpl", $tpl_replace);
  122.     }
  123.                          
  124.                 //проверяем, были ли ошибки в результате выполнения скрипта?
  125.                 if(isset($_SESSION['engine_error'][0]))
  126.                 {
  127.                      exit($_SESSION['engine_error'][0]);
  128.                 }
  129.                 else
  130.                 {
  131.              echo $tpl['main'];
  132.         }
Advertisement
Add Comment
Please, Sign In to add comment