@dww: There's no need for function forking. Here's an example of what the two functions would like. I haven't tested the filtering itself to make sure that it works as expected, but I think it should.
<?php
/**
* Implementation of hook_form_filter()
* @ingroup project_issue_filter
*/
function project_issue_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(
0 => t('Project Issue to link filter (not cached)'),
1 => t('Project issue to link filter (cached)'),
);
case 'no cache':
switch ($delta) {
case 0:
return TRUE;
case 1:
return FALSE;
}
case 'description':
switch ($delta) {
case 0:
return t('Converts references to project issues (in the form of [#12345]) into links. Use this filter when using node access control modules or if access to project issues is not given to all users (both anonymous and authenticated).');
case 1:
return t('Converts references to project issues (in the form of [#12345]) into links. Use this filter if no node access control modules are used on your site and if all users can access all project issues.');
}
case 'prepare':
return $text;
case 'process':
$regex = '(?<!\w)(\[#(\d+)(#comment-(\d+))?\])(?![^<]*<\/a>|([^<]|(<(?!code>)))*<\/code>|([^<]|(<(?!pre>)))*<\/pre>|\w)';
$offset = 0;
while(preg_match('/'.$regex.'/', $text, $preg_matches, PREG_OFFSET_CAPTURE, $offset)) {
$offset++;
$match = $preg_matches[1];
$nid = $preg_matches[2][0];
$comment_id=$preg_matches[4][0];
$node = node_load($nid);
if (is_object($node) && node_access('view', $node)) {
$link = theme_project_issue_issue_link($node, $comment_id);
$text = substr_replace($text, $link, $match[1], strlen($match[0]));
$offset = max($offset, $match[1]+strlen($link));
}
else {
$offset = max($offset, $match[1]+strlen($match[0]));
}
}
return $text;
}
}
/**
* Implementation of hook_requirements()
* @ingroup project_issue_filter
*/
function project_issue_requirements($phase) {
$requirements = array();
$input_formats = array();
if ($phase == 'runtime') {
foreach (filter_formats() as $format => $input_format) {
$filters = filter_list_format($format);
if (isset($filters['project_issue/0']) && isset($filters['project_issue/1'])) {
// Put up an error when both Project issue link (cached and non-cached) are enabled.
$incorrect_formats['!input_format'] = l($input_format->name, "admin/settings/filters/$format");
$requirements[] = array(
'title' => 'Project Issue to link filter',
'value' => t('Filter conflicts were detected.'),
'description' => t('The Project issue to link (not cached) and Project issue to link (cached) filters are both enabled for the !input_format input format. Only one Project issue to link filter should be enabled for any input format.', $incorrect_formats),
'severity' => REQUIREMENT_ERROR,
);
}
//error when HTML filter's weight is higher
// @todo: look for position of both filter/0 and filter/1
// @todo: may need to check position with respect to other filters such as codefilter
if (isset($filters['filter/0']) && $filters['project_issue/0']->weight <= $filters['filter/0']->weight) {
$description_names['%issuefilter'] = $filters['project_issue/0']->name;
$description_names['%htmlfilter'] = $filters['filter/0']->name;
$requirements[] = array(
'title' => 'Project Issue to link filter',
'value' => t('Some filter conflicts were detected.'),
'description' => t('%issuefilter should come after %htmlfilter to prevent loss of layout and highlighting.', $description_names)
.' '.l(t('Please rearange the filters.'), "admin/settings/filters/$format/order"),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
return $requirements;
}
?>