diff options
-rwxr-xr-x | includes/model/Post.php | 29 | ||||
-rw-r--r-- | includes/model/Thread.php | 24 | ||||
-rwxr-xr-x | includes/model/User.php | 6 | ||||
-rwxr-xr-x | index.php | 6 | ||||
-rwxr-xr-x | viewcategory.php | 4 | ||||
-rwxr-xr-x | viewthread.php | 7 | ||||
-rwxr-xr-x | viewuser.php | 6 |
7 files changed, 51 insertions, 31 deletions
diff --git a/includes/model/Post.php b/includes/model/Post.php index eae3d3e..ab3602b 100755 --- a/includes/model/Post.php +++ b/includes/model/Post.php @@ -53,8 +53,8 @@ class Post public $id;
public $content;
public $date_created;
- public $thread;
- public $author;
+ public $thread_id;
+ public $author_id;
private $has_value = false;
@@ -70,10 +70,8 @@ class Post $this->id = $id;
$this->content = $result[0]['post_content'];
$this->date_created = $result[0]['post_date_created'];
- $this->thread = new Thread($result[0]['post_thread']);
-
- $this->author = new User();
- $this->author->get_by_id($result[0]['post_author']);
+ $this->thread_id = $result[0]['post_thread'];
+ $this->author_id = $result[0]['post_author'];
$this->has_value = true;
}
@@ -83,14 +81,27 @@ class Post return $this->has_value;
}
+ public function get_parent_thread(): ?Thread
+ {
+ return new Thread($this->thread_id);
+ }
+
+ public function get_author(): ?User
+ {
+ $result = new User();
+ $result->get_by_id($this->author_id);
+ return $result;
+ }
+
/**
* Get the post content from the database and return it as a string ready for HTML display
*/
function get_content(): string
{
// Build the header
+ $author = $this->get_author();
$result = '<p class="header" id="p' . $this->id . '"><b>#' . $this->id . '</b>';
- $result .= ' Posted by <a href="viewuser.php?id=' . $this->author->id . '">' . $this->author->name . '</a>';
+ $result .= ' Posted by <a href="viewuser.php?id=' . $author->id . '">' . $author->name . '</a>';
$result .= ' on ' . date('m/d/Y g:ia', strtotime($this->date_created));
if (Session::get()->is_signed_in() && Session::get()->get_current_user()->level == USER_LEVEL_MODERATOR) {
$result .= '<a href="moderate.php?type=post&id=' . $this->id . '" style="float:right;">[Options]</a>';
@@ -113,7 +124,7 @@ class Post // User must have permission to edit the post
$current_user = Session::get()->get_current_user();
- if ($current_user->id != $this->author->id) {
+ if ($current_user->id != $this->author_id) {
trigger_error("You don't have sufficient permissions to edit this post.");
return;
}
@@ -141,7 +152,7 @@ class Post Database::get()->query("DELETE FROM posts WHERE post_id = ?", "i", $this->id);
// Decrement the post count of the category
- Database::get()->query("UPDATE categories SET `category_post_count` = `category_post_count` - '1' WHERE category_id = ?", "i", $this->thread->category->id);
+ Database::get()->query("UPDATE categories SET `category_post_count` = `category_post_count` - '1' WHERE category_id = ?", "i", $this->get_parent_thread()->category_id);
}
public static function create($post_content, $post_thread, $post_category)
diff --git a/includes/model/Thread.php b/includes/model/Thread.php index c939738..2a74a0e 100644 --- a/includes/model/Thread.php +++ b/includes/model/Thread.php @@ -11,8 +11,8 @@ class Thread public $subject; public $date_created = 0; public $last_post_date = 0; - public $category; - public $author; + public $category_id; + public $author_id; private $has_value = false; @@ -29,10 +29,8 @@ class Thread $this->subject = $result[0]['thread_subject']; $this->date_created = $result[0]['thread_date_created']; $this->last_post_date = $result[0]['thread_last_post_date']; - $this->category = new Category($result[0]['thread_category']); - - $this->author = new User(); - $this->author->get_by_id($result[0]['thread_author']); + $this->category_id = $result[0]['thread_category']; + $this->author_id = $result[0]['thread_author']; $this->has_value = true; } @@ -79,7 +77,7 @@ class Thread Database::get()->query("DELETE FROM threads WHERE thread_id = ?", "i", $thread->id); // Decrement the thread count of the category - Database::get()->query("UPDATE categories SET `category_thread_count` = `category_thread_count` - '1' WHERE category_id = ?", "i", $thread->category->id); + Database::get()->query("UPDATE categories SET `category_thread_count` = `category_thread_count` - '1' WHERE category_id = ?", "i", $thread->category_id); } public function has_value(): bool @@ -87,6 +85,18 @@ class Thread return $this->has_value; } + public function get_parent_category(): ?Category + { + return new Category($this->category_id); + } + + public function get_author(): ?User + { + $result = new User(); + $result->get_by_id($this->author_id); + return $result; + } + public static function get_all(): array { $sql = "SELECT thread_id FROM threads"; diff --git a/includes/model/User.php b/includes/model/User.php index 17d40cb..e489edf 100755 --- a/includes/model/User.php +++ b/includes/model/User.php @@ -8,7 +8,7 @@ class User public $id;
public $name;
public $password;
- public $date;
+ public $date_registered;
public $level = 'user';
private $has_value = false;
@@ -27,7 +27,7 @@ class User $this->id = $id;
$this->name = $result[0]['user_name'];
$this->password = $result[0]['user_password'];
- $this->date = $result[0]['user_date_registered'];
+ $this->date_registered = $result[0]['user_date_registered'];
$this->level = $result[0]['user_level'];
$this->has_value = true;
@@ -45,7 +45,7 @@ class User $this->id = $result[0]['user_id'];
$this->name = $name;
$this->password = $result[0]['user_password'];
- $this->date = $result[0]['user_date_registered'];
+ $this->date_registered = $result[0]['user_date_registered'];
$this->level = $result[0]['user_level'];
$this->has_value = true;
@@ -23,7 +23,7 @@ <td>
<b><a href="viewthread.php?id=<?= $latest_thread->id ?>"><?= $latest_thread->subject ?></a></b>
<br>
- <small>by <b><a href="viewuser.php?id=<?= $latest_thread->author->id ?>"><?= $latest_thread->author->name ?></a></b>, <?= $latest_thread->date_created ?></small>
+ <small>by <b><a href="viewuser.php?id=<?= $latest_thread->author_id ?>"><?= $latest_thread->get_author()->name ?></a></b>, <?= $latest_thread->date_created ?></small>
</td>
<?php else: ?>
<td>No threads yet!</td>
@@ -44,10 +44,10 @@ <b><a href="viewthread.php?id=<?= $thread->id ?>"><?= $thread->subject ?></a></b>
<small>on <?= date('M d, Y', strtotime($thread->date_created)); ?></small>
</td>
- <td><a href="viewcategory.php?id=<?= $thread->category->id ?>"><?= $thread->category->name ?></a></td>
+ <td><a href="viewcategory.php?id=<?= $thread->category_id ?>"><?= $thread->get_parent_category()->name ?></a></td>
<?php $latest_post = $thread->get_latest_post(); if ($latest_post->has_value()): ?>
<td>
- <small>by <b><a href="viewuser.php?id=<?= $latest_post->author->id ?>"><?= $latest_post->author->name ?></a></b>
+ <small>by <b><a href="viewuser.php?id=<?= $latest_post->author_id ?>"><?= $latest_post->get_author()->name ?></a></b>
on <?= $latest_post->date_created ?></small>
</td>
<?php else: ?>
diff --git a/viewcategory.php b/viewcategory.php index acca740..486dde7 100755 --- a/viewcategory.php +++ b/viewcategory.php @@ -40,10 +40,10 @@ if (!$current->has_value()) { <b><a href="viewthread.php?id=<?= $thread->id ?>"><?= $thread->subject ?></a></b>
<small>on <?= date('M d, Y', strtotime($thread->date_created)); ?></small>
</td>
- <td><a href="viewuser.php?id=<?= $thread->author->id ?>"><?= $thread->author->name ?></a></td>
+ <td><a href="viewuser.php?id=<?= $thread->author_id ?>"><?= $thread->get_author()->name ?></a></td>
<?php $latest_post = $thread->get_latest_post(); if ($latest_post->has_value()): ?>
<td>
- <small>by <b><a href="viewuser.php?id=<?= $latest_post->author->id ?>"><?= $latest_post->author->name ?></a></b>
+ <small>by <b><a href="viewuser.php?id=<?= $latest_post->author_id ?>"><?= $latest_post->get_author()->name ?></a></b>
on <?= $latest_post->date_created ?></small>
</td>
<?php else: ?>
diff --git a/viewthread.php b/viewthread.php index 06debe8..d0a387e 100755 --- a/viewthread.php +++ b/viewthread.php @@ -27,13 +27,12 @@ if (!$current->has_value()) { <meta property="og:title" content="<?= $current->subject; ?>">
<meta property="og:url" content="https://forum.cflip.net/viewthread.php?id=<?= $current->id; ?>">
<meta property="og:type" content="article">
- <meta property="article:section" content="<?= $current->category->name; ?>">
</head>
<body>
<?php include_once 'includes/templates/header.php'; ?>
<h1><?= $current->subject; ?></h1>
- created by <b><?= $current->author->name; ?></b>
- in <b><?= $current->category->name; ?></b>, <?= date('M d, Y g:ia', strtotime($current->date_created)); ?>
+ created by <b><?= $current->get_author()->name; ?></b>
+ in <b><?= $current->get_parent_category()->name; ?></b>, <?= date('M d, Y g:ia', strtotime($current->date_created)); ?>
<?php if (Session::get()->is_signed_in() and Session::get()->get_current_user()->level == USER_LEVEL_MODERATOR): ?>
<a href="moderate.php?type=thread&id=<?= $current->id; ?>">Moderator Options</a>
<?php endif ?>
@@ -59,7 +58,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (empty($post_content) or !$post_content) {
trigger_error('Reply cannot be empty');
} else {
- Post::create($post_content, $current->id, $current->category->id);
+ Post::create($post_content, $current->id, $current->category_id);
header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $current->id);
}
}
diff --git a/viewuser.php b/viewuser.php index 20dc55f..8d9c9c1 100755 --- a/viewuser.php +++ b/viewuser.php @@ -25,7 +25,7 @@ if (!$current->has_value()) { <body>
<?php include_once "includes/templates/header.php" ?>
<h1><?= $current->name; ?></h1>
- member since <?= date('M d, Y', strtotime($current->date)); ?>
+ member since <?= date('M d, Y', strtotime($current->date_registered)); ?>
<h2><?= $current->name; ?>'s Threads</h2>
<table>
<tr>
@@ -39,10 +39,10 @@ if (!$current->has_value()) { <b><a href="viewthread.php?id=<?= $thread->id ?>"><?= $thread->subject ?></a></b>
<small>on <?= date('M d, Y', strtotime($thread->date_created)); ?></small>
</td>
- <td><a href="viewcategory.php?id=<?= $thread->category->id ?>"><?= $thread->category->name ?></a></td>
+ <td><a href="viewcategory.php?id=<?= $thread->category_id ?>"><?= $thread->get_parent_category()->name ?></a></td>
<?php $latest_post = $thread->get_latest_post(); if ($latest_post->has_value()): ?>
<td>
- <small>by <b><a href="viewuser.php?id=<?= $latest_post->author->id ?>"><?= $latest_post->author->name ?></a></b>
+ <small>by <b><a href="viewuser.php?id=<?= $latest_post->author_id ?>"><?= $latest_post->get_author()->name ?></a></b>
on <?= $latest_post->date_created ?></small>
</td>
<?php else: ?>
|