Файл: WM-Koder/news/index.php
Строк: 149
<?php
require '../system/sid.php';
require '../system/config.php';
include '../system/user.php';
include '../system/head.php';
include '../system/navigator.php';
whorm(0, 'news');
$do = isset($_GET['do']) ? $_GET['do'] : NULL;
switch($do) {
default:
echo $div_title . 'Новости' . $div_end;
echo '<div class="menu">';
$look = mysql_result(mysql_query("SELECT COUNT(id) FROM `news`"), 0);
if ($look != false) {
$n = new navigator($look, 10, '?');
$result = mysql_query("SELECT `news`.*,(SELECT COUNT(id) FROM `newscomm` WHERE `newscomm`.`id_new`=`news`.`id`) AS c FROM `news` ORDER BY `news`.`id` DESC {$n->limit}");
$i = 0;
while($sql = mysql_fetch_assoc($result)) {
$cont = (mb_strlen($sql['content'], 'UTF8') > 100)
? mb_substr($sql['content'], 0, 100, 'UTF8') . '...'
: $sql['content'];
echo ($i ++ % 2) ? $div_tworazdel : $div_razdel;
echo '<a href="?do=view&i='.$sql['id'].'"><b>' . $sql['name'] . '</b></a>
<br/> ' . bb_code($cont) . '<br/><div class="auth2"><a href="?do=view&i='.$sql['id'].'">Комментарии (' . $sql['c'] . ')</a></div>' . $div_end;
}
echo $n->navi();
} else {
echo ' <div class="menu"> Новостей нет!</div>';
}
break;
case view:
$i = my_int($_GET['i']);
$n = mysql_query("SELECT * FROM `news` WHERE `id` = '$i' LIMIT 1");
$inf = mysql_fetch_assoc($n);
echo $div_title . '<b>' . $inf['name'] . '</b> (' . date('d-m-Y H:i', $inf['date']) . ')' . $div_end;
echo '<div class="menu">';
$sqlLenta = mysql_query("SELECT id FROM lenta WHERE user = '$user[id]' AND `read` = '1' AND type = 'comments' AND uid = 'new$i' LIMIT 1");
if (mysql_num_rows($sqlLenta) != false)
{
mysql_query("UPDATE lenta SET `read` = '0' WHERE user = '$user[id]' AND `read` = '1' AND type = 'comments' AND uid = 'new$i' LIMIT 1");
}
if (mysql_num_rows($n) == FALSE) {
header('Location: ?');
} else {
if ($user['level'] == 4 || $user['level'] == 5)
{
$_edit = '<a href="http://digmas.tk/admin.php?do=editnews&i='.$inf['id'].'">[изменить]</a>
<a href="http://digmas.tk/admin.php?do=delnews&i='.$inf['id'].'">[удалить]</a> ';
}
elseif ($user['level'] == 3)
{
$_edit = '<a href="http://digmas.tk/moder.php?do=editnews&i='.$inf['id'].'">[изменить]</a>
<a href="http://digmas.tk/moder.php?do=delnews&i='.$inf['id'].'">[удалить]</a> ';
}
$inf['content'] = smiles(bb_code($inf['content']));
echo ''.$_edit.'<br>'.$inf['content'].''.$block.'</div>';
}
if (isset($_GET['d'])) {
$d = my_int($_GET['d']);
if ($user['level'] < 2) {
header('Location: ?do=view&i='.$i.'');
die();
}
$ecom = mysql_query("SELECT `id` FROM `newscomm` WHERE `id` = '$d' LIMIT 1");
if (mysql_num_rows($ecom) != FALSE) {
mysql_query("DELETE FROM `newscomm` WHERE `id` = '$d' LIMIT 1");
header('Location: ?do=view&i='.$i.'');
} else {
header('Location: ?do=view&i='.$i.'');
}
}
if (isset($_POST['add_com'])) {
$mes = trim(mysql_real_escape_string(check($_POST['mes'])));
if (empty($mes)) {
header('Location: ?do=view&i='.$i.'');
} else {
// транслит
if ($user['translit'] == 1) {
$mes = trun_to_rus($mes);
}
// антимат
$ant = mysql_fetch_array(mysql_query("SELECT `antimat` FROM `setting` WHERE `ids` = '1'"));
$mes = ($ant[0] == 1) ? mat($mes) : $mes;
// Антиреклама
$_ant = mysql_fetch_assoc(mysql_query("SELECT `on_rekl`, `text_rekl` FROM `setting` WHERE `ids` = '1'"));
if ($_ant['on_rekl'] == 1 && filesize($_SERVER['DOCUMENT_ROOT'] . '/domains.dat') > 0) {
$ex = explode(',', file_get_contents('domains.dat'));
foreach($ex as $value) {
if ($user['level'] != 4 && $user['level'] != 5 && !preg_match('/[url=http://(.*)[/url]/si', $mes)) {
$mes = preg_replace("/(w)(s|,|.|*|_|-|+)+$value/si", $_ant['text_rekl'], $mes);
}
}
}
// Оповещание последнему постеру
$lst = mysql_fetch_assoc(mysql_query("SELECT `user` FROM `newscomm` WHERE
`id_new` = '$i'
ORDER BY `id` DESC LIMIT 1"));
if ($user['id'] != $lst['user']) {
$NameNew = mysql_fetch_array(mysql_query("SELECT `name` FROM `news` WHERE `id` = '$i' LIMIT 1"));
$message = 'Оставлено сообщение к новости <a href="?do=view&i='.$i.'">' . $NameNew[0] . '</a>.';
mysql_query("INSERT INTO `lenta` SET
`user` = '$lst[user]',
`text` = '$message',
`type` = 'comments',
`date` = '" . time() . "',
`uid` = 'new$i',
`read` = '1'");
}
mysql_query("INSERT INTO `newscomm` SET
`date` = '" . date('d.m.y H:i') . "',
`msg` = '$mes',
`id_new` = '$i',
`user` = '$user[id]'");
header('Location: ?do=view&i='.$i.'');
}
}
$coms = mysql_result(mysql_query("SELECT COUNT(id) FROM `newscomm` WHERE `id_new` = '$i'"), 0);
if ($coms != false) {
$n = new navigator($coms, $user['onp_comments'], '?do=view&i='.$i.'&');
$res = mysql_query("SELECT * FROM `newscomm` WHERE `id_new` = '$i' ORDER BY `id` $ord {$n->limit}");
while($s = mysql_fetch_assoc($res)) {
$del = ($user['level'] >= 2 && $user['level'] <= 5) ? '<a href="?do=view&d='.$s['id'].'">уд</a>' : '';
if (user_inf($s['user'], 'onl') + 300 > time())
{
$online = ' <img src="/views/default/img/on.png" alt="on">';
}
else
{
$online = ' <img src="/views/default/img/off.png" alt="off">';
}
$otv = '<a href="?do=view&i='.$i.'&k='.$s['user'].'&#down">отв</a>';
echo '<div class="menu">';
echo '<table><tr><td>'.uus($s['user']).'</td><td><div class="auth2">'.us($s['user']).''.$online.'</div>('.$s['date'].')</td></tr></table><div class="auth2">'.$del.''.$otv.'</div>'.smiles(bb_code($s['msg'])).'<br><br>';
echo '</td></tr></table></div><div class="menu">';
}
echo $n->navi();
} else {
echo '';
echo '<div class="menu">';
}
if (isset($_SESSION['us']))
{
$Komu = (isset($_GET['k'])) ? '[b]Ответ: ' . user_inf(my_int($_GET['k']), 'user') . '[/b], ' : '';
echo '<a name="down"></a>
<b>Комментарий:</b><br/>';
echo '<FORM method="POST" action="?do=view&i='.$i.'">
<textarea name="mes" id="Site" rows="5" cols="20" class="input">' . $Komu . '</textarea>'.quickcode().'
<br/>
<input type="submit" name="add_com" value="Добавить"/>
</FORM>';
}
break;
}
echo '</div>';
include '../system/foot.php';
?>