You are here

function patterns_validate_service in Patterns 7.2

Same name and namespace in other branches
  1. 7 includes/parser/parser.inc \patterns_validate_service()

Callback of the url patterns/validate.

Returns validation info about the pattern passed in the $_POST array.

1 string reference to 'patterns_validate_service'
patterns_menu in ./patterns.module
Implements hook_menu().

File

includes/parser/parser.inc, line 291

Code

function patterns_validate_service() {
  if (!isset($_POST['pattern'])) {
    print t('No pattern found: Communication error.');
    exit;
  }
  if (!isset($_POST['format']) || $_POST['format'] == PATTERNS_FORMAT_UNKNOWN) {
    print t('Cannot validate: Unknown pattern format.');
    exit;
  }
  if (!isset($_POST['validation'])) {
    print t('Cannot validate: Unknown validation level.');
    exit;
  }
  $pattern = patterns_parser_parse($_POST['pattern'], $_POST['format']);
  if (!$pattern) {
    print t('Pattern could not be parsed. Please check pattern format.');
    exit;
  }

  //The validation level is selected now by the user through $_POST['validation']
  $scan = patterns_scan_pattern($pattern, FALSE, $_POST['validation']);
  if (_patterns_scan_validate_patternscan($scan, FALSE, $_POST['validation'], FALSE)) {
    $count = count($scan['other_sections']) + $scan['info'] + $scan['modules'];
    $out = t('This pattern is valid. !count sections found ->', array(
      '!count' => $count,
    )) . ' ';
    $out .= 'info ';
    $out .= $scan['modules'] ? 'modules ' : '';
    foreach ($scan['other_sections'] as $key => $value) {
      $out .= $key . ' ' . $value;
    }
  }
  else {
    $errors = implode('<br/> ', _patterns_scan_analyze_patternscan($scan));
    $out = t('This pattern is NOT valid.') . '<br/>' . $errors;
  }
  print $out;
}