Topic listing is pretty much complete

This commit is contained in:
flash 2018-05-21 18:37:17 +02:00
parent 5364bcac78
commit feb1ecf530
5 changed files with 70 additions and 53 deletions

View file

@ -1,6 +1,6 @@
.forum__topics {
&__listing {
margin: 2px;
margin: 1px;
}
&__none {
@ -10,6 +10,7 @@
&__entry {
display: flex;
align-items: stretch;
min-height: 40px;
&:not(:first-child) {
margin-top: 1px;
@ -20,7 +21,7 @@
&__icon {
flex-shrink: 0;
flex-grow: 0;
align-self: flex-start;
align-self: center;
}
&__info {
@ -30,12 +31,17 @@
flex-grow: 1;
flex-shrink: 1;
padding: 0 2px;
word-wrap: break-word;
overflow: hidden;
}
&__info,
&__activity {
&__datetime,
&__title {
line-height: 1.4em;
margin-bottom: 2px;
&__link {
text-decoration: none;
color: inherit;
@ -52,7 +58,7 @@
&__author {
font-size: .9em;
line-height: 1em;
line-height: 1.2em;
&__name {
color: inherit;

View file

@ -11,28 +11,11 @@ database = database
charset = utf8mb4
collation = utf8mb4_bin
[Database.sqlite_example]
driver = sqlite
database = store/database.db3
prefix =
[Site]
name = Misuzu
description = Describe your description.
twitter = flashiinet
url = http://misuzu.localhost/
[Database.postgres_example]
driver = pgsql
host = localhost
port = 5432
username = username
password = password
prefix = prefix_
database = database
charset = utf8
schema = public
[Database.sqlsrv_example]
driver = sqlsrv
host = localhost
port = 1433
username = username
password = password
prefix = prefix_
database = database
charset = utf8
[GeoIP]
database_path=/path/to/GeoLite2-Country.mmdb

View file

@ -4,6 +4,8 @@ use Misuzu\Database;
require_once __DIR__ . '/../../misuzu.php';
$forumId = (int)($_GET['f'] ?? 0);
$topicsOffset = max((int)($_GET['o'] ?? 0), 0);
$topicsRange = max(min((int)($_GET['r'] ?? 20), 50), 10);
if ($forumId === 0) {
header('Location: /forum/');
@ -16,8 +18,13 @@ $templating = $app->getTemplating();
if ($forumId > 0) {
$getForum = $db->prepare('
SELECT
`forum_id`, `forum_name`, `forum_type`, `forum_link`, `forum_parent`
FROM `msz_forum_categories`
`forum_id`, `forum_name`, `forum_type`, `forum_link`, `forum_parent`,
(
SELECT COUNT(`topic_id`)
FROM `msz_forum_topics`
WHERE `forum_id` = f.`forum_id`
) as `forum_topic_count`
FROM `msz_forum_categories` as f
WHERE `forum_id` = :forum_id
');
$getForum->bindValue('forum_id', $forumId);
@ -42,28 +49,44 @@ $topics = [];
if ($forum['forum_type'] == 0) {
$getTopics = $db->prepare('
SELECT
t.`topic_id`, t.`topic_title`, t.`topic_view_count`, t.`topic_status`, t.`topic_type`,
t.`topic_id`, t.`topic_title`, t.`topic_view_count`, t.`topic_status`, t.`topic_type`, t.`topic_created`,
au.`user_id` as `author_id`, au.`username` as `author_name`,
COUNT(p.`post_id`) as `topic_post_count`,
MIN(p.`post_id`) as `topic_first_post_id`,
MIN(p.`post_created`) as `topic_first_post_created`,
MAX(p.`post_id`) as `topic_last_post_id`,
MAX(p.`post_created`) as `topic_last_post_created`,
MAX(p.`user_id`) as `topic_last_user_id`,
COALESCE(ar.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `author_colour`
COALESCE(ar.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `author_colour`,
lp.`post_id` as `response_id`,
lp.`post_created` as `response_created`,
lu.`user_id` as `respondent_id`,
lu.`username` as `respondent_name`,
COALESCE(lr.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `respondent_colour`,
(
SELECT COUNT(`post_id`)
FROM `msz_forum_posts`
WHERE `topic_id` = t.`topic_id`
) as `topic_post_count`
FROM `msz_forum_topics` as t
LEFT JOIN `msz_users` as au
ON t.`user_id` = au.`user_id`
LEFT JOIN `msz_roles` as ar
ON ar.`role_id` = au.`display_role`
LEFT JOIN `msz_forum_posts` as p
ON t.`topic_id` = p.`topic_id`
LEFT JOIN `msz_forum_posts` as lp
ON lp.`post_id` = (
SELECT `post_id`
FROM `msz_forum_posts`
WHERE `topic_id` = t.`topic_id`
ORDER BY `post_id` DESC
LIMIT 1
)
LEFT JOIN `msz_users` as lu
ON lu.`user_id` = lp.`user_id`
LEFT JOIN `msz_roles` as lr
ON lr.`role_id` = lu.`display_role`
WHERE t.`forum_id` = :forum_id
AND t.`topic_deleted` IS NULL
GROUP BY t.`topic_id`
ORDER BY t.`topic_type` DESC, t.`topic_bumped` DESC
LIMIT :offset, :take
');
$getTopics->bindValue('forum_id', $forum['forum_id']);
$getTopics->bindValue('offset', $topicsOffset);
$getTopics->bindValue('take', $topicsRange);
$topics = $getTopics->execute() ? $getTopics->fetchAll() : $topics;
}
@ -129,4 +152,6 @@ echo $app->getTemplating()->render('forum.forum', [
'forum_info' => $forum,
'forum_breadcrumbs' => $breadcrumbs,
'forum_topics' => $topics,
'forum_offset' => $topicsOffset,
'forum_range' => $topicsRange,
]);

View file

@ -14,7 +14,7 @@
{% if forum_info.forum_type == 0 %}
{% set fcbuttons = forum_category_buttons(forum_info) %}
{% set fcpagination = pagination(forum_topics|length, 20, 0, canonical_url) %}
{% set fcpagination = pagination(forum_info.forum_topic_count, forum_range, forum_offset, canonical_url) %}
{{ fcbuttons }}
{{ fcpagination }}

View file

@ -119,13 +119,16 @@
<div class="forum__topics__entry__info__title forum__topics__entry__info__title--{{ topic_read }}">
<a href="/forum/topic.php?t={{ topic.topic_id }}" class="forum__topics__entry__info__title__link">{{ topic.topic_title }}</a>
</div>
{% if topic.author_id is not null %}
<div class="forum__topics__entry__info__author">
by <a href="/profile.php?u={{ topic.author_id }}" class="forum__topics__entry__info__author__name" style="color:{{ topic.author_colour|colour_get_css }}">
{{ topic.author_name }}
</a>
</div>
{% if topic.author_id is not null %}
by <a
href="/profile.php?u={{ topic.author_id }}"
class="forum__topics__entry__info__author__name"
style="color:{{ topic.author_colour|colour_get_css }}">{{ topic.author_name }}</a>,
{% endif %}
{{ topic.topic_created }}
</div>
</div>
<div class="forum__topics__entry__stats">
@ -139,14 +142,14 @@
<div class="forum__topics__entry__activity">
<div class="forum__topics__entry__activity__datetime">
<a href="/forum/topic.php?p={{ topic.topic_last_post_id }}#p{{ topic.topic_last_post_id }}" class="forum__topics__entry__activity__datetime__link">
{{ topic.topic_first_post_created }}
<a href="/forum/topic.php?p={{ topic.response_id }}#p{{ topic.response_id }}" class="forum__topics__entry__activity__datetime__link">
{{ topic.response_created }}
</a>
</div>
{% if topic.topic_last_user_id is not null %}
{% if topic.respondent_id is not null %}
<div class="forum__topics__entry__activity__author">
by <a href="/profile.php?u={{ topic.topic_last_user_id }}" class="forum__topics__entry__activity__author__name" style="color:{{ topic.author_colour|colour_get_css }}">
{{ topic.author_name }}
by <a href="/profile.php?u={{ topic.respondent_id }}" class="forum__topics__entry__activity__author__name" style="color:{{ topic.respondent_colour|colour_get_css }}">
{{ topic.respondent_name }}
</a>
</div>
{% endif %}