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';
27include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
32$hashp =
GETPOST(
'hashp',
'aZ09');
33$extname =
GETPOST(
'extname',
'alpha', 1);
34$modulepart =
GETPOST(
'modulepart',
'aZ09');
36$original_file =
GETPOST(
"file",
"alpha");
39if ($limit <= 0 || $limit > 100) {
46 $original_file =
'blog'.(($limit > 0 && $limit <= 100) ?
'-'.$limit :
'').(preg_match(
'/^[a-z][a-z](_[A-Z][A-Z])?$/', $l) ?
'-'.$l :
'').
'-'.$websitekey.
'.rss.cache';
51 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
52 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
54 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
56 $tmp = explode(
'/', $ecmfile->filepath, 2);
58 if (is_numeric($tmp[0])) {
59 $tmp = explode(
'/', $tmp[1], 2);
61 $moduleparttocheck = $tmp[0];
64 if ($moduleparttocheck == $modulepart) {
66 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
72 header(
"X-Content-Type-Options: nosniff");
76 header(
"X-Frame-Options: SAMEORIGIN");
79 http_response_code(401);
80 print
'Bad link. File is from another module part.';
84 $modulepart = $moduleparttocheck;
85 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
95 header(
"X-Content-Type-Options: nosniff");
99 header(
"X-Frame-Options: SAMEORIGIN");
102 http_response_code(404);
103 print
"ErrorFileNotFoundWithSharedLink";
110if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
113if (GETPOSTISSET(
"attachment")) {
114 $attachment = (
GETPOST(
"attachment",
'alphanohtml') ? true :
false);
121$type =
'application/octet-stream';
122if (GETPOSTISSET(
'type')) {
123 $type =
GETPOST(
'type',
'alpha');
129$original_file = str_replace(
"../",
"/", $original_file);
133$cachestring =
GETPOST(
"cache",
'aZ09');
134$cachedelay =
GETPOSTINT(
'cachedelay') ?
GETPOSTINT(
'cachedelay') : ((is_numeric($cachestring) && (int) $cachestring > 1 && (int) $cachestring < 999999) ? $cachestring :
'3600');
137 header(
'Cache-Control: max-age='.$cachedelay.
', public, must-revalidate');
138 header(
'Pragma: cache');
139 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + (
int) $cachedelay).
' GMT');
142$refname = basename(dirname($original_file).
"/");
148 $filename = $original_file;
149 $dir_temp =
$conf->website->dir_temp;
151 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
152 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
156 $website->fetch(0, $websitekey);
158 $filters = array(
'type_container' =>
'blogpost',
'status' =>
'1');
160 $filters[
'lang'] = (string) $l;
164 $arrayofblogs = $websitepage->fetchAll($website->id,
'DESC',
'date_creation', $MAXNEWS, 0, $filters);
165 $eventarray = array();
166 if (is_array($arrayofblogs)) {
167 foreach ($arrayofblogs as $blog) {
168 $blog->fullpageurl = $website->virtualhost.
'/'.$blog->pageurl.
'.php';
169 $blog->image = preg_replace(
'/__WEBSITE_KEY__/', $websitekey, $blog->image);
171 $eventarray[] = $blog;
175 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
176 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
177 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
179 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachestring=".$cachestring.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
184 $filename = $format.
'.'.$extension;
189 $outputfile = $dir_temp.
'/'.$filename;
197 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
199 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
206 $outputlangs->setDefaultLang($l);
207 $outputlangs->loadLangs(array(
"main",
"other"));
208 $title = $outputlangs->transnoentities(
'LatestBlogPosts').
' - '.$website->virtualhost;
209 $desc = $title.($l ?
' ('.$l.
')' :
'');
212 $outputfiletmp = tempnam($dir_temp,
'tmp');
216 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp,
'', $website->virtualhost.
'/wrapper.php?rss=1'.($l ?
'&l='.$l :
''), $l);
219 if (
dol_move($outputfiletmp, $outputfile,
'0', 1, 0, 0)) {
222 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
223 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
226 http_response_code(500);
231 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
233 $langs->load(
"errors");
235 http_response_code(500);
236 print $langs->trans(
"ErrorFailToCreateFile", $outputfile);
242 if (GETPOSTISSET(
"attachment")) {
243 $attachment =
GETPOST(
"attachment");
246 $contenttype =
'application/rss+xml';
247 if (GETPOSTISSET(
"contenttype")) {
248 $contenttype =
GETPOST(
"contenttype");
251 $outputencoding =
'UTF-8';
254 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
257 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
264 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
266 header(
'Cache-Control: private, must-revalidate');
270 $outputfile = $dir_temp.
'/'.$filename;
271 $result = readfile($outputfile);
273 print
'File '.$outputfile.
' was empty.';
278} elseif ($modulepart ==
"mycompany" && preg_match(
'/^\/?logos\//', $original_file)) {
283 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
285 $accessallowed = empty($check_access[
'accessallowed']) ?
'' : $check_access[
'accessallowed'];
286 $sqlprotectagainstexternals = empty($check_access[
'sqlprotectagainstexternals']) ?
'' : $check_access[
'sqlprotectagainstexternals'];
287 $fullpath_original_file = empty($check_access[
'original_file']) ?
'' : $check_access[
'original_file'];
290 $sqlprotectagainstexternals =
'';
295 if (!$accessallowed) {
296 http_response_code(403);
297 print
'Access forbidden';
308 $filename = basename($fullpath_original_file);
311 dol_syslog(
"wrapper.php download $fullpath_original_file filename=$filename content-type=$type");
312 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
315 if (!file_exists($fullpath_original_file_osencoded)) {
316 http_response_code(404);
317 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
323 header(
'Content-Type: '.$type);
324 header(
'Content-Description: File Transfer');
326 header(
'Content-Encoding: '.$encoding);
330 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
332 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
334 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
336 readfile($fullpath_original_file_osencoded);
Class to manage ECM files.
Class to manage translations.
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_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
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_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.
dol_now($mode='auto')
Return date for now.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='')
Build a file from an array of events.