You are here

function pathfilter_filter in Path Filter 5.2

Same name and namespace in other branches
  1. 5 pathfilter.module \pathfilter_filter()
  2. 6.2 pathfilter.module \pathfilter_filter()
  3. 6 pathfilter.module \pathfilter_filter()

Implementation of hook_filter().

File

./pathfilter.module, line 48
This filter takes internal Drupal paths in double quotes, written as e.g. "internal:node/99", and replaces them with the appropriate absolute http URL using Drupal's url() function [1]. E.g. for a site located at http://example.com/mysite

Code

function pathfilter_filter($op, $delta = 0, $format = -1, $text = '') {

  // The "list" operation provides the module an opportunity to declare
  // both how many filters it defines and a human-readable name for each filter.
  // Note that the returned name should be passed through t() for translation.
  if ($op == 'list') {
    return array(
      0 => t('Internal path filter'),
    );
  }

  // All operations besides "list" provide a $delta argument so we know which
  // filter they refer to.
  switch ($delta) {
    case 0:
      switch ($op) {

        // This description is shown in the administrative interface, unlike
        // the filter tips which are shown in the content editing interface.
        case 'description':
          $output = t('Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path.');
          $output .= t(' Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.');
          return $output;

        // The actual filtering is performed here. The supplied text should be
        // returned, once any necessary substitutions have taken place.
        case 'process':
          global $_pathfilter_replacement_patterns;

          // use the 'currying' technique to allow us to pass the format into
          // the callback function.
          $callback = _pathfilter_curry(_pathfilter_process, 3);
          return preg_replace_callback($_pathfilter_replacement_patterns, $callback($format, TRUE), $text);

        // Filter settings for pathfilter.
        case 'settings':
          return _pathfilter_settings($format);
        default:
          return $text;
      }
      break;
  }
}