Файл: news/news.php
Строк: 350
<?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 = 'razd'><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 = 'razd'><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 = '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['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 = 'razd'>";
echo "<img src = '/style/icons/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 output_text($news['msg']) . "<br />";
echo "<font color = 'green'><small>Опубликовано " . vremja($news['time']) . "</small></font> · ";
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'>";
if ($news['link'] != NULL) {
echo "<a href = '" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "' class = 'button left' title = 'Подробности'><span class = 'icon icon119' /></a>";
}
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 on' title = 'Мне нравится'><span class = 'icon icon101' /><b>$like</b></a>";
} else {
echo "<a href = '/news/?news=$news[id]&unlike' class = 'button on' title = 'Не нравится'><span class = 'icon icon100' /><b>$like</b></a>";
}
echo "</span>";
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>";
}
$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;
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>';
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 "</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 = '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 "<table class = 'razd'><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 = 'razd'><tr><td class = 'icon48'>";
avatar($ank['id'], '50');
echo "</td><td class = 'null'>";
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 output_text($post['msg']);
if (isset($user)) {
echo "<br/><div class = 'dropdown'>";
echo "<a href = '#' class = 'button'><span class = 'icon icon96'></span><span class = 'label'>Опции</span><span class = 'toggle'></span></a>";
echo "<div class = 'dropdown-slider'>";
if (isset($user) && $news['close'] == 0 && $user['id'] != $ank['id']) {
echo "<a href = '?new_komm=$post[id]' class = 'ddm'><span class = 'icon icon145'></span><span class = 'label'>Ответить</span></a>";
}
if (isset($user) && $user['level'] > 2 || $user['id'] == $post['id_user'] && $post['time'] > time() - 600) {
echo "<a href = '?edit_komm=$post[id]' class = 'ddm negative'><span class = 'icon icon98'></span><span class = 'label'>Изменить</span></a>";
}
if (user_access('adm_news_delete_comments')) {
echo "<a href = '?news=$news[id]&del=$post[id]' class = 'ddm negative'><span class = 'icon icon58'></span><span class = 'label'>Удалить</span></a>";
}
echo "</div></div>";
}
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';