Файл: sys/inc/news_main.php
Строк: 120
<?php
$q = mysql_query("SELECT * FROM `news` WHERE `main_time` > '" . TIME . "' ORDER BY `id` DESC LIMIT 1");
if (mysql_num_rows($q) == 1) {
$news = mysql_fetch_assoc($q);
$hide = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_hide` WHERE `nid` = '$news[id]' AND uid = '{$user['id']}'"), 0);
$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` = '$news[id]'"), 0);
$kom = @mysql_result(mysql_query("SELECT nick FROM `user` WHERE `id` = '$kum' LIMIT 1"), 0);
$kem = $like - 1;
$komm = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$news[id]'"), 0);
#Лайк
if (isset($_GET['like']) && isset($user)) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '" . intval($_GET['id']) . "' 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['id']) . "')");
}
header("Location: /" . SID);
}
if (isset($_GET['unlike']) && isset($user)) {
mysql_query("DELETE FROM `news_like` WHERE `id_user` = '$user[id]' AND `id_news` = '" . intval($_GET['id']) . "' LIMIT 1");
header("Location: /" . SID);
}
#Сворачиваем новость
if (isset($_GET['hide']) && isset($user)) {
#Только для зарегистрированных
user::only_reg();
if (!isset($_GET['id']) && !is_numeric($_GET['id'])) {
header("Location: /index.php?" . SID);
exit;
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news` WHERE `id` = '" . intval($_GET['id']) . "' 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['id']) . "' 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['id']) . "','$user[id]')");
header("Location: /index.php?" . SID);
exit;
}
if ($hide == 0) {
echo "<div class = 'razd'>";
echo img('feeds.png') . " <a href = '/modules/news/?news=$news[id]'><font size = '3'><b>$news[title]</b></font></a>";
echo "<br />";
echo "<font size = '3'><i>" . text::toOutput($news['msg']) . "</i></font><br />";
if (isset($user)) {
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 ($news['close'] == 1) {
echo "<a class = 'add' href = '/modules/news/?news=$news[id]' title = 'Комментировать. Запрещено'>" . img('comment_white_mini.png') . " <small>$komm " . img('lock-small.png') . "</small></a> ";
} else {
echo "<a class = 'add' href = '/modules/news/?news=$news[id]' title = 'Комментировать'>" . img('comment_white_mini.png') . " <small>$komm</small></a> ";
}
if (isset($user)) {
echo "<a class = 'add' href = '/modules/news/?news=$news[id]&like_all' title = 'Список тех, кому понравилась новость'>" . img('like_mini.png') . " <small>$like</small></a> ";
} else {
echo img('like_mini.png') . " <small>$like</small></a> ";
}
} else {
$komm = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$news[id]'"), 0);
echo "<a class = 'count' href = '/modules/news/?news=$news[id]' title = 'Комментарии'>" . img('comment_white.png') . " $komm</a>";
}
echo "</div><div class = 'razd'>";
if ($news['link'] != NULL) {
echo "<a class = 'add' href = '" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "' title = 'Перейти, чтобы узнать подробности'>" . img('url.png') . " Ссылка</a> ";
}
if (isset($user)) {
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 class = 'add' href = '?id=$news[id]&like'>" . img('like.png') . " Нравится</a> ";
} else {
echo "<a class = 'addi' href = '?id=$news[id]&unlike'>Не нравится</a> ";
}
echo "<a class = 'add' href = '?id=$news[id]&hide'>Свернуть</a>";
}
if (isset($user)) {
$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) {
$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 = '/modules/news/?news=$news[id]&like_all'> ещё $kem пользователю.</a>";
} elseif ($like >= 3) {
echo "<br /><br />";
echo "Это понравилось $vam и <a href = '/modules/news/?news=$news[id]&like_all'> ещё $kem пользователям.</a>";
}
}
echo "</div>";
}
}