Getting News on Frogans

Great news, a news Frogans site.

Here’s a Frogans site designed to give you access to the latest news from the BBC in seven categories (Top Stories, World, Business, Politics, Health, Family & Education, Science & Environment, Technology, Arts & Entertainment).

The idea here is that it makes it easy to go through the latest news without it being distracting.

On the left is a set of buttons, each one with an icon representing a news category. When you roll over a button, the name of the category shows up at the top of the slide, just in case. On the right there are numbered buttons to go to summaries of articles in the current category, starting with the most recent.

And of course, on the bottom right there is a button that will take you to the full article on the BBC’s website.

The content source is comes from the BBC’s RSS feeds, which you can find here:

https://www.bbc.com/news/10628494

As each RSS feed is in XML format, it can be parsed in PHP using PHP’s built-in DOM parser. For example, For example, let’s create an array containing a set of RSS feed URLs:

<?php
 $categories=array(
     array("http://feeds.bbci.co.uk/news/rss.xml", "Top Stories"),
     array("http://feeds.bbci.co.uk/news/world/rss.xml", "World"),
     array("http://feeds.bbci.co.uk/news/business/rss.xml", "Business" ),
     array("http://feeds.bbci.co.uk/news/politics/rss.xml","Politics"),
     array("http://feeds.bbci.co.uk/news/health/rss.xml","Health"),
     array("http://feeds.bbci.co.uk/news/education/rss.xml","Family & Education"),
     array("http://feeds.bbci.co.uk/news/science_and_environment/rss.xml","Science & Environment"),
     array("http://feeds.bbci.co.uk/news/technology/rss.xml","Technology"),
     array("http://feeds.bbci.co.uk/news/entertainment_and_arts/rss.xml","Arts & Entertainment")
     ); 
?>

Now let’s use PHP’s built-in DOM parser to load and parse one of these XML files:

$rss = new DOMDocument();
$my_feed=$categories[$cat][0]; // where $cat is the index of one of the XML files
$rss->load($my_feed);
$feed = array();
foreach ($rss->getElementsByTagName('item') as $key => $node) {
    $item = array ( 
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
);
    array_push($feed, $item);
}

Now we have an array $feed containing the title, description, URL link and publication date for each article contained in the XML file. So, for example, to insert a title into a <text> element in FSDL:

$my_title = $feed[$i]['title']; // where $i is the index of the article in $feed
<restext resid='article_t_r' fontref='title_fnt' size='300,100' orientation='h-ttb-ltr' talign='begin' >
    <text ><?php echo $my_title; ?></text>
</restext>

To check this out, all you will need is Frogans Player for Developers alpha for Mac OSX, Windows or Linux. Right-click on the Frogans puck-thing to open a Frogans site and enter “frogans*lab.” Under “Gallery” you’ll see “BBC News Feed” and you’re there.

Be the first to comment

Leave a Reply

Your email address will not be published.


*