prepare("INSERT INTO feeds (site_name, rss_url, group_id) VALUES (?, ?, ?)");
$stmt->execute([$_POST['site_name'], $_POST['rss_url'], $_POST['group_id']]);
header("Location: index.php");
exit;
}
// 2. Add Group
if (isset($_POST['add_group'])) {
$stmt = $pdo->prepare("INSERT INTO `groups` (name) VALUES (?)");
$stmt->execute([$_POST['group_name']]);
header("Location: index.php");
exit;
}
// 3. Delete Feed
if (isset($_POST['delete_feed'])) {
$stmt = $pdo->prepare("DELETE FROM feeds WHERE id = ?");
$stmt->execute([$_POST['feed_id_to_delete']]);
header("Location: index.php");
exit;
}
// 4. Edit Feed
if (isset($_POST['edit_feed'])) {
$stmt = $pdo->prepare("UPDATE feeds SET site_name = ?, rss_url = ?, group_id = ? WHERE id = ?");
$stmt->execute([
$_POST['edit_site_name'],
$_POST['edit_rss_url'],
$_POST['edit_group_id'],
$_POST['edit_feed_id']
]);
header("Location: index.php");
exit;
}
// 5. Mark as Read (Updated with Undo Memory)
if (isset($_GET['mark_read'])) {
$id = $_GET['mark_read'];
// Update DB
$stmt = $pdo->prepare("UPDATE items SET is_read = 1, is_saved = 0 WHERE id = ?");
$stmt->execute([$id]);
// SAVE ID TO SESSION FOR UNDO
$_SESSION['undo_entry_id'] = $id;
// Redirect logic (Same as before)
$params = [];
if (isset($_GET['view'])) $params[] = "view=" . $_GET['view'];
if (isset($_GET['group_id'])) $params[] = "group_id=" . $_GET['group_id'];
$redirect = count($params) > 0 ? "?" . implode("&", $params) : "index.php";
header("Location: $redirect");
exit;
}
// 6. Save/Unsave Logic
if (isset($_GET['save_item'])) {
$stmt = $pdo->prepare("UPDATE items SET is_saved = 1 WHERE id = ?");
$stmt->execute([$_GET['save_item']]);
$params = [];
if (isset($_GET['view'])) $params[] = "view=" . $_GET['view'];
if (isset($_GET['group_id'])) $params[] = "group_id=" . $_GET['group_id'];
$redirect = count($params) > 0 ? "?" . implode("&", $params) : "index.php";
header("Location: $redirect");
exit;
}
if (isset($_GET['unsave_item'])) {
$stmt = $pdo->prepare("UPDATE items SET is_saved = 0 WHERE id = ?");
$stmt->execute([$_GET['unsave_item']]);
$params = [];
$params[] = "view=" . ($_GET['view'] ?? 'saved');
if (isset($_GET['group_id'])) $params[] = "group_id=" . $_GET['group_id'];
$redirect = "?" . implode("&", $params);
header("Location: $redirect");
exit;
}
// 7. NEW: Undo Handler
if (isset($_GET['undo_action'])) {
if (isset($_SESSION['undo_entry_id'])) {
// Revert the last item to Unread (is_read = 0)
$stmt = $pdo->prepare("UPDATE items SET is_read = 0 WHERE id = ?");
$stmt->execute([$_SESSION['undo_entry_id']]);
// Clear the session so the button disappears
unset($_SESSION['undo_entry_id']);
}
// Redirect logic to keep you on the same page
$params = [];
if (isset($_GET['view'])) $params[] = "view=" . $_GET['view'];
if (isset($_GET['group_id'])) $params[] = "group_id=" . $_GET['group_id'];
$redirect = count($params) > 0 ? "?" . implode("&", $params) : "index.php";
header("Location: $redirect");
exit;
}
// --- DATA FETCHING ---
$groups = $pdo->query("SELECT * FROM `groups`")->fetchAll();
// Fetch all feeds for the management modal
$all_feeds = $pdo->query("SELECT feeds.*, groups.name as group_name FROM feeds LEFT JOIN `groups` ON feeds.group_id = groups.id ORDER BY site_name ASC")->fetchAll();
$view_mode = $_GET['view'] ?? 'unread';
$filter_group_id = $_GET['group_id'] ?? null;
// Build SQL
$sql = "SELECT items.id AS item_id, items.title, items.link, items.description, items.pub_date, feeds.site_name
FROM items JOIN feeds ON items.feed_id = feeds.id ";
$params = [];
if ($view_mode === 'saved') {
$sql .= "WHERE is_saved = 1 ";
} else {
$sql .= "WHERE is_read = 0 AND is_saved = 0 ";
}
if ($filter_group_id) {
$sql .= "AND feeds.group_id = ? ";
$params[] = $filter_group_id;
}
$sql .= "ORDER BY pub_date DESC LIMIT 50";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$items = $stmt->fetchAll();
?>
RSS Catcher
(" . count($items) . ")";
if ($view_mode === 'saved') echo "⭐ Saved Articles" . $count_label;
elseif ($filter_group_id) echo "📂 Group View" . $count_label;
else echo "📥 Unread Articles" . $count_label;
?>
✅ Article marked as read.
↩ Undo
No articles found in this view.
= htmlspecialchars($item['site_name']) ?> | = date('M j, g:i a', strtotime($item['pub_date'])) ?>
= strip_tags(substr($item['description'], 0, 250)) ?>...
| Name |
Group |
Actions |
| = htmlspecialchars($f['site_name']) ?> |
= htmlspecialchars($f['group_name']) ?> |
|