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