Unverified Commit 95d3fc62 authored by Aline Tenório's avatar Aline Tenório Committed by GitHub
Browse files

Merge pull request #39 from lmts-ufape/fixLattes

Atualizando validação de links
parents 02d5a421 8f842ea4
......@@ -16,11 +16,6 @@ class GrupoPesquisaValidation
$url = filter_var($url, FILTER_SANITIZE_URL);
// // Validate url
// if (!filter_var($url, FILTER_VALIDATE_URL)) {
// return false;
// }
//If url doesn't have a protocol
if(substr($url, 0, 4) != 'http'){
$url = 'http://' . $url;
......@@ -30,31 +25,7 @@ class GrupoPesquisaValidation
return false;
}
if($this->getHttpResponseCode_using_getheaders($url) != 200){
return false;
}
return true;
}
function getHttpResponseCode_using_getheaders($url, $followredirects = true)
{
if (!$url || !is_string($url)) {
return false;
}
$headers = @get_headers($url);
if ($headers && is_array($headers)) {
if ($followredirects) {
$headers = array_reverse($headers);
}
foreach ($headers as $hline) {
if (preg_match('/^HTTP\/\S+\s+([1-9][0-9][0-9])\s+.*/', $hline, $matches)) {
$code = $matches[1];
return $code;
}
}
return false;
}
return false;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ class LattesValidation
{
public function validate($attribute, $value, $parameters, $validator)
{
// dd($this->isValidUrl($value));
return $this->isValidUrl($value);
}
......@@ -16,12 +17,6 @@ class LattesValidation
}
$url = filter_var($url, FILTER_SANITIZE_URL);
// Validate url
// if (!filter_var($url, FILTER_VALIDATE_URL)) {
// dd('1');
// return false;
// }
//If url doesn't have a protocol
if(substr($url, 0, 4) != 'http'){
......@@ -31,33 +26,9 @@ class LattesValidation
//dd(parse_url($url)['host'] != 'lattes.cnpq.br');
if(parse_url($url)['host'] != 'buscatextual.cnpq.br' && parse_url($url)['host'] != 'lattes.cnpq.br'){
return false;
}
if($this->getHttpResponseCode_using_getheaders($url) != 200){
return false;
}
}
return true;
}
function getHttpResponseCode_using_getheaders($url, $followredirects = true)
{
if (!$url || !is_string($url)) {
return false;
}
$headers = @get_headers($url);
if ($headers && is_array($headers)) {
if ($followredirects) {
$headers = array_reverse($headers);
}
foreach ($headers as $hline) {
if (preg_match('/^HTTP\/\S+\s+([1-9][0-9][0-9])\s+.*/', $hline, $matches)) {
$code = $matches[1];
return $code;
}
}
return false;
}
return false;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment