dolibarr 19.0.4
modWebsite.class.php
Go to the documentation of this file.
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
25include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
26
27
32{
38 public function __construct($db)
39 {
40 global $langs, $conf;
41
42 $this->db = $db;
43 $this->numero = 10000;
44
45 // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
46 // It is used to group modules in module setup page
47 $this->family = "portal";
48 $this->module_position = '50';
49 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
50 $this->name = preg_replace('/^mod/i', '', get_class($this));
51 $this->description = "Enable to build and serve public web sites with CMS features";
52 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
53 $this->version = 'dolibarr';
54 // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
55 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
56 // Name of image file used for this module.
57 $this->picto = 'website';
58
59 // Data directories to create when module is enabled
60 $this->dirs = array("/website/temp");
61
62 // Config pages
63 $this->config_page_url = array('website.php');
64
65 // Dependencies
66 $this->hidden = getDolGlobalString('MODULE_WEBSITE_DISABLED'); // A condition to disable module
67 $this->depends = array('modFckeditor'); // List of modules id that must be enabled if this module is enabled
68 $this->requiredby = array(); // List of modules id to disable if this one is disabled
69 $this->conflictwith = array(); // List of modules id this module is in conflict with
70 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
71 $this->langfiles = array("website");
72
73 // Constants
74 $this->const = array();
75
76 // New pages on tabs
77 //$this->tabs[] = array(); // To add a new tab identified by code tabname1
78
79 // Boxes
80 $this->boxes = array();
81
82 // Permissions
83 $this->rights = array(); // Permission array used by this module
84 $this->rights_class = 'website';
85 $r = 0;
86
87 $this->rights[$r][0] = 10001;
88 $this->rights[$r][1] = 'Read website content';
89 $this->rights[$r][3] = 0;
90 $this->rights[$r][4] = 'read';
91 $r++;
92
93 $this->rights[$r][0] = 10002;
94 $this->rights[$r][1] = 'Create/modify website content (html and javascript content)';
95 $this->rights[$r][3] = 0;
96 $this->rights[$r][4] = 'write';
97 $r++;
98
99 $this->rights[$r][0] = 10003;
100 $this->rights[$r][1] = 'Create/modify website content (dynamic php code). Dangerous, must be reserved to restricted developers.';
101 $this->rights[$r][3] = 0;
102 $this->rights[$r][4] = 'writephp';
103 $r++;
104
105 $this->rights[$r][0] = 10005;
106 $this->rights[$r][1] = 'Delete website content';
107 $this->rights[$r][3] = 0;
108 $this->rights[$r][4] = 'delete';
109 $r++;
110
111 $this->rights[$r][0] = 10008;
112 $this->rights[$r][1] = 'Export website content';
113 $this->rights[$r][3] = 0;
114 $this->rights[$r][4] = 'export';
115 $r++;
116
117 // Main menu entries
118 $r = 0;
119 $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
120 'type'=>'top', // This is a Left menu entry
121 'titre'=>'WebSites',
122 'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth em092"'),
123 'mainmenu'=>'website',
124 'url'=>'/website/index.php',
125 'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
126 'position'=>100,
127 '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.
128 'perms'=>'$user->rights->website->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
129 'target'=>'',
130 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
131 $r++;
132
133 // Exports
134 $r = 1;
135
136 $this->export_code[$r] = $this->rights_class.'_'.$r;
137 $this->export_label[$r] = 'MyWebsitePages'; // Translation key (used only if key ExportDataset_xxx_z not found)
138 $this->export_permission[$r] = array(array("website", "export"));
139 $this->export_icon[$r] = 'globe';
140 $keyforclass = 'WebsitePage';
141 $keyforclassfile = '/website/class/websitepage.class.php';
142 $keyforelement = 'Website';
143 include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
144 //$keyforselect='myobject'; $keyforelement='myobject'; $keyforaliasextra='extra';
145 //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
146 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
147 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'website_page as t, '.MAIN_DB_PREFIX.'website as p';
148 $this->export_sql_end[$r] .= ' WHERE t.fk_website = p.rowid';
149 $this->export_sql_end[$r] .= ' AND p.entity IN ('.getEntity('website').')';
150 $r++;
151 }
152
153
162 public function init($options = '')
163 {
164 global $conf, $langs;
165
166 $error = 0;
167
168 $result = $this->_load_tables('/install/mysql/', 'website');
169 if ($result < 0) {
170 return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
171 }
172
173 // Remove permissions and default values
174 $this->remove($options);
175
176 // Copy flags and octicons directory
177 $dirarray = array('common/flags'=>'flags', 'common/octicons/build/svg'=>'octicons');
178 foreach ($dirarray as $dirfrom => $dirtarget) {
179 $src = DOL_DOCUMENT_ROOT.'/theme/'.$dirfrom;
180 $dest = DOL_DATA_ROOT.'/medias/image/'.$dirtarget;
181
182 if (is_dir($src)) {
183 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
184 dol_mkdir($dest);
185 $result = dolCopyDir($src, $dest, 0, 0);
186 if ($result < 0) {
187 $langs->load("errors");
188 $this->error = $langs->trans('ErrorFailToCopyDir', $src, $dest);
189 $this->errors[] = $langs->trans('ErrorFailToCopyDir', $src, $dest);
190 $error++;
191 }
192 }
193 }
194
195 if ($error) {
196 return 0;
197 }
198
199 // Website templates
200 $srcroot = DOL_DOCUMENT_ROOT.'/install/doctemplates/websites';
201 $destroot = DOL_DATA_ROOT.'/doctemplates/websites';
202
203 dol_mkdir($destroot);
204
205 // Copy templates in zip format (old)
206 $docs = dol_dir_list($srcroot, 'files', 0, 'website_.*(\.zip|\.jpg)$');
207 foreach ($docs as $cursorfile) {
208 $src = $srcroot.'/'.$cursorfile['name'];
209 $dest = $destroot.'/'.$cursorfile['name'];
210
211 $result = dol_copy($src, $dest, 0, 1); // For full zip templates, we overwrite old existing files
212 if ($result < 0) {
213 $langs->load("errors");
214 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
215 $this->errors[] = $langs->trans('ErrorFailToCopyFile', $src, $dest);
216 $error++;
217 }
218 }
219
220 // Copy templates in dir format (recommended)
221 $docs = dol_dir_list($srcroot, 'directories', 0, 'website_.*$');
222
223 foreach ($docs as $cursorfile) {
224 $src = $srcroot.'/'.$cursorfile['name'];
225 $dest = $destroot.'/'.$cursorfile['name'];
226
227 // Compress it
228 global $errormsg;
229 $errormsg = '';
230 $result = dol_compress_dir($src, $dest.'.zip', 'zip');
231 if ($result < 0) {
232 $error++;
233 $this->error = ($errormsg ? $errormsg : $langs->trans('ErrorFailToCreateZip', $dest));
234 $this->errors[] = ($errormsg ? $errormsg : $langs->trans('ErrorFailToCreateZip', $dest));
235 }
236 }
237
238 if ($error) {
239 return 0;
240 }
241
242 $sql = array();
243
244 return $this->_init($sql, $options);
245 }
246}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Class to describe Websites module.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null)
Copy a dir to another dir.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124