function scanner_scanner_preg_replace in Search and Replace Scanner 7
Implements hook_scanner_preg_replace().
File
- ./
scanner.module, line 1358 - Search and Replace Scanner - works on all nodes text content.
Code
function scanner_scanner_preg_replace(&$node, $field, $matches, $row, $regexstr, $replace) {
$language = NULL;
$hits = 0;
$old_value = NULL;
if (!empty($matches[1])) {
$language = field_language('node', $node, $matches[1]);
// Not every field has a 'value'.
if (isset($node->{$matches[1]}[$language][$row->delta]['value'])) {
$old_value = $node->{$matches[1]}[$language][$row->delta]['value'];
}
}
else {
$old_value = $node->{$field};
}
// Replace the string if one was identified.
if (isset($old_value)) {
$new_value = preg_replace($regexstr, $replace, $old_value, -1, $hits);
}
if (!empty($matches[1])) {
// Not every field has a 'value'.
if (isset($node->{$matches[1]}[$language][$row->delta]['value'])) {
$node->{$matches[1]}[$language][$row->delta]['value'] = $new_value;
}
}
else {
$node->{$field} = $new_value;
}
return $hits;
}