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

56 lines
1.9 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` > ?
AND `post_deleted` IS NULL
AND `post_created` > NOW() - INTERVAL 7 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)
ORDER BY `post_id`
LIMIT 6
');
$fetch->addParameter(1, $startId);
$fetch->execute();
$result = $fetch->getResult();
$sets = [];
while($result->next())
$sets[] = [
'post_id' => $result->getInteger(0),
'topic_id' => $result->getInteger(1),
'topic_title' => $result->getString(2),
'forum_id' => $result->getInteger(3),
'forum_name' => $result->getString(4),
'user_id' => $result->getInteger(5),
'username' => $result->getString(6),
'user_colour' => $result->getInteger(7),
'is_opening_post' => $result->getInteger(8),
];
echo json_encode($sets);
} catch(Exception $ex) {
echo '{"error":104}';
}