Added small topic pagination to topic listing.
This commit is contained in:
parent
019110a4aa
commit
2857f45f1a
10 changed files with 115 additions and 41 deletions
|
@ -202,4 +202,39 @@
|
|||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&__pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: .9em;
|
||||
line-height: 1.2em;
|
||||
|
||||
@media (max-width: @site-mobile-width) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&__title {
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
&__separator {
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
&__item {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
pointer-events: initial;
|
||||
margin: 0 1px;
|
||||
padding: 2px 4px;
|
||||
border-radius: 2px;
|
||||
transition: background-color .2s, box-shadow .2s;
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
background-color: fade(#000, 40%);
|
||||
box-shadow: 0 1px 4px #111;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ require_once 'src/csrf.php';
|
|||
require_once 'src/db.php';
|
||||
require_once 'src/general.php';
|
||||
require_once 'src/git.php';
|
||||
require_once 'src/integer.php';
|
||||
require_once 'src/mail.php';
|
||||
require_once 'src/manage.php';
|
||||
require_once 'src/news.php';
|
||||
|
|
|
@ -9,20 +9,21 @@ if ($forumId === 0) {
|
|||
}
|
||||
|
||||
$forum = forum_fetch($forumId);
|
||||
$forumUserId = user_session_current('user_id', 0);
|
||||
|
||||
if (empty($forum) || ($forum['forum_type'] == MSZ_FORUM_TYPE_LINK && empty($forum['forum_link']))) {
|
||||
echo render_error(404);
|
||||
return;
|
||||
}
|
||||
|
||||
$perms = forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $forum['forum_id'], user_session_current('user_id', 0));
|
||||
$perms = forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $forum['forum_id'], $forumUserId);
|
||||
|
||||
if (!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) {
|
||||
echo render_error(403);
|
||||
return;
|
||||
}
|
||||
|
||||
if (user_warning_check_restriction(user_session_current('user_id', 0))) {
|
||||
if (user_warning_check_restriction($forumUserId)) {
|
||||
$perms &= ~MSZ_FORUM_PERM_SET_WRITE;
|
||||
}
|
||||
|
||||
|
@ -46,7 +47,7 @@ $forumMayHaveTopics = forum_may_have_topics($forum['forum_type']);
|
|||
$topics = $forumMayHaveTopics
|
||||
? forum_topic_listing(
|
||||
$forum['forum_id'],
|
||||
user_session_current('user_id', 0),
|
||||
$forumUserId,
|
||||
$topicsOffset,
|
||||
$forumPagination['range'],
|
||||
perms_check($perms, MSZ_FORUM_PERM_DELETE_TOPIC | MSZ_FORUM_PERM_DELETE_ANY_POST)
|
||||
|
@ -56,11 +57,11 @@ $topics = $forumMayHaveTopics
|
|||
$forumMayHaveChildren = forum_may_have_children($forum['forum_type']);
|
||||
|
||||
if ($forumMayHaveChildren) {
|
||||
$forum['forum_subforums'] = forum_get_children($forum['forum_id'], user_session_current('user_id', 0));
|
||||
$forum['forum_subforums'] = forum_get_children($forum['forum_id'], $forumUserId, MSZ_FORUM_POSTS_PER_PAGE);
|
||||
|
||||
foreach ($forum['forum_subforums'] as $skey => $subforum) {
|
||||
$forum['forum_subforums'][$skey]['forum_subforums']
|
||||
= forum_get_children($subforum['forum_id'], user_session_current('user_id', 0), true);
|
||||
= forum_get_children($subforum['forum_id'], $forumUserId, MSZ_FORUM_POSTS_PER_PAGE, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ if (!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) {
|
|||
return;
|
||||
}
|
||||
|
||||
$topicPagination = pagination_create($topic['topic_post_count'], 10);
|
||||
$topicPagination = pagination_create($topic['topic_post_count'], MSZ_FORUM_POSTS_PER_PAGE);
|
||||
|
||||
if (isset($postInfo['preceeding_post_count'])) {
|
||||
$postsPage = floor($postInfo['preceeding_post_count'] / $topicPagination['range']) + 1;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
define('MSZ_FORUM_POSTS_PER_PAGE', 10);
|
||||
|
||||
function forum_post_create(
|
||||
int $topicId,
|
||||
int $forumId,
|
||||
|
@ -127,27 +129,27 @@ function forum_post_listing(int $topicId, int $offset = 0, int $take = 0, bool $
|
|||
SELECT
|
||||
p.`post_id`, p.`post_text`, p.`post_created`, p.`post_parse`,
|
||||
p.`topic_id`, p.`post_deleted`, p.`post_edited`,
|
||||
INET6_NTOA(p.`post_ip`) as `post_ip`,
|
||||
u.`user_id` as `poster_id`,
|
||||
u.`username` as `poster_name`,
|
||||
u.`user_created` as `poster_joined`,
|
||||
u.`user_country` as `poster_country`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `poster_colour`,
|
||||
INET6_NTOA(p.`post_ip`) AS `post_ip`,
|
||||
u.`user_id` AS `poster_id`,
|
||||
u.`username` AS `poster_name`,
|
||||
u.`user_created` AS `poster_joined`,
|
||||
u.`user_country` AS `poster_country`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) AS `poster_colour`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `user_id` = p.`user_id`
|
||||
AND `post_deleted` IS NULL
|
||||
) as `poster_post_count`,
|
||||
) AS `poster_post_count`,
|
||||
(
|
||||
SELECT MIN(`post_id`) = p.`post_id`
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = p.`topic_id`
|
||||
) AS `is_opening_post`
|
||||
FROM `msz_forum_posts` as p
|
||||
LEFT JOIN `msz_users` as u
|
||||
FROM `msz_forum_posts` AS p
|
||||
LEFT JOIN `msz_users` AS u
|
||||
ON u.`user_id` = p.`user_id`
|
||||
LEFT JOIN `msz_roles` as r
|
||||
LEFT JOIN `msz_roles` AS r
|
||||
ON r.`role_id` = u.`display_role`
|
||||
WHERE `topic_id` = :topic_id
|
||||
%1$s
|
||||
|
|
|
@ -136,27 +136,33 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta
|
|||
$getTopics = db_prepare(sprintf(
|
||||
'
|
||||
SELECT
|
||||
:user_id as `target_user_id`,
|
||||
:user_id AS `target_user_id`,
|
||||
t.`topic_id`, t.`topic_title`, t.`topic_locked`, t.`topic_type`, t.`topic_created`,
|
||||
t.`topic_bumped`, t.`topic_deleted`,
|
||||
au.`user_id` as `author_id`, au.`username` as `author_name`,
|
||||
COALESCE(au.`user_colour`, ar.`role_colour`) 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(lu.`user_colour`, lr.`role_colour`) as `respondent_colour`,
|
||||
au.`user_id` AS `author_id`, au.`username` AS `author_name`,
|
||||
COALESCE(au.`user_colour`, ar.`role_colour`) 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(lu.`user_colour`, lr.`role_colour`) AS `respondent_colour`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = t.`topic_id`
|
||||
%5$s
|
||||
) as `topic_post_count`,
|
||||
) AS `topic_post_count`,
|
||||
(
|
||||
SELECT CEIL(COUNT(`post_id`) / %6$d)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = t.`topic_id`
|
||||
%5$s
|
||||
) AS `topic_pages`,
|
||||
(
|
||||
SELECT COUNT(`user_id`)
|
||||
FROM `msz_forum_topics_track`
|
||||
WHERE `topic_id` = t.`topic_id`
|
||||
) as `topic_view_count`,
|
||||
) AS `topic_view_count`,
|
||||
(
|
||||
SELECT
|
||||
`target_user_id` > 0
|
||||
|
@ -164,20 +170,20 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta
|
|||
t.`topic_bumped` > NOW() - INTERVAL 1 MONTH
|
||||
AND (
|
||||
SELECT COUNT(ti.`topic_id`) < 1
|
||||
FROM `msz_forum_topics_track` as tt
|
||||
RIGHT JOIN `msz_forum_topics` as ti
|
||||
FROM `msz_forum_topics_track` AS tt
|
||||
RIGHT JOIN `msz_forum_topics` AS ti
|
||||
ON ti.`topic_id` = tt.`topic_id`
|
||||
WHERE ti.`topic_id` = t.`topic_id`
|
||||
AND tt.`user_id` = `target_user_id`
|
||||
AND `track_last_read` >= `topic_bumped`
|
||||
)
|
||||
) as `topic_unread`
|
||||
FROM `msz_forum_topics` as t
|
||||
LEFT JOIN `msz_users` as au
|
||||
) AS `topic_unread`
|
||||
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
|
||||
LEFT JOIN `msz_roles` AS ar
|
||||
ON ar.`role_id` = au.`display_role`
|
||||
LEFT JOIN `msz_forum_posts` as lp
|
||||
LEFT JOIN `msz_forum_posts` AS lp
|
||||
ON lp.`post_id` = (
|
||||
SELECT `post_id`
|
||||
FROM `msz_forum_posts`
|
||||
|
@ -186,9 +192,9 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta
|
|||
ORDER BY `post_id` DESC
|
||||
LIMIT 1
|
||||
)
|
||||
LEFT JOIN `msz_users` as lu
|
||||
LEFT JOIN `msz_users` AS lu
|
||||
ON lu.`user_id` = lp.`user_id`
|
||||
LEFT JOIN `msz_roles` as lr
|
||||
LEFT JOIN `msz_roles` AS lr
|
||||
ON lr.`role_id` = lu.`display_role`
|
||||
WHERE (
|
||||
t.`forum_id` = :forum_id
|
||||
|
@ -202,7 +208,8 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta
|
|||
$hasPagination ? 'LIMIT :offset, :take' : '',
|
||||
MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT,
|
||||
implode(',', array_reverse(MSZ_TOPIC_TYPE_ORDER)),
|
||||
$showDeleted ? '' : 'AND `post_deleted` IS NULL'
|
||||
$showDeleted ? '' : 'AND `post_deleted` IS NULL',
|
||||
MSZ_FORUM_POSTS_PER_PAGE
|
||||
));
|
||||
$getTopics->bindValue('forum_id', $forumId);
|
||||
$getTopics->bindValue('user_id', $userId);
|
||||
|
|
|
@ -22,6 +22,7 @@ final class TwigMisuzu extends Twig_Extension
|
|||
new Twig_Filter('bg_settings', 'user_background_settings_strings'),
|
||||
new Twig_Filter('colour_contrast', 'colour_get_css_contrast'),
|
||||
new Twig_Filter('colour_props', 'colour_get_properties'),
|
||||
new Twig_Filter('clamp', 'clamp'),
|
||||
new Twig_Filter('log_format', function (string $text, string $json): string {
|
||||
return vsprintf($text, json_decode($json));
|
||||
}),
|
||||
|
|
5
src/integer.php
Normal file
5
src/integer.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
function clamp($num, int $min, int $max): int
|
||||
{
|
||||
return max($min, min($max, intval($num)));
|
||||
}
|
|
@ -284,6 +284,33 @@
|
|||
{% endif %}
|
||||
<time datetime="{{ topic.topic_created|date('c') }}" title="{{ topic.topic_created|date('r') }}">{{ topic.topic_created|time_diff }}</time>
|
||||
</div>
|
||||
|
||||
{% if topic.topic_pages|default(0) > 1 %}
|
||||
<div class="forum__topic__pagination">
|
||||
<div class="forum__topic__pagination__title">
|
||||
Page:
|
||||
</div>
|
||||
|
||||
{% for i in 1..topic.topic_pages|clamp(0, 3) %}
|
||||
<a href="/forum/topic.php?t={{ topic.topic_id }}{% if i > 1 %}&page={{ i }}{% endif %}" class="forum__topic__pagination__item">
|
||||
{{ i }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% if topic.topic_pages > 3 %}
|
||||
{% if topic.topic_pages > 6 %}
|
||||
<div class="forum__topic__pagination__separator">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for i in (topic.topic_pages - 2)|clamp(4, topic.topic_pages)..topic.topic_pages %}
|
||||
<a href="/forum/topic.php?t={{ topic.topic_id }}{% if i > 1 %}&page={{ i }}{% endif %}" class="forum__topic__pagination__item">
|
||||
{{ i }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="forum__topic__stats">
|
||||
|
|
|
@ -12,11 +12,6 @@ function set_cookie_m(string $name, string $value, int $expires): void
|
|||
);
|
||||
}
|
||||
|
||||
function clamp($num, int $min, int $max): int
|
||||
{
|
||||
return max($min, min($max, intval($num)));
|
||||
}
|
||||
|
||||
function password_entropy(string $password): int
|
||||
{
|
||||
return count(count_chars(utf8_decode($password), 1)) * 8;
|
||||
|
|
Loading…
Reference in a new issue