' . $this->title . '
-
-
+ ';
+
+ if (isset($_SESSION['user'])) {
+ $user = unserialize($_SESSION['user']);
+ if ($user->getId() == parent::getCreator()->getId()) {
+ $html .= '
+
+ ';
+ }
+ }
+
+ $html .= '
+
+
@@ -188,9 +372,9 @@ class Essay extends Post
return $html;
}
- public function allowUser(User $user): bool
+ public function setTitle(string $title)
{
- return parent::getSpace()->allowUser($user);
+ $this->title = $title;
}
public function getTitle(): ?string
@@ -198,79 +382,57 @@ class Essay extends Post
return $this->title;
}
+ public function setMarkdown(string $markdown)
+ {
+ $this->markdown = $markdown;
+ }
+
public function getMarkdown(): ?string
{
return $this->markdown;
}
+ public function getHTML(): string
+ {
+ $parsedown = new Parsedown();
+ $parsedown->setSafeMode(true);
+ return $parsedown->parse($this->markdown);
+ }
+
+ public function setExcerpt(string $excerpt)
+ {
+ $this->excerpt = $excerpt;
+ }
+
public function getExcerpt(): ?string
{
return $this->excerpt;
}
-
- public function setMarkdown(?string $markdown): void
- {
- $this->markdown = $markdown;
- }
-
- public function setExcerpt(?string $excerpt): void
- {
- $this->excerpt = $excerpt;
- }
-
- public function getSpace(): ?Space
- {
- return parent::getSpace();
- }
}
class Moment extends Post
{
private ?string $caption;
- private ?array $images;
+ private $image;
- public function __construct(?Space $space = null, ?int $id = null, User $creator, int $postType, int $status, ?array $images = null, ?string $caption = null)
+ public function __construct(int $space, ?int $id = null, User $creator, int $postType, int $status, $image, string $caption)
{
parent::__construct($space, $id, $creator, $postType, $status);
$this->caption = $caption;
- $this->images = $images;
- }
-
- public function getCaption(): ?string
- {
- return $this->caption;
- }
-
- public function getImages(): ?array
- {
- return $this->images;
- }
-
- public function setCaption(?string $caption): void
- {
- $this->caption = $caption;
- }
-
- public function setImages(?array $images): void
- {
- $this->images = $images;
- }
-}
-
-class Thought extends Post
-{
- private ?string $thought;
-
- public function __construct(?Space $space = null, ?int $id = null, User $creator, int $postType, int $status, string $thought)
- {
- parent::__construct($space, $id, $creator, $postType, $status);
- $this->thought = $thought;
+ $this->image = $image;
if ($id < 0) {
- $stmt = 'INSERT INTO post (id, parentSpace, creator, postType, status, thought) VALUES (?, ?, ?, ?, ?, ?)';
+ if (!isset($image['tmp_name']))
+ return;
+ mkdir($_ENV['IMG_UPLOAD'] . ($id * -1));
+ move_uploaded_file($image['tmp_name'], $_ENV['IMG_UPLOAD'] . ($id * -1) . '/' . $image['name']);
+
+ $this->image = $image['name'];
+
+ $stmt = 'INSERT INTO post (id, space, creator, postType, status, images, caption) VALUES (?, ?, ?, ?, ?, ?, ?)';
parent::setId($id * -1);
- $space = isset($space) ? $space->getId() : $creator->getHomeSpace()->getId();
- exec_stmt($stmt, 'iiiiis', $id * -1, $space, $creator->getId(), 3, 2, $this->thought);
+ $space = isset($space) ? $space : $creator->getHomeSpace()->getId();
+ exec_stmt($stmt, 'iiiiiss', $id * -1, $space, $creator->getId(), 2, 2, $this->image, $this->caption);
$stmt = 'INSERT INTO spacePosts (post, space) VALUES (?, ?)';
exec_stmt($stmt, 'ii', $id * -1, $space);
}
@@ -290,10 +452,118 @@ class Thought extends Post
$user = unserialize($_SESSION['user']);
if ($user->getId() == parent::getCreator()->getId()) {
$html .= '
-
+
+ ';
+ }
+ }
+
+ // TODO: If multiple photos, use components/core/slideshow.php
+ $html .= '
+
+
+
+
 . '/' . $this->image . ')
+
+
' . $this->caption . '
+
+
+ ';
+
+ return $html;
+ }
+
+ public static function edit(int $id, string $caption, int $space)
+ {
+ $post = Post::retrieveFromDB($id);
+ if (!is_a($post, 'Moment'))
+ return;
+
+ $post->setCaption($caption);
+ $post->setSpace($space);
+
+ $stmt = 'UPDATE post SET caption = ?, space = ? WHERE id = ?';
+ exec_stmt($stmt, 'sii', $caption, $space, $id);
+ }
+
+ public function getCaption(): ?string
+ {
+ return $this->caption;
+ }
+
+ public function getImages(): ?array
+ {
+ return $this->image;
+ }
+
+ public function setCaption(?string $caption): void
+ {
+ $this->caption = $caption;
+ }
+
+ public function setImages(?array $image): void
+ {
+ $this->image = $image;
+ }
+}
+
+class Thought extends Post
+{
+ private ?string $thought;
+
+ public function __construct(int $space, ?int $id = null, User $creator, int $postType, int $status, string $thought)
+ {
+ parent::__construct($space, $id, $creator, $postType, $status);
+ $this->thought = $thought;
+
+ if ($id < 0) {
+ $stmt = 'INSERT INTO post (id, space, creator, postType, status, thought) VALUES (?, ?, ?, ?, ?, ?)';
+ parent::setId($id * -1);
+ $space = isset($space) ? $space : $creator->getHomeSpace()->getId();
+ exec_stmt($stmt, 'iiiiis', $id * -1, $space, $creator->getId(), 3, 2, $this->thought);
+ $stmt = 'INSERT INTO spacePosts (post, space) VALUES (?, ?)';
+ exec_stmt($stmt, 'ii', $id * -1, $space);
+ }
+ }
+
+ public static function edit(int $id, string $thought, int $space)
+ {
+ error_log('Updating post ' . $id . ' to have thought = ' . $thought);
+ $post = Post::retrieveFromDB($id);
+ if (!is_a($post, 'Thought'))
+ return;
+
+ $post->setThought($thought);
+ $post->setSpace($space);
+
+ $stmt = 'UPDATE post SET thought = ?, space = ? WHERE id = ?';
+ exec_stmt($stmt, 'sii', $thought, $space, $id);
+ }
+
+ public function getCardHTML(): ?string
+ {
+ $html = '
+
+
+
@' . parent::getCreator()->getUsername() . '
+
+
+ ';
+
+ if (isset($_SESSION['user'])) {
+ $user = unserialize($_SESSION['user']);
+ if ($user->getId() == parent::getCreator()->getId()) {
+ $html .= '
+
';
diff --git a/functions/space.php b/functions/space.php
index 630072b..ed8f338 100644
--- a/functions/space.php
+++ b/functions/space.php
@@ -147,7 +147,7 @@ class Space
foreach ($rawMembers as $m)
$members[] = User::retrieveFromDB($m['user']);
- $stmt = 'SELECT post FROM spacePosts INNER JOIN post ON spacePosts.post = post.id WHERE space = ? ORDER BY post.createdAt DESC';
+ $stmt = 'SELECT post FROM spacePosts INNER JOIN post ON spacePosts.post = post.id WHERE post.space = ? ORDER BY post.createdAt DESC';
$posts = [];
$rawPosts = exec_stmt($stmt, 'i', $rawSpace['id']);
while ($row = $rawPosts->fetch_assoc())
diff --git a/js/actionBar.js b/js/actionBar.js
index 5561673..b64aaa6 100644
--- a/js/actionBar.js
+++ b/js/actionBar.js
@@ -55,6 +55,7 @@ actionPost.addEventListener("click", () => {
return response.json();
})
.then((data) => {
+ console.log(data["html"]);
openModal(data["html"]);
document.querySelector("#redirect").value = window.location.href;
@@ -68,8 +69,6 @@ actionPost.addEventListener("click", () => {
let newPostLabel = document.querySelector("#newPostLabel");
let postType = document.querySelector("#postType");
- let share = document.querySelector("#share");
-
newNavThought.addEventListener("click", () => {
newMoment.style.display = "none";
newEssay.style.display = "none";
@@ -86,7 +85,6 @@ actionPost.addEventListener("click", () => {
newMoment.style.display = "flex";
newPostLabel.innerText = "New Moment";
- newMoment.querySelector('input[type="text"]').focus();
postType.value = "Moment";
});
diff --git a/js/dropdown.js b/js/dropdown.js
index a209f94..09077d0 100644
--- a/js/dropdown.js
+++ b/js/dropdown.js
@@ -18,6 +18,25 @@ window.addEventListener("click", () => {
});
});
+function editPost(id) {
+ fetch("director.php", {
+ method: "POST",
+
+ // TODO: Add Authorization header with JWT
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ body: "ajaxId=editPostHTML&id=" + id,
+ })
+ .then((response) => {
+ return response.json();
+ })
+ .then((data) => {
+ openModal(data["html"]);
+ document.querySelector("#redirect").value = window.location.href;
+ });
+}
+
function deleteSpace(id) {
document.querySelector("#space-" + id).remove();
diff --git a/js/handleEssayModal.js b/js/handleEssayModal.js
new file mode 100644
index 0000000..be78544
--- /dev/null
+++ b/js/handleEssayModal.js
@@ -0,0 +1,24 @@
+let essays = document.querySelectorAll(".divLink");
+
+essays.forEach((e) => {
+ let link = e.querySelector("a").href;
+ let id = link.split("=")[2];
+
+ e.addEventListener("click", () => {
+ fetch("director.php", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ body: "ajaxId=viewEssay&id=" + id,
+ })
+ .then((response) => {
+ return response.json();
+ })
+ .then((data) => {
+ if (!data["html"]) return;
+
+ openModal(data["html"]);
+ });
+ });
+});
diff --git a/js/user.js b/js/user.js
index 1856fe1..2f78b01 100644
--- a/js/user.js
+++ b/js/user.js
@@ -24,8 +24,6 @@ if (logout) {
if (login) {
login.addEventListener("click", () => {
- console.log("click");
-
fetch("director.php", {
method: "POST",
headers: {