You are here

function _icon_filter in Icon API 7

Same name and namespace in other branches
  1. 8 modules/icon_filter/icon_filter.module \_icon_filter()

Process callback for icon filter.

1 string reference to '_icon_filter'
icon_filter_filter_info in modules/icon_filter/icon_filter.module
Implements hook_filter_info().

File

modules/icon_filter/icon_filter.module, line 38
icon_filter.module Provides a filter for text fields to replace an icon token with icon markup.

Code

function _icon_filter($text, $filter, $format, $langcode, $cache, $cache_id) {
  $icons = array();
  if (preg_match_all(ICON_FILTER_REGEX, $text, $matches, PREG_SET_ORDER)) {
    foreach ($matches as $match) {
      if (!isset($icons[$match[0]])) {
        $icons[$match[0]] = theme('icon', array(
          'bundle' => $match[1],
          'icon' => $match[2],
        ));
      }
    }
  }
  foreach ($icons as $search => $replace) {
    if (!empty($replace)) {
      $text = str_replace($search, $replace, $text);
    }
  }
  return $text;
}