You are here

function gm3_filter_google_map_process in Google Maps API V3 7

Callbacks as defined in hook_filter_info.

1 string reference to 'gm3_filter_google_map_process'
gm3_filter_filter_info in gm3_filter/gm3_filter.module
Implementation of hook_filter_info().

File

gm3_filter/gm3_filter.module, line 121

Code

function gm3_filter_google_map_process($text, $filter, $format, $langcode, $cache, $cache_id) {

  // Search for [google_map]...[/google_map]
  preg_match_all('|\\[google_map\\]([^\\[]*)\\[/google_map\\]|i', $text, $matches);
  foreach ($matches[0] as $key => $match_text) {

    // Decode middle!
    if ($map = json_decode(trim($matches[1][$key]), TRUE)) {
      $text = str_replace($match_text, theme('gm3_map', array(
        'map' => $map,
      )), $text);
    }
    else {

      // Failed to decode the JSON, give an error message instead.
      $text = str_replace($match_text, '<p class="error">' . t('The google map you have provided is invalid.') . '</p>', $text);
    }
  }
  return $text;
}