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 * @return string Retourne une chaine vide si c'est valide, sinon une chaine expliquant l'erreur.
13 function inc_verifier_dist($valeur, $type, $options=null){
15 // On vérifie que les options sont bien un tableau
16 if (!is_array($options))
19 // Si la valeur est vide, il n'y a rien a verifier donc c'est bon
20 if (is_null($valeur) or (is_string($valeur) and $valeur == '')) return '';
22 // On cherche si une fonction correspondant au type existe
23 if ($verifier = charger_fonction($type, 'verifier',true)){
24 $erreur = $verifier($valeur, $options);
27 // On passe le tout dans le pipeline du meme nom
44 * Liste toutes les vérifications possibles
46 * @return Retourne un tableau listant les vérifications et leurs options
48 function verifier_lister_disponibles(){
49 static $verifications = null;
51 if (is_null($verifications)){
52 $verifications = array();
53 $liste = find_all_in_path('verifier/', '.+[.]yaml$');
56 foreach ($liste as $fichier=>$chemin){
57 $type_verif = preg_replace(',[.]yaml$,i', '', $fichier);
58 $dossier = str_replace($fichier, '', $chemin);
59 // On ne garde que les vérifications qui ont bien la fonction !
60 if (charger_fonction($type_verif, 'verifier', true)
62 is_array($verif = verifier_charger_infos($type_verif))
65 $verifications[$type_verif] = $verif;
71 return $verifications;
75 * Charger les informations contenues dans le yaml d'une vérification
77 * @param string $type_verif Le type de la vérification
78 * @return array Un tableau contenant le YAML décodé
80 function verifier_charger_infos($type_verif){
81 include_spip('inc/yaml');
82 $fichier = find_in_path("verifier/$type_verif.yaml");
83 $verif = yaml_decode_file($fichier);
84 if (is_array($verif)){
85 $verif['titre'] = $verif['titre'] ?
_T_ou_typo($verif['titre']) : $type_verif;
86 $verif['description'] = $verif['description'] ?
_T_ou_typo($verif['description']) : '';
87 $verif['icone'] = $verif['icone'] ?
find_in_path($verif['icone']) : '';