function getLocation($self = false)
{
    if ($self) {
        $ip = $_SERVER['REMOTE_ADDR'];
    } else {
        $ip = $_GET['ip'];
    }
    $key = '7fc7e88c3b4c0e83127bce07a721043839574567756c1a0b85a4518ce1fa8fbf';
    $yql_base_url = "http://query.yahooapis.com/v1/public/yql";
    $yql_query = "select * from ip.location where ip='{$ip}' and key='{$key}'";
    $yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query) . "&format=json&env=store://datatables.org/alltableswithkeys";
    $locResult = getResultFromYQL($yql_query_url);
    $markup = 'Failed to convert IP to Location, please try again';
    if (isset($locResult['query']) && isset($locResult['query']['results']) && !empty($locResult['query']['results']['Response'])) {
        $resp = $locResult['query']['results']['Response'];
        $markup = '';
        if ($self) {
            $markup .= "<h2>Your IP Address = {$_SERVER['REMOTE_ADDR']}</h2>";
        } else {
            $markup .= "<h2>Entered IP Address = {$_GET['ip']}</h2>";
        }
        $markup .= '<table id="resultarea" border="1" cellpadding="20" align="center">';
        foreach ($resp as $key => $value) {
            if (empty($value)) {
                $value = "-";
            }
            $markup .= <<<MARKUP
<tr><td>{$key}</td><td>{$value}</td></tr>
MARKUP;
        }
        $markup .= '</table>';
    }
    if ($self) {
        return $markup;
    } else {
        echo $markup;
    }
}
Example #2
0
function find($location, $query)
{
    $yelpql = "use 'http://github.com/spullara/yql-tables/raw/master/yelp/yelp.review.search.xml' as yelp; select * from yelp where term='" . $query . "' and location='" . $location . "' and ywsid='AMP_5mIt_VCZiw7xYK0DJw'";
    $result = getResultFromYQL($yelpql);
    return $result->query->results;
}
function weather($woeid)
{
    $yql = 'select * from weather.forecast where woeid=' . $woeid;
    $result = getResultFromYQL($yql);
    return $result->query->results;
}
Example #4
0
function news()
{
    $yelpql = 'select title from rss where url="http://rss.news.yahoo.com/rss/topstories" LIMIT 10';
    $result = getResultFromYQL($yelpql);
    return $result->query->results;
}
Example #5
0
<body>
<h1>Movie Search</h1>
<form action="" method="get">
<?php 
echo 'Search for <input type="text" name="q" value="';
if (empty($_GET['q'])) {
    $_GET['q'] = "";
}
// Echo the query in the search text field
$query = htmlentities($_GET['q'], ENT_QUOTES, 'UTF-8');
echo $query . '" />   <input type="submit" value="Go" /></form>';
// If there is a query
if (!empty($_GET['q'])) {
    echo '<hr />';
    $url = 'select * from boss.search where q="The Artist"  and sites="imdb.com,movies.yahoo.com,indiatimes.com" and ck="dj0yJmk9YWF3ODdGNWZPYjg2JmQ9WVdrOWVsWlZNRk5KTldFbWNHbzlNVEEyTURFNU1qWXkmcz1jb25zdW1lcnNlY3JldCZ4PTUz" and secret="a3d93853ba3bad8a99a175e8ffa90a702cd08cfa"';
    $res = getResultFromYQL($url);
    foreach ($res->query->results->bossresponse->web->results->result as $item) {
        echo '<div class="result"><a href="' . $item->url . '">' . $item->title->content . '</a><br/>' . $item->abstract->content . '<br><font color="green">' . $item->dispurl->content . '</font></div>';
    }
}
/**
 * Function to get results from YQL
 *
 * @param String $yql_query - The YQL Query
 * @param String $env - Environment in which the YQL Query should be executed. (Optional)
 *
 * @return object response
 */
function getResultFromYQL($yql_query)
{
    $yql_base_url = "http://query.yahooapis.com/v1/public/yql";
Example #6
0
function stock($symbol)
{
    $yelpql = "\n\tUSE 'http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml' AS yahoo.finance.quotes;select * from yahoo.finance.quotes where symbol in ('{$symbol}')";
    $result = getResultFromYQL($yelpql);
    return $result->query->results;
}
Example #7
0
function getResultFromYQL($yql_query)
{
    $session = curl_init($yql_query);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    $json = curl_exec($session);
    curl_close($session);
    return json_decode($json, true);
}
if (!empty($_GET['ip'])) {
    $ip = $_GET['ip'];
    $key = '7fc7e88c3b4c0e83127bce07a721043839574567756c1a0b85a4518ce1fa8fbf';
    $yql_base_url = "http://query.yahooapis.com/v1/public/yql";
    $yql_query = "select * from ip.location where ip='{$ip}' and key='{$key}'";
    $yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query) . "&format=json&env=store://datatables.org/alltableswithkeys";
    echo "<pre>";
    var_dump(getResultFromYQL($yql_query_url));
    echo "</pre>";
} else {
    $html = <<<MARKUP
<html>
<head><title>IP Locator</title></head>
<body>
    <form method="GET">
        <p>Enter IP Address: <input type="text" id="ip" name="ip" /></p>
        <p><input type="submit" value="Submit" />
    </form>
</body>
</html>
MARKUP;
    echo $html;
}