[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / plugins / verifie_conformite.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
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 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 include_spip('inc/xml');
16 include_spip('inc/plugin');
17
18 // http://doc.spip.org/@plugin_verifie_conformite
19 function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS){
20 static $etats = array('dev','experimental','test', 'stable');
21
22 $matches = array();
23 $silence = false;
24 $p = null;
25 // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
26 if ($n = spip_xml_match_nodes(",^plugin(\s|$),", $arbre, $matches)){
27 // version de SPIP
28 $vspip = $GLOBALS['spip_version_branche'];
29 foreach($matches as $tag=>$sous){
30 list($tagname,$atts) = spip_xml_decompose_tag($tag);
31 if ($tagname=='plugin' AND is_array($sous)){
32 // On rajoute la condition sur $n :
33 // -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait
34 // un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise
35 // de la meme facon.
36 if (!isset($atts['spip'])
37 OR $n==1
38 OR plugin_version_compatible($atts['spip'],$vspip,'spip')) {
39 // on prend la derniere declaration avec ce nom
40 $p = end($sous);
41 $compat_spip = isset($atts['spip']) ? $atts['spip'] : '';
42 }
43 }
44 }
45 }
46 if (is_null($p)){
47 $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent')." : $plug"));
48 $silence = true;
49 }
50 else
51 $arbre = $p;
52 if (!is_array($arbre)) $arbre = array();
53 // verification de la conformite du plugin avec quelques
54 // precautions elementaires
55 if (!isset($arbre['nom'])){
56 if (!$silence)
57 $arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
58 $arbre['nom'] = array("");
59 }
60 if (!isset($arbre['version'])){
61 if (!$silence)
62 $arbre['erreur'][] = _T('erreur_plugin_version_manquant');
63 $arbre['version'] = array("");
64 }
65 if (!isset($arbre['prefix'])){
66 if (!$silence)
67 $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
68 $arbre['prefix'] = array("");
69 } else{
70 $prefix = trim(end($arbre['prefix']));
71 if (strtoupper($prefix)=='SPIP' AND $plug!="./"){
72 $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
73 }
74 if (isset($arbre['etat'])){
75 $etat = trim(end($arbre['etat']));
76 if (!in_array($etat, $etats))
77 $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu')." : '$etat'";
78 }
79 if (isset($arbre['options'])){
80 foreach($arbre['options'] as $optfile){
81 $optfile = trim($optfile);
82 if (!@is_readable($dir_plugins."$plug/$optfile"))
83 if (!$silence)
84 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
85 }
86 }
87 if (isset($arbre['fonctions'])){
88 foreach($arbre['fonctions'] as $optfile){
89 $optfile = trim($optfile);
90 if (!@is_readable($dir_plugins."$plug/$optfile"))
91 if (!$silence)
92 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
93 }
94 }
95 $fonctions = array();
96 if (isset($arbre['fonctions']))
97 $fonctions = $arbre['fonctions'];
98 $liste_methodes_reservees = array('__construct','__destruct','plugin','install','uninstall',strtolower($prefix));
99
100 $extraire_pipelines = charger_fonction("extraire_pipelines","plugins");
101 $arbre['pipeline'] = $extraire_pipelines($arbre);
102 foreach($arbre['pipeline'] as $pipe){
103 if (!isset($pipe['nom']))
104 if (!$silence)
105 $arbre['erreur'][] = _T("erreur_plugin_nom_pipeline_non_defini");
106 if (isset($pipe['action'])) $action = $pipe['action'];
107 else $action = $pipe['nom'];
108 // verif que la methode a un nom autorise
109 if (in_array(strtolower($action),$liste_methodes_reservees)){
110 if (!$silence)
111 $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit")." : $action";
112 }
113 if (isset($pipe['inclure'])) {
114 $inclure = $dir_plugins."$plug/".$pipe['inclure'];
115 if (!@is_readable($inclure))
116 if (!$silence)
117 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $inclure";
118 }
119 }
120 $necessite = array();
121 $spip_trouve = false;
122 if (spip_xml_match_nodes(',^necessite,',$arbre,$needs)){
123 foreach(array_keys($needs) as $tag){
124 list($tag,$att) = spip_xml_decompose_tag($tag);
125 $necessite[] = $att;
126 if (strtolower($att['id']) == 'spip')
127 $spip_trouve = true;
128 }
129 }
130 if ($compat_spip AND !$spip_trouve)
131 $necessite[] = array('id' => 'spip', 'version' => $compat_spip);
132 $arbre['necessite'] = $necessite;
133 $utilise = array();
134 if (spip_xml_match_nodes(',^utilise,',$arbre,$uses)){
135 foreach(array_keys($uses) as $tag){
136 list($tag,$att) = spip_xml_decompose_tag($tag);
137 $utilise[] = $att;
138 }
139 }
140 $arbre['utilise'] = $utilise;
141 $procure = array();
142 if (spip_xml_match_nodes(',^procure,',$arbre,$uses)){
143 foreach(array_keys($uses) as $tag){
144 list($tag,$att) = spip_xml_decompose_tag($tag);
145 $procure[] = $att;
146 }
147 }
148 $arbre['procure'] = $procure;
149 $path = array();
150 if (spip_xml_match_nodes(',^chemin,',$arbre,$paths)){
151 foreach(array_keys($paths) as $tag){
152 list($tag,$att) = spip_xml_decompose_tag($tag);
153 $att['path'] = $att['dir']; // ancienne syntaxe
154 $path[] = $att;
155 }
156 }
157 else
158 $path = array(array('dir'=>'')); // initialiser par defaut
159 $arbre['path'] = $path;
160 // exposer les noisettes
161 if (isset($arbre['noisette'])){
162 foreach($arbre['noisette'] as $k=>$nut){
163 $nut = preg_replace(',[.]html$,uims','',trim($nut));
164 $arbre['noisette'][$k] = $nut;
165 if (!@is_readable($dir_plugins."$plug/$nut.html"))
166 if (!$silence)
167 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $nut";
168 }
169 }
170 $traduire = array();
171 if (spip_xml_match_nodes(',^traduire,',$arbre,$trads)){
172 foreach(array_keys($trads) as $tag){
173 list($tag,$att) = spip_xml_decompose_tag($tag);
174 $traduire[] = $att;
175 }
176 }
177 $arbre['traduire'] = $traduire;
178 }
179 }
180
181 ?>