Файл: news/news.php
Строк: 306
<?php
/*
* Новости
* DCMS Special
* Модифицировал densnet
* Файл news.php
*/
require_once '../sys/inc/start.php';
require_once '../sys/inc/compress.php';
require_once '../sys/inc/sess.php';
require_once '../sys/inc/settings.php';
require_once '../sys/inc/db_connect.php';
require_once '../sys/inc/ipua.php';
require_once '../sys/inc/fnc.php';
require_once '../sys/inc/user.php';
$set['title'] = 'Новости';
require_once '../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['hide']) && isset($user)) {
#Только для зарегистрированных
only_reg();
if (!isset($_GET['news']) && !is_numeric($_GET['news'])) {
header("Location: /index.php?" . SID);
exit;
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news` WHERE `id` = '" . intval($_GET['news']) . "' LIMIT 1", $db), 0) == 0) {
header("Location: /index.php?" . SID);
exit;
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news_hide` WHERE `nid` = '" . intval($_GET['news']) . "' AND `uid` = '$user[id]' LIMIT 1", $db), 0)) {
header("Location: /index.php?" . SID);
exit;
}
mysql_query("INSERT INTO `news_hide` (`nid`,`uid`) VALUES ('" . intval($_GET['news']) . "','$user[id]')");
header("Location: /index.php?" . 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 "<table class = 'foot'><tr><td class = 'null'>";
echo "<img src = '/style/icons/bullet_error.png' /> Нет результатов";
echo "</td></tr></table>";
}
while ($post = mysql_fetch_assoc($q)) {
$ank = get_user($post['id_user']);
echo "<table class = 'foot'><tr><td class = 'icon48'>";
avatar($ank['id'], '60');
echo "</td><td class = 'null'>";
user($ank['id']);
echo "</td></tr></table>";
}
if ($k_page > 1) {
echo $k_sisa;
}
echo "<div class = 'foot'>";
echo "<img src = '/style/icons/left.png' /> <a href = '/news/'>Вернуться</a>";
echo "</div>";
require_once '../sys/inc/tfoot.php';
}
if (isset($_GET['likes']) && 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: /index.php" . SID);
}
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['unlikes']) && isset($user)) {
mysql_query("DELETE FROM `news_like` WHERE `id_user` = '$user[id]' AND `id_news` = '" . intval($_GET['news']) . "' LIMIT 1");
header("Location: /index.php" . 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 = antimat($msg);
if ($mat) {
$err[] = 'В тексте сообщения обнаружен мат: ' . $mat;
}
if (utf8_strlen($msg) > 10024) {
$err = 'Сообщение слишком длинное';
} elseif (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 = get_user($f['friends']);
$tape_set = mysql_fetch_array(mysql_query("SELECT * FROM `tape_set` WHERE `id_user` = '" . $a['id'] . "' LIMIT 1"));
if ($f['lenta_news'] == 1 && $tape_set['lenta_news'] == 1) {
$tape_msg = "" . ($user['sex'] ? 'прокомментировал' : 'прокомментировала') . " новость [url=/news/?news=$news[id]&page=$pageEnd]" . htmlspecialchars($news['title']) . "[/url]";
mysql_query("INSERT INTO `tape` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$a[id]', '$tape_msg', '$time')");
}
}
$event = "$user[nick] " . ($user['sex'] ? 'прокомментировал' : 'прокомментировала') . " новость [url=/news/?news=$news[id]&page=$pageEnd]" . htmlspecialchars($news['title']) . "[/url]";
mysql_query("INSERT INTO `events` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$user[id]', '$event', '$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']) . "'");
msg('Комментарий успешно удален');
}
err();
if (isset($user) && $user['id'] != $news['id']) {
mysql_query("UPDATE `news` SET `prosm` = '" . ($news['prosm'] + 1) . "' WHERE `id` = '$news[id]' LIMIT 1");
}
echo "<div class = 'foot'>";
echo "<img src = '/style/icons/feed.png' /> " . htmlspecialchars($news['title']) . "<br/>";
if ($news['link'] != NULL) {
echo "<img src = '/style/icons/url_mini.png' /> <a href = '" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "'>Подробности</a><br/>";
}
if (is_file(H . 'sys/news/' . $news['id'] . '.png')) {
echo "<img src = '/sys/news/$news[id].png' style = 'border: 1px solid #CCDDED; padding: 2px; border-radius: 5px; max-width: 150px;'/><br/>";
}
if (user_access('adm_news_edit') && user_access('adm_news_delete')) {
echo "<div class = 'right' id = 'hide'>";
echo "<a href = '?edit=$news[id]' title = 'Редактировать новость'><img src = '/style/icons/feed--pencil.png' /></a>";
echo "<a href = '?delete=$news[id]' title = 'Удалить новость'><img src = '/style/icons/feed--minus.png' /></a>";
echo "</div>";
}
echo output_text($news['msg']) . "<br />";
echo "</div><div class = 'foot'>";
echo "<font color = '#808080'><small>" . vremja($news['time']) . "</small></font> · ";
if (isset($user)) {
$like = 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) {
if ($like == 0) {
echo "<a href = '?news=$news[id]&like'><small>Мне нравится</small></a> ";
} else {
echo "<a href = '?news=$news[id]&like'><small>Мне нравится</small></a> ";
echo "<img src = '/style/icons/thumb_up_mini.png' /> <a href = '?news=$news[id]&like_all'>$like</a>";
}
} else {
if ($like == 0) {
echo "<img src = '/style/icons/thumb_up_mini.png' /> <a href = '?news=$news[id]&unlike'><small>Не нравится</small></a>";
} else {
echo "<a href = '?news=$news[id]&unlike'><small>Не нравится</small></a> ";
echo "<img src = '/style/icons/thumb_up_mini.png' /> <a href = '?news=$news[id]&like_all'>$like</a>";
}
}
$kum = @mysql_result(mysql_query("SELECT `id_user` FROM `news_like` WHERE `id_news` = '" . intval($_GET['news']) . "'"), 0);
$kom = @mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='$kum' LIMIT 1"), 0);
$kem = $like - 1;
if ($like == 1) {
echo "<div>";
echo "Новость понравилась <a href='/info.php?id=$kum'>$kom</a>";
echo "</div>";
} elseif ($like == 2) {
echo "<div>";
echo "Новость понравилась <a href = '/info.php?id=$kum'>$kom</a> и <a href = '?news=$news[id]&like_all'> ещё $kem пользователю.</a>";
echo "</div>";
} elseif ($like >= 3) {
echo "<div>";
echo "Новость понравилась <a href = '/info.php?id=$kum'>$kom</a> и <a href = '?news=$news[id]&like_all'> ещё $kem пользователям.</a>";
echo "</div>";
}
echo '<script type = "text/javascript" src = "//yandex.st/share/share.js" charset = "utf-8"></script>
<span class = "yashare-auto-init" data-yashareL10n = "ru" data-yashareType = "none" data-yashareQuickServices = "vkontakte,twitter,odnoklassniki,moimir"></span>';
}
echo "</div>";
if ($news['close'] == 1) {
echo "<div class = 'err'>";
echo "Новость закрыта для обсуждения";
echo "</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 = 'foot' name = 'form' method = 'POST' action = '?news=" . intval($_GET['news']) . "&page=$page'>";
echo text::auto_bb("form", "msg");
echo L . "<textarea aria-required = 'true' aria-invalid = 'false' required = 'required' name = 'msg'></textarea><br/>";
echo "<button class = 'btn'>";
echo "<img src = '/style/icons/tick.png' /> Опубликовать";
echo "</button></form>";
}
} else {
echo "<div class = 'foot'>";
echo 'Для того, чтобы оставить мнение - вам необходимо авторизоваться или зарегистрироваться';
echo "</div>";
}
if ($k_post == 0) {
echo "<table class = 'foot'><tr><td class = 'null'>";
echo "<img src = '/style/icons/bullet_error.png' /> Нет комментариев";
echo "</td></tr></table>";
} else {
if (isset($user)) {
echo "<div class = 'tabs_time'>";
echo "<a href = '?sort=1' class = '" . ($user['sort'] == 1 ? 'active' : null) . "'>Внизу</a>";
echo "<a href = '?sort=0' class = '" . ($user['sort'] == 0 ? 'active' : null) . "'>Вверху</a>";
echo "</div>";
}
}
while ($post = mysql_fetch_assoc($q)) {
$ank = get_user($post['id_user']);
echo "<table class = 'foot'><tr><td class = 'icon48'>";
avatar($ank['id'], '50');
echo "</td><td class = 'null'>";
user($ank['id']);
echo "<br/>";
echo "<div class = 'right' id = 'hide'>";
if (isset($user) && $news['close'] == 0 && $user['id'] != $ank['id']) {
echo "<a href = '?new_komm=$post[id]' title = 'Ответить'><img src = '/style/icons/pencil.png' /></a>";
}
if (isset($user) && $user['level'] > 2 || $user['id'] == $post['id_user'] && $post['time'] > time() - 600) {
echo "<a href = '?edit_komm=$post[id]' title = 'Редактировать пост'><img src = '/style/icons/set.png' /></a>";
}
if (user_access('adm_news_delete_comments')) {
echo "<a href = '?news=$news[id]&del=$post[id]' title = 'Удалить пост'><img src = '/style/icons/cross.png' /></a>";
}
echo "</div>";
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 "" . output_text($post['msg']) . "<br/>";
echo "<font color = '#808080'><small>" . vremja($post['time']) . "</small></font> ";
echo "</td></tr></table>";
if (isset($otvet)) {
unset($otvet);
}
}
if ($k_page > 1) {
str("?news=" . intval($_GET['news']) . '&', $k_page, $page);
}
echo "<div class = 'foot'>";
echo "<img src = '/style/icons/left.png' /> <a href = '/news/'>Вернуться</a>";
echo "</div>";
require_once '../sys/inc/tfoot.php';