OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
api
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
06/17/2025 10:17:24 AM
rwxrwxr-x
📄
articles.php
2.74 KB
05/19/2025 10:07:13 AM
rwxrwxrwx
📄
stream.php
1.33 KB
05/19/2025 10:07:13 AM
rw-r--r--
📄
test.json
5.78 KB
04/09/2025 12:49:46 PM
rw-r--r--
Editing: articles.php
Close
<?php require_once '../assets/php/db_config.php'; function fetch_articles($readerdb, $rss_id) { // Error handling if RSS ID is not provided if ($rss_id === null) { header('Content-Type: application/json'); echo json_encode(['error' => 'RSS ID not provided.']); exit; } // Prepare the SQL query to fetch articles from the database $stmt = $readerdb->prepare("SELECT rfa.id, rfu.rss_publisher, rfa.url, rfa.title, rfa.description, rfa.image AS articleImage, rfu.rss_image AS rssImage, rfa.date FROM rss_feeds_articles rfa INNER JOIN rss_feeds_url rfu ON rfa.feed_id = rfu.rss_id WHERE rfu.rss_id = ? ORDER BY rfa.date DESC limit 100"); $stmt->bind_param("i", $rss_id); $stmt->execute(); $result = $stmt->get_result(); // Initialize an array to store articles data $articles = []; // If there are articles in the database if ($result->num_rows > 0) { // Fetch data for each article while ($row = $result->fetch_assoc()) { $article = []; $article['id'] = stripslashes($row['id']); $article['title'] = htmlspecialchars(strip_tags(stripslashes($row['title']))); $article['description'] = htmlspecialchars(strip_tags(stripslashes($row['description']))); // Determine which image to use (article or RSS feed image) $image = is_null($row['articleImage']) || $row['articleImage'] === '' ? (is_null($row['rssImage']) || $row['rssImage'] === '' ? '' : $row['rssImage']) : $row['articleImage']; $article['image'] = $image; $article['url'] = $row['url']; // Push the article data to the array $articles[] = $article; } } // If no articles, send a message in the response if (empty($articles)) { $articles = ['message' => 'No news available at the moment.']; } // Return the articles as a JSON response header('Content-Type: application/json'); echo json_encode($articles); // Close the prepared statement $stmt->close(); $readerdb->close(); } ?> <?php // Example of how to call the function and pass the appropriate parameters // Assume that $readerdb is your database connection and $rss_id is provided via URL or request if (isset($_GET['rss_id'])) { $rss_id = $_GET['rss_id']; fetch_articles($readerdb, $rss_id); } else { // If rss_id is not provided, output an error header('Content-Type: application/json'); echo json_encode(['error' => 'RSS ID is missing.']); } ?>