Skip to content

Commit 1a04b5d

Browse files
committed
remaining commit form june 25
1 parent 5c3fe0f commit 1a04b5d

File tree

5 files changed

+79
-55
lines changed

5 files changed

+79
-55
lines changed

.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>OOP</name>
3+
<name>practise</name>
44
<comment></comment>
55
<projects>
66
</projects>

.settings/org.eclipse.php.core.prefs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#Fri Apr 27 10:16:43 NPT 2012
1+
#Mon Jun 25 15:49:55 NPT 2012
22
eclipse.preferences.version=1
3-
include_path=0;/OOP
3+
include_path=0;/practise

nbproject/private/private.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
index.file=index.php
2-
url=http://localhost/oop/
2+
url=http://localhost/practise/

nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<type>org.netbeans.modules.php.project</type>
44
<configuration>
55
<data xmlns="http://www.netbeans.org/ns/php-project/1">
6-
<name>oop</name>
6+
<name>practise</name>
77
</data>
88
</configuration>
99
</project>

yql_test.php

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,80 @@
1-
<h2>Using YQL to Access the Upcoming API</h2>
2-
<form name='upcoming_form'>
3-
Location: <input name='___location' id='___location' type='text' size='20'/><br/>
4-
Event: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name='event' id='event' type='text' size='20'/><br/>
5-
<p><button id='find_event'>Find Event</button></p>
1+
<form id="geosearch">
2+
<p><label for="query">Enter Location:</label>
3+
<input id="query" type="text"/></p>
4+
<p><input type="submit" value="Make Query"/></p>
65
</form>
6+
<div id="results"></div>
77

88
<script>
9-
// Attach event handler to button
10-
document.getElementById("find_event").addEventListener("click",find_event,false);
11-
// Get user input and submit form
12-
function find_event(){
13-
document.upcoming_form.event.value = document.getElementById('event').value || "music";
14-
document.upcoming_form.___location.value = document.getElementById('___location').value || "San Francisco";
15-
document.upcoming_form.submit();
16-
}
17-
</script>
18-
<?php
19-
$BASE_URL = "https://query.yahooapis.com/v1/public/yql";
9+
/*
10+
This example shows how to use YQL to
11+
make queries to the GEO Web service.
12+
The call to the YQL Web service uses
13+
2-legged OAuth and is made with OpenSocial
14+
functions.
15+
*/
16+
function makeQuery(e){
17+
e.preventDefault(); // do not send off form
18+
var container = document.getElementById('results');
19+
var ___location = document.getElementById('query').value || 'SFO';
20+
var content = '';
2021
21-
if(isset($_GET['event']) && isset($_GET['___location'])){
22-
$___location = $_GET['___location'];
23-
$query = $_GET['event'];
24-
$events="";
25-
26-
// Form YQL query and build URI to YQL Web service
27-
$yql_query = "select * from upcoming.events where ___location='$___location' and search_text='$query'";
28-
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
22+
var BASE_URI = 'http://query.yahooapis.com/v1/yql';
2923
30-
// Make call with cURL
31-
$session = curl_init($yql_query_url);
32-
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
33-
$json = curl_exec($session);
34-
// Convert JSON to PHP object
35-
$phpObj = json_decode($json);
36-
37-
// Confirm that results were returned before parsing
38-
if(!is_null($phpObj->query->results)){
39-
// Parse results and extract data to display
40-
foreach($phpObj->query->results->event as $event){
41-
$events .= "<div><h2>" . $event->name . "</h2><p>";
42-
$events .= html_entity_decode(wordwrap($event->description, 80, "<br/>"));
43-
$events .="</p><br/>$event->venue_name<br/>$event->venue_address<br/>";
44-
$events .="$event->venue_city, $event->venue_state_name";
45-
$events .="<p><a href=$event->ticket_url>Buy Tickets</a></p></div>";
46-
}
47-
}
48-
// No results were returned
49-
if(emptyempty($events)){
50-
$events = "Sorry, no events matching $query in $___location";
24+
// function calling the opensocial makerequest method
25+
function runQuery(query, handler) {
26+
gadgets.io.makeRequest(BASE_URI, handler, {
27+
METHOD: 'POST',
28+
POST_DATA: toQueryString({q: query, format: 'json'}),
29+
CONTENT_TYPE: 'JSON',
30+
AUTHORIZATION: 'OAuth'
31+
});
32+
};
33+
34+
// Tool function to create a request string
35+
function toQueryString(obj) {
36+
var parts = [];
37+
for(var each in obj) if (obj.hasOwnProperty(each)) {
38+
parts.push(encodeURIComponent(each) + '=' +
39+
encodeURIComponent(obj[each]));
5140
}
52-
// Display results and unset the global array $_GET
53-
echo $events;
54-
unset($_GET);
55-
}
56-
?>
41+
return parts.join('&');
42+
};
43+
44+
// Run YQL query to GeoPlanet API and extract data from response
45+
runQuery('select * from geo.places where text="' + ___location + '"',
46+
function(rsp) {
47+
if(rsp.data){
48+
var place = rsp.data.query.results.place;
49+
if(place[0]){
50+
placeplace = place[0];
51+
}
52+
var name = place.name || 'Unknown';
53+
var country = place.country.content || place[0].country.content ||
54+
'Unknown';
55+
var latitude = place.centroid.latitude || 'Unknown';
56+
var longitude = place.centroid.longitude || 'Unknown';
57+
var city = place.locality1.content || 'Unknown';
58+
var state = place.admin1.content || 'Unknown';
59+
var county = place.admin2.content || 'Unknown';
60+
var zip = place.postal ? place.postal.content : 'Unknown';
61+
62+
content = '<ul><li><strong>Place Name: </strong>' + name + '</li>'+
63+
'<li><strong>City/Town: </strong>' + city + '</li>' +
64+
'<li><strong>County/District: </strong>' + county + '</li>' +
65+
'<li><strong>State/Province: </strong>' + state + '</li>' +
66+
'<li><strong>Zipcode: </strong>' + zip + '</li>' +
67+
'<li><strong>Country: </strong>' + country + '</li>' +
68+
'<li><strong>Latitude: </strong>' + latitude + '</li>' +
69+
'<li><strong>Longitude: </strong>' + longitude + '</li></ul>';
70+
container.innerHTML = content;
71+
}
72+
else {
73+
container.innerHTML = gadgets.json.stringify(rsp);
74+
}
75+
});
76+
}
77+
// Create an event handler for submitting the form
78+
var form = document.getElementById('geosearch');
79+
form.addEventListener('submit',makeQuery,false);
80+
</script>

0 commit comments

Comments
 (0)