modWebsite.class.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \defgroup website Module website
  19. * \brief website module descriptor.
  20. * \file htdocs/core/modules/modWebsite.class.php
  21. * \ingroup websites
  22. * \brief Description and activation file for the module Website
  23. */
  24. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  25. /**
  26. * Class to describe Websites module
  27. */
  28. class modWebsite extends DolibarrModules
  29. {
  30. /**
  31. * Constructor. Define names, constants, directories, boxes, permissions
  32. *
  33. * @param DoliDB $db Database handler
  34. */
  35. public function __construct($db)
  36. {
  37. global $langs, $conf;
  38. $this->db = $db;
  39. $this->numero = 10000;
  40. // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
  41. // It is used to group modules in module setup page
  42. $this->family = "portal";
  43. $this->module_position = '50';
  44. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  45. $this->name = preg_replace('/^mod/i', '', get_class($this));
  46. $this->description = "Enable to build and serve public web sites with CMS features";
  47. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  48. $this->version = 'dolibarr';
  49. // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
  50. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  51. // Name of image file used for this module.
  52. $this->picto = 'website';
  53. // Data directories to create when module is enabled
  54. $this->dirs = array("/website/temp");
  55. // Config pages
  56. $this->config_page_url = array('website.php');
  57. // Dependencies
  58. $this->hidden = !empty($conf->global->MODULE_WEBSITE_DISABLED); // A condition to disable module
  59. $this->depends = array('modFckeditor'); // List of modules id that must be enabled if this module is enabled
  60. $this->requiredby = array(); // List of modules id to disable if this one is disabled
  61. $this->conflictwith = array(); // List of modules id this module is in conflict with
  62. $this->phpmin = array(5, 6); // Minimum version of PHP required by module
  63. $this->langfiles = array("website");
  64. // Constants
  65. $this->const = array();
  66. // New pages on tabs
  67. //$this->tabs[] = array(); // To add a new tab identified by code tabname1
  68. // Boxes
  69. $this->boxes = array();
  70. // Permissions
  71. $this->rights = array(); // Permission array used by this module
  72. $this->rights_class = 'website';
  73. $r = 0;
  74. $this->rights[$r][0] = 10001;
  75. $this->rights[$r][1] = 'Read website content';
  76. $this->rights[$r][3] = 0;
  77. $this->rights[$r][4] = 'read';
  78. $r++;
  79. $this->rights[$r][0] = 10002;
  80. $this->rights[$r][1] = 'Create/modify website content (html and javascript content)';
  81. $this->rights[$r][3] = 0;
  82. $this->rights[$r][4] = 'write';
  83. $r++;
  84. $this->rights[$r][0] = 10003;
  85. $this->rights[$r][1] = 'Create/modify website content (dynamic php code). Dangerous, must be reserved to restricted developers.';
  86. $this->rights[$r][3] = 0;
  87. $this->rights[$r][4] = 'writephp';
  88. $r++;
  89. $this->rights[$r][0] = 10005;
  90. $this->rights[$r][1] = 'Delete website content';
  91. $this->rights[$r][3] = 0;
  92. $this->rights[$r][4] = 'delete';
  93. $r++;
  94. $this->rights[$r][0] = 10008;
  95. $this->rights[$r][1] = 'Export website content';
  96. $this->rights[$r][3] = 0;
  97. $this->rights[$r][4] = 'export';
  98. $r++;
  99. // Main menu entries
  100. $r = 0;
  101. $this->menu[$r] = array('fk_menu'=>'0', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  102. 'type'=>'top', // This is a Left menu entry
  103. 'titre'=>'WebSites',
  104. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em092"'),
  105. 'mainmenu'=>'website',
  106. 'url'=>'/website/index.php',
  107. 'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  108. 'position'=>100,
  109. 'enabled'=>'$conf->website->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
  110. 'perms'=>'$user->rights->website->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  111. 'target'=>'',
  112. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  113. $r++;
  114. // Exports
  115. $r = 1;
  116. $this->export_code[$r] = $this->rights_class.'_'.$r;
  117. $this->export_label[$r] = 'MyWebsitePages'; // Translation key (used only if key ExportDataset_xxx_z not found)
  118. $this->export_permission[$r] = array(array("website", "export"));
  119. $this->export_icon[$r] = 'globe';
  120. $keyforclass = 'WebsitePage';
  121. $keyforclassfile = '/website/class/websitepage.class.php';
  122. $keyforelement = 'Website';
  123. include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
  124. //$keyforselect='myobject'; $keyforelement='myobject'; $keyforaliasextra='extra';
  125. //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  126. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  127. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'website_page as t, '.MAIN_DB_PREFIX.'website as p';
  128. $this->export_sql_end[$r] .= ' WHERE t.fk_website = p.rowid';
  129. $this->export_sql_end[$r] .= ' AND p.entity IN ('.getEntity('website').')';
  130. $r++;
  131. }
  132. /**
  133. * Function called when module is enabled.
  134. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  135. * It also creates data directories
  136. *
  137. * @param string $options Options when enabling module ('', 'noboxes')
  138. * @return int 1 if OK, 0 if KO
  139. */
  140. public function init($options = '')
  141. {
  142. global $conf, $langs;
  143. // Remove permissions and default values
  144. $this->remove($options);
  145. // Copy flags and octicons directory
  146. $dirarray = array('common/flags'=>'flags', 'common/octicons/build/svg'=>'octicons');
  147. foreach ($dirarray as $dirfrom => $dirtarget) {
  148. $src = DOL_DOCUMENT_ROOT.'/theme/'.$dirfrom;
  149. $dest = DOL_DATA_ROOT.'/medias/image/'.$dirtarget;
  150. if (is_dir($src)) {
  151. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  152. dol_mkdir($dest);
  153. $result = dolCopyDir($src, $dest, 0, 0);
  154. if ($result < 0) {
  155. $langs->load("errors");
  156. $this->error = $langs->trans('ErrorFailToCopyDir', $src, $dest);
  157. return 0;
  158. }
  159. }
  160. }
  161. // Website templates
  162. $srcroot = DOL_DOCUMENT_ROOT.'/install/doctemplates/websites';
  163. $destroot = DOL_DATA_ROOT.'/doctemplates/websites';
  164. dol_mkdir($destroot);
  165. $docs = dol_dir_list($srcroot, 'files', 0, 'website_.*(\.zip|\.jpg)$');
  166. foreach ($docs as $cursorfile) {
  167. $src = $srcroot.'/'.$cursorfile['name'];
  168. $dest = $destroot.'/'.$cursorfile['name'];
  169. $result = dol_copy($src, $dest, 0, 1); // For full zip templates, we overwrite old existing files
  170. if ($result < 0) {
  171. $langs->load("errors");
  172. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  173. }
  174. }
  175. $sql = array();
  176. return $this->_init($sql, $options);
  177. }
  178. }