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