| Server IP : 104.21.21.239 / Your IP : 216.73.216.68 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/banners/public_html/bway/oldfeeds/ |
Upload File : |
<?php
// Set the server's time zone (adjust 'America/New_York' to your server's time zone)
date_default_timezone_set('America/New_York');
// Function to clean XML content
function clean_xml_content($content) {
// Remove any characters before the XML declaration
$content = preg_replace('/^[^<]*<\?xml/', '<?xml', $content);
return $content;
}
// Function to sanitize input for SQL queries
function sanitize_for_sql($link, $input) {
// Remove characters that could be used in SQL injection
$input = str_replace(["'", "\"", "\\"], ["''", "", ""], $input);
return mysqli_real_escape_string($link, htmlspecialchars($input, ENT_QUOTES, 'UTF-8'));
}
// Set a timeout limit for the script execution
set_time_limit(5);
// Database connection
$linkdb = mysqli_connect('amazonaurora.cluster-ro-cemzxojvmybt.us-east-1.rds.amazonaws.com', 'admin', 'xxatN6Lb8Kbwb9MiU1At');
if (!$linkdb) {
die('Could not connect: ' . mysqli_connect_error());
}
mysqli_select_db($linkdb, 'amazonrds') or die('Could not select database');
// Set charset to ensure consistent encoding
mysqli_set_charset($linkdb, 'utf8mb4');
// Confirm `$link` is a valid MySQL connection
if (!($linkdb instanceof mysqli)) {
die('Database link is not a valid MySQL connection');
}
// Fetch feed URLs with specific conditions
$query = "SELECT DISTINCT feedurl FROM feedmasterfeeds WHERE 1 = 1";
if (isset($_GET['id'])) {
$query .= " AND id = " . intval($_GET['id']);
}
$query .= " AND userid NOT IN (103617, 223621, 245783) and id <> 429 and feedurl not like '%youtube%'"; // Exclude specific users
$query .= " ORDER BY RAND() LIMIT 0,1";
$getbw = mysqli_query($linkdb, $query);
if (!$getbw) {
die('Invalid query: ' . mysqli_error($linkdb));
}
// Loop through feed URLs
while ($row = mysqli_fetch_assoc($getbw)) {
$feedurl = $row['feedurl'];
echo $feedurl . "<br>";
try {
// Fetch RSS feed content
$rss_content = file_get_contents($feedurl);
if ($rss_content === FALSE) {
throw new Exception("Failed to fetch RSS feed from URL: " . $feedurl);
}
// Clean the XML content
$rss_content = clean_xml_content($rss_content);
// Parse XML feed
$rss = simplexml_load_string($rss_content);
if ($rss === FALSE) {
throw new Exception("Failed to parse RSS feed from URL: " . $feedurl);
}
// Search for 'item' nodes in RSS feed
$items = $rss->xpath("//*[local-name()='item']");
// Fetch feed information based on feed URL
$getid_query = "SELECT userid, id, feedname FROM feedmasterfeeds WHERE feedurl = '" . mysqli_real_escape_string($linkdb, $feedurl) . "'";
$getid = mysqli_query($linkdb, $getid_query);
if (!$getid) {
die('Invalid query: ' . mysqli_error($linkdb));
}
while ($id_row = mysqli_fetch_assoc($getid)) {
$userid = $id_row['userid'];
$feedid = $id_row['id'];
$feedname = $id_row['feedname'];
// Loop through feed items
foreach ($items as $i => $item) {
$title = (string)$item->title;
$description = isset($item->description) ? (string)$item->description : '';
$link = (string)$item->link;
// Debug: Output the raw title before cleaning
echo "Raw title: " . htmlspecialchars($title) . "<br>";
$chardecodeb = preg_replace('/[^\x20-\x7E]/', '', $title);
// Debug: Output the cleaned title
echo "Cleaned title: " . htmlspecialchars($chardecodeb) . "<br>";
// Check if the cleaned title is empty
if (empty($chardecodeb)) {
echo "Skipping item with empty title.<br>";
continue; // Skip processing this item
}
// Correct usage of mysqli_real_escape_string with custom sanitization
$clean_title = trim(preg_replace('/\s+/', ' ', $chardecodeb)); // Normalize spaces and trim title
$escaped_title = sanitize_for_sql($linkdb, $clean_title);
$checker_query = "SELECT COUNT(*) AS counter FROM amazonrds.feedmaster WHERE title = '$escaped_title' AND userid = " . intval($userid);
// Debug output for SQL query
echo "Executing query: " . $checker_query . "<br>";
$checker = mysqli_query($linkdb, $checker_query);
if (!$checker) {
echo 'Error checking existing items: ' . mysqli_error($linkdb) . "<br>";
continue;
}
$checker_result = mysqli_fetch_assoc($checker);
$conflict = 0;
if ($checker_result['counter'] == 0 && $conflict == 0) {
$newsumnew = preg_replace('/[^\x20-\x7E]/', '', $description);
if ($feedid != 345 || (strpos($link, 'Playbill') === false && strpos($link, 'broadwayworld') === false && $link != 'broadway.com' && strpos($title, 'Guiding Light') === false && strpos($title, 'General Hospital') === false && strpos($title, 'Bold and the Beautiful') === false)) {
// Insert new feed item
$linkdb = mysqli_connect('amazonaurora.cluster-cemzxojvmybt.us-east-1.rds.amazonaws.com', 'admin', 'xxatN6Lb8Kbwb9MiU1At');
$insert_query = "INSERT DELAYED INTO amazonrds.feedmaster (feedid, userid, processed, publisheddate, content, image, title, link, feedname) VALUES ($feedid, $userid, '0', '" . date("Y-m-d H:i:s") . "', '" . sanitize_for_sql($linkdb, $newsumnew) . "', '', '" . $escaped_title . "', '" . sanitize_for_sql($linkdb, $link) . "', '" . sanitize_for_sql($linkdb, $feedname) . "')";
if (!mysqli_query($linkdb, $insert_query)) {
echo "Error inserting data: " . mysqli_error($linkdb) . "<br>";
}
}
// Update feed master feeds
$update_query = "UPDATE LOW_PRIORITY amazonrds.feedmasterfeeds SET lastchecked = '" . date("Y-m-d H:i:s") . "', lastupdated = '" . date("Y-m-d H:i:s") . "' WHERE id = $feedid";
if (!mysqli_query($linkdb, $update_query)) {
echo "Error updating feedmasterfeeds: " . mysqli_error($linkdb) . "<br>";
}
}
}
// Final update for the current feed ID
$final_update_query = "UPDATE LOW_PRIORITY amazonrds.feedmasterfeeds SET lastchecked = '" . date("Y-m-d H:i:s") . "' WHERE id = $feedid";
if (!mysqli_query($linkdb, $final_update_query)) {
echo "Error in final update: " . mysqli_error($linkdb) . "<br>";
}
}
} catch (Exception $e) {
// Handle exceptions and errors
echo 'Error1: ' . $e->getMessage();
}
}
// Close database connection
if ($linkdb) {
mysqli_close($linkdb);
} else {
echo "Warning: \$linkdb is not a valid MySQL connection at the time of close.";
}
?>