Completed
Branch develop (2c126c)
by Laurent
24:08
created

index.php ➔ dolSavePageContent()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 55
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 43
nc 8
nop 3
dl 0
loc 55
rs 9.078
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
28
/**
29
 *	Show HTML header HTML + BODY + Top menu + left menu + DIV
30
 *
31
 * @param 	string 	$head				Optionnal head lines
32
 * @param 	string 	$title				HTML title
33
 * @param	string	$help_url			Url links to help page
34
 * 		                            	Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
35
 *                                  	For other external page: http://server/url
36
 * @param	string	$target				Target to use on links
37
 * @param 	int    	$disablejs			More content into html header
38
 * @param 	int    	$disablehead		More content into html header
39
 * @param 	array  	$arrayofjs			Array of complementary js files
40
 * @param 	array  	$arrayofcss			Array of complementary css files
41
 * @param	string	$morequerystring	Query string to add to the link "print" to get same parameters (set this only if autodetect fails)
42
 * @return	void
43
 */
44
function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='')
0 ignored issues
show
Best Practice introduced by
The function llxHeader() has been defined more than once; this definition is ignored, only the first definition in htdocs/asterisk/wrapper.php (L46-52) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
45
{
46
    global $conf;
47
48
    // html header
49
    top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
50
51
    print '<body id="mainbody">';
52
53
    // top menu and left menu area
54
    if (empty($conf->dol_hide_topmenu))
55
    {
56
        top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url);
57
    }
58
    if (empty($conf->dol_hide_leftmenu))
59
    {
60
        left_menu('', $help_url, '', '', 1, $title, 1);
61
    }
62
63
    // main area
64
    //main_area($title);
65
    print '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">'."\n";
66
}
67
68
69
require '../main.inc.php';
70
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
71
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
72
require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
73
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
74
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
75
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
76
require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php';
77
require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php';
78
79
$langs->load("admin");
80
$langs->load("other");
81
$langs->load("website");
82
83
if (! $user->admin) accessforbidden();
84
85
if (! ((GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)))
86
{
87
    $conf->dol_hide_leftmenu = 1;   // Force hide of left menu.
88
}
89
90
$error=0;
91
$website=GETPOST('website', 'alpha');
92
$page=GETPOST('page', 'alpha');
93
$pageid=GETPOST('pageid', 'int');
94
$pageref=GETPOST('pageref', 'aZ09');
95
$action=GETPOST('action','alpha');
96
97
98
if (GETPOST('delete')) { $action='delete'; }
99
if (GETPOST('preview')) $action='preview';
100
if (GETPOST('createsite')) { $action='createsite'; }
101
if (GETPOST('create')) { $action='create'; }
102
if (GETPOST('editmedias')) { $action='editmedias'; }
103
if (GETPOST('editcss')) { $action='editcss'; }
104
if (GETPOST('editmenu')) { $action='editmenu'; }
105
if (GETPOST('setashome')) { $action='setashome'; }
106
if (GETPOST('editmeta')) { $action='editmeta'; }
107
if (GETPOST('editsource')) { $action='editsource'; }
108
if (GETPOST('editcontent')) { $action='editcontent'; }
109
if (GETPOST('createfromclone')) { $action='createfromclone'; }
110
if (GETPOST('createpagefromclone')) { $action='createpagefromclone'; }
111
112
if (empty($action)) $action='preview';
113
114
$object=new Website($db);
115
$objectpage=new WebsitePage($db);
116
117
$object->fetchAll();    // Init $object->records
118
119
// If website not defined, we take first found
120
if (empty($website))
121
{
122
    foreach($object->records as $key => $valwebsite)
123
    {
124
        $website=$valwebsite->ref;
125
        break;
126
    }
127
}
128
if ($website)
129
{
130
    $res = $object->fetch(0, $website);
131
}
132
133
if ($pageid < 0) $pageid = 0;
134
if (($pageid > 0 || $pageref) && $action != 'add')
135
{
136
	$res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
137
    $pageid = $objectpage->id;
138
}
139
140
global $dolibarr_main_data_root;
141
$pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website;
142
$filehtmlheader=$pathofwebsite.'/htmlheader.html';
143
$filecss=$pathofwebsite.'/styles.css.php';
144
$filejs=$pathofwebsite.'/javascript.js.php';
145
$filerobot=$pathofwebsite.'/robots.txt';
146
$filehtaccess=$pathofwebsite.'/.htaccess';
147
$filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php';
148
$fileindex=$pathofwebsite.'/index.php';
149
150
// Define $urlwithroot
151
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
152
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
153
//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
154
155
156
157
/*
158
 * Actions
159
 */
