You are here

function patterns_validate_service in Patterns 7

Same name and namespace in other branches
  1. 7.2 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 290

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;
  }
  $pattern = patterns_parser_parse($_POST['pattern'], $_POST['format']);
  if (!$pattern) {
    print t('Pattern could not be parsed. Please check pattern format.');
    exit;
  }
  $scan = patterns_scan_pattern($pattern);
  if (_patterns_scan_validate_patternscan($scan)) {
    $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;
}