View source
<?php
function gm3_filter_menu() {
return array(
'gm3_filter' => array(
'title' => 'Google Map filter helper',
'description' => 'Generate the code required to embed a Google Map within a webpage.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gm3_filter_helper_form',
),
'access callback' => 'gm3_filter_helper_form_access',
'file' => 'gm3_filter.form.inc',
),
);
}
function gm3_filter_library() {
return array(
'filter_helper' => array(
'title' => t('Filter helper code'),
'website' => '',
'version' => 1,
'js' => array(
array(
'data' => drupal_get_path('module', 'gm3_filter') . "/js/gm3_filter.js",
),
),
'dependencies' => array(
array(
'gm3',
'gm3',
),
array(
'gm3',
'gm3.point',
),
array(
'gm3',
'gm3.polygon',
),
array(
'gm3',
'gm3.polyline',
),
array(
'gm3',
'gm3.rectangle',
),
array(
'gm3_region',
'region',
),
array(
'gm3_field',
'field_point',
),
array(
'gm3_field',
'field_polygon',
),
array(
'gm3_field',
'field_polyline',
),
array(
'gm3_field',
'field_rectangle',
),
array(
'gm3_region',
'region',
),
),
),
);
}
function gm3_filter_helper_form_access() {
global $user;
return TRUE;
}
function gm3_filter_filter_info() {
return array(
'gm3_filter_google_map' => array(
'title' => 'Google Map',
'description' => 'Embed a Google Map into any formatted text on your site',
'process callback' => 'gm3_filter_google_map_process',
'cache' => FALSE,
'tips callback' => 'gm3_filter_google_map_tips',
'weight' => 0,
),
);
}
function gm3_filter_google_map_process($text, $filter, $format, $langcode, $cache, $cache_id) {
preg_match_all('|\\[google_map\\]([^\\[]*)\\[/google_map\\]|i', $text, $matches);
foreach ($matches[0] as $key => $match_text) {
if ($map = json_decode(trim($matches[1][$key]), TRUE)) {
$text = str_replace($match_text, theme('gm3_map', array(
'map' => $map,
)), $text);
}
else {
$text = str_replace($match_text, '<p class="error">' . t('The google map you have provided is invalid.') . '</p>', $text);
}
}
return $text;
}