Файл: sys/inc/news_main.php
Строк: 123
<?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 = 'blok_text'>";
if (isset($user)) {
echo "<span style = 'float:right;' id = 'hide'>";
echo "<a href = '?id=$news[id]&hide' title = 'Свернуть'>" . img24('cancel.png') . "</a>";
echo "</span>";
}
echo img24('news.png') . " <a href = '/modules/news/?news=$news[id]'>$news[title]</a>";
echo "</div><div class = 'blok_news'>";
echo "<font color = '#FFFFFF'><i>" . text::toOutput($news['msg']) . "</i></font><br /><br />";
echo img16('001.png') . " <small>$news[avtor] · " . date::time($news['time']) . "</small><br /><br />";
if (isset($user)) {
echo "<a class = 'add'>" . img16('eye.png') . " $news[prosm]</a> ";
if ($news['close'] == 1) {
echo "<a href = '/modules/news/?news=$news[id]' class = 'add' title = 'Комментировать. Запрещено'>" . img16('komm.png') . " <small>$komm " . img16('lock.png') . "</small></a> ";
} else {
echo "<a href = '/modules/news/?news=$news[id]' class = 'add' title = 'Комментировать'>" . img16('komm.png') . " <small>$komm</small></a> ";
}
if (isset($user)) {
echo "<a href = '/modules/news/?news=$news[id]&like_all' class = 'add' title = 'Список тех, кому понравилась новость'>" . img16('like.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 = 'add' href = '/modules/news/?news=$news[id]' title = 'Комментарии'>" . img16('komm.png') . " $komm</a> ";
if ($news['link'] != NULL) {
echo "<a class = 'add' href = '" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "' title = 'Перейти, чтобы узнать подробности'>" . img16('link.png') . " Ссылка</a>";
}
}
if (isset($user)) {
echo "<br /><br />";
if ($news['link'] != NULL) {
echo "<a class = 'add' href = '" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "' title = 'Перейти, чтобы узнать подробности'>" . img16('link.png') . " Ссылка</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 class = 'add' href = '?id=$news[id]&like'>" . img16('like.png') . " Нравится</a> ";
} else {
echo "<a class = 'addi' href = '?id=$news[id]&unlike'>Не нравится</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>";
}
}