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