minor fixes
This commit is contained in:
parent
daace699a6
commit
2ce4424db7
20 changed files with 674 additions and 621 deletions
|
@ -1,88 +1,92 @@
|
|||
<?php
|
||||
require(__DIR__ . "/../../libs/page.php");
|
||||
|
||||
$ref = 1732684297;
|
||||
|
||||
function getOut($typer, $idr) {
|
||||
if ($typer == 'user' || $typer == 'comment') {
|
||||
header("Location: " . '/' . $typer . '.php?id=' . htmlspecialchars($idr));
|
||||
die();
|
||||
}
|
||||
require(__DIR__ . "/../../libs/page.php");
|
||||
|
||||
header("Location: /");
|
||||
$ref = 1732684297;
|
||||
|
||||
function getOut($typer, $idr)
|
||||
{
|
||||
if ($typer == 'user' || $typer == 'comment') {
|
||||
header("Location: " . '/' . $typer . '.php?id=' . htmlspecialchars($idr));
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
function post_handler() {
|
||||
global $ref;
|
||||
global $username;
|
||||
global $db;
|
||||
if (!$username || !array_key_exists('post',$_POST)) return;
|
||||
|
||||
$postie = $_POST['post'];
|
||||
$postType = (array_key_exists('type',$_POST)) ? $_POST['type'] : 'root';
|
||||
$postId = (array_key_exists('id',$_POST)) ? $_POST['id'] : 'root';
|
||||
header("Location: /");
|
||||
die();
|
||||
}
|
||||
|
||||
if (strlen($postie) < 1 || strlen($postie) > 1024) {
|
||||
getOut($postType,$postId);
|
||||
}
|
||||
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
|
||||
$fid = bin2hex(random_bytes(16));
|
||||
function post_handler()
|
||||
{
|
||||
global $ref;
|
||||
global $username;
|
||||
global $db;
|
||||
if (!$username || !array_key_exists('post', $_POST)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
||||
|
||||
$type = strtolower($type);
|
||||
$postie = $_POST['post'];
|
||||
$postType = (array_key_exists('type', $_POST)) ? $_POST['type'] : 'root';
|
||||
$postId = (array_key_exists('id', $_POST)) ? $_POST['id'] : 'root';
|
||||
|
||||
$mime = mime_content_type('test' . $type);
|
||||
if (strlen($postie) < 1 || strlen($postie) > 1024) {
|
||||
getOut($postType, $postId);
|
||||
}
|
||||
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
|
||||
$fid = bin2hex(random_bytes(16));
|
||||
|
||||
$legal = ['png','gif','jpeg','jpg','mp4','webm','mp3','wav'];
|
||||
$type = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
||||
|
||||
if (in_array($type, $legal)) {
|
||||
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER["DOCUMENT_ROOT"] . '/../docs/pic/' . $fid . '.' . $type);
|
||||
$postie .= "\nhttps://" . $_SERVER['HTTP_HOST'] . '/pic/' . $fid . '.' . $type;
|
||||
}
|
||||
}
|
||||
$type = strtolower($type);
|
||||
|
||||
$poid = bin2hex(random_bytes(16));
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE username = ? ORDER BY date DESC");
|
||||
$stmt->execute([
|
||||
$username
|
||||
]);
|
||||
$userposts = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
$mime = mime_content_type('test' . $type);
|
||||
|
||||
if ($userposts[0]['date'] - (microtime(true) - $ref) > -3) {
|
||||
echo "You have been rate limited.";
|
||||
return;
|
||||
}
|
||||
$legal = ['png','gif','jpeg','jpg','mp4','webm','mp3','wav'];
|
||||
|
||||
if (in_array($type, $legal)) {
|
||||
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER["DOCUMENT_ROOT"] . '/../docs/pic/' . $fid . '.' . $type);
|
||||
$postie .= "\nhttps://" . $_SERVER['HTTP_HOST'] . '/pic/' . $fid . '.' . $type;
|
||||
}
|
||||
}
|
||||
|
||||
$poid = bin2hex(random_bytes(16));
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE username = ? ORDER BY date DESC");
|
||||
$stmt->execute([
|
||||
$username
|
||||
]);
|
||||
$userposts = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
if ($userposts[0]['date'] - (microtime(true) - $ref) > -3) {
|
||||
echo "You have been rate limited.";
|
||||
return;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
|
||||
$stmt->execute([$username,$postType,$postId,microtime(true) - $ref,$postie,$poid]);
|
||||
|
||||
$postieP = "https://nbg.dervland.net/comment.php?id=" . $poid;
|
||||
|
||||
|
||||
$user10 = ':system';
|
||||
if ($postType == 'user') {
|
||||
$postie = "A user commented on your wall: " . $postieP;
|
||||
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
|
||||
$stmt->execute([$username,$postType,$postId,microtime(true) - $ref,$postie,$poid]);
|
||||
$stmt->execute([$user10,'notification',$postId,microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
|
||||
} elseif ($postType == 'comment') {
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC");
|
||||
$stmt->execute([
|
||||
$postId
|
||||
]);
|
||||
$posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
$postieP = "https://nbg.dervland.net/comment.php?id=" . $poid;
|
||||
$posts2 = $posts1[0]['username'];
|
||||
|
||||
$postie = "A user replied to your post: " . $postieP;
|
||||
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
|
||||
$stmt->execute([$user10,'notification',$posts2,microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
|
||||
}
|
||||
|
||||
$user10 = ':system';
|
||||
if ($postType == 'user') {
|
||||
$postie = "A user commented on your wall: " . $postieP;
|
||||
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
|
||||
$stmt->execute([$user10,'notification',$postId,microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
|
||||
} else if ($postType == 'comment') {
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC");
|
||||
$stmt->execute([
|
||||
$postId
|
||||
]);
|
||||
$posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
$posts2 = $posts1[0]['username'];
|
||||
getOut($postType, $postId);
|
||||
}
|
||||
|
||||
$postie = "A user replied to your post: " . $postieP;
|
||||
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
|
||||
$stmt->execute([$user10,'notification',$posts2,microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
|
||||
}
|
||||
|
||||
getOut($postType,$postId);
|
||||
}
|
||||
|
||||
post_handler();
|
||||
?>
|
||||
post_handler();
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
<?php
|
||||
require(__DIR__ . "/../../libs/page.php");
|
||||
|
||||
function get_handler() {
|
||||
global $db;
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.follow");
|
||||
$stmt->execute([]);
|
||||
$result = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
$result = array_reverse($result,true);
|
||||
require(__DIR__ . "/../../libs/page.php");
|
||||
|
||||
echo json_encode($result);
|
||||
}
|
||||
function get_handler()
|
||||
{
|
||||
global $db;
|
||||
|
||||
get_handler();
|
||||
?>
|
||||
$stmt = $db->prepare("SELECT * FROM main.follow");
|
||||
$stmt->execute([]);
|
||||
$result = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
$result = array_reverse($result, true);
|
||||
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
get_handler();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue