[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / zen-garden / spip20 / plugins / verifie_conformite.php
1 <?php
2 /*
3 * Plugin xxx
4 * (c) 2009 cedric
5 * Distribue sous licence GPL
6 *
7 */
8
9 if (!defined("_ECRIRE_INC_VERSION")) return;
10
11 // http://doc.spip.org/@plugin_verifie_conformite
12 function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS){
13 $silence = false;
14 if (isset($arbre['plugin']) AND is_array($arbre['plugin']))
15 $arbre = end($arbre['plugin']); // derniere def plugin
16 else{
17 $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent')." : $plug/plugin.xml"));
18 $silence = true;
19 }
20 if (!is_array($arbre)) $arbre = array();
21 // verification de la conformite du plugin avec quelques
22 // precautions elementaires
23 if (!isset($arbre['nom'])){
24 if (!$silence)
25 $arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
26 $arbre['nom'] = array("");
27 }
28 if (!isset($arbre['version'])){
29 if (!$silence)
30 $arbre['erreur'][] = _T('erreur_plugin_version_manquant');
31 $arbre['version'] = array("");
32 }
33 if (!isset($arbre['prefix'])){
34 if (!$silence)
35 $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
36 $arbre['prefix'] = array("");
37 }
38 else{
39 $prefix = "";
40 $prefix = trim(end($arbre['prefix']));
41 if (strtoupper($prefix)=='SPIP'){
42 $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
43 }
44 if (isset($arbre['etat'])){
45 $etat = trim(end($arbre['etat']));
46 if (!in_array($etat,array('dev','experimental','test','stable')))
47 $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu')." : $etat";
48 }
49 if (isset($arbre['options'])){
50 foreach($arbre['options'] as $optfile){
51 $optfile = trim($optfile);
52 if (!@is_readable($dir_plugins."$plug/$optfile"))
53 if (!$silence)
54 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
55 }
56 }
57 if (isset($arbre['fonctions'])){
58 foreach($arbre['fonctions'] as $optfile){
59 $optfile = trim($optfile);
60 if (!@is_readable($dir_plugins."$plug/$optfile"))
61 if (!$silence)
62 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
63 }
64 }
65 $fonctions = array();
66 if (isset($arbre['fonctions']))
67 $fonctions = $arbre['fonctions'];
68 $liste_methodes_reservees = array('__construct','__destruct','plugin','install','uninstall',strtolower($prefix));
69 plugin_pipeline_props($arbre);
70 foreach($arbre['pipeline'] as $pipe){
71 if (!isset($pipe['nom']))
72 if (!$silence)
73 $arbre['erreur'][] = _T("erreur_plugin_nom_pipeline_non_defini");
74 if (isset($pipe['action'])) $action = $pipe['action'];
75 else $action = $pipe['nom'];
76 // verif que la methode a un nom autorise
77 if (in_array(strtolower($action),$liste_methodes_reservees)){
78 if (!$silence)
79 $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit")." : $action";
80 }
81 if (isset($pipe['inclure'])) {
82 $inclure = $dir_plugins."$plug/".$pipe['inclure'];
83 if (!@is_readable($inclure))
84 if (!$silence)
85 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $inclure";
86 }
87 }
88 $necessite = array();
89 if (spip_xml_match_nodes(',^necessite,',$arbre,$needs)){
90 foreach(array_keys($needs) as $tag){
91 list($tag,$att) = spip_xml_decompose_tag($tag);
92 $necessite[] = $att;
93 }
94 }
95 $arbre['necessite'] = $necessite;
96 $utilise = array();
97 if (spip_xml_match_nodes(',^utilise,',$arbre,$uses)){
98 foreach(array_keys($uses) as $tag){
99 list($tag,$att) = spip_xml_decompose_tag($tag);
100 $utilise[] = $att;
101 }
102 }
103 $arbre['utilise'] = $utilise;
104 $path = array();
105 if (spip_xml_match_nodes(',^chemin,',$arbre,$paths)){
106 foreach(array_keys($paths) as $tag){
107 list($tag,$att) = spip_xml_decompose_tag($tag);
108 $path[] = $att;
109 }
110 }
111 else
112 $path = array(array('dir'=>'')); // initialiser par defaut
113 $arbre['path'] = $path;
114 // exposer les noisettes
115 if (isset($arbre['noisette'])){
116 foreach($arbre['noisette'] as $k=>$nut){
117 $nut = preg_replace(',[.]html$,uims','',trim($nut));
118 $arbre['noisette'][$k] = $nut;
119 if (!@is_readable($dir_plugins."$plug/$nut.html"))
120 if (!$silence)
121 $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $nut";
122 }
123 }
124 }
125 }
126
127 include_spip('inc/plugin');
128 if (!function_exists('plugin_pipeline_props')){
129 // http://doc.spip.org/@plugin_pipeline_props
130 function plugin_pipeline_props(&$arbre){
131 $pipeline = array();
132 if (spip_xml_match_nodes(',^pipeline,',$arbre,$pipes)){
133 foreach($pipes as $tag=>$p){
134 if (!is_array($p[0])){
135 list($tag,$att) = spip_xml_decompose_tag($tag);
136 $pipeline[] = $att;
137 }
138 else foreach($p as $pipe){
139 $att = array();
140 if (is_array($pipe))
141 foreach($pipe as $k=>$t)
142 $att[$k] = trim(end($t));
143 $pipeline[] = $att;
144 }
145 }
146 unset($arbre[$tag]);
147 }
148 $arbre['pipeline'] = $pipeline;
149 }
150 }
151 ?>