dolibarr  16.0.5
website2.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
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 <https://www.gnu.org/licenses/>.
16  */
17 
32 function dolSaveMasterFile($filemaster)
33 {
34  global $conf;
35 
36  // Now generate the master.inc.php page
37  dol_syslog("We regenerate the master file");
38  dol_delete_file($filemaster);
39 
40  $mastercontent = '<?php'."\n";
41  $mastercontent .= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n";
42  $mastercontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) {\n";
43  $mastercontent .= " if (! defined('USEEXTERNALSERVER')) define('USEEXTERNALSERVER', 1);\n";
44  $mastercontent .= " require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
45  $mastercontent .= "}\n";
46  $mastercontent .= '?>'."\n";
47  $result = file_put_contents($filemaster, $mastercontent);
48  if (!empty($conf->global->MAIN_UMASK)) {
49  @chmod($filemaster, octdec($conf->global->MAIN_UMASK));
50  }
51 
52  return $result;
53 }
54 
65 function dolSavePageAlias($filealias, $object, $objectpage)
66 {
67  global $conf;
68 
69  // Now create the .tpl file
70  dol_syslog("dolSavePageAlias We regenerate the alias page filealias=".$filealias);
71 
72  $aliascontent = '<?php'."\n";
73  $aliascontent .= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n";
74  $aliascontent .= 'global $dolibarr_main_data_root;'."\n";
75  $aliascontent .= 'if (empty($dolibarr_main_data_root)) require \'./page'.$objectpage->id.'.tpl.php\'; ';
76  $aliascontent .= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n";
77  $aliascontent .= '?>'."\n";
78  $result = file_put_contents($filealias, $aliascontent);
79  if ($result === false) {
80  dol_syslog("Failed to write file ".$filealias, LOG_WARNING);
81  }
82  if (!empty($conf->global->MAIN_UMASK)) {
83  @chmod($filealias, octdec($conf->global->MAIN_UMASK));
84  }
85 
86  // Save also alias into language subdirectory if it is not a main language
87  if ($objectpage->lang && in_array($objectpage->lang, explode(',', $object->otherlang))) {
88  $dirname = dirname($filealias);
89  $filename = basename($filealias);
90  $filealiassub = $dirname.'/'.$objectpage->lang.'/'.$filename;
91 
92  $aliascontent = '<?php'."\n";
93  $aliascontent .= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n";
94  $aliascontent .= 'global $dolibarr_main_data_root;'."\n";
95  $aliascontent .= 'if (empty($dolibarr_main_data_root)) require \'../page'.$objectpage->id.'.tpl.php\'; ';
96  $aliascontent .= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n";
97  $aliascontent .= '?>'."\n";
98  $result = file_put_contents($filealiassub, $aliascontent);
99  if ($result === false) {
100  dol_syslog("Failed to write file ".$filealiassub, LOG_WARNING);
101  }
102  if (!empty($conf->global->MAIN_UMASK)) {
103  @chmod($filealiassub, octdec($conf->global->MAIN_UMASK));
104  }
105  } elseif (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
106  // Save also alias into all language subdirectories if it is a main language
107  if (empty($conf->global->WEBSITE_DISABLE_MAIN_LANGUAGE_INTO_LANGSUBDIR) && !empty($object->otherlang)) {
108  $dirname = dirname($filealias);
109  $filename = basename($filealias);
110  foreach (explode(',', $object->otherlang) as $sublang) {
111  // Avoid to erase main alias file if $sublang is empty string
112  if (empty(trim($sublang))) continue;
113  $filealiassub = $dirname.'/'.$sublang.'/'.$filename;
114 
115  $aliascontent = '<?php'."\n";
116  $aliascontent .= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n";
117  $aliascontent .= 'global $dolibarr_main_data_root;'."\n";
118  $aliascontent .= 'if (empty($dolibarr_main_data_root)) require \'../page'.$objectpage->id.'.tpl.php\'; ';
119  $aliascontent .= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n";
120  $aliascontent .= '?>'."\n";
121  $result = file_put_contents($filealiassub, $aliascontent);
122  if ($result === false) {
123  dol_syslog("Failed to write file ".$filealiassub, LOG_WARNING);
124  }
125  if (!empty($conf->global->MAIN_UMASK)) {
126  @chmod($filealiassub, octdec($conf->global->MAIN_UMASK));
127  }
128  }
129  }
130  }
131 
132  return ($result ?true:false);
133 }
134 
135 
147 function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold = 0)
148 {
149  global $conf, $db;
150 
151  // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
152  dol_syslog("dolSavePageContent We regenerate the tpl page filetpl=".$filetpl);
153 
154  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
155 
156  if (dol_is_file($filetpl)) {
157  if ($backupold) {
158  dol_delete_file($filetpl.'.old');
159  $result = dol_move($filetpl, $filetpl.'.old', 0, 1, 0, 0);
160  if (! $result) {
161  return false;
162  }
163  } else {
164  dol_delete_file($filetpl);
165  }
166  }
167 
168  $shortlangcode = '';
169  if ($objectpage->lang) {
170  $shortlangcode = substr($objectpage->lang, 0, 2); // en_US or en-US -> en
171  }
172  if (empty($shortlangcode)) {
173  $shortlangcode = substr($object->lang, 0, 2); // en_US or en-US -> en
174  }
175 
176  $tplcontent = '';
177  $tplcontent .= "<?php // BEGIN PHP\n";
178  $tplcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
179  $tplcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) {\n";
180  $tplcontent .= ' $pathdepth = count(explode(\'/\', $_SERVER[\'SCRIPT_NAME\'])) - 2;'."\n";
181  $tplcontent .= ' require_once ($pathdepth ? str_repeat(\'../\', $pathdepth) : \'./\').\'master.inc.php\';'."\n";
182  $tplcontent .= "} // Not already loaded\n";
183  $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
184  $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
185  $tplcontent .= "ob_start();\n";
186  $tplcontent .= "// END PHP ?>\n";
187  if (!empty($conf->global->WEBSITE_FORCE_DOCTYPE_HTML5)) {
188  $tplcontent .= "<!DOCTYPE html>\n";
189  }
190  $tplcontent .= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"' : '').'>'."\n";
191  $tplcontent .= '<head>'."\n";
192  $tplcontent .= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n";
193  $tplcontent .= '<meta charset="utf-8">'."\n";
194  $tplcontent .= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
195  $tplcontent .= '<meta name="robots" content="index, follow" />'."\n";
196  $tplcontent .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
197  $tplcontent .= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n";
198  $tplcontent .= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n";
199  $tplcontent .= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n";
200  $tplcontent .= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.' (https://www.dolibarr.org)" />'."\n";
201  $tplcontent .= '<meta name="dolibarr:pageid" content="'.dol_string_nohtmltag($objectpage->id).'" />'."\n";
202  // Add canonical reference
203  if ($object->virtualhost) {
204  $tplcontent .= '<link rel="canonical" href="'.(($objectpage->id == $object->fk_default_home) ? '/' : (($shortlangcode != substr($object->lang, 0, 2) ? '/'.$shortlangcode : '').'/'.$objectpage->pageurl.'.php')).'" />'."\n";
205  }
206  // Add translation reference (main language)
207  if ($object->isMultiLang()) {
208  // Add page "translation of"
209  $translationof = $objectpage->fk_page;
210  if ($translationof) {
211  $tmppage = new WebsitePage($db);
212  $tmppage->fetch($translationof);
213  if ($tmppage->id > 0) {
214  $tmpshortlangcode = '';
215  if ($tmppage->lang) {
216  $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
217  }
218  if (empty($tmpshortlangcode)) {
219  $tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en
220  }
221  if ($tmpshortlangcode != $shortlangcode) {
222  $tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2)) ? '/'.$tmpshortlangcode : '').'/'.$tmppage->pageurl.'.php').'" />'."\n";
223  }
224  }
225  }
226 
227  // Add "has translation pages"
228  $sql = "SELECT rowid as id, lang, pageurl from ".MAIN_DB_PREFIX.'website_page where fk_page IN ('.$db->sanitize($objectpage->id.($translationof ? ", ".$translationof : '')).")";
229  $resql = $db->query($sql);
230  if ($resql) {
231  $num_rows = $db->num_rows($resql);
232  if ($num_rows > 0) {
233  while ($obj = $db->fetch_object($resql)) {
234  $tmpshortlangcode = '';
235  if ($obj->lang) {
236  $tmpshortlangcode = preg_replace('/[_-].*$/', '', $obj->lang); // en_US or en-US -> en
237  }
238  if ($tmpshortlangcode != $shortlangcode) {
239  $tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $obj->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2) ? '/'.$tmpshortlangcode : '')).'/'.$obj->pageurl.'.php').'" />'."\n";
240  }
241  }
242  }
243  } else {
244  dol_print_error($db);
245  }
246 
247  // Add myself
248  $tplcontent .= '<?php if ($_SERVER["PHP_SELF"] == "'.(($object->fk_default_home == $objectpage->id) ? '/' : (($shortlangcode != substr($object->lang, 0, 2)) ? '/'.$shortlangcode : '')).'/'.$objectpage->pageurl.'.php") { ?>'."\n";
249  $tplcontent .= '<link rel="alternate" hreflang="'.$shortlangcode.'" href="'.(($object->fk_default_home == $objectpage->id) ? '/' : (($shortlangcode != substr($object->lang, 0, 2)) ? '/'.$shortlangcode : '').'/'.$objectpage->pageurl.'.php').'" />'."\n";
250 
251  $tplcontent .= '<?php } ?>'."\n";
252  }
253  // Add manifest.json. Do we have to add it only on home page ?
254  $tplcontent .= '<?php if ($website->use_manifest) { print \'<link rel="manifest" href="/manifest.json.php" />\'."\n"; } ?>'."\n";
255  $tplcontent .= '<!-- Include link to CSS file -->'."\n";
256  // Add js
257  $tplcontent .= '<link rel="stylesheet" href="/styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n";
258  $tplcontent .= '<!-- Include link to JS file -->'."\n";
259  $tplcontent .= '<script async src="/javascript.js.php"></script>'."\n";
260  // Add headers
261  $tplcontent .= '<!-- Include HTML header from common file -->'."\n";
262  $tplcontent .= '<?php if (file_exists(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")) include DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html"; ?>'."\n";
263  $tplcontent .= '<!-- Include HTML header from page header block -->'."\n";
264  $tplcontent .= preg_replace('/<\/?html>/ims', '', $objectpage->htmlheader)."\n";
265  $tplcontent .= '</head>'."\n";
266 
267  $tplcontent .= '<!-- File generated by Dolibarr website module editor -->'."\n";
268  $tplcontent .= '<body id="bodywebsite" class="bodywebsite bodywebpage-'.$objectpage->ref.'">'."\n";
269  $tplcontent .= $objectpage->content."\n";
270  $tplcontent .= '</body>'."\n";
271  $tplcontent .= '</html>'."\n";
272 
273  $tplcontent .= '<?php // BEGIN PHP'."\n";
274  $tplcontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$objectpage->id.');'."\n";
275  $tplcontent .= "// END PHP ?>\n";
276 
277  //var_dump($filetpl);exit;
278  $result = file_put_contents($filetpl, $tplcontent);
279  if (!empty($conf->global->MAIN_UMASK)) {
280  @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
281  }
282 
283  return $result;
284 }
285 
286 
297 function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object = null)
298 {
299  global $conf, $db;
300 
301  $result1 = false;
302  $result2 = false;
303 
304  dol_mkdir($pathofwebsite);
305 
306  if ($fileindex) {
307  dol_delete_file($fileindex);
308  $indexcontent = '<?php'."\n";
309  $indexcontent .= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n";
310  $indexcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
311  $indexcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n";
312  $indexcontent .= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n";
313  $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
314  $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
315  $indexcontent .= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);'."\n";
316  $indexcontent .= "}\n";
317  $indexcontent .= "include_once './".basename($filetpl)."'\n";
318  $indexcontent .= '// END PHP ?>'."\n";
319 
320  $result1 = file_put_contents($fileindex, $indexcontent);
321  if (!empty($conf->global->MAIN_UMASK)) {
322  @chmod($fileindex, octdec($conf->global->MAIN_UMASK));
323  }
324 
325  if (is_object($object) && $object->fk_default_home > 0) {
326  $objectpage = new WebsitePage($db);
327  $objectpage->fetch($object->fk_default_home);
328 
329  // Create a version for sublanguages
330  if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
331  if (empty($conf->global->WEBSITE_DISABLE_MAIN_LANGUAGE_INTO_LANGSUBDIR) && is_object($object) && !empty($object->otherlang)) {
332  $dirname = dirname($fileindex);
333  foreach (explode(',', $object->otherlang) as $sublang) {
334  // Avoid to erase main alias file if $sublang is empty string
335  if (empty(trim($sublang))) continue;
336  $fileindexsub = $dirname.'/'.$sublang.'/index.php';
337 
338  // Same indexcontent than previously but with ../ instead of ./ for master and tpl file include/require_once.
339  $relpath = '..';
340  $indexcontent = '<?php'."\n";
341  $indexcontent .= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n";
342  $indexcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
343  $indexcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once '".$relpath."/master.inc.php'; } // Load master if not already loaded\n";
344  $indexcontent .= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n";
345  $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
346  $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
347  $indexcontent .= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);'."\n";
348  $indexcontent .= "}\n";
349  $indexcontent .= "include_once '".$relpath."/".basename($filetpl)."'\n"; // use .. instead of .
350  $indexcontent .= '// END PHP ?>'."\n";
351  $result = file_put_contents($fileindexsub, $indexcontent);
352  if ($result === false) {
353  dol_syslog("Failed to write file ".$fileindexsub, LOG_WARNING);
354  }
355  if (!empty($conf->global->MAIN_UMASK)) {
356  @chmod($fileindexsub, octdec($conf->global->MAIN_UMASK));
357  }
358  }
359  }
360  }
361  }
362  } else {
363  $result1 = true;
364  }
365 
366  if ($filewrapper) {
367  dol_delete_file($filewrapper);
368  $wrappercontent = file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.php');
369 
370  $result2 = file_put_contents($filewrapper, $wrappercontent);
371  if (!empty($conf->global->MAIN_UMASK)) {
372  @chmod($filewrapper, octdec($conf->global->MAIN_UMASK));
373  }
374  } else {
375  $result2 = true;
376  }
377 
378  return ($result1 && $result2);
379 }
380 
381 
389 function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent)
390 {
391  global $conf, $pathofwebsite;
392 
393  dol_syslog("Save html header into ".$filehtmlheader);
394 
395  dol_mkdir($pathofwebsite);
396  $result = file_put_contents($filehtmlheader, $htmlheadercontent);
397  if (!empty($conf->global->MAIN_UMASK)) {
398  @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK));
399  }
400 
401  return $result;
402 }
403 
411 function dolSaveCssFile($filecss, $csscontent)
412 {
413  global $conf, $pathofwebsite;
414 
415  dol_syslog("Save css file into ".$filecss);
416 
417  dol_mkdir($pathofwebsite);
418  $result = file_put_contents($filecss, $csscontent);
419  if (!empty($conf->global->MAIN_UMASK)) {
420  @chmod($filecss, octdec($conf->global->MAIN_UMASK));
421  }
422 
423  return $result;
424 }
425 
433 function dolSaveJsFile($filejs, $jscontent)
434 {
435  global $conf, $pathofwebsite;
436 
437  dol_syslog("Save js file into ".$filejs);
438 
439  dol_mkdir($pathofwebsite);
440  $result = file_put_contents($filejs, $jscontent);
441  if (!empty($conf->global->MAIN_UMASK)) {
442  @chmod($filejs, octdec($conf->global->MAIN_UMASK));
443  }
444 
445  return $result;
446 }
447 
455 function dolSaveRobotFile($filerobot, $robotcontent)
456 {
457  global $conf, $pathofwebsite;
458 
459  dol_syslog("Save robot file into ".$filerobot);
460 
461  dol_mkdir($pathofwebsite);
462  $result = file_put_contents($filerobot, $robotcontent);
463  if (!empty($conf->global->MAIN_UMASK)) {
464  @chmod($filerobot, octdec($conf->global->MAIN_UMASK));
465  }
466 
467  return $result;
468 }
469 
477 function dolSaveHtaccessFile($filehtaccess, $htaccess)
478 {
479  global $conf, $pathofwebsite;
480 
481  dol_syslog("Save htaccess file into ".$filehtaccess);
482 
483  dol_mkdir($pathofwebsite);
484  $result = file_put_contents($filehtaccess, $htaccess);
485  if (!empty($conf->global->MAIN_UMASK)) {
486  @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK));
487  }
488 
489  return $result;
490 }
491 
499 function dolSaveManifestJson($file, $content)
500 {
501  global $conf, $pathofwebsite;
502 
503  dol_syslog("Save manifest.js.php file into ".$file);
504 
505  dol_mkdir($pathofwebsite);
506  $result = file_put_contents($file, $content);
507  if (!empty($conf->global->MAIN_UMASK)) {
508  @chmod($file, octdec($conf->global->MAIN_UMASK));
509  }
510 
511  return $result;
512 }
513 
521 function dolSaveReadme($file, $content)
522 {
523  global $conf, $pathofwebsite;
524 
525  dol_syslog("Save README.md file into ".$file);
526 
527  dol_mkdir($pathofwebsite);
528  $result = file_put_contents($file, $content);
529  if (!empty($conf->global->MAIN_UMASK)) {
530  @chmod($file, octdec($conf->global->MAIN_UMASK));
531  }
532 
533  return $result;
534 }
535 
536 
543 function showWebsiteTemplates(Website $website)
544 {
545  global $conf, $langs, $db, $form;
546 
547  $dirthemes = array('/doctemplates/websites');
548  if (!empty($conf->modules_parts['websitetemplates'])) { // Using this feature slow down application
549  foreach ($conf->modules_parts['websitetemplates'] as $reldir) {
550  $dirthemes = array_merge($dirthemes, (array) ($reldir.'doctemplates/websites'));
551  }
552  }
553  $dirthemes = array_unique($dirthemes);
554  // Now dir_themes=array('/themes') or dir_themes=array('/theme','/mymodule/theme')
555 
556  $colspan = 2;
557 
558  print '<!-- For website template import -->'."\n";
559  print '<table class="noborder centpercent">';
560 
561  // Title
562  print '<tr class="liste_titre"><th class="titlefield">';
563  print $form->textwithpicto($langs->trans("Templates"), $langs->trans("ThemeDir").' : '.join(", ", $dirthemes));
564  print '</th>';
565  print '<th class="right">';
566  $url = 'https://www.dolistore.com/43-web-site-templates';
567  print '<a href="'.$url.'" target="_blank" rel="noopener noreferrer external">';
568  print $langs->trans('DownloadMoreSkins');
569  print '</a>';
570  print '</th></tr>';
571 
572  print '<tr><td colspan="'.$colspan.'">';
573 
574  print '<table class="nobordernopadding" width="100%"><tr><td><div class="center">';
575 
576  if (count($dirthemes)) {
577  $i = 0;
578  foreach ($dirthemes as $dir) {
579  //print $dirroot.$dir;exit;
580  $dirtheme = DOL_DATA_ROOT.$dir; // This include loop on $conf->file->dol_document_root
581  if (is_dir($dirtheme)) {
582  $handle = opendir($dirtheme);
583  if (is_resource($handle)) {
584  while (($subdir = readdir($handle)) !== false) {
585  if (is_file($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.'
586  && substr($subdir, 0, 3) <> 'CVS' && preg_match('/\.zip$/i', $subdir)) {
587  $subdirwithoutzip = preg_replace('/\.zip$/i', '', $subdir);
588 
589  // Disable not stable themes (dir ends with _exp or _dev)
590  if ($conf->global->MAIN_FEATURES_LEVEL < 2 && preg_match('/_dev$/i', $subdir)) {
591  continue;
592  }
593  if ($conf->global->MAIN_FEATURES_LEVEL < 1 && preg_match('/_exp$/i', $subdir)) {
594  continue;
595  }
596 
597  print '<div class="inline-block" style="margin-top: 10px; margin-bottom: 10px; margin-right: 20px; margin-left: 20px;">';
598 
599  $file = $dirtheme."/".$subdirwithoutzip.".jpg";
600  $url = DOL_URL_ROOT.'/viewimage.php?modulepart=doctemplateswebsite&file='.$subdirwithoutzip.".jpg";
601 
602  if (!file_exists($file)) {
603  $url = DOL_URL_ROOT.'/public/theme/common/nophoto.png';
604  }
605 
606  $originalfile = basename($file);
607  $entity = $conf->entity;
608  $modulepart = 'doctemplateswebsite';
609  $cache = '';
610  $title = $file;
611 
612  $ret = '';
613  $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 1, '&entity='.$entity);
614  if (!empty($urladvanced)) {
615  $ret .= '<a class="'.$urladvanced['css'].'" target="'.$urladvanced['target'].'" mime="'.$urladvanced['mime'].'" href="'.$urladvanced['url'].'">';
616  } else {
617  $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
618  }
619  print $ret;
620  print '<img class="img-skinthumb shadow" src="'.$url.'" border="0" alt="'.$title.'" title="'.$title.'" style="margin-bottom: 5px;">';
621  print '</a>';
622 
623  print '<br>';
624  print $subdir.' ('.dol_print_size(dol_filesize($dirtheme."/".$subdir), 1, 1).')';
625  print '<br><a href="'.$_SERVER["PHP_SELF"].'?action=importsiteconfirm&website='.$website->ref.'&templateuserfile='.$subdir.'" class="button">'.$langs->trans("Load").'</a>';
626  print '</div>';
627 
628  $i++;
629  }
630  }
631  }
632  }
633  }
634  } else {
635  print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
636  }
637 
638  print '</div></td></tr></table>';
639 
640  print '</td></tr>';
641  print '</table>';
642 }
643 
644 
652 function checkPHPCode($phpfullcodestringold, $phpfullcodestring)
653 {
654  global $conf, $langs, $user;
655 
656  $error = 0;
657 
658  if (empty($phpfullcodestringold) && empty($phpfullcodestring)) {
659  return 0;
660  }
661 
662  // First check forbidden commands
663  $forbiddenphpcommands = array();
664  if (empty($conf->global->WEBSITE_PHP_ALLOW_EXEC)) { // If option is not on, we disallow functions to execute commands
665  $forbiddenphpcommands = array("exec", "passthru", "shell_exec", "system", "proc_open", "popen", "eval", "dol_eval", "executeCLI");
666  }
667  if (empty($conf->global->WEBSITE_PHP_ALLOW_WRITE)) { // If option is not on, we disallow functions to write files
668  $forbiddenphpcommands = array_merge($forbiddenphpcommands, array("fopen", "file_put_contents", "fputs", "fputscsv", "fwrite", "fpassthru", "unlink", "mkdir", "rmdir", "symlink", "touch", "umask"));
669  }
670  foreach ($forbiddenphpcommands as $forbiddenphpcommand) {
671  if (preg_match('/'.$forbiddenphpcommand.'\s*\(/ms', $phpfullcodestring)) {
672  $error++;
673  setEventMessages($langs->trans("DynamicPHPCodeContainsAForbiddenInstruction", $forbiddenphpcommand), null, 'errors');
674  break;
675  }
676  }
677  // This char can be used to execute RCE for example using with echo `ls`
678  $forbiddenphpchars = array();
679  if (empty($conf->global->WEBSITE_PHP_ALLOW_DANGEROUS_CHARS)) { // If option is not on, we disallow functions to execute commands
680  $forbiddenphpchars = array("`");
681  }
682  foreach ($forbiddenphpchars as $forbiddenphpchar) {
683  if (preg_match('/'.$forbiddenphpchar.'/ms', $phpfullcodestring)) {
684  $error++;
685  setEventMessages($langs->trans("DynamicPHPCodeContainsAForbiddenInstruction", $forbiddenphpchar), null, 'errors');
686  break;
687  }
688  }
689  // Check dynamic functions $xxx(
690  if (preg_match('/\$[a-z0-9_]+\(/ims', $phpfullcodestring)) {
691  $error++;
692  setEventMessages($langs->trans("DynamicPHPCodeContainsAForbiddenInstruction", '$...('), null, 'errors');
693  }
694 
695  if (!$error && empty($user->rights->website->writephp)) {
696  if ($phpfullcodestringold != $phpfullcodestring) {
697  $error++;
698  setEventMessages($langs->trans("NotAllowedToAddDynamicContent"), null, 'errors');
699  }
700  }
701 
702  return $error;
703 }
dolSavePageContent
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).
Definition: website2.lib.php:147
WebsitePage
Class Websitepage.
Definition: websitepage.class.php:36
dolSaveManifestJson
dolSaveManifestJson($file, $content)
Save content of a page on disk.
Definition: website2.lib.php:499
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dolSaveMasterFile
dolSaveMasterFile($filemaster)
Save content of a page on disk.
Definition: website2.lib.php:32
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:477
dolSaveRobotFile
dolSaveRobotFile($filerobot, $robotcontent)
Save content of a page on disk.
Definition: website2.lib.php:455
dolSaveIndexPage
dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object=null)
Save content of the index.php and/or the wrapper.php page.
Definition: website2.lib.php:297
dolSaveHtaccessFile
dolSaveHtaccessFile($filehtaccess, $htaccess)
Save content of a page on disk.
Definition: website2.lib.php:477
dol_delete_file
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1231
getAdvancedPreviewUrl
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
Definition: functions.lib.php:9646
dolSaveCssFile
dolSaveCssFile($filecss, $csscontent)
Save content of a page on disk.
Definition: website2.lib.php:411
dolSaveHtmlHeader
dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent)
Save content of a page on disk.
Definition: website2.lib.php:389
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_print_size
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
Definition: functions.lib.php:2884
Website
Class Website.
Definition: website.class.php:36
dol_filesize
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:581
dolSavePageAlias
dolSavePageAlias($filealias, $object, $objectpage)
Save an alias page on disk (A page that include the reference page).
Definition: website2.lib.php:65
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
showWebsiteTemplates
showWebsiteTemplates(Website $website)
Show list of themes.
Definition: website2.lib.php:543
checkPHPCode
checkPHPCode($phpfullcodestringold, $phpfullcodestring)
checkPHPCode
Definition: website2.lib.php:652
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
dolSaveReadme
dolSaveReadme($file, $content)
Save content of a page on disk.
Definition: website2.lib.php:521
dolSaveJsFile
dolSaveJsFile($filejs, $jscontent)
Save content of a page on disk.
Definition: website2.lib.php:433
dol_move
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
Definition: files.lib.php:855