You are here

function pathologic_filter in Pathologic 6

Same name and namespace in other branches
  1. 5 pathologic.module \pathologic_filter()
  2. 6.3 pathologic.module \pathologic_filter()
  3. 6.2 pathologic.module \pathologic_filter()

Implementation of hook_filter().

File

./pathologic.module, line 22
The main and only module file.

Code

function pathologic_filter($op, $delta = 0, $format = -1, $text = '') {
  if ($op === 'process' && $text !== '') {
    if (variable_get("filter_pathologic_href_{$format}", TRUE)) {

      // Do transformation on HREF paths
      // Make relative
      $text = preg_replace_callback(_pathologic_abs_regex('href', $format), '_pathologic_abs_to_rel', $text);

      // Transform attributes
      $text = preg_replace_callback('|href="([^/#][^:"#]+)#?([^:"]*)"|', '_pathologic_do_href', $text);
    }
    if (variable_get("filter_pathologic_src_{$format}", TRUE)) {

      // Do transformation on SRC paths
      // Make relative
      $text = preg_replace_callback(_pathologic_abs_regex('src', $format), '_pathologic_abs_to_rel', $text);

      // Transform attributes
      $text = preg_replace_callback('|src="([^/][^:"]+)"|', '_pathologic_do_src', $text);
    }
    return $text;
  }
  if ($op === 'list') {
    return array(
      t('Pathologic'),
    );
  }
  if ($op === 'description') {
    return t('Corrects paths in content which reference pages or media on this server.');
  }
  if ($op === 'settings') {
    return array(
      'filter_pathologic' => array(
        '#type' => 'fieldset',
        '#title' => t('Pathologic'),
        '#collapsible' => TRUE,
        "filter_pathologic_href_{$format}" => array(
          '#type' => 'checkbox',
          '#title' => t('Transform values of <em>href</em> attributes'),
          '#default_value' => intval(variable_get("filter_pathologic_href_{$format}", 1)),
          '#description' => t('<em>href</em> attributes are used in link tags.'),
        ),
        "filter_pathologic_src_{$format}" => array(
          '#type' => 'checkbox',
          '#title' => t('Transform values of <em>src</em> attributes'),
          '#default_value' => intval(variable_get("filter_pathologic_src_{$format}", 1)),
          '#description' => t('<em>src</em> attributes are used in image tags and tags for other types of embedded media.'),
        ),
        "filter_pathologic_abs_paths_{$format}" => array(
          '#type' => 'textarea',
          '#title' => t('Additional paths to be considered local'),
          '#default_value' => variable_get("filter_pathologic_abs_paths_{$format}", ''),
          '#description' => t('Enter URIs of other Drupal installations which should be considered local in addition to the one for this particular Drupal installation (which is %path). If in doubt, enter the path to the Drupal installation&rsquo;s front page. Enter one path per line.', array(
            '%path' => _pathologic_url('<front>'),
          )),
        ),
      ),
    );
  }
  return $text;
}