Файл: user/wall/comments.php
Строк: 163
<?php
/* Мод "Стена"
* Версия v0.0.1
* Дата последнего редактирования 22.01.2015
* Двиг DCMS Special
* Модифицировал densnet
* Файл comments.php
* Описание: Комментарии к записи, редактирование и удаление записи
*/
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';
$id = intval($_GET['id']);
$wall = mysql_fetch_array(mysql_query("SELECT * FROM `wall` WHERE `id` = '" . intval($_GET['id']) . "';"));
$ank = user::get_user($wall['id_user']);
$set['title'] = ' Запись - ' . $ank['nick'] . '';
require_once H.'sys/inc/thead.php';
title();
aut();
err();
if (isset($_GET['unlike']) && isset($user)) {
mysql_query("DELETE FROM `wall_like` WHERE `id_user` = '$user[id]' AND `id_komm` = '" . intval($_GET['id']) . "' LIMIT 1");
}
if (isset($_GET['like']) && isset($user)) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_like` WHERE `id_komm` = '" . intval($_GET['id']) . "' AND `id_user` = '$user[id]' LIMIT 1"), 0) != 0) {
} else {
mysql_query("INSERT INTO `wall_like` (`id_user`, `id_komm`) values('$user[id]', '" . intval($_GET['id']) . "')");
if (isset($user) && $user['id'] != $ank['id']) {
$mess = "[img]http://$_SERVER[HTTP_HOST]/style/img/like.png[/img] $SexOcen Вашу [url=/user/wall/comments.php?id=$wall[id]]запись[/url].";
mysql_query("INSERT INTO `notification` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$ank[id]', '$mess', '$time')");
}
$like = mysql_query("SELECT * FROM `wall_like` WHERE `id_komm` = '$wall[id]' ORDER BY `id`");
while ($postlike = mysql_fetch_assoc($like)) {
$userlike = user::get_user($postlike['id_user']);
if ($user['id'] != $userlike['id']) {
if ($user['id'] == $ank['id']) {
$not = "[img]http://$_SERVER[HTTP_HOST]/style/img/like.png[/img] $SexOcen Вашу [url=/user/wall/comments.php?id=$wall[id]]запись[/url].";
} elseif ($user['id'] != $ank['id'] && $userlike['id'] != $ank['id']) {
$not = "[img]http://$_SERVER[HTTP_HOST]/style/img/like.png[/img] $SexOcen Вашу [url=/user/wall/comments.php?id=$wall[id]]запись[/url].";
}
if ($userlike['id'] != $user['id'] && $userlike['id'] != $ank['id']) {
mysql_query("INSERT INTO `notification` (`id_user`, `id_kont`, `msg`, `time`) VALUES ('$user[id]', '$userlike[id]', '$not', '$time')");
}
}
}
}
}
$user_id = $ank['id'];
echo "<div class = 'razd'><div style = 'float:right;' id = 'hides'>" . date::time($wall['time']) . "</div>";
echo user($ank['id']);
echo "</div><div class = 'razd'>";
echo "" . text::toOutput($wall['msg']) . " <br />";
$q_f = mysql_query("SELECT * FROM `wall_files` WHERE `id_wall` = '" . intval($_GET['id']) . "'");
while ($file = mysql_fetch_assoc($q_f)) {
if (preg_match('#jpg|jpeg|gif|png#i', $file['ras'])) {
if (isset($user) && $user['level'] > 1) {
echo "<a href = '/files/delete/$file[id]/' title = 'Удалить файл'><img src = '/files/$file[id]/$file[name].$file[ras]' max-width = '100' height = '100' style = 'margin: 1px;'/></a>";
} else {
echo "<img src = '/files/$file[id]/$file[name].$file[ras]' max-width = '100' height = '100' style = 'margin: 1px;'/>";
}
}
}
if (($user['level'] >= 4) || ($user['id'] == $wall['id_user'])) {
echo "<br />";
echo "<a href = 'edit.php?id=$wall[id]' class = 'add'>" . img16('set.png') . " Редактировать</a> ";
echo "<a href = 'edit.php?id=$wall[id]&del' class = 'add'>" . img16('musor.png') . " Удалить</a>";
}
echo "</div>";
if (!isset($_GET['id']) && !is_numeric($_GET['id'])) {
header("Location: index.php?" . SID);
exit;
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `wall` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1", $db), 0) == 0) {
header("Location: index.php?" . SID);
exit;
}
$wall = mysql_fetch_array(mysql_query("SELECT * FROM `wall` WHERE `id` = '" . intval($_GET['id']) . "';"));
if (isset($_POST['msg']) && isset($user)) {
$msg = $_POST['msg'];
if (text::utf8_strlen($msg) > 10024) {
$err = 'Слишком длинное сообщение';
} elseif (text::utf8_strlen($msg) < 2) {
$err = 'Короткое сообщение';
} elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_comments` WHERE `id_wall` = '" . intval($_GET['id']) . "' AND `id_user` = '$user[id]' AND `msg` = '" . mysql_real_escape_string($msg) . "' LIMIT 1"), 0) != 0) {
$err = 'Ваше сообщение повторяет предыдущее';
} else {
mysql_query("INSERT INTO `wall_comments` (`id_user`, `time`, `msg`, `id_wall`) values('$user[id]', '$time', '" . mysql_real_escape_string($msg) . "', '" . intval($_GET['id']) . "')");
mysql_query("UPDATE `user` SET `money` = '" . ($user['money'] + 5) . "', `activity` = '" . ($user['activity'] + 2) . "' WHERE `id` = '$user[id]' LIMIT 1");
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_count` WHERE `id_wall` = '" . intval($_GET['id']) . "' AND `id_user` = '$user[id]' LIMIT 1"), 0) == 0) {
mysql_query("INSERT INTO `wall_count` (`id_user`, `id_wall`) values('$user[id]', '" . intval($_GET['id']) . "')");
}
mysql_query("INSERT INTO `wall` (`user_id`, `who`, `time`) values('$user_id', '" . $user['id'] . "', '" . time() . "')");
if (isset($user) && $user['id'] != $ank['id']) {
$mess = "$SexOst комментарий в Вашей [url=/user/wall/comments.php?id=$wall[id]&page=end]записи[/url]. ";
mysql_query("INSERT INTO `notification` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$ank[id]', '$mess', '$time')");
}
$komm = mysql_query("SELECT * FROM `wall_comments` WHERE `id_wall` = '$wall[id]' ORDER BY `id`");
while ($posts = mysql_fetch_assoc($komm)) {
$userkomm = user::get_user($posts['id_user']);
if ($user['id'] != $userkomm['id']) {
if ($user['id'] == $ank['id']) {
$not = "[img]http://$_SERVER[HTTP_HOST]/style/img/pen.png[/img] $SexKomm Вашу [url=/user/wall/comments.php?id=$wall[id]]запись[/url]. ";
} elseif ($user['id'] != $ank['id'] && $userkomm['id'] != $ank['id']) {
$not = "[img]http://$_SERVER[HTTP_HOST]/style/img/pen.png[/img] $SexKomm Вашу [url=/user/wall/comments.php?id=$wall[id]]запись[/url]. ";
}
if ($userkomm['id'] != $user['id'] && $userkomm['id'] != $ank['id']) {
mysql_query("INSERT INTO `notification` (`id_user`, `id_kont`, `msg`, `time`) VALUES ('$user[id]', '$userkomm[id]', '$not', '$time')");
}
}
}
}
} elseif (isset($_GET['del']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_comments` WHERE `id` = '" . intval($_GET['del']) . "' && `id_wall` = '" . intval($_GET['id']) . "'"), 0)) {
if (isset($user) && ($user['level'] >= 4) || isset($user) && ($user['id'] = $wall['id_user'])) {
mysql_query("DELETE FROM `wall_comments` WHERE `id` = '" . intval($_GET['del']) . "' LIMIT 1");
header("Location: comments.php?id=" . intval($_GET['id']) . "" . SID);
exit;
}
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_comments` WHERE `id_wall` = '" . intval($_GET['id']) . "'"), 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 `wall_comments` WHERE `id_wall` = '" . intval($_GET['id']) . "' ORDER BY `time` ASC LIMIT $start, $set[p_str]");
echo "<div class = 'razd'>";
$like = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_like` WHERE `id_komm` = '" . intval($_GET['id']) . "'"), 0);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_like` WHERE `id_komm` = '" . intval($_GET['id']) . "' AND `id_user` = '$user[id]' LIMIT 1"), 0) == 0) {
echo "<a href = 'comments.php?id=" . intval($_GET['id']) . "&like' class = 'add'>Нравится</a> ";
} else {
echo "<a href = 'comments.php?id=" . intval($_GET['id']) . "&unlike' class = 'addi'>Не нравится</a> ";
}
echo "<a class = 'add' href = 'like_all.php?id=" . intval($_GET['id']) . "'>" . img16('like.png') . " $like</a>";
$kum = @mysql_result(mysql_query("SELECT id_user FROM `wall_like` WHERE `id_komm` = '" . intval($_GET['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 = '/news/?news=$wall[id]&like_all'> ещё $kem пользователю.</a>";
} elseif ($like >= 3) {
echo "<br /><br />";
echo "Это понравилось $vam и <a href = '/news/?news=$wall[id]&like_all'> ещё $kem пользователям.</a>";
}
echo "</div>";
while ($post = mysql_fetch_assoc($q)) {
$ank = user::get_user($post['id_user']);
echo "<table class = 'razd'><tr><td class = 'icon14'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
echo "<div style = 'float:right;'>" . date::time($post['time']) . "</div>";
user($ank['id']);
echo "<br />";
if (isset($user) && ($user['level'] >= 4) || isset($user) && ($user['id'] == $wall['id_user'])) {
echo "<div style = 'float:right;' id = 'hide'>n";
echo "<a href = '?id=" . intval($_GET['id']) . "&del=$post[id]' title = 'Удалить комментарий'>" . img16('musor.png') . "</a>";
echo "</div>";
}
echo text::toOutput($post['msg']);
echo "</td></tr></table>";
}
if ($k_page > 1) {
str("?id=" . intval($_GET['id']) . '&', $k_page, $page);
}
if ($wall['privat_komm'] == 1) {
echo "<div class = 'errs'>";
echo "Автор $SexZapr комментировать";
echo "</div>";
} else {
if (isset($user)) {
echo "<form method = 'post' name = 'message' class = 'razd' action = '?id=" . intval($_GET['id']) . "&page=$page'>";
echo "<textarea required = 'required' name = 'msg' rows = '2' style = 'width:70%'></textarea><br />n";
echo "<button class = 'button sign-ins'>Добавить</button>";
echo "</form>";
}
}
require_once H.'sys/inc/tfoot.php';