You are here

function glossify_filter in Glossify 6

Same name and namespace in other branches
  1. 6.3 glossify.module \glossify_filter()

Implementation of hook_filter().

File

./glossify.module, line 319

Code

function glossify_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
  switch ($op) {
    case 'list':
      return array(
        0 => t('Glossify filter'),
      );
    case 'description':
      return t('Glossify the entered content.');
    case 'prepare':
      return $text;
    case 'process':
      if (($node = menu_get_object()) == NULL) {
        $q = db_query("SELECT nid FROM {node_revisions} WHERE '%s'=CONCAT(format, ':', MD5(body))", $cache_id);
        $r = db_fetch_object($q);
        $node = node_load($r->nid);
      }
      $configurations = variable_get('glossify_configurations', array());
      $html_body = str_get_html($text);
      foreach ($configurations as $config_name => $configuration) {
        if (in_array($node->type, $configuration['from'])) {
          foreach (_fetch_possible_keywords($configuration, $node->nid) as $term_title => $target_url) {
            foreach ($configuration['style'] as $style => $enabled) {
              if ($enabled) {
                if (isset($old_body) && $old_body !== $html_body->innertext) {
                  $html_body = str_get_html($html_body->innertext);
                }
                $replacement = _fetch_replacement($style, $term_title, $target_url);
                $old_body = $html_body->innertext;
                $replaced = 0;
                _glossify_replace($configuration, $html_body, $term_title, $replacement, $replaced);
              }
            }
          }
        }
      }
      return $html_body->innertext;
    default:
      return $text;
  }
}