Created
November 25, 2009 00:52
-
-
Save ydn/242381 to your computer and use it in GitHub Desktop.
YML, YQL, PHP, CSS, and HTML for YAP app search box referenced in YDN blog post: http://developer.yahoo.net/blog/archives/2009/11/yahoo_app_searchbox.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$search_term = $_GET['search_term']; | |
if($search_term){ | |
//http://developer.yahoo.com/yql/console/?q=select%20*%20from%20search.web%20where%20query%3D%22pizza%22 | |
$yql_search_url = "http://query.yahooapis.com/v1/public/yql?" | |
."q=select%20*%20from%20search.web%20where%20query%3D%22$search_term%22&" | |
."format=json&diagnostics=false&callback="; | |
$ch = curl_init($yql_search_url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$response = json_decode(curl_exec($ch)); | |
curl_close($ch); | |
} | |
?> | |
<? if($response->query->results->result): ?> | |
<ul id="results"> | |
<? foreach($response->query->results->result as $result): ?> | |
<li> | |
<a href="<?= $result->clickUrl ?>"><?= $result->title ?></a><br/> | |
<?= $result->abstract ?> | |
</li> | |
<? endforeach ?> | |
</ul> | |
<? else: ?> | |
<style> | |
#wrapper ul { | |
padding-left: 0px; | |
} | |
#wrapper ul li { | |
margin-bottom: 1ex; | |
} | |
</style> | |
<div id="wrapper"> | |
<yml:form replace="results"> | |
<input name="search_term"/> | |
<input type="submit" value="Search"/> | |
</yml:form> | |
<ul id="results"></ul> | |
</div> | |
<? endif ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment