Projet

Général

Profil

Révision 8916d7ec

Ajouté par Assos Assos il y a plus de 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform_validation/webform_validation.validators.inc
123 123
      ),
124 124
      'custom_data' => array(
125 125
        'label' => t('Number the fields add up to'),
126
        'description' => t('Specify the number and the type of comparison. For example:') . theme('item_list', array(
127
          'items' => array(
128
            t('Enter "=3" if the components must add up to exactly 3.'),
129
            t('Enter ">10" if the components must add up to greater than 10.'),
130
            t('Enter ">=10" if the components must add up to greater than or equal to 10.'),
131
            t('Enter "<20" if the components must add up to less than 20.'),
132
            t('Enter "<=20" if the components must add up to less than or equal to 20.'),
126
        'description' => t('Specify the number and the type of comparison. For example:') . theme('table', array(
127
          'header' => array(t('Value'), t('Meaning')),
128
          'rows' => array(
129
            array('=3', t('The components must add up to exactly 3.')),
130
            array('>10', t('The components must add up to greater than 10.')),
131
            array('>=10', t('The components must add up to greater than or equal to 10.')),
132
            array('<20', t('The components must add up to less than 20.')),
133
            array('<=20', t('The components must add up to less than or equal to 20.')),
133 134
          ),
134 135
        )),
135 136
        'validate_regex' => '/^(=|>|>=|<|<=)(-?[\d.]+)$/',
......
239 240
      ),
240 241
      'custom_data' => array(
241 242
        'label' => t('Number to be completed'),
242
        'description' => t('Specify the number that must be completed and the type of comparison. For example:') . theme('item_list', array(
243
          'items' => array(
244
            t('Enter ">=1" if the user must complete <b>at least</b> 1 of the selected components.'),
245
            t('Enter "=3" if the user must complete <b>exactly</b> 3 of the selected components.'),
246
            t('Enter "<=2" if the user must complete <b>at most</b> 2 of the selected components.'),
243
        'description' => t('Specify the number that must be completed and the type of comparison. For example:') . theme('table', array(
244
          'header' => array(t('Value'), t('Meaning')),
245
          'rows' => array(
246
            array('>=1', t('The user must complete <b>at least</b> 1 of the selected components.')),
247
            array('=3', t('The user must complete <b>exactly</b> 3 of the selected components.')),
248
            array('<=2', t('The user must complete <b>at most</b> 2 of the selected components.')),
247 249
          ),
248 250
        )),
249 251
        'validate_regex' => '/^[><]?=\d+$/',
......
341 343
      'custom_error' => TRUE,
342 344
      'custom_data' => array(
343 345
        'label' => t('Pattern'),
344
        'description' => t('Specify a pattern where:') . theme('item_list', array('items' => array(t('@ = any letter A-Z'), t('# = any numeral 0-9'), t('| = separates two or more acceptable patterns'), t('Any other character must appear in its exact position')))) . t('Examples') . theme('item_list', array('items' => array(t('North American phone number: (###) ###-####'), t('D-2500 series model numbers: D-25##'), t('UK Postal Code: @# #@@|@## #@@|@@# #@@|@@## #@@|@#@ #@@|@@#@ #@@|GIR0AA')))),
346
        'description' => t('Specify a pattern where:') . theme('table', array(
347
          'header' => array(t('Value'), t('Meaning')),
348
          'rows' => array(
349
            array('@', t('Any letter A-Z.')),
350
            array('#', t('Any numeral 0-9.')),
351
            array('|', t('Separates two or more acceptable patterns.')),
352
            array('', t('Any other character must appear in its exact position.')),
353
          ),
354
        )) . t('Examples:') . theme('table', array(
355
          'header' => array(t('Value'), t('Meaning')),
356
          'rows' => array(
357
            array('(###) ###-####', t('North American phone number.')),
358
            array('D-25##', t('D-2500 series model numbers.')),
359
            array('@# #@@|@## #@@|@@# #@@|@@## #@@|@#@ #@@|@@#@ #@@|GIR0AA', t('UK Postal Code.')),
360
          ),
361
        )),
345 362
      ),
346 363
      'description' => t('Verifies that a user-entered value follows to a specified pattern.'),
347 364
    ),
......
452 469
    return NULL;
453 470
  }
454 471

  
455
  // Allow translation for all components item names if available.
456
  if (module_exists('webform_localization')) {
457
    foreach ($components as &$component) {
458
      $dummy_element = array(
459
        '#title' => '',
460
      );
461
      _webform_localization_translate_component($dummy_element, $component);
462
      if (isset($dummy_element['#title']) && (string) $dummy_element['#title']) {
463
        $component['name'] = $dummy_element['#title'];
464
      }
465
    }
466
  }
467

  
468 472
  // For certain validators, if all components to be compared are email
469 473
  // components, make the values lower-case to avoid case-sensitive comparison.
470 474
  if (in_array($validator_name, array('equal', 'comparison', 'unique'))) {
......
516 520
          if (isset($num_range['min']) && isset($num_range['max'])) {
517 521
            // Validate the min - max range.
518 522
            if ($subval < $num_range['min'] || $subval > $num_range['max']) {
519
              $errors[$key] = t('%item is not within the allowed range %range.', array('%item' => $components[$key]['name'], '%range' => str_replace('|', ' - ', $rule['data'])));
523
              $options = array(
524
                '%item' => $components[$key]['name'],
525
                '%range' => str_replace('|', ' - ', $rule['data']),
526
              );
527
              $errors[$key] = t('%item is not within the allowed range %range.', $options);
520 528
            }
521 529
          }
522 530
          else {
......
859 867
          'regular' => '%item must %verb with "%string".',
860 868
          'negated' => '%item must not %verb with "%string".',
861 869
        );
862
        $error_vars = array('%item' => $components[$key]['name'], '%verb' => $verb, '%string' => $rule['data']);
870
        $error_vars = array(
871
          '%item' => $components[$key]['name'],
872
          '%verb' => $verb,
873
          '%string' => $rule['data'],
874
        );
863 875
        foreach ($val as $subval) {
864 876
          $test = !preg_match($pattern, $subval);
865 877
          _webform_validation_test($errors, $key, $rule, $test, $error_strings, $error_vars);
......
870 882
    case 'pattern':
871 883
      $pattern = preg_quote($rule['data'], '/');
872 884
      $pattern = str_replace('@', '[a-zA-Z]', $pattern);
873
      $pattern = str_replace('#', '[0-9]', $pattern);
885
      // Since PHP 7.3, the # character is quoted by preg_quote().
886
      $quoted_hash = version_compare(PHP_VERSION, '7.3.0', '>=') ? '\\#' : '#';
887
      $pattern = str_replace($quoted_hash, '[0-9]', $pattern);
874 888
      $pattern = '(' . $pattern . ')';
875 889
      // Un-escape "|" operator.
876 890
      $pattern = preg_replace('/(\\s*)(\\\\)(\\|)(\\s*)/', ')|(', $pattern);
......
909 923
      return $errors;
910 924

  
911 925
    case 'blacklist':
912
      $blacklist = preg_quote($rule['data'], '/');
926
      $blacklist = $rule['data'];
927
      $blacklist = token_replace($blacklist);
928
      $blacklist = preg_quote($blacklist, '/');
913 929
      $blacklist = explode(',', $blacklist);
914 930
      $blacklist = array_map('trim', $blacklist);
915 931
      $blacklist = '/\b(' . implode('|', $blacklist) . ')\b/i';
......
1120 1136
function _webform_validation_i18n_error_message($rule) {
1121 1137
  $rule['error_message'] = filter_xss($rule['error_message']);
1122 1138
  if (module_exists('i18n')) {
1139
    $rule['ruleid'] = isset($rule['ruleid']) ? $rule['ruleid'] : NULL;
1123 1140
    return i18n_string('webform_validation:error_message:' . $rule['ruleid'] . ':message', $rule['error_message']);
1124 1141
  }
1125 1142
  return $rule['error_message'];

Formats disponibles : Unified diff