Source Code: mediasearch
<?
//phpFlickr
require_once("phpFlickr/phpFlickr.php");
$username = "[USERNAME]";
$apiKey = "[APIKEY]";
$apiSecret ="[APISECRET]";
$authToken = '[AUTHTOKEN]'; //optional
// Create new phpFlickr object
$f = new phpFlickr($apiKey, $apiSecret);
$f->setToken($authToken);
$f->enableCache("db","mysql://USERNAME:PASSWORD@SERVER/DBNAME");
//or
$f->enableCache("fs","cache");
// Find the NSID of the username inputted via the form
$nsid = $f->people_findByUsername($username);
$keyword = '';
$youtubeResults;
$flickrResults;
$yahooResults;
if($_GET['txtsearch'] ) {
$keyword =$_GET['txtsearch'];
$youtubeResults = SearchYoutube($keyword);
$flickrResults = SearchFlickr($f,$keyword);
$yahooResults =SearchYahoo($keyword);
}
function RESTRequest($base,$params){
$url = $base.'?'.http_build_query($params);
$c = curl_init($url);
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($c);
curl_close($c);
$xml = simplexml_load_string($response);
return $xml;
}
function SearchYoutube($keyword){
//http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=Ylrp-FT51zPE&user=gotfoo
$devid = "[APIKEY]";
$base ="http://www.youtube.com/api2_rest";
$params = array("method"=>"youtube.videos.list_by_tag","dev_id"=>$devid, "tag"=>$keyword,"per_page"=>"20");
$xml = RESTRequest($base,$params);
// Load up the root element attributes
$html .= "<h2>YouTube Search: ".$keyword."</h2>";
$videos = $xml->video_list;
foreach($videos->video as $video) {
$html .= "<p>\n";
$html .= "<a href='".$video->url."' title='".$video->title."'>".$video->title."</a>";
$html .= "<br>";
$html .= $video->description;
$html .= "<br>";
$html .= "<a href='".$video->url."' title='".$video->title."'><img src='".$video->thumbnail_url."'></a>";
$html .= "<br>";
$html .= "</p>\n";
}
return $html;
}
//Yahoo! Search Using REST
function SearchYahoo($keyword) {
//http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=madonna&results=2
$appid = '[APIKEY]';
$base = "http://search.yahooapis.com/VideoSearchService/V1/videoSearch";
$params = array("appid"=>$appid, "query"=>$keyword,"results"=>"20");
$xml = RESTRequest($base,$params);
// Load up the root element attributes
$html .= "<h2>Yahoo! Search: ".$keyword."</h2>";
foreach($xml->Result as $result) {
$html .= "<p>\n";
$html .= "<a href='".$result->ClickUrl."' title='".$result->DisplayUrl."'>".$result->Title."</a>";
$html .= "<br>";
$html .= $result->Summary;
$html .= "<br>";
$html .= "<a href='".$result->ClickUrl."' title='".$result->DisplayUrl."'><img src='".$result->Thumbnail->Url."' border='0'></a>";
// $html .= "<br>";
$html .= "</p>\n";
}
return $html;
}
//Flickr Search using phpFlickr
function SearchFlickr($f,$keyword){
$tags = "\"".$keyword."\"";
$args = $args = array("tags"=>$keyword, "tag_mode"=>"all","per_page"=>"20");
$photos = $f->photos_search($args);
$html .="<div class='small box'>";
$html .="<h2>Flickr: ".$keyword."</h2>";
if( count($photos['photo']) == 0) {
$html .= "<h3 class='error'>Sorry, No Photos match ".$heading."</h3>";
} else {
$html .= "<p id='photos' style='align:center;' >";
foreach ($photos['photo'] as $photo) {
$html .= "<a href='".$f->buildPhotoURL($photo, "original")."' title='".$photo['title']."' >";
$html .= "<img border='0' alt='$photo[title]' "."src='".$f->buildPhotoURL($photo, "Square")."' id='photo_".$photo['id']."'></a>";
$html .= "<br><a href='http://flickr.com/photos/".$photo['owner']."'>Photo Page</a> <br>";
}
$html .="</p>";
}
$html .="</div>";
return $html;
}
?>
<div id="content">
<h2>Search for Information, Videos and Photos via Yahoo!, YouTube and Flickr.</h2>
<form action="mediasearch.php?page=mashup" method="get">
<p><input type="textbox" id="txtsearch" name="txtsearch" size="40" value="<?php echo $keyword; ?>"> <input type="submit" value="Search">
</p>
</form>
<div id='youtubeResults' class='splitcontentright'>
<?php
echo $youtubeResults;
?>
</div>
<div id='yahooResult' class='splitcontentleft'>
<?php
echo $yahooResults;
?>
</div>
</div>
<div id="subcontent" >
<div id='flickrResult'>
<?php
echo $flickrResults;
?>
</div>
</div>





