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