implemented spaces, fixed login and signup, thought creation and space creation.

This commit is contained in:
2025-05-26 13:00:12 -06:00
parent 54a01f0f1f
commit d3fa1733f4
32 changed files with 1499 additions and 1132 deletions
+46 -35
View File
@@ -60,10 +60,6 @@ class Post
$result = exec_stmt($stmt, 'i', $id)->fetch_assoc();
if ($result['count(id)'] == 1)
return true;
else if ($result['count(id)'] > 1) {
// TODO: Add additional logging here, since that means multiple posts have the same ID.
return true;
}
return false;
}
@@ -80,11 +76,10 @@ class Post
return new Essay(null, $id, $creator, 1, $post['status'], $post['title'], $post['markdown'], $post['excerpt']);
case 3:
return new Thought(null, $post['id'], $creator, 3, $post['status'], $post['thought']);
default:
return null;
}
} else
return null;
}
return null;
}
public function setId(int $id): void
@@ -92,11 +87,6 @@ class Post
$this->id = $id;
}
public function authUser(User $user): bool
{
return true;
}
public function getId(): int
{
return $this->id;
@@ -149,6 +139,10 @@ class Post
public function getSpace(): ?Space
{
if (!isset($this->space)) {
$stmt = 'SELECT space from spacePosts WHERE post = ?';
$rawSpace = exec_stmt($stmt, 'i', $this->id)->fetch_assoc();
}
return $this->space;
}
}
@@ -156,21 +150,17 @@ class Post
class Essay extends Post
{
private string $title;
private string $html;
private string $markdown;
private string $excerpt;
/* private array $files; */
public function __construct(?Space $space = null, ?int $id = null, User $creator, int $postType, int $status, string $title, string $markdown, string $excerpt)
{
parent::__construct($space, $id, $creator, 1, $postType, $status);
require_once 'vendor/autoload.php';
$parsedown = new Parsedown();
$parsedown->setSafeMode(true);
$this->title = $title;
$this->excerpt = $excerpt;
$this->html = $parsedown->text($markdown);
$this->markdown = $markdown;
}
public function getCardHTML(): ?string
@@ -184,8 +174,8 @@ class Essay extends Post
<h4>' . $this->title . '</h4>
</div>
<div class="">
<span>Something</span>
<div class="sm_width">
<i class="nf nf-md-dots_horizontal"></i>
</div>
</div>
<div class="row full_width">
@@ -198,14 +188,19 @@ class Essay extends Post
return $html;
}
public function allowUser(User $user): bool
{
return parent::getSpace()->allowUser($user);
}
public function getTitle(): ?string
{
return $this->title;
}
public function getHTML(): ?string
public function getMarkdown(): ?string
{
return $this->html;
return $this->markdown;
}
public function getExcerpt(): ?string
@@ -215,16 +210,18 @@ class Essay extends Post
public function setMarkdown(?string $markdown): void
{
require_once 'vendor/autoload.php';
$parsedown = new Parsedown();
$parsedown->setSafeMode(true);
$this->html = $parsedown->text($markdown);
$this->markdown = $markdown;
}
public function setExcerpt(?string $excerpt): void
{
$this->excerpt = $excerpt;
}
public function getSpace(): ?Space
{
return parent::getSpace();
}
}
class Moment extends Post
@@ -269,27 +266,41 @@ class Thought extends Post
parent::__construct($space, $id, $creator, $postType, $status);
$this->thought = $thought;
if ($id == null) {
if ($id < 0) {
$stmt = 'INSERT INTO post (id, parentSpace, creator, postType, status, thought) VALUES (?, ?, ?, ?, ?, ?)';
$newID = randomId(1);
parent::setId($newID);
parent::setId($id * -1);
$space = isset($space) ? $space->getId() : $creator->getHomeSpace()->getId();
exec_stmt($stmt, 'iiiiis', $newID, $space, $creator->getId(), 3, 2, $this->thought);
exec_stmt($stmt, 'iiiiis', $id * -1, $space, $creator->getId(), 3, 2, $this->thought);
$stmt = 'INSERT INTO spacePosts (post, space) VALUES (?, ?)';
exec_stmt($stmt, 'ii', $newID, $space);
exec_stmt($stmt, 'ii', $id * -1, $space);
}
}
public function getCardHTML(): ?string
{
$html = '
<div class="std_border padding center full_width top_margin bottom_margin">
<div class="std_border padding center full_width top_margin bottom_margin rel" id="post-' . parent::getId() . '">
<div class="row space_between full_width">
<a href="user.php?view=display&id=' . parent::getCreator()->getId() . '">@' . parent::getCreator()->getUsername() . '</a>
<div class="">
<span>Something</span>
';
if (isset($_SESSION['user'])) {
$user = unserialize($_SESSION['user']);
if ($user->getId() == parent::getCreator()->getId()) {
$html .= '
<div class="dropdown" style="z-index: 0;">
<i class="nf nf-md-dots_horizontal"></i>
<div class="sm_border padding glass dropdownContent">
<a class="underline link" onclick="deletePost(' . parent::getId() . ')">Delete</a>
</div>
</div>
';
}
}
$html .= '
</div>
<div class="line"></div>
<div class="row full_width">