123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- /**
- * @file
- * This file holds the main Drupal hook functions
- * and private functions for the openlayers_filters module.
- *
- * @ingroup openlayers
- */
- /**
- * Implements hook_help().
- */
- function openlayers_filters_help($path, $arg) {
- $output = '';
- switch ($path) {
- case 'admin/help#openlayers_filters':
- $output = '<p>'. t('The OpenLayers Filters module provides input filters
- to allow for inline maps.') .'</p>';
- return $output;
- }
- }
- /**
- * Implements hook_filter_info().
- */
- function openlayers_filters_filter_info() {
- $filters['openlayer'] = array(
- 'title' => t('OpenLayers Filters'),
- 'description' => t('Substitutes a macro text like !macro_example into an
- appropriate rendered OpenLayers map.',
- array(
- '!macro_example' => '[openlayers preset_name]',
- )),
- 'process callback' => '_openlayer_filter_process',
- 'tips callback' => '_openlayer_filter_tips',
- );
- return $filters;
- }
- /**
- * Maps filter process callback
- *
- * Scan text and replace [openlayer preset_name] with OpenLayer objects
- *
- */
- function _openlayer_filter_process($text, $filter) {
- $matches = array();
- preg_match_all('/\[(openlayers[^\]]*)\]/', $text, $matches);
- // Check for found
- if (is_array($matches[1]) && count($matches[1]) > 0) {
- foreach ($matches[1] as $i => $match) {
- $exploded = explode(' ', $match);
- if (count($exploded) > 1 && $preset = check_plain($exploded[1])) {
- $map = openlayers_preset_load($preset);
- }
- else {
- $map = openlayers_preset_load(
- variable_get('openlayers_default_preset', 'default'));
- }
- if (!empty($map->data) && is_array($map->data)) {
- $rendered = openlayers_render_map($map->data);
- // Replace text with rendered map preset
- $text = str_replace($matches[0][$i], $rendered, $text);
- }
- }
- }
- return $text;
- }
- /**
- * Filter tips callback
- */
- function _openlayer_filter_tips($filter, $format, $long = FALSE) {
- if ($long) {
- return t('Substitutes a macro text like !macro_example into a the
- appropriate rendered OpenLayers map. This will render a map
- preset into the body of content. If the preset name is not given,
- as in !macro_example_default, the default map preset will be shown.',
- array(
- '!macro_example' => '[openlayers preset_name]',
- '!macro_example_default' => '[openlayers]'
- )
- );
- }
- else {
- return t('Substitutes a macro text like !macro_example into a the
- appropriate rendered OpenLayers map.',
- array(
- '!macro_example' => '[openlayers preset_name]',
- )
- );
- }
- }
|