You are here

function glossify_filter in Glossify 6.3

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

Implementation of hook_filter().

3 calls to glossify_filter()
glossify_comment in ./glossify.module
Implementation of hook_comment().
glossify_nodeapi in ./glossify.module
Implementation of hook_nodeapi().
theme_glossify_term in ./glossify.module
Render a glossary term.

File

./glossify.module, line 365

Code

function glossify_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
  static $configurations;
  switch ($op) {
    case 'list':
      if (variable_get('glossify_process_mode', GLOSSIFY_USE_FILTER) == GLOSSIFY_USE_FILTER) {
        return array(
          0 => t('Glossify filter'),
        );
      }
      else {
        return array();
      }
    case 'description':
      return t('Glossify the entered content.');
    case 'prepare':
      return $text;
    case 'process':

      // TODO: option should be to only do this on a node page
      // or have a list of paths where this filter will not be invoked
      if (empty($text)) {

        // Nothing to do.
        return $text;
      }
      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);
        if ($r->nid) {
          $node = node_load($r->nid);
        }
        else {

          // have to return something so that we don't lose output
          return $text;
        }
      }
      if (!isset($configurations)) {
        $configurations = variable_get('glossify_configurations', array());
        foreach ($configurations as $key => &$config) {
          if (isset($config['excl_tags']) && !empty($config['excl_tags'])) {
            $html_tags = preg_split("/\r\n|\r|\n|,/", $config['excl_tags']);
            $config['excl_tags'] = array_combine($html_tags, $html_tags);
          }
        }
      }
      if (class_exists('DOMDocument', false)) {
        $newtext = _glossify_replace_terms_phpdom($text, $configurations, $node);
      }
      else {
        $newtext = _glossify_replace_terms_simplehtmldom($text, $configurations, $node);
      }
      return $newtext;
    default:
      return $text;
  }
}