4$websitekey = basename(__DIR__);
5if (strpos($_SERVER[
"PHP_SELF"],
'website/samples/wrapper.php')) {
6 die(
"Sample file for website module. Can't be called directly.");
8if (!defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
9 require_once
'./master.inc.php';
11include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
16$hashp =
GETPOST(
'hashp',
'aZ09');
17$modulepart =
GETPOST(
'modulepart',
'aZ09');
18$entity =
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity;
19$original_file =
GETPOST(
"file",
"alpha");
21$limit =
GETPOST(
'limit',
'int');
26 $original_file =
'blog.rss';
31 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
33 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
35 $tmp = explode(
'/', $ecmfile->filepath, 2);
37 if (is_numeric($tmp[0])) {
38 $tmp = explode(
'/', $tmp[1], 2);
40 $moduleparttocheck = $tmp[0];
43 if ($moduleparttocheck == $modulepart) {
45 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
48 print
'Bad link. File is from another module part.';
51 $modulepart = $moduleparttocheck;
52 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
55 print
"ErrorFileNotFoundWithSharedLink";
62if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
65if (isset($_GET[
"attachment"])) {
66 $attachment = (
GETPOST(
"attachment",
'alphanohtml') ? true :
false);
73$type =
'application/octet-stream';
74if (GETPOSTISSET(
'type')) {
75 $type =
GETPOST(
'type',
'alpha');
81$original_file = str_replace(
"../",
"/", $original_file);
87 header(
'Cache-Control: max-age=3600, public, must-revalidate');
88 header(
'Pragma: cache');
91$refname = basename(dirname($original_file).
"/");
98 $filename = $original_file;
99 $dir_temp = $conf->website->dir_temp;
101 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
102 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
106 $website->fetch(
'', $websitekey);
108 $filters = array(
'type_container'=>
'blogpost',
'status'=>1);
110 $filters[
'lang'] = $l;
113 $MAXNEWS = ($limit ? $limit : 20);
114 $arrayofblogs = $websitepage->fetchAll($website->id,
'DESC',
'date_creation', $MAXNEWS, 0, $filters);
115 $eventarray = array();
116 if (is_array($arrayofblogs)) {
117 foreach ($arrayofblogs as $blog) {
118 $blog->fullpageurl = $website->virtualhost.
'/'.$blog->pageurl.
'.php';
119 $eventarray[] = $blog;
123 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
124 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
125 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
127 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
132 $filename = $format.
'.'.$extension;
137 $outputfile = $dir_temp.
'/'.$filename;
145 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
147 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
154 $outputlangs->setDefaultLang($l);
155 $outputlangs->loadLangs(array(
"main",
"other"));
156 $title = $desc = $outputlangs->transnoentities(
'LatestBlogPosts');
159 $outputfiletmp = tempnam($dir_temp,
'tmp');
163 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp,
'', $website->virtualhost.
'/wrapper.php?rss=1'.($l ?
'&l='.$l :
''), $l);
166 if (
dol_move($outputfiletmp, $outputfile, 0, 1, 0, 0)) {
169 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
170 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
176 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
178 $langs->load(
"errors");
179 print $langs->trans(
"ErrorFailToCreateFile", $outputfile);
186 if (isset($_GET[
"attachment"])) {
187 $attachment = $_GET[
"attachment"];
190 $contenttype =
'application/rss+xml';
191 if (isset($_GET[
"contenttype"])) {
192 $contenttype = $_GET[
"contenttype"];
195 $outputencoding =
'UTF-8';
198 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
201 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
208 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
210 header(
'Cache-Control: private, must-revalidate');
214 $outputfile = $dir_temp.
'/'.$filename;
215 $result = readfile($outputfile);
217 print
'File '.$outputfile.
' was empty.';
223} elseif ($modulepart ==
"mycompany" && preg_match(
'/^\/?logos\//', $original_file)) {
225 readfile(
dol_osencode($conf->mycompany->dir_output.
"/".$original_file));
228 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
230 $accessallowed = empty($check_access[
'accessallowed']) ?
'' : $check_access[
'accessallowed'];
231 $sqlprotectagainstexternals = empty($check_access[
'sqlprotectagainstexternals']) ?
'' : $check_access[
'sqlprotectagainstexternals'];
232 $fullpath_original_file = empty($check_access[
'original_file']) ?
'' : $check_access[
'original_file'];
235 $sqlprotectagainstexternals =
'';
240 if (!$accessallowed) {
241 print
'Access forbidden';
247 $filename = basename($fullpath_original_file);
250 dol_syslog(
"wrapper.php download $fullpath_original_file filename=$filename content-type=$type");
251 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
254 if (!file_exists($fullpath_original_file_osencoded)) {
255 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
261 header(
'Content-Type: '.$type);
262 header(
'Content-Description: File Transfer');
264 header(
'Content-Encoding: '.$encoding);
268 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
270 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
272 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
274 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())
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='', $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.
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.
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 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.