You are here

function link_scanner_preg_replace in Search and Replace Scanner 7

Implements hook_scanner_preg_replace().

File

./scanner.module, line 1491
Search and Replace Scanner - works on all nodes text content.

Code

function link_scanner_preg_replace(&$node, $field, $matches, $row, $regexstr, $replace) {

  // Performed on behalf of link.module.
  $hits = 0;
  if (!empty($matches[1])) {
    $language = field_language('node', $node, $matches[1]);

    // The Link module uses two field values - 'title' and 'url', so each one
    // needs to be checked separately.
    foreach (array(
      'title',
      'url',
    ) as $field_key) {
      if (isset($node->{$matches[1]}[$language][$row->delta][$field_key])) {
        $old_value = $node->{$matches[1]}[$language][$row->delta][$field_key];
        $new_value = preg_replace($regexstr, $replace, $old_value, -1, $new_hits);
        if ($new_hits > 0) {
          $node->{$matches[1]}[$language][$row->delta][$field_key] = $new_value;
          $hits += $new_hits;
        }
      }
    }
  }
  return $hits;
}