Usage example

Ben Garvey
2003-02-10
2003-11-20
  • Ben Garvey

    Ben Garvey - 2003-02-10

    I'm using magpieRSS on my site:  http://www.bengarvey.com (look for the "elswhere" block)

    Here's a code example for doing multiple feeds together:

    require_once 'includes/rss_fetch.inc';

    // Set how often we want to update the feed (in hours)
    $updateTime = 2;

    // Open newsfeed page
    $filename = "rssFeed.html";

    // Check the current time
    $rawNowTime = time();

    // Check the last time we modified the newsfeed page
    $rawModifiedTime = filemtime($filename);

    // Has it been long enough since we last updated it?
    if ( (($rawNowTime - $rawModifiedTime) / 60 / 60) > $updateTime)
    {   
        // Open the newsfeed file now so no one else grabs it while you're populating it
        $fp = fopen($filename, "w");   

        // Set the number of headlines per site
        $total = 3;

        // Initialize our sites
        $url[0] = 'http://boingboing.net/rss.xml';
        $url[1] = 'http://www.phoenixtrap.com/~mjg/content/current.xml';
        $url[3] = 'http://www.bengarvey.com/pn_714/html/backend.php';

        // Fetch the XML for each one
        $count = 0;
        foreach($url as $thisURL)
        {    $rss[$count] = fetch_rss($thisURL);
            $count++;
        }

        // This is the variable we'll use to write to the file
        $string = "";

        // Print out the data for each one
        foreach ($rss as $thisRSS)
        {    // Display the site's name
            $string .= "From " . $thisRSS->channel['title'] . ":<br>\n";

            // Limit to $total entries
            $items = array_slice($thisRSS->items, 0, $total);   
           
            foreach ($items as $item ) {
                $title = $item[title];
                $linkURL = $item[link];
                $date = $item[pubDate];
                $description = $item[description];

                // If we have no title, use the first 20 characters of the description
                if ($title == "")
                {    $title = substr(strip_tags($description), 0, 20) . "...";
                }

                // If we have no link, use the site's link
                if ($linkURL == "")
                {    $linkURL = $thisRSS->channel['link'];
                }

                // Add this headline to our variable
                $string .= "- <a href=$linkURL>$title</a>$date<br>\n";
            }

            $string .= "\n<br>";
        }

        // Write the data to the file
        $write = fputs($fp, $string);
        fclose($fp);
    }

    // Show the RSS!
    readfile($filename);

     
    • Franz Skaaning

      Franz Skaaning - 2003-11-20

      I am a user of Postnuke myself. Could you please axplain this a bit more. I woul dlike to combine more feeds, but cant seem to get it right.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks