4 if (!defined('_ECRIRE_INC_VERSION')) {
9 * Fonction de base de l'API de vérification.
10 * @param mixed $valeur La valeur a verifier.
11 * @param string $type Le type de verification a appliquer.
12 * @param array $options Un eventuel tableau d'options suivant le type.
13 * @param array $valeur_normalisee
14 * Si des options de verification modifient la valeur entrante (normalisent),
15 * alors la valeur modifie sera stockee dans cette variable.
16 * @return string Retourne une chaine vide si c'est valide, sinon une chaine expliquant l'erreur.
18 function inc_verifier_dist($valeur, $type, $options = null, &$valeur_normalisee = null) {
21 // On vérifie que les options sont bien un tableau
22 if (!is_array($options)) {
26 // Si la valeur est vide, il n'y a rien a verifier donc c'est bon
27 if (is_null($valeur) or (is_string($valeur) and $valeur == '')) {
30 // Si c'est une date avec horaire c'est un tableau
31 if (is_array($valeur) and isset($valeur['date']) and $valeur['date'] == '') {
35 // On cherche si une fonction correspondant au type existe
36 if ($verifier = charger_fonction($type, 'verifier', true)) {
37 $erreur = $verifier($valeur, $options, $valeur_normalisee);
40 // On passe le tout dans le pipeline du meme nom
47 'options' => $options,
57 * Liste toutes les vérifications possibles
59 * @param string $repertoire
60 * Dans quel repertoire chercher les yaml.
62 * @return array Retourne un tableau listant les vérifications et leurs options
64 function verifier_lister_disponibles($repertoire = 'verifier') {
65 static $verifications = array();
67 if (!isset($verifications[$repertoire])) {
68 $verifications[$repertoire] = array();
69 $liste = find_all_in_path("$repertoire/", '.+[.]yaml$');
72 foreach ($liste as $fichier => $chemin) {
73 $type = preg_replace(',[.]yaml$,i', '', $fichier);
74 $dossier = str_replace($fichier, '', $chemin);
75 // On ne garde que les vérifications qui ont bien la fonction !
76 if (charger_fonction($type, $repertoire, true)
78 is_array($verif = verifier_charger_infos($type, $repertoire))
81 $verifications[$repertoire][$type] = $verif;
87 return $verifications[$repertoire];
91 * Fonction de callback pour uasort()
92 * Afin de trier selon le titre
93 * @param array $array1 premier élèment
94 * @param array $array2 second élèment
97 function verifier_trier_par_titre($array1,$array2) {
98 if (isset($array1['titre']) and isset($array2['titre'])) {
99 if ($array1['titre'] == $array2['titre']) {
101 } elseif ($array1['titre'] > $array2['titre']) {
112 * Charger les informations contenues dans le yaml d'une vérification
114 * @param string $type_verif
115 * Le type de la vérification
117 * @param string $repertoire
118 * Dans quel repertoire chercher les yaml.
120 * @return array Un tableau contenant le YAML décodé
122 function verifier_charger_infos($type_verif, $repertoire = 'verifier') {
125 if (defined('_DIR_PLUGIN_YAML')) {
126 include_spip('inc/yaml');
127 $fichier = find_in_path("$repertoire/$type_verif.yaml");
129 $verif = yaml_decode_file($fichier);
130 if (is_array($verif)) {
131 $verif['titre'] = (isset($verif['titre']) and $verif['titre']) ?
_T_ou_typo($verif['titre']) : $type_verif;
132 $verif['description'] = (isset($verif['description']) and $verif['description']) ?
_T_ou_typo($verif['description']) : '';
133 $verif['icone'] = (isset($verif['icone']) and $verif['icone']) ?
_T_ou_typo($verif['icone']) : '';