Guest User

router.php

a guest
Aug 29th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.89 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('SYS_KEY'))
  4.     exit('Used no success');
  5.  
  6. class router {
  7.  
  8.     public function GetPage($mod, $user = false, $mysql) {
  9.  
  10.         global $config;
  11.         $mod = !isset($mod) ? $_GET['mod'] : $mod;
  12.  
  13.         if (!preg_match("/^[a-z]/", $mod)) {
  14.             $result = array
  15.                 (
  16.                 'title' => 'Модуль не найден -> ' . $config['title'],
  17.                 'content' => '<p>Формат имени модуля не соответсвует заданным параметрам. Он должен состоять только из букв латинского алфавита и не каких пробелов.</p>'
  18.             );
  19.         } else {
  20.             $user = $this->information($_COOKIE['user_hash']);
  21.  
  22.             if (!isset($user)) {
  23.                 $user_info = array(
  24.                     'hash' => false,
  25.                 );
  26.             } else {
  27.                 $user_info = array(
  28.                     'hash' => $_COOKIE['user_hash'],
  29.                 );
  30.             }
  31.  
  32.             $dir = SYS_DIR . 'modules/' . $mod . '.php';
  33.             if (!file_exists($dir)) {
  34.                 $result = array('title' => 'Модуль не найден -> ' . $config['title'], 'content' => 'На сайте нет такого модуля');
  35.             } else {
  36.                 require $dir;
  37.                 $result = modul($user_info);
  38.                 return array(
  39.                     'content' => $result['content'],
  40.                     'title' => $result['title'],
  41.                     'description' => $config['description'],
  42.                     'keywords' => $config['keyword']
  43.                 );
  44.             }
  45.         }
  46.     }
  47.  
  48.     public function get_scripts($mod = "page_all") {
  49.         require SYS_DIR . 'library/scripts.php';
  50.         $scripts = '';
  51.         if ($mod = "page_all") {
  52.             foreach ($scripts_array as $k => $v) {
  53.                 if ($k == $mod) {
  54.                     $scripts .= $v;
  55.                 }
  56.             }
  57.         } else {
  58.  
  59.             foreach ($scripts_array as $k => $v) {
  60.                 if ($k == $mod or $k == "page_all") {
  61.                     $scripts .= $v;
  62.                 }
  63.             }
  64.         }
  65.         return $scripts;
  66.     }
  67.  
  68.     public function index($user = false) {
  69.  
  70.         global $config, $bbcode, $router, $template, $mysql;
  71.  
  72.  
  73.         $num = $config['number_news'];
  74.         $page = $_GET['page'];
  75.  
  76.         if (empty($num) or !isset($num) or $num < 1)
  77.             $num = 10;
  78.  
  79.         if ($page == 0 or empty($page) or !isset($page) or $page < 0)
  80.             $page = 1;
  81.  
  82.         $query = "SELECT COUNT(`id`) FROM `news` WHERE `public`='1'";
  83.         $mysql_result = $mysql->query($query);
  84.  
  85.         if (mysql_num_rows($mysql_result) > 0) {
  86.             $count = mysql_fetch_row($mysql_result);
  87.         }
  88.  
  89.         $posts = $count[0];
  90.         $total = intval(($posts - 1) / $num) + 1;
  91.         $page = intval($page);
  92.         $start = $page * $num - $num;
  93.  
  94.         if ($page != 1)
  95.             $pervpage = '<a href="' . $name . '/">Первая</a>
  96.                                                                                             <a href="' . $name . '/' . ($page - 1) . '/">Предыдущая</a> ';
  97.         if ($page != $total)
  98.             $nextpage = '<a href="' . $name . '/' . ($page + 1) . '/">Следующая</a>
  99.                                                                                                        <a href="' . $name . '/' . $total . '/">Последняя</a> ';
  100.         if ($page - 2 > 0)
  101.             $page2left = ' <a href="' . $name . '/' . ($page - 2) . '/">' . ($page - 2) . '</a>    ';
  102.         if ($page - 1 > 0)
  103.             $page1left = '<a href="' . $name . '/' . ($page - 1) . '/">' . ($page - 1) . '</a>    ';
  104.         if ($page + 2 <= $total)
  105.             $page2right = '    <a href="' . $name . '/' . ($page + 2) . '/">' . ($page + 2) . '</a>';
  106.         if ($page + 1 <= $total)
  107.             $page1right = '    <a href="' . $name . '/' . ($page + 1) . '/">' . ($page + 1) . '</a>';
  108.  
  109.         $query = $mysql->query("SELECT * FROM `news` WHERE `public`='1' ORDER BY `id` DESC LIMIT $start, $num");
  110.         if (mysql_num_rows($query) > 0) {
  111.  
  112.  
  113.             if (isset($_POST['login_click'])) {
  114.                 $complate = $this->GetPage("auth");
  115.             } else {
  116.                 ob_start();
  117.                 while ($news = mysql_fetch_assoc($query)) {
  118.                     $select_cat = $mysql->query("SELECT `title`,`alt_name` FROM `categories` WHERE `id`='" . $news['cat'] . "'") or die(mysql_error());
  119.                     $cat = mysql_fetch_assoc($select_cat);
  120.  
  121.                     $url = '/news/' . $news['alt_name'] . ".html";
  122.                     $news['description'] = $bbcode->createBBtags($news['description']);
  123.                     $cat_url = '<a href="/category/' . $cat['alt_name'] . '">' . $cat['title'] . "</a>";
  124.                     $tpl_replace = array('{date}' => $news['date'], '{title}' => $news['title'], '{url_full}' => $url, '{description}' => $news['description'], '{author}' => $news['author'], '{category}' => $cat_url);
  125.                     echo $template->load_template("news.tpl", $tpl_replace);
  126.                 }
  127.                 echo $view_navigation = $router->view_navigation($total, $pervpage, $page2left, $page1left, $page, $page1right, $page2right, $nextpage);
  128.  
  129.                 $complate['content'] = ob_get_contents();
  130.                 ob_end_clean();
  131.             }
  132.         } else {
  133.             $complate = "<p>В Базе Данных сайта нет новостей либо вы указали не существующую страницу</p>";
  134.         }
  135.  
  136.         if ($page > 1) {
  137.             $title = "Страница " . $page . ' -> ' . $config['title'];
  138.         } else {
  139.             $title = $config['title'];
  140.         }
  141.  
  142.         $content = $complate['content'];
  143.         $title = $title ? $title : $complate['title'];
  144.  
  145.         $array = array(
  146.             'content' => $content,
  147.             'title' => $title,
  148.             'description' => $config['description'],
  149.             'keywords' => $config['keyword']
  150.         );
  151.  
  152.         return $array;
  153.     }
  154.  
  155.     public function user_group($hash) {
  156.  
  157.         if (!isset($hash)) {
  158.             $not_information = "2";
  159.         } else {
  160.  
  161.             $select_id_group = mysql_query("SELECT `group` FROM `users` WHERE `hash`='" . $hash . "'") or die(mysql_error());
  162.  
  163.             if (mysql_num_rows($select_id_group) > 0) {
  164.                 $user = mysql_fetch_assoc($select_id_group);
  165.                 $id_group = (int) $user['group'];
  166.             } else {
  167.                 $id_group = "2";
  168.             }
  169.         }
  170.  
  171.         $id_group = isset($not_information) ? $not_information : $id_group;
  172.         $query = mysql_query("SELECT * FROM `users_group` WHERE `id`='" . $id_group . "'") or die(mysql_error());
  173.  
  174.         return mysql_fetch_assoc($query);
  175.     }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment