website2.lib.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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. * \file htdocs/core/lib/website2.lib.php
  19. * \ingroup website
  20. * \brief Library for website module (rare functions not required for execution of website)
  21. */
  22. /**
  23. * Save content of a page on disk
  24. *
  25. * @param string $filemaster Full path of filename master.inc.php for website to generate
  26. * @return boolean True if OK
  27. */
  28. function dolSaveMasterFile($filemaster)
  29. {
  30. global $conf;
  31. // Now generate the master.inc.php page
  32. dol_syslog("We regenerate the master file");
  33. dol_delete_file($filemaster);
  34. $mastercontent = '<?php'."\n";
  35. $mastercontent .= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n";
  36. $mastercontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
  37. $mastercontent .= '?>'."\n";
  38. $result = file_put_contents($filemaster, $mastercontent);
  39. if (!empty($conf->global->MAIN_UMASK))
  40. @chmod($filemaster, octdec($conf->global->MAIN_UMASK));
  41. return $result;
  42. }
  43. /**
  44. * Save content of a page on disk.
  45. * It can save file into root directory or into language subdirectory.
  46. *
  47. * @param string $filealias Full path of filename to generate
  48. * @param Website $object Object website
  49. * @param WebsitePage $objectpage Object websitepage
  50. * @return boolean True if OK
  51. * @see dolSavePageContent()
  52. */
  53. function dolSavePageAlias($filealias, $object, $objectpage)
  54. {
  55. global $conf;
  56. // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
  57. dol_syslog("dolSavePageAlias We regenerate the alias page filealias=".$filealias);
  58. $aliascontent = '<?php'."\n";
  59. $aliascontent .= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n";
  60. $aliascontent .= 'global $dolibarr_main_data_root;'."\n";
  61. $aliascontent .= 'if (empty($dolibarr_main_data_root)) require \'./page'.$objectpage->id.'.tpl.php\'; ';
  62. $aliascontent .= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n";
  63. $aliascontent .= '?>'."\n";
  64. $result = file_put_contents($filealias, $aliascontent);
  65. if ($result === false) {
  66. dol_syslog("Failed to write file ".$filealias, LOG_WARNING);
  67. }
  68. if (!empty($conf->global->MAIN_UMASK)) {
  69. @chmod($filealias, octdec($conf->global->MAIN_UMASK));
  70. }
  71. // Save also alias into language subdirectory if we have to
  72. if ($objectpage->lang && in_array($objectpage->lang, explode(',', $object->otherlang))) {
  73. $dirname = dirname($filealias);
  74. $filename = basename($filealias);
  75. $filealias = $dirname.'/'.$objectpage->lang.'/'.$filename;
  76. $aliascontent = '<?php'."\n";
  77. $aliascontent .= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n";
  78. $aliascontent .= 'global $dolibarr_main_data_root;'."\n";
  79. $aliascontent .= 'if (empty($dolibarr_main_data_root)) require \'../page'.$objectpage->id.'.tpl.php\'; ';
  80. $aliascontent .= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n";
  81. $aliascontent .= '?>'."\n";
  82. $result = file_put_contents($filealias, $aliascontent);
  83. if ($result === false) {
  84. dol_syslog("Failed to write file ".$filealias, LOG_WARNING);
  85. }
  86. if (!empty($conf->global->MAIN_UMASK)) {
  87. @chmod($filealias, octdec($conf->global->MAIN_UMASK));
  88. }
  89. }
  90. return ($result ?true:false);
  91. }
  92. /**
  93. * Save content of a page on disk.
  94. * Page contents are always saved into root directory.
  95. *
  96. * @param string $filetpl Full path of filename to generate
  97. * @param Website $object Object website
  98. * @param WebsitePage $objectpage Object websitepage
  99. * @return boolean True if OK
  100. * @see dolSavePageAlias()
  101. */
  102. function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
  103. {
  104. global $conf, $db;
  105. // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
  106. dol_syslog("We regenerate the tpl page filetpl=".$filetpl);
  107. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  108. dol_delete_file($filetpl);
  109. $shortlangcode = '';
  110. if ($objectpage->lang) $shortlangcode = substr($objectpage->lang, 0, 2); // en_US or en-US -> en
  111. $tplcontent = '';
  112. $tplcontent .= "<?php // BEGIN PHP\n";
  113. $tplcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
  114. $tplcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) {\n";
  115. $tplcontent .= ' $pathdepth = count(explode(\'/\', $_SERVER[\'SCRIPT_NAME\'])) - 2;'."\n";
  116. $tplcontent .= ' require_once ($pathdepth ? str_repeat(\'../\', $pathdepth) : \'./\').\'master.inc.php\';'."\n";
  117. $tplcontent .= "} // Not already loaded\n";
  118. $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  119. $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  120. $tplcontent .= "ob_start();\n";
  121. $tplcontent .= "// END PHP ?>\n";
  122. if (!empty($conf->global->WEBSITE_FORCE_DOCTYPE_HTML5))
  123. {
  124. $tplcontent .= "<!DOCTYPE html>\n";
  125. }
  126. $tplcontent .= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"' : '').'>'."\n";
  127. $tplcontent .= '<head>'."\n";
  128. $tplcontent .= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n";
  129. $tplcontent .= '<meta charset="utf-8">'."\n";
  130. $tplcontent .= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
  131. $tplcontent .= '<meta name="robots" content="index, follow" />'."\n";
  132. $tplcontent .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
  133. $tplcontent .= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n";
  134. $tplcontent .= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n";
  135. $tplcontent .= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n";
  136. $tplcontent .= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.' (https://www.dolibarr.org)" />'."\n";
  137. $tplcontent .= '<meta name="dolibarr:pageid" content="'.dol_string_nohtmltag($objectpage->id).'" />'."\n";
  138. // Add translation reference (main language)
  139. if ($object->isMultiLang()) {
  140. // Add myself
  141. $tplcontent .= '<link rel="alternate" hreflang="'.$shortlangcode.'" href="'.(($object->fk_default_home == $objectpage->id) ? '/' : (($shortlangcode != substr($object->lang, 0, 2) ? '/'.$shortlangcode : '')).'/'.$objectpage->pageurl.'.php').'" />'."\n";
  142. // Add page "translation of"
  143. $translationof = $objectpage->fk_page;
  144. if ($translationof) {
  145. $tmppage = new WebsitePage($db);
  146. $tmppage->fetch($translationof);
  147. if ($tmppage->id > 0) {
  148. $tmpshortlangcode = '';
  149. if ($tmppage->lang) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
  150. if ($tmpshortlangcode != $shortlangcode) {
  151. $tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2) ? '/'.$tmpshortlangcode : '')).'/'.$tmppage->pageurl.'.php').'" />'."\n";
  152. }
  153. }
  154. }
  155. // Add "has translation pages"
  156. $sql = 'SELECT rowid as id, lang, pageurl from '.MAIN_DB_PREFIX.'website_page where fk_page IN ('.$objectpage->id.($translationof ? ", ".$translationof : "").")";
  157. $resql = $db->query($sql);
  158. if ($resql)
  159. {
  160. $num_rows = $db->num_rows($resql);
  161. if ($num_rows > 0)
  162. {
  163. while ($obj = $db->fetch_object($resql))
  164. {
  165. $tmpshortlangcode = '';
  166. if ($obj->lang) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $obj->lang); // en_US or en-US -> en
  167. if ($tmpshortlangcode != $shortlangcode) {
  168. $tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $obj->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2) ? '/'.$tmpshortlangcode : '')).'/'.$obj->pageurl.'.php').'" />'."\n";
  169. }
  170. }
  171. }
  172. }
  173. else dol_print_error($db);
  174. }
  175. // Add canonical reference
  176. $tplcontent .= '<link href="'.(($objectpage->id == $object->fk_default_home) ? '/' : (($shortlangcode != substr($object->lang, 0, 2) ? '/'.$shortlangcode : '').'/'.$objectpage->pageurl.'.php')).'" rel="canonical" />'."\n";
  177. // Add manifest.json on homepage
  178. $tplcontent .= '<?php if ($website->use_manifest) { print \'<link rel="manifest" href="/manifest.json.php" />\'."\n"; } ?>'."\n";
  179. $tplcontent .= '<!-- Include link to CSS file -->'."\n";
  180. $tplcontent .= '<link rel="stylesheet" href="/styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n";
  181. $tplcontent .= '<!-- Include HTML header from common file -->'."\n";
  182. $tplcontent .= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n";
  183. $tplcontent .= '<!-- Include HTML header from page header block -->'."\n";
  184. $tplcontent .= preg_replace('/<\/?html>/ims', '', $objectpage->htmlheader)."\n";
  185. $tplcontent .= '</head>'."\n";
  186. $tplcontent .= '<!-- File generated by Dolibarr website module editor -->'."\n";
  187. $tplcontent .= '<body id="bodywebsite" class="bodywebsite bodywebpage-'.$objectpage->ref.'">'."\n";
  188. $tplcontent .= $objectpage->content."\n";
  189. $tplcontent .= '</body>'."\n";
  190. $tplcontent .= '</html>'."\n";
  191. $tplcontent .= '<?php // BEGIN PHP'."\n";
  192. $tplcontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$objectpage->id.');'."\n";
  193. $tplcontent .= "// END PHP ?>\n";
  194. //var_dump($filetpl);exit;
  195. $result = file_put_contents($filetpl, $tplcontent);
  196. if (!empty($conf->global->MAIN_UMASK))
  197. @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
  198. return $result;
  199. }
  200. /**
  201. * Save content of the index.php and wrapper.php page
  202. *
  203. * @param string $pathofwebsite Path of website root
  204. * @param string $fileindex Full path of file index.php
  205. * @param string $filetpl File tpl to index.php page redirect to
  206. * @param string $filewrapper Full path of file wrapper.php
  207. * @return boolean True if OK
  208. */
  209. function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
  210. {
  211. global $conf;
  212. $result1 = false;
  213. $result2 = false;
  214. dol_mkdir($pathofwebsite);
  215. dol_delete_file($fileindex);
  216. $indexcontent = '<?php'."\n";
  217. $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";
  218. $indexcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
  219. $indexcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n";
  220. $indexcontent .= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n";
  221. $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  222. $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  223. $indexcontent .= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);'."\n";
  224. $indexcontent .= "}\n";
  225. $indexcontent .= "include_once './".basename($filetpl)."'\n";
  226. $indexcontent .= '// END PHP ?>'."\n";
  227. $result1 = file_put_contents($fileindex, $indexcontent);
  228. if (!empty($conf->global->MAIN_UMASK)) {
  229. @chmod($fileindex, octdec($conf->global->MAIN_UMASK));
  230. }
  231. dol_delete_file($filewrapper);
  232. $wrappercontent = file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.php');
  233. $result2 = file_put_contents($filewrapper, $wrappercontent);
  234. if (!empty($conf->global->MAIN_UMASK)) {
  235. @chmod($filewrapper, octdec($conf->global->MAIN_UMASK));
  236. }
  237. return ($result1 && $result2);
  238. }
  239. /**
  240. * Save content of a page on disk
  241. *
  242. * @param string $filehtmlheader Full path of filename to generate
  243. * @param string $htmlheadercontent Content of file
  244. * @return boolean True if OK
  245. */
  246. function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent)
  247. {
  248. global $conf, $pathofwebsite;
  249. dol_syslog("Save html header into ".$filehtmlheader);
  250. dol_mkdir($pathofwebsite);
  251. $result = file_put_contents($filehtmlheader, $htmlheadercontent);
  252. if (!empty($conf->global->MAIN_UMASK))
  253. @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK));
  254. return $result;
  255. }
  256. /**
  257. * Save content of a page on disk
  258. *
  259. * @param string $filecss Full path of filename to generate
  260. * @param string $csscontent Content of file
  261. * @return boolean True if OK
  262. */
  263. function dolSaveCssFile($filecss, $csscontent)
  264. {
  265. global $conf, $pathofwebsite;
  266. dol_syslog("Save css file into ".$filecss);
  267. dol_mkdir($pathofwebsite);
  268. $result = file_put_contents($filecss, $csscontent);
  269. if (!empty($conf->global->MAIN_UMASK))
  270. @chmod($filecss, octdec($conf->global->MAIN_UMASK));
  271. return $result;
  272. }
  273. /**
  274. * Save content of a page on disk
  275. *
  276. * @param string $filejs Full path of filename to generate
  277. * @param string $jscontent Content of file
  278. * @return boolean True if OK
  279. */
  280. function dolSaveJsFile($filejs, $jscontent)
  281. {
  282. global $conf, $pathofwebsite;
  283. dol_syslog("Save js file into ".$filejs);
  284. dol_mkdir($pathofwebsite);
  285. $result = file_put_contents($filejs, $jscontent);
  286. if (!empty($conf->global->MAIN_UMASK))
  287. @chmod($filejs, octdec($conf->global->MAIN_UMASK));
  288. return $result;
  289. }
  290. /**
  291. * Save content of a page on disk
  292. *
  293. * @param string $filerobot Full path of filename to generate
  294. * @param string $robotcontent Content of file
  295. * @return boolean True if OK
  296. */
  297. function dolSaveRobotFile($filerobot, $robotcontent)
  298. {
  299. global $conf, $pathofwebsite;
  300. dol_syslog("Save robot file into ".$filerobot);
  301. dol_mkdir($pathofwebsite);
  302. $result = file_put_contents($filerobot, $robotcontent);
  303. if (!empty($conf->global->MAIN_UMASK))
  304. @chmod($filerobot, octdec($conf->global->MAIN_UMASK));
  305. return $result;
  306. }
  307. /**
  308. * Save content of a page on disk
  309. *
  310. * @param string $filehtaccess Full path of filename to generate
  311. * @param string $htaccess Content of file
  312. * @return boolean True if OK
  313. */
  314. function dolSaveHtaccessFile($filehtaccess, $htaccess)
  315. {
  316. global $conf, $pathofwebsite;
  317. dol_syslog("Save htaccess file into ".$filehtaccess);
  318. dol_mkdir($pathofwebsite);
  319. $result = file_put_contents($filehtaccess, $htaccess);
  320. if (!empty($conf->global->MAIN_UMASK))
  321. @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK));
  322. return $result;
  323. }
  324. /**
  325. * Save content of a page on disk
  326. *
  327. * @param string $file Full path of filename to generate
  328. * @param string $content Content of file
  329. * @return boolean True if OK
  330. */
  331. function dolSaveManifestJson($file, $content)
  332. {
  333. global $conf, $pathofwebsite;
  334. dol_syslog("Save manifest.js.php file into ".$file);
  335. dol_mkdir($pathofwebsite);
  336. $result = file_put_contents($file, $content);
  337. if (!empty($conf->global->MAIN_UMASK))
  338. @chmod($file, octdec($conf->global->MAIN_UMASK));
  339. return $result;
  340. }
  341. /**
  342. * Save content of a page on disk
  343. *
  344. * @param string $file Full path of filename to generate
  345. * @param string $content Content of file
  346. * @return boolean True if OK
  347. */
  348. function dolSaveReadme($file, $content)
  349. {
  350. global $conf, $pathofwebsite;
  351. dol_syslog("Save README.md file into ".$file);
  352. dol_mkdir($pathofwebsite);
  353. $result = file_put_contents($file, $content);
  354. if (!empty($conf->global->MAIN_UMASK))
  355. @chmod($file, octdec($conf->global->MAIN_UMASK));
  356. return $result;
  357. }
  358. /**
  359. * Show list of themes. Show all thumbs of themes/skins
  360. *
  361. * @param Website $website Object website to load the tempalte into
  362. * @return void
  363. */
  364. function showWebsiteTemplates(Website $website)
  365. {
  366. global $conf, $langs, $db, $form;
  367. $dirthemes = array('/doctemplates/websites');
  368. if (!empty($conf->modules_parts['websitetemplates'])) // Using this feature slow down application
  369. {
  370. foreach ($conf->modules_parts['websitetemplates'] as $reldir)
  371. {
  372. $dirthemes = array_merge($dirthemes, (array) ($reldir.'doctemplates/websites'));
  373. }
  374. }
  375. $dirthemes = array_unique($dirthemes);
  376. // Now dir_themes=array('/themes') or dir_themes=array('/theme','/mymodule/theme')
  377. $colspan = 2;
  378. print '<!-- For to import website template -->'."\n";
  379. print '<table class="noborder centpercent">';
  380. // Title
  381. print '<tr class="liste_titre"><th class="titlefield">';
  382. print $form->textwithpicto($langs->trans("Templates"), $langs->trans("ThemeDir").' : '.join(", ", $dirthemes));
  383. print '</th>';
  384. print '<th class="right">';
  385. $url = 'https://www.dolistore.com/43-web-site-templates';
  386. print '<a href="'.$url.'" target="_blank">';
  387. print $langs->trans('DownloadMoreSkins');
  388. print '</a>';
  389. print '</th></tr>';
  390. print '<tr><td colspan="'.$colspan.'">';
  391. print '<table class="nobordernopadding" width="100%"><tr><td><div class="center">';
  392. if (count($dirthemes)) {
  393. $i = 0;
  394. foreach ($dirthemes as $dir)
  395. {
  396. //print $dirroot.$dir;exit;
  397. $dirtheme = DOL_DATA_ROOT.$dir; // This include loop on $conf->file->dol_document_root
  398. if (is_dir($dirtheme))
  399. {
  400. $handle = opendir($dirtheme);
  401. if (is_resource($handle))
  402. {
  403. while (($subdir = readdir($handle)) !== false)
  404. {
  405. if (is_file($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.'
  406. && substr($subdir, 0, 3) <> 'CVS' && preg_match('/\.zip$/i', $subdir))
  407. {
  408. $subdirwithoutzip = preg_replace('/\.zip$/i', '', $subdir);
  409. // Disable not stable themes (dir ends with _exp or _dev)
  410. if ($conf->global->MAIN_FEATURES_LEVEL < 2 && preg_match('/_dev$/i', $subdir)) continue;
  411. if ($conf->global->MAIN_FEATURES_LEVEL < 1 && preg_match('/_exp$/i', $subdir)) continue;
  412. print '<div class="inline-block" style="margin-top: 10px; margin-bottom: 10px; margin-right: 20px; margin-left: 20px;">';
  413. $file = $dirtheme."/".$subdirwithoutzip.".jpg";
  414. $url = DOL_URL_ROOT.'/viewimage.php?modulepart=doctemplateswebsite&file='.$subdirwithoutzip.".jpg";
  415. if (!file_exists($file)) $url = DOL_URL_ROOT.'/public/theme/common/nophoto.png';
  416. $originalfile = basename($file);
  417. $entity = $conf->entity;
  418. $modulepart = 'doctemplateswebsite';
  419. $cache = '';
  420. $title = $file;
  421. $ret = '';
  422. $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 1, '&entity='.$entity);
  423. if (!empty($urladvanced)) $ret .= '<a class="'.$urladvanced['css'].'" target="'.$urladvanced['target'].'" mime="'.$urladvanced['mime'].'" href="'.$urladvanced['url'].'">';
  424. else $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
  425. print $ret;
  426. print '<img class="img-skinthumb shadow" src="'.$url.'" border="0" alt="'.$title.'" title="'.$title.'" style="margin-bottom: 5px;">';
  427. print '</a>';
  428. print '<br>';
  429. print $subdir.' ('.dol_print_size(dol_filesize($dirtheme."/".$subdir), 1, 1).')';
  430. print '<br><a href="'.$_SERVER["PHP_SELF"].'?action=importsiteconfirm&website='.$website->ref.'&templateuserfile='.$subdir.'" class="button">'.$langs->trans("Load").'</a>';
  431. print '</div>';
  432. $i++;
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. else {
  440. print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
  441. }
  442. print '</div></td></tr></table>';
  443. print '</td></tr>';
  444. print '</table>';
  445. }