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 18/** 19 * \file htdocs/core/lib/website2.lib.php 20 * \ingroup website 21 * \brief Library for website module (rare functions not required for execution of website) 22 */ 23 24 25 26/** 27 * Save content of a page on disk 28 * 29 * @param string $filemaster Full path of filename master.inc.php for website to generate 30 * @return boolean True if OK 31 */ 32function 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 55/** 56 * Save an alias page on disk (A page that include the reference page). 57 * It saves file into the root directory but also into language subdirectory. 58 * 59 * @param string $filealias Full path of filename to generate 60 * @param Website $object Object website 61 * @param WebsitePage $objectpage Object websitepage 62 * @return boolean True if OK 63 * @see dolSavePageContent() 64 */ 65function 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 136/** 137 * Save content of a page on disk (page name is generally ID_of_page.php). 138 * Page contents are always saved into "root" directory. Only aliases pages saved with dolSavePageAlias() can be in root or language subdir. 139 * 140 * @param string $filetpl Full path of filename to generate 141 * @param Website $object Object website 142 * @param WebsitePage $objectpage Object websitepage 143 * @param int $backupold 1=Make a backup of old page 144 * @return boolean True if OK 145 * @see dolSavePageAlias() 146 */ 147function 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("We regenerate the tpl page filetpl=".$filetpl); 153 154 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; 155 156 if ($backupold) { 157 dol_delete_file($filetpl.'.old'); 158 $result = dol_move($filetpl, $filetpl.'.old', 0, 1, 0, 0); 159 if (! $result) { 160 return false; 161 } 162 } else { 163 dol_delete_file($filetpl); 164 } 165 166 $shortlangcode = ''; 167 if ($objectpage->lang) { 168 $shortlangcode = substr($objectpage->lang, 0, 2); // en_US or en-US -> en 169 } 170 if (empty($shortlangcode)) { 171 $shortlangcode = substr($object->lang, 0, 2); // en_US or en-US -> en 172 } 173 174 $tplcontent = ''; 175 $tplcontent .= "<?php // BEGIN PHP\n"; 176 $tplcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; 177 $tplcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) {\n"; 178 $tplcontent .= ' $pathdepth = count(explode(\'/\', $_SERVER[\'SCRIPT_NAME\'])) - 2;'."\n"; 179 $tplcontent .= ' require_once ($pathdepth ? str_repeat(\'../\', $pathdepth) : \'./\').\'master.inc.php\';'."\n"; 180 $tplcontent .= "} // Not already loaded\n"; 181 $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; 182 $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; 183 $tplcontent .= "ob_start();\n"; 184 $tplcontent .= "// END PHP ?>\n"; 185 if (!empty($conf->global->WEBSITE_FORCE_DOCTYPE_HTML5)) { 186 $tplcontent .= "<!DOCTYPE html>\n"; 187 } 188 $tplcontent .= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"' : '').'>'."\n"; 189 $tplcontent .= '<head>'."\n"; 190 $tplcontent .= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n"; 191 $tplcontent .= '<meta charset="utf-8">'."\n"; 192 $tplcontent .= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n"; 193 $tplcontent .= '<meta name="robots" content="index, follow" />'."\n"; 194 $tplcontent .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; 195 $tplcontent .= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n"; 196 $tplcontent .= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n"; 197 $tplcontent .= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n"; 198 $tplcontent .= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.' (https://www.dolibarr.org)" />'."\n"; 199 $tplcontent .= '<meta name="dolibarr:pageid" content="'.dol_string_nohtmltag($objectpage->id).'" />'."\n"; 200 // Add canonical reference 201 if ($object->virtualhost) { 202 $tplcontent .= '<link rel="canonical" href="'.(($objectpage->id == $object->fk_default_home) ? '/' : (($shortlangcode != substr($object->lang, 0, 2) ? '/'.$shortlangcode : '').'/'.$objectpage->pageurl.'.php')).'" />'."\n"; 203 } 204 // Add translation reference (main language) 205 if ($object->isMultiLang()) { 206 // Add page "translation of" 207 $translationof = $objectpage->fk_page; 208 if ($translationof) { 209 $tmppage = new WebsitePage($db); 210 $tmppage->fetch($translationof); 211 if ($tmppage->id > 0) { 212 $tmpshortlangcode = ''; 213 if ($tmppage->lang) { 214 $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en 215 } 216 if (empty($tmpshortlangcode)) { 217 $tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en 218 } 219 if ($tmpshortlangcode != $shortlangcode) { 220 $tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2)) ? '/'.$tmpshortlangcode : '').'/'.$tmppage->pageurl.'.php').'" />'."\n"; 221 } 222 } 223 } 224 225 // Add "has translation pages" 226 $sql = 'SELECT rowid as id, lang, pageurl from '.MAIN_DB_PREFIX.'website_page where fk_page IN ('.$db->sanitize($objectpage->id.($translationof ? ', '.$translationof : '')).")"; 227 $resql = $db->query($sql); 228 if ($resql) { 229 $num_rows = $db->num_rows($resql); 230 if ($num_rows > 0) { 231 while ($obj = $db->fetch_object($resql)) { 232 $tmpshortlangcode = ''; 233 if ($obj->lang) { 234 $tmpshortlangcode = preg_replace('/[_-].*$/', '', $obj->lang); // en_US or en-US -> en 235 } 236 if ($tmpshortlangcode != $shortlangcode) { 237 $tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $obj->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2) ? '/'.$tmpshortlangcode : '')).'/'.$obj->pageurl.'.php').'" />'."\n"; 238 } 239 } 240 } 241 } else { 242 dol_print_error($db); 243 } 244 245 // Add myself 246 $tplcontent .= '<?php if ($_SERVER["PHP_SELF"] == "'.(($object->fk_default_home == $objectpage->id) ? '/' : (($shortlangcode != substr($object->lang, 0, 2)) ? '/'.$shortlangcode : '')).'/'.$objectpage->pageurl.'.php") { ?>'."\n"; 247 $tplcontent .= '<link rel="alternate" hreflang="'.$shortlangcode.'" href="'.(($object->fk_default_home == $objectpage->id) ? '/' : (($shortlangcode != substr($object->lang, 0, 2)) ? '/'.$shortlangcode : '').'/'.$objectpage->pageurl.'.php').'" />'."\n"; 248 249 $tplcontent .= '<?php } ?>'."\n"; 250 } 251 // Add manifest.json. Do we have to add it only on home page ? 252 $tplcontent .= '<?php if ($website->use_manifest) { print \'<link rel="manifest" href="/manifest.json.php" />\'."\n"; } ?>'."\n"; 253 $tplcontent .= '<!-- Include link to CSS file -->'."\n"; 254 // Add js 255 $tplcontent .= '<link rel="stylesheet" href="/styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n"; 256 $tplcontent .= '<!-- Include link to JS file -->'."\n"; 257 $tplcontent .= '<script async src="/javascript.js.php"></script>'."\n"; 258 // Add headers 259 $tplcontent .= '<!-- Include HTML header from common file -->'."\n"; 260 $tplcontent .= '<?php if (file_exists(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")) include DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html"; ?>'."\n"; 261 $tplcontent .= '<!-- Include HTML header from page header block -->'."\n"; 262 $tplcontent .= preg_replace('/<\/?html>/ims', '', $objectpage->htmlheader)."\n"; 263 $tplcontent .= '</head>'."\n"; 264 265 $tplcontent .= '<!-- File generated by Dolibarr website module editor -->'."\n"; 266 $tplcontent .= '<body id="bodywebsite" class="bodywebsite bodywebpage-'.$objectpage->ref.'">'."\n"; 267 $tplcontent .= $objectpage->content."\n"; 268 $tplcontent .= '</body>'."\n"; 269 $tplcontent .= '</html>'."\n"; 270 271 $tplcontent .= '<?php // BEGIN PHP'."\n"; 272 $tplcontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$objectpage->id.');'."\n"; 273 $tplcontent .= "// END PHP ?>\n"; 274 275 //var_dump($filetpl);exit; 276 $result = file_put_contents($filetpl, $tplcontent); 277 if (!empty($conf->global->MAIN_UMASK)) { 278 @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); 279 } 280 281 return $result; 282} 283 284 285/** 286 * Save content of the index.php and/or the wrapper.php page 287 * 288 * @param string $pathofwebsite Path of website root 289 * @param string $fileindex Full path of file index.php 290 * @param string $filetpl File tpl the index.php page redirect to (used only if $fileindex is provided) 291 * @param string $filewrapper Full path of file wrapper.php 292 * @return boolean True if OK 293 */ 294function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper) 295{ 296 global $conf; 297 298 $result1 = false; 299 $result2 = false; 300 301 dol_mkdir($pathofwebsite); 302 303 if ($fileindex) { 304 dol_delete_file($fileindex); 305 $indexcontent = '<?php'."\n"; 306 $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"; 307 $indexcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; 308 $indexcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n"; 309 $indexcontent .= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n"; 310 $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; 311 $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; 312 $indexcontent .= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);'."\n"; 313 $indexcontent .= "}\n"; 314 $indexcontent .= "include_once './".basename($filetpl)."'\n"; 315 $indexcontent .= '// END PHP ?>'."\n"; 316 317 $result1 = file_put_contents($fileindex, $indexcontent); 318 if (!empty($conf->global->MAIN_UMASK)) { 319 @chmod($fileindex, octdec($conf->global->MAIN_UMASK)); 320 } 321 } else { 322 $result1 = true; 323 } 324 325 if ($filewrapper) { 326 dol_delete_file($filewrapper); 327 $wrappercontent = file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.php'); 328 329 $result2 = file_put_contents($filewrapper, $wrappercontent); 330 if (!empty($conf->global->MAIN_UMASK)) { 331 @chmod($filewrapper, octdec($conf->global->MAIN_UMASK)); 332 } 333 } else { 334 $result2 = true; 335 } 336 337 return ($result1 && $result2); 338} 339 340 341/** 342 * Save content of a page on disk 343 * 344 * @param string $filehtmlheader Full path of filename to generate 345 * @param string $htmlheadercontent Content of file 346 * @return boolean True if OK 347 */ 348function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent) 349{ 350 global $conf, $pathofwebsite; 351 352 dol_syslog("Save html header into ".$filehtmlheader); 353 354 dol_mkdir($pathofwebsite); 355 $result = file_put_contents($filehtmlheader, $htmlheadercontent); 356 if (!empty($conf->global->MAIN_UMASK)) { 357 @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); 358 } 359 360 return $result; 361} 362 363/** 364 * Save content of a page on disk 365 * 366 * @param string $filecss Full path of filename to generate 367 * @param string $csscontent Content of file 368 * @return boolean True if OK 369 */ 370function dolSaveCssFile($filecss, $csscontent) 371{ 372 global $conf, $pathofwebsite; 373 374 dol_syslog("Save css file into ".$filecss); 375 376 dol_mkdir($pathofwebsite); 377 $result = file_put_contents($filecss, $csscontent); 378 if (!empty($conf->global->MAIN_UMASK)) { 379 @chmod($filecss, octdec($conf->global->MAIN_UMASK)); 380 } 381 382 return $result; 383} 384 385/** 386 * Save content of a page on disk. For example into documents/website/mywebsite/javascript.js.php file. 387 * 388 * @param string $filejs Full path of filename to generate 389 * @param string $jscontent Content of file 390 * @return boolean True if OK 391 */ 392function dolSaveJsFile($filejs, $jscontent) 393{ 394 global $conf, $pathofwebsite; 395 396 dol_syslog("Save js file into ".$filejs); 397 398 dol_mkdir($pathofwebsite); 399 $result = file_put_contents($filejs, $jscontent); 400 if (!empty($conf->global->MAIN_UMASK)) { 401 @chmod($filejs, octdec($conf->global->MAIN_UMASK)); 402 } 403 404 return $result; 405} 406 407/** 408 * Save content of a page on disk 409 * 410 * @param string $filerobot Full path of filename to generate 411 * @param string $robotcontent Content of file 412 * @return boolean True if OK 413 */ 414function dolSaveRobotFile($filerobot, $robotcontent) 415{ 416 global $conf, $pathofwebsite; 417 418 dol_syslog("Save robot file into ".$filerobot); 419 420 dol_mkdir($pathofwebsite); 421 $result = file_put_contents($filerobot, $robotcontent); 422 if (!empty($conf->global->MAIN_UMASK)) { 423 @chmod($filerobot, octdec($conf->global->MAIN_UMASK)); 424 } 425 426 return $result; 427} 428 429/** 430 * Save content of a page on disk 431 * 432 * @param string $filehtaccess Full path of filename to generate 433 * @param string $htaccess Content of file 434 * @return boolean True if OK 435 */ 436function dolSaveHtaccessFile($filehtaccess, $htaccess) 437{ 438 global $conf, $pathofwebsite; 439 440 dol_syslog("Save htaccess file into ".$filehtaccess); 441 442 dol_mkdir($pathofwebsite); 443 $result = file_put_contents($filehtaccess, $htaccess); 444 if (!empty($conf->global->MAIN_UMASK)) { 445 @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK)); 446 } 447 448 return $result; 449} 450 451/** 452 * Save content of a page on disk 453 * 454 * @param string $file Full path of filename to generate 455 * @param string $content Content of file 456 * @return boolean True if OK 457 */ 458function dolSaveManifestJson($file, $content) 459{ 460 global $conf, $pathofwebsite; 461 462 dol_syslog("Save manifest.js.php file into ".$file); 463 464 dol_mkdir($pathofwebsite); 465 $result = file_put_contents($file, $content); 466 if (!empty($conf->global->MAIN_UMASK)) { 467 @chmod($file, octdec($conf->global->MAIN_UMASK)); 468 } 469 470 return $result; 471} 472 473/** 474 * Save content of a page on disk 475 * 476 * @param string $file Full path of filename to generate 477 * @param string $content Content of file 478 * @return boolean True if OK 479 */ 480function dolSaveReadme($file, $content) 481{ 482 global $conf, $pathofwebsite; 483 484 dol_syslog("Save README.md file into ".$file); 485 486 dol_mkdir($pathofwebsite); 487 $result = file_put_contents($file, $content); 488 if (!empty($conf->global->MAIN_UMASK)) { 489 @chmod($file, octdec($conf->global->MAIN_UMASK)); 490 } 491 492 return $result; 493} 494 495 496/** 497 * Show list of themes. Show all thumbs of themes/skins 498 * 499 * @param Website $website Object website to load the template into 500 * @return void 501 */ 502function showWebsiteTemplates(Website $website) 503{ 504 global $conf, $langs, $db, $form; 505 506 $dirthemes = array('/doctemplates/websites'); 507 if (!empty($conf->modules_parts['websitetemplates'])) { // Using this feature slow down application 508 foreach ($conf->modules_parts['websitetemplates'] as $reldir) { 509 $dirthemes = array_merge($dirthemes, (array) ($reldir.'doctemplates/websites')); 510 } 511 } 512 $dirthemes = array_unique($dirthemes); 513 // Now dir_themes=array('/themes') or dir_themes=array('/theme','/mymodule/theme') 514 515 $colspan = 2; 516 517 print '<!-- For website template import -->'."\n"; 518 print '<table class="noborder centpercent">'; 519 520 // Title 521 print '<tr class="liste_titre"><th class="titlefield">'; 522 print $form->textwithpicto($langs->trans("Templates"), $langs->trans("ThemeDir").' : '.join(", ", $dirthemes)); 523 print '</th>'; 524 print '<th class="right">'; 525 $url = 'https://www.dolistore.com/43-web-site-templates'; 526 print '<a href="'.$url.'" target="_blank">'; 527 print $langs->trans('DownloadMoreSkins'); 528 print '</a>'; 529 print '</th></tr>'; 530 531 print '<tr><td colspan="'.$colspan.'">'; 532 533 print '<table class="nobordernopadding" width="100%"><tr><td><div class="center">'; 534 535 if (count($dirthemes)) { 536 $i = 0; 537 foreach ($dirthemes as $dir) { 538 //print $dirroot.$dir;exit; 539 $dirtheme = DOL_DATA_ROOT.$dir; // This include loop on $conf->file->dol_document_root 540 if (is_dir($dirtheme)) { 541 $handle = opendir($dirtheme); 542 if (is_resource($handle)) { 543 while (($subdir = readdir($handle)) !== false) { 544 if (is_file($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.' 545 && substr($subdir, 0, 3) <> 'CVS' && preg_match('/\.zip$/i', $subdir)) { 546 $subdirwithoutzip = preg_replace('/\.zip$/i', '', $subdir); 547 548 // Disable not stable themes (dir ends with _exp or _dev) 549 if ($conf->global->MAIN_FEATURES_LEVEL < 2 && preg_match('/_dev$/i', $subdir)) { 550 continue; 551 } 552 if ($conf->global->MAIN_FEATURES_LEVEL < 1 && preg_match('/_exp$/i', $subdir)) { 553 continue; 554 } 555 556 print '<div class="inline-block" style="margin-top: 10px; margin-bottom: 10px; margin-right: 20px; margin-left: 20px;">'; 557 558 $file = $dirtheme."/".$subdirwithoutzip.".jpg"; 559 $url = DOL_URL_ROOT.'/viewimage.php?modulepart=doctemplateswebsite&file='.$subdirwithoutzip.".jpg"; 560 561 if (!file_exists($file)) { 562 $url = DOL_URL_ROOT.'/public/theme/common/nophoto.png'; 563 } 564 565 $originalfile = basename($file); 566 $entity = $conf->entity; 567 $modulepart = 'doctemplateswebsite'; 568 $cache = ''; 569 $title = $file; 570 571 $ret = ''; 572 $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 1, '&entity='.$entity); 573 if (!empty($urladvanced)) { 574 $ret .= '<a class="'.$urladvanced['css'].'" target="'.$urladvanced['target'].'" mime="'.$urladvanced['mime'].'" href="'.$urladvanced['url'].'">'; 575 } else { 576 $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">'; 577 } 578 print $ret; 579 print '<img class="img-skinthumb shadow" src="'.$url.'" border="0" alt="'.$title.'" title="'.$title.'" style="margin-bottom: 5px;">'; 580 print '</a>'; 581 582 print '<br>'; 583 print $subdir.' ('.dol_print_size(dol_filesize($dirtheme."/".$subdir), 1, 1).')'; 584 print '<br><a href="'.$_SERVER["PHP_SELF"].'?action=importsiteconfirm&website='.$website->ref.'&templateuserfile='.$subdir.'" class="button">'.$langs->trans("Load").'</a>'; 585 print '</div>'; 586 587 $i++; 588 } 589 } 590 } 591 } 592 } 593 } else { 594 print '<span class="opacitymedium">'.$langs->trans("None").'</span>'; 595 } 596 597 print '</div></td></tr></table>'; 598 599 print '</td></tr>'; 600 print '</table>'; 601} 602