summaryrefslogtreecommitdiff
path: root/viewcategory.php
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-05-08 17:30:08 -0600
committerGitHub <noreply@github.com>2021-05-08 17:30:08 -0600
commit87b1dfd1f77b08915ee5e905da45e316ba2c0e7d (patch)
treef6c0f8d09454b6e887df0f66ca37c1ce9efb30d0 /viewcategory.php
parent0b045d57b2164b5ce003955d79627ae506a153eb (diff)
parenta09d9f377f5c055e42e5f21b5cdea64c2e2ca896 (diff)
Merge pull request #14 from cflip/refactor
Huge refactor
Diffstat (limited to 'viewcategory.php')
-rw-r--r--viewcategory.php86
1 files changed, 37 insertions, 49 deletions
diff --git a/viewcategory.php b/viewcategory.php
index a10afce..852148b 100644
--- a/viewcategory.php
+++ b/viewcategory.php
@@ -1,6 +1,6 @@
<?php
-include_once 'includes/db_inc.php';
-include_once 'model/Category.php';
+
+include_once 'includes/model/Category.php';
session_start();
@@ -8,65 +8,53 @@ $current = new Category();
if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
http_response_code(404);
- include_once 'templates/404.php';
+ include('includes/templates/404.php');
die();
} else {
- $result = $current->get_from_database($_GET['id'], $dbc);
- if ($result == 0) {
+ $result = $current->get_from_database($_GET['id']);
+ if (!$result) {
http_response_code(404);
- include_once 'templates/404.php';
+ include('includes/templates/404.php');
die();
}
}
?>
<!DOCTYPE html>
-<html>
+<html lang="en">
<head>
- <title><?= $current->name; ?> - cflip.net forum</title>
- <link rel="stylesheet" href="styles/style.css">
+ <title><?= $current->name; ?> - cflip.net forum</title>
+ <link rel="stylesheet" href="styles/style.css">
</head>
<body>
-<?php include_once 'templates/header.php';?>
- <h1><?= $current->name; ?></h1>
- <p><?= $current->description; ?></p>
- <span class="info">
- <?= $current->thread_count . ' threads, ' . $current->post_count . ' posts'; ?>
- </span>
- <h2>Threads</h2>
- <table width="100%">
- <tr>
- <th>Thread Name</th>
- <th>Latest Post</th>
- </tr>
- <?php
- function cmp($a, $b) {
- $da = strtotime($a->date_lastpost);
- $db = strtotime($b->date_lastpost);
-
- if ($da == $db) return 0;
-
- return ($da > $db) ? -1 : 1;
+<?php include('includes/templates/header.php'); ?>
+<h1><?= $current->name; ?></h1>
+<p><?= $current->description; ?></p>
+<span class="info"><?= $current->thread_count . ' threads, ' . $current->post_count . ' posts'; ?></span>
+<h2>Threads</h2>
+<table>
+ <tr>
+ <th>Thread Name</th>
+ <th>Latest Post</th>
+ </tr>
+ <?php
+ $threads = $current->get_threads();
+
+ foreach ($threads as $thread) {
+ $latest_post = $thread->get_latest_post();
+
+ echo '<tr>';
+ echo '<td><b><a href="viewthread.php?id=' . $thread->id . '">' . $thread->subject . '</a></b>';
+ echo '<small> by <b><a href="viewuser.php?id=' . $thread->author->id . '">' . $thread->author->name . '</a></b> on ' . date('M d, Y', strtotime($thread->date_created)) . '</small></td>';
+
+ if (!is_null($latest_post)) {
+ echo '<td>by <b><a href="viewuser.php?id=' . $latest_post->author->id . '">' . $latest_post->author->name . '</a></b><small> on ' . $latest_post->date_created . '</small></td>';
+ } else {
+ echo '<td>No posts yet!</td>';
}
-
- $threads = $current->get_threads($dbc);
- usort($threads, "cmp");
-
- foreach ($threads as $thread) {
- $latest_post = $thread->get_latest_post($dbc);
- echo '<tr>';
- echo '<td><b><a href="viewthread.php?id=' . $thread->id . '">' . $thread->subject . '</a></b>';
- echo '<small> by <b><a href="viewuser.php?id=' . $thread->author->id . '">' . $thread->author->name . '</a></b> on ' . date('M d, Y', strtotime($thread->date_created)) . '</small></td>';
-
- if (!is_null($latest_post)) {
- echo '<td>by <b><a href="viewuser.php?id=' . $latest_post->author->id . '">' . $latest_post->author->name . '</a></b><small> on ' . $latest_post->date_created . '</small></td>';
- } else {
- echo '<td>No posts yet!</td>';
- }
-
- echo '</tr>';
- }
- ?>
- </table>
+ echo '</tr>';
+ }
+ ?>
+</table>
</body>
</html>