4 if (!defined("_ECRIRE_INC_VERSION")) return;
7 * Fonction de base de l'API de vérification.
8 * @param mixed $valeur La valeur a verifier.
9 * @param string $type Le type de verification a appliquer.
10 * @param array $options Un eventuel tableau d'options suivant le type.
11 * @param array $valeur_normalisee
12 * Si des options de verification modifient la valeur entrante (normalisent),
13 * alors la valeur modifie sera stockee dans cette variable.
14 * @return string Retourne une chaine vide si c'est valide, sinon une chaine expliquant l'erreur.
16 function inc_verifier_dist($valeur, $type, $options=null, &$valeur_normalisee=null){
18 // On vérifie que les options sont bien un tableau
19 if (!is_array($options))
22 // Si la valeur est vide, il n'y a rien a verifier donc c'est bon
23 if (is_null($valeur) or (is_string($valeur) and $valeur == '')) return '';
24 // Si c'est une date avec horaire c'est un tableau
25 if (is_array($valeur) and isset($valeur['date']) and $valeur[date
] == '') return '';
27 // On cherche si une fonction correspondant au type existe
28 if ($verifier = charger_fonction($type, 'verifier',true)){
29 $erreur = $verifier($valeur, $options, $valeur_normalisee);
32 // On passe le tout dans le pipeline du meme nom
39 'options' => $options,
49 * Liste toutes les vérifications possibles
51 * @param string $repertoire
52 * Dans quel repertoire chercher les yaml.
54 * @return Retourne un tableau listant les vérifications et leurs options
56 function verifier_lister_disponibles($repertoire='verifier'){
57 static $verifications = array();
59 if (!isset($verifications[$repertoire])) {
60 $verifications[$repertoire] = array();
61 $liste = find_all_in_path("$repertoire/", '.+[.]yaml$');
64 foreach ($liste as $fichier=>$chemin){
65 $type = preg_replace(',[.]yaml$,i', '', $fichier);
66 $dossier = str_replace($fichier, '', $chemin);
67 // On ne garde que les vérifications qui ont bien la fonction !
68 if (charger_fonction($type, $repertoire, true)
70 is_array($verif = verifier_charger_infos($type, $repertoire))
73 $verifications[$repertoire][$type] = $verif;
79 return $verifications[$repertoire];
84 * Charger les informations contenues dans le yaml d'une vérification
86 * @param string $type_verif
87 * Le type de la vérification
89 * @param string $repertoire
90 * Dans quel repertoire chercher les yaml.
92 * @return array Un tableau contenant le YAML décodé
94 function verifier_charger_infos($type_verif, $repertoire='verifier'){
95 include_spip('inc/yaml');
96 $fichier = find_in_path("$repertoire/$type_verif.yaml");
97 $verif = yaml_decode_file($fichier);
98 if (is_array($verif)){
99 $verif['titre'] = (isset($verif['titre']) and $verif['titre']) ?
_T_ou_typo($verif['titre']) : $type_verif;
100 $verif['description'] = (isset($verif['description']) and $verif['description']) ?
_T_ou_typo($verif['description']) : '';
101 $verif['icone'] = (isset($verif['icone']) and $verif['icone']) ?
_T_ou_typo($verif['icone']) : '';