Файл: profiwm.pp.ua/gazeta.php
Строк: 365
<?php
require 'system/sid.php';
require 'system/config.php';
include 'system/user.php';
include 'system/head.php';
include 'system/navigator.php';
whorm(0, 'gazeta');
echo $div_title . 'Газета' . $div_end;
$do = isset($_GET['do']) ? $_GET['do'] : NULL;
switch($do)
{
default:
if ($user['journalist'] == 1) echo $div_menu . '<a href="gazeta.php?do=create">Добавить статью</a>' . $div_end;
if ($user['journalist'] == 1 || $user['level'] == 4 && $user['level'] == 5) {
echo $div_menu . '<a href="gazeta.php?do=gazeta_r">Управление разделами</a>' . $div_end;
}
$look = mysql_result(mysql_query("SELECT COUNT(id) FROM `gazeta_razdel`"), 0);
if ($look != false) {
$n = new navigator($look, 10, '?');
$result = mysql_query("SELECT `gazeta_razdel`.*,
(SELECT COUNT(id) FROM `gazeta_article` WHERE `gazeta_razdel`.`id` = `gazeta_article`.`uid`) AS c,
(SELECT COUNT(id) FROM `gazeta_article` WHERE `gazeta_razdel`.`id` = `gazeta_article`.`uid`
AND `gazeta_article`.`date` > '" . (time() - 86400) . "') AS a FROM `gazeta_razdel` ORDER BY `gazeta_razdel`.`id` ASC {$n->limit}");
$i = 0;
while($sql = mysql_fetch_assoc($result)) {
$new_file = (!empty($sql['a'])) ? '<span style="color: #FF0000;">+' . $sql['a'] . '</span>' : '';
echo ($i ++ % 2) ? $div_tworazdel : $div_razdel;
echo '» <a href="gcat-razdel-'.$sql['id'].'">'.$sql['name'].'</a> (' . $sql['c'] . ')' . $new_file . $div_end;
}
echo $n->navi();
} else {
echo 'Разделы еще не созданы.<br/>';
}
break;
// Управление (журналистам)
case gazeta_r:
if ($user['journalist'] != 1 && $user['level'] < 4) {
header('Location: gazeta.php');
die();
}
echo '<form method="post" action="gazeta.php?do=gazeta_r">
<label for="q">Новый раздел</label>:
<br/>
<input type="text" id="q" name="new"/>
<br/>
<input type="submit" name="create" value="Создать"/>
</form>' . $block;
// создание раздела
if (isset($_POST['create'])) {
$new = trim(mysql_real_escape_string(check($_POST['new'])));
$em = mysql_query("SELECT `id` FROM `gazeta_razdel` WHERE `name` = '$new' LIMIT 1");
if (empty($new)) {
err('Пустое название раздела!');
} elseif (mysql_num_rows($em) != FALSE) {
err('Раздел с таким названием уже создан!');
} else {
mysql_query("INSERT INTO `gazeta_razdel` SET `name` = '$new'");
header('Location: gazeta.php?do=gazeta_r');
}
}
// удаление раздела
if (isset($_GET['x'])) {
$x = my_int($_GET['x']);
$sql = mysql_query("SELECT `id` FROM `gazeta_razdel` WHERE `id` = '$x' LIMIT 1");
if (mysql_num_rows($sql) == FALSE) {
err('Раздел не найден!');
} else {
$in = mysql_fetch_assoc(mysql_query("SELECT `path` FROM `gazeta_article` WHERE `uid` = '$x' LIMIT 1"));
// удаление вложеных файлов
if (file_exists($in['path'])) unlink($in['path']);
// удаление статей
mysql_query("DELETE FROM `gazeta_article` WHERE `uid` = '$x'");
// удаление раздела
mysql_query("DELETE FROM `gazeta_razdel` WHERE `id` = '$x' LIMIT 1");
header('Location: gazeta.php?do=gazeta_r');
}
}
// вывод разделов
$count = mysql_result(mysql_query("SELECT COUNT(id) FROM `gazeta_razdel`"), 0);
if ($count != FALSE) {
$n = new navigator($count, 10, '?do=gazeta_r');
$view = mysql_query("SELECT `gazeta_razdel`.*,(SELECT COUNT(id) FROM `gazeta_article` WHERE `gazeta_razdel`.`id` = `gazeta_article`.`uid`) AS c FROM `gazeta_razdel` ORDER BY `gazeta_razdel`.`id` DESC {$n->limit}");
$i = 0;
while($a = mysql_fetch_assoc($view)) {
$d = '<a href="gdelete-gazeta_r-'.$a['id'].'"><img src="ico/delete.png" alt=""/></a> ';
$e = '<a href="gedit-gazeta_edit-'.$a['id'].'"><img src="ico/edit.png" alt=""/></a> ';
echo ($i ++ % 2) ? $div_tworazdel : $div_razdel;
echo $e . $d . $a['name'] . ' (' . $a['c'] . ')' . $div_end;
}
echo $n->navi();
} else {
echo 'Разделы не созданы.<br/>';
}
break;
// Редактирование раздела газеты
case gazeta_edit:
if ($user['journalist'] != 1 && $user['level'] < 4) {
header('Location: gazeta.php');
die();
}
$x = my_int($_GET['x']);
$sql = mysql_query("SELECT * FROM `gazeta_razdel` WHERE `id` = '$x' LIMIT 1");
if (isset($_POST['go'])) {
$edit = trim(mysql_real_escape_string(check($_POST['edit'])));
$em = mysql_query("SELECT `id` FROM `gazeta_razdel` WHERE `name` = '$new' LIMIT 1");
if (empty($edit)) {
err('Пустое название раздела!');
} elseif (mysql_num_rows($edit) != FALSE) {
err('Раздел с таким названием уже создан!');
} else {
mysql_query("UPDATE `gazeta_razdel` SET `name` = '$edit' WHERE `id` = '$x' LIMIT 1");
header('Location: gazeta.php?do=gazeta_r');
}
}
if (mysql_num_rows($sql) == FALSE) {
err('Раздел не найден!');
} else {
$in = mysql_fetch_assoc($sql);
echo '<form method="post" action="gedit-gazeta_edit-'.$x.'">
<label for="q">Редактировать</label>:
<br/>
<input type="text" id="q" name="edit" value="' . $in['name'] . '"/>
<br/>
<input type="submit" name="go" value="Изменить"/>
</form>';
}
break;
// Разделы
case razdel:
$uid = my_int($_GET['uid']);
$sql = mysql_query("SELECT `id` FROM `gazeta_razdel` WHERE `id` = '$uid' LIMIT 1");
if (mysql_num_rows($sql) == FALSE) {
err('Раздела не существует!');
} else {
$select = mysql_result(mysql_query("SELECT COUNT(id) FROM `gazeta_article` WHERE `uid` = '$uid'"), 0);
if ($select != FALSE) {
$n = new navigator($select, 10, 'gcat-razdel-'.$uid.'&');
$sel = mysql_query("SELECT `gazeta_article`.*,(SELECT COUNT(id) FROM `gazeta_comm` WHERE `gazeta_comm`.`id_new` = `gazeta_article`.`id`) AS c FROM `gazeta_article` WHERE `gazeta_article`.`uid` = '$uid' ORDER BY `gazeta_article`.`id` DESC {$n->limit}");
$i = 0;
while($a = mysql_fetch_assoc($sel)) {
if (!empty($a['path'])) $logo = '<img src="resize.php?img='.$a['path'].'&width=60&height=0" alt=""/> ';
// новые
$New = ($a['date'] > (time() - 86400)) ? ' <span style="color: #FF0000;">(new!)</span>' : '';
// обрезаем большой текст
$cont = (mb_strlen($a['content'], 'UTF8') > 250)
? mb_substr($a['content'], 0, 250, 'UTF8') . '...'
: $a['content'];
echo ($i ++ % 2) ? $div_tworazdel : $div_razdel;
echo $logo . '<a href="glook-info-'.$a['id'].'">' . smiles(bb_code($cont)) . '</a>' . $New . $block . '
<a href="glook-info-'.$a['id'].'">Комментарии (' . $a['c'] . ')</a>' . $div_end;
}
echo $n->navi();
} else {
echo 'В этом разделе еще нет статей.<br/>';
}
}
break;
// Информация о статье
case info:
$uid = my_int($_GET['uid']);
$sql = mysql_query("SELECT * FROM `gazeta_article` WHERE `id` = '$uid' LIMIT 1");
if (isset($_GET['x']))
{
if ($user['journalist'] != 1 && $in['author'] != $user['id'] || $user['level'] < 2)
{
header('location: gazeta.php');
die();
}
$x = my_int($_GET['x']);
$em = mysql_query("SELECT * FROM `gazeta_article` WHERE `id` = '$x' LIMIT 1");
if (mysql_num_rows($em) == FALSE) {
err('Статья не найдена!');
} else {
$is = mysql_fetch_assoc($em);
if (file_exists($is['path'])) unlink($is['path']);
mysql_query("DELETE FROM `gazeta_article` WHERE `id` = '$x' LIMIT 1");
header('Location: gcat-razdel-' . $is['uid']);
}
}
if (mysql_num_rows($sql) == FALSE)
{
err('Статьи не существует!');
} else {
// положительный голос
if (isset($_GET['like']))
{
$prv = mysql_query("SELECT `id` FROM `rating_gazeta` WHERE `uid` = '$uid' AND `who` = '$user[id]' LIMIT 1");
if (mysql_num_rows($prv) != FALSE) {
err('Вы уже голосовали!');
} else {
mysql_query("INSERT INTO `rating_gazeta` SET `uid` = '$uid', `who` = '$user[id]', `like` = '1'");
msg('Ваш голос принят!');
}
}
// отрицательный голос
if (isset($_GET['dlike']))
{
$prv = mysql_query("SELECT `id` FROM `rating_gazeta` WHERE `uid` = '$uid' AND `who` = '$user[id]' LIMIT 1");
if (mysql_num_rows($prv) != FALSE) {
err('Вы уже голосовали!');
} else {
mysql_query("INSERT INTO `rating_gazeta` SET `uid` = '$uid', `who` = '$user[id]', `dlike` = '1'");
msg('Ваш голос принят!');
}
}
$in = mysql_fetch_assoc($sql);
if ($user['journalist'] == 1 && $in['author'] == $user['id'] || $user['level'] >= 2 && $user['level'] <= 5)
{
$d = '<a href="gdelete-info-'.$uid.'"><img src="ico/delete.png" alt=""/></a> ';
$e = '<a href="gedit-edit-'.$uid.'"><img src="ico/edit.png" alt=""/></a> ';
}
if (mb_strlen($in['content'], 'UTF8') > 400 && !isset($_GET['read'])) {
$in['content'] = mb_substr($in['content'], 0, 400, 'UTF8') . '...<br/>
<a href="glook-info-'.$uid.'&read"><span class="next">Далее»</span></a>';
} elseif (mb_strlen($in['content'], 'UTF8') > 400 && isset($_GET['read'])) {
$in['content'] = $in['content'] . '<br/>
<a href="glook-info-'.$uid.'"><span class="next">«Скрыть</span></a>';
} else {
$in['content'] = $in['content'];
}
echo (!empty($in['path']) ? '<a href="'.$in['path'].'"><img src="resize.php?img='.$in['path'].'&width=200&height=0" alt=""/></a><br/>' : '') . '
' . $e . $d . smiles(bb_code($in['content'])) . $block . '
Добавил статью: ' . us($in['author']) . '<br/>
Дата добавления: ' . itime($in['date'], 0) . $block;
// Голосование //
$i_vote = mysql_query("SELECT `id` FROM `rating_gazeta` WHERE `uid` = '$uid' AND `who` = '$user[id]' LIMIT 1");
$like = mysql_result(mysql_query("SELECT SUM(`like`) FROM `rating_gazeta` WHERE `uid` = '$uid'"), 0);
$dlike = mysql_result(mysql_query("SELECT SUM(`dlike`) FROM `rating_gazeta` WHERE `uid` = '$uid'"), 0);
$rat_1 = (empty($like)) ? 0 : $like;
$rat_2 = (empty($dlike)) ? 0 : $dlike;
echo 'Рейтинг: ' . ($like - $dlike) . '<br/>';
if ($like - $dlike >= 1) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 3) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 5) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 7) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 10) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 12) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 15) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 17) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 20) echo '<img src="ico/rating1.gif" alt=""/><br/>';
elseif ($like - $dlike >= 25) echo '<img src="ico/rating1.gif" alt=""/><br/>';
else echo '<img src="ico/rating0.gif" alt=""/><br/>';
if (mysql_num_rows($i_vote) == FALSE) {
echo '<a href="gwv-whovote-'.$uid.'-1">' . $rat_1 . '</a>
<a href="glook-info-'.$uid.'&like">
<img src="ico/plus.png" alt="+"/></a>
Голосовать
<a href="gazeta.php?do=info&uid='.$uid.'&dlike">
<img src="ico/minus.png" alt="-"/></a><a href="gwv-whovote-'.$uid.'-2"> ' . $rat_2 . '</a>' . $block;
} else {
echo '<img src="ico/plus.png" alt="+"/><a href="gwv-whovote-'.$uid.'-1"> ' . $like . '</a> |
<img src="ico/minus.png" alt="-"/><a href="gwv-whovote-'.$uid.'-2"> ' . $dlike . '</a>' . $block;
}
// Голосование //
if (isset($_GET['order']) && $_GET['order'] == 2) {
$sort = '<b>вверху</b> | <a href="gsort-info-'.$uid.'-1">внизу</a>';
$ord = 'DESC';
} elseif (isset($_GET['order']) && $_GET['order'] == 1) {
$sort = '<a href="gsort-info-'.$uid.'-2">вверху</a> | <b>внизу</b>';
$ord = 'ASC';
} else {
$sort = '<a href="gsort-info-'.$uid.'-2">вверху</a> | <b>внизу</b>';
$ord = 'ASC';
}
echo $div_menu . 'Новые: ' . $sort . $div_end;
if (isset($_GET['d'])) {
$d = my_int($_GET['d']);
if ($user['level'] < 2) {
header('Location: glook-info-' . $uid);
die();
}
$ecom = mysql_query("SELECT `id` FROM `gazeta_comm` WHERE `id` = '$d' LIMIT 1");
if (mysql_num_rows($ecom) != FALSE) {
mysql_query("DELETE FROM `gazeta_comm` WHERE `id` = '$d' LIMIT 1");
header('Location: glook-info-' . $uid);
} else {
header('Location: glook-info-' . $uid);
}
}
if (isset($_POST['add_com'])) {
$mes = trim(mysql_real_escape_string(check($_POST['mes'])));
if (empty($mes)) {
header('Location: glook-info-' . $uid);
} 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);
}
}
}
if ($in['author'] != $user['id'])
{
$inlenta = (mb_strlen($mes, 'UTF8') > 50)
? mb_substr($mes, 0, 50, 'UTF8') . '...'
: $mes;
$message = cvetnik($user['id']) . ' оставил сообщение ' . bb_code($inlenta) . ' к вашей <a href="glook-info-'.$uid.'">статье</a>!';
mysql_query("INSERT INTO `letters` (`id`,`who`,`idwho`,`message`,`data`,`read`,`mod`)
VALUES (0,'0','$in[author]','$message','" . time() . "','0','i')");
}
// Оповещание последнему постеру
$lst = mysql_fetch_assoc(mysql_query("SELECT `user` FROM `gazeta_comm` WHERE
`id_new` = '$uid'
ORDER BY `id` DESC LIMIT 1"));
if ($user['id'] != $lst['user']) {
$cont = (mb_strlen($in['content'], 'UTF8') > 20)
? mb_substr($in['content'], 0, 20, 'UTF8') . '...'
: $in['content'];
$message = 'Оставлено сообщение в газете к статье <a href="glook-info-'.$uid.'">' . bb_code($cont) . '</a>.';
mysql_query("INSERT INTO `lenta` SET
`user` = '$lst[user]',
`text` = '$message',
`type` = 'comments',
`date` = '" . time() . "',
`read` = '1'");
}
mysql_query("INSERT INTO `gazeta_comm` SET
`date` = '" . time() . "',
`msg` = '$mes',
`id_new` = '$uid',
`user` = '$user[id]'");
header('Location: glook-info-' . $uid);
}
}
$coms = mysql_result(mysql_query("SELECT COUNT(id) FROM `gazeta_comm` WHERE `id_new` = '$uid'"), 0);
if ($coms != false) {
$n = new navigator($coms, $user['onp_comments'], 'glook-info-'.$uid.'&');
$res = mysql_query("SELECT * FROM `gazeta_comm` WHERE `id_new` = '$uid' ORDER BY `id` $ord {$n->limit}");
while($s = mysql_fetch_assoc($res)) {
$del = ($user['level'] >= 2 && $user['level'] <= 5) ? '<a href="gdc-info-'.$uid.'-'.$s['id'].'"><img src="ico/delete.png" alt=""/></a> ' : '';
$otv = ' <a href="answ-g-info-'.$uid.'-'.$s['user'].'#down">[отв]</a>';
echo $div_razdel . $del . us($s['user']) . $otv . ' (' . itime($s['date'], 0) . ')' . $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>
<label><b>Комментарий:</b></label><br/>
<form method="post" action="glook-info-'.$uid.'">
<textarea name="mes" cols="50" rows="5" style="width: 99%;">' . $Komu . '</textarea>
<br/>
<input type="submit" name="add_com" value="Добавить"/>
</form>';
}
echo '« <a href="gcat-razdel-'.$in['uid'].'">В категорию</a>';
break;
// Редактирование статьи
case edit:
$x = my_int($_GET['x']);
$em = mysql_query("SELECT * FROM `gazeta_article` WHERE `id` = '$x' LIMIT 1");
$in = mysql_fetch_assoc($em);
if ($user['journalist'] == 0 && $user['level'] < 4 || $user['level'] < 4 && $user['journalist'] == 1 && $in['author'] != $user['id']) {
header('Location: gazeta.php');
die();
}
if (isset($_POST['ok'])) {
$mes = trim(mysql_real_escape_string(check($_POST['mes'])));
if (empty($mes)) {
err('Пустое содержание статьи!');
} else {
mysql_query("UPDATE `gazeta_article` SET `content` = '$mes' WHERE `id` = '$x' LIMIT 1");
header('Location: glook-info-' . $x);
}
}
if (mysql_num_rows($em) == FALSE) {
err('Статья не найдена!');
} else {
echo '<form method="post" action="gedit-edit-'.$x.'">
<label for="q">Редактировать</label>:
<br/>
<textarea name="mes" id="q" cols="50" rows="5" style="width: 99%;">' . back_bb($in['content']) . '</textarea>
<br/>
<input type="submit" name="ok" value="Изменить"/>
</form>';
}
break;
// Добавление статьи
case create:
if ($user['journalist'] == 0) {
header('Location: gazeta.php');
die();
}
if (isset($_POST['upl'])) {
$content = trim(mysql_real_escape_string(check($_POST['content'])));
$rzd = my_int($_POST['rzd']);
$fnames = $_FILES['file']['name'];
if (!empty($fnames))
{
$pictures = array('.gif', '.jpg', '.jpeg', '.png');
$ext = strtolower(strrchr($_FILES['file']['name'], '.'));
$par = @getimagesize($_FILES['file']['tmp_name']);
if ($par[0] > 1600 || $par[1] > 1200) {
$err = 'Большое расширение файла!';
} elseif (preg_match('/(.php|.pl|.htaccess)/i', $fnames) || !in_array($ext, $pictures)) {
$err = 'Запрещенный формат файла!';
} elseif ($_FILES['file']['size'] > 1024 * 800) {
$err = 'Большой размер файла!';
}
}
if (!empty($err))
{
err($err);
include 'system/foot.php';
exit();
}
if (empty($content)) {
err('Пустое содержание статьи!');
} elseif (empty($rzd)) {
err('Не выбран раздел!');
} else {
if (!empty($fnames))
{
$foto = 'gazeta/img_' . mt_rand(100000, 999999) . $ext;
if ($ext != '.gif' || $ext != '.png') {
$imgc = @imagecreatefromstring(file_get_contents($_FILES['file']['tmp_name']));
$imgc = img_copyright($imgc); // наложение копирайта
imagejpeg($imgc, $foto, 90);
} else {
copy($_FILES['file']['tmp_name'], $foto);
}
chmod(basename($foto), 0777);
$ins = (!empty($fnames)) ? "`path` = '$foto'," : '';
}
mysql_query("INSERT INTO `gazeta_article` SET
`author` = '$user[id]',
$ins
`content` = '$content',
`date` = '" . time() . "',
`uid` = '$rzd'");
$last = mysql_fetch_array(mysql_query("SELECT `id` FROM `gazeta_article` ORDER BY `id` DESC LIMIT 1"));
header('Location: glook-info-' . $last[0]);
}
}
echo '<form ENCTYPE="multipart/form-data" method="post" action="gazeta.php?do=create">
<label>Содержание статьи:</label><br/>
<textarea name="content" cols="50" rows="5" style="width: 99%;"></textarea>
<br/>
<label>Выбрать раздел:</label><br/>
<select name="rzd">';
$from = mysql_query("SELECT * FROM `gazeta_razdel`");
while($a = mysql_fetch_assoc($from)) {
echo '<option value="' . $a['id'] . '">' . $a['name'] . '</option>';
}
echo '</select>
<br/>
<label>Фото к статье: (*max. 1600x1200px. 800kb.)</label><br/>
<input name="file" type="file" accept="image/jpeg, image/png, image/gif"/>
<br/>
<input type="submit" name="upl" value="Добавить"/>
</form>';
break;
case whovote:
$id = my_int($_GET['id']);
$v = my_int($_GET['v']);
$sql = mysql_query("SELECT id FROM gazeta_article 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_gazeta WHERE uid = '$id' AND $var = '1'"), 0);
if ($sel != 0)
{
$n = new navigator($sel, 10, 'gwv-whovote-'.$id.'-'.$v.'&');
$res = mysql_query("SELECT * FROM rating_gazeta WHERE uid = '$id' AND $var = '1' ORDER BY id DESC {$n->limit}");
$i = 0;
while($a = mysql_fetch_assoc($res))
{
echo ($i ++ % 2) ? $div_tworazdel : $div_razdel;
echo us($a['who']) . $div_end;
}
echo $n->navi();
} else {
echo 'За этот вариант никто не голосовал.<br/>';
}
}
echo '« <a href="glook-info-'.$id.'">Назад</a>';
break;
}
include 'system/foot.php';
?>