You are here

function openlayers_filters_filter in Openlayers 6.2

Same name and namespace in other branches
  1. 6 modules/openlayers_filters/openlayers_filters.module \openlayers_filters_filter()

Implementation of hook_filter().

File

modules/openlayers_filters/openlayers_filters.module, line 29
This file holds the main Drupal hook functions and private functions for the openlayers_filters module.

Code

function openlayers_filters_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
  if ($op == 'list') {
    return array(
      0 => t('Inline OpenLayers Maps'),
    );
  }
  switch ($delta) {
    case 0:
      switch ($op) {
        case 'no cache':
          return TRUE;
        case 'description':
          return t('Substitutes a macro text like !macro_example into an
              appropriate rendered OpenLayers map.', array(
            '!macro_example' => '[openlayers preset_name]',
          ));
        case 'prepare':
          return $text;
        case 'process':
          $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;
      }
      break;
  }
}