X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fplugins%2Fauto%2Fverifier%2Fverifier%2Furl.php;fp=www%2Fplugins%2Fauto%2Fverifier%2Fverifier%2Furl.php;h=dcfc9e24fd84454021c4774ab84019742318ae8a;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/plugins/auto/verifier/verifier/url.php b/www/plugins/auto/verifier/verifier/url.php new file mode 100644 index 0000000..dcfc9e2 --- /dev/null +++ b/www/plugins/auto/verifier/verifier/url.php @@ -0,0 +1,139 @@ + 'verifier_url_protocole', 'php_filter' => 'verifier_php_filter', 'complet' => 'verifier_url_complet'); + $fonction_verif = $fonctions_disponibles[$mode]; + + return $fonction_verif($valeur,$type_protocole,$protocole) ; + +} + +/** + * Vérifier uniquement la présence d'un protocole + * + * @param string $valeur La valeur à vérifier + * @param string $type_protocole : tous, web (http ou https), mail (imap, pop3, smtp), ftp (ftp ou sftp), exact + * @param string $protocole : nom du protocole (si type_protocole=exact) + * @return boolean Retourne true uniquement lorsque l'url est valide + */ +function verifier_url_protocole($url,$type_protocole,$protocole){ + + $urlregex = array('tous' => "^([a-z0-9]*)\:\/\/.*$", + 'web' => "^(https?)\:\/\/.*$", + 'ftp' => "^(s?ftp)\:\/\/.*$", + 'mail' => "^(pop3|smtp|imap)\:\/\/.*$", + 'exact' => "^(".$protocole.")\:\/\/.*$"); + + $msg_erreur = array('tous' => "", + 'web' => "http://, https://", + 'ftp' => "^ftp://, sftp://", + 'mail' => "pop3://, smtp://, imap://", + 'exact' => $protocole."://" ); + + + if (!eregi($urlregex[$type_protocole], $url)) { + if($type_protocole=="tous") { + return _T('verifier:erreur_url_protocole_exact', array('url' => echapper_tags($url))); + } else { + return _T('verifier:erreur_url_protocole', array('url' => echapper_tags($url),'protocole' => $msg_erreur[$type_protocole])); + } + } + return ''; +} + +/** + * Vérifier uniquement la présence d'un protocole + * + * @param string $valeur La valeur à vérifier + * @param string $type_protocole : tous, web (http ou https), mail (imap, pop3, smtp), ftp (ftp ou sftp), exact + * @param string $protocole : nom du protocole (si type_protocole=exact) + * @return boolean Retourne true uniquement lorsque l'url est valide + */ +function verifier_php_filter($url,$type_protocole,$protocole){ + + if (!filter_var($url, FILTER_VALIDATE_URL)) + return _T('verifier:erreur_url', array('url' => echapper_tags($valeur))); + return ''; +} + +/** + * Vérifier la présence d'un protocole et de la bonne syntaxe du reste de l'url + * + * http://phpcentral.com/208-url-validation-in-php.html + * :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor] + * + * @param string $valeur La valeur à vérifier + * @param string $type_protocole : web (http ou https), mail (imap, pop3, smtp), ftp (ftp ou sftp), exact + * @param string $protocole : nom du protocole (si type_protocole=exact) + * @return boolean Retourne true uniquement lorsque l'url est valide + */ +function verifier_url_complet($url,$type_protocole,$protocole){ + + if($msg=verifier_url_protocole($url,$type_protocole,$protocole)!=''){ + return $msg; + } + // SCHEME + $urlregex = "^(.*)\:\/\/"; + + // USER AND PASS (optional) + $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; + + // HOSTNAME OR IP + $urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*"; // http://x = allowed (ex. http://localhost, http://routerlogin) + //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)+"; // http://x.x = minimum + //$urlregex .= "([a-z0-9+\$_-]+\.)*[a-z0-9+\$_-]{2,3}"; // http://x.xx(x) = minimum + //use only one of the above + + // PORT (optional) + $urlregex .= "(\:[0-9]{2,5})?"; + // PATH (optional) + $urlregex .= "(\/([a-z0-9+\$_%,-]\.?)+)*\/?"; + // GET Query (optional) + $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?"; + // ANCHOR (optional) + $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?\$"; + + if (!eregi($urlregex, $url)) + return _T('verifier:erreur_url', array('url' => echapper_tags($valeur))); + return ''; +} \ No newline at end of file