19$websitekey = basename(__DIR__);
20if (strpos($_SERVER[
"PHP_SELF"],
'website/samples/wrapper.php')) {
21 die(
"Sample file for website module. Can't be called directly.");
23if (!defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
24 require_once
'./master.inc.php';
26include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
31$hashp =
GETPOST(
'hashp',
'aZ09');
32$extname =
GETPOST(
'extname',
'alpha', 1);
33$modulepart =
GETPOST(
'modulepart',
'aZ09');
35$original_file =
GETPOST(
"file",
"alpha");
42 $original_file =
'blog.rss';
47 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
48 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
50 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
52 $tmp = explode(
'/', $ecmfile->filepath, 2);
54 if (is_numeric($tmp[0])) {
55 $tmp = explode(
'/', $tmp[1], 2);
57 $moduleparttocheck = $tmp[0];
60 if ($moduleparttocheck == $modulepart) {
62 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
65 print
'Bad link. File is from another module part.';
68 $modulepart = $moduleparttocheck;
69 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
76 print
"ErrorFileNotFoundWithSharedLink";
83if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
86if (GETPOSTISSET(
"attachment")) {
87 $attachment = (
GETPOST(
"attachment",
'alphanohtml') ? true :
false);
94$type =
'application/octet-stream';
95if (GETPOSTISSET(
'type')) {
96 $type =
GETPOST(
'type',
'alpha');
102$original_file = str_replace(
"../",
"/", $original_file);
108 header(
'Cache-Control: max-age=3600, public, must-revalidate');
109 header(
'Pragma: cache');
112$refname = basename(dirname($original_file).
"/");
119 $filename = $original_file;
120 $dir_temp = $conf->website->dir_temp;
122 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
123 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
127 $website->fetch(
'', $websitekey);
129 $filters = array(
'type_container'=>
'blogpost',
'status'=>1);
131 $filters[
'lang'] = $l;
134 $MAXNEWS = ($limit ? $limit : 20);
135 $arrayofblogs = $websitepage->fetchAll($website->id,
'DESC',
'date_creation', $MAXNEWS, 0, $filters);
136 $eventarray = array();
137 if (is_array($arrayofblogs)) {
138 foreach ($arrayofblogs as $blog) {
139 $blog->fullpageurl = $website->virtualhost.
'/'.$blog->pageurl.
'.php';
140 $blog->image = preg_replace(
'/__WEBSITE_KEY__/', $websitekey, $blog->image);
142 $eventarray[] = $blog;
146 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
147 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
148 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
150 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
155 $filename = $format.
'.'.$extension;
160 $outputfile = $dir_temp.
'/'.$filename;
168 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
170 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
177 $outputlangs->setDefaultLang($l);
178 $outputlangs->loadLangs(array(
"main",
"other"));
179 $title = $outputlangs->transnoentities(
'LatestBlogPosts').
' - '.$website->virtualhost;
180 $desc = $title.($l ?
' ('.$l.
')' :
'');
183 $outputfiletmp = tempnam($dir_temp,
'tmp');
187 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp,
'', $website->virtualhost.
'/wrapper.php?rss=1'.($l ?
'&l='.$l :
''), $l);
190 if (
dol_move($outputfiletmp, $outputfile,
'0', 1, 0, 0)) {
193 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
194 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
200 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
202 $langs->load(
"errors");
203 print $langs->trans(
"ErrorFailToCreateFile", $outputfile);
210 if (GETPOSTISSET(
"attachment")) {
211 $attachment =
GETPOST(
"attachment");
214 $contenttype =
'application/rss+xml';
215 if (GETPOSTISSET(
"contenttype")) {
216 $contenttype =
GETPOST(
"contenttype");
219 $outputencoding =
'UTF-8';
222 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
225 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
232 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
234 header(
'Cache-Control: private, must-revalidate');
238 $outputfile = $dir_temp.
'/'.$filename;
239 $result = readfile($outputfile);
241 print
'File '.$outputfile.
' was empty.';
247} elseif ($modulepart ==
"mycompany" && preg_match(
'/^\/?logos\//', $original_file)) {
249 readfile(
dol_osencode($conf->mycompany->dir_output.
"/".$original_file));
252 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
254 $accessallowed = empty($check_access[
'accessallowed']) ?
'' : $check_access[
'accessallowed'];
255 $sqlprotectagainstexternals = empty($check_access[
'sqlprotectagainstexternals']) ?
'' : $check_access[
'sqlprotectagainstexternals'];
256 $fullpath_original_file = empty($check_access[
'original_file']) ?
'' : $check_access[
'original_file'];
259 $sqlprotectagainstexternals =
'';
264 if (!$accessallowed) {
265 print
'Access forbidden';
271 $filename = basename($fullpath_original_file);
274 dol_syslog(
"wrapper.php download $fullpath_original_file filename=$filename content-type=$type");
275 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
278 if (!file_exists($fullpath_original_file_osencoded)) {
279 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
285 header(
'Content-Type: '.$type);
286 header(
'Content-Description: File Transfer');
288 header(
'Content-Encoding: '.$encoding);
292 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
294 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
296 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
298 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_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.
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='')
Build a file from an array of events.