json.inc 1010 B

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