Completed
Branch develop (016be9)
by
unknown
30:04
created

index.php ➔ dolSavePageContent()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 56
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 44
nc 8
nop 3
dl 0
loc 56
rs 9.0544
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* Copyright (C) 2016-2017 Laurent Destailleur  <[email protected]>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 *   	\file       htdocs/website/index.php
20
 *		\ingroup    website
21
 *		\brief      Page to website view/edit
22
 */
23
24
define('NOSCANPOSTFORINJECTION',1);
25
define('NOSTYLECHECK',1);
26
27
require '../main.inc.php';
28
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30
require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
31
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
32
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
33
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
34
require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
35
require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
36
37
$langs->load("admin");
38
$langs->load("other");
39
$langs->load("website");
40
41
if (! $user->admin) accessforbidden();
42
43
if (! ((GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)))
44
{
45
	$conf->dol_hide_leftmenu = 1;   // Force hide of left menu.
46
}
47
48
$error=0;
49
$website=GETPOST('website', 'alpha');
50
$page=GETPOST('page', 'alpha');
51
$pageid=GETPOST('pageid', 'int');
52
$pageref=GETPOST('pageref', 'aZ09');
53
$action=GETPOST('action','alpha');
54
$confirm=GETPOST('confirm','alpha');
55
$cancel=GETPOST('cancel','alpha');
56
57
$type_container=GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
58
59
$section_dir = GETPOST('section_dir', 'alpha');
60
$file_manager = GETPOST('file_manager', 'alpha');
61
62
if (GETPOST('delete')) { $action='delete'; }
63
if (GETPOST('preview')) $action='preview';
64
if (GETPOST('createsite')) { $action='createsite'; }
65
if (GETPOST('createcontainer')) { $action='createcontainer'; }
66
if (GETPOST('editcss')) { $action='editcss'; }
67
if (GETPOST('editmenu')) { $action='editmenu'; }
68
if (GETPOST('setashome')) { $action='setashome'; }
69
if (GETPOST('editmeta')) { $action='editmeta'; }
70
if (GETPOST('editsource')) { $action='editsource'; }
71
if (GETPOST('editcontent')) { $action='editcontent'; }
72
if (GETPOST('createfromclone')) { $action='createfromclone'; }
73
if (GETPOST('createpagefromclone')) { $action='createpagefromclone'; }
74
if (empty($action) && $file_manager) $action='file_manager';
75
76
// Load variable for pagination
77
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
78
$sortfield = GETPOST("sortfield",'alpha');
79
$sortorder = GETPOST("sortorder",'alpha');
80
$page = GETPOST("page",'int');
81
if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
82
$offset = $limit * $page;
83
$pageprev = $page - 1;
84
$pagenext = $page + 1;
85
//if (! $sortfield) $sortfield='name';
86
//if (! $sortorder) $sortorder='ASC';
87
88
if (empty($action)) $action='preview';
89
90
$object=new Website($db);
91
$objectpage=new WebsitePage($db);
92
93
$object->fetchAll();    // Init $object->records
94
95
// If website not defined, we take first found
96
if (empty($website))
97
{
98
	foreach($object->records as $key => $valwebsite)
99
	{
100
		$website=$valwebsite->ref;
101
		break;
102
	}
103
}
104
if ($website)
105
{
106
	$res = $object->fetch(0, $website);
107
}
108
109
if ($pageid < 0) $pageid = 0;
110
if (($pageid > 0 || $pageref) && $action != 'addcontainer')
111
{
112
	$res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
113
	// Check if pageid is inside the new website, if not we reset param pageid
114
	if ($object->id > 0 && ($objectpage->fk_website != $object->id))
115
	{
116
		$res = $objectpage->fetch(0, $object->id, '');;
117
		if ($res == 0)	// Page was not found, we reset it
118
		{
119
			$objectpage=new WebsitePage($db);
120
		}
121
	}
122
	$pageid = $objectpage->id;
123
}
124
125
global $dolibarr_main_data_root;
126
$pathofwebsite=$dolibarr_main_data_root.'/website/'.$website;
127
$filehtmlheader=$pathofwebsite.'/htmlheader.html';
128
$filecss=$pathofwebsite.'/styles.css.php';
129
$filejs=$pathofwebsite.'/javascript.js.php';
130
$filerobot=$pathofwebsite.'/robots.txt';
131
$filehtaccess=$pathofwebsite.'/.htaccess';
132
$filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php';
133
$fileindex=$pathofwebsite.'/index.php';
134
135
// Define $urlwithroot
136
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
137
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
138
//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
139
140
141
$permtouploadfile = $user->rights->website->write;
142
$diroutput = $conf->medias->multidir_output[$conf->entity];
143
144
$relativepath=$section_dir;
145
$upload_dir = $diroutput.'/'.$relativepath;
146
147
148
/*
149
 * Actions
150
 */
151
152
$backtopage=$_SERVER["PHP_SELF"].'?file_manager=1&website='.$website.'&pageid='.$pageid;	// used after a confirm_deletefile into actions_linkedfiles.inc.php
153
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
154
155
if ($action == 'renamefile') $action='file_manager';		// After actions_linkedfiles, if action were renamefile, we set it to 'file_manager'
156
157
// Add directory
158
/*
159
if ($action == 'adddir' && $permtouploadfile)
160
{
161
	$ecmdir->ref                = 'NOTUSEDYET';
162
	$ecmdir->label              = GETPOST("label");
163
	$ecmdir->description        = GETPOST("desc");
164
165
	//$id = $ecmdir->create($user);
166
	if ($id > 0)
167
	{
168
		header("Location: ".$_SERVER["PHP_SELF"]);
169
		exit;
170
	}
171
	else
172
	{
173
		setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
174
		$action = "createcontainer";
175
	}
176
177
	clearstatcache();
178
}
179
*/
180
181
// Remove directory
182
if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
183
{
184
	//$result=$ecmdir->delete($user);
185
	setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
186
187
	clearstatcache();
188
}
189
190
191
if (GETPOST('refreshsite'))		// If we change the site, we reset the pageid and cancel addsite action.
192
{
193
	$pageid=0;
194
	if ($action == 'addsite') $action = 'preview';
195
}
196
if (GETPOST('refreshpage') && ! in_array($action, array('updatecss'))) $action='preview';
197
198
199
// Add site
200
if ($action == 'addsite')
201
{
202
	$db->begin();
203
204
	if (! $error && ! GETPOST('WEBSITE_REF','alpha'))
205
	{
206
		$error++;
207
		setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
208
	}
209
	if (! $error && ! preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF','alpha')))
210
	{
211
		$error++;
212
		setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors');
213
	}
214
215
	if (! $error)
216
	{
217
		$tmpobject=new Website($db);
218
		$tmpobject->ref = GETPOST('WEBSITE_REF','alpha');
219
		$tmpobject->description = GETPOST('WEBSITE_DESCRIPTION','alpha');
220
		$tmpobject->virtualhost = GETPOST('WEBSITE_VIRTUALHOST','alpha');
221
222
		$result = $tmpobject->create($user);
223
		if ($result <= 0)
224
		{
225
			$error++;
226
			setEventMessages($tmpobject->error, $tmpobject->errors, 'errors');
227
		}
228
	}
229
230
	if (! $error)
231
	{
232
		$db->commit();
233
		setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs');
234
		$action='';
235
236
		header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref);
237
		exit;
238
	}
239
	else
240
	{
241
		$db->rollback();
242
		$action='createsite';
243
	}
244
245
	if (! $error)
246
	{
247
		$action = 'preview';
248
		$id = $object->id;
249
	}
250
}
251
252
// Add page/container
253
if ($action == 'addcontainer')
254
{
255
	dol_mkdir($pathofwebsite);
256
257
	$db->begin();
258
259
	$objectpage->fk_website = $object->id;
260
	if (GETPOST('fetchexternalurl','alpha'))
261
	{
262
		$urltograb=GETPOST('externalurl','alpha');
263
	}
264
265
	if ($urltograb)
266
	{
267
		include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
268
269
		// Clean url to grab, so url can be
270
		// http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
271
		$urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
272
		$urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
273
		if (empty($urltograbwithoutdomainandparam) && ! preg_match('/\/$/', $urltograb))
274
		{
275
			$urltograb.='/';
276
		}
277
278
		$urltograbdirwithoutslash = dirname($urltograb.'.');
279
		$urltograbdirrootwithoutslash = getRootURLFromURL($urltograbdirwithoutslash);
280
		// Exemple, now $urltograbdirwithoutslash is https://www.dolimed.com/screenshots
281
		// and $urltograbdirrootwithoutslash is https://www.dolimed.com
282
283
		$tmp = getURLContent($urltograb);
284
		if ($tmp['curl_error_no'])
285
		{
286
			$error++;
287
			setEventMessages('Error getting '.$urltograb.': '.$tmp['curl_error_msg'], null, 'errors');
288
			$action='createcontainer';
289
		}
290
		elseif ($tmp['http_code'] != '200')
291
		{
292
			$error++;
293
			setEventMessages('Error getting '.$urltograb.': '.$tmp['http_code'], null, 'errors');
294
			$action='createcontainer';
295
		}
296
		else
297
		{
298
			// Remove comments
299
			$tmp['content'] = removeHtmlComment($tmp['content']);
300
301
			preg_match('/<head>(.*)<\/head>/is', $tmp['content'], $reg);
302
			$head = $reg[1];
303
304
			$objectpage->type_container = 'page';
305
   			$objectpage->pageurl = dol_sanitizeFileName(preg_replace('/[\/\.]/','-', preg_replace('/\/+$/', '', $urltograbwithoutdomainandparam)));
306
   			if (empty($objectpage->pageurl))
307
   			{
308
   				$tmpdomain = getDomainFromURL($urltograb);
309
   				$objectpage->pageurl=$tmpdomain.'-home';
310
   			}
311
312
			if (preg_match('/<title>(.*)<\/title>/ims', $head, $regtmp))
313
			{
314
				$objectpage->title = $regtmp[1];
315
			}
316
			if (preg_match('/<meta name="description"[^"]+content="([^"]+)"/ims', $head, $regtmp))
317
			{
318
				$objectpage->description = $regtmp[1];
319
			}
320
			if (preg_match('/<meta name="keywords"[^"]+content="([^"]+)"/ims', $head, $regtmp))
321
			{
322
				$objectpage->keywords = $regtmp[1];
323
			}
324
			if (preg_match('/<html\s+lang="([^"]+)"/ims', $tmp['content'], $regtmp))
325
			{
326
				$tmplang=explode('-', $regtmp[1]);
327
				$objectpage->lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : '');
328
			}
329
330
			$objectpage->content = $tmp['content'];
331
			$objectpage->content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $objectpage->content);
332
			$objectpage->content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $objectpage->content);
