flux rss final 0.3
This commit is contained in:
parent
f46a1c7e4b
commit
e678bcf5aa
@ -70,6 +70,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
// Explicitly exclude position from update to prevent jumping to bottom
|
// Explicitly exclude position from update to prevent jumping to bottom
|
||||||
$stmt = db()->prepare("UPDATE channels SET name = ?, type = ?, status = ?, allow_file_sharing = ?, message_limit = ?, icon = ?, category_id = ?, rules_role_id = ? WHERE id = ?");
|
$stmt = db()->prepare("UPDATE channels SET name = ?, type = ?, status = ?, allow_file_sharing = ?, message_limit = ?, icon = ?, category_id = ?, rules_role_id = ? WHERE id = ?");
|
||||||
$stmt->execute([$name, $type, $status, $allow_file_sharing, $message_limit, $icon, $category_id, $rules_role_id, $channel_id]);
|
$stmt->execute([$name, $type, $status, $allow_file_sharing, $message_limit, $icon, $category_id, $rules_role_id, $channel_id]);
|
||||||
|
|
||||||
|
if ($message_limit !== null) {
|
||||||
|
require_once 'db/config.php';
|
||||||
|
enforceChannelLimit($channel_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
header('Location: index.php?server_id=' . $server_id . '&channel_id=' . $channel_id);
|
header('Location: index.php?server_id=' . $server_id . '&channel_id=' . $channel_id);
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
@ -232,26 +232,7 @@ try {
|
|||||||
$last_id = db()->lastInsertId();
|
$last_id = db()->lastInsertId();
|
||||||
|
|
||||||
// Enforce message limit if set
|
// Enforce message limit if set
|
||||||
$stmt = db()->prepare("SELECT message_limit FROM channels WHERE id = ?");
|
enforceChannelLimit($channel_id);
|
||||||
$stmt->execute([$channel_id]);
|
|
||||||
$channel = $stmt->fetch();
|
|
||||||
if ($channel && !empty($channel['message_limit'])) {
|
|
||||||
$limit = (int)$channel['message_limit'];
|
|
||||||
// Delete oldest messages that exceed the limit
|
|
||||||
$stmt = db()->prepare("
|
|
||||||
DELETE FROM messages
|
|
||||||
WHERE channel_id = ?
|
|
||||||
AND id NOT IN (
|
|
||||||
SELECT id FROM (
|
|
||||||
SELECT id FROM messages
|
|
||||||
WHERE channel_id = ?
|
|
||||||
ORDER BY created_at DESC, id DESC
|
|
||||||
LIMIT " . $limit . "
|
|
||||||
) as tmp
|
|
||||||
)
|
|
||||||
");
|
|
||||||
$stmt->execute([$channel_id, $channel_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get server_id for the channel
|
// Get server_id for the channel
|
||||||
$stmt = db()->prepare("SELECT server_id FROM channels WHERE id = ?");
|
$stmt = db()->prepare("SELECT server_id FROM channels WHERE id = ?");
|
||||||
|
|||||||
@ -78,7 +78,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$items = $xml->entry;
|
$items = $xml->entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$feed_items = [];
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
$feed_items[] = $item;
|
||||||
|
}
|
||||||
|
$feed_items = array_reverse($feed_items);
|
||||||
|
|
||||||
|
foreach ($feed_items as $item) {
|
||||||
$guid = (string)($item->guid ?? ($item->id ?? $item->link));
|
$guid = (string)($item->guid ?? ($item->id ?? $item->link));
|
||||||
if (empty($guid) && isset($item->link['href'])) {
|
if (empty($guid) && isset($item->link['href'])) {
|
||||||
$guid = (string)$item->link['href'];
|
$guid = (string)$item->link['href'];
|
||||||
@ -159,6 +165,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
$stmt_msg = db()->prepare("INSERT INTO messages (channel_id, user_id, content, metadata, rss_guid) VALUES (?, ?, ?, ?, ?)");
|
$stmt_msg = db()->prepare("INSERT INTO messages (channel_id, user_id, content, metadata, rss_guid) VALUES (?, ?, ?, ?, ?)");
|
||||||
$stmt_msg->execute([$channel_id, $bot_id, $content, $metadata, $guid]);
|
$stmt_msg->execute([$channel_id, $bot_id, $content, $metadata, $guid]);
|
||||||
|
enforceChannelLimit($channel_id);
|
||||||
$new_items_count++;
|
$new_items_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_GET['token'])) {
|
|||||||
try {
|
try {
|
||||||
$stmt = db()->prepare("INSERT INTO messages (channel_id, user_id, content) VALUES (?, ?, ?)");
|
$stmt = db()->prepare("INSERT INTO messages (channel_id, user_id, content) VALUES (?, ?, ?)");
|
||||||
$stmt->execute([$webhook['channel_id'], 1, $content]); // 1 is system/bot user
|
$stmt->execute([$webhook['channel_id'], 1, $content]); // 1 is system/bot user
|
||||||
|
enforceChannelLimit($webhook['channel_id']);
|
||||||
echo json_encode(['success' => true]);
|
echo json_encode(['success' => true]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
|
|||||||
@ -15,3 +15,26 @@ function db() {
|
|||||||
}
|
}
|
||||||
return $pdo;
|
return $pdo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enforceChannelLimit($channel_id) {
|
||||||
|
$stmt = db()->prepare("SELECT message_limit FROM channels WHERE id = ?");
|
||||||
|
$stmt->execute([$channel_id]);
|
||||||
|
$channel = $stmt->fetch();
|
||||||
|
if ($channel && !empty($channel['message_limit'])) {
|
||||||
|
$limit = (int)$channel['message_limit'];
|
||||||
|
// Delete oldest messages that exceed the limit
|
||||||
|
$stmt = db()->prepare("
|
||||||
|
DELETE FROM messages
|
||||||
|
WHERE channel_id = ?
|
||||||
|
AND id NOT IN (
|
||||||
|
SELECT id FROM (
|
||||||
|
SELECT id FROM messages
|
||||||
|
WHERE channel_id = ?
|
||||||
|
ORDER BY created_at DESC, id DESC
|
||||||
|
LIMIT " . $limit . "
|
||||||
|
) as tmp
|
||||||
|
)
|
||||||
|
");
|
||||||
|
$stmt->execute([$channel_id, $channel_id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -405,3 +405,11 @@
|
|||||||
2026-02-16 23:39:53 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
2026-02-16 23:39:53 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
||||||
2026-02-16 23:40:18 - GET /index.php?server_id=1&channel_id=17 - POST: []
|
2026-02-16 23:40:18 - GET /index.php?server_id=1&channel_id=17 - POST: []
|
||||||
2026-02-16 23:40:19 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
2026-02-16 23:40:19 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
||||||
|
2026-02-16 23:44:06 - GET /?fl_project=38443 - POST: []
|
||||||
|
2026-02-16 23:45:42 - GET /?fl_project=38443 - POST: []
|
||||||
|
2026-02-16 23:45:45 - GET /index.php?server_id=1&channel_id=17 - POST: []
|
||||||
|
2026-02-16 23:45:46 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
||||||
|
2026-02-16 23:46:19 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
||||||
|
2026-02-16 23:46:41 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
||||||
|
2026-02-16 23:47:02 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
||||||
|
2026-02-16 23:48:40 - GET /index.php?server_id=1&channel_id=12 - POST: []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user