/
edit.php
301 lines (250 loc) · 11.1 KB
/
edit.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?php
session_start();
if (!isset($_SESSION['mode'])) {
$_SESSION['mode'] = 'user';
}
if(!isset($_SESSION['user'])) {
$_SESSION['user'] = 'Guest';
}
require ('includes/config.php');
require('includes/user.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $siteTitle ?> - Edit</title>
<?php
echo '<link rel="stylesheet" href="css/blag-light.css">';
if ($usecustombg == "true") {
echo '<style type="text/css">body{background: url("' . $custombg . '")}</style>';
}
echo '<link rel="stylesheet" href="css/blag-' . $_SESSION['theme'] . '.css">';
if ($usepace === 'true') {
echo '<link rel="stylesheet" href="css/pace/pace-centerbar.css">';
echo '<script src="js/pace/pace.min.js"></script>';
}
?>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<?php
if($localcode) {
echo '<script src="js/jquery.min.js"></script>';
} else {
echo '<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script>';
}
?>
<script src="js/bootstrap.min.js"></script>
<script src="js/blag.js"></script>
<style type="text/css">
input#title {
font-size: 30px;
}
input[type='radio'] {
display: none;
}
input[type='radio'] + label {
border: rgba(0,0,0,.4) 1px solid;
border-radius: 33px;
background: rgba(0,0,0,.2);
transition: all .2s ease;
-webkit-transition: all .3s ease;
margin: 0px 5px 0px 5px;
padding: 5px;
width: 50px;
text-align: center;
}
input[type='radio']:checked + label {
background: #d4a017;
color: #c04000;
}
</style>
</head>
<body>
<div class="alert-error" id="errordiv">
Error goes here
</div>
<?php
# Sanitizer function - removes forbidden tags, including script tags
function strip_tags_attributes( $str,
$allowedTags = array('<a>','<b>','<blockquote>','<br>','<cite>','<code>','<del>','<div>','<em>','<ul>','<ol>','<li>','<dl>','<dt>','<dd>','<img>','<video>','<iframe>','<ins>','<u>','<q>','<h3>','<h4>','<h5>','<h6>','<samp>','<strong>','<sub>','<sup>','<p>','<table>','<tr>','<td>','<th>','<pre>','<span>'),
$disabledEvents = array('onclick','ondblclick','onkeydown','onkeypress','onkeyup','onload','onmousedown','onmousemove','onmouseout','onmouseover','onmouseup','onunload') )
{
if( empty($disabledEvents) ) {
return strip_tags($str, implode('', $allowedTags));
}
return preg_replace('/<(.*?)>/ies', "'<' . preg_replace(array('/javascript:[^\"\']*/i', '/(" . implode('|', $disabledEvents) . ")=[\"\'][^\"\']*[\"\']/i', '/\s+/'), array('', '', ' '), stripslashes('\\1')) . '>'", strip_tags($str, implode('', $allowedTags)));
}
if($_SESSION['mode'] === 'admin') {
$postid = 0;
$db = mysqli_connect($dbhost,$dbuname,$dbupass,$dbname);
if (mysqli_connect_errno()) {
//echo "Failed to connect to MySQL: " . mysqli_connect_error();
echo "<script type='text/javascript'>displayLoginError('error', 'MySQL conn failed: " . mysqli_connect_error() . "')</script>";
}
if(isset($_POST["Submit"])) {
//Change this so that apostraphes and stuff can be used
$title = addslashes(strip_tags_attributes($_POST["title"]));
$content = addslashes(strip_tags_attributes($_POST["content"]));
$creator = '<a href="user.php?u=' . $_SESSION['user'] . '">' . $_SESSION['username'] . '</a>';
date_default_timezone_set('America/New_York');
$timestamp = date("m/d/Y") . ' at ' . date("h:i:s a");
$tags = addslashes(strip_tags_attributes($_POST['tags']));
$isNSFW = $_POST['nsfwcheck'];
$sql = "INSERT INTO Posts (title, content, creator, timestamp, tags, isNSFW)
VALUES ('$title',
'$content',
'$creator',
'$timestamp',
'$tags',
'$isNSFW')";
if (!mysqli_query($db,$sql)) {
die('Error: ' . mysqli_error($db));
}
mysqli_close($db);
//header('Location: ' . dirname($_SERVER['REQUEST_URI']));
echo '<script type="text/javascript">location.href = "' . dirname($_SERVER['REQUEST_URI']) . '";</script>';
}
if(isset($_POST['Edit'])) {
if(isset($_POST['type'])) {
if($_POST['type'] === 'reply') {
//bla
}
} else {
$newtitle = addslashes(strip_tags_attributes($_POST['title']));
$newtags = addslashes(strip_tags_attributes($_POST['tags']));
$isNSFW = $_POST['nsfwcheck'];
}
$newcontent = addslashes(strip_tags_attributes($_POST['content']));
$postid = $_POST['postid'];
$return_to = $_GET['return_to'];
$db = mysqli_connect($dbhost,$dbuname,$dbupass,$dbname);
if (mysqli_connect_errno()) {
//echo "Failed to connect to MySQL: " . mysqli_connect_error();
echo "<script type='text/javascript'>displayLoginError('error', 'MySQL conn failed: " . mysqli_connect_error() . "')</script>";
}
if(!isset($_POST['type'])) {
$sql = "UPDATE Posts SET title='$newtitle', content='$newcontent', tags='$newtags', isNSFW='$isNSFW' WHERE PID=$postid";
$header = dirname($_SERVER['REQUEST_URI']) . 'index.php?p=' . $return_to;
} else {
$sql = "UPDATE Replies SET content='$newcontent' WHERE PID=$postid";
$header = dirname($_SERVER['REQUEST_URI']) . 'post.php?reply_to=' . $return_to;
}
if (!mysqli_query($db,$sql)) {
die('Error: ' . mysqli_error($db));
}
mysqli_close($db);
//header('Location: ' . $header);
echo '<script type="text/javascript">location.href = "' . $header . '";</script>';
//echo $header;
}
?>
<div class="header-admin">
<span class="header-content">
<a href="index.php" class="btn homebtn"><i class="fa fa-home"></i></a>
<a href="#" type="submit" name="Logout" class="btn-lock" onclick="document.logout.submit();"><i class="fa fa-lock"></i></a>
<a href="user.php?u=<?php echo $_SESSION['user']; ?>" class="btn btn-random"><i class="fa fa-user"></i></a>
<a href="admin/admin.php" class="btn btn-random"><i class="fa fa-dashboard"></i></a>
<a href="edit.php" class="btn btn-random"><i class="fa fa-pencil"></i></a>
<span class='msg-welcome'>Heyo, <?php echo strtok($_SESSION['username'], ' '); ?>!</span>
</span>
</div>
<div class="blag-body">
<?php
// if($_SESSION['mode'] === 'admin') {
//if(empty($_POST['Submit'])) {
if(!isset($_GET['action'])) { ?>
<form action="" method="post" name="submit" id="submit">
<p><input class="editpage-content" name="title" id="title" type="text" placeholder="Team# and Name">
<p><textarea class="editpage-content" name="content" id="content" rows="18" cols="60" placeholder="Write stuffs here"></textarea>
Tags and stuff:
<p><input class="editpage-content" type="text" placeholder="Separate tags with spaces" value="" name="tags">
<!-- <p><span class="">Tag for mature content?</span>
<input class="" type="radio" value="1" name="nsfwcheck" id="cb1"><label for="cb1">Yes</label>
<input class="" type="radio" value="0" name="nsfwcheck" id="cb2" checked><label for="cb2">No</label> -->
<input class="" type="hidden" value="0" name="nsfwcheck">
<p><input class="btn btn-submit" type="submit" name="Submit" value="Post">
</form>
<?php } else if ($_GET['action'] === 'edit') {
if(isset($_POST['Entereditcontent'])) {
$postid = $_POST['postid'];
if(isset($_POST['type'])) {
if($_POST['type'] === 'reply') {
$body = mysqli_query($db,"SELECT * FROM Replies WHERE PID=$postid");
}
} else {
$body = mysqli_query($db,"SELECT * FROM Posts WHERE PID=$postid");
}
while($row = mysqli_fetch_array($body)) {
?>
<form action="" method="post" name="Edit" id="edit">
<input type="hidden" name="postid" value="<?php echo $postid; ?>">
<?php if(!isset($_POST['type'])) { ?>
<p><input class="editpage-content" name="title" id="title" type="text" placeholder="Team# and Name" value="<?php echo $row['title'] ?>">
<?php } else { ?>
<input type="hidden" name="type" value="reply">
<input type="hidden" name="return_to" value="<?php $_GET['return_to'] ?>">
<?php } ?>
<p><textarea class="editpage-content" name="content" id="content" rows="18" cols="60" placeholder="Write stuffs here"><?php echo $row['content']; ?></textarea>
<?php if(!isset($_POST['type'])) { ?>
Tags and stuff:
<p><input class="editpage-content" type="text" placeholder="Separate tags with spaces" value="<?php echo $row['tags']; ?>" name="tags">
<!-- <p><span class="">Tag for mature content?</span>
<input class="" type="radio" value="1" name="nsfwcheck" id="cb1" <?php echo ($row['isNSFW'] == 1)?'checked':'' ?>><label for="cb1">Yes</label>
<input class="" type="radio" value="0" name="nsfwcheck" id="cb2" <?php echo ($row['isNSFW'] == 0)?'checked':'' ?>><label for="cb2">No</label> -->
<input class="" type="hidden" value="0" name="nsfwcheck">
<?php } ?>
<p><input class="btn btn-submit" type="submit" name="Edit" value="Update">
</form>
<?php
}
}
}
?>
</div>
<form action="login.php" method="post" name="logout" id="logout">
<input type="hidden" value="logout">
</form>
<?php
if ($usetinymce === 'true') { ?>
<!-- <script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script> -->
<script type="text/javascript" src="<?php echo dirname($_SERVER['REQUEST_URI']); ?>/includes/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector:'textarea#content',
plugins: [
"autolink lists link image preview",
"searchreplace code fullscreen",
"media table paste contextmenu"
],
toolbar: "undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
setTimeout(function() {
tinymce.get('content').dom.loadCSS('css/blag-light-tinymce.css');
}, 500); //delay while tinymce loads
$('textarea#bio').keydown(function (e){
if(e.keyCode == 13){
$('textarea#content').val($('textarea#bio').val() + '<br>');
}
});
</script>
<?php
}
} else {
//return to index page if user not logged in
header('Location: ' . dirname($_SERVER['REQUEST_URI']));
die();
}
?>
<!--<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-48081162-1', 'villa7.github.io');
ga('send', 'pageview');
</script> -->
</body>
</html>