Files
mallardnet/views/dupes/home/feed_macros.php
2025-11-22 23:57:26 -08:00

175 lines
8.8 KiB
PHP

<?php
if (!isset($_SESSION["user"]))
header("Location: /");
$post = new Post($_SESSION["user"], $conn);
$posts_fetch = $post->getPosts();
$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();
header("Location: /");
}
}
?>
<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("includes/header.php"); ?>
<tr>
<?php require("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">micros</a>
<a href="/feed/marcos" id="non-selected">macros</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()->rowCount() <= 0)
echo "<p class=\"hint\">There are currently no quacks in this feed.</p>"; // rare message
foreach ($post->getPosts() as $p) {
$rowIndex++;
if ($rowIndex != $post->getPosts()->rowCount()) {
echo "<table class=\"bottom-border status-box\">";
} else {
echo "<table class=\"status-box\">";
}
?>
<tbody>
<tr>
<td class="title">
<h1><?= $p["author"]; ?> <img src="/images/badges/user.gif" alt="user"></h1>
<h2>- <span id="date-time"><?= $p["date"]; ?></span></h2>
<?php
if ($_SESSION["user"] == $p["author"]) {
?>
(<a href="/delete_post/<?= $p["id"]; ?>">Delete</a>)
<?php
}
?>
</h2>
<div> </div>
</td>
</tr>
<tr>
<td>
<?= $p["content"]; ?>
</td>
</tr>
<tr>
</tr>
</tbody>
</table>
<?php
}
?>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<?php require("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>