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');
19$original_file =
GETPOST(
"file",
"alpha");
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 (GETPOSTISSET(
"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 $blog->image = preg_replace(
'/__WEBSITE_KEY__/', $websitekey, $blog->image);
121 $eventarray[] = $blog;
125 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
126 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
127 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
129 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
134 $filename = $format.
'.'.$extension;
139 $outputfile = $dir_temp.
'/'.$filename;
147 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
149 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
156 $outputlangs->setDefaultLang($l);
157 $outputlangs->loadLangs(array(
"main",
"other"));
158 $title = $outputlangs->transnoentities(
'LatestBlogPosts').
' - '.$website->virtualhost;
159 $desc = $title.($l ?
' ('.$l.
')' :
'');
162 $outputfiletmp = tempnam($dir_temp,
'tmp');
166 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp,
'', $website->virtualhost.
'/wrapper.php?rss=1'.($l ?
'&l='.$l :
''), $l);
169 if (
dol_move($outputfiletmp, $outputfile, 0, 1, 0, 0)) {
172 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
173 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
179 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
181 $langs->load(
"errors");
182 print $langs->trans(
"ErrorFailToCreateFile", $outputfile);
189 if (GETPOSTISSET(
"attachment")) {
190 $attachment =
GETPOST(
"attachment");
193 $contenttype =
'application/rss+xml';
194 if (GETPOSTISSET(
"contenttype")) {
195 $contenttype =
GETPOST(
"contenttype");
198 $outputencoding =
'UTF-8';
201 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
204 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
211 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
213 header(
'Cache-Control: private, must-revalidate');
217 $outputfile = $dir_temp.
'/'.$filename;
218 $result = readfile($outputfile);
220 print
'File '.$outputfile.
' was empty.';
226} elseif ($modulepart ==
"mycompany" && preg_match(
'/^\/?logos\//', $original_file)) {
228 readfile(
dol_osencode($conf->mycompany->dir_output.
"/".$original_file));
231 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
233 $accessallowed = empty($check_access[
'accessallowed']) ?
'' : $check_access[
'accessallowed'];
234 $sqlprotectagainstexternals = empty($check_access[
'sqlprotectagainstexternals']) ?
'' : $check_access[
'sqlprotectagainstexternals'];
235 $fullpath_original_file = empty($check_access[
'original_file']) ?
'' : $check_access[
'original_file'];
238 $sqlprotectagainstexternals =
'';
243 if (!$accessallowed) {
244 print
'Access forbidden';
250 $filename = basename($fullpath_original_file);
253 dol_syslog(
"wrapper.php download $fullpath_original_file filename=$filename content-type=$type");
254 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
257 if (!file_exists($fullpath_original_file_osencoded)) {
258 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
264 header(
'Content-Type: '.$type);
265 header(
'Content-Description: File Transfer');
267 header(
'Content-Encoding: '.$encoding);
271 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
273 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
275 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
277 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.
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.