-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbweet.php
56 lines (51 loc) · 1.95 KB
/
bweet.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
<?php
include "inc/main.php";
if(!isset($_USER)) die(header("Location: /"));
function secondsToTime($seconds) {
$dtF = new \DateTime('@0');
$dtT = new \DateTime("@$seconds");
if($seconds > 24*60*60) {
return $dtF->diff($dtT)->format('%a days and %h hours');
} elseif($seconds > 60*60) {
return $dtF->diff($dtT)->format('%h hours and %i minutes');
} elseif($seconds > 60) {
return $dtF->diff($dtT)->format('%i minutes and %s seconds');
} else {
return $dtF->diff($dtT)->format('%s seconds');
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ~$_USER["flags"] & TYPE_SUSPENDED) {
$content = trim($_POST["content"]);
if(strlen($content) > 300) {
$_SESSION["notice"] = "Bweet cannot be longer than 300 characters.";
die(header("Location: /"));
} elseif(strlen($content) < 1) {
$_SESSION["notice"] = "Bweet cannot be blank.";
die(header("Location: /"));
}
$content = htmlspecialchars($content);
$uid = $_USER["id"];
if(is_restricted($_USER, "BWEET")) {
$left = secondsToTime(restricted($_USER, "BWEET"));
$_SESSION["notice"] = "Your ability to Bweet is restricted for $left.";
die(header("Location: /"));
} elseif(is_restricted($_USER, "RATELIMIT")) {
$left = restricted($_USER, "RATELIMIT");
$_SESSION["notice"] = "Can't bweet for another ".($left > 60 ? (floor(($left/60)*10)/10)." minutes" : "$left seconds").".";
die(header("Location: /"));
}
$id = $snowflake->id();
$timestamp = time();
$stmt = $db->prepare("INSERT INTO `tweets` (`id`, `content`, `user`, `timestamp`) VALUES (?, ?, ?, ?)");
if(!$stmt || !$stmt->bind_param("isii", $id, $content, $uid, $timestamp) || !$stmt->execute()) {
$_SESSION["notice"] = "Internal server error.\r\n";
$_SESSION["notice"] .= $db->error;
die(header("Location: /"));
}
$time = 60;
if($_USER["flags"] & TYPE_ADMIN)
$time = 10;
restrict($_USER, "RATELIMIT", $time);
die(header("Location: /"));
} else die(header("Location: /"));
?>