Файл: modules/news/news.php
Строк: 273
<?php
/* DCMS Special
* Дата последнего редактирования 11.12.2015
* Модифицировал densnet
*/
foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
require_once "../../sys/inc/{$inc}.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='list-group-item'>";
echo "<i class='fa fa-info-circle fa-fa'></i> Нет результатов";
echo "</div>";
}
while ($post = mysql_fetch_assoc($q)) {
$ank = 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 fa-fw'></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 = 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 && $not_set['lenta_news'] == 1) {
$not_msg = "$SexKomm новость [url=" . DIR_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 "<ol class='breadcrumb'>";
echo "<li><a href='/'><span class='fa fa-home fa-fw'></span></a></li>";
echo "<li><a href='" . DIR_NEWS . "'>Новости</a></li>";
echo "<li class='active'>$news[title]</li>";
echo "</ol>";
echo "<div class='list-group-item'>";
echo "<h4><a href='?news=$news[id]'>" . 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 (access('adm_news_edit') || access('adm_news_delete')) {
if (access('adm_news_edit')) {
echo "<a href='?edit=$news[id]'>· Редактировать</a> ";
}
if (access('adm_news_delete')) {
echo "<a href='?delete=$news[id]'>· Удалить</a>";
}
}
echo "</small>";
echo "<div class='hr'></div>";
#Текст новости
echo "" . toOutput($news['msg']) . "<br />";
#Изображение, если есть
if ($user['set_news'] == 1) {
if (is_file(H . 'modules/news/images/' . $news['id'] . '.png')) {
echo "<br /><img src='" . DIR_NEWS . "images/$news[id].png' style='border: 1px solid #CCDDED; padding: 2px; border-radius: 5px; max-width: 200px;' />";
}
}
if (isset($user)) {
echo "<div class='hr'></div>";
#Просмотры
echo "<span title='Просмотрели " . sklon_text($news['prosm'], array('раз', 'раза', 'раз')) . "' style='float:right;'><span class='fa fa-eye fa-fw'></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 fa-fw'></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 fa-fw'></span> Нравится $l</a> ";
} else {
echo "<a href='?news=$news[id]&unlike'><span class='fa fa-heart fa-fw'></span> Нравится $l</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='" . DIR_NEWS . "?news=$news[id]&like_all'>" . sklon_text($kem, array('пользователю', 'пользователям', 'пользователям')) . "</a> это нравится";
}
} else {
$vam = "<a href='" . DIR_NEWS . "?news=$news[id]&like_all'>" . sklon_text($like, array('пользователю', 'пользователям', 'пользователям')) . "</a> это нравится";
}
if ($like == 1) {
echo "<div class='hr'></div>";
echo "<font color='#B2B2B2'><i class='fa fa-heart fa-fw'></i> $vam</font>";
} elseif ($like >= 2) {
echo "<div class='hr'></div>";
echo "<font color='#B2B2B2'><i class='fa fa-heart fa-fw'></i> $vam</font>";
}
}
echo "</div>";
if ($news['close'] == 1) {
echo "<div class='alert alert-info'>";
echo "<i class='fa fa-lock fa-fw'></i> Новость закрыта для обсуждения";
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='list-group-item' name='form' method='POST' action='?news=" . intval($_GET['news']) . "&page=$page'>";
echo "Сообщение<br />";
echo "<textarea name='msg' class='form-control' rows='2'></textarea><br/>";
echo "<button class='btn btn-success' name='ok'><span class='fa fa-share-square-o fa-fw'></span> Опубликовать</button>";
echo "</form>";
}
} else {
echo "<div class='list-group-item'>";
echo 'Для того, чтобы комментировать - Вам необходимо авторизоваться или зарегистрироваться';
echo "</div>";
}
if ($k_post == 0) {
echo "<div class='list-group-item'>";
echo "<span class='fa fa-info-circle fa-fw'></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='list-group-item'>";
echo "<ul class='nav nav-tabs' style='margin-bottom: -8px;'>";
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 = get_user($post['id_user']);
echo "<ul class='media-list media-list-conversation list-group-item' 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 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 fa-fw'></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 fa-fw'></span></a> ";
}
if (access('adm_news_delete_comments')) {
echo "<a href='?news=$news[id]&del=$post[id]' title='Удалить'><span class='fa fa-trash-o fa-fw'></span></a>";
}
echo "</span>";
}
echo "</small>";
echo "</div></div>";
echo "</li>";
if (isset($otvet)) {
unset($otvet);
}
echo "</ul>";
}
if ($k_page > 1) {
echo "<div class='list-group-item'>";
str("?news=" . intval($_GET['news']) . '&', $k_page, $page);
echo "</div>";
}
require_once H . 'sys/inc/tfoot.php';