20$websitekey = basename(__DIR__);
21if (strpos($_SERVER[
"PHP_SELF"],
'website/samples/wrapper.php')) {
22 die(
"Sample file for website module. Can't be called directly.");
24if (!defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
25 require_once
'./master.inc.php';
32include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
37$hashp =
GETPOST(
'hashp',
'aZ09');
38$extname =
GETPOST(
'extname',
'alpha', 1);
39$modulepart =
GETPOST(
'modulepart',
'aZ09');
41$original_file =
GETPOST(
"file",
"alpha");
44if ($limit <= 0 || $limit > 100) {
51 $original_file =
'blog'.(($limit > 0 && $limit <= 100) ?
'-'.$limit :
'').(preg_match(
'/^[a-z][a-z](_[A-Z][A-Z])?$/', $l) ?
'-'.$l :
'').
'-'.$websitekey.
'.rss.cache';
56 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
57 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
59 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
61 $tmp = explode(
'/', $ecmfile->filepath, 2);
63 if (is_numeric($tmp[0])) {
64 $tmp = explode(
'/', $tmp[1], 2);
66 $moduleparttocheck = $tmp[0];
69 if ($moduleparttocheck == $modulepart) {
71 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
77 header(
"X-Content-Type-Options: nosniff");
81 header(
"X-Frame-Options: SAMEORIGIN");
84 http_response_code(401);
85 print
'Bad link. File is from another module part.';
89 $modulepart = $moduleparttocheck;
90 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
100 header(
"X-Content-Type-Options: nosniff");
104 header(
"X-Frame-Options: SAMEORIGIN");
107 http_response_code(404);
108 print
"ErrorFileNotFoundWithSharedLink";
115if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
118if (GETPOSTISSET(
"attachment")) {
119 $attachment = (
GETPOST(
"attachment",
'alphanohtml') ? true :
false);
126$type =
'application/octet-stream';
127if (GETPOSTISSET(
'type')) {
128 $type =
GETPOST(
'type',
'alpha');
134$original_file = str_replace(
"../",
"/", $original_file);
138$cachestring =
GETPOST(
"cache",
'aZ09');
139$cachedelay =
GETPOSTINT(
'cachedelay') ?
GETPOSTINT(
'cachedelay') : ((is_numeric($cachestring) && (int) $cachestring > 1 && (int) $cachestring < 999999) ? $cachestring :
'3600');
142 header(
'Cache-Control: max-age='.$cachedelay.
', public, must-revalidate');
143 header(
'Pragma: cache');
144 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + (
int) $cachedelay).
' GMT');
147$refname = basename(dirname($original_file).
"/");
153 $filename = $original_file;
154 $dir_temp = (string) $conf->website->dir_temp;
156 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
157 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
159 $websitepage =
new WebsitePage($db);
161 $website->fetch(0, $websitekey);
163 $filters = array(
'type_container' =>
'blogpost',
'status' =>
'1');
165 $filters[
'lang'] = (string) $l;
169 $arrayofblogs = $websitepage->fetchAll($website->id,
'DESC',
'date_creation', $MAXNEWS, 0, $filters);
170 $eventarray = array();
171 if (is_array($arrayofblogs)) {
172 foreach ($arrayofblogs as $blog) {
173 $blog->fullpageurl = $website->virtualhost.
'/'.$blog->pageurl.
'.php';
174 $blog->image = preg_replace(
'/__WEBSITE_KEY__/', $websitekey, $blog->image);
176 $eventarray[] = $blog;
180 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
181 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
182 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
184 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachestring=".$cachestring.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
189 $filename = $format.
'.'.$extension;
194 $outputfile = $dir_temp.
'/'.$filename;
202 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
204 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
211 $outputlangs->setDefaultLang($l);
212 $outputlangs->loadLangs(array(
"main",
"other"));
213 $title = $outputlangs->transnoentities(
'LatestBlogPosts').
' - '.$website->virtualhost;
214 $desc = $title.($l ?
' ('.$l.
')' :
'');
217 $outputfiletmp = tempnam($dir_temp,
'tmp');
221 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp,
'', $website->virtualhost.
'/wrapper.php?rss=1'.($l ?
'&l='.$l :
''), $l);
224 if (
dol_move($outputfiletmp, $outputfile,
'0', 1, 0, 0)) {
227 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
228 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
231 http_response_code(500);
236 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
238 $langs->load(
"errors");
240 http_response_code(500);
241 print $langs->trans(
"ErrorFailToCreateFile", $outputfile);
247 if (GETPOSTISSET(
"attachment")) {
248 $attachment =
GETPOST(
"attachment");
251 $contenttype =
'application/rss+xml';
252 if (GETPOSTISSET(
"contenttype")) {
253 $contenttype =
GETPOST(
"contenttype");
256 $outputencoding =
'UTF-8';
259 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
262 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
269 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
271 header(
'Cache-Control: private, must-revalidate');
275 $outputfile = $dir_temp.
'/'.$filename;
276 $result = readfile($outputfile);
278 print
'File '.$outputfile.
' was empty.';
283} elseif ($modulepart ==
"mycompany" && preg_match(
'/^\/?logos\//', $original_file)) {
285 readfile(
dol_osencode($conf->mycompany->dir_output.
"/".$original_file));
288 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
290 $accessallowed = empty($check_access[
'accessallowed']) ?
'' : $check_access[
'accessallowed'];
291 $sqlprotectagainstexternals = empty($check_access[
'sqlprotectagainstexternals']) ?
'' : $check_access[
'sqlprotectagainstexternals'];
292 $fullpath_original_file = empty($check_access[
'original_file']) ?
'' : $check_access[
'original_file'];
295 $sqlprotectagainstexternals =
'';
300 if (!$accessallowed) {
301 http_response_code(403);
302 print
'Access forbidden';
313 $filename = basename($fullpath_original_file);
316 dol_syslog(
"wrapper.php download $fullpath_original_file filename=$filename content-type=$type");
317 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
320 if (!file_exists($fullpath_original_file_osencoded)) {
321 http_response_code(404);
322 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
328 header(
'Content-Type: '.$type);
329 header(
'Content-Description: File Transfer');
331 header(
'Content-Encoding: '.$encoding);
335 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
337 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
339 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
341 readfile($fullpath_original_file_osencoded);
Class to manage ECM files.
Class to manage translations.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a 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.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_is_file($pathoffile)
Return if path is a file.
dol_now($mode='gmt')
Return date for now.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dolChmod($filepath, $newmask='')
Change mod of a file.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='')
Build a file from an array of events.