dolibarr 21.0.4
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2016-2023 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
29// We allow POST of rich content with js and style, but only for this php file and if into some given POST variable
30define('NOSCANPOSTFORINJECTION', array('PAGE_CONTENT', 'WEBSITE_CSS_INLINE', 'WEBSITE_JS_INLINE', 'WEBSITE_HTML_HEADER', 'htmlheader'));
31
32define('USEDOLIBARREDITOR', 1);
33define('FORCE_CKEDITOR', 1); // We need CKEditor, even if module is off.
34if (!defined('DISABLE_JS_GRAHP')) {
35 define('DISABLE_JS_GRAPH', 1);
36}
37
38//header('X-XSS-Protection:0'); // Disable XSS filtering protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
39
40// Load Dolibarr environment
41require '../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
52require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
53require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
54require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
55require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
56
57
66// Load translation files required by the page
67$langs->loadLangs(array("admin", "other", "website", "errors"));
68
69// Security check
70if (!$user->hasRight('website', 'read')) {
72}
73
74$conf->dol_hide_leftmenu = 1; // Force hide of left menu.
75
76$error = 0;
77$virtualurl = '';
78$dataroot = '';
79$websiteid = GETPOSTINT('websiteid');
80$websitekey = GETPOST('website', 'alpha');
81$page = GETPOST('page', 'alpha');
82$pageid = GETPOSTINT('pageid');
83$pageref = GETPOST('pageref', 'alphanohtml');
84
85$action = GETPOST('action', 'aZ09');
86$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
87$confirm = GETPOST('confirm', 'alpha');
88$cancel = GETPOST('cancel', 'alpha');
89$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
90$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'websitelist'; // To manage different context of search
91$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
92$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
93$dol_hide_topmenu = GETPOSTINT('dol_hide_topmenu');
94$dol_hide_leftmenu = GETPOSTINT('dol_hide_leftmenu');
95$dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
96
97$type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
98$section_dir = GETPOST('section_dir', 'alpha');
99$file_manager = GETPOST('file_manager', 'alpha');
100$replacesite = GETPOST('replacesite', 'alpha');
101$mode = GETPOST('mode', 'alpha');
102
103if (GETPOST('deletesite', 'alpha')) {
104 $action = 'deletesite';
105}
106if (GETPOST('delete', 'alpha')) {
107 $action = 'delete';
108}
109if (GETPOST('preview', 'alpha')) {
110 $action = 'preview';
111}
112if (GETPOST('createsite', 'alpha')) {
113 $action = 'createsite';
114}
115if (GETPOST('createcontainer', 'alpha')) {
116 $action = 'createcontainer';
117}
118if (GETPOST('editcss', 'alpha')) {
119 $action = 'editcss';
120}
121if (GETPOST('editmenu', 'alpha')) {
122 $action = 'editmenu';
123}
124if (GETPOST('setashome', 'alpha')) {
125 $action = 'setashome';
126}
127if (GETPOST('editmeta', 'alpha')) {
128 $action = 'editmeta';
129}
130if (GETPOST('editsource', 'alpha')) {
131 $action = 'editsource';
132}
133if (GETPOST('editcontent', 'alpha')) {
134 $action = 'editcontent';
135}
136if (GETPOST('exportsite', 'alpha')) {
137 $action = 'exportsite';
138}
139if (GETPOST('importsite', 'alpha')) {
140 $action = 'importsite';
141}
142if (GETPOST('createfromclone', 'alpha')) {
143 $action = 'createfromclone';
144}
145if (GETPOST('createpagefromclone', 'alpha')) {
146 $action = 'createpagefromclone';
147}
148if (empty($action) && $file_manager) {
149 $action = 'file_manager';
150}
151if ($action == 'replacesite' || (empty($action) && $replacesite)) { // Test on permission not required
152 $mode = 'replacesite';
153}
154if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x')) {
155 $pageid = 0;
156}
157
158// Load variable for pagination
159$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
160$sortfield = GETPOST('sortfield', 'aZ09comma');
161$sortorder = GETPOST('sortorder', 'aZ09comma');
162$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
163if (empty($page) || $page == -1) {
164 $page = 0;
165} // If $page is not defined, or '' or -1
166$offset = $limit * $page;
167$pageprev = $page - 1;
168$pagenext = $page + 1;
169//if (! $sortfield) $sortfield='name';
170//if (! $sortorder) $sortorder='ASC';
171
172if (empty($action)) {
173 $action = 'preview';
174}
175
176$object = new Website($db);
177$objectpage = new WebsitePage($db);
178
179$listofwebsites = $object->fetchAll('ASC', 'position'); // Init list of websites
180
181// If website not defined, we take first found
182if (!($websiteid > 0) && empty($websitekey) && $action != 'createsite') {
183 foreach ($listofwebsites as $key => $valwebsite) {
184 $websitekey = $valwebsite->ref;
185 break;
186 }
187}
188if ($websiteid > 0 || $websitekey) {
189 $res = $object->fetch($websiteid, $websitekey);
190 $websitekey = $object->ref;
191}
192
193$website = $object;
194
195// Check pageid received as parameter
196if ($pageid < 0) {
197 $pageid = 0;
198}
199if (($pageid > 0 || $pageref) && $action != 'addcontainer') {
200 $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
201 // @phan-suppress
202 if ($res == 0) {
203 $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), null, $pageref);
204 }
205
206 // Check if pageid is inside the new website, if not we reset param pageid
207 if ($res >= 0 && $object->id > 0) {
208 if ($objectpage->fk_website != $object->id) { // We have a bad page that does not belong to web site
209 if ($object->fk_default_home > 0) {
210 $res = $objectpage->fetch($object->fk_default_home, $object->id, ''); // We search first page of web site
211 if ($res > 0) {
212 $pageid = $object->fk_default_home;
213 }
214 } else {
215 $res = $objectpage->fetch(0, $object->id, ''); // We search first page of web site
216 if ($res == 0) { // Page was not found, we reset it
217 $objectpage = new WebsitePage($db);
218 } else { // We found a page, we set pageid to it.
219 $pageid = $objectpage->id;
220 }
221 }
222 } else { // We have a valid page. We force pageid for the case we got the page with a fetch on ref.
223 $pageid = $objectpage->id;
224 }
225 }
226}
227
228// Define pageid if pageid and pageref not received as parameter or was wrong
229if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer') {
230 $pageid = $object->fk_default_home;
231 if (empty($pageid)) {
232 $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
233 if (!is_array($array) && $array < 0) {
234 dol_print_error(null, $objectpage->error, $objectpage->errors);
235 }
236 $atleastonepage = (is_array($array) && count($array) > 0);
237
238 $firstpageid = 0;
239 $homepageid = 0;
240 foreach ($array as $key => $valpage) {
241 if (empty($firstpageid)) {
242 $firstpageid = $valpage->id;
243 }
244 if ($object->fk_default_home && $key == $object->fk_default_home) {
245 $homepageid = $valpage->id;
246 }
247 }
248 $pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
249 }
250}
251
252
253global $dolibarr_main_data_root;
254$pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey;
255$filehtmlheader = $pathofwebsite.'/htmlheader.html';
256$filecss = $pathofwebsite.'/styles.css.php';
257$filejs = $pathofwebsite.'/javascript.js.php';
258$filerobot = $pathofwebsite.'/robots.txt';
259$filehtaccess = $pathofwebsite.'/.htaccess';
260$filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
261$fileindex = $pathofwebsite.'/index.php';
262$filewrapper = $pathofwebsite.'/wrapper.php';
263$filemanifestjson = $pathofwebsite.'/manifest.json.php';
264$filereadme = $pathofwebsite.'/README.md';
265$filelicense = $pathofwebsite.'/LICENSE';
266$filemaster = $pathofwebsite.'/master.inc.php';
267
268// Define $urlwithroot
269$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
270$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
271//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
272
273
274$permtouploadfile = $user->hasRight('website', 'write');
275$diroutput = $conf->medias->multidir_output[$conf->entity];
276
277$relativepath = $section_dir;
278$upload_dir = preg_replace('/\/$/', '', $diroutput).'/'.preg_replace('/^\//', '', $relativepath);
279
280$htmlheadercontentdefault = '';
281$htmlheadercontentdefault .= '<link rel="stylesheet" id="google-fonts-css" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,700" />'."\n";
282$htmlheadercontentdefault .= '<link rel="stylesheet" id="font-wasesome-css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />'."\n";
283$htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>'."\n";
284$htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>'."\n";
285$htmlheadercontentdefault .= '<!--'."\n";
286$htmlheadercontentdefault .= '<script src="/document.php?modulepart=medias&file=css/myfile.css"></script>'."\n";
287$htmlheadercontentdefault .= '<script src="/document.php?modulepart=medias&file=js/myfile.js"></script>'."\n";
288$htmlheadercontentdefault .= '-->'."\n";
289
290$manifestjsoncontentdefault = '';
291$manifestjsoncontentdefault .= '{
292 "name": "MyWebsite",
293 "short_name": "MyWebsite",
294 "start_url": "/",
295 "lang": "en-US",
296 "display": "standalone",
297 "background_color": "#fff",
298 "description": "A simple Web app.",
299 "icons": [{
300 "src": "images/'.urlencode($website->ref).'/homescreen48.png",
301 "sizes": "48x48",
302 "type": "image/png"
303 }, {
304 "src": "image/'.urlencode($website->ref).'/homescreen72.png",
305 "sizes": "72x72",
306 "type": "image/png"
307 }, {
308 "src": "image/'.urlencode($website->ref).'/homescreen96.png",
309 "sizes": "96x96",
310 "type": "image/png"
311 }, {
312 "src": "image/'.urlencode($website->ref).'/homescreen144.png",
313 "sizes": "144x144",
314 "type": "image/png"
315 }, {
316 "src": "image/'.urlencode($website->ref).'/homescreen168.png",
317 "sizes": "168x168",
318 "type": "image/png"
319 }, {
320 "src": "image/'.urlencode($website->ref).'/homescreen192.png",
321 "sizes": "192x192",
322 "type": "image/png"
323 }],
324 "related_applications": [{
325 "platform": "play",
326 "url": "https://play.google.com/store/apps/details?id=com.nltechno.dolidroidpro"
327 }]
328}';
329
330$listofpages = array();
331
332$algo = '';
333if (GETPOST('optiopagecontent')) {
334 $algo .= 'content';
335}
336if (GETPOST('optionmeta')) {
337 $algo .= 'meta';
338}
339if (GETPOST('optionsitefiles')) {
340 $algo .= 'sitefiles';
341}
342
343if (empty($sortfield)) {
344 if ($action == 'file_manager') { // Test on permission not required
345 $sortfield = 'name';
346 $sortorder = 'ASC';
347 } else {
348 $sortfield = 'pageurl';
349 $sortorder = 'ASC';
350 }
351}
352
353$searchkey = GETPOST('searchstring', 'restricthtmlallowunvalid'); // or 'none', must be same then $searchstring
354
355if ($action == 'replacesite' || $mode == 'replacesite') { // Test on permission not required
356 $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
357 $langcode = GETPOST('optionlanguage', 'aZ09');
358 $otherfilters = array();
359 if (GETPOSTINT('optioncategory') > 0) {
360 $otherfilters['category'] = GETPOSTINT('optioncategory');
361 }
362
363 $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
364}
365
366$usercanedit = $user->hasRight('website', 'write');
367$permissiontoadd = $user->hasRight('website', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
368$permissiontodelete = $user->hasRight('website', 'delete');
369
370
371/*
372 * Actions
373 */
374
375// Protections
376if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
377 $action = 'preview'; // To avoid to make an action on another page or another site when we click on button to select another site or page.
378}
379if (GETPOST('refreshsite', 'alpha') || GETPOST('refreshsite.x', 'alpha') || GETPOST('refreshsite_x', 'alpha')) { // If we change the site, we reset the pageid and cancel addsite action.
380 if ($action == 'addsite') { // Test on permission not required here
381 $action = 'preview';
382 }
383 if ($action == 'updatesource') { // Test on permission not required here
384 $action = 'preview';
385 }
386
387 $pageid = $object->fk_default_home;
388 if (empty($pageid)) {
389 $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
390 if (!is_array($array) && $array < 0) {
391 dol_print_error(null, $objectpage->error, $objectpage->errors);
392 }
393 $atleastonepage = (is_array($array) && count($array) > 0);
394
395 $firstpageid = 0;
396 $homepageid = 0;
397 foreach ($array as $key => $valpage) {
398 if (empty($firstpageid)) {
399 $firstpageid = $valpage->id;
400 }
401 if ($object->fk_default_home && $key == $object->fk_default_home) {
402 $homepageid = $valpage->id;
403 }
404 }
405 $pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
406 }
407}
408if (GETPOST('refreshpage', 'alpha') && !in_array($action, array('updatecss'))) {
409 $action = 'preview';
410}
411
412if ($cancel && $action == 'renamefile') { // Test on permission not required here
413 $cancel = '';
414}
415
416// Cancel
417if ($cancel) {
418 $action = 'preview';
419 $mode = '';
420 if ($backtopage) {
421 header("Location: ".$backtopage);
422 exit;
423 }
424}
425
426$savbacktopage = $backtopage;
427$backtopage = $_SERVER["PHP_SELF"].'?file_manager=1&website='.urlencode($websitekey).'&pageid='.urlencode((string) $pageid).(GETPOST('section_dir', 'alpha') ? '&section_dir='.urlencode(GETPOST('section_dir', 'alpha')) : ''); // used after a confirm_deletefile into actions_linkedfiles.inc.php
428if ($sortfield) {
429 $backtopage .= '&sortfield='.urlencode($sortfield);
430}
431if ($sortorder) {
432 $backtopage .= '&sortorder='.urlencode($sortorder);
433}
434include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; // This manage 'sendit', 'confirm_deletefile', 'renamefile' action when submitting new file.
435
436$backtopage = $savbacktopage;
437//var_dump($backtopage);
438//var_dump($action);
439
440if ($action == 'renamefile') { // Test on permission not required here. Must be after include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; If action were renamefile, we set it to 'file_manager'
441 $action = 'file_manager';
442}
443
444if ($action == 'setwebsiteonline' && $usercanedit) {
445 $website->setStatut($website::STATUS_VALIDATED, null, '', 'WEBSITE_MODIFY', 'status');
446
447 header("Location: ".$_SERVER["PHP_SELF"].'?website='.urlencode(GETPOST('website')).'&pageid='.GETPOSTINT('websitepage'));
448 exit;
449}
450if ($action == 'setwebsiteoffline' && $usercanedit) {
451 $result = $website->setStatut($website::STATUS_DRAFT, null, '', 'WEBSITE_MODIFY', 'status');
452
453 header("Location: ".$_SERVER["PHP_SELF"].'?website='.urlencode(GETPOST('website')).'&pageid='.GETPOSTINT('websitepage'));
454 exit;
455}
456if ($action == 'seteditinline') { // Test on permission not required here
457 if (!getDolGlobalString('WEBSITE_EDITINLINE_SAVE_CKEDITOR_EDIT')) {
458 // Show warning for feature not yet ready
459 setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
460 }
461
462 dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 1);
463 //dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 0); // Force disable of 'Include dynamic content'
464 header("Location: ".$_SERVER["PHP_SELF"].'?website='.urlencode(GETPOST('website')).'&pageid='.GETPOSTINT('pageid'));
465 exit;
466}
467if ($action == 'unseteditinline') { // Test on permission not required here
468 dolibarr_del_const($db, 'WEBSITE_EDITINLINE');
469 header("Location: ".$_SERVER["PHP_SELF"].'?website='.urlencode(GETPOST('website')).'&pageid='.GETPOSTINT('pageid'));
470 exit;
471}
472if ($action == 'setshowsubcontainers') { // Test on permission not required here
473 dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1);
474 //dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 0); // Force disable of edit inline
475 header("Location: ".$_SERVER["PHP_SELF"].'?website='.urlencode(GETPOST('website')).'&pageid='.GETPOSTINT('pageid'));
476 exit;
477}
478if ($action == 'unsetshowsubcontainers') { // Test on permission not required here
479 dolibarr_del_const($db, 'WEBSITE_SUBCONTAINERSINLINE');
480 header("Location: ".$_SERVER["PHP_SELF"].'?website='.urlencode(GETPOST('website')).'&pageid='.GETPOSTINT('pageid'));
481 exit;
482}
483
484if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searchkey && $usercanedit) {
485 $mode = 'replacesite';
486 $action = 'replacesite';
487 $massaction = '';
488}
489
490if ($action == 'deletetemplate' && $usercanedit) {
491 $dirthemes = array('/doctemplates/websites');
492 if (!empty($conf->modules_parts['websitetemplates'])) { // Using this feature slow down application
493 foreach ($conf->modules_parts['websitetemplates'] as $reldir) {
494 $dirthemes = array_merge($dirthemes, (array) ($reldir.'doctemplates/websites'));
495 }
496 }
497 $dirthemes = array_unique($dirthemes);
498
499
500 // Delete template files and dir
501 $mode = 'importsite';
502 $action = 'importsite';
503
504 if (count($dirthemes)) {
505 $i = 0;
506 foreach ($dirthemes as $dir) {
507 //print $dirroot.$dir;exit;
508 $dirtheme = DOL_DATA_ROOT.$dir; // This include loop on $conf->file->dol_document_root
509 if (is_dir($dirtheme)) {
510 $templateuserfile = GETPOST('templateuserfile');
511 $imguserfile = preg_replace('/\.zip$/', '', $templateuserfile).'.jpg';
512 dol_delete_file($dirtheme.'/'.$templateuserfile);
513 dol_delete_file($dirtheme.'/'.$imguserfile);
514 }
515 }
516 }
517}
518
519// Set category
520if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
521 $error = 0;
522 $nbupdate = 0;
523
524 $db->begin();
525
526 $categoryid = GETPOSTINT('setcategory');
527 if ($categoryid > 0) {
528 $tmpwebsitepage = new WebsitePage($db);
529 $category = new Categorie($db);
530 $category->fetch($categoryid);
531
532 foreach ($toselect as $tmpid) {
533 $tmpwebsitepage->id = $tmpid;
534 $result = $category->add_type($tmpwebsitepage, 'website_page');
535 if ($result < 0 && $result != -3) {
536 $error++;
537 setEventMessages($category->error, $category->errors, 'errors');
538 break;
539 } else {
540 $nbupdate++;
541 }
542 }
543 }
544
545 if ($error) {
546 $db->rollback();
547 } else {
548 if ($nbupdate) {
549 setEventMessages($langs->trans("RecordsModified", $nbupdate), null, 'mesgs');
550 }
551
552 $db->commit();
553 }
554 // Now we reload list
555 $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
556}
557
558// Del category
559if ($massaction == 'delcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
560 $error = 0;
561 $nbupdate = 0;
562
563 $db->begin();
564
565 $categoryid = GETPOSTINT('setcategory');
566 if ($categoryid > 0) {
567 $tmpwebsitepage = new WebsitePage($db);
568 $category = new Categorie($db);
569 $category->fetch($categoryid);
570
571 foreach ($toselect as $tmpid) {
572 $tmpwebsitepage->id = $tmpid;
573 $result = $category->del_type($tmpwebsitepage, 'website_page');
574 if ($result < 0 && $result != -3) {
575 $error++;
576 setEventMessages($category->error, $category->errors, 'errors');
577 break;
578 } else {
579 $nbupdate++;
580 }
581 }
582 }
583
584 if ($error) {
585 $db->rollback();
586 } else {
587 if ($nbupdate) {
588 setEventMessages($langs->trans("RecordsModified", $nbupdate), null, 'mesgs');
589 }
590
591 $db->commit();
592 }
593 // Now we reload list
594 $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
595}
596
597// Replacement of string into pages
598if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
599 $replacestring = GETPOST('replacestring', 'restricthtmlallowunvalid'); // or 'none', must be same then $searchstring
600
601 $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
602 $allowimportsite = true;
603 if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
604 $allowimportsite = false;
605 }
606
607 if (!$allowimportsite) {
608 // Blocked by installmodules.lock
609 if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
610 // Show clean corporate message
611 $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
612 } else {
613 // Show technical generic message
614 $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
615 }
616 setEventMessages($message, null, 'errors');
617 } elseif (!$user->hasRight('website', 'writephp')) {
618 setEventMessages("NotAllowedToAddDynamicContent", null, 'errors');
619 } elseif (!$replacestring) {
620 setEventMessages("ErrorReplaceStringEmpty", null, 'errors');
621 } else {
622 $nbreplacement = 0;
623
624 foreach ($toselect as $keyselected) {
625 $objectpage = $listofpages['list'][$keyselected];
626 if ($objectpage->pageurl) {
627 dol_syslog("Replace string into page ".$objectpage->pageurl);
628
629 if (GETPOST('optiopagecontent', 'aZ09')) {
630 $objectpage->content = str_replace($searchkey, $replacestring, $objectpage->content);
631 }
632 if (GETPOST('optionmeta', 'aZ09')) {
633 $objectpage->title = str_replace($searchkey, $replacestring, $objectpage->title);
634 $objectpage->description = str_replace($searchkey, $replacestring, $objectpage->description);
635 $objectpage->keywords = str_replace($searchkey, $replacestring, $objectpage->keywords);
636 }
637
638 $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
639 $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
640
641 // Save page alias
642 $result = dolSavePageAlias($filealias, $object, $objectpage);
643 if (!$result) {
644 setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
645 }
646
647 // Save page of content
648 $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
649 if ($result) {
650 $nbreplacement++;
651 //var_dump($objectpage->content);exit;
652 $objectpage->update($user);
653 } else {
654 $error++;
655 setEventMessages('Failed to write file '.$filetpl, null, 'errors');
656 $action = 'createcontainer';
657 break;
658 }
659 }
660 }
661
662 if ($nbreplacement > 0) {
663 setEventMessages($langs->trans("ReplacementDoneInXPages", $nbreplacement), null, 'mesgs');
664 }
665
666 $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
667 $langcode = GETPOST('optionlanguage', 'aZ09');
668 $otherfilters = array();
669 if (GETPOSTINT('optioncategory') > 0) {
670 $otherfilters['category'] = GETPOSTINT('optioncategory');
671 }
672
673 // Now we reload list
674 $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
675 }
676}
677
678
679// Add directory
680/*
681if ($action == 'adddir' && $permtouploadfile)
682{
683 $ecmdir->ref = 'NOTUSEDYET';
684 $ecmdir->label = GETPOST("label");
685 $ecmdir->description = GETPOST("desc");
686
687 //$id = $ecmdir->create($user);
688 if ($id > 0)
689 {
690 header("Location: ".$_SERVER["PHP_SELF"]);
691 exit;
692 }
693 else
694 {
695 setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
696 $action = "createcontainer";
697 }
698
699 clearstatcache();
700}
701*/
702
703// Add a website
704if ($action == 'addsite' && $usercanedit) {
705 $db->begin();
706
707 if (GETPOST('virtualhost', 'alpha') && !preg_match('/^http/', GETPOST('virtualhost', 'alpha'))) {
708 $error++;
709 setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
710 }
711
712 if (!$error && !GETPOST('WEBSITE_REF', 'alpha')) {
713 $error++;
714 $langs->load("errors");
715 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("WebsiteName")), null, 'errors');
716 }
717 if (!$error && !preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF', 'alpha'))) {
718 $error++;
719 $langs->load("errors");
720 setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors');
721 }
722
723 if (!$error) {
724 $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
725 foreach ($arrayotherlang as $key => $val) {
726 // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
727 if (empty(trim($val))) {
728 continue;
729 }
730 $arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
731 }
732
733 $tmpobject = new Website($db);
734 $tmpobject->ref = GETPOST('WEBSITE_REF', 'alpha');
735 $tmpobject->description = GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml');
736 $tmpobject->lang = GETPOST('WEBSITE_LANG', 'aZ09');
737 $tmpobject->otherlang = implode(',', $arrayotherlang);
738 $tmpobject->virtualhost = GETPOST('virtualhost', 'alpha');
739
740 $result = $tmpobject->create($user);
741 if ($result == 0) {
742 $error++;
743 setEventMessages($langs->trans("ErrorLabelAlreadyExists"), null, 'errors');
744 } elseif ($result < 0) {
745 $error++;
746 setEventMessages($tmpobject->error, $tmpobject->errors, 'errors');
747 }
748 }
749
750 if (!$error) {
751 $db->commit();
752 setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs');
753 $action = '';
754
755 header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref);
756 exit;
757 } else {
758 $db->rollback();
759 $action = 'createsite';
760 }
761
762 if (!$error) {
763 $action = 'preview';
764 $id = $object->id;
765 }
766}
767
768'@phan-var-force int $error';
769
770// Add page/container
771if ($action == 'addcontainer' && $usercanedit) {
772 dol_mkdir($pathofwebsite);
773
774 $db->begin();
775
776 $objectpage->fk_website = $object->id;
777 $objectpage->status = $objectpage::STATUS_DRAFT;
778
779 if (GETPOSTISSET('fetchexternalurl')) { // Fetch from external url
780 $urltograb = GETPOST('externalurl', 'alpha');
781 $grabimages = GETPOSTINT('grabimages') ? 1 : 0;
782 $grabimagesinto = GETPOST('grabimagesinto', 'alpha');
783
784 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
785 // The include seems to break typing on variables
786
787 if (empty($urltograb)) {
788 $error++;
789 $langs->load("errors");
790 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("URL")), null, 'errors');
791 $action = 'createcontainer';
792 } elseif (!preg_match('/^http/', $urltograb)) {
793 $error++;
794 $langs->load("errors");
795 setEventMessages('Error URL must start with http:// or https://', null, 'errors');
796 $action = 'createcontainer';
797 }
798
799 $pageurl = '';
800 if (!$error) {
801 // Clean url to grab, so url can be
802 // http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
803 $urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
804 //$urltograbwithoutdomainandparam = preg_replace('/^file:\/\/[^\/]+\/?/i', '', $urltograb);
805 $urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
806 if (empty($urltograbwithoutdomainandparam) && !preg_match('/\/$/', $urltograb)) {
807 $urltograb .= '/';
808 }
809 $pageurl = dol_sanitizeFileName(preg_replace('/[\/\.]/', '-', preg_replace('/\/+$/', '', $urltograbwithoutdomainandparam)));
810
811 $urltograbdirwithoutslash = dirname($urltograb.'.');
812 $urltograbdirrootwithoutslash = getRootURLFromURL($urltograbdirwithoutslash);
813 // Example, now $urltograbdirwithoutslash is https://www.dolimed.com/screenshots
814 // and $urltograbdirrootwithoutslash is https://www.dolimed.com
815 }
816
817 // Check pageurl is not already used
818 if ($pageurl) {
819 $tmpwebsitepage = new WebsitePage($db);
820 $result = $tmpwebsitepage->fetch(0, $object->id, $pageurl);
821 if ($result > 0) {
822 setEventMessages($langs->trans("AliasPageAlreadyExists", $pageurl), null, 'errors');
823 $error++;
824 $action = 'createcontainer';
825 }
826 }
827
828 if (!$error) {
829 $tmp = getURLContent($urltograb, 'GET', '', 1, array(), array('http', 'https'), 0);
830
831 // Test charset of result and convert it into UTF-8 if not in this encoding charset
832 if (!empty($tmp['content_type']) && preg_match('/ISO-8859-1/', $tmp['content_type'])) {
833 if (function_exists('mb_check_encoding')) {
834 if (mb_check_encoding($tmp['content'], 'ISO-8859-1')) {
835 // This is a ISO-8829-1 encoding string
836 $tmp['content'] = mb_convert_encoding($tmp['content'], 'ISO-8859-1', 'UTF-8');
837 } else {
838 $error++;
839 setEventMessages('Error getting '.$urltograb.': content seems non valid ISO-8859-1', null, 'errors');
840 $action = 'createcontainer';
841 }
842 } else {
843 $error++;
844 setEventMessages('Error getting '.$urltograb.': content seems ISO-8859-1 but functions to convert into UTF-8 are not available in your PHP', null, 'errors');
845 $action = 'createcontainer';
846 }
847 }
848 if (empty($tmp['content_type']) || (!empty($tmp['content_type']) && preg_match('/UTF-8/', $tmp['content_type']))) {
849 if (function_exists('mb_check_encoding')) {
850 if (mb_check_encoding($tmp['content'], 'UTF-8')) {
851 // This is a UTF8 or ASCII compatible string
852 } else {
853 $error++;
854 setEventMessages('Error getting '.$urltograb.': content seems not a valid UTF-8', null, 'errors');
855 $action = 'createcontainer';
856 }
857 }
858 }
859
860 if ($tmp['curl_error_no']) {
861 $error++;
862 setEventMessages('Error getting '.$urltograb.': '.$tmp['curl_error_msg'], null, 'errors');
863 $action = 'createcontainer';
864 } elseif ($tmp['http_code'] != '200') {
865 $error++;
866 setEventMessages('Error getting '.$urltograb.': '.$tmp['http_code'], null, 'errors');
867 $action = 'createcontainer';
868 } else {
869 // Remove comments
870 $tmp['content'] = removeHtmlComment($tmp['content']);
871
872 /* disable this, moved into the create() method
873 // Check there is no PHP content into the imported file (must be only HTML + JS)
874 $phpcontent = dolKeepOnlyPhpCode($tmp['content']);
875 if ($phpcontent) {
876 $error++;
877 setEventMessages('Error getting '.$urltograb.': file that include PHP content is not allowed', null, 'errors');
878 $action = 'createcontainer';
879 }
880 */
881 }
882
883 if (!$error) {
884 $regs = array();
885
886 preg_match('/<head>(.*)<\/head>/ims', $tmp['content'], $regs);
887 $head = $regs[1];
888
889 $objectpage->type_container = 'page';
890 $objectpage->pageurl = $pageurl;
891 if (empty($objectpage->pageurl)) {
892 $tmpdomain = getDomainFromURL($urltograb);
893 $objectpage->pageurl = $tmpdomain.'-home';
894 }
895
896 $objectpage->aliasalt = '';
897
898 if (preg_match('/^(\d+)\-/', basename($urltograb), $regs)) {
899 $objectpage->aliasalt = $regs[1];
900 }
901
902 $regtmp = array();
903 if (preg_match('/<title>(.*)<\/title>/ims', $head, $regtmp)) {
904 $objectpage->title = $regtmp[1];
905 }
906 if (preg_match('/<meta name="title"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
907 if (empty($objectpage->title)) {
908 $objectpage->title = $regtmp[1]; // If title not found into <title>, we get it from <meta title>
909 }
910 }
911 if (preg_match('/<meta name="description"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
912 $objectpage->description = $regtmp[1];
913 }
914 if (preg_match('/<meta name="keywords"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
915 $objectpage->keywords = $regtmp[1];
916 }
917 if (preg_match('/<html\s+lang="([^"]+)"/ims', $tmp['content'], $regtmp)) {
918 $tmplang = explode('-', $regtmp[1]);
919 $objectpage->lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : '');
920 }
921
922 $tmp['content'] = preg_replace('/\s*<meta name="generator"[^"]+content="([^"]+)"\s*\/?>/ims', '', $tmp['content']);
923
924 $objectpage->content = $tmp['content'];
925 $objectpage->content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $objectpage->content);
926 $objectpage->content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $objectpage->content);
927
928 // TODO Replace 'action="$urltograbdirwithoutslash' into action="/"
929 // TODO Replace 'action="$urltograbdirwithoutslash..."' into action="..."
930 // TODO Replace 'a href="$urltograbdirwithoutslash' into a href="/"
931 // TODO Replace 'a href="$urltograbdirwithoutslash..."' into a href="..."
932
933 // Now loop to fetch all css files. Include them inline into header of page
934 $objectpage->htmlheader = $tmp['content'];
935 $objectpage->htmlheader = preg_replace('/^.*<head(\s[^>]*)*>/ims', '', $objectpage->htmlheader);
936 $objectpage->htmlheader = preg_replace('/<\/head(\s[^>]*)*>.*$/ims', '', $objectpage->htmlheader);
937 $objectpage->htmlheader = preg_replace('/<base(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
938 $objectpage->htmlheader = preg_replace('/<meta http-equiv="content-type"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
939 $objectpage->htmlheader = preg_replace('/<meta name="robots"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
940 $objectpage->htmlheader = preg_replace('/<meta name="title"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
941 $objectpage->htmlheader = preg_replace('/<meta name="description"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
942 $objectpage->htmlheader = preg_replace('/<meta name="keywords"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
943 $objectpage->htmlheader = preg_replace('/<meta name="generator"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
944 //$objectpage->htmlheader = preg_replace('/<meta name="verify-v1[^>]*>\n*/ims', '', $objectpage->htmlheader);
945 //$objectpage->htmlheader = preg_replace('/<meta name="msvalidate.01[^>]*>\n*/ims', '', $objectpage->htmlheader);
946 $objectpage->htmlheader = preg_replace('/<title>[^<]*<\/title>\n*/ims', '', $objectpage->htmlheader);
947 $objectpage->htmlheader = preg_replace('/<link[^>]*rel="shortcut[^>]*>\n/ims', '', $objectpage->htmlheader);
948 $objectpage->htmlheader = preg_replace('/<link[^>]*rel="alternate[^>]*>\n/ims', '', $objectpage->htmlheader);
949 $objectpage->htmlheader = preg_replace('/<link[^>]*rel="canonical[^>]*>\n/ims', '', $objectpage->htmlheader);
950
951 // Now loop to fetch JS
952 $tmp = $objectpage->htmlheader;
953
954 // We grab files found into <script> tags
955 preg_match_all('/<script([^\.>]+)src=["\']([^"\'>]+)["\']([^>]*)><\/script>/i', $objectpage->htmlheader, $regs);
956 $errorforsubresource = 0;
957 foreach ($regs[0] as $key => $val) {
958 dol_syslog("We will grab the script resource found into script tag ".$regs[2][$key]);
959
960 $linkwithoutdomain = $regs[2][$key];
961 if (preg_match('/^\//', $regs[2][$key])) {
962 $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
963 } else {
964 $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
965 }
966
967 //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
968 if (preg_match('/^http/', $regs[2][$key])) {
969 $urltograbbis = $regs[2][$key];
970 $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
971 //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
972 }
973
974 //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
975 //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
976
977 // Test if this is an external URL of grabbed web site. If yes, we do not load resource
978 $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
979 $domaintograbbis = getDomainFromURL($urltograbbis);
980 if ($domaintograb != $domaintograbbis) {
981 continue;
982 }
983
984 /*
985 $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
986 if ($tmpgeturl['curl_error_no'])
987 {
988 $error++;
989 setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
990 $errorforsubresource++;
991 $action='createcontainer';
992 }
993 elseif ($tmpgeturl['http_code'] != '200')
994 {
995 $error++;
996 setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
997 $errorforsubresource++;
998 $action='createcontainer';
999 }
1000 else
1001 {
1002 dol_mkdir(dirname($filetosave));
1003
1004 $fp = fopen($filetosave, "w");
1005 fputs($fp, $tmpgeturl['content']);
1006 fclose($fp);
1007 dolChmod($file);
1008 }
1009 */
1010
1011 //$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
1012 $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', '', $tmp);
1013 }
1014 $objectpage->htmlheader = trim($tmp)."\n";
1015
1016
1017 // Now we grab CSS found into <link> tags
1018 $pagecsscontent = "\n".'<style>'."\n";
1019
1020 preg_match_all('/<link([^\.>]+)href=["\']([^"\'>]+\.css[^"\'>]*)["\']([^>]*)>/i', $objectpage->htmlheader, $regs);
1021 $errorforsubresource = 0;
1022 foreach ($regs[0] as $key => $val) {
1023 dol_syslog("We will grab the css resources found into link tag ".$regs[2][$key]);
1024
1025 $linkwithoutdomain = $regs[2][$key];
1026 if (preg_match('/^\//', $regs[2][$key])) {
1027 $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1028 } else {
1029 $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
1030 }
1031
1032 //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
1033 if (preg_match('/^http/', $regs[2][$key])) {
1034 $urltograbbis = $regs[2][$key];
1035 $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1036 //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
1037 }
1038
1039 //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
1040 //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
1041
1042 // Test if this is an external URL of grabbed web site. If yes, we do not load resource
1043 $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
1044 $domaintograbbis = getDomainFromURL($urltograbbis);
1045 if ($domaintograb != $domaintograbbis) {
1046 continue;
1047 }
1048
1049 $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1050 if ($tmpgeturl['curl_error_no']) {
1051 $errorforsubresource++;
1052 setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1053 dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
1054 $action = 'createcontainer';
1055 } elseif ($tmpgeturl['http_code'] != '200') {
1056 $errorforsubresource++;
1057 setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1058 dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
1059 $action = 'createcontainer';
1060 } else {
1061 // Clean some comment
1062 //$tmpgeturl['content'] = dol_string_is_good_iso($tmpgeturl['content'], 1);
1063 //$tmpgeturl['content'] = mb_convert_encoding($tmpgeturl['content'], 'UTF-8', 'UTF-8');
1064 //$tmpgeturl['content'] = remove_bs($tmpgeturl['content']);
1065 //$tmpgeturl['content'] = str_replace('$screen-md-max', 'auto', $tmpgeturl['content']);
1066
1067 //var_dump($tmpgeturl['content']);exit;
1068 $tmpgeturl['content'] = preg_replace('/\/\*\s+CSS content[a-z\s]*\s+\*\//', '', $tmpgeturl['content']);
1069
1070 //dol_mkdir(dirname($filetosave));
1071
1072 //$fp = fopen($filetosave, "w");
1073 //fputs($fp, $tmpgeturl['content']);
1074 //fclose($fp);
1075 //dolChmod($file);
1076
1077 // $filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
1078 $pagecsscontent .= '/* Content of file '.$urltograbbis.' */'."\n";
1079
1080 getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1, $grabimages, $grabimagesinto);
1081
1082 // We try to convert the CSS we got by adding a prefix .bodywebsite with lessc to avoid conflict with CSS of Dolibarr.
1083 include_once DOL_DOCUMENT_ROOT.'/core/class/lessc.class.php';
1084 $lesscobj = new Lessc();
1085 try {
1086 $contentforlessc = ".bodywebsite {\n".$tmpgeturl['content']."\n}\n";
1087 //print '<pre>'.$contentforlessc.'</pre>';
1088 $contentforlessc = $lesscobj->compile($contentforlessc);
1089 //var_dump($contentforlessc); exit;
1090
1091 $pagecsscontent .= $contentforlessc."\n";
1092 //$pagecsscontent.=$tmpgeturl['content']."\n";
1093 } catch (exception $e) {
1094 //echo "failed to compile lessc";
1095 dol_syslog("Failed to compile the CSS from URL ".$urltograbbis." with lessc: ".$e->getMessage(), LOG_WARNING);
1096 $pagecsscontent .= $tmpgeturl['content']."\n";
1097 }
1098
1099 $objectpage->htmlheader = preg_replace('/'.preg_quote($regs[0][$key], '/').'\n*/ims', '', $objectpage->htmlheader);
1100 }
1101 }
1102
1103 $pagecsscontent .= '</style>';
1104 //var_dump($pagecsscontent);
1105
1106 //print dol_escape_htmltag($tmp);exit;
1107 $objectpage->htmlheader .= trim($pagecsscontent)."\n";
1108
1109
1110 // Now we have to fetch all images into page
1111 $tmp = $objectpage->content;
1112
1113 getAllImages($object, $objectpage, $urltograb, $tmp, $action, 1, $grabimages, $grabimagesinto);
1114
1115 // Normalize links href to Dolibarr internal naming
1116 $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2.php"', $tmp);
1117 $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3.php"', $tmp);
1118 $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3-\4.php"', $tmp);
1119
1120 //print dol_escape_htmltag($tmp);exit;
1121 $objectpage->content = $tmp;
1122
1123 $objectpage->grabbed_from = $urltograb;
1124 }
1125 }
1126 } else {
1127 $newaliasnames = '';
1128 if (!$error && GETPOST('WEBSITE_ALIASALT', 'alpha')) {
1129 $arrayofaliastotest = explode(',', str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alpha')));
1130 $websitepagetemp = new WebsitePage($db);
1131 foreach ($arrayofaliastotest as $aliastotest) {
1132 $aliastotest = trim(preg_replace('/\.php$/i', '', $aliastotest));
1133
1134 // Disallow alias name pageX (already used to save the page with id)
1135 if (preg_match('/^page\d+/i', $aliastotest)) {
1136 $error++;
1137 $langs->load("errors");
1138 setEventMessages("Alias name 'pageX' is not allowed", null, 'errors');
1139 $action = 'createcontainer';
1140 break;
1141 } else {
1142 $result = $websitepagetemp->fetch(0, $object->id, $aliastotest);
1143 if ($result < 0) {
1144 $error++;
1145 $langs->load("errors");
1146 setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
1147 $action = 'createcontainer';
1148 break;
1149 }
1150 if ($result > 0) {
1151 $error++;
1152 $langs->load("errors");
1153 setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
1154 $action = 'createcontainer';
1155 break;
1156 }
1157 $newaliasnames .= ($newaliasnames ? ', ' : '').$aliastotest;
1158 }
1159 }
1160 }
1161
1162 $objectpage->title = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
1163 $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
1164 $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
1165 $objectpage->aliasalt = $newaliasnames;
1166 $objectpage->description = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
1167 $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
1168 $objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
1169 $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
1170 $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
1171 $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09') ? 1 : 0;
1172 $objectpage->htmlheader = GETPOST('htmlheader', 'none'); // Must accept tags like '<script>' and '<link>'
1173 $objectpage->author_alias = GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml');
1174 $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS');
1175 $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID');
1176 $substitutionarray = array();
1177 $substitutionarray['__WEBSITE_CREATED_BY__'] = $user->getFullName($langs);
1178
1179 // Define id of the page the new page is translation of
1180 /*
1181 if ($objectpage->lang == $object->lang) {
1182 // If
1183 $pageidfortranslation = (GETPOSTINT('pageidfortranslation') > 0 ? GETPOSTINT('pageidfortranslation') : 0);
1184 if ($pageidfortranslation > 0) {
1185 // We must update the page $pageidfortranslation to set fk_page = $object->id.
1186 // But what if page $pageidfortranslation is already linked to another ?
1187 }
1188 } else {
1189 */
1190 $pageidfortranslation = (GETPOSTINT('pageidfortranslation') > 0 ? GETPOSTINT('pageidfortranslation') : 0);
1191 if ($pageidfortranslation > 0) {
1192 // Check if the page we are translation of is already a translation of a source page. if yes, we will use source id instead
1193 $objectpagetmp = new WebsitePage($db);
1194 $objectpagetmp->fetch($pageidfortranslation);
1195 if ($objectpagetmp->fk_page > 0) {
1196 $pageidfortranslation = $objectpagetmp->fk_page;
1197 }
1198 }
1199 $objectpage->fk_page = $pageidfortranslation;
1200 //}
1201
1202 $content = '';
1203 if (GETPOSTISSET('content')) {
1204 //$content = GETPOST('content', 'restricthtmlallowunvalid'); // @TODO Use a restricthtmlallowunvalidwithphp
1205 $content = GETPOST('content', 'none'); // @TODO Use a restricthtmlallowunvalidwithphp
1206
1207 $objectpage->content = make_substitutions($content, $substitutionarray);
1208 } else {
1209 /*$sample = GETPOST('sample', 'alpha');
1210 if (empty($sample)) {
1211 $sample = 'empty';
1212 }
1213
1214 $pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.dol_sanitizeFileName(strtolower($sample)).'.html';
1215 */
1216 // Init content with content into page-sample-...
1217 //$objectpage->content = make_substitutions(@file_get_contents($pathtosample), $substitutionarray);
1218 }
1219 }
1220
1221 if (!$error) {
1222 if (empty($objectpage->pageurl)) {
1223 $langs->load("errors");
1224 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
1225 $error++;
1226 $action = 'createcontainer';
1227 } elseif (!preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl)) {
1228 $langs->load("errors");
1229 setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
1230 $error++;
1231 $action = 'createcontainer';
1232 }
1233 if (empty($objectpage->title)) {
1234 $langs->load("errors");
1235 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors');
1236 $error++;
1237 $action = 'createcontainer';
1238 }
1239 if ($objectpage->fk_page > 0 && empty($objectpage->lang)) {
1240 $langs->load("errors");
1241 setEventMessages($langs->trans("ErrorLanguageRequiredIfPageIsTranslationOfAnother"), null, 'errors');
1242 $error++;
1243 $action = 'createcontainer';
1244 }
1245 if ($objectpage->fk_page > 0 && !empty($objectpage->lang)) {
1246 if ($objectpage->lang == $website->lang) {
1247 $langs->load("errors");
1248 setEventMessages($langs->trans("ErrorLanguageMustNotBeSourceLanguageIfPageIsTranslationOfAnother"), null, 'errors');
1249 $error++;
1250 $action = 'createcontainer';
1251 }
1252 }
1253 }
1254
1255 $pageid = 0;
1256 if (!$error) {
1257 // Create page. This also check there is no PHP content if user has no pemrissions for that.
1258 $pageid = $objectpage->create($user);
1259 if ($pageid <= 0) {
1260 $error++;
1261 setEventMessages($objectpage->error, $objectpage->errors, 'errors');
1262 $action = 'createcontainer';
1263 }
1264 }
1265
1266 if (!$error) {
1267 // Website categories association
1268 $categoriesarray = GETPOST('categories', 'array');
1269 $result = $objectpage->setCategories($categoriesarray);
1270 if ($result < 0) {
1271 $error++;
1272 setEventMessages($object->error, $object->errors, 'errors');
1273 }
1274 }
1275
1276 if (!$error) {
1277 // If there is no home page yet, this new page will be set as the home page
1278 if (empty($object->fk_default_home)) {
1279 $object->fk_default_home = $pageid;
1280 $res = $object->update($user);
1281 if ($res <= 0) {
1282 $error++;
1283 setEventMessages($object->error, $object->errors, 'errors');
1284 } else {
1285 $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
1286
1287 // Generate the index.php page (to be the home page) and the wrapper.php file
1288 $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
1289
1290 if ($result <= 0) {
1291 setEventMessages('Failed to write file '.$fileindex, null, 'errors');
1292 }
1293 }
1294 }
1295 }
1296
1297 if (!$error) {
1298 if ($pageid > 0) {
1299 $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
1300 $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
1301
1302 // Save page alias
1303 $result = dolSavePageAlias($filealias, $object, $objectpage);
1304 if (!$result) {
1305 setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
1306 }
1307
1308 // Save page of content
1309 $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
1310 if ($result) {
1311 setEventMessages($langs->trans("Saved"), null, 'mesgs');
1312 } else {
1313 setEventMessages('Failed to write file '.$filetpl, null, 'errors');
1314 $action = 'createcontainer';
1315 }
1316 }
1317 }
1318
1319 if (!$error) {
1320 $db->commit();
1321 setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
1322 $action = '';
1323 } else {
1324 $db->rollback();
1325 }
1326
1327 if (!$error) {
1328 $pageid = $objectpage->id;
1329
1330 // To generate the CSS, robot and htmlheader file.
1331
1332 // Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko.
1333 // Recreate also dir of website if not found.
1334 $pathtomedias = DOL_DATA_ROOT.'/medias';
1335 $pathtomediasinwebsite = $pathofwebsite.'/medias';
1336 if (!is_link(dol_osencode($pathtomediasinwebsite))) {
1337 dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
1338 dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists
1339 $result = symlink($pathtomedias, $pathtomediasinwebsite);
1340 if (!$result) {
1341 $langs->load("errors");
1342 setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
1343 }
1344 }
1345
1346 // Now generate the master.inc.php page if it does not exists yet
1347 if (!dol_is_file($filemaster)) {
1348 $result = dolSaveMasterFile($filemaster);
1349 if (!$result) {
1350 $error++;
1351 setEventMessages('Failed to write file '.$filemaster, null, 'errors');
1352 }
1353 }
1354
1355 if (!dol_is_file($filehtmlheader)) {
1356 $htmlheadercontent = "<html>\n";
1357 $htmlheadercontent .= $htmlheadercontentdefault;
1358 $htmlheadercontent .= "</html>";
1359 $result = dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
1360 }
1361
1362 if (!dol_is_file($filecss)) {
1363 $csscontent = "/* CSS content (all pages) */\nbody.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
1364 $result = dolSaveCssFile($filecss, $csscontent);
1365 }
1366
1367 if (!dol_is_file($filejs)) {
1368 $jscontent = "/* JS content (all pages) */\n";
1369 $result = dolSaveJsFile($filejs, $jscontent);
1370 }
1371
1372 if (!dol_is_file($filerobot)) {
1373 $robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
1374 $result = dolSaveRobotFile($filerobot, $robotcontent);
1375 }
1376
1377 if (!dol_is_file($filehtaccess)) {
1378 $htaccesscontent = "# Order allow,deny\n# Deny from all";
1379 $result = dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
1380 }
1381
1382 if (!dol_is_file($filemanifestjson)) {
1383 $manifestjsoncontent = "";
1384 $result = dolSaveManifestJson($filemanifestjson, $manifestjsoncontent);
1385 }
1386
1387 if (!dol_is_file($filereadme)) {
1388 $readmecontent = "Website generated by Dolibarr ERP CRM";
1389 $result = dolSaveReadme($filereadme, $readmecontent);
1390 }
1391
1392 if (!dol_is_file($filelicense)) {
1393 $licensecontent = "MIT License";
1394 $result = dolSaveLicense($filelicense, $licensecontent);
1395 }
1396
1397 $action = 'preview';
1398 }
1399}
1400
1401// Delete site
1402if ($action == 'confirm_deletesite' && $confirm == 'yes' && $permissiontodelete) {
1403 $error = 0;
1404
1405 $db->begin();
1406
1407 $res = $object->fetch(GETPOSTINT('id'));
1408 $website = $object;
1409
1410 if ($res > 0) {
1411 $res = $object->delete($user);
1412 if ($res <= 0) {
1413 $error++;
1414 setEventMessages($object->error, $object->errors, 'errors');
1415 }
1416 }
1417 if (!$error) {
1418 if (GETPOST('delete_also_js', 'alpha') == 'on') {
1419 $pathofwebsitejs = DOL_DATA_ROOT.'/medias/js/'.$object->ref;
1420
1421 dol_delete_dir_recursive($pathofwebsitejs);
1422 }
1423 if (GETPOST('delete_also_medias', 'alpha') == 'on') {
1424 $pathofwebsitemedias = DOL_DATA_ROOT.'/medias/image/'.$object->ref;
1425
1426 dol_delete_dir_recursive($pathofwebsitemedias);
1427 }
1428 }
1429
1430 if (!$error) {
1431 $db->commit();
1432 setEventMessages($langs->trans("SiteDeleted", $object->ref), null, 'mesgs');
1433
1434 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
1435 exit;
1436 } else {
1437 $db->rollback();
1438 setEventMessages($object->error, $object->errors, 'errors');
1439 }
1440}
1441
1442// Delete page (from website page menu)
1443if (GETPOSTISSET('pageid') && $action == 'delete' && $permissiontodelete && !GETPOST('file_manager')) {
1444 $error = 0;
1445
1446 $db->begin();
1447
1448 $res = $object->fetch(0, $websitekey);
1449 $website = $object;
1450
1451 $res = $objectpage->fetch($pageid, $object->id);
1452
1453 if ($res > 0) {
1454 $res = $objectpage->delete($user);
1455 if ($res <= 0) {
1456 $error++;
1457 setEventMessages($objectpage->error, $objectpage->errors, 'errors');
1458 }
1459 }
1460
1461 if (!$error) {
1462 $db->commit();
1463 setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $websitekey), null, 'mesgs');
1464
1465 header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey);
1466 exit;
1467 } else {
1468 $db->rollback();
1469 dol_print_error($db);
1470 }
1471}
1472// Delete page (from menu search)
1473if (!GETPOSTISSET('pageid')) {
1474 $objectclass = 'WebsitePage';
1475
1476 // Add part of code from actions_massactions.inc.php
1477 // Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before)
1478 if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) {
1479 $db->begin();
1480
1481 $objecttmp = new $objectclass($db);
1482 $nbok = 0;
1483 foreach ($toselect as $toselectid) {
1484 $result = $objecttmp->fetch($toselectid);
1485 if ($result > 0) {
1486 $result = $objecttmp->delete($user);
1487
1488 if ($result <= 0) {
1489 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1490 $error++;
1491 break;
1492 } else {
1493 $nbok++;
1494 }
1495 } else {
1496 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1497 $error++;
1498 break;
1499 }
1500 }
1501
1502 if (!$error) {
1503 if ($nbok > 1) {
1504 setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
1505 } else {
1506 setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
1507 }
1508 $db->commit();
1509 } else {
1510 $db->rollback();
1511 }
1512 //var_dump($listofobjectthirdparties);exit;
1513 }
1514
1515 if ($action == 'delete') { // Test on permission not required here
1516 $mode = 'replacesite';
1517 $action = 'replacesite';
1518
1519 $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
1520 $langcode = GETPOST('optionlanguage', 'aZ09');
1521 $otherfilters = array();
1522 if (GETPOSTINT('optioncategory') > 0) {
1523 $otherfilters['category'] = GETPOSTINT('optioncategory');
1524 }
1525
1526 $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
1527 }
1528}
1529
1530// Update css site properties. Re-generates also the wrapper.
1531if ($action == 'updatecss' && $usercanedit) {
1532 // If we tried to reload another site/page, we stay on editcss mode.
1533 if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
1534 $action = 'editcss';
1535 } else {
1536 $res = $object->fetch(0, $websitekey);
1537 $website = $object;
1538
1539 if (GETPOSTISSET('virtualhost')) {
1540 $tmpvirtualhost = preg_replace('/\/$/', '', GETPOST('virtualhost', 'alpha'));
1541 if ($tmpvirtualhost && !preg_match('/^http/', $tmpvirtualhost)) {
1542 $error++;
1543 setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
1544 $action = 'editcss';
1545 }
1546
1547 if (!$error) {
1548 $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
1549 foreach ($arrayotherlang as $key => $val) {
1550 // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
1551 if (empty(trim($val))) {
1552 continue;
1553 }
1554 $arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
1555 }
1556
1557 $object->virtualhost = $tmpvirtualhost;
1558 $object->lang = GETPOST('WEBSITE_LANG', 'aZ09');
1559 $object->otherlang = implode(',', $arrayotherlang);
1560 $object->use_manifest = GETPOSTINT('use_manifest');
1561
1562 $result = $object->update($user);
1563 if ($result < 0) {
1564 $error++;
1565 setEventMessages($object->error, $object->errors, 'errors');
1566 $action = 'editcss';
1567 }
1568 }
1569 }
1570
1571 if (!$error) {
1572 if (($_FILES['addedfile']["name"] != '')) {
1573 $uploadfolder = $conf->website->dir_output.'/'.$websitekey;
1574 if ($_FILES['addedfile']['type'] != 'image/png') {
1575 $error++;
1576 setEventMessages($langs->trans('ErrorFaviconType'), array(), 'errors');
1577 }
1578 $filetoread = realpath(dol_osencode($_FILES['addedfile']['tmp_name']));
1579 $filesize = getimagesize($filetoread);
1580 if ($filesize[0] != $filesize[1]) {
1581 $error++;
1582 setEventMessages($langs->trans('ErrorFaviconMustBeASquaredImage'), array(), 'errors');
1583 }
1584 if (! $error && ($filesize[0] != 16 && $filesize[0] != 32 && $filesize[0] != 64)) {
1585 $error++;
1586 setEventMessages($langs->trans('ErrorFaviconSize'), array(), 'errors');
1587 }
1588 if (!$error) {
1589 dol_add_file_process($uploadfolder, 1, 0, 'addedfile', 'favicon.png');
1590 }
1591 }
1592 if ($error) {
1593 if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
1594 $action = 'preview';
1595 if ($backtopage) {
1596 $backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
1597 header("Location: ".$backtopage);
1598 exit;
1599 }
1600 } else {
1601 $action = 'editcss';
1602 }
1603 }
1604 }
1605
1606 if (!$error) {
1607 // Save master.inc.php file
1608 dol_syslog("Save master file ".$filemaster);
1609
1610 dol_mkdir($pathofwebsite);
1611
1612 // Now generate the master.inc.php page
1613 $result = dolSaveMasterFile($filemaster);
1614 if (!$result) {
1615 $error++;
1616 setEventMessages('Failed to write file '.$filemaster, null, 'errors');
1617 }
1618
1619
1620 $dataposted = trim(GETPOST('WEBSITE_HTML_HEADER', 'restricthtmlallowlinkscript')); // Must accept tags like '<script>' and '<link>'
1621
1622 $dataposted = preg_replace(array('/<html>\n*/ims', '/<\/html>\n*/ims'), array('', ''), $dataposted);
1623 $dataposted = str_replace('<?=', '<?php', $dataposted);
1624
1625 // Html header file
1626 $phpfullcodestringold = '';
1627 $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1628
1629 // Security analysis
1630 $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1631
1632 if (!$errorphpcheck) {
1633 $htmlheadercontent = '';
1634
1635 /* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
1636 $htmlheadercontent.= "<?php // BEGIN PHP\n";
1637 $htmlheadercontent.= '$websitekey=basename(__DIR__);'."\n";
1638 $htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load env if not already loaded"."\n";
1639 $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1640 $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1641 $htmlheadercontent.= "ob_start();\n";
1642 // $htmlheadercontent.= "header('Content-type: text/html');\n"; // Not required. htmlheader.html is never call as a standalone page
1643 $htmlheadercontent.= "// END PHP ?>\n";*/
1644
1645 $htmlheadercontent .= $dataposted."\n";
1646
1647 /*$htmlheadercontent.= "\n".'<?php // BEGIN PHP'."\n";
1648 $htmlheadercontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
1649 $htmlheadercontent.= "// END PHP"."\n";*/
1650
1651 $result = dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
1652 if (!$result) {
1653 $error++;
1654 setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors');
1655 }
1656 } else {
1657 $error++;
1658 }
1659
1660 $dataposted = trim(GETPOST('WEBSITE_CSS_INLINE', 'none'));
1661 $dataposted = str_replace('<?=', '<?php', $dataposted);
1662
1663 // Css file
1664 $phpfullcodestringold = '';
1665 $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1666
1667 // Security analysis
1668 $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1669
1670 if (!$errorphpcheck) {
1671 $csscontent = '';
1672
1673 $csscontent .= "<?php // BEGIN PHP\n";
1674 $csscontent .= '$websitekey=basename(__DIR__);'."\n";
1675 $csscontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
1676 $csscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1677 $csscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1678 $csscontent .= "ob_start();\n";
1679 $csscontent .= "if (! headers_sent()) { /* because file is included inline when in edit mode and we don't want warning */ \n";
1680 $csscontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1681 $csscontent .= "header('Content-type: text/css');\n";
1682 $csscontent .= "}\n";
1683 $csscontent .= "// END PHP ?>\n";
1684
1685 $csscontent .= $dataposted."\n";
1686
1687 $csscontent .= '<?php // BEGIN PHP'."\n";
1688 $csscontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "css");'."\n";
1689 $csscontent .= "// END PHP\n";
1690
1691 dol_syslog("Save css content into ".$filecss);
1692
1693 $result = dolSaveCssFile($filecss, $csscontent);
1694 if (!$result) {
1695 $error++;
1696 setEventMessages('Failed to write file '.$filecss, null, 'errors');
1697 }
1698 } else {
1699 $error++;
1700 }
1701
1702
1703 $dataposted = trim(GETPOST('WEBSITE_JS_INLINE', 'none'));
1704 $dataposted = str_replace('<?=', '<?php', $dataposted);
1705
1706 // Js file
1707 $phpfullcodestringold = '';
1708 $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1709
1710 // Security analysis
1711 $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1712
1713 if (!$errorphpcheck) {
1714 $jscontent = '';
1715
1716 $jscontent .= "<?php // BEGIN PHP\n";
1717 $jscontent .= '$websitekey=basename(__DIR__);'."\n";
1718 $jscontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
1719 $jscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1720 $jscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1721 $jscontent .= "ob_start();\n";
1722 $jscontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1723 $jscontent .= "header('Content-type: application/javascript');\n";
1724 $jscontent .= "// END PHP ?>\n";
1725
1726 $jscontent .= $dataposted."\n";
1727
1728 $jscontent .= '<?php // BEGIN PHP'."\n";
1729 $jscontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "js");'."\n";
1730 $jscontent .= "// END PHP\n";
1731
1732 $result = dolSaveJsFile($filejs, $jscontent);
1733 if (!$result) {
1734 $error++;
1735 setEventMessages('Failed to write file '.$filejs, null, 'errors');
1736 }
1737 } else {
1738 $error++;
1739 }
1740
1741 $dataposted = trim(GETPOST('WEBSITE_ROBOT', 'nohtml'));
1742 $dataposted = str_replace('<?=', '<?php', $dataposted);
1743
1744 // Robot file
1745 $phpfullcodestringold = '';
1746 $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1747
1748 // Security analysis
1749 $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1750
1751 if (!$errorphpcheck) {
1752 $robotcontent = '';
1753
1754 /*$robotcontent.= "<?php // BEGIN PHP\n";
1755 $robotcontent.= '$websitekey=basename(__DIR__);'."\n";
1756 $robotcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load env if not already loaded"."\n";
1757 $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1758 $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1759 $robotcontent.= "ob_start();\n";
1760 $robotcontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1761 $robotcontent.= "header('Content-type: text/css');\n";
1762 $robotcontent.= "// END PHP ?>\n";*/
1763
1764 $robotcontent .= $dataposted."\n";
1765
1766 /*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
1767 $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "robot");'."\n";
1768 $robotcontent.= "// END PHP ?>"."\n";*/
1769
1770 $result = dolSaveRobotFile($filerobot, $robotcontent);
1771 if (!$result) {
1772 $error++;
1773 setEventMessages('Failed to write file '.$filerobot, null, 'errors');
1774 }
1775 } else {
1776 $error++;
1777 }
1778
1779 $dataposted = trim(GETPOST('WEBSITE_HTACCESS', 'nohtml'));
1780 $dataposted = str_replace('<?=', '<?php', $dataposted);
1781
1782 // Htaccess file
1783 $phpfullcodestringold = '';
1784 $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1785
1786 // Security analysis
1787 $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1788
1789 if (!$errorphpcheck) {
1790 if ($dataposted) {
1791 $htaccesscontent = '';
1792 $htaccesscontent .= $dataposted."\n";
1793
1794 $result = dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
1795 if (!$result) {
1796 $error++;
1797 setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
1798 }
1799 } else {
1800 dol_delete_file($filehtaccess, 0, 0);
1801 }
1802 } else {
1803 $error++;
1804 }
1805
1806
1807 $dataposted = trim(GETPOST('WEBSITE_MANIFEST_JSON', 'restricthtmlallowunvalid'));
1808 $dataposted = str_replace('<?=', '<?php', $dataposted);
1809
1810 // Manifest.json file
1811 $phpfullcodestringold = '';
1812 $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1813
1814 // Security analysis
1815 $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1816
1817 if (!$errorphpcheck) {
1818 $manifestjsoncontent = '';
1819
1820 $manifestjsoncontent .= "<?php // BEGIN PHP\n";
1821 $manifestjsoncontent .= '$websitekey=basename(__DIR__);'."\n";
1822 $manifestjsoncontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
1823 $manifestjsoncontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1824 $manifestjsoncontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1825 $manifestjsoncontent .= "ob_start();\n";
1826 $manifestjsoncontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1827 $manifestjsoncontent .= "header('Content-type: application/manifest+json');\n";
1828 $manifestjsoncontent .= "// END PHP ?>\n";
1829
1830 $manifestjsoncontent .= $dataposted."\n";
1831
1832 $manifestjsoncontent .= '<?php // BEGIN PHP'."\n";
1833 $manifestjsoncontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
1834 $manifestjsoncontent .= "// END PHP\n";
1835
1836 $result = dolSaveManifestJson($filemanifestjson, $manifestjsoncontent);
1837 if (!$result) {
1838 $error++;
1839 setEventMessages('Failed to write file '.$filemanifestjson, null, 'errors');
1840 }
1841 } else {
1842 $error++;
1843 }
1844
1845
1846 $dataposted = trim(GETPOST('WEBSITE_README', 'nohtml'));
1847 $dataposted = str_replace('<?=', '<?php', $dataposted);
1848
1849 // README.md file
1850 $phpfullcodestringold = '';
1851 $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1852
1853 // Security analysis
1854 $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1855
1856 if (!$errorphpcheck) {
1857 $readmecontent = '';
1858
1859 /*$readmecontent.= "<?php // BEGIN PHP\n";
1860 $readmecontent.= '$websitekey=basename(__DIR__);'."\n";
1861 $readmecontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
1862 $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1863 $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1864 $readmecontent.= "ob_start();\n";
1865 $readmecontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1866 $readmecontent.= "header('Content-type: application/manifest+json');\n";
1867 $readmecontent.= "// END PHP ?>\n";*/
1868
1869 $readmecontent .= $dataposted."\n";
1870
1871 /*$readmecontent.= '<?php // BEGIN PHP'."\n";
1872 $readmecontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
1873 $readmecontent.= "// END PHP ?>"."\n";*/
1874
1875 $result = dolSaveReadme($filereadme, $readmecontent);
1876 if (!$result) {
1877 $error++;
1878 setEventMessages('Failed to write file '.$filereadme, null, 'errors');
1879 }
1880 } else {
1881 $error++;
1882 }
1883
1884
1885 $dataposted = trim(GETPOST('WEBSITE_LICENSE', 'nohtml'));
1886 $dataposted = str_replace('<?=', '<?php', $dataposted);
1887
1888 // LICENSE file
1889 $phpfullcodestringold = '';
1890 $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
1891
1892 // Security analysis
1893 $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
1894
1895 if (!$errorphpcheck) {
1896 $licensecontent = '';
1897
1898 /*$readmecontent.= "<?php // BEGIN PHP\n";
1899 $readmecontent.= '$websitekey=basename(__DIR__);'."\n";
1900 $readmecontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
1901 $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1902 $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1903 $readmecontent.= "ob_start();\n";
1904 $readmecontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
1905 $readmecontent.= "header('Content-type: application/manifest+json');\n";
1906 $readmecontent.= "// END PHP ?>\n";*/
1907
1908 $licensecontent .= $dataposted."\n";
1909
1910 /*$readmecontent.= '<?php // BEGIN PHP'."\n";
1911 $readmecontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
1912 $readmecontent.= "// END PHP ?>"."\n";*/
1913
1914 $result = dolSaveLicense($filelicense, $licensecontent);
1915 if (!$result) {
1916 $error++;
1917 setEventMessages('Failed to write file '.$filelicense, null, 'errors');
1918 }
1919 } else {
1920 $error++;
1921 }
1922
1923 // Save wrapper.php
1924 $result = dolSaveIndexPage($pathofwebsite, '', '', $filewrapper, $object);
1925
1926
1927 // Message if no error
1928 if (!$error) {
1929 setEventMessages($langs->trans("Saved"), null, 'mesgs');
1930 }
1931
1932 if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
1933 $action = 'preview';
1934 if ($backtopage) {
1935 $backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
1936 header("Location: ".$backtopage);
1937 exit;
1938 }
1939 } else {
1940 $action = 'editcss';
1941 }
1942 }
1943 }
1944}
1945
1946// Update page
1947if ($action == 'setashome' && $usercanedit) {
1948 $db->begin();
1949 $object->fetch(0, $websitekey);
1950 $website = $object;
1951
1952 $object->fk_default_home = $pageid;
1953 $res = $object->update($user);
1954 if (! ($res > 0)) {
1955 $error++;
1956 setEventMessages($object->error, $object->errors, 'errors');
1957 }
1958
1959 if (!$error) {
1960 $db->commit();
1961
1962 $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
1963
1964 // Generate the index.php page to be the home page
1965 $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
1966
1967 if ($result) {
1968 setEventMessages($langs->trans("Saved"), null, 'mesgs');
1969 } else {
1970 setEventMessages('Failed to write file '.$fileindex, null, 'errors');
1971 }
1972
1973 $action = 'preview';
1974 } else {
1975 $db->rollback();
1976 }
1977}
1978
1979// Update page properties (meta)
1980if ($action == 'updatemeta' && $usercanedit) {
1981 $db->begin();
1982
1983 $result = $object->fetch(0, $websitekey);
1984 $website = $object;
1985
1986 $objectpage->fk_website = $object->id;
1987
1988 // Check parameters
1989 if (!preg_match('/^[a-z0-9\-\_]+$/i', GETPOST('WEBSITE_PAGENAME', 'alpha'))) {
1990 $error++;
1991 $langs->load("errors");
1992 setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
1993 $action = 'editmeta';
1994 }
1995
1996 $res = $objectpage->fetch($pageid, $object->id);
1997 if ($res <= 0) {
1998 $error++;
1999 setEventMessages('Page not found '.$objectpage->error, $objectpage->errors, 'errors');
2000 }
2001
2002 // Check alias not exists
2003 if (!$error && GETPOST('WEBSITE_PAGENAME', 'alpha')) {
2004 $websitepagetemp = new WebsitePage($db);
2005 $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, GETPOST('WEBSITE_PAGENAME', 'alpha'));
2006 if ($result < 0) {
2007 $error++;
2008 $langs->load("errors");
2009 setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
2010 $action = 'editmeta';
2011 }
2012 if ($result > 0) {
2013 $error++;
2014 $langs->load("errors");
2015 setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
2016 $action = 'editmeta';
2017 }
2018 }
2019
2020 $newaliasnames = '';
2021 if (!$error && GETPOST('WEBSITE_ALIASALT', 'alpha')) {
2022 $arrayofaliastotest = explode(',', str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alpha')));
2023
2024 $websitepagetemp = new WebsitePage($db);
2025 foreach ($arrayofaliastotest as $aliastotest) {
2026 $aliastotest = trim(preg_replace('/\.php$/i', '', $aliastotest));
2027
2028 // Disallow alias name pageX (already used to save the page with id)
2029 if (preg_match('/^page\d+/i', $aliastotest)) {
2030 $error++;
2031 $langs->load("errors");
2032 setEventMessages("Alias name 'pageX' is not allowed", null, 'errors');
2033 $action = 'editmeta';
2034 break;
2035 } else {
2036 $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, $aliastotest);
2037 if ($result < 0) {
2038 $error++;
2039 $langs->load("errors");
2040 setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
2041 $action = 'editmeta';
2042 break;
2043 }
2044 if ($result > 0) {
2045 $error++;
2046 $langs->load("errors");
2047 setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
2048 $action = 'editmeta';
2049 break;
2050 }
2051 $newaliasnames .= ($newaliasnames ? ', ' : '').$aliastotest;
2052 }
2053 }
2054 }
2055
2056 if (!$error) {
2057 $objectpage->old_object = clone $objectpage;
2058
2059 $objectpage->title = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
2060 $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
2061 $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
2062 $objectpage->aliasalt = $newaliasnames;
2063 $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
2064 $objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
2065 $objectpage->description = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
2066 $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
2067 $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
2068 $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09') ? 1 : 0;
2069 $objectpage->htmlheader = trim(GETPOST('htmlheader', 'restricthtmlallowlinkscript')); // Must accept tags like '<script>' and '<link>'
2070 $objectpage->fk_page = (GETPOSTINT('pageidfortranslation') > 0 ? GETPOSTINT('pageidfortranslation') : 0);
2071 $objectpage->author_alias = trim(GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml'));
2072 $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS', 'alpha');
2073 $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID', 'aZ09');
2074
2075 $newdatecreation = dol_mktime(GETPOSTINT('datecreationhour'), GETPOSTINT('datecreationmin'), GETPOSTINT('datecreationsec'), GETPOSTINT('datecreationmonth'), GETPOSTINT('datecreationday'), GETPOSTINT('datecreationyear'));
2076 if ($newdatecreation) {
2077 $objectpage->date_creation = $newdatecreation;
2078 }
2079
2080 $res = $objectpage->update($user);
2081 if (!($res > 0)) {
2082 $langs->load("errors");
2083 if ($db->lasterrno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
2084 $error++;
2085 $langs->load("errors");
2086 setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists"), null, 'errors');
2087 $action = 'editmeta';
2088 } else {
2089 $error++;
2090 $langs->load("errors");
2091 setEventMessages($objectpage->error, $objectpage->errors, 'errors');
2092 $action = 'editmeta';
2093 }
2094 }
2095 }
2096
2097 if (!$error) {
2098 // Website categories association
2099 $categoriesarray = GETPOST('categories', 'array');
2100 $result = $objectpage->setCategories($categoriesarray);
2101 if ($result < 0) {
2102 $error++;
2103 setEventMessages($object->error, $object->errors, 'errors');
2104 }
2105 }
2106
2107 if (!$error) {
2108 $db->commit();
2109 } else {
2110 $db->rollback();
2111 }
2112
2113 if (!$error) {
2114 $filemaster = $pathofwebsite.'/master.inc.php';
2115 $fileoldalias = $pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
2116 $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
2117
2118 dol_mkdir($pathofwebsite);
2119
2120 // Now generate the master.inc.php page
2121 $result = dolSaveMasterFile($filemaster);
2122 if (!$result) {
2123 setEventMessages('Failed to write file '.$filemaster, null, 'errors');
2124 }
2125
2126 // Now delete the alias.php page
2127 if (!empty($fileoldalias)) {
2128 dol_syslog("We delete old alias page name=".$fileoldalias." to build a new alias page=".$filealias);
2129 dol_delete_file($fileoldalias);
2130
2131 // Delete also pages into language subdirectories
2132 if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
2133 $dirname = dirname($fileoldalias);
2134 $filename = basename($fileoldalias);
2135 $sublangs = explode(',', $object->otherlang);
2136 foreach ($sublangs as $sublang) {
2137 // Under certain conditions $sublang can be an empty string
2138 // ($object->otherlang with empty string or with string like this 'en,,sv')
2139 // if is the case we try to re-delete the main alias file. Avoid it.
2140 if (empty(trim($sublang))) {
2141 continue;
2142 }
2143 $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
2144 dol_delete_file($fileoldaliassub);
2145 }
2146 }
2147 }
2148 // Now delete the alternative alias.php pages
2149 if (!empty($objectpage->old_object->aliasalt)) {
2150 $tmpaltaliases = explode(',', $objectpage->old_object->aliasalt);
2151 if (is_array($tmpaltaliases)) {
2152 foreach ($tmpaltaliases as $tmpaliasalt) {
2153 dol_syslog("We delete old alt alias pages name=".trim($tmpaliasalt));
2154 dol_delete_file($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
2155
2156 // Delete also pages into language subdirectories
2157 if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
2158 $dirname = dirname($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
2159 $filename = basename($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
2160 $sublangs = explode(',', $object->otherlang);
2161 foreach ($sublangs as $sublang) {
2162 // Under certain conditions $ sublang can be an empty string
2163 // ($object->otherlang with empty string or with string like this 'en,,sv')
2164 // if is the case we try to re-delete the main alias file. Avoid it.
2165 if (empty(trim($sublang))) {
2166 continue;
2167 }
2168 $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
2169 dol_delete_file($fileoldaliassub);
2170 }
2171 }
2172 }
2173 }
2174 }
2175
2176 // Save page main alias
2177 $result = dolSavePageAlias($filealias, $object, $objectpage);
2178 if (!$result) {
2179 setEventMessages('Failed to write file '.$filealias, null, 'errors');
2180 }
2181 // Save alt aliases
2182 if (!empty($objectpage->aliasalt)) {
2183 $tmpaltaliases = explode(',', $objectpage->aliasalt);
2184 if (is_array($tmpaltaliases)) {
2185 foreach ($tmpaltaliases as $tmpaliasalt) {
2186 if (trim($tmpaliasalt)) {
2187 $filealias = $pathofwebsite.'/'.trim($tmpaliasalt).'.php';
2188 $result = dolSavePageAlias($filealias, $object, $objectpage);
2189 if (!$result) {
2190 setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
2191 }
2192 }
2193 }
2194 }
2195 }
2196
2197
2198 // Save page of content
2199 $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
2200 if ($result) {
2201 setEventMessages($langs->trans("Saved"), null, 'mesgs');
2202
2203 if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we do not make the redirect
2204 //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
2205 //exit;
2206 $action = 'preview';
2207 } else {
2208 $action = 'editmeta';
2209 }
2210 } else {
2211 setEventMessages('Failed to write file '.$filetpl, null, 'errors');
2212 //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
2213 //exit;
2214 $action = 'preview';
2215 }
2216 }
2217}
2218
2219// Update page
2220if ((($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createfromclone' || $action == 'confirm_createpagefromclone') || ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview')))) && $usercanedit) {
2221 $object->fetch(0, $websitekey);
2222 $website = $object;
2223
2224 if ($action == 'confirm_createfromclone') { // Test on permissions already done
2225 $db->begin();
2226
2227 $objectnew = new Website($db);
2228 $result = $objectnew->createFromClone($user, GETPOSTINT('id'), GETPOST('siteref'), (GETPOSTINT('newlang') ? GETPOSTINT('newlang') : ''));
2229
2230 if ($result < 0) {
2231 $error++;
2232 setEventMessages($objectnew->error, $objectnew->errors, 'errors');
2233 $action = 'preview';
2234
2235 $db->rollback();
2236 } else {
2237 setEventMessages("ObjectClonedSuccessfuly", null, 'mesgs');
2238 $object = $objectnew;
2239 $id = $object->id;
2240 $pageid = $object->fk_default_home;
2241 $websitekey = GETPOST('siteref', 'aZ09');
2242
2243 $db->commit();
2244 }
2245 }
2246
2247 if ($action == 'confirm_createpagefromclone') { // Test on permissions already done
2248 $istranslation = (GETPOST('is_a_translation', 'aZ09') == 'on' ? 1 : 0);
2249 // Protection if it is a translation page
2250 if ($istranslation) {
2251 if (GETPOST('newlang', 'aZ09') == $objectpage->lang || !GETPOST('newlang', 'aZ09')) {
2252 $error++;
2253 setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
2254 $action = 'preview';
2255 }
2256 if (GETPOSTINT('newwebsite') != $object->id) {
2257 $error++;
2258 setEventMessages($langs->trans("WebsiteMustBeSameThanClonedPageIfTranslation"), null, 'errors');
2259 $action = 'preview';
2260 }
2261 }
2262
2263 if (!$error) {
2264 $db->begin();
2265
2266 $newwebsiteid = GETPOSTINT('newwebsite');
2267 $pathofwebsitenew = $pathofwebsite;
2268
2269 $tmpwebsite = new Website($db);
2270 if ($newwebsiteid > 0 && $newwebsiteid != $object->id) {
2271 $tmpwebsite->fetch($newwebsiteid);
2272 $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$tmpwebsite->ref;
2273 } else {
2274 $tmpwebsite = $object;
2275 }
2276
2277 $objectpage = new WebsitePage($db);
2278 $resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('newpageurl', 'aZ09'), (GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''), $istranslation, $newwebsiteid, GETPOST('newtitle', 'alphanohtml'), $tmpwebsite);
2279 if ($resultpage < 0) {
2280 $error++;
2281 setEventMessages($objectpage->error, $objectpage->errors, 'errors');
2282 $action = 'createpagefromclone';
2283
2284 $db->rollback();
2285 } else {
2286 $filetpl = $pathofwebsitenew.'/page'.$resultpage->id.'.tpl.php';
2287 $fileindex = $pathofwebsitenew.'/index.php';
2288 $filewrapper = $pathofwebsitenew.'/wrapper.php';
2289
2290 //var_dump($pathofwebsitenew);
2291 //var_dump($filetpl);
2292 //exit;
2293
2294 dolSavePageContent($filetpl, $tmpwebsite, $resultpage, 1);
2295
2296 // Switch on the new page if web site of new page/container is same
2297 if (empty($newwebsiteid) || $newwebsiteid == $object->id) {
2298 $pageid = $resultpage->id;
2299 }
2300
2301 $db->commit();
2302 }
2303 }
2304 }
2305
2306 $res = 0;
2307
2308 if (!$error) {
2309 // Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko.
2310 // Recreate also dir of website if not found.
2311 $pathtomedias = DOL_DATA_ROOT.'/medias';
2312 $pathtomediasinwebsite = $pathofwebsite.'/medias';
2313 if (!is_link(dol_osencode($pathtomediasinwebsite))) {
2314 dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
2315 dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists
2316 $result = symlink($pathtomedias, $pathtomediasinwebsite);
2317 if (!$result) {
2318 $langs->load("errors");
2319 setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
2320 }
2321 }
2322
2323 /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
2324 {
2325 $object->virtualhost = GETPOST('previewsite', 'alpha');
2326 $object->update($user);
2327 }*/
2328
2329 $objectpage->fk_website = $object->id;
2330
2331 if ($pageid > 0) {
2332 $res = $objectpage->fetch($pageid);
2333 } else {
2334 $res = 0;
2335 if ($object->fk_default_home > 0) {
2336 $res = $objectpage->fetch($object->fk_default_home);
2337 }
2338 if (!($res > 0)) {
2339 $res = $objectpage->fetch(0, $object->id);
2340 }
2341 }
2342 }
2343
2344 if (!$error && $res > 0) {
2345 if ($action == 'updatesource' || $action == 'updatecontent') { // Test on permissions already done
2346 $db->begin();
2347
2348 $phpfullcodestringold = dolKeepOnlyPhpCode($objectpage->content);
2349
2350 $objectpage->content = GETPOST('PAGE_CONTENT', 'none'); // any HTML content allowed
2351
2352 $phpfullcodestring = dolKeepOnlyPhpCode($objectpage->content);
2353
2354 // Security analysis (check PHP content and check permission website->writephp if php content is modified)
2355 $error = checkPHPCode($phpfullcodestringold, $phpfullcodestring);
2356
2357 if ($error) {
2358 if ($action == 'updatesource') { // Test on permissions already done
2359 $action = 'editsource';
2360 }
2361 if ($action == 'updatecontent') { // Test on permissions already done
2362 $action = 'editcontent';
2363 }
2364 }
2365
2366 // Clean data. We remove all the head section.
2367 $objectpage->content = preg_replace('/<head>.*<\/head>/ims', '', $objectpage->content);
2368 /* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */
2369
2370
2371 $res = $objectpage->update($user);
2372 if ($res < 0) {
2373 $error++;
2374 setEventMessages($objectpage->error, $objectpage->errors, 'errors');
2375 if ($action == 'updatesource') { // Test on permissions already done
2376 $action = 'editsource';
2377 }
2378 if ($action == 'updatecontent') { // Test on permissions already done
2379 $action = 'editcontent';
2380 }
2381 }
2382
2383 if (!$error) {
2384 $db->commit();
2385
2386 $filemaster = $pathofwebsite.'/master.inc.php';
2387 //$fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
2388 $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
2389
2390 dol_mkdir($pathofwebsite);
2391
2392 // Now generate the master.inc.php page
2393 $result = dolSaveMasterFile($filemaster);
2394
2395 if (!$result) {
2396 setEventMessages('Failed to write the master file file '.$filemaster, null, 'errors');
2397 }
2398
2399 // Now delete the old alias.php page if we removed one
2400 /*if (!empty($fileoldalias))
2401 {
2402 dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
2403 dol_delete_file($fileoldalias);
2404
2405 // Delete also pages into language subdirectories
2406 if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
2407 $dirname = dirname($fileoldalias);
2408 $filename = basename($fileoldalias);
2409 $sublangs = explode(',', $object->otherlang);
2410 foreach ($sublangs as $sublang) {
2411 $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
2412 dol_delete_file($fileoldaliassub);
2413 }
2414 }
2415 }*/
2416
2417 // Save page alias
2418 $result = dolSavePageAlias($filealias, $object, $objectpage);
2419 if (!$result) {
2420 setEventMessages('Failed to write the alias file '.basename($filealias), null, 'errors');
2421 }
2422
2423 // Save page content
2424 $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
2425 if ($result) {
2426 setEventMessages($langs->trans("Saved"), null, 'mesgs');
2427
2428 if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we do not make the redirect
2429 if ($backtopage) {
2430 header("Location: ".$backtopage);
2431 exit;
2432 } else {
2433 header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
2434 exit;
2435 }
2436 } else {
2437 if ($action == 'updatesource') { // Test on permissions already done
2438 $action = 'editsource';
2439 }
2440 if ($action == 'updatecontent') { // Test on permissions already done
2441 $action = 'editcontent';
2442 }
2443 }
2444 } else {
2445 setEventMessages('Failed to write file '.$filetpl, null, 'errors');
2446 header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
2447 exit;
2448 }
2449 } else {
2450 $db->rollback();
2451 }
2452 } else {
2453 header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
2454 exit;
2455 }
2456 } else {
2457 if (!$error) {
2458 if (empty($websitekey) || $websitekey == '-1') {
2459 setEventMessages($langs->trans("NoWebSiteCreateOneFirst"), null, 'warnings');
2460 } else {
2461 setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
2462 setEventMessages($langs->trans("YouCanCreatePageOrImportTemplate"), null, 'warnings');
2463 }
2464 }
2465 }
2466}
2467
2468if ($action == 'deletelang' && $usercanedit) {
2469 $sql = "UPDATE ".MAIN_DB_PREFIX."website_page SET fk_page = NULL";
2470 $sql .= " WHERE rowid = ".GETPOSTINT('deletelangforid');
2471 //$sql .= " AND fk_page = ".((int) $objectpage->id);
2472
2473 $resql = $db->query($sql);
2474 if (!$resql) {
2475 setEventMessages($db->lasterror(), null, 'errors');
2476 } else {
2477 $objectpage->fk_page = null;
2478 }
2479
2480 $action = 'editmeta';
2481}
2482
2483
2484// Export site
2485if ($action == 'exportsite' && $user->hasRight('website', 'export')) {
2486 $fileofzip = $object->exportWebSite();
2487
2488 if ($fileofzip) {
2489 $file_name = basename($fileofzip);
2490 header("Content-Type: application/zip");
2491 header("Content-Disposition: attachment; filename=".$file_name);
2492 header("Content-Length: ".filesize($fileofzip));
2493
2494 readfile($fileofzip);
2495 exit;
2496 } else {
2497 setEventMessages($object->error, $object->errors, 'errors');
2498 $action = 'preview';
2499 }
2500}
2501
2502// Overwrite site
2503if ($action == 'overwritesite' && $user->hasRight('website', 'export')) {
2504 if (getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')) {
2505 $fileofzip = $object->exportWebSite();
2506 $pathToExport = GETPOST('export_path');
2507 if ($fileofzip) {
2508 $object->overwriteTemplate($fileofzip, $pathToExport);
2509 } else {
2510 setEventMessages($object->error, $object->errors, 'errors');
2511 }
2512 }
2513}
2514// Regenerate site
2515if ($action == 'regeneratesite' && $usercanedit) {
2516 // Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko.
2517 // Recreate also dir of website if not found.
2518 $pathtomedias = DOL_DATA_ROOT.'/medias';
2519 $pathtomediasinwebsite = $pathofwebsite.'/medias';
2520 if (!is_link(dol_osencode($pathtomediasinwebsite))) {
2521 dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
2522 dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists
2523 $result = symlink($pathtomedias, $pathtomediasinwebsite);
2524 if (!$result) {
2525 $langs->load("errors");
2526 setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
2527 $action = 'preview';
2528 }
2529 }
2530
2531 $result = $object->rebuildWebSiteFiles();
2532 if ($result > 0) {
2533 setEventMessages($langs->trans("PagesRegenerated", $result), null, 'mesgs');
2534 $action = 'preview';
2535 } else {
2536 setEventMessages($object->error, $object->errors, 'errors');
2537 $action = 'preview';
2538 }
2539}
2540
2541// Import site
2542if ($action == 'importsiteconfirm' && $usercanedit) {
2543 $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
2544 $allowimportsite = true;
2545 if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
2546 $allowimportsite = false;
2547 }
2548
2549 if ($allowimportsite) {
2550 if (empty($_FILES) && !GETPOSTISSET('templateuserfile')) {
2551 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
2552 $action = 'importsite';
2553 } else {
2554 if (!empty($_FILES) || GETPOSTISSET('templateuserfile')) {
2555 // Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko.
2556 // Recreate also dir of website if not found.
2557 $pathtomedias = DOL_DATA_ROOT.'/medias';
2558 $pathtomediasinwebsite = $pathofwebsite.'/medias';
2559 if (!is_link(dol_osencode($pathtomediasinwebsite))) {
2560 dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
2561 dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
2562 $result = symlink($pathtomedias, $pathtomediasinwebsite);
2563 if (!$result) {
2564 $langs->load("errors");
2565 setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
2566 $action = 'importsite';
2567 }
2568 }
2569
2570 $fileofzip = '';
2571 if (GETPOSTISSET('templateuserfile')) {
2572 // Case we selected one template
2573 $fileofzip = DOL_DATA_ROOT.'/doctemplates/websites/'.GETPOST('templateuserfile', 'alpha'); // $fileofzip will be sanitized later into the importWebSite()
2574 } elseif (!empty($_FILES) && is_array($_FILES['userfile'])) {
2575 // Case we upload a new template
2576 if (is_array($_FILES['userfile']['tmp_name'])) {
2577 $userfiles = $_FILES['userfile']['tmp_name'];
2578 } else {
2579 $userfiles = array($_FILES['userfile']['tmp_name']);
2580 }
2581
2582 // Check if $_FILES is ok
2583 foreach ($userfiles as $key => $userfile) {
2584 if (empty($_FILES['userfile']['tmp_name'][$key])) {
2585 $error++;
2586 if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2) {
2587 setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
2588 $action = 'importsite';
2589 } else {
2590 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
2591 $action = 'importsite';
2592 }
2593 }
2594 }
2595
2596 if (!$error) {
2597 //$upload_dir = $conf->website->dir_temp;
2598 $upload_dir = DOL_DATA_ROOT.'/doctemplates/websites/';
2599 $result = dol_add_file_process($upload_dir, 1, -1, 'userfile', '');
2600 }
2601
2602 // Get name of file (take last one if several name provided)
2603 /*
2604 $fileofzip = $upload_dir.'/unknown';
2605 foreach ($_FILES as $key => $ifile) {
2606 foreach ($ifile['name'] as $key2 => $ifile2) {
2607 $fileofzip = $upload_dir.'/'.$ifile2;
2608 }
2609 }
2610 */
2611
2612 $action = 'importsite';
2613 }
2614
2615 if (!$error && GETPOSTISSET('templateuserfile')) {
2616 $templatewithoutzip = preg_replace('/\.zip$/i', '', GETPOST('templateuserfile'));
2617 $object->setTemplateName($templatewithoutzip);
2618
2619 $result = $object->importWebSite($fileofzip);
2620
2621 if ($result < 0) {
2622 setEventMessages($object->error, $object->errors, 'errors');
2623 $action = 'importsite';
2624 } else {
2625 // Force mode dynamic on
2626 dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1, 'chaine', 0, '', $conf->entity);
2627
2628 header("Location: ".$_SERVER["PHP_SELF"].'?website='.$object->ref);
2629 exit();
2630 }
2631 }
2632 }
2633 }
2634 } else {
2635 if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
2636 // Show clean corporate message
2637 $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
2638 } else {
2639 // Show technical generic message
2640 $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
2641 }
2642 setEventMessages($message, null, 'errors');
2643 }
2644}
2645
2646$domainname = '0.0.0.0:8080';
2647$tempdir = $conf->website->dir_output.'/'.$websitekey.'/';
2648
2649// Generate web site sitemaps
2650if ($action == 'generatesitemaps' && $usercanedit) {
2651 // Define $domainname
2652 if ($website->virtualhost) {
2653 $domainname = $website->virtualhost;
2654 }
2655 if (! preg_match('/^http/i', $domainname)) {
2656 $domainname = 'https://'.$domainname;
2657 }
2658
2659 $domtree = new DOMDocument('1.0', 'UTF-8');
2660
2661 $root = $domtree->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
2662 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
2663
2664 $domtree->formatOutput = true;
2665
2666 $addrsswrapper = 0;
2667 $xmlname = 'sitemap.xml';
2668
2669 $sql = "SELECT wp.rowid, wp.type_container , wp.pageurl, wp.lang, wp.fk_page, wp.tms as tms,";
2670 $sql .= " w.virtualhost, w.fk_default_home";
2671 $sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp, ".MAIN_DB_PREFIX."website as w";
2672 $sql .= " WHERE wp.type_container IN ('page', 'blogpost')";
2673 $sql .= " AND wp.fk_website = w.rowid";
2674 $sql .= " AND wp.status = ".WebsitePage::STATUS_VALIDATED;
2675 $sql .= " AND wp.pageurl NOT IN ('404', '500', '501', '503')";
2676 $sql .= " AND w.ref = '".dol_escape_json($websitekey)."'";
2677 $sql .= " ORDER BY wp.tms DESC, wp.rowid DESC";
2678 $resql = $db->query($sql);
2679 if ($resql) {
2680 $num_rows = $db->num_rows($resql);
2681 if ($num_rows > 0) {
2682 $i = 0;
2683 while ($i < $num_rows) {
2684 $objp = $db->fetch_object($resql);
2685 $url = $domtree->createElement('url');
2686
2687 $shortlangcode = '';
2688 if ($objp->lang) {
2689 $shortlangcode = substr($objp->lang, 0, 2); // en_US or en-US -> en
2690 }
2691 if (empty($shortlangcode)) {
2692 $shortlangcode = substr($object->lang, 0, 2); // Use short lang code of website
2693 }
2694
2695 // Is it a blog post for the RSS wrapper ?
2696 if ($objp->type_container == 'blogpost') {
2697 $addrsswrapper = 1;
2698 }
2699
2700 // Forge $pageurl, adding language prefix if it is an alternative language
2701 $pageurl = $objp->pageurl.'.php';
2702 if ($objp->fk_default_home == $objp->rowid) {
2703 $pageurl = '';
2704 } else {
2705 if ($shortlangcode != substr($object->lang, 0, 2)) {
2706 $pageurl = $shortlangcode.'/'.$pageurl;
2707 }
2708 }
2709
2710 //$pathofpage = $dolibarr_main_url_root.'/'.$pageurl.'.php';
2711
2712 // URL of sitemaps must end with trailing slash if page is ''
2713 $loc = $domtree->createElement('loc', $domainname.'/'.$pageurl);
2714 $lastmod = $domtree->createElement('lastmod', dol_print_date($db->jdate($objp->tms), 'dayrfc', 'gmt'));
2715 $priority = $domtree->createElement('priority', '1');
2716
2717 $url->appendChild($loc);
2718 $url->appendChild($lastmod);
2719 // Add suggested frequency for refresh
2720 if (getDolGlobalString('WEBSITE_SITEMAPS_ADD_WEEKLY_FREQ')) {
2721 $changefreq = $domtree->createElement('changefreq', 'weekly'); // TODO Manage other values
2722 $url->appendChild($changefreq);
2723 }
2724 // Add higher priority for home page
2725 if ($objp->fk_default_home == $objp->rowid) {
2726 $url->appendChild($priority);
2727 }
2728
2729 // Now add alternate language entries
2730 if ($object->isMultiLang()) {
2731 $alternatefound = 0;
2732
2733 // Add page "translation of"
2734 $translationof = $objp->fk_page;
2735 if ($translationof) {
2736 $tmppage = new WebsitePage($db);
2737 $tmppage->fetch($translationof);
2738 if ($tmppage->id > 0) {
2739 $tmpshortlangcode = '';
2740 if ($tmppage->lang) {
2741 $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
2742 }
2743 if (empty($tmpshortlangcode)) {
2744 $tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en
2745 }
2746 if ($tmpshortlangcode != $shortlangcode) {
2747 $xhtmllink = $domtree->createElement('xhtml:link', '');
2748 $xhtmllink->setAttribute("rel", "alternate");
2749 $xhtmllink->setAttribute("hreflang", $tmpshortlangcode);
2750 $xhtmllink->setAttribute("href", $domainname.($objp->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2)) ? '/'.$tmpshortlangcode : '').'/'.$tmppage->pageurl.'.php'));
2751 $url->appendChild($xhtmllink);
2752
2753 $alternatefound++;
2754 }
2755 }
2756 }
2757
2758 // Add "has translation pages"
2759 $sql = 'SELECT rowid as id, lang, pageurl from '.MAIN_DB_PREFIX.'website_page';
2760 $sql .= " WHERE status = ".((int) WebsitePage::STATUS_VALIDATED).' AND fk_page IN ('.$db->sanitize($objp->rowid.($translationof ? ", ".$translationof : "")).")";
2761 $resqlhastrans = $db->query($sql);
2762 if ($resqlhastrans) {
2763 $num_rows_hastrans = $db->num_rows($resqlhastrans);
2764 if ($num_rows_hastrans > 0) {
2765 while ($objhastrans = $db->fetch_object($resqlhastrans)) {
2766 $tmpshortlangcode = '';
2767 if ($objhastrans->lang) {
2768 $tmpshortlangcode = preg_replace('/[_-].*$/', '', $objhastrans->lang); // en_US or en-US -> en
2769 }
2770 if ($tmpshortlangcode != $shortlangcode) {
2771 $xhtmllink = $domtree->createElement('xhtml:link', '');
2772 $xhtmllink->setAttribute("rel", "alternate");
2773 $xhtmllink->setAttribute("hreflang", $tmpshortlangcode);
2774 $xhtmllink->setAttribute("href", $domainname.($objp->fk_default_home == $objhastrans->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2) ? '/'.$tmpshortlangcode : '')).'/'.$objhastrans->pageurl.'.php'));
2775 $url->appendChild($xhtmllink);
2776
2777 $alternatefound++;
2778 }
2779 }
2780 }
2781 } else {
2782 dol_print_error($db);
2783 }
2784
2785 if ($alternatefound) {
2786 // Add myself
2787 $xhtmllink = $domtree->createElement('xhtml:link', '');
2788 $xhtmllink->setAttribute("rel", "alternate");
2789 $xhtmllink->setAttribute("hreflang", $shortlangcode);
2790 $xhtmllink->setAttribute("href", $domainname.'/'.$pageurl);
2791 $url->appendChild($xhtmllink);
2792 }
2793 }
2794
2795 // Now add sitempas extension for news
2796 // TODO When adding and when not ?
2797 /*<news:news>
2798 <news:publication>
2799 <news:name>The Example Times</news:name>
2800 <news:language>en</news:language>
2801 </news:publication>
2802 <news:publication_date>2008-12-23</news:publication_date>
2803 <news:title>Companies A, B in Merger Talks</news:title>
2804 </news:news>
2805 */
2806
2807 $root->appendChild($url);
2808 $i++;
2809 }
2810
2811 // Adding a RSS feed into a sitemap should not be required. The RSS contains pages that are already included into
2812 // the sitemap and RSS feeds are not shown into index.
2813 if ($addrsswrapper && getDolGlobalInt('WEBSITE_ADD_RSS_FEED_INTO_SITEMAP')) {
2814 $url = $domtree->createElement('url');
2815
2816 $pageurl = 'wrapper.php?rss=1';
2817
2818 // URL of sitemaps must end with trailing slash if page is ''
2819 $loc = $domtree->createElement('loc', $domainname.'/'.$pageurl);
2820 $lastmod = $domtree->createElement('lastmod', dol_print_date($db->jdate(dol_now()), 'dayrfc', 'gmt'));
2821
2822 $url->appendChild($loc);
2823 $url->appendChild($lastmod);
2824 // Add suggested frequency for refresh
2825 if (getDolGlobalString('WEBSITE_SITEMAPS_ADD_WEEKLY_FREQ')) {
2826 $changefreq = $domtree->createElement('changefreq', 'weekly'); // TODO Manage other values
2827 $url->appendChild($changefreq);
2828 }
2829
2830 $root->appendChild($url);
2831 }
2832
2833 $domtree->appendChild($root);
2834
2835 if ($domtree->save($tempdir.$xmlname)) {
2836 dolChmod($tempdir.$xmlname);
2837 setEventMessages($langs->trans("SitemapGenerated", $xmlname), null, 'mesgs');
2838 } else {
2839 setEventMessages($object->error, $object->errors, 'errors');
2840 }
2841 }
2842 } else {
2843 dol_print_error($db);
2844 }
2845
2846 // Add the entry Sitemap: into the robot.txt file.
2847 $robotcontent = @file_get_contents($filerobot);
2848 $result = preg_replace('/<?php \/\/ BEGIN PHP[^?]END PHP ?>\n/ims', '', $robotcontent);
2849 if ($result) {
2850 $robotcontent = $result;
2851 }
2852 $robotsitemap = "Sitemap: ".$domainname."/".$xmlname;
2853 $result = strpos($robotcontent, 'Sitemap: ');
2854 if ($result) {
2855 $result = preg_replace('/Sitemap:.*/', $robotsitemap, $robotcontent);
2856 $robotcontent = $result ? $result : $robotcontent;
2857 } else {
2858 $robotcontent .= $robotsitemap."\n";
2859 }
2860 $result = dolSaveRobotFile($filerobot, $robotcontent);
2861 if (!$result) {
2862 $error++;
2863 setEventMessages('Failed to write file '.$filerobot, null, 'errors');
2864 }
2865 $action = 'preview';
2866}
2867
2868
2869/*
2870 * View
2871 */
2872
2873$form = new Form($db);
2874$formadmin = new FormAdmin($db);
2875$formwebsite = new FormWebsite($db);
2876$formother = new FormOther($db);
2877$formconfirm = "";
2878
2879// Confirm generation of website sitemaps
2880if ($action == 'confirmgeneratesitemaps') {
2881 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.urlencode($website->ref), $langs->trans('ConfirmSitemapsCreation'), $langs->trans('ConfirmGenerateSitemaps', $object->ref), 'generatesitemaps', '', "yes", 1);
2882 $action = 'preview';
2883}
2884$helpurl = 'EN:Module_Website|FR:Module_Website_FR|ES:M&oacute;dulo_Website';
2885
2886$arrayofjs = array(
2887 '/includes/ace/src/ace.js',
2888 '/includes/ace/src/ext-statusbar.js',
2889 '/includes/ace/src/ext-language_tools.js',
2890 //'/includes/ace/src/ext-chromevox.js'
2891 //'/includes/jquery/plugins/jqueryscoped/jquery.scoped.js',
2892);
2893$arrayofcss = array();
2894
2895$moreheadcss = '';
2896$moreheadjs = '';
2897
2898$arrayofjs[] = 'includes/jquery/plugins/blockUI/jquery.blockUI.js';
2899$arrayofjs[] = 'core/js/blockUI.js'; // Used by ecm/tpl/enabledfiletreeajax.tpl.php
2900if (!getDolGlobalString('MAIN_ECM_DISABLE_JS')) {
2901 $arrayofjs[] = "includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
2902}
2903
2904$moreheadjs .= '<script type="text/javascript">'."\n";
2905$moreheadjs .= 'var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
2906$moreheadjs .= '</script>'."\n";
2907
2908llxHeader($moreheadcss.$moreheadjs, $langs->trans("Website").(empty($website->ref) ? '' : ' - '.$website->ref), $helpurl, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-website page-index', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
2909
2910print "\n";
2911print '<!-- Open form for all page -->'."\n";
2912print '<form action="'.$_SERVER["PHP_SELF"].($action == 'file_manager' ? '?uploadform=1' : '').'" method="POST" enctype="multipart/form-data" class="websiteformtoolbar">'."\n";
2913print '<input type="hidden" name="token" value="'.newToken().'">';
2914print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2915print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
2916
2917if ($action == 'createsite') {
2918 print '<input type="hidden" name="action" value="addsite">';
2919}
2920if ($action == 'createcontainer') {
2921 print '<input type="hidden" name="action" value="addcontainer">';
2922}
2923if ($action == 'editcss') {
2924 print '<input type="hidden" name="action" value="updatecss">';
2925}
2926if ($action == 'editmenu') {
2927 print '<input type="hidden" name="action" value="updatemenu">';
2928}
2929if ($action == 'setashome') {
2930 print '<input type="hidden" name="action" value="updateashome">';
2931}
2932if ($action == 'editmeta') {
2933 print '<input type="hidden" name="action" value="updatemeta">';
2934}
2935if ($action == 'editsource') {
2936 print '<input type="hidden" name="action" value="updatesource">';
2937}
2938if ($action == 'editcontent') {
2939 print '<input type="hidden" name="action" value="updatecontent">';
2940}
2941if ($action == 'edit') {
2942 print '<input type="hidden" name="action" value="update">';
2943}
2944if ($action == 'importsite') {
2945 print '<input type="hidden" name="action" value="importsiteconfirm">';
2946}
2947if ($action == 'file_manager') {
2948 print '<input type="hidden" name="action" value="file_manager">';
2949}
2950if ($mode) {
2951 print '<input type="hidden" name="mode" value="'.$mode.'">';
2952}
2953
2954print '<div>'."\n";
2955
2956// Add a margin under toolbar ?
2957$style = '';
2958if ($action != 'preview' && $action != 'editcontent' && $action != 'editsource' && !GETPOST('createpagefromclone', 'alphanohtml')) {
2959 $style = ' margin-bottom: 5px;';
2960}
2961
2962
2963if (!GETPOST('hide_websitemenu')) {
2964 $disabled = '';
2965 if (!$user->hasRight('website', 'write')) {
2966 $disabled = ' disabled="disabled"';
2967 }
2968 $disabledexport = '';
2969 if (!$user->hasRight('website', 'export')) {
2970 $disabledexport = ' disabled="disabled"';
2971 }
2972
2973 if ($websitekey) {
2974 $virtualurl = '';
2975 $dataroot = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey;
2976 if (!empty($object->virtualhost)) {
2977 $virtualurl = $object->virtualhost;
2978 }
2979 }
2980
2981 $array = array();
2982 if ($object->id > 0) {
2983 $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
2984 $object->lines = $array;
2985 }
2986 if (!is_array($array) && $array < 0) {
2987 dol_print_error(null, $objectpage->error, $objectpage->errors);
2988 }
2989 $atleastonepage = (is_array($array) && count($array) > 0);
2990
2991 $websitepage = new WebsitePage($db);
2992 if ($pageid > 0) {
2993 $websitepage->fetch($pageid);
2994 }
2995
2996
2997 //var_dump($objectpage);exit;
2998 print '<div class="centpercent websitebar'.(GETPOST('dol_openinpopup', 'aZ09') ? ' hiddenforpopup' : '').'">'."\n";
2999
3000 //
3001 // Toolbar for websites
3002 //
3003
3004 print '<!-- Toolbar for website -->';
3005 if ($action != 'file_manager') {
3006 print '<div class="websiteselection hideonsmartphoneimp minwidth75 tdoverflowmax100 inline-block">';
3007 print $langs->trans("Website").': ';
3008 print '</div>';
3009
3010 // Button Add new website
3011 $urltocreatenewwebsite = $_SERVER["PHP_SELF"].'?action=createsite';
3012 print '<span class="websiteselection paddingrightonly">';
3013 print '<a href="'.$urltocreatenewwebsite.'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddWebsite")).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"><span></a>';
3014 print '</span>';
3015
3016 // List of website
3017 print '<span class="websiteselection nopaddingrightimp">';
3018
3019 $out = '';
3020 $out .= '<select name="website" class="minwidth100 width200 maxwidth150onsmartphone" id="website">';
3021 if (empty($listofwebsites)) {
3022 $out .= '<option value="-1">&nbsp;</option>';
3023 }
3024
3025 // Loop on each sites
3026 $i = 0;
3027 foreach ($listofwebsites as $key => $valwebsite) {
3028 if (empty($websitekey)) {
3029 if ($action != 'createsite') {
3030 $websitekey = $valwebsite->ref;
3031 }
3032 }
3033
3034 $out .= '<option value="'.$valwebsite->ref.'"';
3035 if ($websitekey == $valwebsite->ref) {
3036 $out .= ' selected'; // To preselect a value
3037 }
3038 //$outoption = $valwebsite->getLibStatut(3).' '.$valwebsite->ref.' ';
3039 $outoption = (($valwebsite->status == $valwebsite::STATUS_DRAFT) ? '<span class="opacitymedium">' : '').$valwebsite->ref.(($valwebsite->status == $valwebsite::STATUS_DRAFT) ? '</span>' : '');
3040 $out .= ' data-html="'.dol_escape_htmltag($outoption).'"';
3041 $out .= '>';
3042 $out .= $valwebsite->ref;
3043 $out .= '</option>';
3044 $i++;
3045 }
3046 $out .= '</select>';
3047 $out .= ajax_combobox('website');
3048
3049 if (!empty($conf->use_javascript_ajax)) {
3050 $out .= '<script type="text/javascript">';
3051 $out .= 'jQuery(document).ready(function () {';
3052 $out .= ' jQuery("#website").change(function () {';
3053 $out .= ' console.log("We select "+jQuery("#website option:selected").val());';
3054 $out .= ' if (jQuery("#website option:selected").val() == \'-2\') {';
3055 $out .= ' window.location.href = "'.dol_escape_js($urltocreatenewwebsite).'";';
3056 $out .= ' } else {';
3057 $out .= ' window.location.href = "'.$_SERVER["PHP_SELF"].'?website="+jQuery("#website option:selected").val();';
3058 $out .= ' }';
3059 $out .= ' });';
3060 $out .= '});';
3061 $out .= '</script>';
3062 }
3063 print $out;
3064
3065 print '</span>';
3066
3067 // Switch offline/onine
3068 if (!empty($conf->use_javascript_ajax)) {
3069 print '<span class="websiteselection">';
3070 // Do not use ajax, we need a refresh of full page when we change status of a website
3071 //print '<div class="inline-block marginrightonly">';
3072 //print ajax_object_onoff($object, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle inline-block', 'statuswebsite');
3073 //print '</div>';
3074 if ($website->status == $website::STATUS_DRAFT) {
3075 $text_off = 'Offline';
3076 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setwebsiteonline&token='.newToken().'&website='.urlencode($website->ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_off').'</a>';
3077 } else {
3078 $text_off = 'Online';
3079 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setwebsiteoffline&token='.newToken().'&website='.urlencode($website->ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_on').'</a>';
3080 }
3081 print '</span>';
3082 }
3083
3084 // Refresh / Reload web site (for non javascript browsers)
3085 if (empty($conf->use_javascript_ajax)) {
3086 print '<span class="websiteselection">';
3087 print '<input type="image" class="valignmiddle" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshsite" value="'.$langs->trans("Load").'">';
3088 print '</span>';
3089 }
3090
3091
3092 print '<span class="websiteselection">';
3093
3094 if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
3095 // Edit website properties
3096 print '<a href="'.$_SERVER["PHP_SELF"].'?website='.urlencode($object->ref).'&pageid='.((int) $pageid).'&action=editcss&token='.newToken().'" class="button bordertransp valignmiddle" title="'.dol_escape_htmltag($langs->trans("EditCss")).'"'.$disabled.'>';
3097 print img_picto('', 'setup');
3098 print '<span class="hideonsmartphone paddingleft">'.dol_escape_htmltag($langs->trans("EditCss")).'</span>';
3099 print '</a>';
3100
3101 // Import web site
3102 $importlabel = $langs->trans("ImportSite");
3103 $exportlabel = $langs->trans("ExportSite");
3104 if (!empty($conf->dol_optimize_smallscreen)) {
3105 $importlabel = $langs->trans("Import");
3106 $exportlabel = $langs->trans("Export");
3107 }
3108
3109 if ($atleastonepage) {
3110 print '<input type="submit" class="button bordertransp" disabled="disabled" value="'.dol_escape_htmltag($importlabel).'" name="importsite">';
3111 } else {
3112 print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($importlabel).'" name="importsite">';
3113 }
3114
3115 // // Export web site
3116 $extraCssClass = getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE') ? 'hideobject' : '';
3117 print '<input type="submit" class="button bordertransp ' . $extraCssClass . '" ' . $disabledexport . ' value="' . dol_escape_htmltag($exportlabel) . '" name="exportsite">';
3118
3119 if (getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')) {
3120 // Overwrite template in sources
3121 $overwriteGitUrl = $_SERVER["PHP_SELF"] . '?action=overwritesite&website=' . urlencode($website->ref);
3122 print dolButtonToOpenExportDialog('exportpopup', $langs->trans('ExportOptions'), $langs->trans('ExportSite'), 'exportsite', $overwriteGitUrl, $website);
3123 //print '<a href="'.$_SERVER["PHP_SELF"].'?action=overwritesite&website='.urlencode($website->ref).'" class="button bordertransp hideobject" title="'.dol_escape_htmltag($langs->trans("ExportIntoGIT").". Directory ".getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')).'">'.dol_escape_htmltag($langs->trans("ExportIntoGIT")).'</a>';
3124 }
3125
3126 // Clone web site
3127 print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';
3128
3129 // Delete website
3130 if (!$permissiontodelete) {
3131 $disabled = ' disabled="disabled"';
3132 $title = $langs->trans("NotEnoughPermissions");
3133 $url = '#';
3134 } else {
3135 if ($website->status == $website::STATUS_VALIDATED) {
3136 $disabled = ' disabled="disabled"';
3137 $title = $langs->trans("WebsiteMustBeDisabled", $langs->transnoentitiesnoconv($website->LibStatut(0, 0)));
3138 $url = '#';
3139 } else {
3140 $disabled = '';
3141 $title = $langs->trans("Delete");
3142 $url = $_SERVER["PHP_SELF"].'?action=deletesite&token='.newToken().'&website='.urlencode($website->ref);
3143 }
3144 }
3145 print '<a href="'.$url.'" class="button buttonDelete bordertransp'.($disabled ? ' disabled' : '').'"'.$disabled.' title="'.dol_escape_htmltag($title).'">'.img_picto('', 'delete', 'class=""').'<span class="hideonsmartphone paddingleft">'.$langs->trans("Delete").'</span></a>';
3146
3147 // Regenerate all pages
3148 print '<a href="'.$_SERVER["PHP_SELF"].'?action=regeneratesite&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'"><span class="far fa-hdd"></span></a>';
3149
3150 // Generate site map
3151 print '<a href="'.$_SERVER["PHP_SELF"].'?action=confirmgeneratesitemaps&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'"><span class="fa fa-sitemap"></span></a>';
3152
3153 // Find / replace tool
3154 print '<a href="'.$_SERVER["PHP_SELF"].'?action=replacesite&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'"><span class="fa fa-search"></span></a>';
3155 }
3156
3157 print '</span>';
3158
3159 if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
3160 print '<span class="websiteselection">';
3161
3162 print dolButtonToOpenUrlInDialogPopup('file_manager', $langs->transnoentitiesnoconv("MediaFiles"), '<span class="fa fa-image"></span>', '/website/index.php?action=file_manager&website='.urlencode($website->ref).'&section_dir='.urlencode('image/'.$website->ref.'/'), $disabled);
3163
3164 if (isModEnabled('category')) {
3165 //print '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=website&dol_hide_leftmenu=1&nosearch=1&type=website_page&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("Categories")).'"><span class="fa fa-tags"></span></a>';
3166 print dolButtonToOpenUrlInDialogPopup('categories', $langs->transnoentitiesnoconv("Categories"), '<span class="fa fa-tags"></span>', '/categories/index.php?leftmenu=website&nosearch=1&type='.urlencode(Categorie::TYPE_WEBSITE_PAGE).'&website='.urlencode($website->ref), $disabled);
3167 }
3168
3169 print '</span>';
3170 }
3171 } else {
3172 print '<input type="hidden" name="website" id="website" value="'.$websitekey.'">';
3173 }
3174
3175
3176 print '<span class="websitetools">';
3177
3178 if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') {
3179 $urlext = $virtualurl;
3180 $urlint = $urlwithroot.'/public/website/index.php?website='.$websitekey;
3181
3182 print '<span class="websiteinputurl valignmiddle" id="websiteinputurl">';
3183 $linktotestonwebserver = '<a href="'.($virtualurl ? $virtualurl : '#').'" class="valignmiddle">';
3184 $linktotestonwebserver .= '<span class="hideonsmartphone paddingrightonly">'.$langs->trans("TestDeployOnWeb", $virtualurl).'</span>'.img_picto('', 'globe');
3185 $linktotestonwebserver .= '</a>';
3186
3187 $htmltext = '';
3188 if (empty($object->fk_default_home)) {
3189 $htmltext .= '<br><span class="error">'.$langs->trans("YouMustDefineTheHomePage").'</span><br><br>';
3190 } elseif (empty($virtualurl)) {
3191 //$htmltext .= '<br><span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span><br><br>';
3192 } else {
3193 $htmltext .= '<br><center>'.$langs->trans("GoTo").' <a href="'.$virtualurl.'" target="_website">'.$virtualurl.'</a></center><br>';
3194 }
3195 if (getDolGlobalString('WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER')) {
3196 $htmltext .= '<!-- Message defined translate key set into WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER -->';
3197 $htmltext .= '<br>'.$langs->trans(getDolGlobalString('WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER'));
3198 } else {
3199 $htmltext .= $langs->trans("ToDeployYourWebsiteOnLiveYouHave3Solutions").'<br><br>';
3200 $htmltext .= '<div class="titre inline-block">1</div> - '.$langs->trans("SetHereVirtualHost", $dataroot);
3201 $htmltext .= '<br>';
3202 $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
3203 $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
3204 $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);
3205
3206 $examplewithapache = "<VirtualHost *:80>\n";
3207 $examplewithapache .= '#php_admin_value open_basedir /tmp/:'.DOL_DOCUMENT_ROOT.':'.DOL_DATA_ROOT.':/dev/urandom'."\n";
3208 $examplewithapache .= "\n";
3209 $examplewithapache .= 'DocumentRoot "'.DOL_DOCUMENT_ROOT.'"'."\n";
3210 $examplewithapache .= "\n";
3211 $examplewithapache .= '<Directory "'.DOL_DOCUMENT_ROOT.'">'."\n";
3212 $examplewithapache .= 'AllowOverride FileInfo Options
3213 Options -Indexes -MultiViews -FollowSymLinks -ExecCGI
3214 Require all granted
3215 </Directory>'."\n".'
3216 <Directory "'.DOL_DATA_ROOT.'/website">
3217 AllowOverride FileInfo Options
3218 Options -Indexes -MultiViews +FollowSymLinks -ExecCGI
3219 Require all granted
3220 </Directory>'."\n".'
3221 <Directory "'.DOL_DATA_ROOT.'/medias">
3222 AllowOverride FileInfo Options
3223 Options -Indexes -MultiViews -FollowSymLinks -ExecCGI
3224 Require all granted
3225 </Directory>'."\n";
3226
3227 $examplewithapache .= "\n";
3228 $examplewithapache .= "#ErrorLog /var/log/apache2/".$websitekey."_error_log\n";
3229 $examplewithapache .= "#TransferLog /var/log/apache2/".$websitekey."_access_log\n";
3230
3231 $examplewithapache .= "\n";
3232 $examplewithapache .= "# If you need include the payment page into a frame of the website,\n";
3233 $examplewithapache .= "# you need to make a proxy redirection of URLs required for the payment to your backoffice pages\n";
3234 $examplewithapache .= "#SSLProxyEngine On\n";
3235 $examplewithapache .= "#SSLProxyVerify none\n";
3236 $examplewithapache .= "#SSLProxyCheckPeerCN off\n";
3237 $examplewithapache .= "#SSLProxyCheckPeerName off\n";
3238 $examplewithapache .= "#ProxyPreserveHost Off\n";
3239 $examplewithapache .= '#ProxyPass "/public/payment/" "'.$urlwithroot.'/public/payment/'."\n";
3240 $examplewithapache .= '#ProxyPassReverse "/public/payment/" "'.$urlwithroot.'/public/payment/'."\n";
3241 $examplewithapache .= '#ProxyPass "/includes/" "'.$urlwithroot.'/includes/'."\n";
3242 $examplewithapache .= '#ProxyPassReverse "/includes/" "'.$urlwithroot.'/includes/'."\n";
3243 $examplewithapache .= '#ProxyPass "/theme/" "'.$urlwithroot.'/theme/'."\n";
3244 $examplewithapache .= '#ProxyPassReverse "/theme/" "'.$urlwithroot.'/theme/'."\n";
3245 $examplewithapache .= '#ProxyPass "/core/js/" "'.$urlwithroot.'/core/js/'."\n";
3246 $examplewithapache .= '#ProxyPassReverse "/core/js/" "'.$urlwithroot.'/core/js/'."\n";
3247 $examplewithapache .= "\n";
3248
3249 $examplewithapache .= "</VirtualHost>\n";
3250
3251 $htmltext .= '<br>'.$langs->trans("ExampleToUseInApacheVirtualHostConfig").':<br>';
3252 $htmltext .= '<div class="quatrevingtpercent exampleapachesetup wordbreak" spellcheck="false">'.dol_nl2br(dol_escape_htmltag($examplewithapache, 1, 1)).'</div>';
3253
3254 $htmltext .= '<br>';
3255 $htmltext .= '<div class="titre inline-block">2</div> - '.$langs->trans("YouCanAlsoTestWithPHPS");
3256 $htmltext .= '<br><div class="urllink"><input type="text" id="cliphpserver" spellcheck="false" class="quatrevingtpercent" value="php -S 0.0.0.0:8080 -t '.$dataroot.'"></div>';
3257 $htmltext .= ajax_autoselect("cliphpserver");
3258 $htmltext .= '<br>';
3259 $htmltext .= '<div class="titre inline-block">3</div> - '.$langs->trans("YouCanAlsoDeployToAnotherWHP");
3260 }
3261 print $form->textwithpicto($linktotestonwebserver, $htmltext, 1, 'none', 'valignmiddle', 0, 3, 'helpvirtualhost');
3262 print '</span>';
3263 }
3264
3265 if (in_array($action, array('editcss', 'editmenu', 'file_manager', 'replacesiteconfirm')) || in_array($mode, array('replacesite'))) {
3266 if ($action == 'editcss') {
3267 // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
3268 // accesskey is for Mac: CTRL + key for all browsers
3269 $stringforfirstkey = $langs->trans("KeyboardShortcut");
3270 if ($conf->browser->name == 'chrome') {
3271 $stringforfirstkey .= ' ALT +';
3272 } elseif ($conf->browser->name == 'firefox') {
3273 $stringforfirstkey .= ' ALT + SHIFT +';
3274 } else {
3275 $stringforfirstkey .= ' CTL +';
3276 }
3277
3278 print '<input type="submit" accesskey="s" title="'.dol_escape_htmltag($stringforfirstkey.' s').'" id="savefileandstay" class="button buttonforacesave hideonsmartphone small" value="'.dol_escape_htmltag($langs->trans("SaveAndStay")).'" name="updateandstay">';
3279 }
3280 if (preg_match('/^create/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') {
3281 print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
3282 }
3283 if (preg_match('/^edit/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') {
3284 print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
3285 }
3286 if ($action != 'preview') {
3287 print '<input type="submit" class="button button-cancel small" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="cancel">';
3288 }
3289 }
3290
3291 print '</span>';
3292
3293 //
3294 // Toolbar for pages
3295 //
3296
3297 if ($websitekey && $websitekey != '-1' && (!in_array($action, array('editcss', 'editmenu', 'importsite', 'file_manager', 'replacesite', 'replacesiteconfirm'))) && (!in_array($mode, array('replacesite'))) && !$file_manager) {
3298 print '</div>'."\n"; // Close current websitebar to open a new one
3299
3300 print '<!-- Toolbar for websitepage -->';
3301 print '<div class="centpercent websitebar"'.($style ? ' style="'.$style.'"' : '').'>'."\n";
3302
3303 print '<div class="websiteselection hideonsmartphoneimp minwidth75 tdoverflowmax100 inline-block">';
3304 print $langs->trans("PageContainer").': ';
3305 print '</div>';
3306
3307 // Button Add new web page
3308 print '<span class="websiteselection paddingrightonly">';
3309 print '<a href="'.$_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref).'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"></span></a>';
3310 print '</span>';
3311
3312
3313 $out = '';
3314
3315 $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'minwidth100 maxwidth200onsmartphone');
3316
3317 $out .= '<span class="websiteselection nopaddingrightimp">';
3318 $out .= $s;
3319 $out .= '</span>';
3320
3321 $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref);
3322
3323 if (!empty($conf->use_javascript_ajax)) {
3324 $out .= '<script type="text/javascript">';
3325 $out .= 'jQuery(document).ready(function () {';
3326 $out .= ' jQuery("#pageid").change(function () {';
3327 $out .= ' console.log("We select "+jQuery("#pageid option:selected").val());';
3328 $out .= ' if (jQuery("#pageid option:selected").val() == \'-2\') {';
3329 $out .= ' window.location.href = "'.$urltocreatenewpage.'";';
3330 $out .= ' } else {';
3331 $out .= ' window.location.href = "'.$_SERVER["PHP_SELF"].'?website='.urlencode($website->ref).'&pageid="+jQuery("#pageid option:selected").val();';
3332 $out .= ' }';
3333 $out .= ' });';
3334 $out .= '});';
3335 $out .= '</script>';
3336 }
3337
3338 print $out;
3339
3340 // Button to switch status
3341 if (!empty($conf->use_javascript_ajax)) {
3342 print '<span class="websiteselection">';
3343 //print '<div class="inline-block marginrightonly">';
3344 if ($object->status == $object::STATUS_DRAFT) { // website is off, we do not allow to change status of page
3345 $text_off = 'SetWebsiteOnlineBefore';
3346 if ($websitepage->status == $websitepage::STATUS_DRAFT) { // page is off
3347 print '<span class="valignmiddle disabled opacitymedium">'.img_picto($langs->trans($text_off), 'switch_off').'</span>';
3348 } else {
3349 print '<span class="valignmiddle disabled opacitymedium">'.img_picto($langs->trans($text_off), 'switch_on').'</span>';
3350 }
3351 } else {
3352 print ajax_object_onoff($websitepage, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle inline-block'.(empty($websitepage->id) ? ' opacitymedium disabled' : ''), 'statuswebsitepage', 1, 'website='.urlencode($website->ref).'&pageid='.((int) $websitepage->id));
3353 }
3354 //print '</div>';
3355 print '</span>';
3356 }
3357
3358 print '<span class="websiteselection">';
3359
3360 print '<input type="image" class="valignmiddle buttonwebsite hideonsmartphone" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshpage" value="'.$langs->trans("Load").'"'.(($action != 'editsource') ? '' : ' disabled="disabled"').'>';
3361
3362 // Print nav arrows
3363 $pagepreviousid = 0;
3364 $pagenextid = 0;
3365 if ($pageid) {
3366 $sql = "SELECT MAX(rowid) as pagepreviousid FROM ".MAIN_DB_PREFIX."website_page WHERE rowid < ".((int) $pageid)." AND fk_website = ".((int) $object->id);
3367 $resql = $db->query($sql);
3368 if ($resql) {
3369 $obj = $db->fetch_object($resql);
3370 if ($obj) {
3371 $pagepreviousid = $obj->pagepreviousid;
3372 }
3373 } else {
3374 dol_print_error($db);
3375 }
3376 $sql = "SELECT MIN(rowid) as pagenextid FROM ".MAIN_DB_PREFIX."website_page WHERE rowid > ".((int) $pageid)." AND fk_website = ".((int) $object->id);
3377 $resql = $db->query($sql);
3378 if ($resql) {
3379 $obj = $db->fetch_object($resql);
3380 if ($obj) {
3381 $pagenextid = $obj->pagenextid;
3382 }
3383 } else {
3384 dol_print_error($db);
3385 }
3386 }
3387
3388 if ($pagepreviousid) {
3389 print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.((int) $pagepreviousid).'&action='.urlencode($action).'&token='.newToken().'">'.img_previous($langs->trans("PreviousContainer")).'</a>';
3390 } else {
3391 print '<span class="valignmiddle opacitymedium">'.img_previous($langs->trans("PreviousContainer")).'</span>';
3392 }
3393 if ($pagenextid) {
3394 print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.((int) $pagenextid).'&action='.urlencode($action).'&token='.newToken().'">'.img_next($langs->trans("NextContainer")).'</a>';
3395 } else {
3396 print '<span class="valignmiddle opacitymedium">'.img_next($langs->trans("NextContainer")).'</span>';
3397 }
3398
3399 print '</span>';
3400
3401 if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') {
3402 $disabled = '';
3403 if (!$user->hasRight('website', 'write')) {
3404 $disabled = ' disabled="disabled"';
3405 }
3406
3407 // Confirmation delete site
3408 if ($action == 'deletesite') {
3409 // Create an array for form
3410 $formquestion = array(
3411 array('type' => 'checkbox', 'name' => 'delete_also_js', 'label' => $langs->trans("DeleteAlsoJs"), 'value' => 0),
3412 array('type' => 'checkbox', 'name' => 'delete_also_medias', 'label' => $langs->trans("DeleteAlsoMedias"), 'value' => 0),
3413 //array('type' => 'other','name' => 'newlang','label' => $langs->trans("Language"), 'value' => $formadmin->select_language(GETPOST('newlang', 'aZ09')?GETPOST('newlang', 'aZ09'):$langs->defaultlang, 'newlang', 0, null, '', 0, 0, 'minwidth200')),
3414 //array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
3415 );
3416
3417 if ($atleastonepage) {
3418 $langs->load("errors");
3419 $formquestion[] = array('type' => 'onecolumn', 'value' => '<div class="warning">'.$langs->trans("WarningPagesWillBeDeleted").'</div>');
3420 }
3421
3422 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsite'), '', 'confirm_deletesite', $formquestion, 0, 1, 210 + ($atleastonepage ? 70 : 0), 580);
3423
3424 print $formconfirm;
3425 }
3426
3427 // Confirmation to clone
3428 if ($action == 'createfromclone') {
3429 // Create an array for form
3430 $formquestion = array(
3431 array('type' => 'text', 'name' => 'siteref', 'label' => $langs->trans("WebSite"), 'value' => 'copy_of_'.$object->ref)
3432 );
3433
3434 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200);
3435
3436 print $formconfirm;
3437 }
3438
3439 if ($pageid > 0 && $atleastonepage) { // pageid can be set without pages, if homepage of site is set and all pages were removed
3440 // Confirmation to clone
3441 if ($action == 'createpagefromclone') {
3442 // Create an array for form
3443 $preselectedlanguage = GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''; // Dy default, we do not force any language on pages
3444 $onlylang = array();
3445 if ($website->otherlang) {
3446 if (!empty($website->lang)) {
3447 $onlylang[$website->lang] = $website->lang.' ('.$langs->trans("Default").')';
3448 }
3449 foreach (explode(',', $website->otherlang) as $langkey) {
3450 if (empty(trim($langkey))) {
3451 continue;
3452 }
3453 $onlylang[$langkey] = $langkey;
3454 }
3455 $textifempty = $langs->trans("Default");
3456 } else {
3457 $onlylang['none'] = 'none';
3458 $textifempty = $langs->trans("Default");
3459 }
3460 $formquestion = array(
3461 array('type' => 'hidden', 'name' => 'sourcepageurl', 'value' => $objectpage->pageurl),
3462 array('type' => 'other', 'tdclass' => 'fieldrequired', 'name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)),
3463 array('type' => 'text', 'tdclass' => 'maxwidth200 fieldrequired', 'moreattr' => 'autofocus="autofocus"', 'name' => 'newtitle', 'label' => $langs->trans("WEBSITE_TITLE"), 'value' => $langs->trans("CopyOf").' '.$objectpage->title),
3464 array('type' => 'text', 'tdclass' => 'maxwidth200', 'name' => 'newpageurl', 'label' => $langs->trans("WEBSITE_PAGENAME"), 'value' => '')
3465 );
3466 if (count($onlylang) > 1) {
3467 $formquestion[] = array('type' => 'checkbox', 'tdclass' => 'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0, 'morecss' => 'margintoponly');
3468 }
3469
3470 $value = $formadmin->select_language($preselectedlanguage, 'newlang', 0, array(), $textifempty, 0, 0, 'minwidth200', 1, 0, 0, $onlylang, 1);
3471 $formquestion[] = array('type' => 'other', 'name' => 'newlang', 'label' => $form->textwithpicto($langs->trans("Language"), $langs->trans("DefineListOfAltLanguagesInWebsiteProperties")), 'value' => $value);
3472
3473 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550);
3474
3475 print $formconfirm;
3476 }
3477
3478 print '<span class="websiteselection">';
3479
3480 // Edit web page properties
3481 print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editmeta&token='.newToken().'" class="button bordertransp valignmiddle" title="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'"'.$disabled.'>';
3482 print img_picto('', 'setup');
3483 print '<span class="hideonsmartphone paddingleft">'.dol_escape_htmltag($langs->trans("EditPageMeta")).'</span>';
3484 print '</a>';
3485
3486 // Edit HTML content
3487 print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editsource&token='.newToken().'" class="button bordertransp"'.$disabled.'>';
3488 print img_picto('', 'code');
3489 print '<span class="hideonsmartphone paddingleft">'.dol_escape_htmltag($langs->trans($conf->dol_optimize_smallscreen ? "HTML" : "EditHTMLSource")).'</span>';
3490 print '</a>';
3491
3492 // Edit CKEditor
3493 if (getDolGlobalInt('WEBSITE_ALLOW_CKEDITOR')) {
3494 print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editcontent&token='.newToken().'" class="button bordertransp"'.$disabled.'>'.dol_escape_htmltag("CKEditor").'</a>';
3495 } else {
3496 print '<!-- Add option WEBSITE_ALLOW_CKEDITOR to allow ckeditor -->';
3497 }
3498
3499 print '</span>';
3500
3501
3502 // Switch include dynamic content / edit inline
3503 print '<!-- button EditInLine and ShowSubcontainers -->'."\n";
3504 print '<div class="websiteselectionsection inline-block">';
3505
3506 print '<div class="inline-block marginrightonly">'; // Button includes dynamic content
3507 print $langs->trans("ShowSubcontainers");
3508 if (!getDolGlobalString('WEBSITE_SUBCONTAINERSINLINE')) {
3509 print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=setshowsubcontainers&token='.newToken().'">'.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', 0, 0, 0, '', 'nomarginleft').'</a>';
3510 } else {
3511 print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unsetshowsubcontainers&token='.newToken().'">'.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', 0, 0, 0, '', 'nomarginleft').'</a>';
3512 }
3513 print '</div>';
3514
3515 print '<div class="inline-block marginrightonly">'; // Button edit inline
3516
3517 print '<span id="switchckeditorinline">'."\n";
3518 // Enable CKEditor inline with js on section and div with conteneditable=true
3519 print '<!-- Code to enabled edit inline ckeditor -->'."\n";
3520 print '<script type="text/javascript">
3521 $(document).ready(function() {
3522 var isEditingEnabled = '.(getDolGlobalString("WEBSITE_EDITINLINE") ? 'true' : 'false').';
3523 if (isEditingEnabled)
3524 {
3525 switchEditorOnline(true);
3526 }
3527
3528 $( "#switchckeditorinline" ).click(function() {
3529 switchEditorOnline();
3530 });
3531
3532 function switchEditorOnline(forceenable)
3533 {
3534 if (! isEditingEnabled || forceenable)
3535 {
3536 console.log("Enable inline edit for some html tags with contenteditable=true attribute");
3537
3538 jQuery(\'section[contenteditable="true"],div[contenteditable="true"],header[contenteditable="true"],main[contenteditable="true"],footer[contenteditable="true"]\').each(function(idx){
3539 var idtouse = $(this).attr(\'id\');
3540 console.log("Enable inline edit for "+idtouse);
3541 if (idtouse !== undefined) {
3542 var inlineditor = CKEDITOR.inline(idtouse, {
3543 // Allow some non-standard markup that we used in the introduction.
3544 // + a[target];div{float,display} ?
3545 extraAllowedContent: \'span(*);cite(*);q(*);dl(*);dt(*);dd(*);ul(*);li(*);header(*);main(*);footer(*);button(*);h1(*);h2(*);h3(*);\',
3546 //extraPlugins: \'sourcedialog\',
3547 removePlugins: \'flash,stylescombo,exportpdf,scayt,wsc,pagebreak,iframe,smiley\',
3548 // Show toolbar on startup (optional).
3549 // startupFocus: true
3550 });
3551
3552 // Custom bar tool
3553 // Note the Source tool does not work on inline
3554 inlineditor.config.toolbar = [
3555 [\'Templates\',\'NewPage\'],
3556 [\'Save\'],
3557 [\'Maximize\',\'Preview\'],
3558 [\'PasteText\'],
3559 [\'Undo\',\'Redo\',\'-\',\'Find\',\'Replace\',\'-\',\'SelectAll\',\'RemoveFormat\'],
3560 [\'CreateDiv\',\'ShowBlocks\'],
3561 [\'Form\', \'Checkbox\', \'Radio\', \'TextField\', \'Textarea\', \'Select\', \'Button\', \'ImageButton\', \'HiddenField\'],
3562 [\'Bold\',\'Italic\',\'Underline\',\'Strike\',\'Superscript\'],
3563 [\'NumberedList\',\'BulletedList\',\'-\',\'Outdent\',\'Indent\',\'Blockquote\'],
3564 [\'JustifyLeft\',\'JustifyCenter\',\'JustifyRight\',\'JustifyBlock\'],
3565 [\'Link\',\'Unlink\'],
3566 [\'Image\',\'Table\',\'HorizontalRule\'],
3567 [\'Styles\',\'Format\',\'Font\',\'FontSize\'],
3568 [\'TextColor\',\'BGColor\']
3569 ];
3570
3571 // Start editor
3572 //inlineditor.on(\'instanceReady\', function () {
3573 // ...
3574 //});
3575
3576 CKEDITOR.instances[idtouse].on(\'change\', function() {
3577 $(this.element.$).addClass(\'modified\');
3578 })
3579 } else {
3580 console.warn("A html section has the contenteditable=true attribute but has no id attribute");
3581 }
3582 })
3583
3584 isEditingEnabled = true;
3585
3586 // Trigger the function when clicking outside the elements with contenteditable=true attribute
3587 // so we can save the change.
3588 $(document).on(\'click\', function(e) {
3589 var target = $(e.target);
3590
3591 // Check if the click is outside the elements with contenteditable=true attribute
3592 if (!target.closest(\'[contenteditable="true"]\').length) {
3593 // Repeat through the elements with contenteditable="true" attribute
3594 $(\'[contenteditable="true"]\').each(function() {
3595 var idToUse = $(this).attr(\'id\');
3596 var elementType = $(this).prop("tagName").toLowerCase(); // Get the tag name (div, section, footer...)
3597 var instance = CKEDITOR.instances[idToUse];
3598
3599 // Check if the element has been modified
3600 if ($(this).hasClass(\'modified\')) {
3601 var content = instance.getData();
3602 content = "\\n" + content;
3603
3604 // Retrieving the content and ID of the element
3605 var elementId = $(this).attr(\'id\');
3606
3607 ';
3608 if (getDolGlobalString('WEBSITE_EDITINLINE_SAVE_CKEDITOR_EDIT')) {
3609 print '
3610 console.log("A change has been detected, we send new content for update with ajax");
3611
3612 // Sending data via AJAX to update section
3613 $.ajax({
3614 type: \'POST\',
3615 url: \'' . DOL_URL_ROOT . '/core/ajax/editinline.php\',
3616 data: {
3617 website_ref: \''.dol_escape_js($website->ref).'\',
3618 page_id: \'' . ((int) $websitepage->id) . '\',
3619 content: content,
3620 element_id: elementId,
3621 element_type: elementType,
3622 action: \'updatedElementContent\',
3623 token: \'' . newToken() . '\'
3624 },
3625 success: function(response) {
3626 console.log(response);
3627 var $lastWebsitebar = $(".websitebar").last();
3628 var $span = $("<span></span>").html("'.$langs->trans("Saved").'").css({
3629 \'display\': \'block\',
3630 \'position\': \'absolute\',
3631 \'margin-top\': \'6px\',
3632 \'right\': \'5px\',
3633 \'background-color\': \'#e3f0db\',
3634 \'color\': \'#446548\',
3635 \'font-size\': \'14px\',
3636 \'padding\': \'0px 5px\',
3637 \'z-index\': 1000
3638 });
3639 $lastWebsitebar.after($span);
3640
3641 // Close message after 2 seconds
3642 setTimeout(function() {
3643 $span.fadeOut(500, function() {
3644 $(this).remove();
3645 });
3646 }, 2000);
3647 }
3648 });
3649 ';
3650 } else {
3651 print 'console.log("A change has been detected, but saving is not enabled by option WEBSITE_EDITINLINE_SAVE_CKEDITOR_EDIT, so no ajax update is done");';
3652 }
3653 print '
3654
3655 $(this).removeClass(\'modified\');
3656 }
3657 });
3658 }
3659 });
3660
3661 } else {
3662 console.log("Disable inline edit");
3663 for(name in CKEDITOR.instances) {
3664 CKEDITOR.instances[name].destroy(true);
3665 }
3666 isEditingEnabled = false;
3667 }
3668 }
3669 });
3670 </script>';
3671 print $langs->trans("EditInLine");
3672 print '</span>';
3673
3674 //$disableeditinline = $websitepage->grabbed_from;
3675 $disableeditinline = 0;
3676 if ($disableeditinline) {
3677 //print '<input type="submit" class="button bordertransp" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'" value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
3678 print '<a class="nobordertransp opacitymedium nohoverborder marginleftonlyshort"'.$disabled.' href="#" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'">'.img_picto($langs->trans("OnlyEditionOfSourceForGrabbedContent"), 'switch_off', '', 0, 0, 0, '', 'nomarginleft').'</a>';
3679 } else {
3680 //print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
3681 if (!getDolGlobalString('WEBSITE_EDITINLINE')) {
3682 print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=seteditinline&token='.newToken().'">'.img_picto($langs->trans("EditInLineOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', 0, 0, 0, '', 'nomarginleft').'</a>';
3683 } else {
3684 print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unseteditinline&token='.newToken().'">'.img_picto($langs->trans("EditInLineOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', 0, 0, 0, '', 'nomarginleft').'</a>';
3685 }
3686 }
3687
3688 print '</div>';
3689
3690 print '</div>';
3691
3692 // Set page as homepage
3693 print '<span class="websiteselection">';
3694 if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) {
3695 //$disabled=' disabled="disabled"';
3696 //print '<span class="button bordertransp disabled"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fas fa-home"></span></span>';
3697 //print '<input type="submit" class="button bordertransp" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
3698 print '<a href="#" class="button bordertransp disabled" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fas fa-home valignmiddle btnTitle-icon"></span></a>';
3699 } else {
3700 //$disabled='';
3701 //print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
3702 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setashome&token='.newToken().'&website='.urlencode($website->ref).'&pageid='.((int) $pageid).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fas fa-home valignmiddle btnTitle-icon"></span></a>';
3703 }
3704 print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
3705
3706 // Delete
3707 if ($websitepage->status != $websitepage::STATUS_DRAFT) {
3708 $disabled = ' disabled="disabled"';
3709 $title = $langs->trans("WebpageMustBeDisabled", $langs->transnoentitiesnoconv($websitepage->LibStatut(0, 0)));
3710 $url = '#';
3711 } else {
3712 $disabled = '';
3713 $title = '';
3714 $url = $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&pageid='.((int) $websitepage->id).'&website='.urlencode($website->ref); // action=delete for webpage, deletesite for website
3715 }
3716 print '<a href="'.$url.'" class="button buttonDelete bordertransp'.($disabled ? ' disabled' : '').'"'.$disabled.' title="'.dol_escape_htmltag($title).'">'.img_picto('', 'delete', 'class=""').'<span class="hideonsmartphone paddingleft">'.$langs->trans("Delete").'</span></a>';
3717 print '</span>';
3718 }
3719 }
3720
3721 //print '</span>'; // end website selection
3722
3723 print '<span class="websitetools">';
3724
3725 if (($pageid > 0 && $atleastonepage) && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
3726 $realpage = $urlwithroot.'/public/website/index.php?website='.$websitekey.'&pageref='.$websitepage->pageurl;
3727 $pagealias = $websitepage->pageurl;
3728
3729 $htmltext = $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $langs->transnoentitiesnoconv("TestDeployOnWeb"));
3730 //$htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), '{s1}');
3731 //$htmltext = str_replace('{s1}', $dataroot.'<br>'.DOL_DATA_ROOT.'/medias<br>'.DOL_DOCUMENT_ROOT, $htmltext);
3732 //$htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
3733 //$htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/medias', $htmltext);
3734
3735 print '<div class="websiteinputurl inline-block paddingright">';
3736 print '<a class="websitebuttonsitepreview inline-block" id="previewpage" href="'.$realpage.'&nocache='.dol_now().'" class="button" target="tab'.$websitekey.'" alt="'.dol_escape_htmltag($htmltext).'">';
3737 print $form->textwithpicto('', $htmltext, 1, 'preview');
3738 print '</a>'; // View page in new Tab
3739 print '</div>';
3740
3741 /*print '<div class="websiteinputurl inline-block" id="websiteinputpage">';
3742 print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
3743 $htmltext = $langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta"));
3744 print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias');
3745 print '</div>';*/
3746
3747 /*
3748 $urlext = $virtualurl.'/'.$pagealias.'.php';
3749 $urlint = $urlwithroot.'/public/website/index.php?website='.$websitekey;
3750
3751 $htmltext = $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl ? $urlext : '<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>');
3752
3753 print '<a class="websitebuttonsitepreview'.($virtualurl ? '' : ' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewpageext" href="'.$urlext.'" target="tab'.$websitekey.'ext" alt="'.dol_escape_htmltag($htmltext).'">';
3754 print $form->textwithpicto('', $htmltext, 1, 'preview_ext');
3755 print '</a>';
3756 */
3757 //print '<input type="submit" class="button" name="previewpage" target="tab'.$websitekey.'"value="'.$langs->trans("ViewPageInNewTab").'">';
3758
3759 // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
3760 }
3761 if (!in_array($mode, array('replacesite')) && !in_array($action, array('editcss', 'editmenu', 'file_manager', 'replacesiteconfirm', 'createsite', 'createcontainer', 'createfromclone', 'createpagefromclone', 'deletesite'))) {
3762 if ($action == 'editsource' || $action == 'editmeta') {
3763 // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
3764 // accesskey is for Mac: CTRL + key for all browsers
3765 $stringforfirstkey = $langs->trans("KeyboardShortcut");
3766 if ($conf->browser->name == 'chrome') {
3767 $stringforfirstkey .= ' ALT +';
3768 } elseif ($conf->browser->name == 'firefox') {
3769 $stringforfirstkey .= ' ALT + SHIFT +';
3770 } else {
3771 $stringforfirstkey .= ' CTL +';
3772 }
3773
3774 print '<input type="submit" accesskey="s" title="'.dol_escape_htmltag($stringforfirstkey.' s').'" id="savefileandstay" class="button buttonforacesave hideonsmartphone small" value="'.dol_escape_htmltag($langs->trans("SaveAndStay")).'" name="updateandstay">';
3775 }
3776 if (preg_match('/^create/', $action)) {
3777 print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
3778 }
3779 if (preg_match('/^edit/', $action)) {
3780 print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
3781 }
3782 if ($action != 'preview') {
3783 print '<input type="submit" class="button button-cancel small" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="cancel">';
3784 }
3785 }
3786
3787 print '</span>'; // end websitetools
3788
3789 print '<span class="websitehelp">';
3790 if ($action == 'editsource' || $action == 'editcontent' || GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha')) {
3791 $url = 'https://wiki.dolibarr.org/index.php/Module_Website';
3792
3793 $htmltext = '<small>';
3794 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource", $url);
3795 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSourceb", $url);
3796 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSourcec", $url);
3797 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSourced", $url);
3798 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource1", $url);
3799 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource2", $url);
3800 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource3", $url);
3801 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource4", $url);
3802 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSourceMore", $url);
3803 $htmltext .= '<br>';
3804 $htmltext .= '</small>';
3805 if ($conf->browser->layout == 'phone') {
3806 print $form->textwithpicto('', $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution');
3807 } else {
3808 //img_help(($tooltiptrigger != '' ? 2 : 1), $alt)
3809 print $form->textwithpicto($langs->trans("SyntaxHelp").' '.img_help(2, $langs->trans("SyntaxHelp")), $htmltext, 1, 'none', 'inline-block', 1, 2, 'tooltipsubstitution');
3810 }
3811 }
3812 print '</span>'; // end websitehelp
3813
3814
3815 if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') {
3816 // Adding jquery code to change on the fly url of preview ext
3817 if (!empty($conf->use_javascript_ajax)) {
3818 print '<script type="text/javascript">
3819 jQuery(document).ready(function() {
3820 jQuery("#websiteinputurl").keyup(function() {
3821 console.log("Website external url modified "+jQuery("#previewsiteurl").val());
3822 if (jQuery("#previewsiteurl").val() != "" && jQuery("#previewsiteurl").val().startsWith("http"))
3823 {
3824 jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 1 });
3825 }
3826 else jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 0.2 });
3827 ';
3828 print '
3829 });
3830 jQuery("#previewsiteext,#previewpageext").click(function() {
3831
3832 newurl=jQuery("#previewsiteurl").val();
3833 if (! newurl.startsWith("http"))
3834 {
3835 alert(\''.dol_escape_js($langs->trans("ErrorURLMustStartWithHttp")).'\');
3836 return false;
3837 }
3838
3839 newpage=jQuery("#previewsiteurl").val() + "/" + jQuery("#previewpageurl").val() + ".php";
3840 console.log("Open url "+newurl);
3841 /* Save url */
3842 jQuery.ajax({
3843 method: "POST",
3844 url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
3845 data: {
3846 field: \'editval_virtualhost\',
3847 element: \'website\',
3848 table_element: \'website\',
3849 fk_element: '.((int) $object->id).',
3850 value: newurl,
3851 },
3852 context: document.body
3853 });
3854
3855 jQuery("#previewsiteext").attr("href",newurl);
3856 jQuery("#previewpageext").attr("href",newpage);
3857 });
3858 });
3859 </script>';
3860 }
3861 }
3862 }
3863
3864 print '</div>'."\n"; // end current websitebar
3865}
3866
3867
3868$head = array();
3869
3870
3871/*
3872 * Edit Site HTML header and CSS
3873 */
3874
3875if ($action == 'editcss') {
3876 print '<div class="fiche">';
3877
3878 print '<br>';
3879
3880 if (!GETPOSTISSET('WEBSITE_CSS_INLINE')) {
3881 $csscontent = @file_get_contents($filecss);
3882 // Clean the php css file to remove php code and get only css part
3883 $csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims', '', $csscontent);
3884 } else {
3885 $csscontent = GETPOST('WEBSITE_CSS_INLINE', 'none');
3886 }
3887 if (!trim($csscontent)) {
3888 $csscontent = '/* CSS content (all pages) */'."\nbody.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
3889 }
3890
3891 if (!GETPOSTISSET('WEBSITE_JS_INLINE')) {
3892 $jscontent = @file_get_contents($filejs);
3893 // Clean the php js file to remove php code and get only js part
3894 $jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims', '', $jscontent);
3895 } else {
3896 $jscontent = GETPOST('WEBSITE_JS_INLINE', 'none');
3897 }
3898 if (!trim($jscontent)) {
3899 $jscontent = '/* JS content (all pages) */'."\n";
3900 }
3901
3902 if (!GETPOSTISSET('WEBSITE_HTML_HEADER')) {
3903 $htmlheadercontent = @file_get_contents($filehtmlheader);
3904 // Clean the php htmlheader file to remove php code and get only html part
3905 $htmlheadercontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims', '', $htmlheadercontent);
3906 } else {
3907 $htmlheadercontent = GETPOST('WEBSITE_HTML_HEADER', 'none'); // Must accept tags like '<script>' and '<link>'
3908 }
3909 if (!trim($htmlheadercontent)) {
3910 $htmlheadercontent = "<html>\n";
3911 $htmlheadercontent .= $htmlheadercontentdefault;
3912 $htmlheadercontent .= "</html>";
3913 } else {
3914 $htmlheadercontent = preg_replace('/^\s*<html>/ims', '', $htmlheadercontent);
3915 $htmlheadercontent = preg_replace('/<\/html>\s*$/ims', '', $htmlheadercontent);
3916 $htmlheadercontent = '<html>'."\n".trim($htmlheadercontent)."\n".'</html>';
3917 }
3918
3919 if (!GETPOSTISSET('WEBSITE_ROBOT')) {
3920 $robotcontent = @file_get_contents($filerobot);
3921 // Clean the php htmlheader file to remove php code and get only html part
3922 $robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims', '', $robotcontent);
3923 } else {
3924 $robotcontent = GETPOST('WEBSITE_ROBOT', 'nohtml');
3925 }
3926 if (!trim($robotcontent)) {
3927 $robotcontent .= "# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n";
3928 $robotcontent .= "User-agent: *\n";
3929 $robotcontent .= "Allow: /public/\n";
3930 $robotcontent .= "Disallow: /administrator/\n";
3931 }
3932
3933 if (!GETPOSTISSET('WEBSITE_HTACCESS')) {
3934 $htaccesscontent = @file_get_contents($filehtaccess);
3935 // Clean the php htaccesscontent file to remove php code and get only html part
3936 $htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims', '', $htaccesscontent);
3937 } else {
3938 $htaccesscontent = GETPOST('WEBSITE_HTACCESS', 'nohtml'); // We must use 'nohtml' and not 'alphanohtml' because we must accept "
3939 }
3940
3941 if (!GETPOSTISSET('WEBSITE_MANIFEST_JSON')) {
3942 $manifestjsoncontent = @file_get_contents($filemanifestjson);
3943 // Clean the manifestjson file to remove php code and get only html part
3944 $manifestjsoncontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims', '', $manifestjsoncontent);
3945 } else {
3946 $manifestjsoncontent = trim(GETPOST('WEBSITE_MANIFEST_JSON', 'restricthtmlallowunvalid'));
3947 $manifestjsoncontent = str_replace('<?=', '<?php', $manifestjsoncontent);
3948 }
3949
3950 //if (!trim($manifestjsoncontent)) {
3951 //$manifestjsoncontent.="";
3952 //}
3953
3954 if (!GETPOSTISSET('WEBSITE_README')) {
3955 $readmecontent = @file_get_contents($filereadme);
3956 // Clean the readme file to remove php code and get only html part
3957 $readmecontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims', '', $readmecontent);
3958 } else {
3959 $readmecontent = GETPOST('WEBSITE_README', 'restricthtmlallowunvalid');
3960 }
3961 //if (!trim($readmecontent)) {
3962 //$readmecontent.="";
3963 //}
3964
3965 if (!GETPOSTISSET('WEBSITE_LICENSE')) {
3966 $licensecontent = @file_get_contents($filelicense);
3967 // Clean the readme file to remove php code and get only html part
3968 $licensecontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims', '', $licensecontent);
3969 } else {
3970 $licensecontent = GETPOST('WEBSITE_LICENSE', 'restricthtmlallowunvalid');
3971 }
3972 //if (!trim($licensecontent)) {
3973 //$readmecontent.="";
3974 //}
3975
3976 print dol_get_fiche_head();
3977
3978 print '<!-- Edit Website properties -->'."\n";
3979 print '<table class="border centpercent">';
3980
3981 // Website
3982 print '<tr><td class="titlefieldcreate fieldrequired">';
3983 print $langs->trans('WebSite');
3984 print '</td><td>';
3985 print $websitekey;
3986 print '</td></tr>';
3987
3988 // Status of web site
3989 if ($action != 'createcontainer') {
3990 if (empty($conf->use_javascript_ajax)) {
3991 print '<!-- Status of web site page -->'."\n";
3992 print '<tr><td class="fieldrequired">';
3993 print $langs->trans('Status');
3994 print '</td><td>';
3995 print $form->selectyesno('status', $object->status);
3996 print '</td></tr>';
3997 }
3998 }
3999
4000 // Main language
4001 print '<tr><td class="tdtop fieldrequired">';
4002 $htmltext = '';
4003 print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG');
4004 print '</td><td>';
4005 print img_picto('', 'language', 'class="picotfixedwidth"');
4006 print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : ($object->lang ? $object->lang : '0')), 'WEBSITE_LANG', 0, array(), 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
4007 print '</td>';
4008 print '</tr>';
4009
4010 // Other languages
4011 print '<tr><td class="tdtop">';
4012 $htmltext = $langs->trans("Example").': fr,de,sv,it,pt';
4013 print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2);
4014 print '</td><td>';
4015 print img_picto('', 'language', 'class="picotfixedwidth"');
4016 print '<input type="text" class="flat maxwidth200" value="'.(GETPOSTISSET('WEBSITE_OTHERLANG') ? GETPOST('WEBSITE_OTHERLANG', 'alpha') : $object->otherlang).'" name="WEBSITE_OTHERLANG">';
4017 print '</td>';
4018 print '</tr>';
4019
4020 // VirtualHost
4021 print '<tr><td class="tdtop">';
4022
4023 $htmltext = $langs->trans("VirtualhostDesc");
4024 print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, 'virtualhosttooltip');
4025 print '</td><td>';
4026 print '<input type="text" class="flat minwidth300" value="'.(GETPOSTISSET('virtualhost') ? GETPOST('virtualhost', 'alpha') : $virtualurl).'" name="virtualhost">';
4027 print '</td>';
4028 print '</tr>';
4029
4030 // Favicon
4031 print '<tr><td>';
4032 print $form->textwithpicto($langs->trans('ImportFavicon'), $langs->trans('FaviconTooltip'));
4033 print '</td><td>';
4034 $maxfilesizearray = getMaxFileSizeArray();
4035 $maxmin = $maxfilesizearray['maxmin'];
4036 if ($maxmin > 0) {
4037 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
4038 }
4039 print '<input type="file" class="flat minwidth300" name="addedfile" id="addedfile"/>';
4040
4041 $uploadfolder = $conf->website->dir_output.'/'.$websitekey;
4042 if (dol_is_file($uploadfolder.'/favicon.png')) {
4043 print '<div class="inline-block valignmiddle marginrightonly">';
4044 print '<img style="max-height: 80px" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=website&file='.$websitekey.'/favicon.png">';
4045 print '</div>';
4046 }
4047 print '</tr></td>';
4048
4049 // CSS file
4050 print '<tr><td class="tdtop">';
4051 $htmlhelp = $langs->trans("CSSContentTooltipHelp");
4052 print $form->textwithpicto($langs->trans('WEBSITE_CSS_INLINE'), $htmlhelp, 1, 'help', '', 0, 2, 'csstooltip');
4053 print '</td><td>';
4054
4055 $poscursor = array('x' => GETPOST('WEBSITE_CSS_INLINE_x'), 'y' => GETPOST('WEBSITE_CSS_INLINE_y'));
4056 $doleditor = new DolEditor('WEBSITE_CSS_INLINE', $csscontent, '', 220, 'ace', 'In', true, false, 'ace', 0, '100%', 0, $poscursor);
4057 print $doleditor->Create(1, '', true, 'CSS', 'css');
4058
4059 print '</td></tr>';
4060
4061 // JS file
4062 print '<tr><td class="tdtop">';
4063 $textwithhelp = $langs->trans('WEBSITE_JS_INLINE');
4064 $htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
4065 print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmljstooltip2');
4066
4067 print '</td><td>';
4068
4069 $poscursor = array('x' => GETPOST('WEBSITE_JS_INLINE_x'), 'y' => GETPOST('WEBSITE_JS_INLINE_y'));
4070 $doleditor = new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', 220, 'ace', 'In', true, false, 'ace', 0, '100%', 0, $poscursor);
4071 print $doleditor->Create(1, '', true, 'JS', 'javascript');
4072
4073 print '</td></tr>';
4074
4075 // Common HTML header
4076 print '<tr><td class="tdtop">';
4077 print $langs->trans('WEBSITE_HTML_HEADER');
4078 $htmlhelp = $langs->trans("Example").' :<br>';
4079 $htmlhelp .= dol_nl2br(dol_htmlentities($htmlheadercontentdefault)); // do not use dol_htmlentitiesbr here, $htmlheadercontentdefault is HTML with content like <link> and <script> that we want to be html encode as they must be show as doc content not executable instruction.
4080 $textwithhelp = $form->textwithpicto('', $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
4081 $htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
4082 print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmlheadertooltip2');
4083 print '</td><td>';
4084
4085 $poscursor = array('x' => GETPOST('WEBSITE_HTML_HEADER_x'), 'y' => GETPOST('WEBSITE_HTML_HEADER_y'));
4086 $doleditor = new DolEditor('WEBSITE_HTML_HEADER', $htmlheadercontent, '', 220, 'ace', 'In', true, false, 'ace', 0, '100%', 0, $poscursor);
4087 print $doleditor->Create(1, '', true, 'HTML Header', 'html');
4088
4089 print '</td></tr>';
4090
4091 // Robot file
4092 print '<tr><td class="tdtop">';
4093 print $langs->trans('WEBSITE_ROBOT');
4094 print '</td><td>';
4095
4096 $poscursor = array('x' => GETPOST('WEBSITE_ROBOT_x'), 'y' => GETPOST('WEBSITE_ROBOT_y'));
4097 $doleditor = new DolEditor('WEBSITE_ROBOT', $robotcontent, '', 220, 'ace', 'In', true, false, 'ace', 0, '100%', 0, $poscursor);
4098 print $doleditor->Create(1, '', true, 'Robot file', 'text');
4099
4100 print '</td></tr>';
4101
4102 // .htaccess
4103 print '<tr><td class="tdtop">';
4104
4105 $textwithhelp3 = $langs->trans("Example").' :';
4106 $textwithhelp3 .= "<br># Order allow,deny\n";
4107 $textwithhelp3 .= "<br># Deny from all\n";
4108 $textwithhelp3 .= "<br># Require all granted\n";
4109
4110 print $form->textwithpicto($langs->trans('WEBSITE_HTACCESS'), $textwithhelp3, 1, 'help', '', 0, 2, 'htmlheadertooltip3');
4111 print '</td><td>';
4112
4113 $poscursor = array('x' => GETPOST('WEBSITE_HTACCESS_x'), 'y' => GETPOST('WEBSITE_HTACCESS_y'));
4114 $doleditor = new DolEditor('WEBSITE_HTACCESS', $htaccesscontent, '', 220, 'ace', 'In', true, false, 'ace', 0, '100%', 0, $poscursor);
4115 print $doleditor->Create(1, '', true, $langs->trans("File").' .htaccess', 'text');
4116
4117 print '</td></tr>';
4118
4119 // Manifest.json
4120 print '<tr><td class="tdtop">';
4121 $htmlhelp = $langs->trans("Example").' :<br>';
4122 $htmlhelp .= '<small>'.dol_htmlentitiesbr($manifestjsoncontentdefault).'</small>';
4123 print $form->textwithpicto($langs->trans('WEBSITE_MANIFEST_JSON'), $htmlhelp, 1, 'help', '', 0, 2, 'manifestjsontooltip');
4124 print '</td><td>';
4125 print $langs->trans("UseManifest").': '.$form->selectyesno('use_manifest', $website->use_manifest, 1).'<br>';
4126
4127 $poscursor = array('x' => GETPOST('WEBSITE_MANIFEST_JSON_x'), 'y' => GETPOST('WEBSITE_MANIFEST_JSON_y'));
4128 $doleditor = new DolEditor('WEBSITE_MANIFEST_JSON', $manifestjsoncontent, '', 220, 'ace', 'In', true, false, 'ace', 0, '100%', 0, $poscursor);
4129 print $doleditor->Create(1, '', true, $langs->trans("File").' manifest.json', 'text');
4130 print '</td></tr>';
4131
4132 // README.md
4133 print '<tr><td class="tdtop">';
4134 $htmlhelp = $langs->trans("EnterHereReadmeInformation");
4135 print $form->textwithpicto($langs->trans("File").' README.md', $htmlhelp, 1, 'help', '', 0, 2, 'readmetooltip');
4136 print '</td><td>';
4137
4138 $poscursor = array('x' => GETPOST('WEBSITE_README_x'), 'y' => GETPOST('WEBSITE_README_y'));
4139 $doleditor = new DolEditor('WEBSITE_README', $readmecontent, '', 220, 'ace', 'In', true, false, 'ace', 0, '100%', 0, $poscursor);
4140 print $doleditor->Create(1, '', true, $langs->trans("File").' README.md', 'text');
4141
4142 print '</td></tr>';
4143
4144 // LICENSE
4145 print '<tr><td class="tdtop">';
4146 $htmlhelp = $langs->trans("EnterHereLicenseInformation");
4147 print $form->textwithpicto($langs->trans("File").' LICENSE', $htmlhelp, 1, 'help', '', 0, 2, 'licensetooltip');
4148 print '</td><td>';
4149
4150 $poscursor = array('x' => GETPOST('WEBSITE_LICENSE_x'), 'y' => GETPOST('WEBSITE_LICENSE_y'));
4151 $doleditor = new DolEditor('WEBSITE_LICENSE', $licensecontent, '', 220, 'ace', 'In', true, false, 'ace', 0, '100%', 0, $poscursor);
4152 print $doleditor->Create(1, '', true, $langs->trans("File").' LICENSE', 'text');
4153
4154 print '</td></tr>';
4155
4156 // RSS
4157 print '<tr><td class="tdtop">';
4158 $htmlhelp = $langs->trans('RSSFeedDesc');
4159 print $form->textwithpicto($langs->trans('RSSFeed'), $htmlhelp, 1, 'help', '', 0, 2, '');
4160 print '</td><td>';
4161 print '/wrapper.php?rss=1[&l=XX][&limit=99][&cachedelay=99]';
4162 print '</td></tr>';
4163
4164 print '</table>';
4165
4166 print dol_get_fiche_end();
4167
4168 print '</div>';
4169
4170 print '<br>';
4171}
4172
4173
4174if ($action == 'createsite') {
4175 print '<div class="fiche">';
4176
4177 print '<br>';
4178
4179 /*$h = 0;
4180 $head = array();
4181
4182 $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
4183 $head[$h][1] = $langs->trans("AddSite");
4184 $head[$h][2] = 'card';
4185 $h++;
4186
4187 print dol_get_fiche_head($head, 'card', '', -1, 'globe');
4188 */
4189 if ($action == 'createcontainer') {
4190 print load_fiche_titre($langs->trans("AddSite"));
4191 }
4192
4193 print '<!-- Add site -->'."\n";
4194 print '<div class="tabBar tabBarWithBottom">';
4195
4196 print '<table class="border centpercent">';
4197
4198 $siteref = $sitedesc = $sitelang = $siteotherlang = '';
4199 if (GETPOST('WEBSITE_REF')) {
4200 $siteref = GETPOST('WEBSITE_REF', 'aZ09');
4201 }
4202 if (GETPOST('WEBSITE_DESCRIPTION')) {
4203 $sitedesc = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
4204 }
4205 if (GETPOST('WEBSITE_LANG')) {
4206 $sitelang = GETPOST('WEBSITE_LANG', 'aZ09');
4207 }
4208 if (GETPOST('WEBSITE_OTHERLANG')) {
4209 $siteotherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
4210 }
4211
4212 print '<tr><td class="titlefieldcreate fieldrequired">';
4213 print $form->textwithpicto($langs->trans('WebsiteName'), $langs->trans("Example").': MyPortal, www.mywebsite.com, ...');
4214 print '</td><td>';
4215 print '<input type="text" class="flat maxwidth300" name="WEBSITE_REF" value="'.dol_escape_htmltag($siteref).'" autofocus>';
4216 print '</td></tr>';
4217
4218 print '<tr><td class="fieldrequired">';
4219 print $langs->trans('MainLanguage');
4220 print '</td><td>';
4221 $shortlangcode = preg_replace('/[_-].*$/', '', trim($langs->defaultlang));
4222 print img_picto('', 'language', 'class="pictofixedwidth"');
4223 print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : $shortlangcode), 'WEBSITE_LANG', 0, array(), 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
4224 print '</td></tr>';
4225
4226 print '<tr><td>';
4227 $htmltext = $langs->trans("Example").': fr,de,sv,it,pt';
4228 print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2);
4229 print '</td><td>';
4230 print img_picto('', 'language', 'class="pictofixedwidth"');
4231 print '<input type="text" class="flat minwidth300" name="WEBSITE_OTHERLANG" value="'.dol_escape_htmltag($siteotherlang).'">';
4232 print '</td></tr>';
4233
4234 print '<tr><td>';
4235 print $langs->trans('Description');
4236 print '</td><td>';
4237 print '<input type="text" class="flat minwidth500" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
4238 print '</td></tr>';
4239
4240 print '<tr><td>';
4241
4242 $htmltext = $langs->trans("VirtualhostDesc");
4243 /*$htmltext = str_replace('{s1}', DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/<i>websiteref</i>', $htmltext);
4244 $htmltext .= '<br>';
4245 $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
4246 $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
4247 $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);*/
4248
4249
4250 print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, '');
4251 print '</td><td>';
4252 print '<input type="text" class="flat minwidth300" name="virtualhost" value="'.dol_escape_htmltag(GETPOST('virtualhost', 'alpha')).'">';
4253 print '</td></tr>';
4254
4255 print '</table>';
4256 print '</div>';
4257
4258 if ($action == 'createsite') {
4259 print '<div class="center">';
4260
4261 print '<input type="submit" class="button small" name="addcontainer" value="'.$langs->trans("Create").'">';
4262 print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
4263
4264 print '</div>';
4265 }
4266
4267
4268 //print '</div>';
4269
4270 //print dol_get_fiche_end();
4271
4272 print '</div>';
4273
4274 print '<br>';
4275}
4276
4277// Page view to import a website template
4278if ($action == 'importsite') {
4279 print '<!-- action=importsite -->';
4280 print '<div class="fiche">';
4281
4282 print '<br>';
4283
4284 print load_fiche_titre($langs->trans("ImportSite"));
4285
4286 print dol_get_fiche_head(array(), '0', '', -1);
4287
4288 print '<span class="opacitymedium">'.$langs->trans("ZipOfWebsitePackageToImport").'</span><br><br>';
4289
4290
4291 $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
4292 $allowimportsite = true;
4293 if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
4294 $allowimportsite = false;
4295 }
4296
4297 if ($allowimportsite) {
4298 $maxfilesizearray = getMaxFileSizeArray();
4299 $maxmin = $maxfilesizearray['maxmin'];
4300 if ($maxmin > 0) {
4301 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
4302 }
4303 print '<input class="flat minwidth400" type="file" name="userfile[]" accept=".zip">';
4304 print '<input type="submit" class="button small" name="buttonsubmitimportfile" value="'.dol_escape_htmltag($langs->trans("Upload")).'">';
4305 print '<input type="submit" class="button button-cancel small" name="preview" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
4306 print '<br><br><br>';
4307 } else {
4308 if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
4309 // Show clean corporate message
4310 $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
4311 } else {
4312 // Show technical generic message
4313 $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
4314 }
4315 print info_admin($message).'<br><br>';
4316 }
4317
4318
4319 print '<span class="opacitymedium">'.$langs->trans("ZipOfWebsitePackageToLoad").'</span><br><br>';
4320
4321 showWebsiteTemplates($website);
4322
4323 print dol_get_fiche_end();
4324
4325 print '</div>';
4326
4327 print '<br>';
4328}
4329
4330if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties of a web site OR properties of a web page
4331 print '<div class="fiche">';
4332
4333 print '<br>';
4334
4335 /*$h = 0;
4336 $head = array();
4337
4338 $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
4339 $head[$h][1] = $langs->trans("AddPage");
4340 $head[$h][2] = 'card';
4341 $h++;
4342
4343 print dol_get_fiche_head($head, 'card', '', -1, 'globe');
4344 */
4345 if ($action == 'createcontainer') {
4346 print load_fiche_titre($langs->trans("AddPage"));
4347 }
4348
4349 print '<!-- Edit or create page/container -->'."\n";
4350 //print '<div class="fichecenter">';
4351
4352 $hiddenfromfetchingafterload = ' hideobject';
4353 $hiddenmanuallyafterload = ' hideobject';
4354 if (GETPOST('radiocreatefrom') == 'checkboxcreatefromfetching') {
4355 $hiddenfromfetchingafterload = '';
4356 }
4357 if (GETPOST('radiocreatefrom') == 'checkboxcreatemanually') {
4358 $hiddenmanuallyafterload = '';
4359 }
4360
4361 if ($action == 'editmeta' || empty($conf->use_javascript_ajax)) { // No autohide/show in such case
4362 $hiddenfromfetchingafterload = '';
4363 $hiddenmanuallyafterload = '';
4364 }
4365
4366 if ($action == 'createcontainer') {
4367 print '<br>';
4368
4369 if (!empty($conf->use_javascript_ajax)) {
4370 print '<input type="radio" name="radiocreatefrom" id="checkboxcreatemanually" value="checkboxcreatemanually"'.(GETPOST('radiocreatefrom') == 'checkboxcreatemanually' ? ' checked' : '').'> ';
4371 }
4372 print '<label for="checkboxcreatemanually"><span class="opacitymediumxx">'.$langs->trans("OrEnterPageInfoManually").'</span></label><br>';
4373 print '<hr class="tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
4374 }
4375
4376 print '<table class="border tableforfield nobackground centpercent tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
4377
4378 if ($action != 'createcontainer') {
4379 print '<tr><td class="titlefield fieldrequired">';
4380 print $langs->trans('IDOfPage').' - '.$langs->trans('InternalURLOfPage');
4381 print '</td><td>';
4382 print $pageid;
4383 //print '</td></tr>';
4384
4385 //print '<tr><td class="titlefield fieldrequired">';
4386 //print $langs->trans('InternalURLOfPage');
4387 //print '</td><td>';
4388 print ' &nbsp; - &nbsp; ';
4389 print '/public/website/index.php?website='.urlencode($websitekey).'&pageid='.urlencode((string) $pageid);
4390 //if ($objectpage->grabbed_from) print ' - <span class="opacitymedium">'.$langs->trans('InitiallyGrabbedFrom').' '.$objectpage->grabbed_from.'</span>';
4391 print '</td></tr>';
4392
4393 $type_container = $objectpage->type_container;
4394 $pageurl = $objectpage->pageurl;
4395 $pagealiasalt = $objectpage->aliasalt;
4396 $pagetitle = $objectpage->title;
4397 $pagedescription = $objectpage->description;
4398 $pageimage = $objectpage->image;
4399 $pagekeywords = $objectpage->keywords;
4400 $pagelang = $objectpage->lang;
4401 $pageallowedinframes = $objectpage->allowed_in_frames;
4402 $pagehtmlheader = $objectpage->htmlheader;
4403 $pagedatecreation = $objectpage->date_creation;
4404 $pagedatemodification = $objectpage->date_modification;
4405 $pageauthorid = $objectpage->fk_user_creat;
4406 $pageusermodifid = $objectpage->fk_user_modif;
4407 $pageauthoralias = $objectpage->author_alias;
4408 $pagestatus = $objectpage->status;
4409 } else { // $action = 'createcontainer'
4410 $type_container = 'page';
4411 $pageurl = '';
4412 $pagealiasalt = '';
4413 $pagetitle = '';
4414 $pagedescription = '';
4415 $pageimage = '';
4416 $pagekeywords = '';
4417 $pagelang = '';
4418 $pageallowedinframes = 0;
4419 $pagehtmlheader = '';
4420 $pagedatecreation = dol_now();
4421 $pagedatemodification = '';
4422 $pageauthorid = $user->id;
4423 $pageusermodifid = 0;
4424 $pageauthoralias = '';
4425 $pagestatus = 1;
4426 }
4427 if (GETPOST('WEBSITE_TITLE', 'alpha')) {
4428 $pagetitle = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
4429 }
4430 if (GETPOST('WEBSITE_PAGENAME', 'alpha')) {
4431 $pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
4432 }
4433 if (GETPOST('WEBSITE_ALIASALT', 'alpha')) {
4434 $pagealiasalt = str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alphanohtml'));
4435 }
4436 if (GETPOST('WEBSITE_DESCRIPTION', 'alpha')) {
4437 $pagedescription = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
4438 }
4439 if (GETPOST('WEBSITE_IMAGE', 'alpha')) {
4440 $pageimage = GETPOST('WEBSITE_IMAGE', 'alpha');
4441 }
4442 if (GETPOST('WEBSITE_KEYWORDS', 'alpha')) {
4443 $pagekeywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
4444 }
4445 if (GETPOST('WEBSITE_LANG', 'aZ09')) {
4446 $pagelang = GETPOST('WEBSITE_LANG', 'aZ09');
4447 }
4448 if (GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09')) {
4449 $pageallowedinframes = 1;
4450 }
4451 if (GETPOST('htmlheader', 'none')) { // Must accept tags like '<script>' and '<link>'
4452 $pagehtmlheader = GETPOST('htmlheader', 'none');
4453 }
4454
4455 if ($action != 'createcontainer') {
4456 if (empty($conf->use_javascript_ajax)) {
4457 print '<!-- Status of web site page -->'."\n";
4458 print '<tr><td class="fieldrequired">';
4459 print $langs->trans('Status');
4460 print '</td><td>';
4461 print $form->selectyesno('status', $objectpage->status);
4462 print '</td></tr>';
4463 }
4464 }
4465
4466 // Type of container
4467 print '<tr><td class="titlefield fieldrequired">';
4468 print $langs->trans('WEBSITE_TYPE_CONTAINER');
4469 print '</td><td>';
4470 print img_picto('', 'object_technic', 'class="paddingrightonly"').' ';
4471 print $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') ? GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') : $type_container), 0, '', 1, 'minwidth300');
4472 print '</td></tr>';
4473
4474 print '<script type="text/javascript">
4475 jQuery(document).ready(function() {
4476 jQuery("#selectWEBSITE_TYPE_CONTAINER").change(function() {
4477 console.log("We change type of page : "+jQuery("#selectWEBSITE_TYPE_CONTAINER").val());
4478 if (jQuery("#selectWEBSITE_TYPE_CONTAINER").val() == \'blogpost\') {
4479 jQuery(".trpublicauthor").show();
4480 } else {
4481 jQuery(".trpublicauthor").hide();
4482 }
4483 if (jQuery("#selectWEBSITE_TYPE_CONTAINER").val() == \'service\' || jQuery("#selectWEBSITE_TYPE_CONTAINER").val() == \'library\') {
4484 $(".spanprefix").html("_" + $("#selectWEBSITE_TYPE_CONTAINER").val() + "_");
4485 jQuery(".spanprefix").show();
4486 } else {
4487 jQuery(".spanprefix").hide();
4488 }
4489 });
4490
4491 // Force at init execution a first time of the handler change
4492 jQuery("#selectWEBSITE_TYPE_CONTAINER").trigger(\'change\');
4493 });
4494 </script>
4495 ';
4496
4497 // Title
4498 print '<tr><td class="fieldrequired">';
4499 print $langs->trans('WEBSITE_TITLE');
4500 print '</td><td>';
4501 print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" id="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'" autofocus>';
4502 print '</td></tr>';
4503
4504 // Alias page
4505 print '<tr><td class="titlefieldcreate fieldrequired">';
4506 print $langs->trans('WEBSITE_PAGENAME');
4507 print '</td><td>';
4508 print '<span class="opacitymedium spanprefix hidden"></span> ';
4509 print '<input type="text" class="flat minwidth300" name="WEBSITE_PAGENAME" id="WEBSITE_PAGENAME" value="'.dol_escape_htmltag((string) preg_replace('/^_[a-z]+_/', '', (string) $pageurl)).'">';
4510 print '</td></tr>';
4511
4512 print '<script type="text/javascript">
4513 $(document).ready(function() {
4514 console.log("Manage prefix for service or library");
4515 if ($("#selectWEBSITE_TYPE_CONTAINER").val() == "service" || $("#selectWEBSITE_TYPE_CONTAINER").val() == "library") {
4516 $(".spanprefix").html("_" + $("#selectWEBSITE_TYPE_CONTAINER").val() + "_");
4517 $(".spanprefix").show();
4518 }
4519 $(".websiteformtoolbar").on("submit", function(event) {
4520 if ($("#selectWEBSITE_TYPE_CONTAINER").val() == "service" || $("#selectWEBSITE_TYPE_CONTAINER").val() == "library") {
4521 var prefix = "_" + $("#selectWEBSITE_TYPE_CONTAINER").val() + "_";
4522 var userInput = $("#WEBSITE_PAGENAME").val();
4523 var $inputField = $("#WEBSITE_PAGENAME");
4524 if (userInput.indexOf(prefix) !== 0) {
4525 $inputField.val(prefix + userInput);
4526 }
4527 }
4528 });
4529 });
4530 </script>
4531 ';
4532
4533 print '<tr><td class="titlefieldcreate">';
4534 $htmlhelp = $langs->trans("WEBSITE_ALIASALTDesc");
4535 print $form->textwithpicto($langs->trans('WEBSITE_ALIASALT'), $htmlhelp, 1, 'help', '', 0, 2, 'aliastooltip');
4536 print '</td><td>';
4537 print '<input type="text" class="flat minwidth500" name="WEBSITE_ALIASALT" value="'.dol_escape_htmltag($pagealiasalt).'">';
4538 print '</td></tr>';
4539
4540 print '<tr><td>';
4541 print $langs->trans('WEBSITE_DESCRIPTION');
4542 print '</td><td>';
4543 print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($pagedescription).'">';
4544 print '</td></tr>';
4545
4546 // Deprecated. Image for RSS or Thumbs must be taken from the content.
4547 if (getDolGlobalInt('WEBSITE_MANAGE_IMAGE_FOR_PAGES')) {
4548 print '<tr class="trimageforpage hidden"><td>';
4549 $htmlhelp = $langs->trans("WEBSITE_IMAGEDesc");
4550 print $form->textwithpicto($langs->trans('WEBSITE_IMAGE'), $htmlhelp, 1, 'help', '', 0, 2, 'imagetooltip');
4551 print '</td><td>';
4552 print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_IMAGE" value="'.dol_escape_htmltag($pageimage).'">';
4553 print '</td></tr>';
4554
4555 print '<script type="text/javascript">
4556 jQuery(document).ready(function() {
4557 jQuery("#selectWEBSITE_TYPE_CONTAINER").change(function() {
4558 console.log("We change type of page : "+jQuery("#selectWEBSITE_TYPE_CONTAINER").val());
4559 if (jQuery("#selectWEBSITE_TYPE_CONTAINER").val() == \'blogpost\') {
4560 jQuery(".trimageforpage").show();
4561 } else {
4562 jQuery(".trimageforpage").hide();
4563 }
4564 });
4565 });
4566 </script>
4567 ';
4568 }
4569
4570 // Keywords
4571 print '<tr><td>';
4572 $htmlhelp = $langs->trans("WEBSITE_KEYWORDSDesc");
4573 print $form->textwithpicto($langs->trans('WEBSITE_KEYWORDS'), $htmlhelp, 1, 'help', '', 0, 2, 'keywordtooltip');
4574 print '</td><td>';
4575 print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($pagekeywords).'">';
4576 print '</td></tr>';
4577
4578 print '<tr><td>';
4579 print $langs->trans('Language');
4580 print '</td><td>';
4581 $onlykeys = array();
4582 if ($object->lang) {
4583 $onlykeys[$object->lang] = $object->lang;
4584 } else {
4585 $onlykeys[$langs->defaultlang] = $langs->defaultlang;
4586 }
4587 if ($object->otherlang) {
4588 $tmparray = explode(',', $object->otherlang);
4589 foreach ($tmparray as $key) {
4590 $tmpkey = trim($key);
4591 if (strlen($key) == 2) {
4592 $tmpkey = strtolower($key);
4593 }
4594 $onlykeys[$tmpkey] = $tmpkey;
4595 }
4596 }
4597 if (empty($object->lang) && empty($object->otherlang)) {
4598 $onlykeys = null; // We keep full list of languages
4599 }
4600 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, array(), '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys, 1);
4601 $htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties");
4602 print $form->textwithpicto('', $htmltext);
4603 print '</td></tr>';
4604
4605 // Translation of
4606 $translationof = 0;
4607 $translatedby = 0;
4608 print '<!-- Translation of --><tr><td>';
4609 print $langs->trans('TranslationLinks');
4610 print '</td><td>';
4611 if ($action != 'createcontainer') {
4612 // Has translation pages
4613 $sql = "SELECT rowid, lang from ".MAIN_DB_PREFIX."website_page where fk_page = ".((int) $objectpage->id);
4614 $resql = $db->query($sql);
4615 if ($resql) {
4616 $num_rows = $db->num_rows($resql);
4617 if ($num_rows > 0) {
4618 print '<span class="opacitymedium">'.$langs->trans('ThisPageHasTranslationPages').':</span>';
4619 $i = 0;
4620 $tmppage = new WebsitePage($db);
4621 $tmpstring = '';
4622 while ($obj = $db->fetch_object($resql)) {
4623 $result = $tmppage->fetch($obj->rowid);
4624 if ($result > 0) {
4625 if ($i > 0) {
4626 $tmpstring .= '<br>';
4627 }
4628 $tmpstring .= $tmppage->getNomUrl(1).' '.picto_from_langcode($tmppage->lang).' '.$tmppage->lang;
4629 // Button unlink
4630 $tmpstring .= ' <a class="paddingleft" href="'.$_SERVER["PHP_SELF"].'?website='.urlencode($object->ref).'&pageid='.((int) $objectpage->id).'&action=deletelang&token='.newToken().'&deletelangforid='.((int) $tmppage->id).'">'.img_picto($langs->trans("Remove"), 'unlink').'</a>';
4631 $translatedby++;
4632 $i++;
4633 }
4634 }
4635 if ($i > 1) {
4636 print '<br>';
4637 } else {
4638 print ' ';
4639 }
4640 print $tmpstring;
4641 }
4642 } else {
4643 dol_print_error($db);
4644 }
4645 }
4646 if ((empty($translatedby) || ($objectpage->lang != $object->lang)) && ($action == 'editmeta' || $action == 'createcontainer' || $objectpage->fk_page > 0)) {
4647 $sourcepage = new WebsitePage($db);
4648 $result = 1;
4649 if ($objectpage->fk_page > 0) {
4650 $result = $sourcepage->fetch($objectpage->fk_page);
4651 if ($result == 0) {
4652 // not found, we can reset value to clean database
4653 // TODO
4654 }
4655 }
4656 if ($result >= 0) {
4657 if ($translatedby) {
4658 print '<br>';
4659 }
4660 $translationof = $objectpage->fk_page;
4661 print '<span class="opacitymedium">'.$langs->trans('ThisPageIsTranslationOf').'</span> ';
4662 print $sourcepage->getNomUrl(2).' '.$formwebsite->selectContainer($website, 'pageidfortranslation', ($translationof ? $translationof : -1), 1, $action, 'minwidth300', array($objectpage->id));
4663 if ($translationof > 0 && $sourcepage->lang) {
4664 print picto_from_langcode($sourcepage->lang).' '.$sourcepage->lang;
4665 // Button unlink
4666 print ' <a class="paddingleft" href="'.$_SERVER["PHP_SELF"].'?website='.urlencode($object->ref).'&pageid='.((int) $objectpage->id).'&action=deletelang&token='.newToken().'&deletelangforid='.((int) $objectpage->id).'">'.img_picto($langs->trans("Remove"), 'unlink').'</a>';
4667 }
4668 }
4669 }
4670 print '</td></tr>';
4671
4672 // Categories
4673 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
4674 $langs->load('categories');
4675
4676 if (!GETPOSTISSET('categories')) {
4677 $c = new Categorie($db);
4678 $cats = $c->containing($objectpage->id, Categorie::TYPE_WEBSITE_PAGE);
4679 $arrayselected = array();
4680 if (is_array($cats)) {
4681 foreach ($cats as $cat) {
4682 $arrayselected[] = $cat->id;
4683 }
4684 }
4685
4686 //$cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', '', 0, 0, 3);
4687 $cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', 'parent', 0, 0, 3);
4688 }
4689
4690 print '<tr><td class="toptd">'.$form->editfieldkey('Categories', 'categories', '', $objectpage, 0).'</td><td>';
4691 print img_picto('', 'category', 'class="pictofixedwidth"');
4692 print $form->multiselectarray('categories', $cate_arbo, (GETPOSTISSET('categories') ? GETPOST('categories', 'array') : $arrayselected), 0, 0, 'minwidth200 widthcentpercentminusxx');
4693
4694 print dolButtonToOpenUrlInDialogPopup('categories', $langs->transnoentitiesnoconv("Categories"), img_picto('', 'add'), '/categories/index.php?leftmenu=website&nosearch=1&type='.urlencode(Categorie::TYPE_WEBSITE_PAGE).'&website='.urlencode($website->ref), $disabled);
4695
4696 print "</td></tr>";
4697 }
4698
4699 if (getDolGlobalString('WEBSITE_PAGE_SHOW_INTERNAL_LINKS_TO_OBJECT')) { // TODO Replace this with link into element_element ?
4700 print '<tr><td class="titlefieldcreate">';
4701 print 'ObjectClass';
4702 print '</td><td>';
4703 print '<input type="text" class="flat minwidth300" name="WEBSITE_OBJECTCLASS" placeholder="ClassName::/path/class/ObjectClass.class.php" >';
4704 print '</td></tr>';
4705
4706 print '<tr><td class="titlefieldcreate">';
4707 print 'ObjectID';
4708 print '</td><td>';
4709 print '<input type="text" class="flat minwidth300" name="WEBSITE_OBJECTID" >';
4710 print '</td></tr>';
4711 }
4712
4713 $fuser = new User($db);
4714
4715 // Date last modification
4716 if ($action != 'createcontainer') {
4717 print '<tr><td>';
4718 print $langs->trans('DateLastModification');
4719 print '</td><td>';
4720 print dol_print_date($pagedatemodification, 'dayhour', 'tzuser');
4721 print '</td></tr>';
4722
4723 print '<tr><td>';
4724 print $langs->trans('UserModification');
4725 print '</td><td>';
4726 if ($pageusermodifid > 0) {
4727 $fuser->fetch($pageusermodifid);
4728 print $fuser->getNomUrl(-1);
4729 } else {
4730 print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
4731 }
4732 print '</td></tr>';
4733 }
4734
4735 // Content - Example/templates of page
4736 $url = 'https://wiki.dolibarr.org/index.php/Module_Website';
4737 $htmltext = '<small>';
4738 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource", $url);
4739 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource1", $url);
4740 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource2", $url);
4741 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource3", $url);
4742 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource4", $url);
4743 $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSourceMore", $url);
4744 $htmltext .= '<br>';
4745 $htmltext .= '</small>';
4746
4747 $formmail = new FormMail($db);
4748 $formmail->withaiprompt = 'html';
4749 $formmail->withlayout = 'websitepage';
4750 $showlinktolayout = $formmail->withlayout;
4751 $showlinktoai = ($formmail->withaiprompt && isModEnabled('ai')) ? 'textgenerationwebpage' : '';
4752 if (($action == 'createcontainer' && $showlinktolayout) || ($action == 'createcontainer' && $showlinktoai)) {
4753 print '<tr><td class="titlefield tdtop">';
4754 if ($conf->browser->layout == 'phone') {
4755 print $form->textwithpicto('', $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution');
4756 } else {
4757 //img_help(($tooltiptrigger != '' ? 2 : 1), $alt)
4758 print $form->textwithpicto($langs->trans("PreviewPageContent").' '.img_help(2, $langs->trans("PreviewPageContent")), $htmltext, 1, 'none', 'inline-block', 1, 2, 'tooltipsubstitution');
4759 }
4760 print '</td><td class="tdtop">';
4761
4762 $out = '';
4763
4764 $showlinktolayoutlabel = $langs->trans("FillPageWithALayout");
4765 $showlinktoailabel = $langs->trans("FillPageWithAIContent");
4766 $htmlname = 'content';
4767 // Fill $out
4768 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
4769
4770 print $out;
4771 print '</td></tr>';
4772 }
4773
4774 if ($action == 'createcontainer') {
4775 print '<tr id="pageContent"><td class="tdtop">';
4776 if (!$showlinktolayout || !$showlinktoai) {
4777 if ($conf->browser->layout == 'phone') {
4778 print $form->textwithpicto('', $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution');
4779 } else {
4780 //img_help(($tooltiptrigger != '' ? 2 : 1), $alt)
4781 print $form->textwithpicto($showlinktolayout ? '' : ($langs->trans("PreviewPageContent").' '.img_help(2, $langs->trans("PreviewPageContent"))), $htmltext, 1, 'none', 'inline-block', 1, 2, 'tooltipsubstitution');
4782 }
4783 }
4784 print '</td><td>';
4785 //$doleditor = new DolEditor('content', GETPOST('content', 'restricthtmlallowunvalid'), '', 200, 'dolibarr_mailings', 'In', true, true, true, 40, '90%');
4786 $doleditor = new DolEditor('content', GETPOST('content', 'none'), '', 200, 'dolibarr_mailings', 'In', true, true, true, 40, '90%');
4787 $doleditor->Create();
4788 print '</div>';
4789 print '</td></tr>';
4790 }
4791
4792 // Date creation
4793 print '<tr><td>';
4794 print $langs->trans('DateCreation');
4795 print '</td><td>';
4796 print $form->selectDate($pagedatecreation, 'datecreation', 1, 1, 0, '', 1, 1);
4797 //print dol_print_date($pagedatecreation, 'dayhour');
4798 print '</td></tr>';
4799
4800 // Author
4801 print '<tr><td>';
4802 print $langs->trans('Author');
4803 print '</td><td>';
4804 if ($pageauthorid > 0) {
4805 $fuser->fetch($pageauthorid);
4806 print $fuser->getNomUrl(-1);
4807 } else {
4808 print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
4809 }
4810 print '</td></tr>';
4811
4812 // Author - public alias
4813 print '<tr class="trpublicauthor hidden"><td>';
4814 print $langs->trans('PublicAuthorAlias');
4815 print '</td><td>';
4816 print '<input type="text" class="flat minwidth300" name="WEBSITE_AUTHORALIAS" value="'.dol_escape_htmltag($pageauthoralias).'" placeholder="Anonymous">';
4817 print '</td></tr>';
4818
4819 print '<tr><td class="tdhtmlheader tdtop">';
4820 $htmlhelp = $langs->trans("EditTheWebSiteForACommonHeader").'<br><br>';
4821 $htmlhelp .= $langs->trans("Example").' :<br>';
4822 $htmlhelp .= dol_nl2br(dol_htmlentities($htmlheadercontentdefault)); // do not use dol_htmlentitiesbr here, $htmlheadercontentdefault is HTML with content like <link> and <script> that we want to be html encode as they must be show as doc content not executable instruction.
4823 print $form->textwithpicto($langs->transnoentitiesnoconv('HtmlHeaderPage'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
4824 print '</td><td>';
4825 $poscursor = array('x' => GETPOST('htmlheader_x'), 'y' => GETPOST('htmlheader_y'));
4826 $doleditor = new DolEditor('htmlheader', $pagehtmlheader, '', 120, 'ace', 'In', true, false, 'ace', ROWS_3, '100%', 0, $poscursor);
4827 print $doleditor->Create(1, '', true, 'HTML Header', 'html');
4828 print '</td></tr>';
4829
4830 // Allowed in frames
4831 print '<tr><td>';
4832 print $langs->trans('AllowedInFrames');
4833 //$htmlhelp = $langs->trans("AllowedInFramesDesc");
4834 //print $form->textwithpicto($langs->trans('AllowedInFrames'), $htmlhelp, 1, 'help', '', 0, 2, 'allowedinframestooltip');
4835 print '</td><td>';
4836 print '<input type="checkbox" class="flat" name="WEBSITE_ALLOWED_IN_FRAMES" value="1"'.($pageallowedinframes ? 'checked="checked"' : '').'>';
4837 print '</td></tr>';
4838
4839 print '</table>';
4840
4841 if ($action == 'createcontainer') {
4842 print '<div class="center tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
4843
4844 print '<input type="submit" class="button small" name="addcontainer" value="'.$langs->trans("Create").'">';
4845 print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
4846
4847 print '</div>';
4848
4849
4850 print '<br>';
4851
4852 if (!empty($conf->use_javascript_ajax)) {
4853 print '<input type="radio" name="radiocreatefrom" id="checkboxcreatefromfetching" value="checkboxcreatefromfetching"'.(GETPOST('radiocreatefrom') == 'checkboxcreatefromfetching' ? ' checked' : '').'> ';
4854 }
4855 print '<label for="checkboxcreatefromfetching"><span class="opacitymediumxx">'.$langs->trans("CreateByFetchingExternalPage").'</span></label><br>';
4856 print '<hr class="tablecheckboxcreatefromfetching'.$hiddenfromfetchingafterload.'">';
4857 print '<table class="tableforfield centpercent tablecheckboxcreatefromfetching'.$hiddenfromfetchingafterload.'">';
4858 print '<tr><td class="titlefield">';
4859 print $langs->trans("URL");
4860 print '</td><td>';
4861 print info_admin($langs->trans("OnlyEditionOfSourceForGrabbedContentFuture"), 0, 0, 'warning');
4862 print '<input class="flat minwidth500" type="text" name="externalurl" value="'.dol_escape_htmltag(GETPOST('externalurl', 'alpha')).'" placeholder="https://externalsite/pagetofetch"> ';
4863 print '<br><input class="flat paddingtop" type="checkbox" name="grabimages" value="1" checked="checked"> '.$langs->trans("GrabImagesInto");
4864 print ' ';
4865 print $langs->trans("ImagesShouldBeSavedInto").' ';
4866 $arraygrabimagesinto = array('root' => $langs->trans("WebsiteRootOfImages"), 'subpage' => $langs->trans("SubdirOfPage"));
4867 print $form->selectarray('grabimagesinto', $arraygrabimagesinto, GETPOSTISSET('grabimagesinto') ? GETPOST('grabimagesinto') : 'root', 0, 0, 0, '', 0, 0, 0, '', '', 1);
4868 print '<br>';
4869
4870 print '<input class="button small" style="margin-top: 5px" type="submit" name="fetchexternalurl" value="'.dol_escape_htmltag($langs->trans("FetchAndCreate")).'">';
4871 print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
4872
4873 print '</td></tr>';
4874 print '</table>';
4875 }
4876
4877 if ($action == 'createcontainer') {
4878 print '<script type="text/javascript">
4879 jQuery(document).ready(function() {
4880 var disableautofillofalias = 0;
4881 var selectedm = \'\';
4882 var selectedf = \'\';
4883
4884 jQuery("#WEBSITE_TITLE").keyup(function() {
4885 if (disableautofillofalias == 0) {
4886 var valnospecial = jQuery("#WEBSITE_TITLE").val();
4887 valnospecial = valnospecial.replace(/[éèê]/g, \'e\').replace(/[à]/g, \'a\').replace(/[ù]/g, \'u\').replace(/[î]/g, \'i\');
4888 valnospecial = valnospecial.replace(/[ç]/g, \'c\').replace(/[ö]/g, \'o\');
4889 valnospecial = valnospecial.replace(/[^\w]/gi, \'-\').toLowerCase();
4890 valnospecial = valnospecial.replace(/\-+/g, \'-\').replace(/\-$/, \'\');
4891 console.log("disableautofillofalias=0 so we replace WEBSITE_TITLE with "+valnospecial);
4892 jQuery("#WEBSITE_PAGENAME").val(valnospecial);
4893 }
4894 });
4895 jQuery("#WEBSITE_PAGENAME").keyup(function() {
4896 if (jQuery("#WEBSITE_PAGENAME").val() == \'\') {
4897 disableautofillofalias = 0;
4898 } else {
4899 disableautofillofalias = 1;
4900 }
4901 });
4902 jQuery("#WEBSITE_PAGENAME").blur(function() {
4903 if (jQuery("#WEBSITE_PAGENAME").val() == \'\') {
4904 disableautofillofalias = 0;
4905 jQuery("#WEBSITE_TITLE").trigger(\'keyup\');
4906 }
4907 });
4908
4909 jQuery("#checkboxcreatefromfetching,#checkboxcreatemanually").click(function() {
4910 console.log("we select a method to create a new container "+jQuery("#checkboxcreatefromfetching:checked").val())
4911 jQuery(".tablecheckboxcreatefromfetching").hide();
4912 jQuery(".tablecheckboxcreatemanually").hide();
4913 if (typeof(jQuery("#checkboxcreatefromfetching:checked").val()) != \'undefined\') {
4914 console.log("show create from spider form");
4915 if (selectedf != \'createfromfetching\') {
4916 jQuery(".tablecheckboxcreatefromfetching").show();
4917 selectedf = \'createfromfetching\';
4918 selectedm = \'\';
4919 } else {
4920 jQuery(".tablecheckboxcreatefromfetching").hide();
4921 selectedf = \'\';
4922 }
4923 }
4924 if (typeof(jQuery("#checkboxcreatemanually:checked").val()) != \'undefined\') {
4925 console.log("show create from scratch or template form");
4926 if (selectedm != \'createmanually\') {
4927 jQuery(".tablecheckboxcreatemanually").show();
4928 selectedm = \'createmanually\';
4929 selectedf = \'\';
4930 } else {
4931 jQuery(".tablecheckboxcreatemanually").hide();
4932 selectedm = \'\';
4933 }
4934 }
4935 });
4936 });
4937 </script>';
4938 }
4939 //print '</div>';
4940
4941 //print dol_get_fiche_end();
4942
4943 print '</div>';
4944
4945 print '<br>';
4946}
4947
4948
4949// Print formconfirm
4950if ($action == 'preview') {
4951 print $formconfirm;
4952}
4953
4954if ($action == 'editfile' || $action == 'file_manager' || $action == 'convertimgwebp' || $action == 'confirmconvertimgwebp') {
4955 print '<!-- Edit Media -->'."\n";
4956 print '<div class="fiche"><br>';
4957
4958 $module = 'medias';
4959 $formalreadyopen = 2; // So the form to submit a new file will not be open another time inside the core/tpl/filemanager.tpl.php
4960 if (empty($url)) {
4961 $url = DOL_URL_ROOT.'/website/index.php'; // Must be an url without param
4962 }
4963 include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php';
4964
4965 print '</div>';
4966}
4967
4968if ($action == 'editmenu') {
4969 print '<!-- Edit Menu -->'."\n";
4970 print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
4971}
4972
4973if ($action == 'editsource') {
4974 // Editing with source editor
4975
4976 $contentforedit = '';
4977 //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
4978 //$contentforedit.=$csscontent;
4979 //$contentforedit.='</style>'."\n";
4980 $contentforedit .= $objectpage->content;
4981 //var_dump($_SESSION["dol_screenheight"]);
4982 $maxheightwin = 480;
4983 if (isset($_SESSION["dol_screenheight"])) {
4984 if ($_SESSION["dol_screenheight"] > 680) {
4985 $maxheightwin = $_SESSION["dol_screenheight"] - 400;
4986 }
4987 if ($_SESSION["dol_screenheight"] > 800) {
4988 $maxheightwin = $_SESSION["dol_screenheight"] - 490;
4989 }
4990 }
4991
4992 $poscursor = array('x' => GETPOST('PAGE_CONTENT_x'), 'y' => GETPOST('PAGE_CONTENT_y'));
4993 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
4994 $doleditor = new DolEditor('PAGE_CONTENT', $contentforedit, '', $maxheightwin, 'Full', '', true, true, 'ace', ROWS_5, '40%', 0, $poscursor);
4995 $doleditor->Create(0, '', false, 'HTML Source', 'php');
4996}
4997
4998if ($action == 'editcontent') {
4999 // Editing with default ckeditor
5000
5001 $contentforedit = '';
5002 //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
5003 //$contentforedit.=$csscontent;
5004 //$contentforedit.='</style>'."\n";
5005 $contentforedit .= $objectpage->content;
5006
5007 $nbrep = array();
5008 // If contentforedit has a string <img src="xxx", we replace the xxx with /viewimage.php?modulepart=medias&file=xxx except if xxx starts
5009 // with http, /viewimage.php or DOL_URL_ROOT./viewimage.phps
5010 $contentforedit = preg_replace('/(<img.*\ssrc=")(?!http|\/viewimage\.php|'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $contentforedit, -1, $nbrep);
5011
5012 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
5013 $poscursor = array('x' => GETPOST('PAGE_CONTENT_x'), 'y' => GETPOST('PAGE_CONTENT_y'));
5014 $doleditor = new DolEditor('PAGE_CONTENT', $contentforedit, '', 500, 'Full', '', true, true, true, ROWS_5, '90%', 0, $poscursor);
5015 $doleditor->Create(0, '', false);
5016}
5017
5018print "</div>\n";
5019print "</form>\n";
5020
5021
5022if ($mode == 'replacesite' || $massaction == 'replace') {
5023 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5024 print '<input type="hidden" name="token" value="'.newToken().'">';
5025 print '<input type="hidden" name="action" value="replacesiteconfirm">';
5026 print '<input type="hidden" name="mode" value="replacesite">';
5027 print '<input type="hidden" name="website" value="'.$website->ref.'">';
5028
5029
5030 print '<!-- Search page and replace string -->'."\n";
5031 print '<div class="fiche"><br>';
5032
5033 print load_fiche_titre($langs->trans("ReplaceWebsiteContent"), '', 'search');
5034
5035 print '<div class="fichecenter"><div class="fichehalfleft">';
5036
5037 print '<div class="tagtable">';
5038
5039 print '<div class="tagtr">';
5040 print '<div class="tagtd paddingrightonly opacitymedium">';
5041 print $langs->trans("SearchReplaceInto");
5042 print '</div>';
5043 print '<div class="tagtd">';
5044 print '<input type="checkbox" class="marginleftonly" id="checkboxoptiopagecontent" name="optiopagecontent" value="content"'.((!GETPOSTISSET('buttonreplacesitesearch') || GETPOST('optiopagecontent', 'aZ09')) ? ' checked' : '').'> <label for="checkboxoptiopagecontent" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("Content").'</label><br>';
5045 print '<input type="checkbox" class="marginleftonly" id="checkboxoptionmeta" name="optionmeta" value="meta"'.(GETPOST('optionmeta', 'aZ09') ? ' checked' : '').'> <label for="checkboxoptionmeta" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("WEBSITE_PAGENAME").' | '.$langs->trans("Title").' | '.$langs->trans("Description").' | '.$langs->trans("Keywords").'</label><br>';
5046 print '<input type="checkbox" class="marginleftonly" id="checkboxoptionsitefiles" name="optionsitefiles" value="sitefiles"'.(GETPOST('optionsitefiles', 'aZ09') ? ' checked' : '').'> <label for="checkboxoptionsitefiles" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("GlobalCSSorJS").'</label><br>';
5047 print '</div>';
5048 print '</div>';
5049
5050 print '<div class="tagtr">';
5051 print '<div class="tagtd paddingrightonly opacitymedium" style="padding-right: 10px !important">';
5052 print $langs->trans("SearchString");
5053 print '</div>';
5054 print '<div class="tagtd">';
5055 print '<input type="text" name="searchstring" value="'.dol_escape_htmltag($searchkey, 0, 0, '', 1).'" autofocus>';
5056 print '</div>';
5057 print '</div>';
5058
5059 print '</div>';
5060
5061 print '</div><div class="fichehalfleft">';
5062
5063 print '<div class="tagtable">';
5064
5065 print '<div class="tagtr">';
5066 print '<div class="tagtd paddingrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
5067 print $langs->trans("WEBSITE_TYPE_CONTAINER");
5068 print '</div>';
5069 print '<div class="tagtd">';
5070 print img_picto('', 'object_technic', 'class="paddingrightonly"').' ';
5071 print $formwebsite->selectTypeOfContainer('optioncontainertype', (GETPOST('optioncontainertype', 'alpha') ? GETPOST('optioncontainertype', 'alpha') : ''), 1, '', 1, 'minwidth125 maxwidth400 widthcentpercentminusx');
5072 print '</div>';
5073 print '</div>';
5074
5075 print '<div class="tagtr">';
5076 print '<div class="tagtd paddingrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
5077 print $langs->trans("Language");
5078 print '</div>';
5079 print '<div class="tagtd">';
5080 print img_picto('', 'language', 'class="paddingrightonly"').' '.$formadmin->select_language(GETPOSTISSET('optionlanguage') ? GETPOST('optionlanguage') : '', 'optionlanguage', 0, array(), '1', 0, 0, 'minwidth125 maxwidth400 widthcentpercentminusx', 2, 0, 0, array(), 1);
5081 print '</div>';
5082 print '</div>';
5083
5084 // Categories
5085 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
5086 print '<div class="tagtr">';
5087 print '<div class="tagtd paddingrightonly marginrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
5088 print $langs->trans("Category");
5089 print '</div>';
5090 print '<div class="tagtd">';
5091 print img_picto('', 'category', 'class="paddingrightonly"').' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('optioncategory') ? GETPOST('optioncategory') : '', 'optioncategory', 0, 0, 0, 0, 'minwidth125 maxwidth400 widthcentpercentminusx');
5092 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
5093 print ajax_combobox('optioncategory');
5094 print '</div>';
5095 print '</div>';
5096 }
5097
5098 print '</div>';
5099
5100 print '<input type="submit" class="button margintoponly" name="buttonreplacesitesearch" value="'.dol_escape_htmltag($langs->trans("Search")).'">';
5101
5102 print '</div></div>';
5103
5104 if ($mode == 'replacesite') {
5105 print '<!-- List of search result -->'."\n";
5106 print '<div class="rowsearchresult clearboth">';
5107
5108 print '<br>';
5109 print '<br>';
5110
5111 if ($listofpages['code'] == 'OK') {
5112 $arrayofselected = is_array($toselect) ? $toselect : array();
5113 $param = '';
5114 $nbtotalofrecords = count($listofpages['list']);
5115 $num = $limit;
5116 $permissiontodelete = $user->hasRight('website', 'delete');
5117
5118 // List of mass actions available
5119 $arrayofmassactions = array();
5120 if ($user->hasRight('website', 'writephp') && $searchkey) {
5121 $arrayofmassactions['replace'] = img_picto('', 'replacement', 'class="pictofixedwidth"').$langs->trans("Replace");
5122 }
5123 if ($user->hasRight('website', 'write')) {
5124 $arrayofmassactions['setcategory'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("ClassifyInCategory");
5125 }
5126 if ($user->hasRight('website', 'write')) {
5127 $arrayofmassactions['delcategory'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("RemoveCategory");
5128 }
5129 if ($permissiontodelete) {
5130 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
5131 }
5132 if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
5133 $arrayofmassactions = array();
5134 }
5135
5136 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
5137 $massactionbutton .= '<div class="massactionother massactionreplace hidden">';
5138 $massactionbutton .= $langs->trans("ReplaceString");
5139 $massactionbutton .= ' <input type="text" name="replacestring" value="'.dol_escape_htmltag(GETPOST('replacestring', 'none')).'">';
5140 $massactionbutton .= '</div>';
5141 $massactionbutton .= '<div class="massactionother massactionsetcategory massactiondelcategory hidden">';
5142 $massactionbutton .= img_picto('', 'category', 'class="pictofixedwidth"');
5143 $massactionbutton .= $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('setcategory') ? GETPOST('setcategory') : '', 'setcategory', 64, 0, 0, 0, 'minwidth300 alignstart');
5144 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
5145 $massactionbutton .= ajax_combobox('setcategory');
5146 $massactionbutton .= '</div>';
5147
5148 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
5149
5150 //$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
5151 $selectedfields = '';
5152 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
5153
5154 print_barre_liste($langs->trans("Results"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 1, 1, 1);
5155
5156 $topicmail = "WebsitePageRef";
5157 $modelmail = "websitepage_send";
5158 $objecttmp = new WebsitePage($db);
5159 $trackid = 'wsp'.$object->id;
5160 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
5161
5162 $param = 'mode=replacesite&website='.urlencode($website->ref);
5163 $param .= '&searchstring='.urlencode($searchkey);
5164 if (GETPOST('optiopagecontent')) {
5165 $param .= '&optiopagecontent=content';
5166 }
5167 if (GETPOST('optionmeta')) {
5168 $param .= '&optionmeta=meta';
5169 }
5170 if (GETPOST('optionsitefiles')) {
5171 $param .= '&optionsitefiles=optionsitefiles';
5172 }
5173 if (GETPOST('optioncontainertype')) {
5174 $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
5175 }
5176 if (GETPOST('optionlanguage')) {
5177 $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
5178 }
5179 if (GETPOST('optioncategory')) {
5180 $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
5181 }
5182
5183 print '<div class="div-table-responsive-no-min">';
5184 print '<table class="noborder centpercent">';
5185 print '<tr class="liste_titre">';
5186 // Action column
5187 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
5188 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
5189 }
5190 print getTitleFieldOfList("Type", 0, $_SERVER['PHP_SELF'], 'type_container', '', $param, '', $sortfield, $sortorder, '')."\n";
5191 print getTitleFieldOfList("Page", 0, $_SERVER['PHP_SELF'], 'pageurl', '', $param, '', $sortfield, $sortorder, '')."\n";
5192 print getTitleFieldOfList("Language", 0, $_SERVER['PHP_SELF'], 'lang', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
5193 print getTitleFieldOfList("Categories", 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
5194 print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
5195 print getTitleFieldOfList("UserCreation", 0, $_SERVER['PHP_SELF'], 'fk_user_creat', '', $param, '', $sortfield, $sortorder, '')."\n";
5196 print getTitleFieldOfList("DateCreation", 0, $_SERVER['PHP_SELF'], 'date_creation', '', $param, '', $sortfield, $sortorder, 'center ')."\n"; // Date creation
5197 print getTitleFieldOfList("DateLastModification", 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ')."\n"; // Date last modif
5198 print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
5199 // Action column
5200 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
5201 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
5202 }
5203 print '</tr>';
5204
5205 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
5206 $c = new Categorie($db);
5207
5208 $totalnbwords = 0;
5209
5210 foreach ($listofpages['list'] as $answerrecord) {
5211 if (is_object($answerrecord) && get_class($answerrecord) == 'WebsitePage') {
5212 $param = '?mode=replacesite';
5213 $param .= '&websiteid='.$website->id;
5214 $param .= '&optiopagecontent='.GETPOST('optiopagecontent', 'aZ09');
5215 $param .= '&optionmeta='.GETPOST('optionmeta', 'aZ09');
5216 $param .= '&optionsitefiles='.GETPOST('optionsitefiles', 'aZ09');
5217 $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
5218 $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
5219 $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
5220 $param .= '&searchstring='.urlencode($searchkey);
5221
5222 print '<tr>';
5223
5224 // Action column
5225 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
5226 print '<td class="nowrap center">';
5227
5228 print '<!-- Status of page -->'."\n";
5229 if ($massactionbutton || $massaction) {
5230 $selected = 0;
5231 if (in_array($answerrecord->id, $arrayofselected)) {
5232 $selected = 1;
5233 }
5234 print '<input id="'.$answerrecord->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$answerrecord->id.'"'.($selected ? ' checked="checked"' : '').'>';
5235 }
5236 print '</td>';
5237 }
5238
5239 // Type of container
5240 print '<td class="nowraponall">';
5241 //print $langs->trans("Container").'<br>';
5242 if (!empty($conf->cache['type_of_container'][$answerrecord->type_container])) {
5243 print $langs->trans($conf->cache['type_of_container'][$answerrecord->type_container]);
5244 } else {
5245 print $langs->trans($answerrecord->type_container);
5246 }
5247 print '</td>';
5248
5249 // Container url and label
5250 $titleofpage = ($answerrecord->title ? $answerrecord->title : $langs->trans("NoTitle"));
5251 print '<td class="tdoverflowmax300" title="'.dol_escape_htmltag($titleofpage).'">';
5252 print $answerrecord->getNomUrl(1);
5253 print ' <span class="opacitymedium">('.dol_escape_htmltag($titleofpage).')</span>';
5254 //print '</td>';
5255 //print '<td class="tdoverflow100">';
5256 print '<br>';
5257 print '<span class="opacitymedium">'.dol_escape_htmltag($answerrecord->description ? $answerrecord->description : $langs->trans("NoDescription")).'</span>';
5258 print '</td>';
5259
5260 // Language
5261 print '<td class="center">';
5262 print picto_from_langcode($answerrecord->lang, $answerrecord->lang);
5263 print '</td>';
5264
5265 // Categories - Tags
5266 print '<td class="center">';
5267 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
5268 // Get current categories
5269 $existing = $c->containing($answerrecord->id, Categorie::TYPE_WEBSITE_PAGE, 'object');
5270 if (is_array($existing)) {
5271 foreach ($existing as $tmpcategory) {
5272 //var_dump($tmpcategory);
5273 print img_object($langs->trans("Category").' : '.$tmpcategory->label, 'category', 'style="padding-left: 2px; padding-right: 2px; color: #'.($tmpcategory->color != '' ? $tmpcategory->color : '888').'"');
5274 }
5275 }
5276 }
5277 //var_dump($existing);
5278 print '</td>';
5279
5280 // Number of words
5281 print '<td class="center nowraponall">';
5282 $textwithouthtml = dol_string_nohtmltag(dolStripPhpCode($answerrecord->content));
5283 $characterMap = 'áàéèëíóúüñùç0123456789';
5284 $nbofwords = str_word_count($textwithouthtml, 0, $characterMap);
5285 if ($nbofwords) {
5286 print $nbofwords.' '.$langs->trans("words");
5287 $totalnbwords += $nbofwords;
5288 }
5289 print '</td>';
5290
5291 // Author
5292 print '<td class="tdoverflowmax125">';
5293 if (!empty($answerrecord->fk_user_creat)) {
5294 if (empty($conf->cache['user'][$answerrecord->fk_user_creat])) {
5295 $tmpuser = new User($db);
5296 $tmpuser->fetch($answerrecord->fk_user_creat);
5297 $conf->cache['user'][$answerrecord->fk_user_creat] = $tmpuser;
5298 } else {
5299 $tmpuser = $conf->cache['user'][$answerrecord->fk_user_creat];
5300 }
5301 print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
5302 }
5303 print '</td>';
5304
5305 // Date creation
5306 print '<td class="center nowraponall">';
5307 print dol_print_date($answerrecord->date_creation, 'dayhour');
5308 print '</td>';
5309
5310 // Date last modification
5311 print '<td class="center nowraponall">';
5312 print dol_print_date($answerrecord->date_modification, 'dayhour');
5313 print '</td>';
5314
5315 // Edit properties, HTML sources, status
5316 print '<td class="tdwebsitesearchresult right nowraponall">';
5317 $disabled = '';
5318 $urltoedithtmlsource = $_SERVER["PHP_SELF"].'?action=editmeta&token='.newToken().'&websiteid='.$website->id.'&pageid='.$answerrecord->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].$param);
5319 if (!$user->hasRight('website', 'write')) {
5320 $disabled = ' disabled';
5321 $urltoedithtmlsource = '';
5322 }
5323 print '<a class="editfielda marginleftonly marginrightonly '.$disabled.'" href="'.$urltoedithtmlsource.'" title="'.$langs->trans("EditPageMeta").'">'.img_picto($langs->trans("EditPageMeta"), 'pencil-ruler').'</a>';
5324
5325 $disabled = '';
5326 $urltoedithtmlsource = $_SERVER["PHP_SELF"].'?action=editsource&token='.newToken().'&websiteid='.$website->id.'&pageid='.$answerrecord->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].$param);
5327 if (!$user->hasRight('website', 'write')) {
5328 $disabled = ' disabled';
5329 $urltoedithtmlsource = '';
5330 }
5331 print '<a class="editfielda marginleftonly marginrightonly '.$disabled.'" href="'.$urltoedithtmlsource.'" title="'.$langs->trans("EditHTMLSource").'">'.img_picto($langs->trans("EditHTMLSource"), 'edit').'</a>';
5332
5333 print '<span class="marginleftonly marginrightonly"></span>';
5334 print ajax_object_onoff($answerrecord, 'status', 'status', 'Enabled', 'Disabled', array(), 'valignmiddle inline-block');
5335
5336 print '</td>';
5337
5338 // Action column
5339 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
5340 print '<td class="nowrap center">';
5341
5342 print '<!-- Status of page -->'."\n";
5343 if ($massactionbutton || $massaction) {
5344 $selected = 0;
5345 if (in_array($answerrecord->id, $arrayofselected)) {
5346 $selected = 1;
5347 }
5348 print '<input id="'.$answerrecord->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$answerrecord->id.'"'.($selected ? ' checked="checked"' : '').'>';
5349 }
5350 print '</td>';
5351 }
5352
5353 print '</tr>';
5354 } else {
5355 // $answerrecord is not list of WebsitePage
5356 '@phan-var-force array{type:string} $answerrecord';
5357 $param = '?mode=replacesite';
5358 $param .= '&websiteid='.$website->id;
5359 $param .= '&optiopagecontent='.GETPOST('optiopagecontent', 'aZ09');
5360 $param .= '&optionmeta='.GETPOST('optionmeta', 'aZ09');
5361 $param .= '&optionsitefiles='.GETPOST('optionsitefiles', 'aZ09');
5362 $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
5363 $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
5364 $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
5365 $param .= '&searchstring='.urlencode($searchkey);
5366
5367 print '<tr>';
5368
5369 // Action column
5370 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
5371 print '<td class="nowrap center">';
5372 print '</td>';
5373 }
5374
5375 // Type of container
5376 print '<td>';
5377 $translateofrecordtype = array(
5378 'website_csscontent' => 'WEBSITE_CSS_INLINE',
5379 'website_jscontent' => 'WEBSITE_JS_INLINE',
5380 'website_robotcontent' => 'WEBSITE_ROBOT',
5381 'website_htmlheadercontent' => 'WEBSITE_HTML_HEADER',
5382 'website_htaccess' => 'WEBSITE_HTACCESS',
5383 'website_readme' => 'WEBSITE_README',
5384 'website_manifestjson' => 'WEBSITE_MANIFEST_JSON'
5385 );
5386 print '<span class="opacitymedium">';
5387 if (!empty($translateofrecordtype[$answerrecord['type']])) {
5388 print $langs->trans($translateofrecordtype[$answerrecord['type']]);
5389 } else {
5390 print $answerrecord['type'];
5391 }
5392 print '</span>';
5393 print '</td>';
5394
5395 // Container url and label
5396 print '<td>';
5397 $backtopageurl = $_SERVER["PHP_SELF"].$param;
5398 print '<a href="'.$_SERVER["PHP_SELF"].'?action=editcss&token='.newToken().'&website='.urlencode($website->ref).'&backtopage='.urlencode($backtopageurl).'">'.$langs->trans("EditCss").'</a>';
5399 print '</td>';
5400
5401 // Language
5402 print '<td>';
5403 print '</td>';
5404
5405 // Categories - Tags
5406 print '<td>';
5407 print '</td>';
5408
5409 // Nb of words
5410 print '<td>';
5411 print '</td>';
5412
5413 print '<td>';
5414 print '</td>';
5415
5416 print '<td>';
5417 print '</td>';
5418
5419 // Date last modification
5420 print '<td class="center nowraponall">';
5421 //print dol_print_date(filemtime());
5422 print '</td>';
5423
5424 // Edit properties, HTML sources, status
5425 print '<td>';
5426 print '</td>';
5427
5428 // Action column
5429 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
5430 print '<td class="nowrap center">';
5431 print '</td>';
5432 }
5433
5434 print '</tr>';
5435 }
5436 }
5437
5438 if (count($listofpages['list']) >= 2) {
5439 // Total
5440 print '<tr class="lite_titre">';
5441
5442 // Action column
5443 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
5444 print '<td class="nowrap center">';
5445 print '</td>';
5446 }
5447
5448 // Type of container
5449 print '<td>';
5450 print $langs->trans("Total");
5451 print '</td>';
5452
5453 // Container url and label
5454 print '<td>';
5455 print '</td>';
5456
5457 // Language
5458 print '<td>';
5459 print '</td>';
5460
5461 // Categories - Tags
5462 print '<td>';
5463 print '</td>';
5464
5465 // Nb of words
5466 print '<td class="center nowraponall">';
5467 print $totalnbwords.' '.$langs->trans("words");
5468 print '</td>';
5469
5470 print '<td>';
5471 print '</td>';
5472
5473 print '<td>';
5474 print '</td>';
5475
5476 // Date last modification
5477 print '<td>';
5478 print '</td>';
5479
5480 // Edit properties, HTML sources, status
5481 print '<td>';
5482 print '</td>';
5483
5484 // Action column
5485 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
5486 print '<td class="nowrap center">';
5487 print '</td>';
5488 }
5489
5490 print '</tr>';
5491 }
5492
5493 print '</table>';
5494 print '</div>';
5495 print '<br>';
5496 } else {
5497 print '<div class="warning">'.$listofpages['message'].'</div>';
5498 }
5499
5500 print '</div>';
5501 }
5502
5503 print '</form>';
5504}
5505
5506if ((empty($action) || $action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') && !in_array($mode, array('replacesite'))) {
5507 if ($pageid > 0 && $atleastonepage) {
5508 // $filejs
5509 // $filecss
5510 // $filephp
5511
5512 // Output page under the Dolibarr top menu
5513 $objectpage->fetch($pageid);
5514
5515 $jscontent = @file_get_contents($filejs);
5516
5517 $out = '<!-- Page content '.$filetpl.' : Div with (Htmlheader/Style of page from database + CSS Of website from file + Page content from database or by include if WEBSITE_SUBCONTAINERSINLINE is on) -->'."\n";
5518
5519 // Include a html so we can benefit of the header of page.
5520 // Note: We can't use iframe as it can be used to include another external html file
5521 // Note: We can't use frame as it is deprecated.
5522 /*if ($includepageintoaframeoradiv == 'iframe')
5523 {
5524 $out .= "<iframe><body></html>";
5525 }*/
5526 $out .= "\n<html><head>\n";
5527 $out .= "<!-- htmlheader/style of page from database -->\n";
5528 $out .= dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1, 'htmlheader');
5529
5530 $out .= "<!-- htmlheader/style of website from files -->\n";
5531 // TODO Keep only the <link> or the <script> tags
5532 /*
5533 $htmlheadercontent = @file_get_contents($filehtmlheader);
5534 $dom = new DOMDocument;
5535 @$dom->loadHTML($htmlheadercontent);
5536 $styles = $dom->getElementsByTagName('link');
5537 $scripts = $dom->getElementsByTagName('script');
5538 foreach($styles as $stylescursor)
5539 {
5540 $out.=$stylescursor;
5541 }
5542 foreach($scripts as $scriptscursor)
5543 {
5544 $out.=$scriptscursor;
5545 }
5546 */
5547
5548 $out .= "</head>\n";
5549 $out .= "\n";
5550 $out .= "<body>\n";
5551
5552
5553 $out .= '<div id="websitecontentundertopmenu" class="websitecontentundertopmenu boostrap-iso">'."\n";
5554
5555 // REPLACEMENT OF LINKS When page called by website editor
5556
5557 $out .= '<!-- style of website from file -->'."\n";
5558 $out .= '<style scoped>'."\n"; // "scoped" means "apply to parent element only and not grand parent". No more supported by browsers, snif !
5559 $tmpout = '';
5560 $tmpout .= '/* Include website CSS file */'."\n";
5561 //$csscontent = @file_get_contents($filecss);
5562 ob_start();
5563 include $filecss;
5564 $csscontent = ob_get_contents();
5565 ob_end_clean();
5566 $tmpout .= dolWebsiteReplacementOfLinks($object, $csscontent, 1, 'css');
5567 $tmpout .= '/* Include style from the HTML header of page */'."\n";
5568 // Clean the html header of page to get only <style> content
5569 $tmp = preg_split('(<style[^>]*>|</style>)', $objectpage->htmlheader);
5570 $tmpstyleinheader = '';
5571 $i = 0;
5572 foreach ($tmp as $valtmp) {
5573 $i++;
5574 if ($i % 2 == 0) {
5575 $tmpstyleinheader .= $valtmp."\n";
5576 }
5577 }
5578 $tmpout .= $tmpstyleinheader."\n";
5579 // Clean style that may affect global style of Dolibarr
5580 $tmpout = preg_replace('/}[\s\n]*body\s*{[^}]+}/ims', '}', $tmpout);
5581 $out .= $tmpout;
5582 $out .= '</style>'."\n";
5583
5584 // Note: <div>, <section>, ... with contenteditable="true" inside this can be edited with inline ckeditor
5585
5586 // Do not enable the contenteditable when page was grabbed, ckeditor is removing span and adding borders,
5587 // so editable will be available only from container created from scratch
5588 //$out.='<div id="bodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
5589 $out .= '<div id="divbodywebsite" class="bodywebsite bodywebpage-'.$objectpage->ref.'">'."\n";
5590
5591 $newcontent = $objectpage->content;
5592
5593 // If mode WEBSITE_SUBCONTAINERSINLINE is on
5594 if (getDolGlobalString('WEBSITE_SUBCONTAINERSINLINE')) {
5595 // TODO Check file $filephp exists, if not create it.
5596
5597 //var_dump($filetpl);
5598 $filephp = $filetpl;
5599
5600 // Get session info and obfuscate session cookie
5601 $savsessionname = session_name();
5602 $savsessionid = $_COOKIE[$savsessionname];
5603 $_COOKIE[$savsessionname] = 'obfuscatedcookie';
5604
5605 ob_start();
5606 try {
5607 $res = include $filephp;
5608 if (empty($res)) {
5609 print "ERROR: Failed to include file '".$filephp."'. Try to edit and re-save page with this ID.";
5610 }
5611 } catch (Exception $e) {
5612 print $e->getMessage();
5613 }
5614 $newcontent = ob_get_contents();
5615 ob_end_clean();
5616
5617 // Restore data
5618 $_COOKIE[$savsessionname] = $savsessionid;
5619 }
5620
5621 // Change the contenteditable to "true" or "false" when mode Edit Inline is on or off
5622 if (!getDolGlobalString('WEBSITE_EDITINLINE')) {
5623 // Remove the contenteditable="true"
5624 $newcontent = preg_replace('/(div|section|header|main|footer)(\s[^>]*)contenteditable="true"/', '\1\2', $newcontent);
5625 } else {
5626 // Keep the contenteditable="true" when mode Edit Inline is on
5627 }
5628 $out .= dolWebsiteReplacementOfLinks($object, $newcontent, 0, 'html', $objectpage->id)."\n";
5629 //$out.=$newcontent;
5630
5631 $out .= '</div>'."\n";
5632
5633 $out .= '</div> <!-- End div id=websitecontentundertopmenu -->'."\n";
5634
5635 /*if ($includepageintoaframeoradiv == 'iframe')
5636 {
5637 $out .= "</body></html></iframe>";
5638 }*/
5639 $out .= "\n</body></html>\n";
5640
5641 $out .= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";
5642
5643 print $out;
5644
5645 /*file_put_contents($filetpl, $out);
5646 dolChmod($filetpl);
5647
5648 // Output file on browser
5649 dol_syslog("index.php include $filetpl $filename content-type=$type");
5650 $original_file_osencoded=dol_osencode($filetpl); // New file name encoded in OS encoding charset
5651
5652 // This test if file exists should be useless. We keep it to find bug more easily
5653 if (! file_exists($original_file_osencoded))
5654 {
5655 dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
5656 exit;
5657 }
5658
5659 //include_once $original_file_osencoded;
5660 */
5661
5662 /*print '<iframe class="websiteiframenoborder centpercent" src="'.DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$pageid.'"/>';
5663 print '</iframe>';*/
5664 } else {
5665 if (empty($websitekey) || $websitekey == '-1') {
5666 print '<br><br><div class="center previewnotyetavailable"><span class="">'.$langs->trans("NoWebSiteCreateOneFirst").'</span></div><br><br><br>';
5667 print '<div class="center"><div class="logo_setup"></div></div>';
5668 } else {
5669 print '<br><br><div class="center previewnotyetavailable"><span class="">'.$langs->trans("PreviewOfSiteNotYetAvailable", $object->ref).'</span></div><br><br><br>';
5670 print '<div class="center"><div class="logo_setup"></div></div>';
5671 }
5672 }
5673}
5674
5675// End of page
5676llxFooter();
5677$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:459
ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array(), $morecss='', $htmlname='', $forcenojs=0, $moreparam='')
On/off button to change a property status of an object This uses the ajax service objectonoff....
Definition ajax.lib.php:750
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
$c
Definition line.php:327
$object ref
Definition info.php:89
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class permettant la generation de composants html autre Only common components are here.
Class to manage component html for module website.
lessphp v0.8.0 http://leafo.net/lessphp
Class to manage Dolibarr users.
Class Website.
Class Websitepage.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_is_file($pathoffile)
Return if path is a file.
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='')
Get and save an upload file (for example after submitting a new file a mail form).
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $backtopagejsfields='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dolButtonToOpenExportDialog($name, $label, $buttonstring, $exportSiteName, $overwriteGitUrl, $website)
Create a dialog with two buttons for export and overwrite of a website.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getDomainFromURL($url, $mode=0)
Function get second level domain name.
getRootURLFromURL($url)
Function root url from a long url For example: https://www.abc.mydomain.com/dir/page....
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
removeHtmlComment($content)
Function to remove comments into HTML content.
a disabled
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:150
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:153
getMaxFileSizeArray()
Return the max allowed for file upload.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
dolSaveMasterFile($filemaster)
Save content of a page on disk.
showWebsiteTemplates(Website $website)
Show list of themes.
dolSaveLicense($file, $content)
Save content of a page on disk.
checkPHPCode(&$phpfullcodestringold, &$phpfullcodestring)
Check a new string containing only php code (including <php tag)
dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent)
Save content of a page on disk.
dolSaveReadme($file, $content)
Save content of a page on disk.
dolSaveManifestJson($file, $content)
Save content of a page on disk.
dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object=null)
Save content of the index.php and/or the wrapper.php page.
dolSavePageAlias($filealias, $object, $objectpage)
Save an alias page on disk (A page that include the reference page).
dolSaveHtaccessFile($filehtaccess, $htaccess)
Save content of a page on disk.
dolSaveJsFile($filejs, $jscontent)
Save content of a page on disk.
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).
dolSaveCssFile($filecss, $csscontent)
Save content of a page on disk.
dolSaveRobotFile($filerobot, $robotcontent)
Save content of a page on disk.
getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks=0, $grabimages=1, $grabimagesinto='subpage')
Download all images found into an external URL.
dolStripPhpCode($str, $replacewith='')
Remove PHP code part from a string.
dolWebsiteReplacementOfLinks($website, $content, $removephppart=0, $contenttype='html', $containerid=0)
Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.
getPagesFromSearchCriterias($type, $algo, $searchstring, $max=25, $sortfield='date_creation', $sortorder='DESC', $langcode='', $otherfilters=[], $status=1)
Return list of containers object that match a criteria.
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.