[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / verifier / verifier / taille.php
1 <?php
2
3 // Sécurité
4 if (!defined('_ECRIRE_INC_VERSION')) {
5 return;
6 }
7
8 /**
9 * Vérifier une taille minimale/maximale, pour un mot de passe par exemple
10 *
11 * @param string $valeur
12 * La valeur à vérifier.
13 * @param array $options
14 * Les éléments à vérifier (min, max, egal).
15 * @return string
16 * Retourne une chaine vide si c'est valide, sinon une chaine expliquant l'erreur.
17 */
18
19 function verifier_taille_dist($valeur, $options = array()) {
20 $ok = true;
21 if (!is_string($valeur)) {
22 return _T('erreur_inconnue_generique');
23 }
24
25 include_spip('inc/charsets');
26 $erreur = '';
27 $taille = spip_strlen($valeur);
28
29 if (isset($options['min'])) {
30 $ok = ($ok and ($taille >= $options['min']));
31 }
32
33 if (isset($options['max'])) {
34 $ok = ($ok and ($taille <= $options['max']));
35 }
36 if (isset($options['egal'])) {
37 $ok = ($ok and ($taille == $options['egal']));
38 }
39
40 if (!$ok) {
41 // On ajoute la taille actuelle aux valeurs de remplacement
42 $options['nb'] = $taille;
43 if (isset($options['min']) and isset($options['max'])) {
44 $erreur = _T('verifier:erreur_taille_entre', $options);
45 } elseif (isset($options['max'])) {
46 $erreur = _T('verifier:erreur_taille_max', $options);
47 } elseif (isset($options['egal'])) {
48 $erreur = _T('verifier:erreur_taille_egal', $options);
49 } else {
50 $erreur = _T('verifier:erreur_taille_min', $options);
51 }
52 }
53
54 return $erreur;
55 }