|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 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/core/lib/website.lib.php |
|
20
|
|
|
* \ingroup website |
|
21
|
|
|
* \brief Library for website module |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content. |
|
28
|
|
|
* Used to ouput the page on the Preview. |
|
29
|
|
|
* |
|
30
|
|
|
* @param Website $website Web site object |
|
31
|
|
|
* @param string $content Content to replace |
|
32
|
|
|
* @param int $removephppart 0=Replace PHP sections with a PHP badge. 1=Remove completely PHP sections. |
|
33
|
|
|
* @return boolean True if OK |
|
34
|
|
|
*/ |
|
35
|
|
|
function dolWebsiteReplacementOfLinks($website, $content, $removephppart=0) |
|
36
|
|
|
{ |
|
37
|
|
|
// Replace php code. Note $content may come from database and does not contains body tags. |
|
38
|
|
|
$replacewith='...php...'; |
|
39
|
|
|
if ($removephppart) $replacewith=''; |
|
40
|
|
|
$content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content); |
|
41
|
|
|
|
|
42
|
|
|
$replacewith='<span class="phptag">...php...</span>'; |
|
43
|
|
|
if ($removephppart) $replacewith=''; |
|
44
|
|
|
$content = preg_replace('/<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
45
|
|
|
|
|
46
|
|
|
// Replace relative link / with dolibarr URL |
|
47
|
|
|
$content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep); |
|
48
|
|
|
// Replace relative link /xxx.php with dolibarr URL |
|
49
|
|
|
$content = preg_replace('/(href=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
50
|
|
|
|
|
51
|
|
|
$content = preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
52
|
|
|
|
|
53
|
|
|
// <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
54
|
|
|
$content = preg_replace('/(<img[^>]*src=")(?!(http|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
55
|
|
|
|
|
56
|
|
|
// action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage |
|
57
|
|
|
$content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
58
|
|
|
|
|
59
|
|
|
return $content; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Render a string of an HTML content and output it. |
|
65
|
|
|
* Used to ouput the page when viewed from server (Dolibarr or Apache). |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $content Content string |
|
68
|
|
|
* @return void |
|
69
|
|
|
* @see dolWebsiteSaveContent |
|
70
|
|
|
*/ |
|
71
|
|
|
function dolWebsiteOutput($content) |
|
72
|
|
|
{ |
|
73
|
|
|
global $db, $langs, $conf, $user; |
|
74
|
|
|
global $dolibarr_main_url_root, $dolibarr_main_data_root; |
|
75
|
|
|
|
|
76
|
|
|
dol_syslog("dolWebsiteOutput start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')'); |
|
77
|
|
|
|
|
78
|
|
|
// Define $urlwithroot |
|
79
|
|
|
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
80
|
|
|
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
81
|
|
|
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
82
|
|
|
|
|
83
|
|
|
// Note: This seems never called when page is output inside the website editor (search 'REPLACEMENT OF LINKS When page called by website editor') |
|
84
|
|
|
|
|
85
|
|
|
if (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server |
|
86
|
|
|
{ |
|
87
|
|
|
global $website; |
|
88
|
|
|
|
|
89
|
|
|
// Replace relative link / with dolibarr URL: ...href="/"... |
|
90
|
|
|
$content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep); |
|
91
|
|
|
// Replace relative link /xxx.php with dolibarr URL: ...href="....php" |
|
92
|
|
|
$content=preg_replace('/(href=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
93
|
|
|
|
|
94
|
|
|
// Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart=" |
|
95
|
|
|
$content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3"', $content, -1, $nbrep); |
|
96
|
|
|
// Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: ...href="/viewimage.php?modulepart=" |
|
97
|
|
|
$content=preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3"', $content, -1, $nbrep); |
|
98
|
|
|
|
|
99
|
|
|
// Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/ |
|
100
|
|
|
$content=preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
101
|
|
|
|
|
102
|
|
|
// action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage |
|
103
|
|
|
$content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
104
|
|
|
} |
|
105
|
|
|
else // REPLACEMENT OF LINKS When page called from virtual host |
|
106
|
|
|
{ |
|
107
|
|
|
$symlinktomediaexists=1; |
|
108
|
|
|
|
|
109
|
|
|
// Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server |
|
110
|
|
|
// <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
111
|
|
|
// become |
|
112
|
|
|
// <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
113
|
|
|
$nbrep=0; |
|
114
|
|
|
if (! $symlinktomediaexists) |
|
115
|
|
|
{ |
|
116
|
|
|
$content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/?>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
117
|
|
|
$content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
118
|
|
|
} |
|
119
|
|
|
else |
|
120
|
|
|
{ |
|
121
|
|
|
$content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/?>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
122
|
|
|
$content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1medias/\4\5', $content, -1, $nbrep); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
dol_syslog("dolWebsiteOutput end"); |
|
127
|
|
|
|
|
128
|
|
|
print $content; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Format img tags to introduce viewimage on img src. |
|
134
|
|
|
* |
|
135
|
|
|
* @param string $content Content string |
|
136
|
|
|
* @return void |
|
137
|
|
|
* @see dolWebsiteOutput |
|
138
|
|
|
*/ |
|
139
|
|
|
/* |
|
140
|
|
|
function dolWebsiteSaveContent($content) |
|
141
|
|
|
{ |
|
142
|
|
|
global $db, $langs, $conf, $user; |
|
143
|
|
|
global $dolibarr_main_url_root, $dolibarr_main_data_root; |
|
144
|
|
|
|
|
145
|
|
|
//dol_syslog("dolWebsiteSaveContent start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')'); |
|
146
|
|
|
|
|
147
|
|
|
// Define $urlwithroot |
|
148
|
|
|
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
149
|
|
|
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
150
|
|
|
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
151
|
|
|
|
|
152
|
|
|
//$content = preg_replace('/(<img.*src=")(?!(http|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
153
|
|
|
|
|
154
|
|
|
return $content; |
|
155
|
|
|
} |
|
156
|
|
|
*/ |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Clean an HTML page to report only content, so we can include it into another page. |
|
161
|
|
|
* It outputs content of file sanitized from html and body part. |
|
162
|
|
|
* |
|
163
|
|
|
* @param string $containeralias Path to file to include (must be a page from website root. Example: 'mypage.php' means 'mywebsite/mypage.php') |
|
164
|
|
|
* @return void |
|
165
|
|
|
*/ |
|
166
|
|
|
function includeContainer($containeralias) |
|
167
|
|
|
{ |
|
168
|
|
|
global $conf, $db, $langs, $mysoc, $user, $website; |
|
169
|
|
|
global $includehtmlcontentopened; |
|
170
|
|
|
global $websitekey; |
|
171
|
|
|
|
|
172
|
|
|
$MAXLEVEL=20; |
|
173
|
|
|
|
|
174
|
|
|
if (! preg_match('/\.php$/i', $containeralias)) $containeralias.='.php'; |
|
175
|
|
|
|
|
176
|
|
|
$fullpathfile=DOL_DATA_ROOT.'/website/'.$websitekey.'/'.$containeralias; |
|
177
|
|
|
|
|
178
|
|
|
if (empty($includehtmlcontentopened)) $includehtmlcontentopened=0; |
|
179
|
|
|
$includehtmlcontentopened++; |
|
180
|
|
|
if ($includehtmlcontentopened > $MAXLEVEL) |
|
181
|
|
|
{ |
|
182
|
|
|
print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.$MAXLEVEL.".\n"; |
|
183
|
|
|
return; |
|
184
|
|
|
} |
|
185
|
|
|
// file_get_contents is not possible. We must execute code with include |
|
186
|
|
|
//$content = file_get_contents($fullpathfile); |
|
187
|
|
|
//print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/ |
|
188
|
|
|
|
|
189
|
|
|
ob_start(); |
|
190
|
|
|
$res = include $fullpathfile; // Include because we want to execute code content |
|
191
|
|
|
$tmpoutput = ob_get_contents(); |
|
192
|
|
|
ob_end_clean(); |
|
193
|
|
|
|
|
194
|
|
|
print "\n".'<!-- include '.$fullpathfile.' level = '.$includehtmlcontentopened.' -->'."\n"; |
|
195
|
|
|
print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $tmpoutput); |
|
196
|
|
|
|
|
197
|
|
|
if (! $res) |
|
198
|
|
|
{ |
|
199
|
|
|
print 'ERROR: FAILED TO INCLUDE PAGE '.$containeralias.".\n"; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
$includehtmlcontentopened--; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Download all images found into page content $tmp. |
|
209
|
|
|
* If $modifylinks is set, links to images will be replace with a link to viewimage wrapper. |
|
210
|
|
|
* |
|
211
|
|
|
* @param Website $object Object website |
|
212
|
|
|
* @param WebsitePage $objectpage Object website page |
|
213
|
|
|
* @param string $urltograb URL to grab (exemple: http://www.nltechno.com/ or http://www.nltechno.com/dir1/ or http://www.nltechno.com/dir1/mapage1) |
|
214
|
|
|
* @param string $tmp Content to parse |
|
215
|
|
|
* @param string $action Var $action |
|
216
|
|
|
* @param string $modifylinks 0=Do not modify content, 1=Replace links with a link to viewimage |
|
217
|
|
|
* @return void |
|
218
|
|
|
*/ |
|
219
|
|
|
function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks=0) |
|
220
|
|
|
{ |
|
221
|
|
|
global $conf; |
|
222
|
|
|
|
|
223
|
|
|
$error=0; |
|
224
|
|
|
|
|
225
|
|
|
$alreadygrabbed=array(); |
|
226
|
|
|
|
|
227
|
|
|
if (preg_match('/\/$/', $urltograb)) $urltograb.='.'; |
|
228
|
|
|
$urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1 |
|
229
|
|
|
|
|
230
|
|
|
preg_match_all('/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs); |
|
231
|
|
|
|
|
232
|
|
|
foreach ($regs[0] as $key => $val) |
|
233
|
|
|
{ |
|
234
|
|
|
if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
235
|
|
|
|
|
236
|
|
|
if (preg_match('/^\//', $regs[2][$key])) |
|
237
|
|
|
{ |
|
238
|
|
|
$urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
|
239
|
|
|
$urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
240
|
|
|
} |
|
241
|
|
|
else |
|
242
|
|
|
{ |
|
243
|
|
|
$urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
$linkwithoutdomain = $regs[2][$key]; |
|
247
|
|
|
$filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
|
248
|
|
|
if (preg_match('/^http/', $regs[2][$key])) |
|
249
|
|
|
{ |
|
250
|
|
|
$urltograbbis = $regs[2][$key]; |
|
251
|
|
|
$linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]); |
|
252
|
|
|
$filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
256
|
|
|
|
|
257
|
|
|
// Clean the aa/bb/../cc into aa/cc |
|
258
|
|
|
$filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave); |
|
259
|
|
|
$filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename); |
|
260
|
|
|
|
|
261
|
|
|
//var_dump($filetosave); |
|
262
|
|
|
//var_dump($filename); |
|
263
|
|
|
//exit; |
|
264
|
|
|
|
|
265
|
|
|
if (empty($alreadygrabbed[$urltograbbis])) |
|
266
|
|
|
{ |
|
267
|
|
|
$tmpgeturl = getURLContent($urltograbbis); |
|
268
|
|
|
if ($tmpgeturl['curl_error_no']) |
|
269
|
|
|
{ |
|
270
|
|
|
$error++; |
|
271
|
|
|
setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
|
272
|
|
|
$action='create'; |
|
273
|
|
|
} |
|
274
|
|
|
elseif ($tmpgeturl['http_code'] != '200') |
|
275
|
|
|
{ |
|
276
|
|
|
$error++; |
|
277
|
|
|
setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
|
278
|
|
|
$action='create'; |
|
279
|
|
|
} |
|
280
|
|
|
else |
|
281
|
|
|
{ |
|
282
|
|
|
$alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
|
283
|
|
|
|
|
284
|
|
|
dol_mkdir(dirname($filetosave)); |
|
285
|
|
|
|
|
286
|
|
|
$fp = fopen($filetosave, "w"); |
|
287
|
|
|
fputs($fp, $tmpgeturl['content']); |
|
288
|
|
|
fclose($fp); |
|
289
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
290
|
|
|
@chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
291
|
|
|
} |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
if ($modifylinks) |
|
295
|
|
|
{ |
|
296
|
|
|
$tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', '<img'.$regs[1][$key].'src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'"'.$regs[3][$key].'>', $tmp); |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
// Search X in "background...url(X)" |
|
301
|
|
|
preg_match_all('/background([^\.\/\(;]+)url\([\"\']?([^\)\"\']*)[\"\']?\)/i', $tmp, $regs); |
|
302
|
|
|
|
|
303
|
|
|
foreach ($regs[0] as $key => $val) |
|
304
|
|
|
{ |
|
305
|
|
|
if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
306
|
|
|
|
|
307
|
|
|
if (preg_match('/^\//', $regs[2][$key])) |
|
308
|
|
|
{ |
|
309
|
|
|
$urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
|
310
|
|
|
$urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
311
|
|
|
} |
|
312
|
|
|
else |
|
313
|
|
|
{ |
|
314
|
|
|
$urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
$linkwithoutdomain = $regs[2][$key]; |
|
318
|
|
|
$filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
|
319
|
|
|
|
|
320
|
|
|
if (preg_match('/^http/', $regs[2][$key])) |
|
321
|
|
|
{ |
|
322
|
|
|
$urltograbbis = $regs[2][$key]; |
|
323
|
|
|
$linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]); |
|
324
|
|
|
$filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
328
|
|
|
|
|
329
|
|
|
// Clean the aa/bb/../cc into aa/cc |
|
330
|
|
|
$filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave); |
|
331
|
|
|
$filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename); |
|
332
|
|
|
|
|
333
|
|
|
//var_dump($filetosave); |
|
334
|
|
|
//var_dump($filename); |
|
335
|
|
|
//exit; |
|
336
|
|
|
|
|
337
|
|
|
if (empty($alreadygrabbed[$urltograbbis])) |
|
338
|
|
|
{ |
|
339
|
|
|
$tmpgeturl = getURLContent($urltograbbis); |
|
340
|
|
|
if ($tmpgeturl['curl_error_no']) |
|
341
|
|
|
{ |
|
342
|
|
|
$error++; |
|
343
|
|
|
setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
|
344
|
|
|
$action='create'; |
|
345
|
|
|
} |
|
346
|
|
|
elseif ($tmpgeturl['http_code'] != '200') |
|
347
|
|
|
{ |
|
348
|
|
|
$error++; |
|
349
|
|
|
setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
|
350
|
|
|
$action='create'; |
|
351
|
|
|
} |
|
352
|
|
|
else |
|
353
|
|
|
{ |
|
354
|
|
|
$alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
|
355
|
|
|
|
|
356
|
|
|
dol_mkdir(dirname($filetosave)); |
|
357
|
|
|
|
|
358
|
|
|
$fp = fopen($filetosave, "w"); |
|
359
|
|
|
fputs($fp, $tmpgeturl['content']); |
|
360
|
|
|
fclose($fp); |
|
361
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
362
|
|
|
@chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
363
|
|
|
} |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
if ($modifylinks) |
|
367
|
|
|
{ |
|
368
|
|
|
$tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp); |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
|
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* Save content of a page on disk |
|
377
|
|
|
* |
|
378
|
|
|
* @param string $filealias Full path of filename to generate |
|
379
|
|
|
* @param Website $object Object website |
|
380
|
|
|
* @param WebsitePage $objectpage Object websitepage |
|
381
|
|
|
* @return boolean True if OK |
|
382
|
|
|
*/ |
|
383
|
|
|
function dolSavePageAlias($filealias, $object, $objectpage) |
|
384
|
|
|
{ |
|
385
|
|
|
global $conf; |
|
386
|
|
|
|
|
387
|
|
|
// Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header) |
|
388
|
|
|
dol_syslog("We regenerate the alias page filealias=".$filealias); |
|
389
|
|
|
|
|
390
|
|
|
$aliascontent = '<?php'."\n"; |
|
391
|
|
|
$aliascontent.= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n"; |
|
392
|
|
|
$aliascontent.= 'global $dolibarr_main_data_root;'."\n"; |
|
393
|
|
|
$aliascontent.= 'if (empty($dolibarr_main_data_root)) require \'./page'.$objectpage->id.'.tpl.php\'; '; |
|
394
|
|
|
$aliascontent.= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n"; |
|
395
|
|
|
$aliascontent.= '?>'."\n"; |
|
396
|
|
|
$result = file_put_contents($filealias, $aliascontent); |
|
397
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
398
|
|
|
@chmod($filealias, octdec($conf->global->MAIN_UMASK)); |
|
399
|
|
|
|
|
400
|
|
|
return ($result?true:false); |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
|
|
404
|
|
|
/** |
|
405
|
|
|
* Save content of a page on disk |
|
406
|
|
|
* |
|
407
|
|
|
* @param string $filetpl Full path of filename to generate |
|
408
|
|
|
* @param Website $object Object website |
|
409
|
|
|
* @param WebsitePage $objectpage Object websitepage |
|
410
|
|
|
* @return boolean True if OK |
|
411
|
|
|
*/ |
|
412
|
|
|
function dolSavePageContent($filetpl, $object, $objectpage) |
|
413
|
|
|
{ |
|
414
|
|
|
global $conf; |
|
415
|
|
|
|
|
416
|
|
|
// Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header) |
|
417
|
|
|
dol_syslog("We regenerate the tpl page filetpl=".$filetpl); |
|
418
|
|
|
|
|
419
|
|
|
dol_delete_file($filetpl); |
|
420
|
|
|
|
|
421
|
|
|
$shortlangcode = ''; |
|
422
|
|
|
if ($objectpage->lang) $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang); // en_US or en-US -> en |
|
423
|
|
|
|
|
424
|
|
|
$tplcontent =''; |
|
425
|
|
|
$tplcontent.= "<?php // BEGIN PHP\n"; |
|
426
|
|
|
$tplcontent.= '$websitekey=basename(dirname(__FILE__));'."\n"; |
|
427
|
|
|
$tplcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n"; |
|
428
|
|
|
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
429
|
|
|
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
430
|
|
|
$tplcontent.= "ob_start();\n"; |
|
431
|
|
|
$tplcontent.= "// END PHP ?>\n"; |
|
432
|
|
|
$tplcontent.= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"':'').'>'."\n"; |
|
433
|
|
|
$tplcontent.= '<head>'."\n"; |
|
434
|
|
|
$tplcontent.= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n"; |
|
435
|
|
|
$tplcontent.= '<meta charset="UTF-8">'."\n"; |
|
436
|
|
|
$tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n"; |
|
437
|
|
|
$tplcontent.= '<meta name="robots" content="index, follow" />'."\n"; |
|
438
|
|
|
$tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; |
|
439
|
|
|
$tplcontent.= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n"; |
|
440
|
|
|
$tplcontent.= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n"; |
|
441
|
|
|
$tplcontent.= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n"; |
|
442
|
|
|
$tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.'" />'."\n"; |
|
443
|
|
|
$tplcontent.= '<!-- Include link to CSS file -->'."\n"; |
|
444
|
|
|
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n"; |
|
445
|
|
|
$tplcontent.= '<!-- Include HTML header from common file -->'."\n"; |
|
446
|
|
|
$tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/website/'.$object->ref.'/htmlheader.html"); ?>'."\n"; |
|
447
|
|
|
$tplcontent.= '<!-- Include HTML header from page inline block -->'."\n"; |
|
448
|
|
|
$tplcontent.= $objectpage->htmlheader."\n"; |
|
449
|
|
|
$tplcontent.= '</head>'."\n"; |
|
450
|
|
|
|
|
451
|
|
|
$tplcontent.= '<!-- File generated by Dolibarr website module editor -->'."\n"; |
|
452
|
|
|
$tplcontent.= '<body id="bodywebsite" class="bodywebsite">'."\n"; |
|
453
|
|
|
$tplcontent.= $objectpage->content."\n"; |
|
454
|
|
|
$tplcontent.= '</body>'."\n"; |
|
455
|
|
|
$tplcontent.= '</html>'."\n"; |
|
456
|
|
|
|
|
457
|
|
|
$tplcontent.= '<?php // BEGIN PHP'."\n"; |
|
458
|
|
|
$tplcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; |
|
459
|
|
|
$tplcontent.= "// END PHP ?>"."\n"; |
|
460
|
|
|
|
|
461
|
|
|
//var_dump($filetpl);exit; |
|
462
|
|
|
$result = file_put_contents($filetpl, $tplcontent); |
|
463
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
464
|
|
|
@chmod($filetpl, octdec($conf->global->MAIN_UMASK)); |
|
465
|
|
|
|
|
466
|
|
|
return $result; |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* Save content of a page on disk |
|
472
|
|
|
* |
|
473
|
|
|
* @param string $filehtmlheader Full path of filename to generate |
|
474
|
|
|
* @param string $htmlheadercontent Content of file |
|
475
|
|
|
* @return boolean True if OK |
|
476
|
|
|
*/ |
|
477
|
|
|
function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent) |
|
478
|
|
|
{ |
|
479
|
|
|
global $conf, $pathofwebsite; |
|
480
|
|
|
|
|
481
|
|
|
dol_syslog("Save html header into ".$filehtmlheader); |
|
482
|
|
|
|
|
483
|
|
|
dol_mkdir($pathofwebsite); |
|
484
|
|
|
$result = file_put_contents($filehtmlheader, $htmlheadercontent); |
|
485
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
486
|
|
|
@chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); |
|
487
|
|
|
|
|
488
|
|
|
if (! $result) |
|
489
|
|
|
{ |
|
490
|
|
|
setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors'); |
|
491
|
|
|
return false; |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
return true; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* Save content of a page on disk |
|
499
|
|
|
* |
|
500
|
|
|
* @param string $filecss Full path of filename to generate |
|
501
|
|
|
* @param string $csscontent Content of file |
|
502
|
|
|
* @return boolean True if OK |
|
503
|
|
|
*/ |
|
504
|
|
|
function dolSaveCssFile($filecss, $csscontent) |
|
505
|
|
|
{ |
|
506
|
|
|
global $conf, $pathofwebsite; |
|
507
|
|
|
|
|
508
|
|
|
dol_syslog("Save css file into ".$filecss); |
|
509
|
|
|
|
|
510
|
|
|
dol_mkdir($pathofwebsite); |
|
511
|
|
|
$result = file_put_contents($filecss, $csscontent); |
|
512
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
513
|
|
|
@chmod($filecss, octdec($conf->global->MAIN_UMASK)); |
|
514
|
|
|
|
|
515
|
|
|
if (! $result) |
|
516
|
|
|
{ |
|
517
|
|
|
setEventMessages('Failed to write file '.$filecss, null, 'errors'); |
|
518
|
|
|
return false; |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
return true; |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
/** |
|
525
|
|
|
* Save content of a page on disk |
|
526
|
|
|
* |
|
527
|
|
|
* @param string $filejs Full path of filename to generate |
|
528
|
|
|
* @param string $jscontent Content of file |
|
529
|
|
|
* @return boolean True if OK |
|
530
|
|
|
*/ |
|
531
|
|
|
function dolSaveJsFile($filejs, $jscontent) |
|
532
|
|
|
{ |
|
533
|
|
|
global $conf, $pathofwebsite; |
|
534
|
|
|
|
|
535
|
|
|
dol_syslog("Save js file into ".$filejs); |
|
536
|
|
|
|
|
537
|
|
|
dol_mkdir($pathofwebsite); |
|
538
|
|
|
$result = file_put_contents($filejs, $jscontent); |
|
539
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
540
|
|
|
@chmod($filejs, octdec($conf->global->MAIN_UMASK)); |
|
541
|
|
|
|
|
542
|
|
|
if (! $result) |
|
543
|
|
|
{ |
|
544
|
|
|
setEventMessages('Failed to write file '.$filejs, null, 'errors'); |
|
545
|
|
|
return false; |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
return true; |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
/** |
|
552
|
|
|
* Save content of a page on disk |
|
553
|
|
|
* |
|
554
|
|
|
* @param string $filerobot Full path of filename to generate |
|
555
|
|
|
* @param string $robotcontent Content of file |
|
556
|
|
|
* @return boolean True if OK |
|
557
|
|
|
*/ |
|
558
|
|
|
function dolSaveRobotFile($filerobot, $robotcontent) |
|
559
|
|
|
{ |
|
560
|
|
|
global $conf, $pathofwebsite; |
|
561
|
|
|
|
|
562
|
|
|
dol_syslog("Save robot file into ".$filerobot); |
|
563
|
|
|
|
|
564
|
|
|
dol_mkdir($pathofwebsite); |
|
565
|
|
|
$result = file_put_contents($filerobot, $robotcontent); |
|
566
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
567
|
|
|
@chmod($filerobot, octdec($conf->global->MAIN_UMASK)); |
|
568
|
|
|
|
|
569
|
|
|
if (! $result) |
|
570
|
|
|
{ |
|
571
|
|
|
setEventMessages('Failed to write file '.$filerobot, null, 'errors'); |
|
572
|
|
|
return false; |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
return true; |
|
576
|
|
|
} |
|
577
|
|
|
|
|
578
|
|
|
/** |
|
579
|
|
|
* Save content of a page on disk |
|
580
|
|
|
* |
|
581
|
|
|
* @param string $filehtaccess Full path of filename to generate |
|
582
|
|
|
* @param string $htaccess Content of file |
|
583
|
|
|
* @return boolean True if OK |
|
584
|
|
|
*/ |
|
585
|
|
|
function dolSaveHtaccessFile($filehtaccess, $htaccess) |
|
586
|
|
|
{ |
|
587
|
|
|
global $conf, $pathofwebsite; |
|
588
|
|
|
|
|
589
|
|
|
dol_syslog("Save htaccess file into ".$filehtaccess); |
|
590
|
|
|
|
|
591
|
|
|
dol_mkdir($pathofwebsite); |
|
592
|
|
|
$result = file_put_contents($filehtaccess, $htaccess); |
|
593
|
|
|
if (! empty($conf->global->MAIN_UMASK)) |
|
594
|
|
|
@chmod($filehtaccess, octdec($conf->global->MAIN_UMASK)); |
|
595
|
|
|
|
|
596
|
|
|
if (! $result) |
|
597
|
|
|
{ |
|
598
|
|
|
setEventMessages('Failed to write file '.$filehtaccess, null, 'errors'); |
|
599
|
|
|
return false; |
|
600
|
|
|
} |
|
601
|
|
|
|
|
602
|
|
|
return true; |
|
603
|
|
|
} |
|
604
|
|
|
|
|
605
|
|
|
|
|
606
|
|
|
|