160
161
if (GETPOST('refreshsite'))		// If we change the site, we reset the pageid and cancel addsite action.
162
{
163
	$pageid=0;
164
	if ($action == 'addsite') $action = 'preview';
165
}
166
if (GETPOST('refreshpage') && ! in_array($action, array('updatecss'))) $action='preview';
167
168
169
// Add site
170
if ($action == 'addsite')
171
{
172
	$db->begin();
173
174
	if (! $error && ! GETPOST('WEBSITE_REF','alpha'))
175
	{
176
		$error++;
177
		setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
178
	}
179
	if (! $error && ! preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF','alpha')))
180
	{
181
		$error++;
182
		setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors');
183
	}
184
185
	if (! $error)
186
	{
187
		$tmpobject=new Website($db);
188
		$tmpobject->ref = GETPOST('WEBSITE_REF','alpha');
189
		$tmpobject->description = GETPOST('WEBSITE_DESCRIPTION','alpha');
190
		$tmpobject->virtualhost = GETPOST('WEBSITE_VIRTUALHOST','alpha');
191
192
		$result = $tmpobject->create($user);
193
		if ($result <= 0)
194
		{
195
			$error++;
196
			setEventMessages($tmpobject->error, $tmpobject->errors, 'errors');
197
		}
198
	}
199
200
	if (! $error)
201
	{
202
		$db->commit();
203
		setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs');
204
		$action='';
205
206
		header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref);
207
		exit;
208
	}
209
	else
210
	{
211
		$db->rollback();
212
		$action='createsite';
213
	}
214
215
	if (! $error)
216
	{
217
		$action = 'preview';
218
		$id = $object->id;
219
	}
220
}
221
222
// Add page
223
if ($action == 'add')
224
{
225
    $db->begin();
226
227
    $objectpage->fk_website = $object->id;
228
    if (GETPOST('fetchexternalurl','alpha'))
229
    {
230
    	$urltograb=GETPOST('externalurl','alpha');
231
    }
232
233
    if ($urltograb)
234
    {
235
    	// Clean url to grab, so url can be
236
    	// http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
237
    	$urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
238
    	$urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
239
		if (empty($urltograbwithoutdomainandparam) && ! preg_match('/\/$/', $urltograb))
240
		{
241
			$urltograb.='/';
242
		}
243
		$urltograbdirwithoutslash = dirname($urltograb.'.');
244
245
    	include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
246
247
    	$tmp = getURLContent($urltograb);
248
    	if ($tmp['curl_error_no'])
249
    	{
250
    		$error++;
251
    		setEventMessages($tmp['curl_error_msg'], null, 'errors');
252
    		$action='create';
253
    	}
254
    	else
255
    	{
256
    		preg_match('/<head>(.*)<\/head>/is', $tmp['content'], $reg);
257
    		$head = $reg[1];
258
259
   			$objectpage->pageurl = dol_sanitizeFileName(preg_replace('/[\/\.]/','-',$urltograbwithoutdomainandparam));
1 ignored issue
show
Bug introduced by
It seems like preg_replace('/[\\/\\.]/...bwithoutdomainandparam) targeting preg_replace() can also be of type array<integer,string>; however, dol_sanitizeFileName() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
260
   			if (empty($objectpage->pageurl))
261
   			{
262
   				$tmpdomain = getDomainFromURL($urltograb);
263
   				$objectpage->pageurl=$tmpdomain.'-home';
264
   			}
265
266
    		if (preg_match('/<title>(.*)<\/title>/ims', $head, $regtmp))
267
    		{
268
    			$objectpage->title = $regtmp[1];
269
    		}
270
    		if (preg_match('/<meta name="description"[^"]+content="([^"]+)"/ims', $head, $regtmp))
271
    		{
272
    			$objectpage->description = $regtmp[1];
273
    		}
274
    		if (preg_match('/<meta name="keywords"[^"]+content="([^"]+)"/ims', $head, $regtmp))
275
    		{
276
    			$objectpage->keywords = $regtmp[1];
277
    		}
278
    		if (preg_match('/<html\s+lang="([^"]+)"/ims', $tmp['content'], $regtmp))
279
    		{
280
    			$tmplang=explode('-', $regtmp[1]);
281
    			$objectpage->lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : '');
282
    		}
283
284
    		$objectpage->content = $tmp['content'];
285
    		$objectpage->content = preg_replace('/^.*<body[^>]*>/ims', '', $objectpage->content);
286
    		$objectpage->content = preg_replace('/<\/body[^>]*>.*$/ims', '', $objectpage->content);
287
288
289
    		// Now loop to fetch all css files. Include them inline into header of page
290
    		$objectpage->htmlheader = $tmp['content'];
291
    		$objectpage->htmlheader = preg_replace('/^.*<head[^>]*>/ims', '', $objectpage->htmlheader);
292
    		$objectpage->htmlheader = preg_replace('/<\/head[^>]*>.*$/ims', '', $objectpage->htmlheader);
293
    		$objectpage->htmlheader = preg_replace('/<base[^>]*>\n*/ims', '', $objectpage->htmlheader);
294
    		$objectpage->htmlheader = preg_replace('/<meta name="robot[^>]*>\n*/ims', '', $objectpage->htmlheader);
295
    		$objectpage->htmlheader = preg_replace('/<meta name="keywords[^>]*>\n*/ims', '', $objectpage->htmlheader);
296
    		$objectpage->htmlheader = preg_replace('/<meta name="title[^>]*>\n*/ims', '', $objectpage->htmlheader);
297
    		$objectpage->htmlheader = preg_replace('/<meta name="description[^>]*>\n*/ims', '', $objectpage->htmlheader);
298
    		$objectpage->htmlheader = preg_replace('/<meta name="generator[^>]*>\n*/ims', '', $objectpage->htmlheader);
299
    		//$objectpage->htmlheader = preg_replace('/<meta name="verify-v1[^>]*>\n*/ims', '', $objectpage->htmlheader);
300
    		//$objectpage->htmlheader = preg_replace('/<meta name="msvalidate.01[^>]*>\n*/ims', '', $objectpage->htmlheader);
301
    		$objectpage->htmlheader = preg_replace('/<title>[^<]*<\/title>\n*/ims', '', $objectpage->htmlheader);
302
    		$objectpage->htmlheader = preg_replace('/<link[^>]*rel="shortcut[^>]*>\n/ims', '', $objectpage->htmlheader);
303
304
    		// Now loop to fetch JS
305
    		$tmp = $objectpage->htmlheader;
306
307
    		preg_match_all('/<script([^\.]+)src="([^>"]+)"([^>]*)><\/script>/i', $objectpage->htmlheader, $regs);
308
    		foreach ($regs[0] as $key => $val)
309
    		{
310
    			$urltograbbis = $urltograbdirwithoutslash.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
311
312
    			$linkwithoutdomain = $regs[2][$key];
313
    			//$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
314
    			if (preg_match('/^http/', $regs[2][$key]))
315
    			{
316
    				$urltograbbis = $regs[2][$key];
317
    				$linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
318
    				//$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
319
    			}
320
				/*
321
    			$tmpgeturl = getURLContent($urltograbbis);
322
    			if ($tmpgeturl['curl_error_no'])
323
    			{
324
    				$error++;
325
    				setEventMessages($tmpgeturl['curl_error_msg'], null, 'errors');
326
    				$action='create';
327
    			}
328
    			else
329
    			{
330
    				dol_mkdir(dirname($filetosave));
331
332
    				$fp = fopen($filetosave, "w");
333
    				fputs($fp, $tmpgeturl['content']);
334
    				fclose($fp);
335
    				if (! empty($conf->global->MAIN_UMASK))
336
    					@chmod($file, octdec($conf->global->MAIN_UMASK));
337
    			}
338
339
    			$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
340
    			*/
341
    			$tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', '', $tmp);
342
    		}
343
    		$objectpage->htmlheader = trim($tmp);
344
345
346
    		// Now loop to fetch CSS
347
    		$pagecsscontent = "\n".'<style>'."\n";
348
349
    		preg_match_all('/<link([^\.]+)href="([^>"]+\.css)"([^>]*)>/i', $objectpage->htmlheader, $regs);
350
			foreach ($regs[0] as $key => $val)
351
    		{
352
    			$urltograbbis = $urltograbdirwithoutslash.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
353
    			$linkwithoutdomain = $regs[2][$key];
354
    			//$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
355
    			if (preg_match('/^http/', $regs[2][$key]))
356
    			{
357
    				$urltograbbis = $regs[2][$key];
358
    				$linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
359
    				//$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
360
    			}
361
362
    			$tmpgeturl = getURLContent($urltograbbis);
363
    			if ($tmpgeturl['curl_error_no'])
364
    			{
365
    				$error++;
366
    				setEventMessages($tmpgeturl['curl_error_msg'], null, 'errors');
367
    				$action='create';
368
    			}
369
    			else
370
    			{
371
    			 //dol_mkdir(dirname($filetosave));
372
373
    			 //$fp = fopen($filetosave, "w");
374
    			 //fputs($fp, $tmpgeturl['content']);
375
    			 //fclose($fp);
376
    			 //if (! empty($conf->global->MAIN_UMASK))
377
    			 //	@chmod($file, octdec($conf->global->MAIN_UMASK));
378
    			 }
379
380
    			 //	$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
381
    			 $pagecsscontent.='/* Content of file '.$urltograbbis.' */'."\n";
382
383
    			 getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1);
384
385
    			 $pagecsscontent.=$tmpgeturl['content']."\n";
386
387
    			 $objectpage->htmlheader = preg_replace('/'.preg_quote($regs[0][$key],'/').'\n*/ims', '', $objectpage->htmlheader);
388
    		}
389
390
    		$pagecsscontent.='</style>'."\n";
391
			//var_dump($pagecsscontent);
392
393
    		//print dol_escape_htmltag($tmp);exit;
394
    		$objectpage->htmlheader .= $pagecsscontent;
395
396
397
    		// Now loop to fetch all images
398
    		$tmp = $objectpage->content;
399
400
    		getAllImages($object, $objectpage, $urltograb, $tmp, $action, 1);
401
402
			//print dol_escape_htmltag($tmp);exit;
403
			$objectpage->content = $tmp;
404
405
    		$objectpage->grabbed_from = $urltograb;
406
    	}
407
    }
408
    else
409
    {
410
	    $objectpage->title = GETPOST('WEBSITE_TITLE','alpha');
411
	    $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME','alpha');
412
	    $objectpage->description = GETPOST('WEBSITE_DESCRIPTION','alpha');
413
	    $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS','alpha');
414
	    $objectpage->lang = GETPOST('WEBSITE_LANG','aZ09');
415
	    $objectpage->htmlheader = GETPOST('htmlheader','none');
416
    }
417
418
    if (! $error)
419
    {
420
	    if (empty($objectpage->pageurl))
421
	    {
422
	        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
423
	        $error++;
424
	        $action='create';
425
	    }
426
	    else if (! preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl))
427
	    {
428
	    	setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
429
	    	$error++;
430
	    	$action='create';
431
	    }
432
	    if (empty($objectpage->title))
433
	    {
434
	        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors');
435
	        $error++;
436
	        $action='create';
437
	    }
438
    }
439
440
    if (! $error)
441
    {
442
        $res = $objectpage->create($user);
443
        if ($res <= 0)
444
        {
445
            $error++;
446
            setEventMessages($objectpage->error, $objectpage->errors, 'errors');
447
        }
448
    }
449
    if (! $error)
450
    {
451
    	if (! empty($objectpage->content))
452
    	{
453
			$filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
454
			$filetpl=$pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
455
456
    		// Save page alias
457
    		$result=dolSavePageAlias($filealias, $object, $objectpage);
458
    		if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
459
460
    		// Save page of content
461
    		$result=dolSavePageContent($filetpl, $object, $objectpage);
462
    		if ($result)
463
    		{
464
    			setEventMessages($langs->trans("Saved"), null, 'mesgs');
465
    			//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
466
    			//exit;
467
    		}
468
    		else
469
    		{
470
    			setEventMessages('Failed to write file '.$filetpl, null, 'errors');
471
    			//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
472
    			//exit;
473
    		}
474
    	}
475
    }
476
	if (! $error)
477
	{
478
		$db->commit();
479
	    setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
480
	    $action='';
481
	}
482
	else
483
	{
484
		$db->rollback();
485
	}
486
487
	if (! $error)
488
	{
489
		$pageid = $objectpage->id;
490
491
		// To generate the CSS, robot and htmlheader file.
492
493
		if (! dol_is_file($filehtmlheader))
494
		{
495
			$htmlheadercontent = "<!-- HTML header content (common for all pages) -->";
496
			$result=dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
497
		}
498
499
		if (! dol_is_file($filecss))
500
		{
501
			$csscontent = "/* CSS content (all pages) */\nbody.bodywebsite { margin: 0; }";
502
			$result=dolSaveCssFile($filecss, $csscontent);
503
		}
504
505
		if (! dol_is_file($filejs))
506
		{
507
			$jscontent = "/* JS content (all pages) */\n";
508
			$result=dolSaveJsFile($filejs, $jscontent);
509
		}
510
511
		if (! dol_is_file($filerobot))
512
		{
513
			$robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
514
			$result=dolSaveRobotFile($filerobot, $robotcontent);
515
		}
516
517
		if (! dol_is_file($filehtaccess))
518
		{
519
			$htaccesscontent = "# Order allow,deny\n# Deny from all";
520
			$result=dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
521
		}
522
523
		$action = 'preview';
524
	}