333
334
			$absoluteurlinaction=$urltograbdirwithoutslash;
335
			// TODO Replace 'action="$urltograbdirwithoutslash' into action="/"
336
			// TODO Replace 'action="$urltograbdirwithoutslash..."' into   action="..."
337
			// TODO Replace 'a href="$urltograbdirwithoutslash' into a href="/"
338
			// TODO Replace 'a href="$urltograbdirwithoutslash..."' into a href="..."
339
340
			// Now loop to fetch all css files. Include them inline into header of page
341
			$objectpage->htmlheader = $tmp['content'];
342
			$objectpage->htmlheader = preg_replace('/^.*<head(\s[^>]*)*>/ims', '', $objectpage->htmlheader);
343
			$objectpage->htmlheader = preg_replace('/<\/head(\s[^>]*)*>.*$/ims', '', $objectpage->htmlheader);
344
			$objectpage->htmlheader = preg_replace('/<base(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
345
			$objectpage->htmlheader = preg_replace('/<meta name="robot(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
346
			$objectpage->htmlheader = preg_replace('/<meta name="keywords(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
347
			$objectpage->htmlheader = preg_replace('/<meta name="title(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
348
			$objectpage->htmlheader = preg_replace('/<meta name="description(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
349
			$objectpage->htmlheader = preg_replace('/<meta name="generator(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
350
			//$objectpage->htmlheader = preg_replace('/<meta name="verify-v1[^>]*>\n*/ims', '', $objectpage->htmlheader);
351
			//$objectpage->htmlheader = preg_replace('/<meta name="msvalidate.01[^>]*>\n*/ims', '', $objectpage->htmlheader);
352
			$objectpage->htmlheader = preg_replace('/<title>[^<]*<\/title>\n*/ims', '', $objectpage->htmlheader);
353
			$objectpage->htmlheader = preg_replace('/<link[^>]*rel="shortcut[^>]*>\n/ims', '', $objectpage->htmlheader);
354
355
			// Now loop to fetch JS
356
			$tmp = $objectpage->htmlheader;
357
358
			preg_match_all('/<script([^\.>]+)src=["\']([^"\'>]+)["\']([^>]*)><\/script>/i', $objectpage->htmlheader, $regs);
359
			foreach ($regs[0] as $key => $val)
360
			{
361
				dol_syslog("We will grab the resource found into script tag ".$regs[2][$key]);
362
363
				$linkwithoutdomain = $regs[2][$key];
364
				if (preg_match('/^\//', $regs[2][$key]))
365
				{
366
					$urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key];	// We use dirroot
367
				}
368
				else
369
				{
370
					$urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key];	// We use dir of grabbed file
371
				}
372
373
				//$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
374
				if (preg_match('/^http/', $regs[2][$key]))
375
				{
376
					$urltograbbis = $regs[2][$key];
377
					$linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
378
					//$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
379
				}
380
381
				//print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
382
				//print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
383
384
				// Test if this is an external URL of grabbed web site. If yes, we do not load resource
385
				$domaintograb = getDomainFromURL($urltograbdirwithoutslash);
386
				$domaintograbbis = getDomainFromURL($urltograbbis);
387
				if ($domaintograb != $domaintograbbis) continue;
388
389
				/*
390
    			$tmpgeturl = getURLContent($urltograbbis);
391
    			if ($tmpgeturl['curl_error_no'])
392
    			{
393
    				$error++;
394
    				setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
395
    				$action='createcontainer';
396
    			}
397
				elseif ($tmpgeturl['http_code'] != '200')
398
				{
399
					$error++;
400
					setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
401
					$action='createcontainer';
402
				}
403
				else
404
    			{
405
    				dol_mkdir(dirname($filetosave));
406
407
    				$fp = fopen($filetosave, "w");
408
    				fputs($fp, $tmpgeturl['content']);
409
    				fclose($fp);
410
    				if (! empty($conf->global->MAIN_UMASK))
411
    					@chmod($file, octdec($conf->global->MAIN_UMASK));
412
    			}
413
				*/
414
415
				//$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
416
				$tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', '', $tmp);
417
			}
418
			$objectpage->htmlheader = trim($tmp);
419
420
421
			// Now loop to fetch CSS
422
			$pagecsscontent = "\n".'<style>'."\n";
423
424
			preg_match_all('/<link([^\.>]+)href=["\']([^"\'>]+\.css[^"\'>]*)["\']([^>]*)>/i', $objectpage->htmlheader, $regs);
425
			foreach ($regs[0] as $key => $val)
426
			{
427
				dol_syslog("We will grab the resource found into link tag ".$regs[2][$key]);
428
429
				$linkwithoutdomain = $regs[2][$key];
430
				if (preg_match('/^\//', $regs[2][$key]))
431
				{
432
					$urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key];	// We use dirroot
433
				}
434
				else
435
				{
436
					$urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key];	// We use dir of grabbed file
437
				}
438
439
				//$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
440
				if (preg_match('/^http/', $regs[2][$key]))
441
				{
442
					$urltograbbis = $regs[2][$key];
443
					$linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
444
					//$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
445
				}
446
447
				//print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
448
				//print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
449
450
				// Test if this is an external URL of grabbed web site. If yes, we do not load resource
451
				$domaintograb = getDomainFromURL($urltograbdirwithoutslash);
452
				$domaintograbbis = getDomainFromURL($urltograbbis);
453
				if ($domaintograb != $domaintograbbis) continue;
454
455
				$tmpgeturl = getURLContent($urltograbbis);
456
				if ($tmpgeturl['curl_error_no'])
457
				{
458
					$error++;
459
					setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
460
					$action='createcontainer';
461
				}
462
				elseif ($tmpgeturl['http_code'] != '200')
463
				{
464
					$error++;
465
					setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
466
					$action='createcontainer';
467
				}
468
				else
469
				{
470
					//dol_mkdir(dirname($filetosave));
471
472
					//$fp = fopen($filetosave, "w");
473
					//fputs($fp, $tmpgeturl['content']);
474
					//fclose($fp);
475
					//if (! empty($conf->global->MAIN_UMASK))
476
					//	@chmod($file, octdec($conf->global->MAIN_UMASK));
477
478
					//	$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
479
					$pagecsscontent.='/* Content of file '.$urltograbbis.' */'."\n";
480
481
					getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1);
482
483
					$pagecsscontent.=$tmpgeturl['content']."\n";
484
485
					$objectpage->htmlheader = preg_replace('/'.preg_quote($regs[0][$key],'/').'\n*/ims', '', $objectpage->htmlheader);
486
				}
487
			}
488
489
			$pagecsscontent.='</style>'."\n";
490
			//var_dump($pagecsscontent);
491
492
			//print dol_escape_htmltag($tmp);exit;
493
			$objectpage->htmlheader .= $pagecsscontent;
494
495
496
			// Now loop to fetch all images
497
			$tmp = $objectpage->content;
498
499
			getAllImages($object, $objectpage, $urltograb, $tmp, $action, 1);
500
501
			//print dol_escape_htmltag($tmp);exit;
502
			$objectpage->content = $tmp;
503
504
			$objectpage->grabbed_from = $urltograb;
505
		}
506
	}
507
	else
508
	{
509
		$objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER','alpha');
510
		$objectpage->title = GETPOST('WEBSITE_TITLE','alpha');
511
		$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME','alpha');
512
		$objectpage->description = GETPOST('WEBSITE_DESCRIPTION','alpha');
513
		$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS','alpha');
514
		$objectpage->lang = GETPOST('WEBSITE_LANG','aZ09');
515
		$objectpage->htmlheader = GETPOST('htmlheader','none');
516
517
		$substitutionarray=array();
518
		$substitutionarray['__WEBSITE_CREATE_BY__']=$user->getFullName($langs);
519
		$objectpage->content = make_substitutions(file_get_contents(DOL_DOCUMENT_ROOT.'/website/pagetemplate.html'), $substitutionarray);
520
	}
521
522
	if (! $error)
523
	{
524
		if (empty($objectpage->pageurl))
525
		{
526
			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
527
			$error++;
528
			$action='createcontainer';
529
		}
530
		else if (! preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl))
531
		{
532
			setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
533
			$error++;
534
			$action='createcontainer';
535
		}
536
		if (empty($objectpage->title))
537
		{
538
			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors');
539
			$error++;
540
			$action='createcontainer';
541
		}
542
	}
543
544
	if (! $error)
545
	{
546
		$res = $objectpage->create($user);
547
		if ($res <= 0)
548
		{
549
			$error++;
550
			setEventMessages($objectpage->error, $objectpage->errors, 'errors');
551
			$action='createcontainer';
552
		}
553
	}
554
	if (! $error)
555
	{
556
		if (! empty($objectpage->content))
557
		{
558
			$filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
559
			$filetpl=$pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
560
561
			// Save page alias
562
			$result=dolSavePageAlias($filealias, $object, $objectpage);
563
			if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
564
565
			// Save page of content
566
			$result=dolSavePageContent($filetpl, $object, $objectpage);
567
			if ($result)
568
			{
569
				setEventMessages($langs->trans("Saved"), null, 'mesgs');
570
				//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
571
				//exit;
572
			}
573
			else
574
			{
575
				setEventMessages('Failed to write file '.$filetpl, null, 'errors');
576
				//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
577
				//exit;
578
			}
579
		}
580
	}
581
	if (! $error)
582
	{
583
		$db->commit();
584
		setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
585
		$action='';
586
	}
587
	else
588
	{
589
		$db->rollback();
590
	}
591
592
	if (! $error)
593
	{
594
		$pageid = $objectpage->id;
595
596
		// To generate the CSS, robot and htmlheader file.
597
598
		// Check symlink to medias and restore it if ko
599
		$pathtomedias=DOL_DATA_ROOT.'/medias';
600
		$pathtomediasinwebsite=$pathofwebsite.'/medias';
601
		if (! is_link(dol_osencode($pathtomediasinwebsite)))
602
		{
603
			dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
604
			dol_mkdir(dirname($pathtomediasinwebsite));     // To be sure dir for website exists
605
			$result = symlink($pathtomedias, $pathtomediasinwebsite);
606
		}
607
608
		if (! dol_is_file($filehtmlheader))
609
		{
610
			$htmlheadercontent ="<html>\n";
611
			$htmlheadercontent.='<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>'."\n";
612
			$htmlheadercontent.='<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>'."\n";
613
			$htmlheadercontent.='<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />'."\n";
614
			$htmlheadercontent.="</html>";
615
			$result=dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
616
		}
617
618
		if (! dol_is_file($filecss))
619
		{
620
			$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;}";
621
			$result=dolSaveCssFile($filecss, $csscontent);
622
		}
623
624
		if (! dol_is_file($filejs))
625
		{
626
			$jscontent = "/* JS content (all pages) */\n";
627
			$result=dolSaveJsFile($filejs, $jscontent);
628
		}
629
630
		if (! dol_is_file($filerobot))
631
		{
632
			$robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
633
			$result=dolSaveRobotFile($filerobot, $robotcontent);
634
		}
635
636
		if (! dol_is_file($filehtaccess))
637
		{
638
			$htaccesscontent = "# Order allow,deny\n# Deny from all";
639
			$result=dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
640
		}
641
642
		$action = 'preview';
643
	}
644
}
645
646
// Delete page
647
if ($action == 'delete')
648
{
649
	$db->begin();
650
651
	$res = $object->fetch(0, $website);
652
653
	$res = $objectpage->fetch($pageid, $object->fk_website);
654
655
	if ($res > 0)
656
	{
657
		$res = $objectpage->delete($user);
658
		if (! $res > 0)
659
		{
660
			$error++;
661
			setEventMessages($objectpage->error, $objectpage->errors, 'errors');
662
		}
663
664
		if (! $error)
665
		{
666
			$db->commit();
667
			setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
668
669
			header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
670
			exit;
671
		}
672
		else
673
		{
674
			$db->rollback();
675
		}
676
	}
677
	else
678
	{
679
		dol_print_error($db);
680
	}
681
}
682
683
// Update css
684
if ($action == 'updatecss')
685
{
686
	if (GETPOST('refreshsite','alpha') || GETPOST('refreshpage','alpha'))		// If we tried to reload another site/page, we stay on editcss mode.
687
	{
688
		$action='editcss';
689
	}
690
	else
691
	{
692
		$res = $object->fetch(0, $website);
693
694
		// Html header file
695
		$htmlheadercontent ='';
696
697
		/* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
698
	    $htmlheadercontent.= "<?php // BEGIN PHP\n";
699
	    $htmlheadercontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
700
	    $htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
701
	    $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
702
	    $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
703
	    $htmlheadercontent.= "ob_start();\n";
704
	    // $htmlheadercontent.= "header('Content-type: text/html');\n";		// Not required. htmlheader.html is never call as a standalone page
705
	    $htmlheadercontent.= "// END PHP ?>\n";*/
706
707
		$htmlheadercontent.= preg_replace(array('/<html>\n*/ims','/<\/html>\n*/ims'),array('',''),GETPOST('WEBSITE_HTML_HEADER', 'none'));
708
709
		/*$htmlheadercontent.= "\n".'<?php // BEGIN PHP'."\n";
710
	    $htmlheadercontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
711
	    $htmlheadercontent.= "// END PHP ?>"."\n";*/
712
713
		$htmlheadercontent = trim($htmlheadercontent)."\n";
714
715
		dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
716
717
718
		// Css file
719
		$csscontent ='';
720
721
		$csscontent.= "<?php // BEGIN PHP\n";
722
		$csscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
723
		$csscontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n";	// For the css, we need to set path of master using the dirname of css file.
724
		$csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
725
		$csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
726
		$csscontent.= "ob_start();\n";
727
		$csscontent.= "header('Content-type: text/css');\n";
728
		$csscontent.= "// END PHP ?>\n";
729
730
		$csscontent.= GETPOST('WEBSITE_CSS_INLINE', 'none');
731
732
		$csscontent.= "\n".'<?php // BEGIN PHP'."\n";
733
		$csscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
734
		$csscontent.= "// END PHP ?>"."\n";
735
736
		dol_syslog("Save css content into ".$filecss);
737
738
		dol_mkdir($pathofwebsite);
739
		$result = file_put_contents($filecss, $csscontent);
740
		if (! empty($conf->global->MAIN_UMASK))
741
			@chmod($filecss, octdec($conf->global->MAIN_UMASK));
742
743
		if (! $result)
744
		{
745
			$error++;
746
			setEventMessages('Failed to write file '.$filecss, null, 'errors');
747
		}
748
749
750
		// Js file
751
		$jscontent ='';
752
753
		$jscontent.= "<?php // BEGIN PHP\n";
754
		$jscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
755
		$jscontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n";	// For the css, we need to set path of master using the dirname of css file.
756
		$jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
757
		$jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
758
		$jscontent.= "ob_start();\n";
759
		$jscontent.= "header('Content-type: application/javascript');\n";
760
		$jscontent.= "// END PHP ?>\n";
761
762
		$jscontent.= GETPOST('WEBSITE_JS_INLINE', 'none');
763
764
		$jscontent.= "\n".'<?php // BEGIN PHP'."\n";
765
		$jscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
766
		$jscontent.= "// END PHP ?>"."\n";
767
768
		dol_syslog("Save js content into ".$filejs);
769
770
		dol_mkdir($pathofwebsite);
771
		$result = file_put_contents($filejs, $jscontent);
772
		if (! empty($conf->global->MAIN_UMASK))
773
			@chmod($filejs, octdec($conf->global->MAIN_UMASK));
774
775
		if (! $result)
776
		{
777
			$error++;
778
			setEventMessages('Failed to write file '.$filejs, null, 'errors');
779
		}
780
781
782
		// Robot file
783
		$robotcontent ='';
784
785
		/*$robotcontent.= "<?php // BEGIN PHP\n";
786
	    $robotcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
787
	    $robotcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
788
	    $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
789
	    $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
790
	    $robotcontent.= "ob_start();\n";
791
	    $robotcontent.= "header('Content-type: text/css');\n";
792
	    $robotcontent.= "// END PHP ?>\n";*/
793
794
		$robotcontent.= GETPOST('WEBSITE_ROBOT', 'none');
795
796
		/*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
797
	    $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
798
	    $robotcontent.= "// END PHP ?>"."\n";*/
799
800
		dol_syslog("Save file robot into ".$filerobot);
801
802
		dol_mkdir($pathofwebsite);
803
		$result = file_put_contents($filerobot, $robotcontent);
804
		if (! empty($conf->global->MAIN_UMASK))
805
			@chmod($filerobot, octdec($conf->global->MAIN_UMASK));
806
807
		if (! $result)
808
		{
809
			$error++;
810
			setEventMessages('Failed to write file '.$filerobot, null, 'errors');
811
		}
812
813
814
		// Css file
815
		$htaccesscontent ='';
816
817
		/*$robotcontent.= "<?php // BEGIN PHP\n";
818
    	 $robotcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
819
    	 $robotcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
820
    	 $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
821
    	 $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
822
    	 $robotcontent.= "ob_start();\n";
823
    	 $robotcontent.= "header('Content-type: text/css');\n";
824
    	 $robotcontent.= "// END PHP ?>\n";*/
825
826
		$htaccesscontent.= GETPOST('WEBSITE_HTACCESS', 'none');
827
828
		/*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
829
    	 $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
830
    	 $robotcontent.= "// END PHP ?>"."\n";*/
831
832
		dol_syslog("Save file htaccess into ".$filehtaccess);
833
834
		dol_mkdir($pathofwebsite);
835
		$result = file_put_contents($filehtaccess, $htaccesscontent);
836
		if (! empty($conf->global->MAIN_UMASK))
837
			@chmod($filehtaccess, octdec($conf->global->MAIN_UMASK));
838
839
   		if (! $result)
840
   		{
841
   			$error++;
842
   			setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
843
   		}
844
845
		// Message if no error
846
		if (! $error)
847
		{
848
			setEventMessages($langs->trans("Saved"), null, 'mesgs');
849
		}
850
851
		$action='preview';
852
	}
853
}
854
855
// Update page
856
if ($action == 'setashome')
857
{
858
	$db->begin();
859
	$object->fetch(0, $website);
860
861
	$object->fk_default_home = $pageid;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pageid can also be of type string or array<integer,string>. However, the property $fk_default_home is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
862
	$res = $object->update($user);
863
	if (! $res > 0)
864
	{
865
		$error++;
866
		setEventMessages($object->error, $object->errors, 'errors');
867
	}
868
869
	if (! $error)
870
	{
871
		$db->commit();
872
873
		// Generate the index.php page to be the home page
874
		//-------------------------------------------------
875
		dol_mkdir($pathofwebsite);
876
		dol_delete_file($fileindex);
877
878
		$indexcontent = '<?php'."\n";
879
		$indexcontent.= '// File generated to provide a shortcut to the Home Page - DO NOT MODIFY - It is just an include.'."\n";
880
		$indexcontent.= "include_once './".basename($filetpl)."'\n";
881
		$indexcontent.= '?>'."\n";
882
		$result = file_put_contents($fileindex, $indexcontent);
883
		if (! empty($conf->global->MAIN_UMASK))
884
			@chmod($fileindex, octdec($conf->global->MAIN_UMASK));
885
886
		if ($result) setEventMessages($langs->trans("Saved"), null, 'mesgs');
887
		else setEventMessages('Failed to write file '.$fileindex, null, 'errors');
888
889
		$action='preview';
890
	}
891
	else
892
	{
893
		$db->rollback();
894
	}
895
}
896
897
// Update page (meta)
898
if ($action == 'updatemeta')
899
{
900
	$db->begin();
901
	$object->fetch(0, $website);
902
903
	$objectpage->fk_website = $object->id;
904
905
	// Check parameters
906
	if (! preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl))
