PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/class/class_plugins.php

http://malleo-cms.googlecode.com/
PHP | 130 lines | 87 code | 11 blank | 32 comment | 20 complexity | 3b694793ba7594f3c29269029c76bc21 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. |------------------------------------------------------------------------------------------------------------
  4. | Software: Malleo ( CMS )
  5. | Contact: SP - http://www.malleo-cms.com
  6. | Support: http://www.malleo-cms.com?module=forum
  7. | Documentation : Support: http://www.malleo-cms.com?module=wiki
  8. |------------------------------------------------------------------------------------------------------------
  9. | Author: Stephane RAJALU
  10. | Copyright (c) 2008-2009, Stephane RAJALU All Rights Reserved
  11. |------------------------------------------------------------------------------------------------------------
  12. | License: Distributed under the CECILL V2 License
  13. | This program is distributed in the hope that it will be useful - WITHOUT
  14. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. | FITNESS FOR A PARTICULAR PURPOSE.
  16. |
  17. | Please read Licence_CeCILL_V2-en.txt
  18. | SVP lisez Licence_CeCILL_V2-fr.txt
  19. |------------------------------------------------------------------------------------------------------------
  20. */
  21. if ( !defined('PROTECT') )
  22. {
  23. die("Tentative de Hacking");
  24. }
  25. class plugins
  26. {
  27. var $liste_plugins = '';
  28. function get_liste_plugins($force=false){
  29. global $cache;
  30. if ($force==true){
  31. $this->liste_plugins = $cache->appel_cache('listing_plugins',true);
  32. }elseif (!isset($this->liste_plugins) || empty($this->liste_plugins))
  33. {
  34. $this->liste_plugins = $cache->appel_cache('listing_plugins');
  35. }
  36. return $this->liste_plugins;
  37. }
  38. //
  39. // Execute les requetes SQL situees dans plugins/modules/Nom_Du_Module/infos.xml
  40. // dans la structure <module><install><requete>CREATE ... </requete><requete>UPDATE ... </requete>...
  41. function install_plugin($plugin,$type){
  42. global $root,$c,$cf,$liste_plugins,$cache,$prefixe;
  43. $dir_plug = ($type==0)? 'modules':'blocs';
  44. $file = $root.'plugins/'.$dir_plug.'/'.$plugin.'/infos.xml';
  45. $this->get_liste_plugins();
  46. if (!array_key_exists($plugin, $this->liste_plugins) && file_exists($file)){
  47. $xml = simplexml_load_file($file);
  48. $this->declarer_plugin($plugin,$type,$xml->version);
  49. if (is_object($xml->install) && is_object($xml->install->requete)){
  50. foreach($xml->install->requete as $sql){
  51. // On remplace le prefixe par celui définis par l'auteur du mod
  52. if (is_object($xml->prefixe) && $xml->prefixe != ''){
  53. $sql = preg_replace('#([` ])'.$xml->prefixe.'#i','\\1'.$prefixe,$sql);
  54. // A defaut de précision, on consid?re que le prefixe est a_
  55. }else{
  56. $sql = preg_replace('#([` ])a_#i','\\1'.$prefixe,$sql);
  57. }
  58. if (!$resultat=$c->sql_query($sql)) message_die(E_ERROR,31,__FILE__,__LINE__,$sql);
  59. }
  60. }
  61. $cache->purger_cache();
  62. }
  63. }
  64. //
  65. // Declare le module dans la table plugins
  66. function declarer_plugin($plugin,$type,$version){
  67. global $c,$cache,$cf;
  68. $sql = 'INSERT INTO '.TABLE_PLUGINS.' (plugin, type, version) VALUES ("'.$plugin.'",'.$type.',"'.$version.'")';
  69. if (!$resultat=$c->sql_query($sql)) message_die(E_ERROR,31,__FILE__,__LINE__,$sql);
  70. $this->get_liste_plugins(true);
  71. }
  72. //
  73. // Update le plugin specifie en parametre
  74. function update_plugin($plugin,$type){
  75. global $root,$c;
  76. $this->get_liste_plugins();
  77. // RECUPERATION de la VERSION courante
  78. $version_courante = $this->liste_plugins[$plugin]['version'];
  79. $version_atteinte = $version_courante;
  80. $extract = array();
  81. $dir_plug = ($type==0)? 'modules':'blocs';
  82. $file = $root.'plugins/'.$dir_plug.'/'.$plugin.'/infos.xml';
  83. $xml = simplexml_load_file($file);
  84. $version_finale = $xml->version;
  85. // RECUPERATION des requetes de MAJ dans le XML
  86. if (array_key_exists($plugin, $this->liste_plugins) && file_exists($file)){
  87. $dom = new DomDocument();
  88. $dom->load($file);
  89. $listeVersions = $dom->getElementsByTagName('step');
  90. foreach($listeVersions as $version){
  91. $id_version = $version->getAttribute("id_version");
  92. if ($id_version > $version_atteinte) $version_atteinte = $id_version;
  93. $requetes = $version->getElementsByTagName('requete');
  94. foreach($requetes as $req){
  95. $extract[$id_version][] = $req->firstChild->nodeValue;
  96. }
  97. }
  98. ksort($extract);
  99. }
  100. // EXECUTION des REQUETES de MAJ
  101. if (sizeof($extract)>0){
  102. foreach($extract as $id_version=>$paquet){
  103. if ($id_version > $version_courante AND $id_version <= $version_finale){
  104. foreach ($paquet as $id=>$sql){
  105. if (!$resultat=$c->sql_query($sql)) message_die(E_ERROR,31,__FILE__,__LINE__,$sql);
  106. }
  107. }
  108. }
  109. }
  110. // MAJ du numero de version en base
  111. if ($version_finale>$version_courante){
  112. $sql = 'UPDATE '.TABLE_PLUGINS.' SET version="'.$version_finale.'"
  113. WHERE plugin="'.$plugin.'" AND type='.$type;
  114. if (!$resultat=$c->sql_query($sql)) message_die(E_ERROR,31,__FILE__,__LINE__,$sql);
  115. $this->get_liste_plugins(true);
  116. }
  117. }
  118. }
  119. ?>