PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/spip/ecrire/plugins/verifie_conformite.php

https://github.com/eyeswebcrea/espace-couture-sittler.fr
PHP | 167 lines | 143 code | 7 blank | 17 comment | 41 complexity | 1742c874595a0a0f66aa1beddcbfa683 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2011 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined('_ECRIRE_INC_VERSION')) return;
  12. include_spip('inc/xml');
  13. include_spip('inc/plugin');
  14. // http://doc.spip.org/@plugin_verifie_conformite
  15. function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS){
  16. static $etats = array('dev','experimental','test', 'stable');
  17. $matches = array();
  18. $silence = false;
  19. $p = null;
  20. // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
  21. if ($n = spip_xml_match_nodes(",^plugin(\s|$),", $arbre, $matches)){
  22. // version de SPIP
  23. $vspip = $GLOBALS['spip_version_branche'];
  24. foreach($matches as $tag=>$sous){
  25. list($tagname,$atts) = spip_xml_decompose_tag($tag);
  26. if ($tagname=='plugin' AND is_array($sous)){
  27. if (!isset($atts['spip'])
  28. OR plugin_version_compatible($atts['spip'],$vspip)) {
  29. // on prend la derniere declaration avec ce nom
  30. $p = end($sous);
  31. $compat_spip = isset($atts['spip']) ? $atts['spip'] : '';
  32. }
  33. }
  34. }
  35. }
  36. if (is_null($p)){
  37. $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent')." : $plug"));
  38. $silence = true;
  39. }
  40. else
  41. $arbre = $p;
  42. if (!is_array($arbre)) $arbre = array();
  43. // verification de la conformite du plugin avec quelques
  44. // precautions elementaires
  45. if (!isset($arbre['nom'])){
  46. if (!$silence)
  47. $arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
  48. $arbre['nom'] = array("");
  49. }
  50. if (!isset($arbre['version'])){
  51. if (!$silence)
  52. $arbre['erreur'][] = _T('erreur_plugin_version_manquant');
  53. $arbre['version'] = array("");
  54. }
  55. if (!isset($arbre['prefix'])){
  56. if (!$silence)
  57. $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
  58. $arbre['prefix'] = array("");
  59. } else{
  60. $prefix = trim(end($arbre['prefix']));
  61. if (strtoupper($prefix)=='SPIP'){
  62. $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
  63. }
  64. if (isset($arbre['etat'])){
  65. $etat = trim(end($arbre['etat']));
  66. if (!in_array($etat, $etats))
  67. $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu')." : '$etat'";
  68. }
  69. if (isset($arbre['options'])){
  70. foreach($arbre['options'] as $optfile){
  71. $optfile = trim($optfile);
  72. if (!@is_readable($dir_plugins."$plug/$optfile"))
  73. if (!$silence)
  74. $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
  75. }
  76. }
  77. if (isset($arbre['fonctions'])){
  78. foreach($arbre['fonctions'] as $optfile){
  79. $optfile = trim($optfile);
  80. if (!@is_readable($dir_plugins."$plug/$optfile"))
  81. if (!$silence)
  82. $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
  83. }
  84. }
  85. $fonctions = array();
  86. if (isset($arbre['fonctions']))
  87. $fonctions = $arbre['fonctions'];
  88. $liste_methodes_reservees = array('__construct','__destruct','plugin','install','uninstall',strtolower($prefix));
  89. $extraire_pipelines = charger_fonction("extraire_pipelines","plugins");
  90. $arbre['pipeline'] = $extraire_pipelines($arbre);
  91. foreach($arbre['pipeline'] as $pipe){
  92. if (!isset($pipe['nom']))
  93. if (!$silence)
  94. $arbre['erreur'][] = _T("erreur_plugin_nom_pipeline_non_defini");
  95. if (isset($pipe['action'])) $action = $pipe['action'];
  96. else $action = $pipe['nom'];
  97. // verif que la methode a un nom autorise
  98. if (in_array(strtolower($action),$liste_methodes_reservees)){
  99. if (!$silence)
  100. $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit")." : $action";
  101. }
  102. if (isset($pipe['inclure'])) {
  103. $inclure = $dir_plugins."$plug/".$pipe['inclure'];
  104. if (!@is_readable($inclure))
  105. if (!$silence)
  106. $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $inclure";
  107. }
  108. }
  109. $necessite = array();
  110. $spip_trouve = false;
  111. if (spip_xml_match_nodes(',^necessite,',$arbre,$needs)){
  112. foreach(array_keys($needs) as $tag){
  113. list($tag,$att) = spip_xml_decompose_tag($tag);
  114. $necessite[] = $att;
  115. if (strtolower($att['id']) == 'spip')
  116. $spip_trouve = true;
  117. }
  118. }
  119. if ($compat_spip AND !$spip_trouve)
  120. $necessite[] = array('id' => 'spip', 'version' => $compat_spip);
  121. $arbre['necessite'] = $necessite;
  122. $utilise = array();
  123. if (spip_xml_match_nodes(',^utilise,',$arbre,$uses)){
  124. foreach(array_keys($uses) as $tag){
  125. list($tag,$att) = spip_xml_decompose_tag($tag);
  126. $utilise[] = $att;
  127. }
  128. }
  129. $arbre['utilise'] = $utilise;
  130. $path = array();
  131. if (spip_xml_match_nodes(',^chemin,',$arbre,$paths)){
  132. foreach(array_keys($paths) as $tag){
  133. list($tag,$att) = spip_xml_decompose_tag($tag);
  134. $path[] = $att;
  135. }
  136. }
  137. else
  138. $path = array(array('dir'=>'')); // initialiser par defaut
  139. $arbre['path'] = $path;
  140. // exposer les noisettes
  141. if (isset($arbre['noisette'])){
  142. foreach($arbre['noisette'] as $k=>$nut){
  143. $nut = preg_replace(',[.]html$,uims','',trim($nut));
  144. $arbre['noisette'][$k] = $nut;
  145. if (!@is_readable($dir_plugins."$plug/$nut.html"))
  146. if (!$silence)
  147. $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $nut";
  148. }
  149. }
  150. $traduire = array();
  151. if (spip_xml_match_nodes(',^traduire,',$arbre,$trads)){
  152. foreach(array_keys($trads) as $tag){
  153. list($tag,$att) = spip_xml_decompose_tag($tag);
  154. $traduire[] = $att;
  155. }
  156. }
  157. $arbre['traduire'] = $traduire;
  158. }
  159. }
  160. ?>