907
	{
908
		$error++;
909
		setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
910
		$action='editmeta';
911
	}
912
913
	$res = $objectpage->fetch($pageid, $object->fk_website);
914
	if ($res <= 0)
915
	{
916
		$error++;
917
		dol_print_error($db, 'Page not found');
918
	}
919
920
	if (! $error)
921
	{
922
		$objectpage->old_object = clone $objectpage;
923
924
		$objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
925
		$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
926
		$objectpage->title = GETPOST('WEBSITE_TITLE', 'alpha');
927
		$objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
928
		$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alpha');
929
		$objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
930
		$objectpage->htmlheader = GETPOST('htmlheader', 'none');
931
932
		$res = $objectpage->update($user);
933
		if (! $res > 0)
934
		{
935
			$error++;
936
			setEventMessages($objectpage->error, $objectpage->errors, 'errors');
937
		}
938
939
		if (! $error)
940
		{
941
			$db->commit();
942
943
			$filemaster=$pathofwebsite.'/master.inc.php';
944
			$fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
945
			$filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
946
947
			dol_mkdir($pathofwebsite);
948
949
950
			// Now generate the master.inc.php page
951
			dol_syslog("We regenerate the master file (because we update meta)");
952
			dol_delete_file($filemaster);
953
954
			$mastercontent = '<?php'."\n";
955
			$mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n";
956
			$mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
957
			//$mastercontent.= "include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';"."\n";
958
			//$mastercontent.= '$website = new WebSite($db)'."\n";
959
			$mastercontent.= '?>'."\n";
960
			$result = file_put_contents($filemaster, $mastercontent);
961
			if (! empty($conf->global->MAIN_UMASK))
962
				@chmod($filemaster, octdec($conf->global->MAIN_UMASK));
963
964
			if (! $result) setEventMessages('Failed to write file '.$filemaster, null, 'errors');
965
966
967
			// Now generate the alias.php page
968
			if (! empty($fileoldalias))
969
			{
970
				dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
971
				dol_delete_file($fileoldalias);
972
			}
973
974
			// Save page alias
975
			$result=dolSavePageAlias($filealias, $object, $objectpage);
976
			if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
977
978
			// Save page of content
979
			$result=dolSavePageContent($filetpl, $object, $objectpage);
980
			if ($result)
981
			{
982
				setEventMessages($langs->trans("Saved"), null, 'mesgs');
983
				//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
984
				//exit;
985
			}
986
			else
987
			{
988
				setEventMessages('Failed to write file '.$filetpl, null, 'errors');
989
				//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
990
	   			//exit;
991
			}
992
993
			$action='preview';
994
		}
995
		else
996
		{
997
			$db->rollback();
998
		}
999
	}
1000
}
1001
1002
// Update page
1003
if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createfromclone' || $action == 'confirm_createpagefromclone')
1004
	|| ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))
