-
Notifications
You must be signed in to change notification settings - Fork 5
/
comments.php
117 lines (103 loc) · 3.41 KB
/
comments.php
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
<?php
/*
* CloudLevels, an easy way to share user created level files for video games.
* Copyright (C) 2016 Alexander Aquino
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
//CloudLevels View All Comments
//Header + Vars:
$page_title='Comments';
include 'header.php';
//Delete comments
if($user_type==2&&!empty($_GET["deletecomment"])){
try{
$stmt = $db->prepare("
DELETE FROM cl_comment
WHERE id = ?");
$stmt->execute(array($_GET["deletecomment"]));
}
//Handle errors
catch(PDOException $ex){
errorbox('Failed to delete comment.');
include 'footer.php';
exit(0);
}
successbox('Comment deleted. Please wait.');
header("Location:comments.php");
include 'footer.php';
exit(0);
}
$comments=null;
$num_rows=0;
try{
//Get requested comments
$where='';
$args=array();
//Author
if(!empty($_GET["author"])){
$where='WHERE cl_user.username = ?';
array_push($args, $_GET["author"]);
}
$stmt = $db->prepare("
SELECT SQL_CALC_FOUND_ROWS *
FROM cl_comment JOIN cl_user ON cl_comment.author=cl_user.id
" . $where . "
ORDER BY cl_comment.id DESC
" . page_sql_calc(10));
$stmt->execute($args);
$comments = $stmt->fetchAll();
$num_rows = $db->query('SELECT FOUND_ROWS()')->fetchColumn();
}
//Handle errors
catch(PDOException $ex){
errorbox('Failed to load comments.');
}
?>
<br>
<div class="container">
<div class="row card hoverable">
<span class="col s12 card-title <?php echo $theme ?> white-text center" style="font-size: 200%;">Filters</span>
<form action="comments.php" method="get">
<div class="input-field col s12">
<i class="fa fa-user prefix" aria-hidden="true"></i>
<input id="author" name="author" type="text" value="<?php if(!empty($_GET["author"])){echo $_GET["author"];} ?>" class="validate">
<label for="author">Author</label>
</div>
<button class="btn waves-effect waves-light <?php echo $theme ?> col s10 l8 offset-s1 offset-l2" type="submit">Filter</button>
</form><div class="row"></div>
</div>
</div>
<div class="container">
<div class="row card hoverable">
<span class="col s12 card-title <?php echo $theme ?> white-text center" style="font-size: 200%;">Comments</span>
<div class="row"></div>
<?php
//Comments
foreach($comments as $comment){
$append='';
if($user_type==2) $append=' <span class="green-text">[' . $comment[4] . ']</span> <a href="comments.php?deletecomment=' . $comment[0] . '" class="red-text">[Delete]</a>';
$append2=' <a href="index.php">[Link]</a>';
if($comment['file']>0) $append2=' <a href="file.php?id=' . $comment['file'] . '">[Link]</a>';
commentbox($comment, $append . $append2);
}
//Pages
pagination($num_rows, 10, $theme);
?>
</div>
</div>
<?php
//Footer
include 'footer.php';
?>