6f2b900629f610b6ba3d7cc31b2b5b800cc12cb0
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2019 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) {
17 include_spip('inc/xml');
18 include_spip('inc/plugin');
20 // http://code.spip.net/@plugin_verifie_conformite
21 function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS
) {
22 static $etats = array('dev', 'experimental', 'test', 'stable');
27 // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
28 if ($n = spip_xml_match_nodes(",^plugin(\s|$),", $arbre, $matches)) {
30 $vspip = $GLOBALS['spip_version_branche'];
31 foreach ($matches as $tag => $sous) {
32 list($tagname, $atts) = spip_xml_decompose_tag($tag);
33 if ($tagname == 'plugin' and is_array($sous)) {
34 // On rajoute la condition sur $n :
35 // -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait
36 // un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise
38 if (!isset($atts['spip'])
40 or plugin_version_compatible($atts['spip'], $vspip, 'spip')
42 // on prend la derniere declaration avec ce nom
44 $compat_spip = isset($atts['spip']) ?
$atts['spip'] : '';
50 $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent') . " : $plug"));
55 if (!is_array($arbre)) {
58 // verification de la conformite du plugin avec quelques
59 // precautions elementaires
60 if (!isset($arbre['nom'])) {
62 $arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
64 $arbre['nom'] = array("");
66 if (!isset($arbre['version'])) {
68 $arbre['erreur'][] = _T('erreur_plugin_version_manquant');
70 $arbre['version'] = array("");
72 if (!isset($arbre['prefix'])) {
74 $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
76 $arbre['prefix'] = array("");
78 $prefix = trim(end($arbre['prefix']));
79 if (strtoupper($prefix) == 'SPIP' and $plug != "./") {
80 $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
82 if (isset($arbre['etat'])) {
83 $etat = trim(end($arbre['etat']));
84 if (!in_array($etat, $etats)) {
85 $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '$etat'";
88 if (isset($arbre['options'])) {
89 foreach ($arbre['options'] as $optfile) {
90 $optfile = trim($optfile);
91 if (!@is_readable
($dir_plugins . "$plug/$optfile")) {
93 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
98 if (isset($arbre['fonctions'])) {
99 foreach ($arbre['fonctions'] as $optfile) {
100 $optfile = trim($optfile);
101 if (!@is_readable
($dir_plugins . "$plug/$optfile")) {
103 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
108 $fonctions = array();
109 if (isset($arbre['fonctions'])) {
110 $fonctions = $arbre['fonctions'];
112 $liste_methodes_reservees = array(
121 $extraire_pipelines = charger_fonction("extraire_pipelines", "plugins");
122 $arbre['pipeline'] = $extraire_pipelines($arbre);
123 foreach ($arbre['pipeline'] as $pipe) {
124 if (!isset($pipe['nom'])) {
126 $arbre['erreur'][] = _T("erreur_plugin_nom_pipeline_non_defini");
129 if (isset($pipe['action'])) {
130 $action = $pipe['action'];
132 $action = $pipe['nom'];
134 // verif que la methode a un nom autorise
135 if (in_array(strtolower($action), $liste_methodes_reservees)) {
137 $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit") . " : $action";
140 if (isset($pipe['inclure'])) {
141 $inclure = $dir_plugins . "$plug/" . $pipe['inclure'];
142 if (!@is_readable
($inclure)) {
144 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $inclure";
149 $necessite = array();
150 $spip_trouve = false;
151 if (spip_xml_match_nodes(',^necessite,', $arbre, $needs)) {
152 foreach (array_keys($needs) as $tag) {
153 list($tag, $att) = spip_xml_decompose_tag($tag);
154 if (!isset($att['id'])) {
156 $arbre['erreur'][] = _T('erreur_plugin_attribut_balise_manquant',
157 array('attribut' => 'id', 'balise' => $att));
162 if (strtolower($att['id']) == 'spip') {
167 if ($compat_spip and !$spip_trouve) {
168 $necessite[] = array('id' => 'spip', 'version' => $compat_spip);
170 $arbre['necessite'] = $necessite;
172 if (spip_xml_match_nodes(',^utilise,', $arbre, $uses)) {
173 foreach (array_keys($uses) as $tag) {
174 list($tag, $att) = spip_xml_decompose_tag($tag);
175 if (!isset($att['id'])) {
177 $arbre['erreur'][] = _T('erreur_plugin_attribut_balise_manquant',
178 array('attribut' => 'id', 'balise' => $att));
185 $arbre['utilise'] = $utilise;
187 if (spip_xml_match_nodes(',^procure,', $arbre, $uses)) {
188 foreach (array_keys($uses) as $tag) {
189 list($tag, $att) = spip_xml_decompose_tag($tag);
193 $arbre['procure'] = $procure;
195 if (spip_xml_match_nodes(',^chemin,', $arbre, $paths)) {
196 foreach (array_keys($paths) as $tag) {
197 list($tag, $att) = spip_xml_decompose_tag($tag);
198 $att['path'] = $att['dir']; // ancienne syntaxe
202 $path = array(array('dir' => ''));
203 } // initialiser par defaut
204 $arbre['path'] = $path;
205 // exposer les noisettes
206 if (isset($arbre['noisette'])) {
207 foreach ($arbre['noisette'] as $k => $nut) {
208 $nut = preg_replace(',[.]html$,uims', '', trim($nut));
209 $arbre['noisette'][$k] = $nut;
210 if (!@is_readable
($dir_plugins . "$plug/$nut.html")) {
212 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $nut";
218 if (spip_xml_match_nodes(',^traduire,', $arbre, $trads)) {
219 foreach (array_keys($trads) as $tag) {
220 list($tag, $att) = spip_xml_decompose_tag($tag);
224 $arbre['traduire'] = $traduire;