1005
{
1006
	$object->fetch(0, $website);
1007
1008
	if ($action == 'confirm_createfromclone')
1009
	{
1010
		$objectnew = new Website($db);
1011
		$result = $objectnew->createFromClone($user, GETPOST('id','int'), GETPOST('siteref','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''));
1012
		if ($result < 0)
1013
		{
1014
			$error++;
1015
			setEventMessages($objectnew->error, $objectnew->errors, 'errors');
1016
			$action='preview';
1017
		}
1018
		else
1019
		{
1020
			$object = $objectnew;
1021
			$id = $object->id;
1022
			$pageid = $object->fk_default_home;
1023
		}
1024
	}
1025
1026
	if ($action == 'confirm_createpagefromclone')
1027
	{
1028
		$istranslation=(GETPOST('is_a_translation','aZ09')=='on'?1:0);
1029
		if ($istranslation)
1030
		{
1031
			if (GETPOST('newlang','aZ09') == $objectpage->lang)
1032
			{
1033
				$error++;
1034
				setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
1035
				$action='preview';
1036
			}
1037
		}
1038
1039
		if (! $error)
1040
		{
1041
			$objectpage = new WebsitePage($db);
1042
			$result = $objectpage->createFromClone($user, $pageid, GETPOST('pageurl','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''), $istranslation, GETPOST('newwebsite','int'));
1043
			if ($result < 0)
1044
			{
1045
				$error++;
1046
				setEventMessages($objectpage->error, $objectpage->errors, 'errors');
1047
				$action='createpagefromclone';
1048
			}
1049
			else
1050
			{
1051
				// TODO Switch on the new page ?
1052
			}
1053
		}
1054
	}
1055
1056
	$res = 0;
1057
1058
	if (! $error)
1059
	{
1060
		// Check symlink to medias and restore it if ko
1061
		$pathtomedias=DOL_DATA_ROOT.'/medias';
1062
		$pathtomediasinwebsite=$pathofwebsite.'/medias';
1063
		if (! is_link(dol_osencode($pathtomediasinwebsite)))
1064
		{
1065
			dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
1066
			dol_mkdir(dirname($pathtomediasinwebsite));     // To be sure dir for website exists
1067
			$result = symlink($pathtomedias, $pathtomediasinwebsite);
1068
		}
1069
1070
		/*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
1071
	    {
1072
	        $object->virtualhost = GETPOST('previewsite', 'alpha');
1073
	        $object->update($user);
1074
	    }*/
1075
1076
		$objectpage->fk_website = $object->id;
1077
1078
		if ($pageid > 0)
1079
		{
1080
			$res = $objectpage->fetch($pageid);
1081
		}
1082
		else
1083
		{
1084
			$res=0;
1085
			if ($object->fk_default_home > 0)
1086
			{
1087
				$res = $objectpage->fetch($object->fk_default_home);
1088
			}
1089
			if (! ($res > 0))
1090
			{
1091
				$res = $objectpage->fetch(0, $object->id);
1092
			}
1093
		}
1094
	}
1095
1096
	if (! $error && $res > 0)
1097
	{
1098
		if ($action == 'updatesource' || $action == 'updatecontent')
1099
		{
1100
			$db->begin();
1101
1102
			$objectpage->content = GETPOST('PAGE_CONTENT','none');
1103
1104
			// Clean data. We remove all the head section.
1105
			$objectpage->content = preg_replace('/<head>.*<\/head>/s', '', $objectpage->content);
1106
			/* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */
1107
1108
1109
			$res = $objectpage->update($user);
1110
			if ($res < 0)
1111
			{
1112
				$error++;
1113
				setEventMessages($objectpage->error, $objectpage->errors, 'errors');
1114
			}
1115
1116
			if (! $error)
1117
			{
1118
				$db->commit();
1119
1120
				$filemaster=$pathofwebsite.'/master.inc.php';
1121
				//$fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
1122
				$filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
1123
1124
				dol_mkdir($pathofwebsite);
1125
1126
1127
				// Now generate the master.inc.php page
1128
				dol_syslog("We regenerate the master file");
1129
				dol_delete_file($filemaster);
1130
1131
				$mastercontent = '<?php'."\n";
1132
				$mastercontent.= '// File generated to link to the master file'."\n";
1133
				$mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
1134
				$mastercontent.= '?>'."\n";
1135
				$result = file_put_contents($filemaster, $mastercontent);
1136
				if (! empty($conf->global->MAIN_UMASK))
1137
					@chmod($filemaster, octdec($conf->global->MAIN_UMASK));
1138
1139
				if (! $result) setEventMessages('Failed to write file '.$filemaster, null, 'errors');
1140
1141
1142
				// Now generate the alias.php page
1143
				if (! empty($fileoldalias))
1144
				{
1145
					dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
1146
					dol_delete_file($fileoldalias);
1147
				}
1148
1149
				// Save page alias
1150
				$result=dolSavePageAlias($filealias, $object, $objectpage);
1151
				if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
1152
1153
				// Save page content
1154
				$result=dolSavePageContent($filetpl, $object, $objectpage);
1155
				if ($result)
1156
				{
1157
					setEventMessages($langs->trans("Saved"), null, 'mesgs');
1158
					header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
1159
	   				exit;
1160
				}
1161
				else
1162
				{
1163
					setEventMessages('Failed to write file '.$filetpl, null, 'errors');
1164
					header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
1165
	   				exit;
1166
				}
1167
			}
1168
			else
1169
			{
1170
				$db->rollback();
1171
			}
1172
		}
1173
		else
1174
		{
1175
			header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
1176
			exit;
1177
		}
1178
	}
1179
	else
1180
	{
1181
		if (! $error) setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
1182
	}
1183
}
1184
1185
// Export site
1186
if (GETPOST('exportsite'))
1187
{
1188
	$fileofzip = $object->exportWebSite();
1189
1190
	if ($fileofzip)
1191
	{
1192
		$file_name = basename($fileofzip);
1193
1194
		header("Content-Type: application/zip");
1195
		header("Content-Disposition: attachment; filename=".$file_name);
1196
		header("Content-Length: " . filesize($fileofzip));
1197
1198
		readfile($fileofzip);
1199
		exit;
1200
	}
1201
}
1202
1203
1204
1205
/*
1206
 * View
1207
 */
1208
1209
$form = new Form($db);
1210
$formadmin = new FormAdmin($db);
1211
$formwebsite = new FormWebsite($db);
1212
1213
$help_url='';
1214
1215
$arrayofjs = array(
1216
	'/includes/ace/ace.js',
1217
	'/includes/ace/ext-statusbar.js',
1218
	'/includes/ace/ext-language_tools.js',
1219
	//'/includes/ace/ext-chromevox.js'
1220
	//'/includes/jquery/plugins/jqueryscoped/jquery.scoped.js',
1221
);
1222
$arrayofcss = array();
1223
1224
$moreheadcss='';
1225
$moreheadjs='';
1226
1227
$arrayofjs[]='includes/jquery/plugins/blockUI/jquery.blockUI.js';
1228
$arrayofjs[]='core/js/blockUI.js';	// Used by ecm/tpl/enabledfiletreeajax.tpl.pgp
1229
if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $arrayofjs[]="includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
1230
1231
$moreheadjs.='<script type="text/javascript">'."\n";
1232
$moreheadjs.='var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
1233
$moreheadjs.='</script>'."\n";
1234
1235
llxHeader($moreheadcss.$moreheadjs, $langs->trans("websiteetup"), $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
1236
1237
print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">';
1238
1239
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1240
if ($action == 'createsite')
1241
{
1242
	print '<input type="hidden" name="action" value="addsite">';
1243
}
1244
if ($action == 'createcontainer')
1245
{
1246
	print '<input type="hidden" name="action" value="addcontainer">';
1247
}
1248
if ($action == 'editcss')
1249
{
1250
	print '<input type="hidden" name="action" value="updatecss">';
1251
}
1252
if ($action == 'editmenu')
1253
{
1254
	print '<input type="hidden" name="action" value="updatemenu">';
1255
}
1256
if ($action == 'setashome')
1257
{
1258
	print '<input type="hidden" name="action" value="updateashome">';
1259
}
1260
if ($action == 'editmeta')
1261
{
1262
	print '<input type="hidden" name="action" value="updatemeta">';
1263
}
1264
if ($action == 'editsource')
1265
{
1266
	print '<input type="hidden" name="action" value="updatesource">';
1267
}
1268
if ($action == 'editcontent')
1269
{
1270
	print '<input type="hidden" name="action" value="updatecontent">';
1271
}
1272
if ($action == 'edit')
1273
{
1274
	print '<input type="hidden" name="action" value="update">';
1275
}
1276
if ($action == 'file_manager')
1277
{
1278
	print '<input type="hidden" name="action" value="file_manager">';
1279
}
1280
1281
print '<div>';
1282
1283
// Add a margin under toolbar ?
1284
$style='';
1285
if ($action != 'preview' && $action != 'editcontent' && $action != 'editsource') $style=' margin-bottom: 5px;';
1286
1287
1288
if (! GETPOST('hide_websitemenu'))
1289
{
1290
//var_dump($objectpage);exit;
1291
print '<div class="centpercent websitebar">';
1292
1293
if (count($object->records) > 0)
1294
{
1295
	// ***** Part for web sites
1296
1297
	print '<div class="websiteselection hideonsmartphoneimp minwidth100 tdoverflowmax100">';
1298
	print $langs->trans("Website").' : ';
1299
	print '</div>';
1300
1301
	print '<div class="websiteselection hideonsmartphoneimp">';
1302
	print ' <input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("Add")).'" name="createsite">';
1303
	print '</div>';
1304
1305
	// List of website
1306
	print '<div class="websiteselection">';
1307
	$out='';
1308
	$out.='<select name="website" class="minwidth100" id="website">';
1309
	if (empty($object->records)) $out.='<option value="-1">&nbsp;</option>';
1310
	// Loop on each sites
1311
	$i=0;
1312
	foreach($object->records as $key => $valwebsite)
1313
	{
1314
		if (empty($website)) $website=$valwebsite->ref;
1315
1316
		$out.='<option value="'.$valwebsite->ref.'"';
1317
		if ($website == $valwebsite->ref) $out.=' selected';		// To preselect a value
1318
		$out.='>';
1319
		$out.=$valwebsite->ref;
1320
		$out.='</option>';
1321
		$i++;
1322
	}
1323
	$out.='</select>';
1324
	$out.=ajax_combobox('website');
1325
	print $out;
1326
	//print '<input type="submit" class="button" name="refreshsite" value="'.$langs->trans("Load").'">';
1327
	print '<input type="image" class="valignbottom" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshpage" value="'.$langs->trans("Load").'">';
1328
1329
1330
	if ($website)
1331
	{
1332
		$virtualurl='';
1333
		$dataroot=DOL_DATA_ROOT.'/website/'.$website;
1334
		if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost;
1335
	}
1336
1337
	if ($website && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone'))
1338
	{
1339
		$disabled='';
1340
		if (empty($user->rights->website->write)) $disabled=' disabled="disabled"';
1341
1342
		print ' &nbsp; ';
1343
1344
		print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditCss")).'" name="editcss">';
1345
		//print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditMenu")).'" name="editmenu">';
1346
		print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';
1347
		print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ExportSite")).'" name="exportsite">';
1348
1349
		print ' &nbsp; ';
1350
1351
		print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="file_manager">';
1352
		/*print '<a class="button button_file_manager"'.$disabled.'>'.dol_escape_htmltag($langs->trans("MediaFiles")).'</a>';
1353
		print '<script language="javascript">
1354
			jQuery(document).ready(function () {
1355
           		jQuery(".button_file_manager").click(function () {
1356
					var $dialog = $(\'<div></div>\').html(\'<iframe style="border: 0px;" src="'.DOL_URL_ROOT.'/website/index.php?hide_websitemenu=1&dol_hide_topmenu=1&dol_hide_leftmenu=1&file_manager=1&website='.$website.'&pageid='.$pageid.'" width="100%" height="100%"></iframe>\')
1357
					.dialog({
1358
						autoOpen: false,
1359
						modal: true,
1360
						height: 500,
1361
						width: \'80%\',
1362
						title: "'.dol_escape_js($langs->trans("FileManager")).'"
1363
					});
1364
					$dialog.dialog(\'open\');
1365
				});
1366
			});
1367
			</script>';
1368
		*/
1369
	}
1370
1371
	print '</div>';
1372
1373
	// Button for website
1374
	print '<div class="websitetools">';
1375
1376
	if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
1377
	{
1378
		print '<a class="websitebuttonsitepreview" id="previewsite" href="'.$urlwithroot.'/public/website/index.php?website='.$website.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">';
1379
		print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview');
1380
		print '</a>';
1381
1382
		print '<div class="websiteinputurl" id="websiteinputurl">';
1383
		print '<input type="text" id="previewsiteurl" class="minwidth200imp" name="previewsite" placeholder="'.$langs->trans("http://myvirtualhost").'" value="'.$virtualurl.'">';
1384
		//print '<input type="submit" class="button" name="previewwebsite" target="tab'.$website.'" value="'.$langs->trans("ViewSiteInNewTab").'">';
1385
		$htmltext=$langs->trans("SetHereVirtualHost", $dataroot);
1386
		print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helpvirtualhost');
1387
		print '</div>';
1388
1389
		$urlext=$virtualurl;
1390
		$urlint=$urlwithroot.'/public/website/index.php?website='.$website;
1391
		print '<a class="websitebuttonsitepreview'.($urlext?'':' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewsiteext" href="'.$urlext.'" target="tab'.$website.'ext" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext)).'">';
1392
		print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:'<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>'), 1, 'preview_ext');
1393
		print '</a>';
1394
	}
1395
1396
	if (in_array($action, array('editcss','editmenu','file_manager')))
1397
	{
1398
		if (preg_match('/^create/',$action) && $action != 'file_manager') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
1399
		if (preg_match('/^edit/',$action) && $action != 'file_manager') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
1400
		if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
1401
	}
1402
1403
	print '</div>';
1404
1405
1406
	// ***** Part for pages
1407
1408
	if ($website && ! in_array($action, array('editcss','editmenu')))
1409
	{
1410
		print '</div>';	// Close current websitebar to open a new one
1411
1412
		$array=$objectpage->fetchAll($object->id);
1413
		if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
1414
		$atleastonepage=(is_array($array) && count($array) > 0);
1415
1416
		print '<div class="centpercent websitebar"'.($style?' style="'.$style.'"':'').'">';
1417
1418
		print '<div class="websiteselection hideonsmartphoneimp minwidth100 tdoverflowmax100">';
1419
		print $langs->trans("PageContainer").': ';
1420
		print '</div>';
1421
1422
		print '<div class="websiteselection hideonsmartphoneimp">';
1423
		print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("Add")).'" name="createcontainer">';
1424
		print '</div>';
1425
1426
		print '<div class="websiteselection">';
1427
1428
		if ($action != 'addcontainer')
1429
		{
1430
			$out='';
1431
			$out.='<select name="pageid" id="pageid" class="minwidth200 maxwidth300">';
1432
			if ($atleastonepage)
1433
			{
1434
				if (empty($pageid) && $action != 'createcontainer')      // Page id is not defined, we try to take one
1435
				{
1436
					$firstpageid=0;$homepageid=0;
1437
					foreach($array as $key => $valpage)
1438
					{
1439
						if (empty($firstpageid)) $firstpageid=$valpage->id;
1440
						if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid=$valpage->id;
1441
					}
1442
					$pageid=$homepageid?$homepageid:$firstpageid;   // We choose home page and if not defined yet, we take first page
1443
				}
1444
1445
				foreach($array as $key => $valpage)
1446
				{
1447
					$out.='<option value="'.$key.'"';
1448
					if ($pageid > 0 && $pageid == $key) $out.=' selected';		// To preselect a value
1449
					$out.='>';
1450
					$out.='['.$valpage->type_container.'] ';
1451
					$out.=$valpage->pageurl.' - '.$valpage->title;
1452
					if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')';
1453
					$out.='</option>';
1454
				}
1455
			}
1456
			else $out.='<option value="-1">&nbsp;</option>';
1457
			$out.='</select>';
1458
			$out.=ajax_combobox('pageid');
1459
			print $out;
1460
		}
1461
		else
1462
		{
1463
			print $langs->trans("New");
1464
		}
1465
1466
		//print '<input type="submit" class="button" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>';
1467
		print '<input type="image" class="valignbottom" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>';
1468
1469
		if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
1470
		{
1471
			$disabled='';
1472
			if (empty($user->rights->website->write)) $disabled=' disabled="disabled"';
1473
1474
			// Confirmation to clone
1475
			if ($action == 'createfromclone') {
1476
				// Create an array for form
1477
				$formquestion = array(
1478
				array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("WebSite")  ,'value'=> 'copy_of_'.$object->ref),
1479
				//array('type' => 'checkbox', 'name' => 'is_a_translation', 'label' => $langs->trans("SiteIsANewTranslation"), 'value' => 0),
1480
				//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')),
1481
				//array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
1482
				);
1483
1484
				$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id='.$object->id, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200);
1485
1486
				print $formconfirm;
1487
			}
1488
1489
			if ($pageid > 0)
1490
			{
1491
				// Confirmation to clone
1492
				if ($action == 'createpagefromclone') {
1493
					// Create an array for form
1494
					$formquestion = array(
1495
						array('type' => 'text', 'name' => 'pageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME")  ,'value'=> 'copy_of_'.$objectpage->pageurl),
1496
						array('type' => 'checkbox', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0),
1497
						array('type' => 'other','name' => 'newlang','label' => $langs->trans("Language"), 'value' => $formadmin->select_language(GETPOST('newlang', 'az09')?GETPOST('newlang', 'az09'):$langs->defaultlang, 'newlang', 0, null, 1, 0, 0, 'minwidth200')),
1498
						array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)),
1499
					);
1500
1501
				   	$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?website='.$object->ref.'&pageid=' . $pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550);
1502
1503
					print $formconfirm;
1504
				}
1505
1506
				print ' &nbsp; ';
1507
1508
				print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
1509
				print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
1510
				print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditHTMLSource")).'" name="editsource">';
1511
				if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button nobordertransp" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
1512
				else print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
1513
				print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
1514
				print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage?'':' disabled="disabled"').'>';
1515
			}
1516
		}
1517
1518
		print '</div>';	// end website selection
1519
1520
		print '<div class="websitetools">';
1521
1522
		if ($website && $pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone'))
1523
		{
1524
			$websitepage = new WebSitePage($db);
1525
			$websitepage->fetch($pageid);
1526
1527
			$realpage=$urlwithroot.'/public/website/index.php?website='.$website.'&pageref='.$websitepage->pageurl;
1528
			$pagealias = $websitepage->pageurl;
1529
1530
			print '<a class="websitebuttonsitepreview" id="previewpage" href="'.$realpage.'&nocache='.dol_now().'" class="button" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage)).'">';
1531
			print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview');
1532
			print '</a>';       // View page in new Tab
1533
1534
			print '<div class="websiteinputurl" id="websiteinputpage">';
1535
			print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
1536
			$htmltext=$langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta"));
1537
			print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias');
1538
			print '</div>';
1539
1540
			$urlext=$virtualurl.'/'.$pagealias.'.php';
1541
			$urlint=$urlwithroot.'/public/website/index.php?website='.$website;
1542
			print '<a class="websitebuttonsitepreview'.($virtualurl?'':' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewpageext" href="'.$urlext.'" target="tab'.$website.'ext" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">';
1543
			print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl?$urlext:'<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>'), 1, 'preview_ext');
1544
			print '</a>';
1545
			//print '<input type="submit" class="button" name="previewpage" target="tab'.$website.'"value="'.$langs->trans("ViewPageInNewTab").'">';
1546
1547
			// TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
1548
		}
1549
		if (! in_array($action, array('editcss','editmenu','file_manager','createsite','createcontainer','createpagefromclone')))
1550
		{
1551
			if (preg_match('/^create/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
1552
			if (preg_match('/^edit/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
1553
			if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
1554
		}
1555
1556
		print '</div>';	// end websitetools
1557
1558
		print '<div class="websitehelp">';
1559
		if (GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha'))
1560
		{
1561
			$htmltext=$langs->transnoentitiesnoconv("YouCanEditHtmlSource").'<br>';
1562
			print $form->textwithpicto($langs->trans("SyntaxHelp"), $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution');
1563
		}
1564
		print '</div>';	// end websitehelp
1565
1566
1567
1568
		if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
1569
		{
1570
			// Adding jquery code to change on the fly url of preview ext
1571
			if (! empty($conf->use_javascript_ajax))
1572
			{
1573
				print '<script type="text/javascript" language="javascript">
1574
                    jQuery(document).ready(function() {
1575
                		jQuery("#websiteinputurl").keyup(function() {
1576
                            console.log("Website external url modified "+jQuery("#previewsiteurl").val());
1577
                			if (jQuery("#previewsiteurl").val() != "") jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 1 });
1578
                			else jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 0.2 });
1579
                		});
1580
                    	jQuery("#previewsiteext,#previewpageext").click(function() {
1581
                            newurl=jQuery("#previewsiteurl").val();
1582
                            newpage=jQuery("#previewsiteurl").val() + "/" + jQuery("#previewpageurl").val() + ".php";
1583
                            console.log("Open url "+newurl);
1584
                            /* Save url */
1585
                            jQuery.ajax({
1586
                                method: "POST",
1587
                                url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
1588
                                data: {
1589
                                    field: \'editval_virtualhost\',
1590
                                    element: \'website\',
1591
                                    table_element: \'website\',
1592
                                    fk_element: '.$object->id.',
1593
                                    value: newurl,
1594
                                },
1595
                                context: document.body
1596
                            });
1597
1598
                            jQuery("#previewsiteext").attr("href",newurl);
1599
                            jQuery("#previewpageext").attr("href",newpage);
1600
                        });
1601
                    });
1602
                    </script>';
1603
			}
1604
		}
1605
	}
1606
}
1607
else
1608
{
1609
	print '<div class="websiteselection">';
1610
	$langs->load("errors");
1611
	print $langs->trans("ErrorModuleSetupNotComplete");
1612
	print '<div>';
1613
	$action='';
1614
}
1615
1616
print '</div>';	// end current websitebar
1617
}
1618
1619
1620
1621
$head = array();
1622
1623
1624
/*
1625
 * Edit Site HTML header and CSS
1626
 */
1627
1628
if ($action == 'editcss')
1629
{
1630
	print '<div class="fiche">';
1631
1632
	print '<br>';
1633
	if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
1634
	{
1635
		$csscontent = @file_get_contents($filecss);
1636
		// Clean the php css file to remove php code and get only css part
1637
		$csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $csscontent);
1638
	}
1639
	else
1640
	{
1641
		$csscontent = GETPOST('WEBSITE_CSS_INLINE');
1642
	}
1643
	if (! trim($csscontent)) $csscontent='/* CSS content (all pages) */'."\n"."body.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
1644
1645
	if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
1646
	{
1647
		$jscontent = @file_get_contents($filejs);
1648
		// Clean the php js file to remove php code and get only js part
1649
		$jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $jscontent);
1650
	}
1651
	else
1652
	{
1653
		$jscontent = GETPOST('WEBSITE_JS_INLINE');
1654
	}
1655
	if (! trim($jscontent)) $jscontent='/* JS content (all pages) */'."\n";
1656
1657
	if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
1658
	{
1659
		$htmlheadercontent = @file_get_contents($filehtmlheader);
1660
		// Clean the php htmlheader file to remove php code and get only html part
1661
		$htmlheadercontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htmlheadercontent);
1662
	}
1663
	else
1664
	{
1665
		$htmlheadercontent = GETPOST('WEBSITE_HTML_HEADER');
1666
	}
1667
	if (! trim($htmlheadercontent))
1668
	{
1669
		$htmlheadercontent ="<html>\n";
1670
		$htmlheadercontent.='<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>'."\n";
1671
		$htmlheadercontent.='<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>'."\n";
1672
		$htmlheadercontent.='<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />'."\n";
1673
		$htmlheadercontent.="</html>";
1674
	}
1675
	else
1676
	{
1677
		$htmlheadercontent = preg_replace('/^\s*<html>/ims', '', $htmlheadercontent);
1678
		$htmlheadercontent = preg_replace('/<\/html>\s*$/ims', '', $htmlheadercontent);
1679
		$htmlheadercontent='<html>'."\n".trim($htmlheadercontent)."\n".'</html>';
1680
	}
1681
1682
	if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
1683
	{
1684
		$robotcontent = @file_get_contents($filerobot);
1685
		// Clean the php htmlheader file to remove php code and get only html part
1686
		$robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $robotcontent);
1687
	}
