-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
234 lines (209 loc) · 6.38 KB
/
index.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
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
<?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 Front Page
//Header + Vars:
$page_title='';
include 'header.php';
//When there is comment data
if($user_type!=-1&&!empty($_POST["comment"])){
try{
date_default_timezone_set('America/New_York');
$stmt = $db->prepare("
INSERT INTO cl_comment(author, file, date, ip, comment)
VALUES(?,?,?,?,?)");
$stmt->execute(array($_SESSION['uid'], 0, date("F j, Y"), $_SERVER['REMOTE_ADDR'], nl2br(htmlspecialchars($_POST["comment"]))));
}
//Handle errors
catch(PDOException $ex){
errorbox('Failed to post comment.');
include 'footer.php';
exit(0);
}
successbox('Your comment has been posted. Please wait.');
header("Location:index.php");
include 'footer.php';
exit(0);
}
//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:index.php");
include 'footer.php';
exit(0);
}
$result1=null;
$result2=null;
$result3=null;
$comments=null;
$num_rows=0;
try{
//Featured
$stmt = $db->prepare("
SELECT *
FROM cl_file JOIN cl_user ON cl_file.author=cl_user.id
WHERE featured=1
ORDER BY cl_file.id DESC
LIMIT 4");
$stmt->execute();
$result1 = $stmt->fetchAll();
//Popular
$stmt = $db->prepare("
SELECT *
FROM cl_file JOIN cl_user ON cl_file.author=cl_user.id
ORDER BY likes DESC
LIMIT 4");
$stmt->execute();
$result2 = $stmt->fetchAll();
//Recent
$stmt = $db->prepare("
SELECT *
FROM cl_file JOIN cl_user ON cl_file.author=cl_user.id
ORDER BY cl_file.id DESC
LIMIT 4");
$stmt->execute();
$result3 = $stmt->fetchAll();
//Comments
$stmt = $db->prepare("
SELECT SQL_CALC_FOUND_ROWS *
FROM cl_comment JOIN cl_user ON cl_comment.author=cl_user.id
WHERE file = 0
ORDER BY cl_comment.id DESC
" . page_sql_calc(10));
$stmt->execute();
$comments = $stmt->fetchAll();
$num_rows = $db->query('SELECT FOUND_ROWS()')->fetchColumn();
}
//Handle errors
catch(PDOException $ex){
errorbox('Failed to load file information.');
}
?>
<div class="section no-pad-bot" id="index-banner">
<div class="container">
<br><br>
<h1 class="header center <?php echo $theme ?>-text"><?php echo $site_name ?></h1>
<div class="row center">
<h5 class="header col s12 light"><?php echo $site_desc ?></h5>
</div>
<div class="row center">
<a href="<?php echo $game_url ?>" id="download-button" class="btn-large waves-effect waves-light <?php echo $theme ?>">Download Game</a>
</div>
<br><br>
</div>
</div>
<div class="container">
<div class="card hoverable row">
<span class="col s12 card-title <?php echo $theme ?> white-text center" style="font-size: 200%;">Featured</span>
<div class="card-content"><br><br>
<?php
if(!empty($result1)){
foreach($result1 as $file){
filebox($file);
}
}
?>
</div>
<div class="col s12 card-action">
<a class="<?php echo $theme ?>-text right" href="browse.php?featured=on">See more...</a>
</div>
</div>
</div>
<div class="container">
<div class="card hoverable row">
<span class="col s12 card-title <?php echo $theme ?> white-text center" style="font-size: 200%;">Popular</span>
<div class="card-content"><br><br>
<?php
if(!empty($result2)){
foreach($result2 as $file){
filebox($file);
}
}
?>
</div>
<div class="col s12 card-action">
<a class="<?php echo $theme ?>-text right" href="browse.php?sort=popular">See more...</a>
</div>
</div>
</div>
<div class="container">
<div class="card hoverable row">
<span class="col s12 card-title <?php echo $theme ?> white-text center" style="font-size: 200%;">Recent</span>
<div class="card-content"><br><br>
<?php
if(!empty($result3)){
foreach($result3 as $file){
filebox($file);
}
}
?>
</div>
<div class="col s12 card-action">
<a class="<?php echo $theme ?>-text right" href="browse.php?sort=recent">See more...</a>
</div>
</div>
</div>
<?php if(!empty($comments)){ ?>
<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="index.php?deletecomment=' . $comment[0] . '" class="red-text">[Delete]</a>';
commentbox($comment, $append);
}
//Pages
pagination($num_rows, 10, $theme);
?>
</div>
</div>
<?php }
if($user_type==0||$user_type==2){ ?>
<div class="container">
<div class="row card hoverable">
<span class="col s12 card-title <?php echo $theme ?> white-text center" style="font-size: 200%;">New Comment</span>
<form action="index.php" method="post" class="col s12 m10 offset-m1 l8 offset-l2">
<div class="input-field col s12">
<i class="fa fa-comment prefix" aria-hidden="true"></i>
<textarea id="comment" name="comment" class="materialize-textarea" required></textarea>
<label for="comment">Comment</label>
</div>
<button class="btn waves-effect waves-light <?php echo $theme ?> col s12" type="submit">Post</button>
</form><div class="row"></div>
</div>
</div>
<?php
}
//Footer
include 'footer.php';
?>