Файл: modules/news/index.php
Строк: 192
<?php
/* DCMS S (Special)
* Версия файла 0.0.1
* Дата последнего редактирования 25.11.2015
* Модифицировал densnet
*/
require_once '../../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';
#Заголовок
title();
aut();
#Константа папки новостей
define('DIR_NEWS', "/modules/news/");
#Сокращаем пути
if (isset($_GET['edit'])) {
require_once H . DIR_NEWS . 'edit.php';
} elseif (isset($_GET['delete'])) {
require_once H . DIR_NEWS . 'delete.php';
} elseif (isset($_GET['add'])) {
require_once H . DIR_NEWS . 'add.php';
} elseif (isset($_GET['settings'])) {
require_once H . DIR_NEWS . 'settings.php';
} elseif (isset($_GET['edit_komm'])) {
require_once H . DIR_NEWS . 'edit_komm.php';
} elseif (isset($_GET['news'])) {
require_once H . DIR_NEWS . 'news.php';
} elseif (isset($_GET['new_komm'])) {
require_once H . DIR_NEWS . 'komm.php';
} elseif (isset($_GET['add'])) {
require_once H . DIR_NEWS . 'add.php';
} else {
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `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` ORDER BY `id` DESC LIMIT $start, $set[p_str]");
echo "<div class='card'>";
echo "<div class='card-header'><div class='bd-example'>";
echo "<span style='float: right;' id='hides'>";
if (IS_WEB) {
echo "<a data-toggle='modal' data-target='#news_menu' href='/?users_set'><span style='padding: 10px;' data-toggle='tooltip' data-placement='left' title='Выберите действие'><span class='fa fa-ellipsis-v fa-lg'></span></span></a>";
} else {
echo "<a data-toggle='modal' data-target='#news_menu' href='/?users_set'><span style='padding: 10px;' title='Выберите действие'><span class='fa fa-ellipsis-v fa-lg'></span></span></a>";
}
echo "</span>";
echo "</div>";
echo "Новости</div>";
?>
<div class="modal fade bd-example-modal-sm" id='news_menu' tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<?php
if (user::access('adm_news_add') && isset($user)) {
echo "<a class='list-group-item' href='?add'><span class='fa fa-plus fa-fw'></span> Новая новость</a>";
}
echo "<a class='list-group-item' href='?settings'><span class='fa fa-cog fa-fw'></span> Параметры</a>";
?>
</div>
</div>
</div>
<?php
#Выводим список новостейы
while ($post = mysql_fetch_assoc($q)) {
$like = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '$post[id]'"), 0);
$komm = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$post[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: " . DIR_NEWS . "" . 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: " . DIR_NEWS . "" . SID);
}
echo "<div class='card-block'>";
echo "<h5><a href='?news=$post[id]'>" . text::toOutput($post['title']) . "</a></h5>";
#Текст новости
echo "" . text::toOutput($post['msg']) . "<br />";
#Изображение, если есть
if ($user['set_news'] == 1) {
if (is_file(H . 'modules/news/images/' . $post['id'] . '.png')) {
echo "<img src = '/modules/news/images/$post[id].png' style = 'border: 1px solid #CCDDED; padding: 2px; border-radius: 5px; max-width: 150px;' /><br />";
}
}
echo "<small style='color: #9197a3;'>";
echo "<span class='fa fa-user'></span> $post[avtor] · <span title = '" . date::time($post['time']) . "'>" . date::times($post['time']) . "</span> ";
if (user::access('adm_news_edit') || user::access('adm_news_delete')) {
if (user::access('adm_news_edit')) {
echo "<a href='?edit=$post[id]'>· Редактировать</a> ";
}
if (user::access('adm_news_delete')) {
echo "<a href='?delete=$post[id]'>· Удалить</a>";
}
}
echo "</small>";
if (isset($user)) {
echo "<div class = 'hr'></div>";
#Просмотры
echo "<span title = 'Просмотрели " . sklon_text($post['prosm'], array('раз', 'раза', 'раз')) . "' style = 'float:right;'><span class='fa fa-eye'></span> $post[prosm]</span>";
if ($post['link'] != NULL) {
echo "<a href = '" . htmlentities($post['link'], ENT_QUOTES, 'UTF-8') . "' title = 'Перейти, чтобы узнать подробности'><span class='fa fa-share-alt'></span> Источник</a> ";
}
if ($like == 0) {
$l = null;
} else {
$l = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '$post[id]'"), 0);
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news_like` WHERE `id_news` = '$post[id]' AND `id_user` = '$user[id]' LIMIT 1"), 0) == 0) {
echo "<a href = '" . DIR_NEWS . "?id=$post[id]&like'><span class='fa fa-heart-o'></span> Нравится $l</a> ";
} else {
echo "<a href = '" . DIR_NEWS . "?id=$post[id]&unlike'><span class='fa fa-heart'></span> Нравится $l</a> ";
}
$kom = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$post[id]' AND `id_user` = '$user[id]' LIMIT 1"), 0);
if ($kom == 0) {
$komms = null;
} else {
$komms = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$post[id]' AND `id_user` = '$user[id]' LIMIT 1"), 0);
}
if ($kom == 0) {
echo "<a href = '?news=$post[id]' title = 'Комментировать'><span class='fa fa-comment-o'></span> Комментарий $komms ";
if ($post['close'] == 1) {
echo "<span class='fa fa-lock'></span>";
}
echo "</a> ";
} else {
echo "<a href = '?news=$post[id]' title = 'Комментировать'><span class='fa fa-comment'></span> Комментарий $komms ";
if ($post['close'] == 1) {
echo "<span class='fa fa-lock'></span>";
}
echo "</a> ";
}
$kum = @mysql_result(mysql_query("SELECT id_user FROM `news_like` WHERE `id_news` = '$post[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 = '/modules/news/?news=$post[id]&like_all'>" . sklon_text($kem, array('пользователю', 'пользователям', 'пользователям')) . "</a> это нравится";
}
} else {
$vam = "<a href = '/modules/news/?news=$post[id]&like_all'>" . sklon_text($like, array('пользователю', 'пользователям', 'пользователям')) . "</a> это нравится";
}
if ($like == 1) {
echo "<div class = 'hr'></div>";
echo "<font color = '#B2B2B2'><span class='fa fa-heart'></span> $vam</font>";
} elseif ($like >= 2) {
echo "<div class = 'hr'></div>";
echo "<font color = '#B2B2B2'><span class='fa fa-heart'></span> $vam</font>";
}
}
if ($user['set_news_comments'] == 1) {
echo "<br />";
$k_posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '$post[id]'"), 0);
$k_pages = k_page($k_posts, $set['p_str']);
$pages = page($k_pages);
$starts = $set['p_str'] * $pages - $set['p_str'];
if (IS_WEB) {
$qs = mysql_query("SELECT * FROM `news_komm` WHERE `id_news` = '$post[id]' ORDER BY `id` DESC LIMIT 5");
} else {
$qs = mysql_query("SELECT * FROM `news_komm` WHERE `id_news` = '$post[id]' ORDER BY `id` DESC LIMIT 3");
}
if ($k_posts == 0) {
echo "<span style = 'color: #9197a3;'><span class='fa fa-comments'></span> Еще не обсуждали...</span>";
}
while ($posts = mysql_fetch_assoc($qs)) {
$anks = user::get_user($posts['id_user']);
echo "<ul class='media-list media-list-conversation'>";
echo "<li class='media'>";
echo "<a class='media-left' href='/info.php?id=$anks[id]'>";
avatars($anks['id'], '30');
echo "</a>";
echo "<div class='media-body'><div class='media-body-text'>";
echo "<b>" . user($anks['id']) . "</b> ";
echo text::toOutput($posts['msg']);
echo "</div><div class='media-footer'>";
echo "<small class='text-muted'>";
echo "<span data-toggle='tooltip' data-placement='right' title='" . date::time($posts['time']) . "' style='color:grey;'>" . date::times($posts['time']) . "</span> ";
echo "</small>";
echo "</div></div>";
echo "</li>";
echo "</ul>";
}
}
echo "</div>";
}
#Если нет новостей
if ($k_post == 0) {
echo "<div class = 'alert alert-info'>";
echo "<span class='fa fa-info-circle'></span> Нет результатов";
echo "</div>";
}
if ($k_page > 1) {
str('index.php?', $k_page, $page);
}
echo "</div>";
}
require_once H . 'sys/inc/tfoot.php';