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