1 | <?php |
---|
2 | |
---|
3 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
4 | |
---|
5 | // Fonctions analysant les fichiers plugin.xml et archives.xml en decoulant |
---|
6 | // Il faudrait aussi admettre les fichiers paquet.xml de la 2.2 |
---|
7 | |
---|
8 | include_spip('inc/xml'); |
---|
9 | |
---|
10 | function step_get_infos_plugin($constante, $p, $actifs, $recents) { |
---|
11 | if($constante == '_DIR_PLUGINS_SUPPL') |
---|
12 | $dir = _DIR_RACINE.constant($constante); |
---|
13 | else |
---|
14 | $dir = constant($constante); |
---|
15 | lire_fichier($dir . $p . '/plugin.xml', $xml); |
---|
16 | // enlever la balise doctype qui provoque une erreur "balise non fermee" |
---|
17 | $xml = preg_replace('#<!DOCTYPE[^>]*>#','',$xml); |
---|
18 | // traduire le xml en php |
---|
19 | //spip_log("spip_get_infos $dir $p"); |
---|
20 | if (!is_array($plugin = spip_xml_parse($xml))) return; |
---|
21 | |
---|
22 | // [extrait] de plugins/verifie_conformite.php |
---|
23 | // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP |
---|
24 | if (!spip_xml_match_nodes(",^plugin(\s|$),", $plugin, $matches)) |
---|
25 | return ''; |
---|
26 | |
---|
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 | if (!isset($atts['spip']) |
---|
33 | OR plugin_version_compatible($atts['spip'], $vspip)) |
---|
34 | // on prend la derniere declaration avec ce nom |
---|
35 | $plugin = end($sous); |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | // [/extrait] de plugins/verifie_conformite.php |
---|
40 | |
---|
41 | // applatir les champs du plugin (ie les balises <multi> sont des chaines...) |
---|
42 | return step_xml_parse_plugin($plugin); |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | // parse un fichier de source dont l'url est donnee |
---|
47 | // ce fichier est un fichier XML contenant <zone><zone_elt/></zone> |
---|
48 | function step_xml_parse_zone($xml){ |
---|
49 | |
---|
50 | // enlever la balise doctype qui provoque une erreur "balise non fermee" |
---|
51 | $xml = preg_replace('#<!DOCTYPE[^>]*>#','',$xml); |
---|
52 | if (!is_array($arbre = spip_xml_parse($xml)) OR !is_array($arbre = $arbre['archives'][0])){ |
---|
53 | return false; |
---|
54 | } |
---|
55 | |
---|
56 | // boucle sur les elements pour creer un tableau array (url_zip => datas) |
---|
57 | $paquets = array(); |
---|
58 | foreach ($arbre as $z=>$c){ |
---|
59 | $c = $c[0]; |
---|
60 | // si plugin et fichier zip, on ajoute le paquet dans la liste |
---|
61 | if ((is_array($c['plugin'])) AND ($url = $c['zip'][0]['file'][0])) { |
---|
62 | $paquets[$url] = array( |
---|
63 | 'plugin' => step_xml_parse_plugin($c['plugin'][0]), |
---|
64 | 'file' => $url, |
---|
65 | ); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | if (!$paquets) { |
---|
70 | return false; |
---|
71 | } |
---|
72 | |
---|
73 | return $paquets; |
---|
74 | } |
---|
75 | |
---|
76 | // aplatit plusieurs cles d'un arbre xml dans un tableau |
---|
77 | // effectue un trim() au passage |
---|
78 | function step_xml_aplatit_multiple($array, $arbre){ |
---|
79 | $a = array(); |
---|
80 | // array('uri','archive'=>'zip',...) |
---|
81 | foreach ($array as $i=>$n){ |
---|
82 | if (is_string($i)) $cle = $i; |
---|
83 | else $cle = $n; |
---|
84 | $a[$n] = trim(spip_xml_aplatit($arbre[$cle])); |
---|
85 | } |
---|
86 | return $a; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | // parse un plugin.xml genere par spip_xml_parse() |
---|
91 | // en un tableau plus facilement utilisable |
---|
92 | // cette fonction doit permettre de mapper des changements |
---|
93 | // de syntaxe entre plugin.xml et step |
---|
94 | function step_xml_parse_plugin($arbre){ |
---|
95 | |
---|
96 | if (!is_array($arbre)) |
---|
97 | return false; |
---|
98 | |
---|
99 | // on commence par les simples ! |
---|
100 | $plug_arbre = step_xml_aplatit_multiple( |
---|
101 | array('nom','icon','auteur','licence','version','version_base','etat','shortdesc','slogan','categorie','tags', |
---|
102 | 'description','lien','options','fonctions','prefix','install'), |
---|
103 | $arbre); |
---|
104 | $plug_arbre['prefix'] = strtolower($plug_arbre['prefix']); |
---|
105 | |
---|
106 | // on continue avec les plus complexes... |
---|
107 | // 1) balises avec attributs |
---|
108 | foreach (array( |
---|
109 | 'necessite'=>array('necessite', null), |
---|
110 | 'utilise'=>array('utilise', null), |
---|
111 | 'chemin'=>array('path', array('dir'=>''))) |
---|
112 | as $balise=>$p){ |
---|
113 | $params = $res = array(); |
---|
114 | // recherche de la balise et extraction des attributs |
---|
115 | if (spip_xml_match_nodes(",^$balise,",$arbre, $res)){ |
---|
116 | foreach(array_keys($res) as $tag){ |
---|
117 | list($tag,$att) = spip_xml_decompose_tag($tag); |
---|
118 | $params[] = $att; |
---|
119 | } |
---|
120 | } |
---|
121 | // valeur par defaut |
---|
122 | else { |
---|
123 | if ($p[1]!==null) |
---|
124 | $params[] = $p[1]; |
---|
125 | } |
---|
126 | $plug_arbre[$p[0]] = $params; |
---|
127 | } |
---|
128 | |
---|
129 | // 2) balises impriquees |
---|
130 | // (pipeline, boutons, onglets) |
---|
131 | // on verra plus tard si besoin ! |
---|
132 | |
---|
133 | return $plug_arbre; |
---|
134 | } |
---|
135 | |
---|
136 | ?> |
---|