108 lines
5.6 KiB
PHP
108 lines
5.6 KiB
PHP
<?php
|
||
ini_set('display_errors', 0);
|
||
@mkdir('img/' . $_SERVER['SERVER_NAME'] . '/ava', 0700);
|
||
/* ----------------------------------------------------------------------
|
||
11.02.2023
|
||
Получаем страницу
|
||
---------------------------------------------------------------------- */
|
||
$page = \DB::getAll("SELECT * FROM `pages` WHERE `id`=? LIMIT 1", $_GET['id']);
|
||
if ($page[0]['status']==0)header( 'Location: /403/' );
|
||
$page[0]['date']=date('d.m.Y', $page[0]['t']);
|
||
|
||
|
||
/* ----------------------------------------------------------------------
|
||
02.04.2024
|
||
Получаем обложку
|
||
---------------------------------------------------------------------- */
|
||
$page[0]['img']=\DB::getValue("SELECT `filename` FROM `pages_img` WHERE `pages_id`=? LIMIT 1", $page[0]['id']);
|
||
|
||
|
||
|
||
$smarty->assign('page', $page);
|
||
/* ----------------------------------------------------------------------
|
||
02.04.2024
|
||
Получаем данные о категории
|
||
---------------------------------------------------------------------- */
|
||
$category_title=\DB::getValue("SELECT `title` FROM `pages_category` WHERE `id`=?", $page[0]['category']);
|
||
$smarty->assign('category_title', $category_title);
|
||
|
||
|
||
/* ----------------------------------------------------------------------
|
||
11.02.2023
|
||
Получаем данные о пользователе
|
||
---------------------------------------------------------------------- */
|
||
$autor=\DB::getAll("SELECT * FROM `users` WHERE `id`=? LIMIT 1", $page[0]['user_id']);
|
||
if ($autor[0]['dostup']=='a')$autor[0]['dostup']='Администратор сайта';
|
||
$smarty->assign('autor', $autor);
|
||
/* ----------------------------------------------------------------------
|
||
11.02.2023
|
||
Получаем количество статей пользователя
|
||
---------------------------------------------------------------------- */
|
||
$pageskolvo=\DB::getAll("SELECT count(*) FROM `pages` WHERE `user_id`=? AND `status`=1", $page[0]['user_id']);
|
||
$smarty->assign('pageskolvo', $pageskolvo[0]['count(*)']);
|
||
/* ----------------------------------------------------------------------
|
||
11.02.2023
|
||
Получаем коментарии
|
||
---------------------------------------------------------------------- */
|
||
$comments=\DB::getAll("SELECT * FROM `pages_comments` WHERE `page_id`=? AND `status`=1 ORDER BY `id` DESC", $page[0]['id']);
|
||
//Получаем инфу о пользователе - аву и фио
|
||
for ($i=0; $i<count($comments); $i++){
|
||
$user_info=\DB::getAll("SELECT `fio`, `ava` FROM `users` WHERE `id`=? LIMIT 1", $comments[$i]['user_id'] );
|
||
$comments[$i]['ava']=$user_info[0]['ava'];
|
||
$comments[$i]['fio']=$user_info[0]['fio'];
|
||
unset($user_info);
|
||
}
|
||
$smarty->assign('comments', $comments);
|
||
/* ----------------------------------------------------------------------
|
||
14.02.2023
|
||
Пишем статистику
|
||
---------------------------------------------------------------------- */
|
||
$see=\DB::getValue("SELECT `see` FROM `pages` WHERE `id`=? LIMIT 1", $page[0]['id']);
|
||
$user_id=($_SESSION['user_id'])?$_SESSION['user_id']:session_id();
|
||
$id=\DB::getValue("SELECT `id` FROM `likes` WHERE `content_id`=? AND `user_id`=? AND `tip`='see' LIMIT 1", array($page[0]['id'], $user_id));
|
||
if (!$id){
|
||
$see++;
|
||
\DB::set("UPDATE `pages` SET `see`=? WHERE `id`=? LIMIT 1", array($see, $page[0]['id']));
|
||
\DB::add("INSERT INTO `likes` (`user_id`, `content_id`, `tip`) VALUES(?, ?, ?)", array($user_id, $page[0]['id'], 'see'));
|
||
}
|
||
$smarty->assign('see', $see);
|
||
|
||
|
||
|
||
/* ----------------------------------------------------------------------
|
||
01.04.2023
|
||
Получаем спиосок категорий страниц
|
||
---------------------------------------------------------------------- */
|
||
$categories=\DB::getAll("SELECT * FROM `pages_category` ORDER BY `title`");
|
||
for ($i=0; $i<count($categories); $i++)$categories[$i]['count']=\DB::getAll("SELECT COUNT(*) FROM `pages` WHERE `category`=? AND `status`=1", $categories[$i]['id'])[0]['COUNT(*)'];
|
||
$smarty->assign('categories', $categories);
|
||
|
||
/* ----------------------------------------------------------------------
|
||
02.04.2023
|
||
Получаем самое читабельное
|
||
---------------------------------------------------------------------- */
|
||
$popular_pages=\DB::getAll("SELECT * FROM `pages` WHERE `status`=1 ORDER BY `see` DESC LIMIT 5");
|
||
for ($i=0; $i<count($popular_pages); $i++)$popular_pages[$i]['img']=\DB::getValue("SELECT `filename` FROM `pages_img` WHERE `pages_id`=? LIMIT 1", $popular_pages[$i]['id']);
|
||
//print_r($popular_pages);
|
||
$smarty->assign('popular_pages', $popular_pages);
|
||
|
||
/* ----------------------------------------------------------------------
|
||
02.04.2023
|
||
Получаем вложенные изображения, кроме первого
|
||
---------------------------------------------------------------------- */
|
||
|
||
$page_img=\DB::getAll("SELECT * FROM `pages_img` WHERE `pages_id`=?", $page[0]['id']);
|
||
unset($page_img[0]);
|
||
$smarty->assign('page_img', $page_img);
|
||
//print_r($page_img);
|
||
|
||
/* ----------------------------------------------------------------------
|
||
02.04.2023
|
||
Получаем коменты
|
||
---------------------------------------------------------------------- */
|
||
$comments=\DB::getAll("SELECT * FROM `pages_comments` WHERE `page_id`=? AND `status`=1 ORDER BY `t` DESC", $page[0]['id']);
|
||
for ($i=0; $i<count($comments); $i++)$comments[$i]['fio']=\DB::getValue("SELECT `fio` FROM `users` WHERE `id`=?", $comments[$i]['user_id']);
|
||
//print_r($comments);
|
||
$smarty->assign('comments', $comments);
|
||
|
||
?>
|