1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
| <!-- PHP SETTINGS BEGIN -->
<?php
$time=time();
if (session_id()=='') session_start();
$db=mysqli_connect("localhost","имя_пользователя","пароль","имя_базы") or die();
$res=mysqli_query($db,"set names utf8");
$mess_url='https://3forum.000webhostapp.com/index.php';
//получаем id текущей темы
$res=mysqli_query($db,"SELECT id FROM таблица WHERE file_name='".$mess_url."'");
$res=mysqli_fetch_array($res);
$theme_id=0;
if (isset($_POST["contr_cod"])){ //отправлен комментарий
$mess_login=htmlspecialchars($_POST["mess_login"]);
$user_text=htmlspecialchars($_POST["user_text"]);
if (md5($_POST["contr_cod"])==$_POST["prov_summa"]){ //код правильный
if ($mess_login!='' and $user_text!=''){
if (is_numeric($_POST["parent_id"]) and is_numeric($_POST["f_parent"]))
$res=mysqli_query($db,"insert into comment
(parent_id, first_parent, date, theme_id, login, message)
values ('".$_POST["parent_id"]."','".$_POST["f_parent"]."',
'".$time."','".$theme_id."','".$mess_login."','".$user_text."')");
else $res=mysqli_query($db,"insert into comment (date, theme_id, login, message)
values ('".$time."','".$theme_id."','".$mess_login."','".$user_text."')");
$_SESSION["send"]="Комментарий принят!";
header("Location: index.php#last"); #exit;
}
else {
$_SESSION["send"]="Не все поля заполнены!";
header("Location: index.php#last"); #exit;
}
}
else {
$_SESSION["send"]="Неверный проверочный код!";
header("Location: index.php#last"); #exit;
}
}
if (isset($_SESSION["send"]) and $_SESSION["send"]!="") { //вывод сообщения
echo '<script type="text/javascript">alert("'.$_SESSION["send"].'");</script>';
$_SESSION["send"]="";
}
?>
<!-- PHP SETTINGS END -->
<!-- HTML BEGIN -->
<html lang="ru">
<head>
<meta charset="UTF-8">
<link rel="icon" href="https://www.cyberforum.ru/images/favicon.ico">
<title>3 форум - </title>
<style type="text/css">
.header {
height: 120px;
background-color: green;
margin: 5px;
}
.content {
background-color: green;
margin: 5px;
}
.footer {
background-color: green;
margin: 5px;
}
.add_comment {
display: table;
width: 580px;
border: 1px solid #000;
background-color: #6AF;
}
.close_hint, .open_hint {
float: right;
border: 1px solid #77A;
background: #6e6;
width: 100px;
text-align: center;
cursor: pointer;
}
.close_hint { margin: 5px; color: #F00; }
.comm_body { padding: 0 5px; background-color: #EEE; text-align:left; }
.comm_head { padding: 3px; border: 1px solid #77A; background-color: #DFD; }
.comm_minus { background: url('images/minus.png') no-repeat; }
.comm_plus { background: url('images/plus.png') no-repeat; }
.comm_minus, .comm_plus {
float: right;
width: 19px;
height: 18px;
cursor: pointer;
}
.comm_text { display: none; }
.sp_link { color: #F33; cursor: pointer; }
.strelka {
background: url(images/strelka.png) no-repeat;
border-left: 2px solid #000;
}
.strelka_2 { background: url(images/strelka_2.png) no-repeat; }
#hint { position: absolute; display: none; z-index: 100; }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
//Добавление в форму отправки комментария значений id родительских комментариев
function comm_on(p_id,first_p){
document.add_comment.parent_id.value=p_id;
document.add_comment.f_parent.value=first_p;
}
$(document).ready(function(){
//Показать скрытое под спойлером сообщение
$(".sp_link").click(function(){
$(this).parent().children(".comm_text").toggle("normal");
});
//Показать форму ответа на имеющийся комментарий
$(".open_hint").click(function(){
$("#hint").animate({
top: $(this).offset().top + 25, left: $(document).width()/2 -
$("#hint").width()/2
}, 400).fadeIn(800);
});
//Скрыть форму ответа на имеющийся комментарий
$(".close_hint").click(function(){ $("#hint").fadeOut(1200); });
//Получение id оцененного комментария
$(".comm_plus,.comm_minus").click(function(){
id_comm=$(this).parents(".comm_head").attr("id").substr(1);
});
//Отправление оценки комментария в файл rating_comm.php
$(".comm_plus").click(function(){
jQuery.post("rating_comm.php",{comm_id:id_comm,ocenka:1},rating_comm);
});
$(".comm_minus").click(function(){
jQuery.post("rating_comm.php",{comm_id:id_comm,ocenka:0},rating_comm);
});
//Возврат рейтинга комментария и его обновление
function rating_comm(data){
$("#rating_comm"+id_comm).fadeOut(800,function(){
$(this).html(data).fadeIn(800);
});
}
});
</script>
</head>
<body>
<div class="header">
<h1>header</h1>
</div>
<div class="content">
<h1>content</h1>
<!-- COMMENTS AREA BEGIN -->
<!-- COMMENTS LIST AREA BEGIN -->
<?php
function parents($up=0, $left=0) { //Строим иерархическое дерево комментариев
global $tag,$mess_url;
for ($i=0; $i<=count($tag[$up])-1; $i++) {
//Можно выделять цветом указанные логины
if ($tag[$up][$i][2]=='Admin') $tag[$up][$i][2]='<font color="#C00">Admin</font>';
if ($tag[$up][$i][6]==0) $tag[$up][$i][6]=$tag[$up][$i][0];
//Высчитываем рейтинг комментария
$sum=$tag[$up][$i][4]-$tag[$up][$i][5];
if ($up==0) echo '<div style="padding:5px 0 0 0;">';
else {
if (count($tag[$up])-1!=$i)
echo '<div class="strelka" style="padding:5px 0 0 '.($left-2).'px;">'; #тут открываем комментарий со стрелкой влево
else echo '<div class="strelka_2" style="padding:5px 0 0 '.$left.'px;">'; #иначе тут открываем комментарий со вниз стрелкой влево
}
echo '<div class="comm_head" id="m'.$tag[$up][$i][0].'">';
echo '<div style="float:left;"><b>'.$tag[$up][$i][2].'</b></div>';
echo '<div class="comm_minus"></div>';
echo '<div style="float:right; width:30px;" id="rating_comm'.$tag[$up][$i][0].'">';
echo '<b>'.$sum.'</b></div><div class="comm_plus"></div>';
echo '<a style="float:right; width:70px;" href="'.$mess_url.'#m';
echo $tag[$up][$i][0].'"># '.$tag[$up][$i][0].'</a>';
echo '<div style="float:right; width:170px;">';
echo '('.date("H:i:s d.m.Y", $tag[$up][$i][3]).' г.)</div>';
echo '<div style="clear:both;"></div></div>';
echo '<div class="comm_body">';
#if ($sum<0) echo '<u class="sp_link">Показать/скрыть</u><div class="comm_text">';
echo '<div style="word-wrap:break-word;">';
echo str_replace("<br />","<br>",nl2br($tag[$up][$i][1])).'</div>';
echo '<div class="open_hint" onClick="comm_on('.$tag[$up][$i][0].',
'.$tag[$up][$i][6].')">Ответить</div><div style="clear:both;"></div></div>';
if (isset($tag[ $tag[$up][$i][0] ])) parents($tag[$up][$i][0],20); #ну а тут закрываем все стрелки
echo '</div>';
}
}
$res=mysqli_query($db,"SELECT * FROM comment
WHERE theme_id='".$theme_id."' ORDER BY id"); #and moderation=1
$number=mysqli_num_rows($res);
if ($number>0) {
echo '<div style="border:1px solid #000000;padding:5px;text-align:center;">';
echo '<b>Последние комментарии:</b><br>';
while ($com=mysqli_fetch_assoc($res))
$tag[(int)$com["parent_id"]][] = array((int)$com["id"], $com["message"],
$com["login"], $com["date"], $com["plus"], $com["minus"], $com["first_parent"]);
echo parents().'</div><br>';
}
?>
<!-- COMMENTS LIST AREA END -->
<?php
$cod=rand(1,5); $cod2=rand(5,10);
echo '<div id="last" align="center">';
echo '<form method="POST" action="'.$mess_url.'#last" class="add_comment"';
echo 'name="add_comment" id="hint"><div class="close_hint">Закрыть</div>';
echo '<textarea cols="68" rows="5" name="user_text"></textarea>';
echo '<div style="margin:5px; float:left;">';
echo 'Имя: <input type="text" name="mess_login" maxlength="20" value=""></div>';
echo '<div style="margin:5px; float:right;">'.$cod.' + '.$cod2.' = ';
echo '<input type="hidden" name="prov_summa" value="'.md5($cod+$cod2).'">';
echo '<input type="hidden" name="parent_id" value="0">';
echo '<input type="hidden" name="f_parent" value="0">';
echo '<input type="text" name="contr_cod" maxlength="4" size="4"> ';
echo '<input type="submit" value="Отправить"></div>';
echo '</form>';
echo '<form method="POST" action="'.$mess_url.'#last" class="add_comment">';
echo 'Добавить комментарий:';
echo '<textarea cols="68" rows="5" name="user_text"></textarea>';
echo '<div style="margin:5px; float:left;">';
echo 'Имя: <input type="text" name="mess_login" maxlength="20" value=""></div>';
echo '<div style="margin:5px; float:right;">'.$cod.' + '.$cod2.' = ';
echo '<input type="hidden" name="prov_summa" value="'.md5($cod+$cod2).'">';
echo '<input type="text" name="contr_cod" maxlength="4" size="4"> ';
echo '<input type="submit" value="Отправить"></div>';
echo '</form></div>';
?>
<!-- COMMENTS AREA END -->
</div>
<div class="footer">
<h1>footer</h1>
</div>
</body>
</html>
<!-- HTML END --> |