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