json.inc 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Plugin to provide a google geocoder.
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t("GeoJSON"),
  13. 'description' => t('Get the geometry of a GeoJSON string, file, or URL'),
  14. 'callback' => 'geocoder_json',
  15. 'field_types' => array('text', 'text_long', 'file', 'computed'),
  16. 'field_callback' => 'geocoder_json_field',
  17. );
  18. /**
  19. * Process Markup
  20. */
  21. function geocoder_json($json_string, $options = array()) {
  22. geophp_load();
  23. return geoPHP::load($json_string, 'json');
  24. }
  25. function geocoder_json_field($field, $field_item) {
  26. if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
  27. return geocoder_json($field_item['value']);
  28. }
  29. if ($field['type'] == 'file') {
  30. if ($field_item['fid']) {
  31. $file = file_load($field_item['fid']);
  32. $json = file_get_contents($file->uri);
  33. return geocoder_json($json);
  34. }
  35. }
  36. }