-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.oregon.php
244 lines (206 loc) · 9.18 KB
/
class.oregon.php
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?PHP
class cOregonXML
{
var $sXMLHeader = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mdsml PUBLIC "-//emacsian/MDSML 10.0" "http://web.emacsian.com/MetInfo/mdsml-10.0.dtd">';
var $sXMLRoot = 'mdsml';
/****************************************************
*
* Convert simple PHP Array to XML
*
****************************************************/
function doConvertDataToXML($inArrayData)
{
$tBuffer = '';
foreach($inArrayData AS $inArrayName => $inArrayEntry)
{
// Just Skip Empty Array Entry (Probably we should kill loop here)
if (!isset($inArrayEntry['name']) || empty($inArrayEntry['name']))
continue;
$tEntryKey = '<'.$inArrayEntry['name'];
if (isset($inArrayEntry['attributes']) && !empty($inArrayEntry['attributes']) && is_array($inArrayEntry['attributes']))
foreach($inArrayEntry['attributes'] AS $tAttrName => $tAttrValue)
$tEntryKey .= ' '.$tAttrName.'="'.$tAttrValue.'"';
$tEntryKey .= '>';
// Key Value
if (isset($inArrayEntry['value']) && !empty($inArrayEntry['value']))
{
if (is_array($inArrayEntry['value']))
{
$tEntryKey .= $this->doConvertDataToXML($inArrayEntry['value']);
} else
{
$tEntryKey .= $inArrayEntry['value'];
}
}
//
$tEntryKey .= '</'.$inArrayEntry['name'].'>';
$tBuffer .= $tEntryKey;
}
return $tBuffer;
}
function doConvertToXML($inSourceData)
{
$tBuffer = $this->sXMLHeader.'<'.$this->sXMLRoot.'>';
$tBuffer .= $this->doConvertDataToXML($inSourceData);
$tBuffer .= '</'.$this->sXMLRoot.'>';
return $tBuffer;
}
/****************************************************
*
* Generate Weather OS Error Message
*
****************************************************/
function getErrorXML($inMessage = 'no data')
{
$tReturn = Array();
$tErrorEntry = Array();
$tErrorEntry['name'] = 'error';
$tErrorEntry['value'] = $inMessage;
$tErrorEntry['attributes']['xml:lang'] = 'en';
$tReturn[] = $tErrorEntry;
return $this->doConvertToXML($tReturn);
}
/****************************************************
*
* Generate Client Software Information Message
*
* No dynamic generation is available here.
* This method is implemented to be compatible with Weather OS
* But returned value should be treated more of a 'dummy' value.
*
****************************************************/
function getClientInfoXML()
{
global $config;
if ($config['cache']['enable'])
{
// Retrive data from cache (if possible)
}
$tClientEntry = Array();
$tClientEntry['name'] = 'clientsw';
$tClientEntry['value'] = 'Weather OS client software (Windows) version 1.1.57';
$tClientEntry['attributes']['force'] = 0;
$tClientEntry['attributes']['href'] = 'http://www2.os-weather.com/download/OSWeather_1.1.msi';
$tClientEntry['attributes']['version'] = '1.1.57';
$tClientArray = Array();
$tClientArray[] = $tClientEntry;
return $this->doConvertToXML($tClientArray);
}
/****************************************************
*
*
*
****************************************************/
function getRegionXML($inRegionArray)
{
$tReturn = Array();
foreach($inRegionArray AS $inRegionKey => $inRegionValue)
{
$tRegionEntry = Array();
$tRegionEntry['name'] = 'region';
$tRegionEntry['value'] = $inRegionValue;
$tRegionEntry['attributes']['code'] = $inRegionKey;
$tRegionEntry['attributes']['xml:lang'] = 'en';
$tReturn[] = $tRegionEntry;
}
return $this->doConvertToXML($tReturn);
}
/****************************************************
*
*
*
****************************************************/
function getCountryAreaXML($inCountryArray)
{
$tReturn = Array();
foreach($inCountryArray AS $inCountryKey => $inCountryName)
{
$tCountryEntry = Array();
$tCountryEntry['name'] = 'countryarea';
$tCountryEntry['value'] = $inCountryName;
$tCountryEntry['attributes']['code'] = $inCountryKey;
$tCountryEntry['attributes']['xml:lang'] = 'en';
$tReturn[] = $tCountryEntry;
}
return $this->doConvertToXML($tReturn);
}
/****************************************************
*
*
*
****************************************************/
function getStationsXML($inStationArray)
{
$tReturn = Array();
foreach($inStationArray AS $inStationKey => $inStationName)
{
$tCountryEntry = Array();
$tCountryEntry['name'] = 'station';
$tCountryEntry['value'] = $inStationName;
$tCountryEntry['attributes']['code'] = $inStationKey;
$tCountryEntry['attributes']['xml:lang'] = 'en';
$tReturn[] = $tCountryEntry;
}
return $this->doConvertToXML($tReturn);
}
/****************************************************
*
*
*
****************************************************/
function getForecastXML($inForecastData)
{
$tReturn = Array();
foreach($inForecastData AS $inForecastKey => $inForecastEntry)
{
if (empty($inForecastEntry))
continue;
$tForecastEntry = Array();
$tForecastEntry['name'] = 'wxfcst';
$tForecastEntry['attributes']['station'] = $inForecastKey;
$tForecastEntry['attributes']['latitude'] = $inForecastEntry['position']['latitude'];
$tForecastEntry['attributes']['longitude'] = $inForecastEntry['position']['longitude'];
$tIconTest = 0;
foreach($inForecastEntry['forecast'] AS $inDayForecastKey => $inDayForecastEntry)
{
$tDayForecastEntry = Array();
$tDayForecastEntry['name'] = 'forecast';
$tDayForecastEntry['value'] = Array
(
Array('name' => 'maxtemp', 'value' => $inDayForecastEntry['temperature']['maximal']),
Array('name' => 'mintemp', 'value' => $inDayForecastEntry['temperature']['minimal']),
Array('name' => 'icon', 'value' => ++$tIconTest)
);
$tDayForecastEntry['attributes']['day'] = $inDayForecastKey;
$tForecastEntry['value'][] = $tDayForecastEntry;
}
//$tReturn[] = $tForecastEntry;
//TODO: Change to correct Localtime!!
$tTimeLocal = Array();
$tTimeLocal['name'] = 'localtime';
$tTimeLocal['value'] = $inForecastEntry['general']['time']['value'];
$tTimeLocal['attributes']['utcoffset'] = $inForecastEntry['general']['time']['utcoffset'];
$tTimeLocal['attributes']['stdoffset'] = '0';
$tTimeEntry = Array();
$tTimeEntry['name'] = 'time';
$tTimeEntry['value'][] = $tTimeLocal;
$tForecastEntry['value'][] = $tTimeEntry;
//$tReturn[] = $tTimeEntry;
$tReturn[] = $tForecastEntry;
}
//TODO: Change to correct UTC Time!
$tUTCDateTime = new DateTime('now');
$tUTCDateTime->setTimezone(new DateTimeZone('UTC'));
$tTimeUTC = Array();
$tTimeUTC['name'] = 'utc';
$tTimeUTC['value'] = $tUTCDateTime->format('Y-m-d H:i:s').' UTC';
$tTimeUTC['attributes']['utcoffset'] = '0';
$tTimeUTC['attributes']['stdoffset'] = '0';
$tTimeEntry = Array();
$tTimeEntry['name'] = 'time';
$tTimeEntry['value'][] = $tTimeUTC;
$tReturn[] = $tTimeEntry;
return $this->doConvertToXML($tReturn);
}
}
?>