forked from 4kev90/4kev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpub.php
148 lines (116 loc) · 4.13 KB
/
pub.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
<?php
session_start();
include('functions.php');
include('connectToDatabase.php');
//connect to database
$con = connect_to_database();
$boardName = 'pub';
//prepare variables to insert
$name = mysqli_real_escape_string($con, $_POST['name']);
$comm = mysqli_real_escape_string($con, $_POST['comment']);
$ipAddr = $_SERVER['REMOTE_ADDR'];
setcookie('keepName', $name, time()+3600, '/');
//check if user is banned
if($comm) {
$sql = "SELECT * FROM bannedUsers ";
$result = (mysqli_query($con, $sql));
while($row = mysqli_fetch_assoc( $result )) {
if($row['ipAddress'] == $ipAddr) {
//check if ban is expired
$actualDate = (float)date('YmdHis', time());
if($row['expire'] >= $actualDate) {
//if user is still banned, send him to ban page with query string with info about ban
$reason = $row['reason'];
$date1 = $row['date1'];
$date2 = $row['date2'];
header('Location: http://4kev.org/banned.php?reason=' . $reason . '&date1=' . $date1 . '&date2=' . $date2);
die;
}
}
}
}
//insert data into table
if($comm) {
$sql = "INSERT INTO pub (name, commento, ipAddress) VALUES ('$name', '$comm', '$ipAddr')";
mysqli_query($con, $sql);
//redirect to same page
header('Location: ' . $_SERVER['PHP_SELF']);
die;
}
?>
<HTML>
<head>
<title><?php echo 'Pub'; ?></title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<?php
if($_COOKIE["style"])
$style = $_COOKIE["style"];
else
$style = $defaultTheme;
echo '<link rel="stylesheet" type="text/css" href="/themes/' . $style . '.css?v=' . time() . '">';
?>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript" src="/myjs.js?v=<?=time();?>"></script>
</head>
<div class="bgImage">
<?php boardList($con, $op); ?>
<br>
<div id="boardName">
<!--BANNER-->
<?php banner(); ?>
<p style="font-size:30px"><b><? echo $boardName; ?></b></p>
<?php echo $top_message; ?>
</div>
<br><br>
<!--submission form-->
<div class="form" id="form">
<form style='display:inline;' action="#" method="post" enctype="multipart/form-data" onsubmit="myButton.disabled = true; return true;">
<?php
echo '<textarea placeholder="Name" rows="1" cols="30" input type="text" name="name" />' . $_COOKIE["keepName"] . '</textarea><br>';
?>
<textarea placeholder="Comment" style="width:300px; resize:both;" rows="4" cols="40" input type="text" name="comment" /></textarea><br>
<button style="text-align:center; height:30px; width:300px" type="submit" value="Post" name="myButton">Post</button>
</form>
</div>
<br><hr>
</div>
<?php
//display posts
$selectSQL = "SELECT * FROM pub ORDER BY ID DESC";
$selectRes = mysqli_query($con, $selectSQL);
echo "<div style='text-align:center;'><div class='post' style='width:80%; text-align:left;'>";
echo "<p style='padding-left:10px;'>";
while( $row = mysqli_fetch_assoc( $selectRes ) ){
//prepare variables
$rowID = $row['ID'];
$rowName = htmlspecialchars($row['name']);
$rowComment = htmlspecialchars($row['commento']);
//print name
echo "<span class='userName'><strong> ";
if(!$row['name'])
echo("Anonymous");
else
echo nl2br("$rowName");
echo ': ';
echo "</strong></span>";
//PRINT COMMENT
//divide comment into lines
$lines = explode("\n", $rowComment);
//apply redtext
foreach ($lines as $line) {
//check for redtext
$checkRed = htmlspecialchars_decode($line);
if($checkRed[0] == '>')
echo nl2br("<span class='redtext'>");
else
echo nl2br("<span>");
echo nl2br("$line ");
echo nl2br("</span><br>");
}
}
echo "</p></div></div>";
?>
<br>
</body>
</html>