10 defined(
'JPATH_PLATFORM') or die();
33 public function createNode($changeset, $latitude, $longitude, $tags)
35 $token = $this->oauth->getToken();
39 'oauth_token' => $token[
'key']
43 $base =
'node/create';
46 $path = $this->getOption(
'api.url') . $base;
53 foreach ($tags as $key => $value)
55 $tag_list .=
'<tag k="' . $key .
'" v="' . $value .
'"/>';
59 $xml =
'<?xml version="1.0" encoding="UTF-8"?>
60 <osm version="0.6" generator="JOpenstreetmap">
61 <node changeset="' . $changeset .
'" lat="' . $latitude .
'" lon="' . $longitude .
'">'
66 $header[
'Content-Type'] =
'text/xml';
69 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters, $xml, $header);
71 return $response->body;
85 public function createWay($changeset, $tags, $nds)
87 $token = $this->oauth->getToken();
91 'oauth_token' => $token[
'key']
98 $path = $this->getOption(
'api.url') . $base;
105 foreach ($tags as $key => $value)
107 $tag_list .=
'<tag k="' . $key .
'" v="' . $value .
'"/>';
115 foreach ($nds as $value)
117 $nd_list .=
'<nd ref="' . $value .
'"/>';
121 $xml =
'<?xml version="1.0" encoding="UTF-8"?>
122 <osm version="0.6" generator="JOpenstreetmap">
123 <way changeset="' . $changeset .
'">'
129 $header[
'Content-Type'] =
'text/xml';
132 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters, $xml, $header);
134 return $response->body;
149 public function createRelation($changeset, $tags, $members)
151 $token = $this->oauth->getToken();
155 'oauth_token' => $token[
'key']
159 $base =
'relation/create';
162 $path = $this->getOption(
'api.url') . $base;
169 foreach ($tags as $key => $value)
171 $tag_list .=
'<tag k="' . $key .
'" v="' . $value .
'"/>';
178 if (!empty($members))
180 foreach ($members as $member)
182 if ($member[
'type'] ==
"node")
184 $member_list .=
'<member type="' . $member[
'type'] .
'" role="' . $member[
'role'] .
'" ref="' . $member[
'ref'] .
'"/>';
186 elseif ($member[
'type'] ==
"way")
188 $member_list .=
'<member type="' . $member[
'type'] .
'" ref="' . $member[
'ref'] .
'"/>';
193 $xml =
'<?xml version="1.0" encoding="UTF-8"?>
194 <osm version="0.6" generator="JOpenstreetmap">
195 <relation relation="' . $changeset .
'" >'
201 $header[
'Content-Type'] =
'text/xml';
204 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters, $xml, $header);
206 return $response->body;
220 public function readElement($element, $id)
222 if ($element !=
'node' && $element !=
'way' && $element !=
'relation')
224 throw new DomainException(
"Element should be a node, a way or a relation");
228 $base = $element .
'/' . $id;
231 $path = $this->getOption(
'api.url') . $base;
234 $xml_string = $this->sendRequest($path);
236 return $xml_string->$element;
251 public function updateElement($element, $xml, $id)
253 if ($element !=
'node' && $element !=
'way' && $element !=
'relation')
255 throw new DomainException(
"Element should be a node, a way or a relation");
258 $token = $this->oauth->getToken();
262 'oauth_token' => $token[
'key']
266 $base = $element .
'/' . $id;
269 $path = $this->getOption(
'api.url') . $base;
271 $header[
'Content-Type'] =
'text/xml';
274 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters, $xml, $header);
276 return $response->body;
294 public function deleteElement($element, $id, $version, $changeset, $latitude = null, $longitude = null)
296 if ($element !=
'node' && $element !=
'way' && $element !=
'relation')
298 throw new DomainException(
"Element should be a node, a way or a relation");
301 $token = $this->oauth->getToken();
305 'oauth_token' => $token[
'key']
309 $base = $element .
'/' . $id;
312 $path = $this->getOption(
'api.url') . $base;
315 $xml =
'<?xml version="1.0" encoding="UTF-8"?>
316 <osm version="0.6" generator="JOpenstreetmap">
317 <' . $element .
' id="' . $id .
'" version="' . $version .
'" changeset="' . $changeset .
'"';
319 if (!empty($latitude) && !empty($longitude))
321 $xml .=
' lat="' . $latitude .
'" lon="' . $longitude .
'"';
326 $header[
'Content-Type'] =
'text/xml';
329 $response = $this->oauth->oauthRequest($path,
'DELETE', $parameters, $xml, $header);
331 return $response->body;
345 public function historyOfElement($element, $id)
347 if ($element !=
'node' && $element !=
'way' && $element !=
'relation')
349 throw new DomainException(
"Element should be a node, a way or a relation");
353 $base = $element .
'/' . $id .
'/history';
356 $path = $this->getOption(
'api.url') . $base;
359 $xml_string = $this->sendRequest($path);
361 return $xml_string->$element;
376 public function versionOfElement($element, $id ,$version)
378 if ($element !=
'node' && $element !=
'way' && $element !=
'relation')
380 throw new DomainException(
"Element should be a node, a way or a relation");
384 $base = $element .
'/' . $id .
'/' . $version;
387 $path = $this->getOption(
'api.url') . $base;
390 $xml_string = $this->sendRequest($path);
392 return $xml_string->$element;
406 public function multiFetchElements($element, $params)
408 if ($element !=
'nodes' && $element !=
'ways' && $element !=
'relations')
410 throw new DomainException(
"Element should be nodes, ways or relations");
414 $single_element = substr($element, 0, strlen($element) - 1);
417 $base = $element .
'?' . $element .
"=" . $params;
420 $path = $this->getOption(
'api.url') . $base;
423 $xml_string = $this->sendRequest($path);
425 return $xml_string->$single_element;
439 public function relationsForElement($element, $id)
441 if ($element !=
'node' && $element !=
'way' && $element !=
'relation')
443 throw new DomainException(
"Element should be a node, a way or a relation");
447 $base = $element .
'/' . $id .
'/relations';
450 $path = $this->getOption(
'api.url') . $base;
453 $xml_string = $this->sendRequest($path);
455 return $xml_string->$element;
467 public function waysForNode($id)
470 $base =
'node/' . $id .
'/ways';
473 $path = $this->getOption(
'api.url') . $base;
476 $xml_string = $this->sendRequest($path);
478 return $xml_string->way;
492 public function fullElement($element, $id)
494 if ($element !=
'way' && $element !=
'relation')
496 throw new DomainException(
"Element should be a way or a relation");
500 $base = $element .
'/' . $id .
'/full';
503 $path = $this->getOption(
'api.url') . $base;
506 $xml_string = $this->sendRequest($path);
508 return $xml_string->node;
524 public function redaction($element, $id, $version, $redaction_id)
526 if ($element !=
'node' && $element !=
'way' && $element !=
'relation')
528 throw new DomainException(
"Element should be a node, a way or a relation");
531 $token = $this->oauth->getToken();
535 'oauth_token' => $token[
'key']
539 $base = $element .
'/' . $id .
'/' . $version .
'/redact?redaction=' . $redaction_id;
542 $path = $this->getOption(
'api.url') . $base;
545 $response = $this->oauth->oauthRequest($path,
'PUT', $parameters);
547 $xml_string = simplexml_load_string($response->body);