525
}
526
527
// Delete page
528
if ($action == 'delete')
529
{
530
    $db->begin();
531
532
    $res = $object->fetch(0, $website);
533
534
    $res = $objectpage->fetch($pageid, $object->fk_website);
535
536
    if ($res > 0)
537
    {
538
        $res = $objectpage->delete($user);
539
        if (! $res > 0)
540
        {
541
            $error++;
542
            setEventMessages($objectpage->error, $objectpage->errors, 'errors');
543
        }
544
545
        if (! $error)
546
        {
547
            $db->commit();
548
            setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
549
550
            header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
551
            exit;
552
        }
553
        else
554
        {
555
            $db->rollback();
556
        }
557
    }
558
    else
559
    {
560
        dol_print_error($db);
561
    }
562
}
563
564
// Update css
565
if ($action == 'updatecss')
566
{
567
	if (GETPOST('refreshsite') || GETPOST('refreshpage'))		// If we tried to reload another site/page, we stay on editcss mode.
568
	{
569
		$action='editcss';
570
	}
571
	else
572
	{
573
	    $res = $object->fetch(0, $website);
574
575
	    // Html header file
576
	    $htmlheadercontent ='';
577
578
	    /* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
579
	    $htmlheadercontent.= "<?php // BEGIN PHP\n";
580
	    $htmlheadercontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
581
	    $htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
582
	    $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
583
	    $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
584
	    $htmlheadercontent.= "ob_start();\n";
585
	    // $htmlheadercontent.= "header('Content-type: text/html');\n";		// Not required. htmlheader.html is never call as a standalone page
586
	    $htmlheadercontent.= "// END PHP ?>\n";*/
587
588
	    $htmlheadercontent.= preg_replace(array('/<html>\n*/ims','/<\/html>\n*/ims'),array('',''),GETPOST('WEBSITE_HTML_HEADER', 'none'));
589
590
	    /*$htmlheadercontent.= "\n".'<?php // BEGIN PHP'."\n";
591
	    $htmlheadercontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
592
	    $htmlheadercontent.= "// END PHP ?>"."\n";*/
593
594
	    $htmlheadercontent = trim($htmlheadercontent)."\n";
595
596
	    dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
597
598
599
	    // Css file
600
	    $csscontent ='';
601
602
	    $csscontent.= "<?php // BEGIN PHP\n";
603
	    $csscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
604
	    $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.
605
	    $csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
606
	    $csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
607
	    $csscontent.= "ob_start();\n";
608
	    $csscontent.= "header('Content-type: text/css');\n";
609
	    $csscontent.= "// END PHP ?>\n";
610
611
	    $csscontent.= GETPOST('WEBSITE_CSS_INLINE', 'none');
612
613
	    $csscontent.= "\n".'<?php // BEGIN PHP'."\n";
614
	    $csscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
615
	    $csscontent.= "// END PHP ?>"."\n";
616
617
	    dol_syslog("Save css content into ".$filecss);
618
619
	    dol_mkdir($pathofwebsite);
620
	    $result = file_put_contents($filecss, $csscontent);
621
	    if (! empty($conf->global->MAIN_UMASK))
622
	        @chmod($filecss, octdec($conf->global->MAIN_UMASK));
623
624
	    if (! $result)
625
	    {
626
	        $error++;
627
	        setEventMessages('Failed to write file '.$filecss, null, 'errors');
628
	    }
629
630
631
		// Js file
632
	    $jscontent ='';
633
634
	    $jscontent.= "<?php // BEGIN PHP\n";
635
	    $jscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
636
	    $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.
637
	    $jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
638
	    $jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
639
	    $jscontent.= "ob_start();\n";
640
	    $jscontent.= "header('Content-type: application/javascript');\n";
641
	    $jscontent.= "// END PHP ?>\n";
642
643
	    $jscontent.= GETPOST('WEBSITE_JS_INLINE', 'none');
644
645
	    $jscontent.= "\n".'<?php // BEGIN PHP'."\n";
646
	    $jscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
647
	    $jscontent.= "// END PHP ?>"."\n";
648
649
	    dol_syslog("Save js content into ".$filejs);
650
651
	    dol_mkdir($pathofwebsite);
652
	    $result = file_put_contents($filejs, $jscontent);
653
	    if (! empty($conf->global->MAIN_UMASK))
654
	        @chmod($filejs, octdec($conf->global->MAIN_UMASK));
655
656
	    if (! $result)
657
	    {
658
	        $error++;
659
	        setEventMessages('Failed to write file '.$filejs, null, 'errors');
660
	    }
661
662
663
	    // Robot file
664
	    $robotcontent ='';
665
666
	    /*$robotcontent.= "<?php // BEGIN PHP\n";
667
	    $robotcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
668
	    $robotcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
669
	    $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
670
	    $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
671
	    $robotcontent.= "ob_start();\n";
672
	    $robotcontent.= "header('Content-type: text/css');\n";
673
	    $robotcontent.= "// END PHP ?>\n";*/
674
675
	    $robotcontent.= GETPOST('WEBSITE_ROBOT', 'none');
676
677
	    /*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
678
	    $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
679
	    $robotcontent.= "// END PHP ?>"."\n";*/
680
681
	    dol_syslog("Save file robot into ".$filerobot);
682
683
	    dol_mkdir($pathofwebsite);
684
	    $result = file_put_contents($filerobot, $robotcontent);
685
	    if (! empty($conf->global->MAIN_UMASK))
686
	    	@chmod($filerobot, octdec($conf->global->MAIN_UMASK));
687
688
    	if (! $result)
689
    	{
690
    		$error++;
691
    		setEventMessages('Failed to write file '.$filerobot, null, 'errors');
692
    	}
693
694
695
    	// Css file
696
    	$htaccesscontent ='';
697
698
    	/*$robotcontent.= "<?php // BEGIN PHP\n";
699
    	 $robotcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
700
    	 $robotcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
701
    	 $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
702
    	 $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
703
    	 $robotcontent.= "ob_start();\n";
704
    	 $robotcontent.= "header('Content-type: text/css');\n";
705
    	 $robotcontent.= "// END PHP ?>\n";*/
706
707
    	$htaccesscontent.= GETPOST('WEBSITE_HTACCESS', 'none');
708
709
    	/*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
710
    	 $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
711
    	 $robotcontent.= "// END PHP ?>"."\n";*/
712
713
    	dol_syslog("Save file htaccess into ".$filehtaccess);
714
715
    	dol_mkdir($pathofwebsite);
716
    	$result = file_put_contents($filehtaccess, $htaccesscontent);
717
    	if (! empty($conf->global->MAIN_UMASK))
718
    		@chmod($filehtaccess, octdec($conf->global->MAIN_UMASK));
719
720
   		if (! $result)
721
   		{
722
   			$error++;
723
   			setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
724
   		}
725
726
		// Message if no error
727
	    if (! $error)
728
	    {
729
	        setEventMessages($langs->trans("Saved"), null, 'mesgs');
730
	    }
731
732
	    $action='preview';
733
	}
734
}
735
736
// Update page
737
if ($action == 'setashome')
738
{
739
    $db->begin();
740
    $object->fetch(0, $website);
741
742
    $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...
743
    $res = $object->update($user);
744
    if (! $res > 0)
745
    {
746
        $error++;
747
        setEventMessages($object->error, $object->errors, 'errors');
748
    }
749
750
    if (! $error)
751
    {
752
        $db->commit();
753
754
        // Generate the index.php page to be the home page
755
        //-------------------------------------------------
756
        dol_mkdir($pathofwebsite);
757
        dol_delete_file($fileindex);
758
759
        $indexcontent = '<?php'."\n";
760
        $indexcontent.= '// File generated to provide a shortcut to the Home Page - DO NOT MODIFY - It is just an include.'."\n";
761
        $indexcontent.= "include_once './".basename($filetpl)."'\n";
762
        $indexcontent.= '?>'."\n";
763
        $result = file_put_contents($fileindex, $indexcontent);
764
        if (! empty($conf->global->MAIN_UMASK))
765
            @chmod($fileindex, octdec($conf->global->MAIN_UMASK));
766
767
        if ($result) setEventMessages($langs->trans("Saved"), null, 'mesgs');
768
        else setEventMessages('Failed to write file '.$fileindex, null, 'errors');
769
770
        $action='preview';
771
    }
772
    else
773
    {
774
        $db->rollback();
775
    }
776
}
777
778
// Update page (meta)
779
if ($action == 'updatemeta')
780
{
781
    $db->begin();
782
    $object->fetch(0, $website);
783
784
    $objectpage->fk_website = $object->id;
785
786
	// Check parameters
787
    if (! preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl))
788
    {
789
    	$error++;
790
    	setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
791
    	$action='editmeta';
792
    }
793
794
    $res = $objectpage->fetch($pageid, $object->fk_website);
795
    if ($res <= 0)
796
    {
797
    	$error++;
798
        dol_print_error($db, 'Page not found');
799
    }
800
801
    if (! $error)
