You are here

function feeds_tamper_find_replace_validate in Feeds Tamper 6

Same name and namespace in other branches
  1. 7 plugins/find_replace.inc \feeds_tamper_find_replace_validate()
1 string reference to 'feeds_tamper_find_replace_validate'
find_replace.inc in plugins/find_replace.inc

File

plugins/find_replace.inc, line 50

Code

function feeds_tamper_find_replace_validate(&$settings) {
  $settings['regex'] = FALSE;
  if (!$settings['word_boundaries'] && !$settings['whole'] && $settings['case_sensitive']) {
    $settings['func'] = 'str_replace';
  }
  elseif (!$settings['word_boundaries'] && !$settings['whole'] && !$settings['case_sensitive']) {
    $settings['func'] = 'str_ireplace';
  }
  else {
    $settings['regex'] = TRUE;
    if ($settings['whole']) {
      $regex = '/^' . preg_quote($settings['find'], '/') . '$/u';
    }
    else {

      // Word boundaries can only match a word with letters at the end.
      if (!preg_match('/^\\w(.*\\w)?$/u', $settings['find'])) {
        form_set_error('settings][find', t('Search text must begin and end with a letter, number, or underscore to use the %option option.', array(
          '%option' => t('Respect word boundaries'),
        )));
      }
      $regex = '/\\b' . preg_quote($settings['find'], '/') . '\\b/u';
    }
    if (!$settings['case_sensitive']) {
      $regex .= 'i';
    }
    $settings['regex_find'] = $regex;
  }
}