You are here

function openlayers_filters_filter in Openlayers 6

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

Implementation of hook_filter().

File

modules/openlayers_filters/openlayers_filters.module, line 28
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) {

  // Check op for list
  if ($op == 'list') {
    return array(
      0 => t('Inline OpenLayers Maps'),
    );
  }

  // Check delta
  switch ($delta) {
    case 0:
      switch ($op) {
        case 'no cache':

          // No caching
          return TRUE;
        case 'description':
          return t('Substitutes a macro text like !macro_example into a the 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);

              // Check for openlayers prefix
              if ($exploded[0] == 'openlayers') {

                // Check for preset name
                if ($preset = check_plain($exploded[1])) {
                  $map = openlayers_get_map($preset);
                }
                else {
                  $map = openlayers_get_default_map();
                }

                // Check map
                if (!empty($map)) {

                  // Render map
                  $rendered = openlayers_render_map($map);

                  // Replace text
                  $text = str_replace($matches[0][$i], $rendered['themed'], $text);
                }
              }
            }
          }
          return $text;
      }
      break;
  }
}