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

View file

@ -11,28 +11,11 @@ database = database
charset = utf8mb4 charset = utf8mb4
collation = utf8mb4_bin collation = utf8mb4_bin
[Database.sqlite_example] [Site]
driver = sqlite name = Misuzu
database = store/database.db3 description = Describe your description.
prefix = twitter = flashiinet
url = http://misuzu.localhost/
[Database.postgres_example] [GeoIP]
driver = pgsql database_path=/path/to/GeoLite2-Country.mmdb
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

View file

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

View file

@ -14,7 +14,7 @@
{% if forum_info.forum_type == 0 %} {% if forum_info.forum_type == 0 %}
{% set fcbuttons = forum_category_buttons(forum_info) %} {% 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 }} {{ fcbuttons }}
{{ fcpagination }} {{ fcpagination }}

View file

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