[5] | 1 | <?php |
---|
| 2 | // --------------------------------------------------------------------- |
---|
| 3 | // |
---|
| 4 | // Sktheme : manage themes under SPIP (squelettes + habillages) |
---|
| 5 | // |
---|
| 6 | // Copyright (c) 2006 - Skedus |
---|
| 7 | // |
---|
| 8 | // This program is free software; you can redistribute it and/or modify |
---|
| 9 | // it under the terms of the GNU General Public License as published by |
---|
| 10 | // the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | // (at your option) any later version. |
---|
| 12 | // |
---|
| 13 | // You should have received a copy of the GNU General Public License |
---|
| 14 | // along with this program; |
---|
| 15 | // |
---|
| 16 | // --------------------------------------------------------------------- |
---|
| 17 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
| 18 | |
---|
| 19 | function sktheme_xml_get_infos($xml_dir,$xml_type){ |
---|
| 20 | |
---|
| 21 | include_spip('inc/plugin'); |
---|
| 22 | |
---|
| 23 | $ret = array(); |
---|
| 24 | if ((@file_exists($xml_dir))&&(is_dir($xml_dir))){ |
---|
| 25 | if (@file_exists($xml_dir."/$xml_type.xml")) { |
---|
| 26 | lire_fichier($xml_dir."/$xml_type.xml", $texte); |
---|
| 27 | $arbre = parse_plugin_xml($texte); |
---|
| 28 | if (!isset($arbre[$xml_type])&&is_array($arbre[$xml_type])) |
---|
| 29 | $arbre = array('erreur' => array(_T('erreur_plugin_fichier_def_incorrect')." : $xml_dir/$xml_type.xml")); |
---|
| 30 | } |
---|
| 31 | else { |
---|
| 32 | // pour arriver ici on l'a vraiment cherche... |
---|
| 33 | //debug echo "error: erreur_plugin_fichier_def_absent $xml_dir/$xml_type.xml<br>"; |
---|
| 34 | $arbre = array('erreur' => array(_T('erreur_plugin_fichier_def_absent')." : $xml_dir/$xml_type.xml")); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | sktheme_xml_verifie_conformite($xml_dir,$xml_type,$arbre); |
---|
| 38 | |
---|
| 39 | $ret['nom'] = applatit_arbre($arbre['nom']); |
---|
| 40 | $ret['version'] = trim(end($arbre['version'])); |
---|
| 41 | if (isset($arbre['auteur'])) |
---|
| 42 | $ret['auteur'] = applatit_arbre($arbre['auteur']); |
---|
| 43 | if (isset($arbre['description'])) |
---|
| 44 | $ret['description'] = applatit_arbre($arbre['description']); |
---|
| 45 | if (isset($arbre['lien'])) |
---|
| 46 | $ret['lien'] = join(' ',$arbre['lien']); |
---|
| 47 | if (isset($arbre['etat'])) |
---|
| 48 | $ret['etat'] = trim(end($arbre['etat'])); |
---|
| 49 | if (isset($arbre['options'])) |
---|
| 50 | $ret['options'] = $arbre['options']; |
---|
| 51 | if (isset($arbre['fonctions'])) |
---|
| 52 | $ret['fonctions'] = $arbre['fonctions']; |
---|
| 53 | $ret['prefix'] = $arbre['prefix']; |
---|
| 54 | if (isset($arbre['pipeline'])) |
---|
| 55 | $ret['pipeline'] = $arbre['pipeline']; |
---|
| 56 | if (isset($arbre['erreur'])) |
---|
| 57 | $ret['erreur'] = $arbre['erreur']; |
---|
| 58 | if (isset($arbre['squelettes'])) { |
---|
| 59 | $ret['squelettes'] = $arbre['squelettes']; |
---|
| 60 | } |
---|
| 61 | if (isset($arbre['type'])) { |
---|
| 62 | $ret['type'] = trim(applatit_arbre($arbre['type'])); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | // Compute extra values |
---|
| 66 | $etat = 'dev'; |
---|
| 67 | if (isset($ret['etat'])) |
---|
| 68 | $etat = $ret['etat']; |
---|
| 69 | switch ($etat) { |
---|
| 70 | case 'experimental': |
---|
| 71 | $puce = 'puce-rouge.gif'; |
---|
| 72 | $titre_etat = _T('plugin_etat_experimental'); |
---|
| 73 | break; |
---|
| 74 | case 'test': |
---|
| 75 | $puce = 'puce-orange.gif'; |
---|
| 76 | $titre_etat = _T('plugin_etat_test'); |
---|
| 77 | break; |
---|
| 78 | case 'stable': |
---|
| 79 | $puce = 'puce-verte.gif'; |
---|
| 80 | $titre_etat = _T('plugin_etat_stable'); |
---|
| 81 | break; |
---|
| 82 | default: |
---|
| 83 | $puce = 'puce-poubelle.gif'; |
---|
| 84 | $titre_etat = _T('plugin_etat_developpement'); |
---|
| 85 | break; |
---|
| 86 | } |
---|
| 87 | $ret['extra_puce'] = $puce; |
---|
| 88 | $ret['extra_img_puce'] = "<img src='"._DIR_IMG_PACK."$puce' width='9' height='9' style='border:0;' alt=\"$titre_etat\" title=\"$titre_etat\" /> "; |
---|
| 89 | $ret['extra_titre_etat'] = $titre_etat; |
---|
| 90 | } |
---|
| 91 | return $ret; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | function sktheme_xml_verifie_conformite($xml_dir,$xml_type="plugin",&$arbre){ |
---|
| 95 | $silence = false; |
---|
| 96 | if (isset($arbre[$xml_type])&&is_array($arbre[$xml_type])) |
---|
| 97 | $arbre = end($arbre[$xml_type]); // derniere def xml_type |
---|
| 98 | else{ |
---|
| 99 | $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent')." : $xml_dir/plugin.xml")); |
---|
| 100 | $silence = true; |
---|
| 101 | } |
---|
| 102 | // verification de la conformite du plugin avec quelques |
---|
| 103 | // precautions elementaires |
---|
| 104 | if (!isset($arbre['nom'])){ |
---|
| 105 | if (!$silence) |
---|
| 106 | $arbre['erreur'][] = _T('erreur_plugin_nom_manquant'); |
---|
| 107 | $arbre['nom'] = array(""); |
---|
| 108 | } |
---|
| 109 | if (!isset($arbre['version'])){ |
---|
| 110 | if (!$silence) |
---|
| 111 | $arbre['erreur'][] = _T('erreur_plugin_version_manquant'); |
---|
| 112 | $arbre['version'] = array(""); |
---|
| 113 | } |
---|
| 114 | if (!isset($arbre['prefix'])){ |
---|
| 115 | if (!$silence) |
---|
| 116 | $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant'); |
---|
| 117 | $arbre['prefix'] = array(""); |
---|
| 118 | } |
---|
| 119 | else{ |
---|
| 120 | $prefix = ""; |
---|
| 121 | $prefix = trim(end($arbre['prefix'])); |
---|
| 122 | if (isset($arbre['etat'])){ |
---|
| 123 | $etat = trim(end($arbre['etat'])); |
---|
| 124 | if (!preg_match(',^(dev|experimental|test|stable)$,',$etat)) |
---|
| 125 | $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu')." : $etat"; |
---|
| 126 | } |
---|
| 127 | if (isset($arbre['options'])){ |
---|
| 128 | foreach($arbre['options'] as $optfile){ |
---|
| 129 | $optfile = trim($optfile); |
---|
| 130 | if (!@is_readable(_DIR_PLUGINS."$xml_dir/$optfile")) |
---|
| 131 | if (!$silence) |
---|
| 132 | $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile"; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | if (isset($arbre['fonctions'])){ |
---|
| 136 | foreach($arbre['fonctions'] as $optfile){ |
---|
| 137 | $optfile = trim($optfile); |
---|
| 138 | if (!@is_readable(_DIR_PLUGINS."$xml_dir/$optfile")) |
---|
| 139 | if (!$silence) |
---|
| 140 | $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile"; |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | $fonctions = array(); |
---|
| 144 | if (isset($arbre['fonctions'])) |
---|
| 145 | $fonctions = $arbres['fonctions']; |
---|
| 146 | $liste_methodes_reservees = array('__construct','__destruct','plugin','install','uninstall',strtolower($prefix)); |
---|
| 147 | if (is_array($arbre['pipeline'])){ |
---|
| 148 | foreach($arbre['pipeline'] as $pipe){ |
---|
| 149 | $nom = trim(end($pipe['nom'])); |
---|
| 150 | if (isset($pipe['action'])) |
---|
| 151 | $action = trim(end($pipe['action'])); |
---|
| 152 | else |
---|
| 153 | $action = $nom; |
---|
| 154 | // verif que la methode a un nom autorise |
---|
| 155 | if (in_array(strtolower($action),$liste_methodes_reservees)){ |
---|
| 156 | if (!$silence) |
---|
| 157 | $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit")." : $action"; |
---|
| 158 | } |
---|
| 159 | else{ |
---|
| 160 | // verif que le fichier de def est bien present |
---|
| 161 | if (isset($pipe['inclure'])){ |
---|
| 162 | $inclure = _DIR_PLUGINS."$xml_dir/".end($pipe['inclure']); |
---|
| 163 | if (!@is_readable($inclure)) |
---|
| 164 | if (!$silence) |
---|
| 165 | $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $inclure"; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | ?> |
---|