1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die();
11
12 13 14 15 16 17
18 class JOpenstreetmapChangesets extends JOpenstreetmapObject
19 {
20 21 22 23 24 25 26 27 28
29 public function createChangeset($changesets=array())
30 {
31 $token = $this->oauth->getToken();
32
33
34 $parameters = array(
35 'oauth_token' => $token['key'],
36 'oauth_token_secret' => $token['secret'],
37 );
38
39
40 $base = 'changeset/create';
41
42
43 $path = $this->getOption('api.url') . $base;
44
45 $xml = '<?xml version="1.0" encoding="UTF-8"?>
46 <osm version="0.6" generator="JOpenstreetmap">';
47
48 if (!empty($changesets))
49 {
50
51 foreach ($changesets as $tags)
52 {
53 $xml .= '<changeset>';
54
55 if (!empty($tags))
56 {
57
58 foreach ($tags as $key => $value)
59 {
60 $xml .= '<tag k="' . $key . '" v="' . $value . '"/>';
61 }
62 }
63
64 $xml .= '</changeset>';
65 }
66 }
67
68 $xml .= '</osm>';
69
70 $header['Content-Type'] = 'text/xml';
71
72
73 $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
74
75 return $response->body;
76 }
77
78 79 80 81 82 83 84 85 86
87 public function readChangeset($id)
88 {
89
90 $base = 'changeset/' . $id;
91
92
93 $path = $this->getOption('api.url') . $base;
94
95
96 $xml_string = $this->sendRequest($path);
97
98 return $xml_string->changeset;
99 }
100
101 102 103 104 105 106 107 108 109 110
111 public function updateChangeset($id, $tags = array())
112 {
113 $token = $this->oauth->getToken();
114
115
116 $parameters = array(
117 'oauth_token' => $token['key'],
118 );
119
120
121 $base = 'changeset/' . $id;
122
123
124 $path = $this->getOption('api.url') . $base;
125
126
127 $tag_list = '';
128
129 if (!empty($tags))
130 {
131 foreach ($tags as $key => $value)
132 {
133 $tag_list .= '<tag k="' . $key . '" v="' . $value . '"/>';
134 }
135 }
136
137 $xml = '<?xml version="1.0" encoding="UTF-8"?>
138 <osm version="0.6" generator="JOpenstreetmap">
139 <changeset>'
140 . $tag_list .
141 '</changeset>
142 </osm>';
143
144 $header['Content-Type'] = 'text/xml';
145
146
147 $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
148
149 $xml_string = simplexml_load_string($response->body);
150
151 return $xml_string->changeset;
152 }
153
154 155 156 157 158 159 160 161 162
163 public function closeChangeset($id)
164 {
165 $token = $this->oauth->getToken();
166
167
168 $parameters = array(
169 'oauth_token' => $token['key'],
170 );
171
172
173 $base = 'changeset/' . $id . '/close';
174
175
176 $path = $this->getOption('api.url') . $base;
177
178 $header['format'] = 'text/xml';
179
180
181 $this->oauth->oauthRequest($path, 'PUT', $parameters, $header);
182 }
183
184 185 186 187 188 189 190 191 192
193 public function downloadChangeset($id)
194 {
195
196 $base = 'changeset/' . $id . '/download';
197
198
199 $path = $this->getOption('api.url') . $base;
200
201
202 $xml_string = $this->sendRequest($path);
203
204 return $xml_string->create;
205 }
206
207 208 209 210 211 212 213 214 215 216
217 public function expandBBoxChangeset($id, $nodes)
218 {
219 $token = $this->oauth->getToken();
220
221
222 $parameters = array(
223 'oauth_token' => $token['key'],
224 );
225
226
227 $base = 'changeset/' . $id . '/expand_bbox';
228
229
230 $path = $this->getOption('api.url') . $base;
231
232
233 $node_list = '';
234
235 if (!empty($nodes))
236 {
237 foreach ($nodes as $node)
238 {
239 $node_list .= '<node lat="' . $node[0] . '" lon="' . $node[1] . '"/>';
240 }
241 }
242
243 $xml = '<?xml version="1.0" encoding="UTF-8"?>
244 <osm version="0.6" generator="JOpenstreetmap">
245 <changeset>'
246 . $node_list .
247 '</changeset>
248 </osm>';
249
250 $header['Content-Type'] = 'text/xml';
251
252
253 $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
254
255 $xml_string = simplexml_load_string($response->body);
256
257 return $xml_string->changeset;
258 }
259
260 261 262 263 264 265 266 267 268
269 public function queryChangeset($param)
270 {
271
272 $base = 'changesets/' . $param;
273
274
275 $path = $this->getOption('api.url') . $base;
276
277
278 $xml_string = $this->sendRequest($path);
279
280 return $xml_string->osm;
281 }
282
283 284 285 286 287 288 289 290 291 292
293 public function diffUploadChangeset($xml, $id)
294 {
295 $token = $this->oauth->getToken();
296
297
298 $parameters = array(
299 'oauth_token' => $token['key'],
300 );
301
302
303 $base = 'changeset/' . $id . '/upload';
304
305
306 $path = $this->getOption('api.url') . $base;
307
308 $header['Content-Type'] = 'text/xml';
309
310
311 $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
312
313 $xml_string = simplexml_load_string($response->body);
314
315 return $xml_string->diffResult;
316 }
317 }
318