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