<?php

    
// Get the RSS feed generated by Yahoo Pipes (The pipe takes in a single get variable 'q' and then performs are Flickr Photo Search for 24 photos related to the keywords passed to it.)

    
$data = @file_get_contents('http://pipes.yahoo.com/pipes/pipe.run?_id=vGzOJbe_3RGkHXO1BR50VA&_render=rss&q='.urlencode($_GET['q']));

    
// Create a new XML object from the Yahoo Pipes Feed, replace media: with media, to avoid syntax errors when pulling images.

    
if($data$xml = new simpleXMLElement(str_replace('media:''media'$data)); else $err 'Unable to Retrieve Flickr Photo Feed';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title><?=$_GET['q']?> - Flickr Feed</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="style_box.css" type="text/css" />
</head>
<body>
    <div id="wrapper">
        <h1><?=$_GET['q']?> - Flickr Feed</h1>
        <?
            
if($data) {
                
// For each of the <item>'s within the RSS feed, echo out some XHTML containing some of the child values of that item.
                
                
foreach($xml->channel->item as $item) {
                    echo 
'
                    <a href="'
.$item->link.'" target="_blank">
                        <img src="'
.$item->mediagroup->mediathumbnail->attributes()->url.'" class="flickr_img" alt="'.$item->title.'" />
                    </a>'
;
                }
            } else {
                echo 
$err;
            }
        
?>
    </div>
</body>
</html>