This repository has been archived on 2021-07-02. You can view files and clone it, but cannot push or open issues or pull requests.
chie/public/category.php

133 lines
6.0 KiB
PHP

<?php
require_once '../startup.php';
include_once '_category.php';
include_once '_topics.php';
include_once '_posts.php';
include_once '_user.php';
include_once '_track.php';
$catId = isset($_GET['id']) && is_string($_GET['id']) && ctype_digit($_GET['id']) ? (int)$_GET['id'] : 0;
$categoryInfo = category_info($catId);
if(!$categoryInfo) {
die_ex('Invalid category', 404);
}
if($categoryInfo['cat_type'] == 2) {
http_response_code(302);
header('Location: ' . $categoryInfo['cat_link']);
return;
}
$title = $categoryInfo['cat_name'];
include FMF_LAYOUT . '/header.php';
$breadcrumbs_arr = category_breadcrumbs($categoryInfo['cat_id'], true);
$breadcrumbs = '<a href="/">forum.flash.moe</a> &raquo; ';
foreach($breadcrumbs_arr as $breadcrumb) {
$breadcrumbs .= sprintf('<a href="/category/%d">%s</a> &raquo; ', $breadcrumb['cat_id'], $breadcrumb['cat_name']);
}
echo $breadcrumbs;
?>
<h3 class="forum-title"><?=$categoryInfo['cat_name'];?></h3>
<?php
$categories = category_children($categoryInfo['cat_id'], 2);
if(count($categories) > 0) {
?>
<div class="forum-category">
<div class="forum-category-title">
<div class="forum-category-title-info">Categories</div>
<div class="forum-category-count">Topics</div>
<div class="forum-category-count">Posts</div>
<div class="forum-category-latest forum-category-latest-header">Latest post</div>
</div>
<div class="forum-category-children">
<?php
foreach($categories as $cat1) {
$trackStatus = track_check_category(current_user_id(), $cat1['cat_id']);
?>
<div class="forum-category-board">
<div class="forum-category-board-indicator<?=($trackStatus ? ' unread' : '');?>" title="<?=($trackStatus ? 'There are unread posts' : 'No unread posts');?>"></div>
<div class="forum-category-board-info">
<a href="/category/<?=$cat1['cat_id'];?>"><?=htmlentities($cat1['cat_name']);?></a>
<div class="forum-category-board-desc"><?=htmlentities($cat1['cat_description']);?></div>
</div>
<?php if($cat1['cat_type'] != 2) { ?>
<div class="forum-category-count"><?=number_format($cat1['cat_count_topics']);?></div>
<div class="forum-category-count"><?=number_format($cat1['cat_count_posts']);?></div>
<div class="forum-category-latest">
<?php if($cat1['cat_last_post_id'] < 1) { ?>
No posts
<?php } else { $postInfo = post_info($cat1['cat_last_post_id']); ?>
<a href="/post/<?=$cat1['cat_last_post_id'];?>">#<?=$cat1['cat_last_post_id'];?></a><br/>
<time datetime="<?=date('c', $postInfo['post_created']);?>"><?=date(FMF_DATE_FORMAT, $postInfo['post_created']);?></time>
<?php } ?>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<?php
}
if($categoryInfo['cat_type'] == 0) {
$topics = topics_in_category($categoryInfo['cat_id']);
?>
<a href="/category/<?=$categoryInfo['cat_id'];?>/create" class="createtopicbtn">Create Topic</a>
<div class="topics">
<div class="topics-header">
<div class="topics-header-info">Topics</div>
<div class="topics-item-author">Author</div>
<div class="topics-item-created">Created</div>
<div class="topics-item-count">Posts</div>
<div class="topics-item-latest topics-item-latest-header">Latest reply</div>
</div>
<div class="topics-items">
<?php
foreach($topics as $topic) {
$authorInfo = user_info($topic['user_id']);
$trackStatus = track_check_topic(current_user_id(), $topic['topic_id']);
?>
<div class="topics-item">
<div class="topics-item-indicator<?=($trackStatus ? ' unread' : '');?>" title="<?=($trackStatus ? 'There are unread posts' : 'No unread posts');?>">
</div>
<?php if(!empty($topic['topic_resolved'])) { ?>
<img src="/images/tick.png" title="<?=($categoryInfo['cat_variation'] === 1 ? 'Implemented' : 'Resolved');?>" class="topics-item-status" alt="<?=($categoryInfo['cat_variation'] === 1 ? 'Implemented' : 'Resolved');?>" class="topics-item-status"/>
<?php } elseif(!empty($topic['topic_confirmed'])) { ?>
<img src="/images/<?=($categoryInfo['cat_variation'] === 1 ? 'star' : 'error');?>.png" title="<?=($categoryInfo['cat_variation'] === 1 ? 'Accepted' : 'Confirmed');?>" alt="<?=($categoryInfo['cat_variation'] === 1 ? 'Accepted' : 'Confirmed');?>" class="topics-item-status"/>
<?php } ?>
<?php if(!empty($topic['topic_locked'])) { ?>
<img src="/images/lock.png" title="Locked" alt="Locked" class="topics-item-status"/>
<?php } ?>
<div class="topics-item-info">
<a href="/topic/<?=$topic['topic_id'];?>"><?=htmlentities($topic['topic_title']);?></a>
</div>
<div class="topics-item-author"><a href="/user/<?=$authorInfo['user_id'] ?? 0;?>"><?=$authorInfo['user_login'] ?? 'Deleted User';?></a></div>
<div class="topics-item-created">
<time datetime="<?=date('c', $topic['topic_created']);?>"><?=date(FMF_DATE_FORMAT, $topic['topic_created']);?></time>
</div>
<div class="topics-item-count"><?=number_format($topic['topic_count_replies']);?></div>
<div class="topics-item-latest">
<?php if($topic['topic_last_post_id'] < 1) { ?>
No replies
<?php } else { $postInfo = post_info($topic['topic_last_post_id']); ?>
<a href="/post/<?=$postInfo['post_id'];?>">#<?=$postInfo['post_id'];?></a><br/>
<time datetime="<?=date('c', $postInfo['post_created']);?>"><?=date(FMF_DATE_FORMAT, $postInfo['post_created']);?></time>
<?php } ?>
</div>
</div>
<?php
}
?>
</div>
</div>
<a href="/category/<?=$categoryInfo['cat_id'];?>/create" class="createtopicbtn">Create Topic</a>
<?php
}
include FMF_LAYOUT . '/footer.php';