function _w3c_validator_validate_uri_tidy in W3C Validator 6
Validate a url using tidy library method.
File
- ./
w3c_validator.module, line 159 - W3C Validator proxy.
Code
function _w3c_validator_validate_uri_tidy($uri) {
if (empty($uri)) {
return FALSE;
}
// Create a token for this request
$token = w3c_validator_create_access_token($uri);
// The token is used as a header to allow validation of authenticated pages, see hook_init
$response = drupal_http_request($uri, array(
'w3c-validator-token' => $token,
));
$html = $response->data;
$config = array();
$tidy = new tidy();
$tidy
->parseString($html, $config);
$tidy
->diagnose();
preg_match_all('/^(?:line (\\d+) column (\\d+) - )?(\\S+): (?:\\[((?:\\d+\\.?){4})]:)?(.*?)$/m', $tidy->errorBuffer, $tidy_errors, PREG_SET_ORDER);
$error_array = array();
$warning_array = array();
foreach ($tidy_errors as $tidy_error) {
$data = array(
'line' => $tidy_error[1],
'col' => $tidy_error[2],
'message' => $tidy_error[5],
);
if ($tidy_error[3] == 'Error') {
$error_array[] = $data;
}
elseif ($tidy_error[3] == 'Warning') {
$warning_array[] = $data;
}
}
$result = array(
'uri' => $uri,
'doctype' => '',
'validity' => empty($error_array) && empty($warning_array) ? 'true' : 'false',
'errors' => $error_array,
'warnings' => $warning_array,
'response' => $response,
);
return $result;
}