Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!defined('SYS_KEY'))
- exit('Used no success');
- class router {
- public function GetPage($mod, $user = false, $mysql) {
- global $config;
- $mod = !isset($mod) ? $_GET['mod'] : $mod;
- if (!preg_match("/^[a-z]/", $mod)) {
- $result = array
- (
- 'title' => 'Модуль не найден -> ' . $config['title'],
- 'content' => '<p>Формат имени модуля не соответсвует заданным параметрам. Он должен состоять только из букв латинского алфавита и не каких пробелов.</p>'
- );
- } else {
- $user = $this->information($_COOKIE['user_hash']);
- if (!isset($user)) {
- $user_info = array(
- 'hash' => false,
- );
- } else {
- $user_info = array(
- 'hash' => $_COOKIE['user_hash'],
- );
- }
- $dir = SYS_DIR . 'modules/' . $mod . '.php';
- if (!file_exists($dir)) {
- $result = array('title' => 'Модуль не найден -> ' . $config['title'], 'content' => 'На сайте нет такого модуля');
- } else {
- require $dir;
- $result = modul($user_info);
- return array(
- 'content' => $result['content'],
- 'title' => $result['title'],
- 'description' => $config['description'],
- 'keywords' => $config['keyword']
- );
- }
- }
- }
- public function get_scripts($mod = "page_all") {
- require SYS_DIR . 'library/scripts.php';
- $scripts = '';
- if ($mod = "page_all") {
- foreach ($scripts_array as $k => $v) {
- if ($k == $mod) {
- $scripts .= $v;
- }
- }
- } else {
- foreach ($scripts_array as $k => $v) {
- if ($k == $mod or $k == "page_all") {
- $scripts .= $v;
- }
- }
- }
- return $scripts;
- }
- public function index($user = false) {
- global $config, $bbcode, $router, $template, $mysql;
- $num = $config['number_news'];
- $page = $_GET['page'];
- if (empty($num) or !isset($num) or $num < 1)
- $num = 10;
- if ($page == 0 or empty($page) or !isset($page) or $page < 0)
- $page = 1;
- $query = "SELECT COUNT(`id`) FROM `news` WHERE `public`='1'";
- $mysql_result = $mysql->query($query);
- if (mysql_num_rows($mysql_result) > 0) {
- $count = mysql_fetch_row($mysql_result);
- }
- $posts = $count[0];
- $total = intval(($posts - 1) / $num) + 1;
- $page = intval($page);
- $start = $page * $num - $num;
- if ($page != 1)
- $pervpage = '<a href="' . $name . '/">Первая</a>
- <a href="' . $name . '/' . ($page - 1) . '/">Предыдущая</a> ';
- if ($page != $total)
- $nextpage = '<a href="' . $name . '/' . ($page + 1) . '/">Следующая</a>
- <a href="' . $name . '/' . $total . '/">Последняя</a> ';
- if ($page - 2 > 0)
- $page2left = ' <a href="' . $name . '/' . ($page - 2) . '/">' . ($page - 2) . '</a> ';
- if ($page - 1 > 0)
- $page1left = '<a href="' . $name . '/' . ($page - 1) . '/">' . ($page - 1) . '</a> ';
- if ($page + 2 <= $total)
- $page2right = ' <a href="' . $name . '/' . ($page + 2) . '/">' . ($page + 2) . '</a>';
- if ($page + 1 <= $total)
- $page1right = ' <a href="' . $name . '/' . ($page + 1) . '/">' . ($page + 1) . '</a>';
- $query = $mysql->query("SELECT * FROM `news` WHERE `public`='1' ORDER BY `id` DESC LIMIT $start, $num");
- if (mysql_num_rows($query) > 0) {
- if (isset($_POST['login_click'])) {
- $complate = $this->GetPage("auth");
- } else {
- ob_start();
- while ($news = mysql_fetch_assoc($query)) {
- $select_cat = $mysql->query("SELECT `title`,`alt_name` FROM `categories` WHERE `id`='" . $news['cat'] . "'") or die(mysql_error());
- $cat = mysql_fetch_assoc($select_cat);
- $url = '/news/' . $news['alt_name'] . ".html";
- $news['description'] = $bbcode->createBBtags($news['description']);
- $cat_url = '<a href="/category/' . $cat['alt_name'] . '">' . $cat['title'] . "</a>";
- $tpl_replace = array('{date}' => $news['date'], '{title}' => $news['title'], '{url_full}' => $url, '{description}' => $news['description'], '{author}' => $news['author'], '{category}' => $cat_url);
- echo $template->load_template("news.tpl", $tpl_replace);
- }
- echo $view_navigation = $router->view_navigation($total, $pervpage, $page2left, $page1left, $page, $page1right, $page2right, $nextpage);
- $complate['content'] = ob_get_contents();
- ob_end_clean();
- }
- } else {
- $complate = "<p>В Базе Данных сайта нет новостей либо вы указали не существующую страницу</p>";
- }
- if ($page > 1) {
- $title = "Страница " . $page . ' -> ' . $config['title'];
- } else {
- $title = $config['title'];
- }
- $content = $complate['content'];
- $title = $title ? $title : $complate['title'];
- $array = array(
- 'content' => $content,
- 'title' => $title,
- 'description' => $config['description'],
- 'keywords' => $config['keyword']
- );
- return $array;
- }
- public function user_group($hash) {
- if (!isset($hash)) {
- $not_information = "2";
- } else {
- $select_id_group = mysql_query("SELECT `group` FROM `users` WHERE `hash`='" . $hash . "'") or die(mysql_error());
- if (mysql_num_rows($select_id_group) > 0) {
- $user = mysql_fetch_assoc($select_id_group);
- $id_group = (int) $user['group'];
- } else {
- $id_group = "2";
- }
- }
- $id_group = isset($not_information) ? $not_information : $id_group;
- $query = mysql_query("SELECT * FROM `users_group` WHERE `id`='" . $id_group . "'") or die(mysql_error());
- return mysql_fetch_assoc($query);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment