3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2012 *
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')) return;
15 include_spip('inc/xml');
16 include_spip('inc/plugin');
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');
25 // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
26 if ($n = spip_xml_match_nodes(",^plugin(\s|$),", $arbre, $matches)){
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
36 if (!isset($atts['spip'])
38 OR plugin_version_compatible($atts['spip'],$vspip,'spip')) {
39 // on prend la derniere declaration avec ce nom
41 $compat_spip = isset($atts['spip']) ?
$atts['spip'] : '';
47 $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent')." : $plug"));
52 if (!is_array($arbre)) $arbre = array();
53 // verification de la conformite du plugin avec quelques
54 // precautions elementaires
55 if (!isset($arbre['nom'])){
57 $arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
58 $arbre['nom'] = array("");
60 if (!isset($arbre['version'])){
62 $arbre['erreur'][] = _T('erreur_plugin_version_manquant');
63 $arbre['version'] = array("");
65 if (!isset($arbre['prefix'])){
67 $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
68 $arbre['prefix'] = array("");
70 $prefix = trim(end($arbre['prefix']));
71 if (strtoupper($prefix)=='SPIP' AND $plug!="./"){
72 $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
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'";
79 if (isset($arbre['options'])){
80 foreach($arbre['options'] as $optfile){
81 $optfile = trim($optfile);
82 if (!@is_readable
($dir_plugins."$plug/$optfile"))
84 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
87 if (isset($arbre['fonctions'])){
88 foreach($arbre['fonctions'] as $optfile){
89 $optfile = trim($optfile);
90 if (!@is_readable
($dir_plugins."$plug/$optfile"))
92 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
96 if (isset($arbre['fonctions']))
97 $fonctions = $arbre['fonctions'];
98 $liste_methodes_reservees = array('__construct','__destruct','plugin','install','uninstall',strtolower($prefix));
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']))
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)){
111 $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit")." : $action";
113 if (isset($pipe['inclure'])) {
114 $inclure = $dir_plugins."$plug/".$pipe['inclure'];
115 if (!@is_readable
($inclure))
117 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $inclure";
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);
126 if (strtolower($att['id']) == 'spip')
130 if ($compat_spip AND !$spip_trouve)
131 $necessite[] = array('id' => 'spip', 'version' => $compat_spip);
132 $arbre['necessite'] = $necessite;
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);
140 $arbre['utilise'] = $utilise;
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);
148 $arbre['procure'] = $procure;
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
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"))
167 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $nut";
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);
177 $arbre['traduire'] = $traduire;