1688
	else
1689
	{
1690
		$robotcontent = GETPOST('WEBSITE_ROBOT');
1691
	}
1692
	if (! trim($robotcontent))
1693
	{
1694
		$robotcontent.="# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n";
1695
		$robotcontent.="User-agent: *\n";
1696
		$robotcontent.="Allow: /public/\n";
1697
		$robotcontent.="Disallow: /administrator/\n";
1698
	}
1699
1700
	if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
1701
	{
1702
		$htaccesscontent = @file_get_contents($filehtaccess);
1703
		// Clean the php htaccesscontent file to remove php code and get only html part
1704
		$htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htaccesscontent);
1705
	}
1706
	else
1707
	{
1708
		$htaccesscontent = GETPOST('WEBSITE_HTACCESS');
1709
	}
1710
	if (! trim($htaccesscontent))
1711
	{
1712
		$htaccesscontent.="# Order allow,deny\n";
1713
		$htaccesscontent.="# Deny from all\n";
1714
	}
1715
	//else $htaccesscontent='<html>'."\n".$htaccesscontent."\n".'</html>';*/
1716
1717
	dol_fiche_head();
1718
1719
	print '<!-- Edit CSS -->'."\n";
1720
	print '<table class="border" width="100%">';
1721
1722
	// Website
