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