geocoder.services.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Implements hook_services_resources().
  4. */
  5. function geocoder_services_resources() {
  6. return array(
  7. 'geocoder' => array(
  8. 'retrieve' => array(
  9. 'help' => 'Geocode data',
  10. 'file' => array('type' => 'inc', 'module' => 'geocoder', 'name' => 'geocoder.services'),
  11. 'callback' => 'geocoder_services_geocode',
  12. 'access callback' => 'geocoder_services_access',
  13. 'access arguments append' => TRUE,
  14. 'args' => array(
  15. array(
  16. 'name' => 'handler',
  17. 'type' => 'string',
  18. 'description' => 'The geocoder handler to use - google, gpx, kml etc.',
  19. 'source' => array('path' => '0'),
  20. 'optional' => FALSE,
  21. ),
  22. array(
  23. 'name' => 'data',
  24. 'type' => 'string',
  25. 'description' => 'Value to geocode',
  26. 'source' => array('param' => 'data'),
  27. 'optional' => FALSE,
  28. ),
  29. array(
  30. 'name' => 'output',
  31. 'type' => 'string',
  32. 'description' => 'Output Format (GPX, WKT, etc.)',
  33. 'source' => array('param' => 'output'),
  34. 'optional' => TRUE,
  35. ),
  36. ),
  37. ),
  38. 'index' => array(
  39. 'help' => 'List Geocoder Capabilities',
  40. 'file' => array('type' => 'inc', 'module' => 'geocoder', 'name' => 'geocoder.services'),
  41. 'callback' => 'geocoder_services_capabilities',
  42. 'access callback' => 'geocoder_services_capabilities_ac', // Always returns TRUE
  43. ),
  44. ),
  45. );
  46. }
  47. function geocoder_services_capabilities_ac() {
  48. return TRUE;
  49. }
  50. function geocoder_services_access($handler, $data, $output) {
  51. if ($handler == 'default') {
  52. $handler == 'json';
  53. }
  54. return geocoder_service_check_perms($handler);
  55. }
  56. /**
  57. * Callback for geocoding service
  58. *
  59. * @param string $handler
  60. * @param string $data
  61. * @return object
  62. */
  63. function geocoder_services_geocode($handler, $data, $format = 'default') {
  64. geophp_load();
  65. geocoder_service_check_request($handler, $format);
  66. $geom = geocoder($handler, $data);
  67. if (!$format || $format == 'default') {
  68. $result = $geom->out('json');
  69. return json_decode($result);
  70. }
  71. else {
  72. return $geom->out($format);
  73. }
  74. }
  75. function geocoder_services_capabilities() {
  76. geophp_load();
  77. $handlers = array();
  78. foreach (geocoder_handler_info() as $hid => $handler) {
  79. $handlers[$hid] = $handler['title'] . ' - ' . $handler['description'];
  80. }
  81. $object = new stdClass();
  82. $object->handlers = $handlers;
  83. $object->output = geoPHP::getAdapterMap();
  84. return $object;
  85. }