Fixed post lookup.
This commit is contained in:
parent
78a3fa9c07
commit
a67c3d67ff
4 changed files with 28 additions and 23 deletions
|
@ -5,10 +5,10 @@ $postId = (int)($_GET['p'] ?? 0);
|
|||
$topicId = (int)($_GET['t'] ?? 0);
|
||||
|
||||
if ($topicId < 1 && $postId > 0) {
|
||||
$postInfo = forum_post_find($postId);
|
||||
$postInfo = forum_post_find($postId, user_session_current('user_id', 0));
|
||||
|
||||
if (!empty($postInfo['target_topic_id'])) {
|
||||
$topicId = (int)$postInfo['target_topic_id'];
|
||||
if (!empty($postInfo['topic_id'])) {
|
||||
$topicId = (int)$postInfo['topic_id'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ if (isset($postInfo['preceeding_post_count'])) {
|
|||
$postsPage = floor($postInfo['preceeding_post_count'] / $topicPagination['range']) + 1;
|
||||
}
|
||||
|
||||
$postsOffset = pagination_offset($topicPagination, $postsPage ?? pagination_param());
|
||||
$postsOffset = pagination_offset($topicPagination, $postsPage ?? pagination_param('page'));
|
||||
|
||||
if (!pagination_is_valid_offset($postsOffset)) {
|
||||
echo render_error(404);
|
||||
|
|
|
@ -51,25 +51,30 @@ function forum_post_update(
|
|||
return $updatePost->execute();
|
||||
}
|
||||
|
||||
function forum_post_find(int $postId): array
|
||||
function forum_post_find(int $postId, int $userId): array
|
||||
{
|
||||
$getPostInfo = db_prepare('
|
||||
SELECT
|
||||
:post_id as `target_post_id`,
|
||||
(
|
||||
SELECT `topic_id`
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `post_id` = `target_post_id`
|
||||
) as `target_topic_id`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = `target_topic_id`
|
||||
AND `post_id` < `target_post_id`
|
||||
ORDER BY `post_id`
|
||||
) as `preceeding_post_count`
|
||||
');
|
||||
$getPostInfo = db_prepare(sprintf(
|
||||
'
|
||||
SELECT
|
||||
p.`post_id`, p.`topic_id`,
|
||||
((%s) & %d) as `can_view_deleted`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = p.`topic_id`
|
||||
AND `post_id` < p.`post_id`
|
||||
AND (`can_view_deleted` OR `post_deleted` IS NULL)
|
||||
ORDER BY `post_id`
|
||||
) as `preceeding_post_count`
|
||||
FROM `msz_forum_posts` AS p
|
||||
WHERE p.`post_id` = :post_id
|
||||
',
|
||||
forum_perms_get_user_sql(MSZ_FORUM_PERMS_GENERAL, 'p.`forum_id`'),
|
||||
MSZ_FORUM_PERM_DELETE_TOPIC | MSZ_FORUM_PERM_DELETE_ANY_POST
|
||||
));
|
||||
$getPostInfo->bindValue('post_id', $postId);
|
||||
$getPostInfo->bindValue('perm_user_id_user', $userId);
|
||||
$getPostInfo->bindValue('perm_user_id_role', $userId);
|
||||
|
||||
return $getPostInfo->execute() ? $getPostInfo->fetch(PDO::FETCH_ASSOC) : [];
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
{% macro forum_topic_tools(info, pagination_info, can_reply) %}
|
||||
{% from 'macros.twig' import pagination %}
|
||||
|
||||
{% set pag = pagination(pagination_info, '/forum/topic.php', null, {'t': info.topic_id}) %}
|
||||
{% set pag = pagination(pagination_info, '/forum/topic.php', null, {'t': info.topic_id}, 'page') %}
|
||||
|
||||
{% if can_reply or pag|trim|length > 0 %}
|
||||
<div class="container forum__actions">
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
{% set title = topic_info.topic_title %}
|
||||
{% set canonical_url = url_construct('/forum/topic.php', {
|
||||
't': topic_info.topic_id,
|
||||
'p': topic_pagination.page > 1 ? topic_pagination.page : 0,
|
||||
'page': topic_pagination.page > 1 ? topic_pagination.page : 0,
|
||||
}) %}
|
||||
|
||||
{% set topic_tools = forum_topic_tools(topic_info, topic_pagination, can_reply) %}
|
||||
|
|
Loading…
Reference in a new issue