modExternalRss.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \defgroup externalrss Module externalrss
  20. * \brief Module pour inclure des informations externes RSS
  21. * \file htdocs/core/modules/modExternalRss.class.php
  22. * \ingroup externalrss
  23. * \brief Fichier de description et activation du module externalrss
  24. */
  25. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  26. /**
  27. * Class to describe and enable module externalrss
  28. */
  29. class modExternalRss extends DolibarrModules
  30. {
  31. /**
  32. * Constructor. Define names, constants, directories, boxes, permissions
  33. *
  34. * @param DoliDB $db Database handler
  35. */
  36. function __construct($db)
  37. {
  38. global $conf;
  39. $this->db = $db;
  40. $this->numero = 320;
  41. $this->family = "technic";
  42. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  43. $this->name = preg_replace('/^mod/i','',get_class($this));
  44. $this->description = "Ajout de files d'informations RSS dans les ecrans Dolibarr";
  45. $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
  46. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  47. $this->special = 1;
  48. $this->picto='rss';
  49. // Data directories to create when module is enabled
  50. $this->dirs = array("/externalrss/temp");
  51. // Config pages
  52. $this->config_page_url = array("external_rss.php");
  53. // Dependencies
  54. $this->depends = array();
  55. $this->requiredby = array();
  56. $this->phpmin = array(4,2,0);
  57. $this->phpmax = array();
  58. // Constants
  59. $this->const = array();
  60. // Boxes
  61. $this->boxes = array();
  62. // Les boites sont ajoutees lors de la configuration des flux
  63. // Permissions
  64. $this->rights = array();
  65. $this->rights_class = 'externalrss';
  66. }
  67. /**
  68. * Function called when module is enabled.
  69. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  70. * It also creates data directories
  71. *
  72. * @param string $options Options when enabling module ('', 'noboxes')
  73. * @return int 1 if OK, 0 if KO
  74. */
  75. function init($options='')
  76. {
  77. global $conf;
  78. $sql = array();
  79. // Recherche configuration de boites
  80. $this->boxes=array();
  81. $sql="select name, value from ".MAIN_DB_PREFIX."const";
  82. $sql.= " WHERE name like 'EXTERNAL_RSS_TITLE_%'";
  83. $sql.= " AND entity = ".$conf->entity;
  84. $result=$this->db->query($sql);
  85. if ($result)
  86. {
  87. while ($obj = $this->db->fetch_object($result))
  88. {
  89. if (preg_match('/EXTERNAL_RSS_TITLE_([0-9]+)/i',$obj->name,$reg))
  90. {
  91. // Definie la boite si on a trouvee une ancienne configuration
  92. //$this->boxes[$reg[1]][0] = "(ExternalRSSInformations)";
  93. $this->boxes[$reg[1]]['file'] = "box_external_rss.php";
  94. $this->boxes[$reg[1]]['note'] = $reg[1]." (".$obj->value.")";
  95. }
  96. }
  97. $this->db->free($result);
  98. }
  99. $sql = array();
  100. return $this->_init($sql,$options);
  101. }
  102. /**
  103. * Function called when module is disabled.
  104. * Remove from database constants, boxes and permissions from Dolibarr database.
  105. * Data directories are not deleted
  106. *
  107. * @param string $options Options when enabling module ('', 'noboxes')
  108. * @return int 1 if OK, 0 if KO
  109. */
  110. function remove($options='')
  111. {
  112. $sql = array();
  113. // Delete old declarations of RSS box
  114. $this->boxes[0]['file'] = "box_external_rss.php";
  115. return $this->_remove($sql,$options);
  116. }
  117. }