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