topical media & game development

talk show tell print

mashup-flickr-complete-visualizing-news-index.php / php



  <?php
    // include any required files
    require_once(dirname(__FILE__) . '/../lib/visualizing-news.php');
  ?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Beginning Flickr Mashups: Visualizing the News</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../css/visualizing-news.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <h1>Visualizing the News </h1>
    <?php
    // Initialise the feed URLs
    feedList = array(
      'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml' => 'BBC News',
      'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/technology/rss.xml' => 'BBC Technology News',
      'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/entertainment/rss.xml' => 'BBC Entertainment News',
      'http://rss.cnn.com/rss/cnn_topstories.rss' => 'CNN News',
      'http://rss.imdb.com/news/' => 'Internet Movie Database News',
    );
  
    // See if a feed has been chosen
    selectedFeed = _REQUEST['feed'];
  ?>
    <form name="form" id="form" method="post" action=<index.php>>
      <select name="feed">
  <?php
    feedUrls = array_keys(feedList);
    foreach (feedUrls as feedUrl)
    {
  ?>
        <option value="<?php echo feedUrl ?>" <?php echo (feedUrl == selectedFeed) 
  ? 'selected="selected"' : '' ?>><?php echo feedList[feedUrl]?></option>
  <?php
    }
  ?>  
      </select>
      <input type="submit" name="Submit" value="Go" />
    </form>
  
  <?php
    if (!empty(selectedFeed))
    {
      visualizer = new NewsVisualizer(selectedFeed);
      items = visualizer->getItems();
  ?>
  <div class="disclaimer">The images shown below were automatically chosen from 
  Flickr based on keywords found in the news feed. They do not bear any direct 
  relationship to the news feed or article and no such relationship should be assumed 
  or inferred.</div>
  <div class="news-feed">
    <h2 class="news-feed-title"><?php echo visualizer->getTitle() ?></h2>
    <p class="news-feed-description"><?php echo visualizer->getDescription() ?></p>
    <ul class="news-items">
  <?php
      foreach (items as item)
      {
  ?>
      <li class="news-item">
        <ul class="news-text">
          <li class="news-title"><a href="<?php echo item->getLink() ?>" 
  target="_blank"><?php echo item->getTitle() ?></a></li>
          <li class="news-description"><?php echo item->getDescription() ?></li>
          <li class="news-keywords">Keywords: <?php echo join(item->getKeywords(), 
  ", " ) ?></li>
        </ul>
        <ul class="news-images">
  <?php
         photos = item->getPhotos();
         foreach (photos as photo)
         {
  ?>
          <li><a href="<?php echo photo['link'] ?>" target="_blank"><img src="<?php 
  echo photo['url'] ?>" /></a></li>
  <?php
         }
  ?>
        </ul>
      </li>
  <?php
      }
  ?>
    </ul>
  </div>
  <?php
    }
  ?>
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.