-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandleEvents.php
More file actions
111 lines (79 loc) · 2.3 KB
/
Copy pathhandleEvents.php
File metadata and controls
111 lines (79 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
function getXmlDataByUrl($url) {
$responseXmlData = file_get_contents($url);
if ($responseXmlData === FALSE) {
return FALSE;
}
$xmlData = simplexml_load_string($responseXmlData);
if ($xmlData === FALSE) {
return FALSE;
}
return $xmlData;
}
function getWoeidByNO($no_city) {
$urlPrefix = "http://where.yahooapis.com/v1/";
$urlAppID = ".3ulDM7V34G484oLjMN1KMN67JOstf47t3GK9_n9zCovJLlzkl7X5MSvFwFnRqHFKQ--";
$url = $urlPrefix;
$url .= "concordance/usps/{$no_city}?appid=";
$url .= $urlAppID;
$xmlData = getXmlDataByUrl($url);
if ($xmlData === FALSE) {
return FALSE;
}
$woeid = $xmlData->woeid;
return $woeid;
}
function getWoeidByName($name_city, $state) {
$state = str_replace('+', ' ', $state);
$urlPrefix = "http://where.yahooapis.com/v1/";
$urlAppID = ".3ulDM7V34G484oLjMN1KMN67JOstf47t3GK9_n9zCovJLlzkl7X5MSvFwFnRqHFKQ--";
$url = $urlPrefix;
$url .= "places\$and(.q('{$name_city}'),.type(7));start=0;count=10?appid=";
$url .= $urlAppID;
$xmlData = getXmlDataByUrl($url);
if ($xmlData === FALSE) {
return FALSE;
}
$woeid = FALSE;
foreach ($xmlData->place as $entry) {
$code = $entry->admin1->attributes()->code;
if (stristr($code, $state) != NULL) {
$woeid = $entry->woeid;
break;
}
$code = (string)$entry->country;
if (stristr($code, $state) != NULL) {
$woeid = $entry->woeid;
break;
}
}
return $woeid;
}
function handleEvent() {
$type = $_GET['type'];
$woeid = FALSE;
if ($type == 'zipcode') {
$no_city = $_GET['no_city'];
$woeid = getWoeidByNO($no_city);
} else {
$name_city = $_GET['name_city'];
$name_city = str_replace('_', '+', $name_city);
$state = $_GET['state'];
$state = str_replace('_', '+', $state);
$woeid = getWoeidByName($name_city, $state);
}
if ($woeid == FALSE) {
print_r('');
return;
}
$unit = $_GET['unit'];
$url = "http://weather.yahooapis.com/forecastrss?w=" . $woeid . "&u=" . $unit;
$xmlData = getXmlDataByUrl($url);
if ($xmlData == FALSE) {
print_r('');
return;
}
print_r($url);
}
handleEvent();
?>