This repository has been archived on 2024-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
satori-services/public/recent-forum-posts.php
2022-07-04 00:07:38 +00:00

43 lines
1.4 KiB
PHP

<?php
require_once '_flashii.php';
$startId = (int)filter_input(INPUT_GET, 'start', FILTER_SANITIZE_NUMBER_INT);
try {
$fetch = $db->prepare('
SELECT
p.`post_id`,
t.`topic_id`, t.`topic_title`,
f.`forum_id`, f.`forum_name`,
u.`user_id`, u.`username`,
COALESCE(u.`user_colour`, r.`role_colour`) AS `user_colour`,
(
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
ON u.`user_id` = p.`user_id`
LEFT JOIN `msz_roles` AS r
ON r.`role_id` = u.`display_role`
LEFT JOIN `msz_forum_topics` AS t
ON t.`topic_id` = p.`topic_id`
LEFT JOIN `msz_forum_categories` AS f
ON f.`forum_id` = p.`forum_id`
WHERE `post_id` > :post_id
AND `post_deleted` IS NULL
AND `post_created` > NOW() - INTERVAL 2 DAY
AND p.`forum_id` IN (2, 7, 24, 6, 5, 4, 16, 20, 8, 19, 10, 11, 13, 21, 15, 14, 27, 29, 28, 18, 23)
ORDER BY `post_id`
LIMIT 10
');
$fetch->bindValue('post_id', $startId);
if($fetch->execute())
echo json_encode($fetch->fetchAll(PDO::FETCH_ASSOC));
else
echo '[]';
} catch(PDOException $ex) {
http_response_code(500);
echo '{"error":104}';
}