Файл: news/news.php
Строк: 376
<?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 "<div class = 'razd'>";
echo "<img src = '/style/img/error.png' /> Нет результатов";
echo "</div>";
}
while ($post = mysql_fetch_assoc($q)) {
$ank = get_user($post['id_user']);
echo "<div class = 'razd'>";
avatar($ank['id'], '30');
user($ank['id']);
echo "</div>";
}
if ($k_page > 1) {
echo $k_sisa;
}
echo "<div class = 'razd'>";
echo "<span class = 'icon icon63' /> <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['likess']) && 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/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['unlikess']) && isset($user)) {
mysql_query("DELETE FROM `news_like` WHERE `id_user` = '$user[id]' AND `id_news` = '" . intval($_GET['news']) . "' LIMIT 1");
header("Location: /news/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']);
$not_set = mysql_fetch_array(mysql_query("SELECT * FROM `notification_set` WHERE `id_user` = '" . $a['id'] . "' LIMIT 1"));
if ($f['lenta_news'] == 1 && $tape_set['lenta_news'] == 1) {
$not_msg = "$SexKomm новость [url=/news/?news=$news[id]&page=$pageEnd]" . htmlspecialchars($news['title']) . "[/url]";
mysql_query("INSERT INTO `notification` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$a[id]', '$not_msg', '$time')");
}
}
$event = "$user[nick] $SexKomm новость [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 = 'razd'>";
echo "<img src = '/style/img/feed.png' /> " . htmlspecialchars($news['title']) . "<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/>";
}
echo text::toOutput($news['msg']);
echo "</div><div class = 'razd'>";
if (isset($user)) {
$like = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '$news[id]'"), 0);
echo "<span class = 'tiptip'>";
echo "<a class = 'button left' title = 'Автор новости'><span class = 'icon icon191' /><span class = 'label'>Автор $news[avtor]</span></a>";
echo "<a class = 'button right' title = 'Время создания новости'><span class = 'label'>" . vremja($news['time']) . "</span></a><br />";
if (user_access('adm_news_edit') && user_access('adm_news_delete')) {
echo "<div class = 'dropdown'>";
echo "<a href = '#' class = 'button'><span class = 'icon icon96' /><span class = 'label'>Опции</span><span class = 'toggle'></span></a>";
echo "<div class = 'dropdown-slider'>";
if (user_access('adm_news_edit')) {
echo "<a href = '?edit=$news[id]' class = 'ddm'><span class = 'icon icon145' /><span class = 'label'>Изменить</span></a>";
}
if (user_access('adm_news_delete')) {
echo "<a href = '?delete=$news[id]' class = 'ddm negative'><span class = 'icon icon58' /><span class = 'label'>Удалить</span></a>";
}
echo "</div></div>";
}
if ($news['link'] != NULL) {
echo "<a href = '" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "' class = 'button left' title = 'Перейти, чтобы узнать подробности'><span class = 'icon icon119' /><span class = 'label'>Ссылка</span></a>";
}
if ($news['link'] != NULL) {
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' class = 'button middle' title = 'Мне нравится'><span class = 'icon icon101' /></a>";
} else {
echo "<a href = '?news=$news[id]&unlike' class = 'button middle on' title = 'Не нравится'><span class = 'icon icon100' /></a>";
}
}else{
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' class = 'button left' title = 'Мне нравится'><span class = 'icon icon101' /></a>";
} else {
echo "<a href = '?news=$news[id]&unlike' class = 'button left on' title = 'Не нравится'><span class = 'icon icon100' /></a>";
}
}
echo "<a href = '?news=$news[id]&like_all' class = 'button right' title = 'Список тех, кому понравилась новость'><span class = 'label'>$like</span></a>";
echo "</span>";
$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 = 'errs'>";
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 = 'razd' 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 = 'action' name = 'ok'>";
echo "<span class = 'label'><span class = 'icon icon57' /> Опубликовать</span>";
echo "</button></form>";
}
} else {
echo "<div class = 'razd'>";
echo 'Для того, чтобы комментировать - Вам необходимо авторизоваться или зарегистрироваться';
echo "</div>";
}
if ($k_post == 0) {
echo "<div class = 'errs'>";
echo img('error.png') . " Файл не найден!";
echo "</div>";
} else {
if (isset($user)) {
echo "<div class = 'tabs t_bar clear_fix'>";
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 = 'razd'><tr><td class = 'icon48'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
if (isset($user)) {
echo "<span style = 'float: right;' id = 'hide'>";
if (isset($user) && $news['close'] == 0 && $user['id'] != $ank['id']) {
echo "<a href = '?new_komm=$post[id]' title = 'Ответить'><img src = '/style/img/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/img/wrench.png' /></a>";
}
if (user_access('adm_news_delete_comments')) {
echo "<a href = '?news=$news[id]&del=$post[id]' title = 'Удалить'><img src = '/style/img/delete.png' /></a>";
}
echo "</span>";
}
user($ank['id']);
echo " <font color = '#808080'><small>(" . vremja($post['time']) . ")</small></font> ";
echo "<br/>";
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 "</td></tr></table>";
if (isset($otvet)) {
unset($otvet);
}
}
if ($k_page > 1) {
str("?news=" . intval($_GET['news']) . '&', $k_page, $page);
}
echo "<div class = 'razd'>";
echo "<span class = 'icon icon63' /> <a href = '/news/'>Вернуться</a>";
echo "</div>";
require_once '../sys/inc/tfoot.php';