Wordpress template code to search movies from rottentomatoes api

Wordpress sample template used to search movies in rottentomatoes. This template is deisgned based on rottentomatoes search api. Please signup for api key before using this template.
<?php /** * @package WordPress * @subpackage Default_Theme */ /* Template Name: movie-search Author:http://forum.indiacitys.com */ ?> <?php get_header();?> <div id="content" class="widecolumn"> <div class="post"> <div class="singlepost entry"> <b><u>Search your favourite Movies</u></b><hr style="height:2px;border-width:0;color:gray;background-color:gray" /> <br> <form action="http://www.xxxxxxxxxxx/moviesrchlens.php" method="post"> Search term : <input type="text" name="srchkeyinput" /><br><br> <input type="submit" name="moviesrch" value="Submit Form" /> </form> <?php $searchkey = 'The thing'; $apikey = '<---your api key here--->'; $searchkey = urlencode($searchkey); if(isset($_POST['moviesrch'])) { $searchkey = urlencode($_POST["srchkeyinput"]); } $movierequesturl = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey='.$apikey.'&q='.$searchkey; // setup curl to make a call to the endpoint $session = curl_init($movierequesturl); // indicates that we want the response back curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // exec curl and get the data back $data = curl_exec($session); // remember to close the curl session once we are finished retrieveing the data curl_close($session); // decode the json data to make it easier to parse the php $search_results = json_decode($data); if ($search_results === NULL) die('Error parsing json'); // play with the data! $movies = $search_results->movies; echo "<hr style='height:2px;border-width:0;color:gray;background-color:gray' />"; echo "Search results for your query='<b>".$searchkey."</b>'<hr style='height:2px;border-width:0;color:gray;background-color:gray' />"; foreach ($movies as $movie) { echo '<a href="'.$movie->links->alternate.'"><b>'.$movie->title.' ('.$movie->year.')</b></a>'; echo '<br>'; echo '<b>MPAA RATING</b>:'.$movie->mpaa_rating; echo '<br>'; echo '<b>RUN TIME:</b>'.$movie->runtime; echo '<br>'; echo '<b>Critics:</b>'.$movie->critics_consensus; echo '<br>'; echo '<b>Theater release</b>:'.$movie->release_dates->theater; echo '<br>'; echo '<b>DVD</b>:'.$movie->release_dates->dvd; echo '<br>'; echo '<b>Synopsis</b>:'.$movie->synopsis; echo '<br>'; echo '<b>Critics rating</b>:'.$movie->ratings->critics_rating; echo '<br>'; echo '<b>Audience rating</b>:'.$movie->ratings->audience_rating; echo '<br>'; echo '<b>Critics score</b>:'.$movie->ratings->critics_score; echo '<br>'; echo '<b>Audience score</b>:'.$movie->ratings->audience_score; echo '<br>'; echo '<b>cast:</b> <br>'; $mcast = $movie->abridged_cast; foreach ($mcast as $castarray) { echo $castarray->name."<br>"; } echo "<table border='1'>"; echo '<tr><td> <a href="'.$movie->posters->thumbnail.'"> <img src="'.$movie->posters->thumbnail.'"/></a> </td>'; echo '<td><a href="'.$movie->posters->profile.'"> <img src="'.$movie->posters->profile.'"/></a> </td></tr></table>'; echo "<hr style='height:2px;border-width:0;color:gray;background-color:gray' />"; }?> </div> <!--content--> </div> <!--post--> </div> <!--single post--> <?php get_footer(); ?>
Sign In or Register to comment.