Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Walter Felipe
submeta
Commits
4e543828
Commit
4e543828
authored
Jun 12, 2020
by
alinetenorio
Browse files
validação do link de grupo de pesquisa
parent
5ae315e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/TrabalhoController.php
View file @
4e543828
...
...
@@ -93,7 +93,7 @@ class TrabalhoController extends Controller
'area'
=>
[
'required'
,
'string'
],
'subArea'
=>
[
'required'
,
'string'
],
'pontuacaoPlanilha'
=>
[
'required'
,
'string'
],
'linkGrupo'
=>
[
'required'
,
'string'
],
'linkGrupo'
=>
[
'required'
,
'string'
,
'link_grupo'
],
'linkLattesEstudante'
=>
[
'required'
,
'string'
,
'link_lattes'
],
'nomeParticipante.*'
=>
[
'required'
,
'string'
],
'emailParticipante.*'
=>
[
'required'
,
'string'
],
...
...
@@ -142,7 +142,7 @@ class TrabalhoController extends Controller
'area'
=>
[
'required'
,
'string'
],
'subArea'
=>
[
'required'
,
'string'
],
'pontuacaoPlanilha'
=>
[
'required'
,
'string'
],
'linkGrupo'
=>
[
'required'
,
'string'
],
'linkGrupo'
=>
[
'required'
,
'string'
,
'link_grupo'
],
'linkLattesEstudante'
=>
[
'required'
,
'string'
,
'link_lattes'
],
'nomeParticipante.*'
=>
[
'required'
,
'string'
],
'emailParticipante.*'
=>
[
'required'
,
'string'
],
...
...
app/Providers/AppServiceProvider.php
View file @
4e543828
...
...
@@ -26,5 +26,6 @@ class AppServiceProvider extends ServiceProvider
{
Validator
::
extend
(
'cpf'
,
'\App\Utils\CpfValidation@validate'
);
Validator
::
extend
(
'link_lattes'
,
'\App\Utils\LattesValidation@validate'
,
'Link inválido'
);
Validator
::
extend
(
'link_grupo'
,
'\App\Utils\GrupoPesquisaValidation@validate'
,
'Link inválido'
);
}
}
app/Utils/GrupoPesquisaValidation.php
0 → 100644
View file @
4e543828
<?php
namespace
App\Utils
;
class
GrupoPesquisaValidation
{
public
function
validate
(
$attribute
,
$value
,
$parameters
,
$validator
)
{
return
$this
->
isValidUrl
(
$value
);
}
function
isValidUrl
(
$url
)
{
// first do some quick sanity checks:
if
(
!
$url
||
!
is_string
(
$url
))
{
return
false
;
}
$url
=
filter_var
(
$url
,
FILTER_SANITIZE_URL
);
// Validate url
if
(
!
filter_var
(
$url
,
FILTER_VALIDATE_URL
))
{
return
false
;
}
// if(parse_url($url)['host'] != 'dgp.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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment