You are here

function customfilter_filter in Custom filter 6

Same name and namespace in other branches
  1. 5 customfilter.module \customfilter_filter()
  2. 6.2 customfilter.module \customfilter_filter()

Implements hook_filter().

8 string references to 'customfilter_filter'
customfilter_filter_add_submit in ./customfilter.admin.inc
Submission callback for the add filter form.
customfilter_filter_edit_submit in ./customfilter.admin.inc
Submission callback for the filter edit form.
customfilter_import_form_submit in ./customfilter.admin.inc
Submission callback for the import form.
customfilter_update_6103 in ./customfilter.install
Implements hook_update_N().
customfilter_update_6111 in ./customfilter.install
Implements hook_update_N().

... See full list

File

./customfilter.module, line 16
Allows the users with the right permission to define custom filters.

Code

function customfilter_filter($op, $delta = 0, $format = -1, $text = '') {
  $filters = _customfilter_get_filters();
  switch ($op) {
    case 'description':
      return isset($filters[$delta]['description']) ? $filters[$delta]['description'] : '';
    case 'list':
      $flist = array();
      foreach ($filters as $filter) {
        $flist[$filter['fid']] = t('Custom filter #!fid (%fname)', array(
          '!fid' => $filter['fid'],
          '%fname' => $filter['name'],
        ));
      }
      return $flist;
    case 'no cache':
      return isset($filters[$delta]['cache']) ? !$filters[$delta]['cache'] : FALSE;
    case 'process':

      // If the text passed is an empty string, then return it immediately.
      if (empty($text)) {
        return '';
      }

      // If the filter cannot be loaded from the database, then return the text
      // passed to the function.
      if (!isset($filters[$delta])) {
        return $text;
      }
      $globals =& _customfilter_globals('push');
      $globals->text = $text;
      $rules = _customfilter_get_rules($delta);
      if (is_array($rules) && count($rules)) {

        // Reset the object containing the global variables.
        _customfilter_code_vars(TRUE);

        // Prepare the stack used to save the parent rule.
        $globals->stack = array();
        foreach ($rules as $rule) {
          if ($rule['enabled']) {
            $globals->stack[] = $rule;
            $globals->text = preg_replace_callback($rule['pattern'], '_customfilter_process', $globals->text);
            array_pop($globals->stack);
          }
        }
      }
      $result = $globals->text;
      _customfilter_globals('pop');
      return $result;
    default:
      return $text;
  }
}