802
    {
803
        $objectpage->old_object = clone $objectpage;
804
805
        $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
806
        $objectpage->title = GETPOST('WEBSITE_TITLE', 'alpha');
807
        $objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
808
        $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alpha');
809
        $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
810
        $objectpage->htmlheader = GETPOST('htmlheader', 'none');
811
812
        $res = $objectpage->update($user);
813
        if (! $res > 0)
814
        {
815
            $error++;
816
            setEventMessages($objectpage->error, $objectpage->errors, 'errors');
817
        }
818
819
        if (! $error)
820
        {
821
            $db->commit();
822
823
            $filemaster=$pathofwebsite.'/master.inc.php';
824
            $fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
825
            $filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
826
827
            dol_mkdir($pathofwebsite);
828
829
830
            // Now generate the master.inc.php page
831
            dol_syslog("We regenerate the master file (because we update meta)");
832
            dol_delete_file($filemaster);
833
834
            $mastercontent = '<?php'."\n";
835
            $mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n";
836
            $mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
837
            //$mastercontent.= "include_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php';"."\n";
838
            //$mastercontent.= '$website = new WebSite($db)'."\n";
839
            $mastercontent.= '?>'."\n";
840
            $result = file_put_contents($filemaster, $mastercontent);
841
            if (! empty($conf->global->MAIN_UMASK))
842
                @chmod($filemaster, octdec($conf->global->MAIN_UMASK));
843
844
            if (! $result) setEventMessages('Failed to write file '.$filemaster, null, 'errors');
845
846
847
            // Now generate the alias.php page
848
            if (! empty($fileoldalias))
849
            {
850
                dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
851
                dol_delete_file($fileoldalias);
852
            }
853
854
            // Save page alias
855
            $result=dolSavePageAlias($filealias, $object, $objectpage);
856
            if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
857
858
			// Save page of content
859
            $result=dolSavePageContent($filetpl, $object, $objectpage);
860
            if ($result)
861
            {
862
                setEventMessages($langs->trans("Saved"), null, 'mesgs');
863
                //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
864
                //exit;
865
            }
866
            else
867
            {
868
            	setEventMessages('Failed to write file '.$filetpl, null, 'errors');
869
        	    //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
870
       	        //exit;
871
            }
872
873
            $action='preview';
874
        }
875
        else
876
        {
877
            $db->rollback();
878
        }
879
    }
880
}
881
882
// Update page
883
if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createfromclone' || $action == 'confirm_createpagefromclone')
884
	|| ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))
