Файл: modules/news/news.php
Строк: 316
<?php
/* DCMS S (Special)
* Версия файла 0.0.1
* Дата последнего редактирования 25.11.2015
* Модифицировал densnet
*/
require_once H . 'sys/inc/start.php';
require_once H . 'sys/inc/compress.php';
require_once H . 'sys/inc/sess.php';
require_once H . 'sys/inc/settings.php';
require_once H . 'sys/inc/db_connect.php';
require_once H . 'sys/inc/ipua.php';
require_once H . 'sys/inc/fnc.php';
require_once H . 'sys/inc/user.php';
$set['title'] = 'Новости';
require_once H . 'sys/inc/thead.php';
$news = mysql_fetch_assoc(mysql_query("SELECT * FROM `news` WHERE `id` = '" . intval($_GET['news']) . "' LIMIT 1"));
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news` WHERE `id` = '$news[id]' LIMIT 1", $db), 0) == 0) {
header("Location: ?" . SID);
exit;
}
#Список тех, кому понравилась новость
if (isset($_GET['like_all'])) {
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '" . intval($_GET['news']) . "'"), 0);
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];
$k_sisa = $k_post - 1;
$q = mysql_query("SELECT * FROM `news_like` WHERE `id_news` = '" . intval($_GET['news']) . "' ORDER BY `id` DESC LIMIT $start, $set[p_str]");
if ($k_post == 0) {
echo "<div class = 'alert alert-info'>";
echo "<span class='fa fa-info-circle'></span> Нет результатов";
echo "</div>";
}
while ($post = mysql_fetch_assoc($q)) {
$ank = user::get_user($post['id_user']);
echo "<div class='list-group-item'>";
avatar($ank['id'], '30');
user($ank['id']);
echo "</div>";
}
if ($k_page > 1) {
echo $k_sisa;
}
echo "<div class='list-group-item'><a href='" . DIR_NEWS . "'><span class='fa fa-arrow-left'></span> Новости</a></div>";
require_once H . 'sys/inc/tfoot.php';
}
if (isset($_GET['like']) && isset($user)) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '" . intval($_GET['news']) . "' AND `id_user` = '$user[id]' LIMIT 1"), 0) != 0) {
} else {
mysql_query("INSERT INTO `news_like` (`id_user`, `id_news`) values('$user[id]', '" . intval($_GET['news']) . "')");
}
header("Location: ?news=" . intval($_GET['news']) . "" . SID);
}
if (isset($_GET['unlike']) && isset($user)) {
mysql_query("DELETE FROM `news_like` WHERE `id_user` = '$user[id]' AND `id_news` = '" . intval($_GET['news']) . "' LIMIT 1");
header("Location: ?news=" . intval($_GET['news']) . "" . SID);
}
if (isset($_POST['msg']) && isset($user) && $news['close'] == 0) {
$msg = $_POST['msg'];
$mat = text::antimat($msg);
if ($mat) {
$err[] = 'В тексте сообщения обнаружен мат: ' . $mat;
}
if (text::utf8_strlen($msg) > 10024) {
$err = 'Сообщение слишком длинное';
} elseif (text::utf8_strlen($msg) < 2) {
$err = 'Короткое сообщение';
} elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '" . intval($_GET['news']) . "' AND `id_user` = '$user[id]' AND `msg` = '" . mysql_real_escape_string($msg) . "' LIMIT 1"), 0) != 0) {
$err = 'Ваше сообщение повторяет предыдущее';
} elseif (!isset($err)) {
mysql_query("INSERT INTO `news_komm` (`id_user`, `time`, `msg`, `id_news`) values('$user[id]', '$time', '" . mysql_real_escape_string($msg) . "', '" . intval($_GET['news']) . "')");
mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] + 3) . "', `activity` = '" . ($user['activity'] + 2) . "' WHERE `id` = '$user[id]' LIMIT 1");
$q = mysql_query("SELECT * FROM `friends` WHERE `user` = '" . $user['id'] . "' AND `i` = '1'");
while ($f = mysql_fetch_array($q)) {
$a = user::get_user($f['friends']);
$not_set = mysql_fetch_array(mysql_query("SELECT * FROM `notification_set` WHERE `id_user` = '" . $a['id'] . "' LIMIT 1"));
if ($f['lenta_news'] == 1 && $not_set['lenta_news'] == 1) {
$not_msg = "$SexKomm новость [url=/modules/news/?news=$news[id]&p=$pageEnd]" . htmlspecialchars($news['title']) . "[/url]";
mysql_query("INSERT INTO `notifications` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$a[id]', '$not_msg', '$time')");
}
}
msg('Ваше сообщение успешно добавлено');
header("Location: ?news=" . intval($_GET['news']) . "" . SID);
exit;
}
}
#Удаление комментария
if (isset($_GET['del']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id` = '" . intval($_GET['del']) . "'"), 0) && isset($user) && $user['level'] > 2) {
mysql_query("DELETE FROM `news_komm` WHERE `id` = '" . intval($_GET['del']) . "'");
header("Location: ?news=" . intval($_GET['news']) . "" . SID);
}
err();
if (isset($user) && $user['id'] != $news['id']) {
mysql_query("UPDATE `news` SET `prosm` = '" . ($news['prosm'] + 1) . "' WHERE `id` = '$news[id]' LIMIT 1");
}
$like = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '" . $news['id'] . "'"), 0);
echo "<div class='card-block'>";
echo "<h4><a href = '?news=$news[id]'>" . text::toOutput($news['title']) . "</a></h4>";
echo "<small style = 'color: #9197a3;'>";
echo "<span class='fa fa-user'></span> $news[avtor] · <span title = '" . date::time($news['time']) . "'>" . date::times($news['time']) . "</span> ";
if (user::access('adm_news_edit') || user::access('adm_news_delete')) {
if (user::access('adm_news_edit')) {
echo "<a href='?edit=$news[id]'>· Редактировать</a> ";
}
if (user::access('adm_news_delete')) {
echo "<a href='?delete=$news[id]'>· Удалить</a>";
}
}
echo "</small>";
echo "<div class='hr'></div>";
#Текст новости
echo "" . text::toOutput($news['msg']) . "<br />";
#Изображение, если есть
if ($user['set_news'] == 1) {
if (is_file(H . 'modules/news/images/' . $news['id'] . '.png')) {
echo "<br /><img src = '/modules/news/images/$news[id].png' style = 'border: 1px solid #CCDDED; padding: 2px; border-radius: 5px; max-width: 150px;' />";
}
}
if (isset($user)) {
echo "<div class = 'hr'></div>";
#Просмотры
echo "<span title = 'Просмотрели " . sklon_text($news['prosm'], array('раз', 'раза', 'раз')) . "' style = 'float:right;'><span class='fa fa-eye'></span> $news[prosm]</span>";
if ($news['link'] != NULL) {
echo "<a href = '" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "' title = 'Перейти, чтобы узнать подробности'><span class='fa fa-share-alt'></span> Источник</a> ";
}
if ($like == 0) {
$l = null;
} else {
$l = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '$news[id]'"), 0);
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '$news[id]' AND `id_user` = '$user[id]' LIMIT 1"), 0) == 0) {
echo "<a href = '?news=$news[id]&like'><span class='fa fa-heart-o'></span> Нравится $l</a> ";
} else {
echo "<a href = '?news=$news[id]&unlike'><span class='fa fa-heart'></span> Нравится $l</a> ";
}
$kom = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$news[id]' AND `id_user` = '$user[id]' LIMIT 1"), 0);
if ($kom == 0) {
$komms = null;
} else {
$komms = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$news[id]' AND `id_user` = '$user[id]' LIMIT 1"), 0);
}
if ($kom == 0) {
echo "<a title = 'Комментировать'><span class='fa fa-comment-o'></span> Комментарий $komms ";
if ($news['close'] == 1) {
echo "<span class='fa fa-lock'></span>";
}
echo "</a> ";
} else {
echo "<a title = 'Комментировать'><span class='fa fa-comment'></span> Комментарий $komms ";
if ($news['close'] == 1) {
echo "<span class='fa fa-lock'></span>";
}
echo "</a> ";
}
$kum = @mysql_result(mysql_query("SELECT id_user FROM `news_like` WHERE `id_news` = '$news[id]'"), 0);
$kom = @mysql_result(mysql_query("SELECT nick FROM `user` WHERE `id` = '$kum' LIMIT 1"), 0);
$kem = $like - 1;
#Выводит тех, кому понравилась новость
if ($user['id'] == $kum) {
if ($like == 1) {
$vam = "Вам это нравится";
} elseif ($like >= 2) {
$vam = "Вам и еще <a href = '/modules/news/?news=$news[id]&like_all'>" . sklon_text($kem, array('пользователю', 'пользователям', 'пользователям')) . "</a> это нравится";
}
} else {
$vam = "<a href = '/modules/news/?news=$news[id]&like_all'>" . sklon_text($like, array('пользователю', 'пользователям', 'пользователям')) . "</a> это нравится";
}
if ($like == 1) {
echo "<div class = 'hr'></div>";
echo "<font color = '#B2B2B2'><span class='fa fa-heart'></span> $vam</font>";
} elseif ($like >= 2) {
echo "<div class = 'hr'></div>";
echo "<font color = '#B2B2B2'><span class='fa fa-heart'></span> $vam</font>";
}
}
echo "</div>";
if ($news['close'] == 1) {
echo "<div class='card-block'><div class = 'label label-danger'>";
echo "<span class='fa fa-lock'></span> Новость закрыта для обсуждения";
echo "</div></div>";
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '" . intval($_GET['news']) . "'"), 0);
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];
$q = @mysql_query("SELECT * FROM `news_komm` WHERE `id_news` = '" . intval($_GET['news']) . "' ORDER BY `id` $sort LIMIT $start, $set[p_str]");
if (isset($user)) {
if (isset($user) && $news['close'] == 0) {
echo "<form class='card-block' name='form' method='POST' action='?news=" . intval($_GET['news']) . "&page=$page'>";
echo "<b>Сообщение</b><br />";
echo "<textarea name='msg' class='form-control' rows='2'></textarea><br/>";
echo "<button class='btn btn-success' name='ok'>Опубликовать</button>";
echo "</form>";
}
} else {
echo "<div class = 'card-block'>";
echo 'Для того, чтобы комментировать - Вам необходимо авторизоваться или зарегистрироваться';
echo "</div>";
}
if ($k_post == 0) {
echo "<div class='alert alert-info'>";
echo "<span class='fa fa-info-circle'></span> Нет результатов";
echo "</div>";
} else {
if (isset($user)) {
$li = "<li class='nav-item'><a class='nav-link' ";
$lir = "<li class='nav-item'><a class='nav-link' ";
echo "<div class='card-block'>";
echo "<ul class='nav nav-tabs'>";
if ($user['sort'] == 1) {
$lir = "<li class='nav-item'><a class='nav-link active' ";
} elseif ($user['sort'] == 0) {
$li = "<li class='nav-item'><a class='nav-link active' ";
} else {
$li = "<li class='nav-item'><a class='nav-link' ";
}
echo "$lir href='?news=" . intval($_GET['news']) . "&page=$page&sort=1'>Внизу</a></li>";
echo "$li href='?news=" . intval($_GET['news']) . "&page=$page&sort=0'>Вверху</a></li>";
echo "</ul>";
echo "</div>";
}
}
while ($post = mysql_fetch_assoc($q)) {
$ank = user::get_user($post['id_user']);
echo "<ul class='media-list media-list-conversation card-block' style='border-bottom: 1px solid #dcdee3;padding:3px;'>";
echo "<li class='media'>";
echo "<a class='media-left' href='/info.php?id=$ank[id]'>";
avatars($ank['id'], '40');
echo "</a>";
echo "<div class='media-body'><div class='media-body-text'>";
if ($post['otvet'] != 0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id`='$post[otvet]'"), 0) != 0) {
$otvet = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$post[otvet]'"));
}
if (isset($otvet)) {
echo "$otvet[nick], ";
}
echo text::toOutput($post['msg']);
echo "</div><div class='media-footer'>";
echo "<small class='text-muted'>";
echo user($ank['id']) . " <span data-toggle='tooltip' data-placement='right' title='" . date::time($post['time']) . "' style='color:grey;'>" . date::times($post['time']) . "</span> ";
if (isset($user)) {
echo "<span style = 'float: right;'>";
if (isset($user) && $news['close'] == 0 && $user['id'] != $ank['id']) {
echo "<a href = '?new_komm=$post[id]' title = 'Ответить'><span class='fa fa-pencil'></span></a> ";
}
if (isset($user) && $user['level'] > 2 || $user['id'] == $post['id_user'] && $post['time'] > time() - 600) {
echo "<a href = '?edit_komm=$post[id]' title = 'Изменить'><span class='fa fa-pencil-square-o'></span></a> ";
}
if (user::access('adm_news_delete_comments')) {
echo "<a href = '?news=$news[id]&del=$post[id]' title = 'Удалить'><span class='fa fa-trash-o'></span></a>";
}
echo "</span>";
}
echo "</small>";
echo "</div></div>";
echo "</li>";
if (isset($otvet)) {
unset($otvet);
}
echo "</ul>";
}
if ($k_page > 1) {
str("?news=" . intval($_GET['news']) . '&', $k_page, $page);
}
echo "<div class = 'card-block'><a href = '" . DIR_NEWS . "'><span class='fa fa-arrow-left'></span> Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';