[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins / verifier / verifier / url.php
index be3ac08..44e7a86 100644 (file)
@@ -32,8 +32,9 @@ function verifier_url_dist($valeur, $options = array()) {
        }
 
        // Choix du type de protocole à vérifier
-       if (!$options['type_protocole'] or !in_array($options['type_protocole'], array('tous','web','mail','ftp','exact'))) {
+       if (!$options['type_protocole'] or !in_array($options['type_protocole'], array('tous','web','mail','ftp','webcal_souple','webcal_strict','exact'))) {
                $type_protocole = 'web';
+               $protocole = '';
        } else {
                $type_protocole = $options['type_protocole'];
                $protocole = '' ;
@@ -44,7 +45,6 @@ function verifier_url_dist($valeur, $options = array()) {
 
        $fonctions_disponibles = array('protocole_seul' => 'verifier_url_protocole', 'php_filter' => 'verifier_php_filter', 'complet' => 'verifier_url_complet');
        $fonction_verif = $fonctions_disponibles[$mode];
-
        return $fonction_verif($valeur,$type_protocole,$protocole) ;
 }
 
@@ -52,7 +52,7 @@ function verifier_url_dist($valeur, $options = array()) {
  * 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 $type_protocole : tous, web (http ou https), mail (imap, pop3, smtp), ftp (ftp ou sftp), webcal (webcal, http, https), exact
  * @param string $protocole : nom du protocole (si type_protocole=exact)
  * @return boolean Retourne true uniquement lorsque l'url est valide
  */
@@ -63,6 +63,7 @@ function verifier_url_protocole($url, $type_protocole, $protocole) {
                'web' => '#^(https?)\:\/\/.*$# i',
                'ftp' => '#^(s?ftp)\:\/\/.*$# i',
                'mail' => '#^(pop3|smtp|imap)\:\/\/.*$# i',
+               'webcal' => '#^(webcal|https?)\:\/\/.*$# i',
                'exact' => '#^(".$protocole.")\:\/\/.*$# i'
        );
 
@@ -71,6 +72,7 @@ function verifier_url_protocole($url, $type_protocole, $protocole) {
                'web' => 'http://, https://',
                'ftp' => '^ftp://, sftp://',
                'mail' => 'pop3://, smtp://, imap://',
+               'webcal' => 'webcal://, http://, https://',
                'exact' => $protocole.'://'
        );
 
@@ -86,15 +88,18 @@ function verifier_url_protocole($url, $type_protocole, $protocole) {
 }
 
 /**
- * Vérifier uniquement la présence d'un protocole
+ * Vérifier la présence d'un protocole,
+ * puis utilise le filtre FILTER_VALIDATE_URL de PHP pour s'assurer que l'url est complète
  *
  * @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 $type_protocole : tous, web (http ou https), mail (imap, pop3, smtp), ftp (ftp ou sftp), webcal (webcal, http, https), 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 ($msg = verifier_url_protocole($url, $type_protocole, $protocole)) {
+               return $msg;
+       }
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
                return _T('verifier:erreur_url', array('url' => echapper_tags($valeur)));
        }
@@ -108,13 +113,13 @@ function verifier_php_filter($url, $type_protocole, $protocole) {
  * <http[s]|ftp> :// [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 $type_protocole : web (http ou https), mail (imap, pop3, smtp), ftp (ftp ou sftp), webcal (webcal, http, https), 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) != '') {
+       if ($msg = verifier_url_protocole($url, $type_protocole, $protocole)) {
                return $msg;
        }
        // SCHEME
@@ -134,12 +139,12 @@ function verifier_url_complet($url, $type_protocole, $protocole) {
        // PATH (optional)
        $urlregex .= '(\/([a-z0-9+\$_%,-]\.?)+)*\/?';
        // GET Query (optional)
-       $urlregex .= '(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?';
+       $urlregex .= '(\?[a-z+&\$_.-][a-z0-9;:@\&%=+\$_.-]*)?';
        // ANCHOR (optional)
        $urlregex .= '(\#[a-z_.-][a-z0-9+\$_.-]*)?\$# i';
 
        if (!preg_match($urlregex, $url)) {
-               return _T('verifier:erreur_url', array('url' => echapper_tags($valeur)));
+               return _T('verifier:erreur_url', array('url' => echapper_tags($url)));
        }
        return '';
 }