\s*
\s*/i', $in, $matches)) {
// img tag already has an anchor
}
else if(preg_match('/
/i', $in, $matches)) {
$out = '' . $matches[0] . '';
}
else {
// not matched
}
return $out;
}
/**
* Implements hook_filter_info()
*/
function imganchor_filter_info() {
$filters['imganchor'] = array(
'title' => t('image anchor'),
'description' => t('Add an anchor tag to the img tag that does not have anchor tag.'),
'process callback' => 'imganchor_filter_process',
'tips callback' => 'imganchor_filter_tips',
);
return $filters;
}
/**
* Implementation of hook_filter()
*/
function imganchor_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
if (empty($text)) return $text;
//--DEBUG
imganchor_debugout("----before filter----");
imganchor_debugout($text);
$text = _filter_imganchor($text);
//--DEBUG
imganchor_debugout("----after filter----");
imganchor_debugout($text);
return $text;
}
/**
* Implements hook_filter_FILTER_tips()
*/
function imganchor_filter_tips($filter, $format, $long) {
return t('Add an anchor tag to the img tag that does not have anchor tag.');
}
/**
* Debug function
*/
function imganchor_debugout($str) {
// return; // for production
$outfile = "/tmp/imganchor.txt";
if(is_array($str) || is_object($str)) {
error_log(print_r($str, TRUE) . "\n", 3, $outfile);
}
else {
error_log($str . "\n", 3, $outfile);
}
}