Файл: modules/news/news.php
Строк: 270
<?php
/* Мод "Новости"
* Версия v0.0.1
* Дата последнего редактирования 27.11.2014
* Двиг DCMS Special
* Модифицировал densnet
* Файл news.php
* Описание: показывает ность и комментарии к ней
*/
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 = 'errs'>";
echo img('error.png') . " Нет результатов";
echo "</div>";
}
while ($post = mysql_fetch_assoc($q)) {
$ank = user::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'>" . img('left.png') . " <a href = '" . DIR_NEWS . "'>Новости</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]&page=$pageEnd]" . htmlspecialchars($news['title']) . "[/url]";
mysql_query("INSERT INTO `notifications` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$a[id]', '$not_msg', '$time')");
}
}
$event = "$user[nick] $SexKomm новость [url=/modules/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']) . "'");
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 = 'navigation'><a href = '/index.php'>Главная</a> > <a href = '" . DIR_NEWS . "'>Новости</a> > <b>" . htmlspecialchars($news['title']) . "</b></div>";
echo "<div style = 'font-size: 18px;font-weight: bold;text-shadow: 0px 2px 2px #ffffff;color: #CCCCCC;' class = 'razd'>";
if (user::access('adm_news_edit') || user::access('adm_news_delete')) {
echo "<span style = 'float:right;' id = 'hide'>";
if (user::access('adm_news_edit')) {
echo "<a href = '?edit=$news[id]' class = 'add'>" . img('set_mini.png') . "</a> ";
}
if (user::access('adm_news_delete')) {
echo "<a href = '?delete=$news[id] ' class = 'add'>" . img('del.png') . "</a>";
}
echo "</span>";
}
echo img('rss.png') . " " . htmlspecialchars($news['title']);
echo "</div>";
echo "<div class = 'razd'>";
#Изображения
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 "<i>" . text::toOutput($news['msg']) . "</i><br /><br />";
#Автор и время
echo img('user_mini.png') . " <small>$news[avtor] · " . date::time($news['time']) . "</small><br /><br />";
#Просмотры
echo "<a class = 'add'>" . img('eye_mini.png') . " <small>$news[prosm]</small></a> ";
#Список лайкнувших
if (isset($user)) {
echo "<a href = '?news=$news[id]&like_all' class = 'add' title = 'Список тех, кому понравилась новость'>" . img('like_mini.png') . " <small>$like</small></a> ";
} else {
echo "<a class = 'add'>" . img('like_mini.png') . " <small>$like</small></a> ";
}
#Ссылка
if ($news['link'] != NULL) {
echo "<a href = '" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "' class = 'add' title = 'Перейти, чтобы узнать подробности'>" . img('url.png') . " Ссылка</a> ";
}
if (isset($user)) {
echo "<br /><br />";
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 = '" . DIR_NEWS . "?news=$news[id]&like' class = 'add' title = 'Мне нравится'>" . img('like.png') . " Нравится</a> ";
} else {
echo "<a href = '" . DIR_NEWS . "?news=$news[id]&unlike' class = 'addi' title = 'Не нравится'>Не нравится</a> ";
}
$like = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '$news[id]'"), 0);
$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 ($user['id'] == $kum) {
$vam = "Вам";
} else {
$vam = "<a href='/info.php?id=$kum'>$kom</a>";
}
if ($like == 1) {
echo "<br /><br />";
echo "$vam это нравится";
} elseif ($like == 2) {
echo "<br /><br />";
echo "Это понравилось $vam и <a href = '" . DIR_NEWS . "?news=$news[id]&like_all'> ещё $kem пользователю.</a>";
} elseif ($like >= 3) {
echo "<br /><br />";
echo "Это понравилось $vam и <a href = '" . DIR_NEWS . "?news=$news[id]&like_all'> ещё $kem пользователям.</a>";
}
}
echo "<br />";
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]");
$komm = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$news[id]'"), 0);
echo "<div class = 'razdel'>" . img('komm.png') . " <b>Комментарии $komm</b></div>";
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 = 'clik' name = 'ok'>" . img('pens.png') . " Опубликовать</button>";
echo "</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 = user::get_user($post['id_user']);
echo "<table class = 'razd'><tr><td class = 'icon14'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
echo "<span style = 'float:right;'><small>" . date::time($post['time']) . "</small></span>";
user($ank['id']);
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($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('pen.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('set_mini.png') . "</a> ";
}
if (user::access('adm_news_delete_comments')) {
echo "<a href = '?news=$news[id]&del=$post[id]' title = 'Удалить'>" . img('del.png') . "</a>";
}
echo "</span>";
}
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'>" . img('left.png') . " <a href = '" . DIR_NEWS . "'>Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';