function pathologic_filter in Pathologic 6.2
Same name and namespace in other branches
- 5 pathologic.module \pathologic_filter()
- 6.3 pathologic.module \pathologic_filter()
- 6 pathologic.module \pathologic_filter()
Implementation of hook_filter().
File
- ./
pathologic.module, line 15 - Pathologic text filter for Drupal.
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.
// The "internal:" bit in the regex makes life easier for those migrating
// from the Path Filter module.
$text = preg_replace_callback('|href="(internal:)?([^/#][^:"#\\?]+)([\\?]([^#]+))?(#([^:"]*))?"|', '_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.
// The "internal:" bit in the regex makes life easier for those migrating
// from the Path Filter module.
$text = preg_replace_callback('|src="(internal:)?([^/][^:"\\?]+)([\\?]([^#]+))?"|', '_pathologic_do_src', $text);
}
return $text;
}
elseif ($op === 'list') {
return array(
t('Pathologic'),
);
}
elseif ($op === 'description') {
return t('Corrects paths in links and images in your Drupal content in situations which would otherwise cause them to “break.”');
}
elseif ($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’s front page. Enter one path per line.', array(
'%path' => _pathologic_url('<front>'),
)),
),
),
);
}
return $text;
}