885
{
886
    $object->fetch(0, $website);
887
888
	if ($action == 'confirm_createfromclone')
889
	{
890
		$objectnew = new Website($db);
891
		$result = $objectnew->createFromClone($user, GETPOST('id','int'), GETPOST('siteref','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''));
892
		if ($result < 0)
893
		{
894
			$error++;
895
			setEventMessages($objectnew->error, $objectnew->errors, 'errors');
896
			$action='preview';
897
		}
898
		else
899
		{
900
			$object = $objectnew;
901
			$id = $object->id;
902
			$pageid = $object->fk_default_home;
903
		}
904
	}
905
906
	if ($action == 'confirm_createpagefromclone')
907
	{
908
		$istranslation=(GETPOST('is_a_translation','aZ09')=='on'?1:0);
909
		if ($istranslation)
910
		{
911
			if (GETPOST('newlang','aZ09') == $objectpage->lang)
912
			{
913
				$error++;
914
				setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
915
				$action='preview';
916
			}
917
		}
918
919
		if (! $error)
920
		{
921
	    	$objectpage = new WebsitePage($db);
922
			$result = $objectpage->createFromClone($user, $pageid, GETPOST('pageurl','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''), $istranslation, GETPOST('newwebsite','int'));
923
			if ($result < 0)
924
			{
925
				$error++;
926
				setEventMessages($objectpage->error, $objectpage->errors, 'errors');
927
				$action='createpagefromclone';
928
			}
929
		}
930
    }
931
932
    $res = 0;
933
934
    if (! $error)
935
    {
936
	    // Check symlink to medias and restore it if ko
937
	    $pathtomedias=DOL_DATA_ROOT.'/medias';
938
	    $pathtomediasinwebsite=$pathofwebsite.'/medias';
939
	    if (! is_link(dol_osencode($pathtomediasinwebsite)))
940
	    {
941
	        dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
942
	        dol_mkdir(dirname($pathtomediasinwebsite));     // To be sure dir for website exists
943
	        $result = symlink($pathtomedias, $pathtomediasinwebsite);
944
	    }
945
946
	    /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
947
	    {
948
	        $object->virtualhost = GETPOST('previewsite', 'alpha');
949
	        $object->update($user);
950
	    }*/
951
952
	    $objectpage->fk_website = $object->id;
953
954
	    if ($pageid > 0)
955
	    {
956
	        $res = $objectpage->fetch($pageid);
957
	    }
958
	    else
959
	    {
960
	        $res=0;
961
	        if ($object->fk_default_home > 0)
962
	        {
963
	            $res = $objectpage->fetch($object->fk_default_home);
964
	        }
965
	        if (! ($res > 0))
966
	        {
967
	            $res = $objectpage->fetch(0, $object->id);
968
	        }
969
	    }
970
    }
971
972
    if (! $error && $res > 0)
973
    {
974
        if ($action == 'updatesource' || $action == 'updatecontent')
975
        {
976
            $db->begin();
977
978
            $objectpage->content = GETPOST('PAGE_CONTENT','none');
979
980
            // Clean data. We remove all the head section.
981
            $objectpage->content = preg_replace('/<head>.*<\/head>/s', '', $objectpage->content);
982
            /* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */
983
984
985
            $res = $objectpage->update($user);
986
            if ($res < 0)
987
            {
988
                $error++;
989
                setEventMessages($objectpage->error, $objectpage->errors, 'errors');
990
            }
991
992
        	if (! $error)
993
        	{
994
        		$db->commit();
995
996
        		$filemaster=$pathofwebsite.'/master.inc.php';
997
        		//$fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
998
        		$filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
999
1000
        	    dol_mkdir($pathofwebsite);
1001
1002
1003
        		// Now generate the master.inc.php page
1004
        		dol_syslog("We regenerate the master file");
1005
        		dol_delete_file($filemaster);
1006
1007
        		$mastercontent = '<?php'."\n";
1008
        		$mastercontent.= '// File generated to link to the master file'."\n";
1009
        		$mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
1010
        		$mastercontent.= '?>'."\n";
1011
        		$result = file_put_contents($filemaster, $mastercontent);
1012
        		if (! empty($conf->global->MAIN_UMASK))
1013
        		    @chmod($filemaster, octdec($conf->global->MAIN_UMASK));
1014
1015
    		    if (! $result) setEventMessages('Failed to write file '.$filemaster, null, 'errors');
1016
1017
1018
    		    // Now generate the alias.php page
1019
                if (! empty($fileoldalias))
1020
                {
1021
        		    dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
1022
        		    dol_delete_file($fileoldalias);
1023
                }
1024
1025
                // Save page alias
1026
                $result=dolSavePageAlias($filealias, $object, $objectpage);
1027
                if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
1028
1029
				// Save page content
1030
        	    $result=dolSavePageContent($filetpl, $object, $objectpage);
1031
        	    if ($result)
1032
        	    {
1033
        	        setEventMessages($langs->trans("Saved"), null, 'mesgs');
1034
        	        header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
1035
       	            exit;
1036
        	    }
1037
        	    else
1038
        	    {
1039
        	        setEventMessages('Failed to write file '.$filetpl, null, 'errors');
1040
        	        header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
1041
       	            exit;
1042
        	    }
1043
        	}
1044
        	else
1045
        	{
1046
        		$db->rollback();
1047
        	}
1048
        }
1049
        else
1050
        {
1051
            header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
1052
            exit;
1053
        }
1054
    }
1055
    else
1056
    {
1057
        if (! $error) setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
1058
    }
1059
}
1060
1061
// Export site
1062
if (GETPOST('exportsite'))
1063
{
1064
	$fileofzip = exportWebSite($object);
1065
1066
	$file_name = basename($fileofzip);
1067
1068
	header("Content-Type: application/zip");
1069
	header("Content-Disposition: attachment; filename=".$file_name);
1070
	header("Content-Length: " . filesize($fileofzip));
1071
1072
	readfile($fileofzip);
1073
	exit;
1074
}
1075
1076
1077
1078
/*
1079
 * View
1080
 */
1081
1082
$form = new Form($db);
1083
$formadmin = new FormAdmin($db);
1084
$formwebsite = new FormWebsite($db);
1085
1086
$help_url='';
1087
1088
llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, 0,
1089
	array(
1090
		'/includes/ace/ace.js',
1091
		'/includes/ace/ext-statusbar.js',
1092
		'/includes/ace/ext-language_tools.js',
1093
		//'/includes/ace/ext-chromevox.js'
1094
	), array());
1095
1096
print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
1097
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1098
if ($action == 'createsite')
1099
{
1100
    print '<input type="hidden" name="action" value="addsite">';
1101
}
1102
if ($action == 'create')
1103
{
1104
    print '<input type="hidden" name="action" value="add">';
1105
}
1106
if ($action == 'editcss')
1107
{
1108
    print '<input type="hidden" name="action" value="updatecss">';
1109
}
1110
if ($action == 'editmenu')
1111
{
1112
    print '<input type="hidden" name="action" value="updatemenu">';
1113
}
1114
if ($action == 'setashome')
1115
{
1116
    print '<input type="hidden" name="action" value="updateashome">';
1117
}
1118
if ($action == 'editmeta')
1119
{
1120
    print '<input type="hidden" name="action" value="updatemeta">';
1121
}
1122
if ($action == 'editsource')
1123
{
1124
    print '<input type="hidden" name="action" value="updatesource">';
1125
}
1126
if ($action == 'editcontent')
1127
{
1128
    print '<input type="hidden" name="action" value="updatecontent">';
1129
}
1130
if ($action == 'edit')
1131
{
1132
    print '<input type="hidden" name="action" value="update">';
1133
}
1134
1135
1136
// Add a margin under toolbar ?
1137
$style='';
1138
if ($action != 'preview' && $action != 'editcontent' && $action != 'editsource') $style=' margin-bottom: 5px;';
1139
1140
//var_dump($objectpage);exit;
1141
print '<div class="centpercent websitebar">';
1142
1143
if (count($object->records) > 0)
1144
{
1145
    // ***** Part for web sites
1146
1147
	print '<div class="websiteselection hideonsmartphoneimp minwwidth100">';
1148
	print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("AddWebsite")).'" name="createsite">';
1149
	print '</div>';
1150
1151
    print '<div class="websiteselection hideonsmartphoneimp">';
1152
    print $langs->trans("Website").': ';
1153
    print '</div>';
1154
1155
    // List of websites
1156
    print '<div class="websiteselection">';
1157
    $out='';
1158
    $out.='<select name="website" class="minwidth100" id="website">';
1159
    if (empty($object->records)) $out.='<option value="-1">&nbsp;</option>';
1160
    // Loop on each sites
1161
    $i=0;
1162
    foreach($object->records as $key => $valwebsite)
1163
    {
1164
        if (empty($website)) $website=$valwebsite->ref;
1165
1166
        $out.='<option value="'.$valwebsite->ref.'"';
1167
        if ($website == $valwebsite->ref) $out.=' selected';		// To preselect a value
1168
        $out.='>';
1169
        $out.=$valwebsite->ref;
1170
        $out.='</option>';
1171
        $i++;
1172
    }
1173
    $out.='</select>';
1174
    $out.=ajax_combobox('website');
1175
    print $out;
1176
    print '<input type="submit" class="button" name="refreshsite" value="'.$langs->trans("Load").'">';
1177
1178
    if ($website)
1179
    {
1180
        $virtualurl='';
1181
        $dataroot=DOL_DATA_ROOT.'/websites/'.$website;
1182
        if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost;
1183
    }
1184
1185
    if ($website && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone'))
1186
    {
1187
        $disabled='';
1188
        if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"';
1189
1190
        print ' &nbsp; ';
1191
1192
        print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditCss")).'" name="editcss">';
1193
        //print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditMenu")).'" name="editmenu">';
1194
        print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';
1195
        print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ExportSite")).'" name="exportsite">';
1196
1197
		print ' &nbsp; ';
1198
1199
        print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="editmedias">';
1200
    }
1201
1202
    print '</div>';
1203
1204
    // Button for websites
1205
    print '<div class="websitetools">';
1206
1207
    if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
1208
    {
1209
        print '<a class="websitebuttonsitepreview" id="previewsite" href="'.$urlwithroot.'/public/websites/index.php?website='.$website.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">';
1210
        print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview');
1211
        print '</a>';
1212
1213
        print '<div class="websiteinputurl" id="websiteinputurl">';
1214
        print '<input type="text" id="previewsiteurl" class="minwidth200imp" name="previewsite" placeholder="'.$langs->trans("http://myvirtualhost").'" value="'.$virtualurl.'">';
1215
        //print '<input type="submit" class="button" name="previewwebsite" target="tab'.$website.'" value="'.$langs->trans("ViewSiteInNewTab").'">';
1216
        $htmltext=$langs->trans("SetHereVirtualHost", $dataroot);
1217
        print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helpvirtualhost');
1218
        print '</div>';
1219
1220
        $urlext=$virtualurl;
1221
        $urlint=$urlwithroot.'/public/websites/index.php?website='.$website;
1222
        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)).'">';
1223
        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');
1224
        print '</a>';
1225
    }
1226
1227
    if (in_array($action, array('editcss','editmenu','editmedias')))
1228
    {
1229
        if (preg_match('/^create/',$action) && $action != 'editmedias') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
1230
        if (preg_match('/^edit/',$action) && $action != 'editmedias') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
1231
        if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
1232
    }
1233
1234
    print '</div>';
1235
1236
1237
    // ***** Part for pages
1238
1239
    if ($website && ! in_array($action, array('editcss','editmenu','editmedias')))
1240
    {
1241
        print '</div>';	// Close current websitebar to open a new one
1242
1243
        $array=$objectpage->fetchAll($object->id);
1244
        if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
1245
        $atleastonepage=(is_array($array) && count($array) > 0);
1246
1247
        print '<div class="centpercent websitebar"'.($style?' style="'.$style.'"':'').'">';
1248
1249
        print '<div class="websiteselection hideonsmartphoneimp minwidth100">';
1250
        print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("AddPage")).'" name="create">';
1251
        print '</div>';
1252
1253
        print '<div class="websiteselection hideonsmartphoneimp">';
1254
        print $langs->trans("Page").': ';
1255
        print '</div>';
1256
        print '<div class="websiteselection">';
1257
1258
        if ($action != 'add')
1259
        {
1260
            $out='';
1261
            $out.='<select name="pageid" id="pageid" class="minwidth200 maxwidth300">';
1262
            if ($atleastonepage)
1263
            {
1264
                if (empty($pageid) && $action != 'create')      // Page id is not defined, we try to take one
1265
                {
1266
                    $firstpageid=0;$homepageid=0;
1267
                    foreach($array as $key => $valpage)
1268
                    {
1269
                        if (empty($firstpageid)) $firstpageid=$valpage->id;
1270
                        if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid=$valpage->id;
1271
                    }
1272
                    $pageid=$homepageid?$homepageid:$firstpageid;   // We choose home page and if not defined yet, we take first page
1273
                }
1274
1275
                foreach($array as $key => $valpage)
1276
                {
1277
                    $out.='<option value="'.$key.'"';
1278
                    if ($pageid > 0 && $pageid == $key) $out.=' selected';		// To preselect a value
1279
                    $out.='>';
1280
                    $out.=$valpage->pageurl.' - '.$valpage->title;
1281
                    if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')';
1282
                    $out.='</option>';
1283
                }
1284
            }
1285
            else $out.='<option value="-1">&nbsp;</option>';
1286
            $out.='</select>';
1287
            $out.=ajax_combobox('pageid');
1288
            print $out;
1289
        }
1290
        else
1291
        {
1292
            print $langs->trans("New");
1293
        }
1294
1295
        print '<input type="submit" class="button" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>';
1296
1297
        if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
1298
        {
1299
            $disabled='';
1300
            if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"';
1301
1302
            // Confirmation to clone
1303
            if ($action == 'createfromclone') {
1304
            	// Create an array for form
1305
            	$formquestion = array(
1306
            	array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("Website")  ,'value'=> 'copy_of_'.$object->ref),
1307
            	//array('type' => 'checkbox', 'name' => 'is_a_translation', 'label' => $langs->trans("SiteIsANewTranslation"), 'value' => 0),
1308
            	//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')),
1309
            	//array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("Website"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
1310
            	);
1311
1312
            	$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id='.$object->id, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200);
1313
1314
            	print $formconfirm;
1315
            }
1316
1317
            if ($pageid > 0)
1318
            {
1319
                // Confirmation to clone
1320
                if ($action == 'createpagefromclone') {
1321
	                // Create an array for form
1322
					$formquestion = array(
1323
						array('type' => 'text', 'name' => 'pageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME")  ,'value'=> 'copy_of_'.$objectpage->pageurl),
1324
						array('type' => 'checkbox', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0),
1325
						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')),
1326
						array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("Website"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
1327
					);
1328
1329
	               	$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?pageid=' . $pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 250);
1330
1331
					print $formconfirm;
1332
	            }
1333
1334
                print ' &nbsp; ';
1335
1336
                print '<input type="submit" class="button"'.$disabled.'  value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
1337
                print '<input type="submit" class="button"'.$disabled.'  value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
1338
                print '<input type="submit" class="button"'.$disabled.'  value="'.dol_escape_htmltag($langs->trans("EditHTMLSource")).'" name="editsource">';
1339
                if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
1340
                else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
1341
        		print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
1342
                print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage?'':' disabled="disabled"').'>';
1343
            }
1344
        }
1345
1346
        print '</div>';	// end website selection
1347
1348
        print '<div class="websitetools">';
1349
1350
        if ($website && $pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone'))
1351
        {
1352
            $websitepage = new WebSitePage($db);
1353
            $websitepage->fetch($pageid);
1354
1355
            $realpage=$urlwithroot.'/public/websites/index.php?website='.$website.'&pageref='.$websitepage->pageurl;
1356
            $pagealias = $websitepage->pageurl;
1357
1358
            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)).'">';
1359
            print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview');
1360
            print '</a>';       // View page in new Tab
1361
1362
            print '<div class="websiteinputurl" id="websiteinputpage">';
1363
            print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
1364
            $htmltext=$langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta"));
1365
            print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias');
1366
            print '</div>';
1367
1368
            $urlext=$virtualurl.'/'.$pagealias.'.php';
1369
            $urlint=$urlwithroot.'/public/websites/index.php?website='.$website;
1370
            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)).'">';
1371
            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');
1372
            print '</a>';
1373
            //print '<input type="submit" class="button" name="previewpage" target="tab'.$website.'"value="'.$langs->trans("ViewPageInNewTab").'">';
1374
1375
            // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
1376
        }
1377
        if (! in_array($action, array('editcss','editmenu','editmedias','createsite','create','createpagefromclone')))
