Файл: profiwm.pp.ua/news.php
Строк: 204
<?php
require 'system/sid.php';
require 'system/config.php';
include 'system/user.php';
include 'system/head.php';
include 'system/navigator.php';
whorm(0, 'news');
echo $div_title . 'Новости' . $div_end;
$do = isset($_GET['do']) ? $_GET['do'] : NULL;
switch($do) {
default:
$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="news-view-'.$sql['id'].'">' . $sql['name'] . '</a>
<br/> ' . bb_code($cont) . '<br/><a href="news-view-'.$sql['id'].'">Комментарии (' . $sql['c'] . ')</a>' . $div_end;
}
echo $n->navi();
} else {
echo 'Новостей нет!<br/>';
}
break;
case view:
$i = my_int($_GET['i']);
$n = mysql_query("SELECT * FROM `news` WHERE `id` = '$i' LIMIT 1");
$inf = mysql_fetch_assoc($n);
if (!isset($_SESSION["newlook$i"])) $_SESSION[$i] = 0;
if ($_SESSION["newlook$i"] <> 1) {
$_SESSION["newlook$i"]++;
mysql_query("UPDATE `news` SET `look` = `look` + '1' WHERE `id` = '$i'");
}
//-------------------------------------------//
$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 (isset($_GET['like']))
{
$prv = mysql_query("SELECT `id` FROM `rating_news` WHERE `uid` = '$i' AND `who` = '$user[id]' LIMIT 1");
if (mysql_num_rows($prv) != FALSE) {
err('Вы уже голосовали!');
} else {
mysql_query("INSERT INTO `rating_news` SET `uid` = '$i', `who` = '$user[id]', `like` = '1'");
msg('Ваш голос принят!');
}
}
// отрицательный голос
if (isset($_GET['dlike']))
{
$prv = mysql_query("SELECT `id` FROM `rating_news` WHERE `uid` = '$i' AND `who` = '$user[id]' LIMIT 1");
if (mysql_num_rows($prv) != FALSE) {
err('Вы уже голосовали!');
} else {
mysql_query("INSERT INTO `rating_news` SET `uid` = '$i', `who` = '$user[id]', `dlike` = '1'");
msg('Ваш голос принят!');
}
}
if (mysql_num_rows($n) == FALSE) {
header('Location: news.php');
} else {
$edit = (!empty($inf['edit'])) ? $div_razdel . 'Редактировалось: ' . itime($inf['edit'], 0) . $div_end : '';
if ($user['level'] == 4 || $user['level'] == 5)
{
$_edit = '<a href="aenew-editnews-'.$inf['id'].'"><img src="ico/edit.png" alt=""/></a>
<a href="adnew-delnews-'.$inf['id'].'"><img src="ico/delete.png" alt=""/></a> ';
}
elseif ($user['level'] == 3)
{
$_edit = '<a href="menew-editnews-'.$inf['id'].'"><img src="ico/edit.png" alt=""/></a>
<a href="mdnew-delnews-'.$inf['id'].'"><img src="ico/delete.png" alt=""/></a> ';
}
$inf['content'] = smiles(bb_code($inf['content']));
echo itime($inf['date'], 0) . $block . $_edit . $inf['content'] . $edit . $block . '
Просмотров: ' . $inf['look'] . $block;
// Голосование //
$i_vote = mysql_query("SELECT `id` FROM `rating_news` WHERE `uid` = '$i' AND `who` = '$user[id]' LIMIT 1");
$like = mysql_result(mysql_query("SELECT SUM(`like`) FROM `rating_news` WHERE `uid` = '$i'"), 0);
$dlike = mysql_result(mysql_query("SELECT SUM(`dlike`) FROM `rating_news` WHERE `uid` = '$i'"), 0);
$rat_1 = (empty($like)) ? 0 : $like;
$rat_2 = (empty($dlike)) ? 0 : $dlike;
if (mysql_num_rows($i_vote) == FALSE) {
echo '<a href="wl-whovote-'.$i.'-1">' . $rat_1 . '</a>
<a href="lnewview-'.$i.'&like">
<img src="ico/plus.png" alt="+"/></a>
Голосовать
<a href="lnewview-'.$i.'&dlike">
<img src="ico/minus.png" alt="-"/></a><a href="wl-whovote-'.$i.'-2"> ' . $rat_2 . '</a>' . $block;
} else {
echo '<img src="ico/plus.png" alt="+"/><a href="wl-whovote-'.$i.'-1"> ' . $rat_1 . '</a> |
<img src="ico/minus.png" alt="-"/><a href="wl-whovote-'.$i.'-2"> ' . $rat_2 . '</a>' . $block;
}
// Голосование //
}
if (isset($_GET['order']) && $_GET['order'] == 2) {
$sort = '<b>вверху</b> | <a href="sortnew-view-'.$i.'-1">внизу</a>';
$ord = 'DESC';
} elseif (isset($_GET['order']) && $_GET['order'] == 1) {
$sort = '<a href="sortnew-view-'.$i.'-2">вверху</a> | <b>внизу</b>';
$ord = 'ASC';
} else {
$sort = '<a href="sortnew-view-'.$i.'-2">вверху</a> | <b>внизу</b>';
$ord = 'ASC';
}
echo $div_menu . 'Новые: ' . $sort . $div_end;
$coms = mysql_result(mysql_query("SELECT COUNT(id) FROM `newscomm` WHERE `id_new` = '$i'"), 0);
if ($coms > 10) {
$pg = ceil($coms / 10);
$st = '&page=' . $pg;
} else {
$st = '';
}
if (isset($_GET['d'])) {
$d = my_int($_GET['d']);
if ($user['level'] < 2) {
header('Location: news-view-' . $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: news-view-' . $i . $st);
} else {
header('Location: news-view-' . $i . $st);
}
}
if (isset($_POST['add_com'])) {
$mes = trim(mysql_real_escape_string(check($_POST['mes'])));
if (empty($mes)) {
header('Location: news-view-' . $i . $st);
} 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("/(ws|,|.|*|_|-|+)+$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="news-view-'.$i.$st.'">' . $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: news-view-' . $i . $st);
}
}
if ($coms != false) {
$n = new navigator($coms, $user['onp_comments'], 'news-view-'.$i.$st.'&');
$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="dcnew-'.$s['id'].'"><img src="ico/delete.png" alt=""/></a> ' : '';
$otv = ' <a href="answ-cnew-view-'.$i.'-'.$s['user'].$st.'#down">[отв]</a>';
echo $div_razdel . $del . us($s['user']) . $otv . ' (' . $s['date'] . ')' . $div_end . $div_tworazdel . smiles(bb_code($s['msg'])) . $div_end;
}
echo $n->navi();
} else {
echo 'Комментариев нет!<br/>';
}
$Komu = (isset($_GET['k'])) ? '[b]Ответ: ' . user_inf(my_int($_GET['k']), 'user') . '[/b], ' : '';
echo '<a name="down"></a>
<b>Комментарий:</b><br/>
<FORM method="POST" action="news-view-'.$i.$st.'">
<textarea name="mes" cols="50" rows="5" style="width: 99%;">' . $Komu . '</textarea>
<br/>
<input type="submit" name="add_com" value="Добавить"/>
</FORM>';
break;
case whovote:
$id = my_int($_GET['id']);
$v = my_int($_GET['v']);
$sql = mysql_query("SELECT id FROM news WHERE id = '$id' LIMIT 1");
if (mysql_num_rows($sql) == false)
{
err('Ошибка!');
} elseif ($v != 1 && $v != 2) {
err('Ошибка!');
} else {
$var = ($v == 1) ? '`like`' : 'dlike';
$sel = mysql_result(mysql_query("SELECT COUNT(id) FROM rating_news WHERE uid = '$id' AND $var = '1'"), 0);
if ($sel != 0)
{
$n = new navigator($sel, 10, 'wl-whovote-'.$id.'-'.$v.'&');
$res = mysql_query("SELECT * FROM rating_news WHERE uid = '$id' AND $var = '1' ORDER BY id DESC {$n->limit}");
$i = 0;
while($a = mysql_fetch_assoc($res))
{
echo ($i ++ % 2) ? $div_razdel : $div_tworazdel;
echo us($a['who']) . $div_end;
}
echo $n->navi();
} else {
echo 'За этот вариант никто не голосовал.<br/>';
}
}
echo '« <a href="news-view-'.$id.'">Назад</a>';
break;
}
include 'system/foot.php';
?>