1723
	print '<tr><td class="titlefieldcreate">';
1724
	print $langs->trans('WebSite');
1725
	print '</td><td>';
1726
	print $website;
1727
	print '</td></tr>';
1728
1729
	// CSS file
1730
	print '<tr><td class="tdtop">';
1731
	print $langs->trans('WEBSITE_CSS_INLINE');
1732
	print '</td><td>';
1733
1734
	$doleditor=new DolEditor('WEBSITE_CSS_INLINE', $csscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1735
	print $doleditor->Create(1, '', true, 'CSS', 'css');
1736
1737
	print '</td></tr>';
1738
1739
	// JS file
1740
	print '<tr><td class="tdtop">';
1741
	print $langs->trans('WEBSITE_JS_INLINE');
1742
	print '</td><td>';
1743
1744
	$doleditor=new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1745
	print $doleditor->Create(1, '', true, 'JS', 'javascript');
1746
1747
	print '</td></tr>';
1748
1749
	// Common HTML header
1750
	print '<tr><td class="tdtop">';
1751
	$htmlhelp=$langs->trans("Example").' :<br>';
1752
	$htmlhelp.='&lt;script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous" &gt;&lt;/script&gt;<br>';
1753
	$htmlhelp.='&lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=" crossorigin="anonymous" &gt;&lt;/script&gt;<br>';
1754
	$htmlhelp.='&lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /&gt;<br>';
1755
	print $form->textwithpicto($langs->trans('WEBSITE_HTML_HEADER'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
1756
	print '</td><td>';
1757
1758
	$doleditor=new DolEditor('WEBSITE_HTML_HEADER', $htmlheadercontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1759
	print $doleditor->Create(1, '', true, 'HTML Header', 'html');
1760
1761
	print '</td></tr>';
1762
1763
	// Robot file
1764
	print '<tr><td class="tdtop">';
1765
	print $langs->trans('WEBSITE_ROBOT');
1766
	print '</td><td>';
1767
1768
	$doleditor=new DolEditor('WEBSITE_ROBOT', $robotcontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1769
	print $doleditor->Create(1, '', true, 'Robot file', 'text');
1770
1771
	print '</td></tr>';
1772
1773
	// .htaccess
1774
	print '<tr><td class="tdtop">';
1775
	print $langs->trans('WEBSITE_HTACCESS');
1776
	print '</td><td>';
1777
1778
	$doleditor=new DolEditor('WEBSITE_HTACCESS', $htaccesscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1779
	print $doleditor->Create(1, '', true, $langs->trans("File").' .htaccess', 'text');
1780
1781
	print '</td></tr>';
1782
1783
	print '</table>';
1784
1785
	dol_fiche_end();
1786
1787
	print '</div>';
1788
1789
	print '<br>';
1790
}
1791
1792
if ($action == 'createsite')
1793
{
1794
	print '<div class="fiche">';
1795
1796
	print '<br>';
1797
1798
	/*$h = 0;
1799
	$head = array();
1800
1801
	$head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
1802
	$head[$h][1] = $langs->trans("AddSite");
1803
   	$head[$h][2] = 'card';
1804
	$h++;
1805
1806
    dol_fiche_head($head, 'card', $langs->trans("AddSite"), -1, 'globe');
1807
    */
1808
	if ($action == 'createcontainer') print_fiche_titre($langs->trans("AddSite"));
1809
1810
	print '<!-- Add site -->'."\n";
1811
	//print '<div class="fichecenter">';
1812
1813
	print '<table class="border" width="100%">';
1814
1815
	if (GETPOST('WEBSITE_REF'))         $siteref=GETPOST('WEBSITE_REF','alpha');
1816
	if (GETPOST('WEBSITE_DESCRIPTION')) $sitedesc=GETPOST('WEBSITE_DESCRIPTION','alpha');
1817
1818
	print '<tr><td class="titlefieldcreate fieldrequired">';
1819
	print $langs->trans('Ref');
1820
	print '</td><td>';
1821
	print '<input type="text" class="flat maxwidth300" name="WEBSITE_REF" value="'.dol_escape_htmltag($siteref).'">';
1822
	print '</td></tr>';
1823
1824
	print '<tr><td>';
1825
	print $langs->trans('Description');
1826
	print '</td><td>';
1827
	print '<input type="text" class="flat minwidth300" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
1828
	print '</td></tr>';
1829
1830
	print '<tr><td>';
1831
	print $form->textwithpicto($langs->trans('Virtualhost'), $langs->trans("SetHereVirtualHost", DOL_DATA_ROOT.'/website/<i>websiteref</i>'), 1, 'help', '', 0, 2, 'tooltipvirtual');
1832
	print '</td><td>';
1833
	print '<input type="text" class="flat minwidth300" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
1834
	print '</td></tr>';
1835
1836
1837
	print '</table>';
1838
1839
	if ($action == 'createsite')
1840
	{
1841
		print '<div class="center">';
1842
1843
		print '<input class="button" type="submit" name="addcontainer" value="'.$langs->trans("Create").'">';
1844
		print '<input class="button" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
1845
1846
		print '</div>';
1847
	}
1848
1849
1850
	//print '</div>';
1851
1852
	//dol_fiche_end();
1853
1854
	print '</div>';
1855
1856
	print '<br>';
1857
}
1858
1859
if ($action == 'editmeta' || $action == 'createcontainer')
1860
{
1861
	print '<div class="fiche">';
1862
1863
	print '<br>';
1864
1865
	/*$h = 0;
1866
	$head = array();
1867
1868
	$head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
1869
	$head[$h][1] = $langs->trans("AddPage");
1870
   	$head[$h][2] = 'card';
1871
	$h++;
1872
1873
    dol_fiche_head($head, 'card', $langs->trans("AddPage"), -1, 'globe');
1874
    */
1875
	if ($action == 'createcontainer') print_fiche_titre($langs->trans("AddPage"));
1876
1877
	print '<!-- Edit or create page/container -->'."\n";
1878
	//print '<div class="fichecenter">';
1879
1880
	if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
1881
	{
1882
		if ($action == 'createcontainer')
1883
		{
1884
			print '<br>';
1885
1886
			print ' * '.$langs->trans("CreateByFetchingExternalPage").'<br><hr>';
1887
			print '<table class="border" width="100%">';
1888
			print '<tr><td class="titlefield">';
1889
			print $langs->trans("URL");
1890
			print '</td><td>';
1891
			print '<input class="flat minwidth300" type="text" name="externalurl" value="'.dol_escape_htmltag(GETPOST('externalurl','alpha')).'" placeholder="http://externalsite/pagetofetch"> ';
1892
			print '<input class="button" type="submit" name="fetchexternalurl" value="'.dol_escape_htmltag($langs->trans("FetchAndCreate")).'">';
1893
			print '</td></tr>';
1894
			print '</table>';
1895
1896
			print '<br>';
1897
1898
			print ' * '.$langs->trans("OrEnterPageInfoManually").'<br><hr>';
1899
		}
1900
	}
1901
1902
	print '<table class="border" width="100%">';
1903
1904
	if ($action != 'createcontainer')
1905
	{
1906
		print '<tr><td class="titlefield fieldrequired">';
1907
		print $langs->trans('IDOfPage');
1908
		print '</td><td>';
1909
		print $pageid;
1910
		print '</td></tr>';
1911
1912
		print '<tr><td class="titlefield">';
1913
		print $langs->trans('WEBSITE_PAGEURL');
1914
		print '</td><td>';
1915
		print '/public/website/index.php?website='.urlencode($website).'&pageid='.urlencode($pageid);
1916
		print '</td></tr>';
1917
1918
		/*
1919
        print '<tr><td class="titlefield">';
1920
        print $langs->trans('InitiallyGrabbedFrom');
1921
        print '</td><td>';
1922
        print $objectpage->grabbed_from;
1923
        print '</td></tr>';
1924
        */
1925
1926
		$type_container=$objectpage->type_container;
1927
		$pageurl=$objectpage->pageurl;
1928
		$pagetitle=$objectpage->title;
1929
		$pagedescription=$objectpage->description;
1930
		$pagekeywords=$objectpage->keywords;
1931
		$pagelang=$objectpage->lang;
1932
		$pagehtmlheader=$objectpage->htmlheader;
1933
	}
1934
	if (GETPOST('WEBSITE_PAGENAME','alpha'))    $pageurl=GETPOST('WEBSITE_PAGENAME','alpha');
1935
	if (GETPOST('WEBSITE_TITLE','alpha'))       $pagetitle=GETPOST('WEBSITE_TITLE','alpha');
1936
	if (GETPOST('WEBSITE_DESCRIPTION','alpha')) $pagedescription=GETPOST('WEBSITE_DESCRIPTION','alpha');
1937
	if (GETPOST('WEBSITE_KEYWORDS','alpha'))    $pagekeywords=GETPOST('WEBSITE_KEYWORDS','alpha');
1938
	if (GETPOST('WEBSITE_LANG','aZ09'))         $pagelang=GETPOST('WEBSITE_LANG','aZ09');
1939
	if (GETPOST('htmlheader','none'))			$pagehtmlheader=GETPOST('htmlheader','none');
1940
1941
	print '<tr><td class="titlefield fieldrequired">';
1942
	print $langs->trans('WEBSITE_TYPE_CONTAINER');
1943
	print '</td><td>';
1944
	$arrayoftype=array('page'=>$langs->trans("Page"), 'banner'=>$langs->trans("Banner"), 'blogpost'=>$langs->trans("BlogPost"), 'other'=>$langs->trans("Other"));
1945
	print $form->selectarray('WEBSITE_TYPE_CONTAINER', $arrayoftype, $type_container);
1946
	print '</td></tr>';
1947
1948
	print '<tr><td class="titlefieldcreate fieldrequired">';
1949
	print $langs->trans('WEBSITE_PAGENAME');
1950
	print '</td><td>';
1951
	print '<input type="text" class="flat maxwidth300" name="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
1952
	print '</td></tr>';
1953
1954
	print '<tr><td class="fieldrequired">';
1955
	print $langs->trans('WEBSITE_TITLE');
1956
	print '</td><td>';
1957
	print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'">';
1958
	print '</td></tr>';
1959
1960
	print '<tr><td>';
1961
	print $langs->trans('WEBSITE_DESCRIPTION');
1962
	print '</td><td>';
1963
	print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($pagedescription).'">';
1964
	print '</td></tr>';
1965
1966
	print '<tr><td>';
1967
	print $langs->trans('WEBSITE_KEYWORDS');
1968
	print '</td><td>';
1969
	print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($pagekeywords).'">';
1970
	print '</td></tr>';
1971
1972
	print '<tr><td>';
1973
	print $langs->trans('Language');
1974
	print '</td><td>';
1975
	print $formadmin->select_language($pagelang?$pagelang:$langs->defaultlang, 'WEBSITE_LANG', 0, null, '1');
1976
	print '</td></tr>';
1977
1978
	print '<tr><td class="tdhtmlheader tdtop">';
1979
	$htmlhelp=$langs->trans("EditTheWebSiteForACommonHeader").'<br><br>';
1980
	$htmlhelp.=$langs->trans("Example").' :<br>';
1981
	$htmlhelp.='&lt;script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous" &gt;&lt;/script&gt;<br>';
1982
	$htmlhelp.='&lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=" crossorigin="anonymous" &gt;&lt;/script&gt;<br>';
1983
	$htmlhelp.='&lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /&gt;<br>';
1984
	print $form->textwithpicto($langs->trans('HtmlHeaderPage'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
1985
	print '</td><td>';
1986
	$doleditor=new DolEditor('htmlheader', $pagehtmlheader, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1987
	print $doleditor->Create(1, '', true, 'HTML Header', 'html');
1988
	print '</td></tr>';
1989
1990
	print '</table>';
1991
1992
	if ($action == 'createcontainer')
1993
	{
1994
		print '<div class="center">';
1995
1996
		print '<input class="button" type="submit" name="addcontainer" value="'.$langs->trans("Create").'">';
1997
		print '<input class="button" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
1998
1999
		print '</div>';
2000
	}
2001
2002
2003
	//print '</div>';
2004
2005
	//dol_fiche_end();
2006
2007
	print '</div>';
2008
2009
	print '<br>';
2010
}
2011
2012
if ($action == 'editfile' || $action == 'file_manager')
2013
{
2014
	print '<!-- Edit Media -->'."\n";
2015
	print '<div class="fiche"><br><br>';
2016
	//print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
2017
2018
	$module = 'medias';
2019
	if (empty($url)) $url=DOL_URL_ROOT.'/website/index.php';	// Must be an url without param
2020
	include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php';
2021
2022
	print '</div>';
2023
}
2024
2025
if ($action == 'editmenu')
2026
{
2027
	print '<!-- Edit Menu -->'."\n";
2028
	print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
2029
}
2030
2031
if ($action == 'editsource')
2032
{
2033
	/*
2034
	 * Editing with source editor
2035
	 */
2036
2037
	$contentforedit = '';
2038
	/*$contentforedit.='<style scoped>'."\n";        // "scoped" means "apply to parent element only". Not yet supported by browsers
2039
	 $contentforedit.=$csscontent;
2040
	 $contentforedit.='</style>'."\n";*/
2041
	$contentforedit .= $objectpage->content;
2042
2043
	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
2044
	$doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,'ace',ROWS_5,'90%');
2045
	$doleditor->Create(0, '', false, 'HTML Source', 'php');
2046
}
2047
2048
if ($action == 'editcontent')
2049
{
2050
	/*
2051
     * Editing with default ckeditor
2052
     */
2053
2054
	$contentforedit = '';
2055
	/*$contentforedit.='<style scoped>'."\n";        // "scoped" means "apply to parent element only". Not yet supported by browsers
2056
    $contentforedit.=$csscontent;
2057
    $contentforedit.='</style>'."\n";*/
2058
	$contentforedit .= $objectpage->content;
2059
2060
	$contentforedit = preg_replace('/(<img.*src=")(?!http)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $contentforedit, -1, $nbrep);
2061
2062
	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
2063
	$doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%');
2064
	$doleditor->Create(0, '', false);
2065
}
2066
2067
print "</div>\n</form>\n";
2068
2069
2070
2071
if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
2072
{
2073
	if ($pageid > 0)
2074
	{
2075
		// Ouput page under the Dolibarr top menu
2076
		$objectpage->fetch($pageid);
2077
		$csscontent = @file_get_contents($filecss);
2078
		$jscontent = @file_get_contents($filejs);
2079
2080
		$out = '<!-- Page content '.$filetpl.' : Div with (CSS Of website from file + Style/htmlheader of page from database + Page content from database) -->'."\n";
2081
2082
		$out.='<div id="websitecontentundertopmenu" class="websitecontentundertopmenu">'."\n";
2083
		// TODO Use contenteditable="true" / document.getElementById("myP").contentEditable="true" for part coming from CKEditor
2084
2085
2086
		// REPLACEMENT OF LINKS When page called by website editor
2087
2088
		$out.='<style scoped>'."\n";        // "scoped" means "apply to parent element only". No more supported by browsers, snif !
2089
		$tmpout='';
2090
		$tmpout.= '/* Include website CSS file */'."\n";
2091
		$tmpout.= dolWebsiteReplacementOfLinks($object, $csscontent, 1);
2092
		$tmpout.= '/* Include style from the HTML header of page */'."\n";
2093
		// Clean the html header of page to get only <style> content
2094
		$tmp = preg_split('(<style[^>]*>|</style>)', $objectpage->htmlheader);
2095
		$tmpstyleinheader ='';
2096
		$i=0;
2097
		foreach($tmp as $valtmp)
2098
		{
2099
			$i++;
2100
			if ($i % 2 == 0) $tmpstyleinheader.=$valtmp."\n";
2101
		}
2102
		$tmpout.= $tmpstyleinheader."\n";
2103
		// Clean style that may affect global style of Dolibarr
2104
		$tmpout=preg_replace('/}[\s\n]*body\s*{[^}]+}/ims','}',$tmpout);
2105
		$out.=$tmpout;
2106
		$out.='</style>'."\n";
2107
2108
		// Do not enable the contenteditable when page was grabbed, ckeditor is removing span and adding borders,
2109
		// so editable will be available from container created from scratch
2110
		//$out.='<div id="bodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
2111
		$out.='<div id="bodywebsite" class="bodywebsite">'."\n";
2112
2113
		$out.=dolWebsiteReplacementOfLinks($object, $objectpage->content)."\n";
2114
2115
		$out.='</div>';
2116
2117
		$out.='</div> <!-- End div id=websitecontentundertopmenu -->';
2118
2119
		$out.= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";
2120
2121
		// For jqueryscoped (does not work as expected)
2122
		//$out.="<script>$.scoped();</script>";
2123
2124
		print $out;
2125
2126
		/*file_put_contents($filetpl, $out);
2127
        if (! empty($conf->global->MAIN_UMASK))
2128
            @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
2129
2130
        // Output file on browser
2131
        dol_syslog("index.php include $filetpl $filename content-type=$type");
2132
        $original_file_osencoded=dol_osencode($filetpl);	// New file name encoded in OS encoding charset
2133
2134
        // This test if file exists should be useless. We keep it to find bug more easily
2135
        if (! file_exists($original_file_osencoded))
2136
        {
2137
            dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
2138
            exit;
2139
        }
2140
2141
        //include_once $original_file_osencoded;
2142
        */
2143
2144
		/*print '<iframe class="websiteiframenoborder centpercent" src="'.DOL_URL_ROOT.'/public/website/index.php?website='.$website.'&pageid='.$pageid.'"/>';
2145
        print '</iframe>';*/
2146
	}
2147
	else
2148
	{
2149
		print '<br><br><div class="center">'.$langs->trans("PreviewOfSiteNotYetAvailable", $website).'</center><br><br><br>';
2150
		print '<div class="center"><div class="logo_setup"></div></div>';
2151
	}
2152
}
2153
2154
2155
2156
llxFooter();
2157
2158
$db->close();
2159