1378
        {
1379
            if (preg_match('/^create/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
1380
            if (preg_match('/^edit/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
1381
            if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
1382
        }
1383
1384
        print '</div>';	// end websitetools
1385
1386
        print '<div class="websitehelp">';
1387
        if (GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha'))
1388
        {
1389
        	$htmltext=$langs->transnoentitiesnoconv("YouCanEditHtmlSource");
1390
        	print $form->textwithpicto($langs->trans("SyntaxHelp"), $htmltext, 1, 'help', 'inline-block', 0, 2, 'tooltipsubstitution');
1391
        }
1392
        print '</div>';	// end websitehelp
1393
1394
1395
1396
        if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
1397
        {
1398
            // Adding jquery code to change on the fly url of preview ext
1399
            if (! empty($conf->use_javascript_ajax))
1400
            {
1401
                print '<script type="text/javascript" language="javascript">
1402
                    jQuery(document).ready(function() {
1403
                		jQuery("#websiteinputurl").keyup(function() {
1404
                            console.log("Website external url modified "+jQuery("#previewsiteurl").val());
1405
                			if (jQuery("#previewsiteurl").val() != "") jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 1 });
1406
                			else jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 0.2 });
1407
                		});
1408
                    	jQuery("#previewsiteext,#previewpageext").click(function() {
1409
                            newurl=jQuery("#previewsiteurl").val();
1410
                            newpage=jQuery("#previewsiteurl").val() + "/" + jQuery("#previewpageurl").val() + ".php";
1411
                            console.log("Open url "+newurl);
1412
                            /* Save url */
1413
                            jQuery.ajax({
1414
                                method: "POST",
1415
                                url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
1416
                                data: {
1417
                                    field: \'editval_virtualhost\',
1418
                                    element: \'websites\',
1419
                                    table_element: \'website\',
1420
                                    fk_element: '.$object->id.',
1421
                                    value: newurl,
1422
                                },
1423
                                context: document.body
1424
                            });
1425
1426
                            jQuery("#previewsiteext").attr("href",newurl);
1427
                            jQuery("#previewpageext").attr("href",newpage);
1428
                        });
1429
                    });
1430
                    </script>';
1431
            }
1432
        }
1433
    }
1434
}
1435
else
1436
{
1437
    print '<div class="websiteselection">';
1438
    $langs->load("errors");
1439
    print $langs->trans("ErrorModuleSetupNotComplete");
1440
    print '<div>';
1441
    $action='';
1442
}
1443
1444
1445
print '</div>';	// end current websitebar
1446
1447
$head = array();
1448
1449
1450
/*
1451
 * Edit mode
1452
 */
1453
1454
if ($action == 'editcss')
1455
{
1456
    print '<div class="fiche">';
1457
1458
    print '<br>';
1459
1460
    $csscontent = @file_get_contents($filecss);
1461
    // Clean the php css file to remove php code and get only css part
1462
    $csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $csscontent);
1463
    $csscontent.= GETPOST('WEBSITE_CSS_INLINE');
1464
    if (! trim($csscontent)) $csscontent='/* CSS content (all pages) */'."\n".'body.bodywebsite { margin: 0; }';
1465
1466
    $jscontent = @file_get_contents($filejs);
1467
    // Clean the php js file to remove php code and get only js part
1468
    $jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $jscontent);
1469
    $jscontent.= GETPOST('WEBSITE_JS_INLINE');
1470
    if (! trim($jscontent)) $jscontent='/* JS content (all pages) */'."\n";
1471
1472
    $htmlheader = @file_get_contents($filehtmlheader);
1473
    // Clean the php htmlheader file to remove php code and get only html part
1474
    $htmlheader = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htmlheader);
1475
    if (! trim($htmlheader)) $htmlheader='<!-- HTML header content (common for all pages) -->';
1476
    else $htmlheader='<html>'."\n".trim($htmlheader)."\n".'</html>';
1477
1478
    $robotcontent = @file_get_contents($filerobot);
1479
    // Clean the php htmlheader file to remove php code and get only html part
1480
    $robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $robotcontent);
1481
    if (! trim($robotcontent))
1482
    {
1483
    	$robotcontent.="# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n";
1484
    	$robotcontent.="User-agent: *\n";
1485
    	$robotcontent.="Allow: /public/\n";
1486
    	$robotcontent.="Disallow: /administrator/\n";
1487
    }
1488
1489
    $htaccesscontent = @file_get_contents($filehtaccess);
1490
    // Clean the php htaccesscontent file to remove php code and get only html part
1491
    $htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htaccesscontent);
1492
    if (! trim($htaccesscontent))
1493
    {
1494
    	$htaccesscontent.="# Order allow,deny\n";
1495
		$htaccesscontent.="# Deny from all\n";
1496
    }
1497
    //else $htaccesscontent='<html>'."\n".$htaccesscontent."\n".'</html>';*/
1498
1499
    dol_fiche_head();
1500
1501
    print '<!-- Edit CSS -->'."\n";
1502
    print '<table class="border" width="100%">';
1503
1504
    // Website
1505
    print '<tr><td class="titlefieldcreate">';
1506
    print $langs->trans('WebSite');
1507
    print '</td><td>';
1508
    print $website;
1509
    print '</td></tr>';
1510
1511
    // CSS file
1512
    print '<tr><td class="tdtop">';
1513
    print $langs->trans('WEBSITE_CSS_INLINE');
1514
    print '</td><td>';
