diff options
Diffstat (limited to 'viewcategory.php')
-rw-r--r-- | viewcategory.php | 86 |
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> |