3 $websitekey = basename(__DIR__);
4 if (strpos(
$_SERVER[
"PHP_SELF"],
'website/samples/wrapper.php')) die(
"Sample file for website module. Can be called directly.");
5 if (!defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) { require_once
'./master.inc.php'; }
6 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
11 $hashp =
GETPOST(
'hashp',
'aZ09');
12 $modulepart =
GETPOST(
'modulepart',
'aZ09');
13 $entity =
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity;
14 $original_file =
GETPOST(
"file",
"alpha");
16 $limit =
GETPOST(
'limit',
'int');
20 if ($rss) $original_file =
'blog.rss';
25 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
27 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
30 $tmp = explode(
'/', $ecmfile->filepath, 2);
32 if (is_numeric($tmp[0]))
34 $tmp = explode(
'/', $tmp[1], 2);
36 $moduleparttocheck = $tmp[0];
40 if ($moduleparttocheck == $modulepart)
43 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
47 print 'Bad link. File is from another module part.';
51 $modulepart = $moduleparttocheck;
52 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
56 print "ErrorFileNotFoundWithSharedLink";
63 if (preg_match(
'/\.(html|htm)$/i', $original_file)) $attachment =
false;
64 if (isset($_GET[
"attachment"])) $attachment = (
GETPOST(
"attachment",
'alphanohtml') ?
true :
false);
65 if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS_WEBSITE)) $attachment =
false;
68 $type =
'application/octet-stream';
73 $original_file = str_replace(
"../",
"/", $original_file);
80 header(
'Cache-Control: max-age=3600, public, must-revalidate');
81 header(
'Pragma: cache');
84 $refname = basename(dirname($original_file).
"/");
91 $filename = $original_file;
92 $dir_temp = $conf->website->dir_temp;
94 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
95 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
99 $website->fetch(
'', $websitekey);
101 $filters = array(
'type_container'=>
'blogpost');
102 if ($l) $filters[
'lang'] = $l;
104 $MAXNEWS = ($limit ? $limit : 20);
105 $arrayofblogs = $websitepage->fetchAll($website->id,
'DESC',
'date_creation', $MAXNEWS, 0, $filters);
106 $eventarray = array();
107 if (is_array($arrayofblogs)) {
108 foreach ($arrayofblogs as $blog) {
109 $blog->fullpageurl = $website->virtualhost.
'/'.$blog->pageurl.
'.php';
110 $eventarray[] = $blog;
114 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
115 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
116 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
118 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
124 $filename = $format.
'.'.$extension;
129 $outputfile = $dir_temp.
'/'.$filename;
138 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
141 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
148 $langs->load(
"other");
149 $title = $desc = $langs->transnoentities(
'LatestBlogPosts');
152 $outputfiletmp = tempnam($dir_temp,
'tmp');
153 @chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
156 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp,
'', $website->virtualhost.
'/wrapper.php?rss=1'.($l ?
'&l='.$l :
''), $l);
160 if (
dol_move($outputfiletmp, $outputfile, 0, 1)) $result = 1;
162 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
163 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
170 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
172 $langs->load(
"errors");
173 print $langs->trans(
"ErrorFailToCreateFile", $outputfile);
181 if (isset($_GET[
"attachment"])) $attachment = $_GET[
"attachment"];
183 $contenttype =
'application/rss+xml';
184 if (isset($_GET[
"contenttype"])) $contenttype = $_GET[
"contenttype"];
186 $outputencoding =
'UTF-8';
188 if ($contenttype) header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
189 if ($attachment) header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
194 if ($cachedelay) header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
195 else header(
'Cache-Control: private, must-revalidate');
198 $outputfile = $dir_temp.
'/'.$filename;
199 $result = readfile($outputfile);
200 if (!$result)
print 'File '.$outputfile.
' was empty.';
207 elseif ($modulepart ==
"mycompany" && preg_match(
'/^\/?logos\//', $original_file))
209 readfile(
dol_osencode($conf->mycompany->dir_output.
"/".$original_file));
213 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
215 $accessallowed = $check_access[
'accessallowed'];
216 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
217 $fullpath_original_file = $check_access[
'original_file'];
221 $sqlprotectagainstexternals =
'';
228 print 'Access forbidden';
234 $filename = basename($fullpath_original_file);
237 dol_syslog(
"wrapper.php download $fullpath_original_file filename=$filename content-type=$type");
238 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
241 if (!file_exists($fullpath_original_file_osencoded))
243 print "ErrorFileDoesNotExists: ".$original_file;
249 header(
'Content-Type: '.$type);
250 header(
'Content-Description: File Transfer');
251 if ($encoding) header(
'Content-Encoding: '.$encoding);
253 if ($attachment) header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
254 else header(
'Content-Disposition: inline; filename="'.$filename.
'"');
255 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
257 readfile($fullpath_original_file_osencoded);
259 if (is_object($db)) $db->close();
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
dol_filesize($pathoffile)
Return size of a file.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter= '', $url= '', $langcode= '')
Build a file from an array of events.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser= '', $refname= '', $mode= 'read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices) ...
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return mime type of a file.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
dol_filemtime($pathoffile)
Return time of a file.
Class to manage ECM files.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)