1515
1516
    $doleditor=new DolEditor('WEBSITE_CSS_INLINE', $csscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1517
	print $doleditor->Create(1, '', true, 'CSS', 'css');
1518
1519
    print '</td></tr>';
1520
1521
    // JS file
1522
    print '<tr><td class="tdtop">';
1523
    print $langs->trans('WEBSITE_JS_INLINE');
1524
    print '</td><td>';
1525
1526
    $doleditor=new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1527
	print $doleditor->Create(1, '', true, 'JS', 'javascript');
1528
1529
    print '</td></tr>';
1530
1531
    // Common HTML header
1532
	print '<tr><td class="tdtop">';
1533
    print $langs->trans('WEBSITE_HTML_HEADER');
1534
    print '</td><td>';
1535
1536
    $doleditor=new DolEditor('WEBSITE_HTML_HEADER', $htmlheader, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1537
	print $doleditor->Create(1, '', true, 'HTML Header', 'html');
1538
1539
    print '</td></tr>';
1540
1541
    // Robot file
1542
	print '<tr><td class="tdtop">';
1543
    print $langs->trans('WEBSITE_ROBOT');
1544
    print '</td><td>';
1545
1546
    $doleditor=new DolEditor('WEBSITE_ROBOT', $robotcontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1547
	print $doleditor->Create(1, '', true, 'Robot file', 'txt');
1548
1549
    print '</td></tr>';
1550
1551
    // .htaccess
1552
	print '<tr><td class="tdtop">';
1553
    print $langs->trans('WEBSITE_HTACCESS');
1554
    print '</td><td>';
1555
1556
    $doleditor=new DolEditor('WEBSITE_HTACCESS', $htaccesscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1557
	print $doleditor->Create(1, '', true, $langs->trans("File").' .htaccess', 'txt');
1558
1559
    print '</td></tr>';
1560
1561
    print '</table>';
1562
1563
    dol_fiche_end();
1564
1565
    print '</div>';
1566
1567
    print '<br>';
1568
}
1569
1570
if ($action == 'createsite')
1571
{
1572
    print '<div class="fiche">';
1573
1574
    print '<br>';
1575
1576
	/*$h = 0;
1577
	$head = array();
1578
1579
	$head[$h][0] = dol_buildpath('/websites/index.php',1).'?id='.$object->id;
1580
	$head[$h][1] = $langs->trans("AddSite");
1581
   	$head[$h][2] = 'card';
1582
	$h++;
1583
1584
    dol_fiche_head($head, 'card', $langs->trans("AddSite"), -1, 'globe');
1585
    */
1586
	if ($action == 'create') print_fiche_titre($langs->trans("AddSite"));
1587
1588
    print '<!-- Add site -->'."\n";
1589
    //print '<div class="fichecenter">';
1590
1591
    print '<table class="border" width="100%">';
1592
1593
    if (GETPOST('WEBSITE_REF'))         $siteref=GETPOST('WEBSITE_REF','alpha');
1594
    if (GETPOST('WEBSITE_DESCRIPTION')) $sitedesc=GETPOST('WEBSITE_DESCRIPTION','alpha');
1595
1596
    print '<tr><td class="titlefieldcreate fieldrequired">';
1597
    print $langs->trans('Ref');
1598
    print '</td><td>';
1599
    print '<input type="text" class="flat maxwidth300" name="WEBSITE_REF" value="'.dol_escape_htmltag($siteref).'">';
1600
    print '</td></tr>';
1601
1602
    print '<tr><td>';
1603
    print $langs->trans('Description');
1604
    print '</td><td>';
1605
    print '<input type="text" class="flat minwidth300" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
1606
    print '</td></tr>';
1607
1608
    print '<tr><td>';
1609
    print $form->textwithpicto($langs->trans('Virtualhost'), $langs->trans("SetHereVirtualHost", DOL_DATA_ROOT.'/websites/<i>websiteref</i>'), 1, 'help', '', 0, 2, 'tooltipvirtual');
1610
    print '</td><td>';
1611
    print '<input type="text" class="flat minwidth300" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
1612
    print '</td></tr>';
1613
1614
1615
    print '</table>';
1616
1617
    if ($action == 'createsite')
1618
    {
1619
    	print '<div class="center">';
1620
1621
	    print '<input class="button" type="submit" name="add" value="'.$langs->trans("Create").'">';
1622
    	print '<input class="button" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
1623
1624
    	print '</div>';
1625
    }
1626
1627
1628
	//print '</div>';
1629
1630
    //dol_fiche_end();
1631
1632
    print '</div>';
1633
1634
    print '<br>';
1635
}
1636
1637
if ($action == 'editmeta' || $action == 'create')
1638
{
1639
    print '<div class="fiche">';
1640
1641
    print '<br>';
1642
1643
	/*$h = 0;
1644
	$head = array();
1645
1646
	$head[$h][0] = dol_buildpath('/websites/index.php',1).'?id='.$object->id;
1647
	$head[$h][1] = $langs->trans("AddPage");
1648
   	$head[$h][2] = 'card';
1649
	$h++;
1650
1651
    dol_fiche_head($head, 'card', $langs->trans("AddPage"), -1, 'globe');
1652
    */
1653
	if ($action == 'create') print_fiche_titre($langs->trans("AddPage"));
1654
1655
    print '<!-- Edit or create page -->'."\n";
1656
    //print '<div class="fichecenter">';
1657
1658
    if ($action == 'create')
1659
    {
1660
    	print '<br>';
1661
1662
    	print ' * '.$langs->trans("CreateByFetchingExternalPage").'<br><hr>';
1663
    	print '<table class="border" width="100%">';
1664
    	print '<tr><td class="titlefieldcreate">';
1665
    	print $langs->trans("URL");
1666
    	print '</td><td>';
1667
    	print '<input class="flat minwidth300" type="text" name="externalurl" value="'.dol_escape_htmltag(GETPOST('externalurl','alpha')).'" placeholder="http://externalsite/pagetofetch"> ';
1668
		print '<input class="button" type="submit" name="fetchexternalurl" value="'.dol_escape_htmltag($langs->trans("FetchAndCreate")).'">';
1669
    	print '</td></tr>';
1670
    	print '</table>';
1671
1672
    	print '<br>';
1673
1674
    	print ' * '.$langs->trans("OrEnterPageInfoManually").'<br><hr>';
1675
    }
1676
1677
    print '<table class="border" width="100%">';
1678
1679
    if ($action != 'create')
1680
    {
1681
        print '<tr><td class="titlefield">';
1682
        print $langs->trans('IDOfPage');
1683
        print '</td><td>';
1684
        print $pageid;
1685
        print '</td></tr>';
1686
1687
        print '<tr><td class="titlefield">';
1688
        print $langs->trans('WEBSITE_PAGEURL');
1689
        print '</td><td>';
1690
        print '/public/websites/index.php?website='.urlencode($website).'&pageid='.urlencode($pageid);
1691
        print '</td></tr>';
1692
1693
        /*
1694
        print '<tr><td class="titlefield">';
1695
        print $langs->trans('InitiallyGrabbedFrom');
1696
        print '</td><td>';
1697
        print $objectpage->grabbed_from;
1698
        print '</td></tr>';
1699
        */
1700
1701
        $pageurl=$objectpage->pageurl;
1702
        $pagetitle=$objectpage->title;
1703
        $pagedescription=$objectpage->description;
1704
        $pagekeywords=$objectpage->keywords;
1705
        $pagelang=$objectpage->lang;
1706
        $pagehtmlheader=$objectpage->htmlheader;
1707
    }
1708
    if (GETPOST('WEBSITE_PAGENAME','alpha'))    $pageurl=GETPOST('WEBSITE_PAGENAME','alpha');
1709
    if (GETPOST('WEBSITE_TITLE','alpha'))       $pagetitle=GETPOST('WEBSITE_TITLE','alpha');
1710
    if (GETPOST('WEBSITE_DESCRIPTION','alpha')) $pagedescription=GETPOST('WEBSITE_DESCRIPTION','alpha');
1711
    if (GETPOST('WEBSITE_KEYWORDS','alpha'))    $pagekeywords=GETPOST('WEBSITE_KEYWORDS','alpha');
1712
    if (GETPOST('WEBSITE_LANG','aZ09'))         $pagelang=GETPOST('WEBSITE_LANG','aZ09');
1713
	if (GETPOST('htmlheader','none'))			$pagehtmlheader=GETPOST('htmlheader','none');
1714
1715
    print '<tr><td class="titlefieldcreate fieldrequired">';
1716
    print $langs->trans('WEBSITE_PAGENAME');
1717
    print '</td><td>';
1718
    print '<input type="text" class="flat maxwidth300" name="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
1719
    print '</td></tr>';
1720
1721
    print '<tr><td class="fieldrequired">';
1722
    print $langs->trans('WEBSITE_TITLE');
1723
    print '</td><td>';
1724
    print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'">';
1725
    print '</td></tr>';
1726
1727
    print '<tr><td>';
1728
    print $langs->trans('WEBSITE_DESCRIPTION');
1729
    print '</td><td>';
1730
    print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($pagedescription).'">';
1731
    print '</td></tr>';
1732
1733
    print '<tr><td>';
1734
    print $langs->trans('WEBSITE_KEYWORDS');
1735
    print '</td><td>';
1736
    print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($pagekeywords).'">';
1737
    print '</td></tr>';
1738
1739
    print '<tr><td>';
1740
    print $langs->trans('Language');
1741
    print '</td><td>';
1742
    print $formadmin->select_language($pagelang?$pagelang:$langs->defaultlang, 'WEBSITE_LANG');
1743
    print '</td></tr>';
1744
1745
    print '<tr><td>';
1746
    print $langs->trans('HtmlHeaderPage');
1747
    print '</td><td>';
1748
    $doleditor=new DolEditor('htmlheader', $pagehtmlheader, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
1749
    print $doleditor->Create(1, '', true, 'HTML Header', 'html');
1750
    print '</td></tr>';
1751
1752
    print '</table>';
1753
1754
    if ($action == 'create')
1755
    {
1756
    	print '<div class="center">';
1757
1758
	    print '<input class="button" type="submit" name="add" value="'.$langs->trans("Create").'">';
1759
    	print '<input class="button" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
1760
1761
    	print '</div>';
1762
    }
1763
1764
1765
	//print '</div>';
1766
1767
    //dol_fiche_end();
1768
1769
    print '</div>';
1770
1771
    print '<br>';
1772
}
1773
1774
if ($action == 'editmedias')
1775
{
1776
    print '<!-- Edit Media -->'."\n";
1777
    print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
1778
}
1779
1780
if ($action == 'editmenu')
1781
{
1782
    print '<!-- Edit Menu -->'."\n";
1783
    print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
1784
}
1785
1786
if ($action == 'editsource')
1787
{
1788
	/*
1789
	 * Editing with source editor
1790
	 */
1791
1792
	$contentforedit = '';
1793
	/*$contentforedit.='<style scoped>'."\n";        // "scoped" means "apply to parent element only". Not yet supported by browsers
1794
	 $contentforedit.=$csscontent;
1795
	 $contentforedit.='</style>'."\n";*/
1796
	$contentforedit .= $objectpage->content;
1797
1798
	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1799
	$doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,'ace',ROWS_5,'90%');
1800
	$doleditor->Create(0, '', false, 'HTML Source', 'php');
1801
}
1802
1803
if ($action == 'editcontent')
1804
{
1805
    /*
1806
     * Editing with default ckeditor
1807
     */
1808
1809
    $contentforedit = '';
1810
    /*$contentforedit.='<style scoped>'."\n";        // "scoped" means "apply to parent element only". Not yet supported by browsers
1811
    $contentforedit.=$csscontent;
1812
    $contentforedit.='</style>'."\n";*/
1813
    $contentforedit .= $objectpage->content;
1814
1815
    $contentforedit = preg_replace('/(<img.*src=")(?!http)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $contentforedit, -1, $nbrep);
1816
1817
    require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1818
    $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%');
1819
    $doleditor->Create(0, '', false);
1820
}
1821
1822
print "</div>\n</form>\n";
1823
1824
1825
1826
if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
1827
{
1828
    if ($pageid > 0)
1829
    {
1830
    	// Ouput page under the Dolibarr top menu
1831
        $objectpage->fetch($pageid);
1832
        $csscontent = @file_get_contents($filecss);
1833
        $jscontent = @file_get_contents($filejs);
1834
1835
        $out = '<!-- Page content '.$filetpl.' : Div with (CSS Of website from file + Style/htmlheader of page from database + Page content from database) -->'."\n";
1836
1837
        $out.='<div id="websitecontentundertopmenu" class="websitecontentundertopmenu">'."\n";
1838
1839
1840
        // REPLACEMENT OF LINKS When page called by website editor
1841
1842
        $out.='<style scoped>'."\n";        // "scoped" means "apply to parent element only". Not yet supported by browsers
1843
        $out.= '<!-- Include website CSS file -->'."\n";
1844
        $out.=dolWebsiteReplacementOfLinks($object, $csscontent);
1845
        $out.= '<!-- Include HTML header from page inline block -->'."\n";
1846
        $out.= $objectpage->htmlheader."\n";
1847
        $out.='</style>'."\n";
1848
1849
		$out.='<div id="bodywebsite" class="bodywebsite">'."\n";
1850
1851
        $out.=dolWebsiteReplacementOfLinks($object, $objectpage->content)."\n";
1852
1853
        $out.='</div>';
1854
1855
        $out.='</div>';
1856
1857
        $out.= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";
1858
1859
        print $out;
1860
1861
        /*file_put_contents($filetpl, $out);
1862
        if (! empty($conf->global->MAIN_UMASK))
1863
            @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
1864
1865
        // Output file on browser
1866
        dol_syslog("index.php include $filetpl $filename content-type=$type");
1867
        $original_file_osencoded=dol_osencode($filetpl);	// New file name encoded in OS encoding charset
1868
1869
        // This test if file exists should be useless. We keep it to find bug more easily
1870
        if (! file_exists($original_file_osencoded))
1871
        {
1872
            dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
1873
            exit;
1874
        }
1875
1876
        //include_once $original_file_osencoded;
1877
        */
1878
1879
        /*print '<iframe class="websiteiframenoborder centpercent" src="'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website.'&pageid='.$pageid.'"/>';
1880
        print '</iframe>';*/
1881
    }
1882
    else
1883
    {
1884
        print '<br><br><div class="center">'.$langs->trans("PreviewOfSiteNotYetAvailable", $website).'</center><br><br><br>';
1885
        print '<div class="center"><div class="logo_setup"></div></div>';
1886
    }
1887
}
1888
1889
1890
1891
llxFooter();
1892
1893
$db->close();
1894
1895
1896
1897
1898
/**
1899
 * Save content of a page on disk
1900
 *
1901
 * @param	string		$filealias			Full path of filename to generate
1902
 * @param	Website		$object				Object website
1903
 * @param	WebsitePage	$objectpage			Object websitepage
1904
 * @return	boolean							True if OK
1905
 */
1906
function dolSavePageAlias($filealias, $object, $objectpage)
1907
{
1908
	global $conf;
1909
1910
	// Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
1911
	dol_syslog("We regenerate the alias page filealias=".$filealias);
1912
1913
	$aliascontent = '<?php'."\n";
1914
	$aliascontent.= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n";
1915
	$aliascontent.= 'global $dolibarr_main_data_root;'."\n";
1916
	$aliascontent.= 'if (empty($dolibarr_main_data_root)) require \'./page'.$objectpage->id.'.tpl.php\'; ';
1917
	$aliascontent.= 'else require $dolibarr_main_data_root.\'/websites/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n";
1918
	$aliascontent.= '?>'."\n";
1919
	$result = file_put_contents($filealias, $aliascontent);
1920
	if (! empty($conf->global->MAIN_UMASK))
1921
		@chmod($filealias, octdec($conf->global->MAIN_UMASK));
1922
1923
	return ($result?true:false);
1924
}
1925
1926
1927
/**
1928
 * Save content of a page on disk
1929
 *
1930
 * @param	string		$filetpl			Full path of filename to generate
1931
 * @param	Website		$object				Object website
1932
 * @param	WebsitePage	$objectpage			Object websitepage
1933
 * @return	boolean							True if OK
1934
 */
1935
function dolSavePageContent($filetpl, $object, $objectpage)
1936
{
1937
	global $conf;
1938
1939
	// Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
1940
	dol_syslog("We regenerate the tpl page filetpl=".$filetpl);
1941
1942
	dol_delete_file($filetpl);
1943
1944
	$shortlangcode = '';
1945
	if ($objectpage->lang) $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang);		// en_US or en-US -> en
1946
1947
	$tplcontent ='';
1948
	$tplcontent.= "<?php // BEGIN PHP\n";
1949
	$tplcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
1950
	$tplcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
1951
	$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
1952
	$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
1953
	$tplcontent.= "ob_start();\n";
1954
	$tplcontent.= "// END PHP ?>\n";
1955
	$tplcontent.= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"':'').'>'."\n";
1956
	$tplcontent.= '<head>'."\n";
1957
	$tplcontent.= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n";
1958
	$tplcontent.= '<meta charset="UTF-8">'."\n";
1959
	$tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
1960
	$tplcontent.= '<meta name="robots" content="index, follow" />'."\n";
1961
	$tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
1962
	$tplcontent.= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n";
1963
	$tplcontent.= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n";
1964
	$tplcontent.= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n";
1965
	$tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.'" />'."\n";
1966
	$tplcontent.= '<!-- Include link to CSS file -->'."\n";
1967
	$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n";
1968
	$tplcontent.= '<!-- Include HTML header from common file -->'."\n";
1969
	$tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/websites/'.$object->ref.'/htmlheader.html"); ?>'."\n";
1970
	$tplcontent.= '<!-- Include HTML header from page inline block -->'."\n";
1971
	$tplcontent.= $objectpage->htmlheader."\n";
1972
	$tplcontent.= '</head>'."\n";
1973
1974
	$tplcontent.= '<!-- File generated by Dolibarr website module editor -->'."\n";
1975
	$tplcontent.= '<body id="bodywebsite" class="bodywebsite">'."\n";
1976
	$tplcontent.= $objectpage->content."\n";
1977
	$tplcontent.= '</body>'."\n";
1978
1979
	$tplcontent.= '<?php // BEGIN PHP'."\n";
1980
	$tplcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
1981
	$tplcontent.= "// END PHP ?>"."\n";
1982
1983
	//var_dump($filetpl);exit;
1984
	$result = file_put_contents($filetpl, $tplcontent);
1985
	if (! empty($conf->global->MAIN_UMASK))
1986
		@chmod($filetpl, octdec($conf->global->MAIN_UMASK));
1987
1988
	return $result;
1989
}
1990
1991
1992
/**
1993
 * Save content of a page on disk
1994
 *
1995
 * @param	string		$filehtmlheader		Full path of filename to generate
1996
 * @param	string		$htmlheadercontent	Content of file
1997
 * @return	boolean							True if OK
1998
 */
1999
function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent)
2000
{
2001
	global $conf, $pathofwebsite;
2002
2003
	dol_syslog("Save html header into ".$filehtmlheader);
2004
2005
	dol_mkdir($pathofwebsite);
2006
	$result = file_put_contents($filehtmlheader, $htmlheadercontent);
2007
	if (! empty($conf->global->MAIN_UMASK))
2008
		@chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK));
2009
2010
	if (! $result)
2011
	{
2012
		setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors');
2013
		return false;
2014
	}
2015
2016
	return true;
2017
}
2018
2019
/**
2020
 * Save content of a page on disk
2021
 *
2022
 * @param	string		$filecss			Full path of filename to generate
2023
 * @param	string		$csscontent			Content of file
2024
 * @return	boolean							True if OK
2025
 */
