modExternalRss.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <https://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 Description and activation file for the 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. public 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. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  46. $this->version = 'dolibarr';
  47. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  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. public 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. while ($obj = $this->db->fetch_object($result)) {
  87. $reg = array();
  88. if (preg_match('/EXTERNAL_RSS_TITLE_([0-9]+)/i', $obj->name, $reg)) {
  89. // Definie la boite si on a trouvee une ancienne configuration
  90. //$this->boxes[$reg[1]][0] = "(ExternalRSSInformations)";
  91. $this->boxes[$reg[1]]['file'] = "box_external_rss.php";
  92. $this->boxes[$reg[1]]['note'] = $reg[1]." (".$obj->value.")";
  93. }
  94. }
  95. $this->db->free($result);
  96. }
  97. $sql = array();
  98. return $this->_init($sql, $options);
  99. }
  100. /**
  101. * Function called when module is disabled.
  102. * Remove from database constants, boxes and permissions from Dolibarr database.
  103. * Data directories are not deleted
  104. *
  105. * @param string $options Options when enabling module ('', 'noboxes')
  106. * @return int 1 if OK, 0 if KO
  107. */
  108. public function remove($options = '')
  109. {
  110. $sql = array();
  111. // Delete old declarations of RSS box
  112. $this->boxes[0]['file'] = "box_external_rss.php";
  113. return $this->_remove($sql, $options);
  114. }
  115. }