177 lines
8.9 KiB
PHP
177 lines
8.9 KiB
PHP
<?php
|
|
if (!isset($_SESSION["user"]))
|
|
header("Location: /");
|
|
|
|
$dirBump = dirname(__DIR__, 2); // weird folder bug
|
|
|
|
$post = new Post($_SESSION["user"], $conn);
|
|
$posts_fetch = $post->getPosts(2);
|
|
$rowIndex = 0;
|
|
|
|
if (isset($_POST["send"])) {
|
|
$form = (object) [
|
|
"title" => htmlspecialchars(trim($_POST["post-title"])),
|
|
"content" => htmlspecialchars(trim($_POST["post-content"])),
|
|
];
|
|
|
|
$post->getForm($form->title, $form->content);
|
|
$post->postUpdate();
|
|
|
|
if ($post->error == NULL) {
|
|
$post->insertPost();
|
|
if ($form->title == NULL) {
|
|
header("Location: /feed/micros");
|
|
} else {
|
|
header("Location: /feed/marcos");
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<html>
|
|
<head>
|
|
<title><?= $website->title; ?>: <?= $website->slogan; ?></title>
|
|
<link rel="stylesheet" href="/styles/main.css">
|
|
<script src="/scripts/from-now.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<table class="container" align="center">
|
|
<tbody>
|
|
<?php require($dirBump."/includes/header.php"); ?>
|
|
|
|
<tr>
|
|
<?php require($dirBump."/includes/left_sidebar.php"); ?>
|
|
|
|
<td valign="top" align="left">
|
|
<table class="post-container">
|
|
<tbody>
|
|
<?php
|
|
if (isset($_POST["send"]) && isset($post))
|
|
if ($post->error != NULL) echo "<font style=\"color: #831f1f\">$post->error</font> <br>";
|
|
?>
|
|
<form action="/" method="POST">
|
|
<tr>
|
|
<td class="speech-bubble">
|
|
<input id="text-title" type="text" placeholder="post title" name="post-title" class="post-text" maxlength="60"></textarea>
|
|
<textarea id="text-content" name="post-content" rows="2" class="post-text" placeholder="what's quacking?" maxlength=2500></textarea>
|
|
<span id="text-length" class="post-label">300</span>
|
|
</td>
|
|
<td valign="top" width="50">
|
|
<img src="/images/profile_pic/duck.gif" alt="duck" class="pfp">
|
|
<input type="submit" name="send" value="post">
|
|
</td>
|
|
</tr>
|
|
</form>
|
|
</tbody>
|
|
</table>
|
|
|
|
<table class="box-tab small-tabs feed">
|
|
<tbody>
|
|
<tr>
|
|
<th align="left">
|
|
<a href="/feed/micros" id="non-selected">micros</a>
|
|
<a href="/feed/marcos">marcos</a>
|
|
<a href="/feed/gallery" id="non-selected">gallery</a>
|
|
</th>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<table class="status-feed">
|
|
<tbody>
|
|
<tr>
|
|
<td>
|
|
<?php
|
|
if ($post->getPosts(2)->rowCount() <= 0)
|
|
echo "<p class=\"hint\">There are currently no quacks in this section.</p>"; // rare message
|
|
|
|
foreach ($post->getPosts(2) as $p) {
|
|
$rowIndex++;
|
|
if ($rowIndex != $post->getPosts(2)->rowCount()) {
|
|
echo "<table class=\"bottom-border status-box\">";
|
|
} else {
|
|
echo "<table class=\"status-box\">";
|
|
}
|
|
?>
|
|
<tbody>
|
|
<tr>
|
|
<td class="title">
|
|
<a href="/quack/<?= $p["id"]; ?>" class="blog-button"><h1><?= $p["title"]; ?></h1></a>
|
|
<?php
|
|
if ($_SESSION["user"] == $p["author"])
|
|
echo "<div class=\"right\">
|
|
<a href=\"/delete_quack/".$p["id"]."\"><img alt=\"Delete\" src=\"/images/buttons/del.gif\" \></a>
|
|
</div>";
|
|
?>
|
|
</td>
|
|
<td>
|
|
by
|
|
<h1><?= $p["author"]; ?> <img src="/images/badges/user.gif" alt="user"></h1>
|
|
<h2>- <span id="date-time"><?= $p["date"]; ?></span></h2>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<?php
|
|
}
|
|
?>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
|
|
<?php require($dirBump."/includes/footer.php"); ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<script>
|
|
var alltimeStamps = document.querySelectorAll('#date-time');
|
|
var textTitle = document.getElementById('text-title');
|
|
var textContext = document.getElementById('text-content');
|
|
var textLength = document.getElementById('text-length');
|
|
var textLimit = 300;
|
|
|
|
// A little stack overflow-ish code?
|
|
for (var t=0;t<alltimeStamps.length; t++) {
|
|
const stringUTC = alltimeStamps[t].textContent.replace(' ', 'T') + 'Z';
|
|
const objUTC = new Date(stringUTC);
|
|
objUTC.setTime(objUTC.getTime() + objUTC.getTimezoneOffset()*60*1000);
|
|
console.log(alltimeStamps[t].textContent);
|
|
alltimeStamps[t].textContent = fromNow(objUTC);
|
|
}
|
|
|
|
function checkRed() {
|
|
if (textLength.textContent < 0) {
|
|
textLength.style.color = "red";
|
|
} else {
|
|
textLength.style.color = "";
|
|
}
|
|
}
|
|
|
|
textContext.addEventListener('input', function handleChange(event) {
|
|
console.log(textLimit);
|
|
textLength.textContent = textLimit - textContext.value.length;
|
|
checkRed();
|
|
});
|
|
|
|
textTitle.addEventListener('input', function handleChange(event) {
|
|
console.log(textLimit);
|
|
if (textTitle.value.trim() == "") {
|
|
textLimit = 300;
|
|
} else {
|
|
textLimit = 2500;
|
|
}
|
|
textContext.setAttribute('maxLength', textLimit);
|
|
textLength.textContent = textLimit - textContext.value.length;
|
|
checkRed();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|