2026
function dolSaveCssFile($filecss, $csscontent)
2027
{
2028
	global $conf, $pathofwebsite;
2029
2030
	dol_syslog("Save html header into ".$filecss);
2031
2032
	dol_mkdir($pathofwebsite);
2033
	$result = file_put_contents($filecss, $csscontent);
2034
	if (! empty($conf->global->MAIN_UMASK))
2035
		@chmod($filecss, octdec($conf->global->MAIN_UMASK));
2036
2037
	if (! $result)
2038
	{
2039
		setEventMessages('Failed to write file '.$filecss, null, 'errors');
2040
		return false;
2041
	}
2042
2043
	return true;
2044
}
2045
2046
/**
2047
 * Save content of a page on disk
2048
 *
2049
 * @param	string		$filejs				Full path of filename to generate
2050
 * @param	string		$jscontent			Content of file
2051
 * @return	boolean							True if OK
2052
 */
2053
function dolSaveJsFile($filejs, $jscontent)
2054
{
2055
	global $conf, $pathofwebsite;
2056
2057
	dol_syslog("Save html header into ".$filejs);
2058
2059
	dol_mkdir($pathofwebsite);
2060
	$result = file_put_contents($filejs, $jscontent);
2061
	if (! empty($conf->global->MAIN_UMASK))
2062
		@chmod($filejs, octdec($conf->global->MAIN_UMASK));
2063
2064
	if (! $result)
2065
	{
2066
		setEventMessages('Failed to write file '.$filejs, null, 'errors');
2067
		return false;
2068
	}
2069
2070
	return true;
2071
}
2072
2073
/**
2074
 * Save content of a page on disk
2075
 *
2076
 * @param	string		$filerobot			Full path of filename to generate
2077
 * @param	string		$robotcontent		Content of file
2078
 * @return	boolean							True if OK
2079
 */
2080
function dolSaveRobotFile($filerobot, $robotcontent)
2081
{
2082
	global $conf, $pathofwebsite;
2083
2084
	dol_syslog("Save html header into ".$filerobot);
2085
2086
	dol_mkdir($pathofwebsite);
2087
	$result = file_put_contents($filerobot, $robotcontent);
2088
	if (! empty($conf->global->MAIN_UMASK))
2089
		@chmod($filerobot, octdec($conf->global->MAIN_UMASK));
2090
2091
	if (! $result)
2092
	{
2093
		setEventMessages('Failed to write file '.$filerobot, null, 'errors');
2094
		return false;
2095
	}
2096
2097
	return true;
2098
}
2099
2100
/**
2101
 * Save content of a page on disk
2102
 *
2103
 * @param	string		$filehtaccess		Full path of filename to generate
2104
 * @param	string		$htaccess			Content of file
2105
 * @return	boolean							True if OK
2106
 */
2107
function dolSaveHtaccessFile($filehtaccess, $htaccess)
2108
{
2109
	global $conf, $pathofwebsite;
2110
2111
	dol_syslog("Save html header into ".$filehtaccess);
2112
2113
	dol_mkdir($pathofwebsite);
2114
	$result = file_put_contents($filehtaccess, $htaccess);
2115
	if (! empty($conf->global->MAIN_UMASK))
2116
		@chmod($filehtaccess, octdec($conf->global->MAIN_UMASK));
2117
2118
	if (! $result)
2119
	{
2120
		setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
2121
		return false;
2122
	}
2123
2124
	return true;
2125
}
2126
2127