3$websitekey = basename(__DIR__);
4if (strpos($_SERVER[
"PHP_SELF"],
'website/samples/wrapper.php')) {
5 die(
"Sample file for website module. Can't be called directly.");
7if (!defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
8 require_once
'./master.inc.php';
10include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
15$hashp =
GETPOST(
'hashp',
'aZ09');
16$modulepart =
GETPOST(
'modulepart',
'aZ09');
17$entity =
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity;
18$original_file =
GETPOST(
"file",
"alpha");
20$limit =
GETPOST(
'limit',
'int');
25 $original_file =
'blog.rss';
30 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
32 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
34 $tmp = explode(
'/', $ecmfile->filepath, 2);
36 if (is_numeric($tmp[0])) {
37 $tmp = explode(
'/', $tmp[1], 2);
39 $moduleparttocheck = $tmp[0];
42 if ($moduleparttocheck == $modulepart) {
44 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
47 print
'Bad link. File is from another module part.';
50 $modulepart = $moduleparttocheck;
51 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
54 print
"ErrorFileNotFoundWithSharedLink";
61if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
64if (isset($_GET[
"attachment"])) {
65 $attachment = (
GETPOST(
"attachment",
'alphanohtml') ? true :
false);
67if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS_WEBSITE)) {
72$type =
'application/octet-stream';
73if (GETPOSTISSET(
'type')) {
74 $type =
GETPOST(
'type',
'alpha');
80$original_file = str_replace(
"../",
"/", $original_file);
86 header(
'Cache-Control: max-age=3600, public, must-revalidate');
87 header(
'Pragma: cache');
90$refname = basename(dirname($original_file).
"/");
97 $filename = $original_file;
98 $dir_temp = $conf->website->dir_temp;
100 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
101 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
105 $website->fetch(
'', $websitekey);
107 $filters = array(
'type_container'=>
'blogpost',
'status'=>1);
109 $filters[
'lang'] = $l;
112 $MAXNEWS = ($limit ? $limit : 20);
113 $arrayofblogs = $websitepage->fetchAll($website->id,
'DESC',
'date_creation', $MAXNEWS, 0, $filters);
114 $eventarray = array();
115 if (is_array($arrayofblogs)) {
116 foreach ($arrayofblogs as $blog) {
117 $blog->fullpageurl = $website->virtualhost.
'/'.$blog->pageurl.
'.php';
118 $eventarray[] = $blog;
122 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
123 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
124 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
126 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
131 $filename = $format.
'.'.$extension;
136 $outputfile = $dir_temp.
'/'.$filename;
144 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
146 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
153 $outputlangs->setDefaultLang($l);
154 $outputlangs->loadLangs(array(
"main",
"other"));
155 $title = $desc = $outputlangs->transnoentities(
'LatestBlogPosts');
158 $outputfiletmp = tempnam($dir_temp,
'tmp');
162 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp,
'', $website->virtualhost.
'/wrapper.php?rss=1'.($l ?
'&l='.$l :
''), $l);
165 if (
dol_move($outputfiletmp, $outputfile, 0, 1, 0, 0)) {
168 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
169 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
175 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
177 $langs->load(
"errors");
178 print $langs->trans(
"ErrorFailToCreateFile", $outputfile);
185 if (isset($_GET[
"attachment"])) {
186 $attachment = $_GET[
"attachment"];
189 $contenttype =
'application/rss+xml';
190 if (isset($_GET[
"contenttype"])) {
191 $contenttype = $_GET[
"contenttype"];
194 $outputencoding =
'UTF-8';
197 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
200 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
207 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
209 header(
'Cache-Control: private, must-revalidate');
213 $outputfile = $dir_temp.
'/'.$filename;
214 $result = readfile($outputfile);
216 print
'File '.$outputfile.
' was empty.';
222} elseif ($modulepart ==
"mycompany" && preg_match(
'/^\/?logos\//', $original_file)) {
224 readfile(
dol_osencode($conf->mycompany->dir_output.
"/".$original_file));
227 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
229 $accessallowed = empty($check_access[
'accessallowed']) ?
'' : $check_access[
'accessallowed'];
230 $sqlprotectagainstexternals = empty($check_access[
'sqlprotectagainstexternals']) ?
'' : $check_access[
'sqlprotectagainstexternals'];
231 $fullpath_original_file = empty($check_access[
'original_file']) ?
'' : $check_access[
'original_file'];
234 $sqlprotectagainstexternals =
'';
239 if (!$accessallowed) {
240 print
'Access forbidden';
246 $filename = basename($fullpath_original_file);
249 dol_syslog(
"wrapper.php download $fullpath_original_file filename=$filename content-type=$type");
250 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
253 if (!file_exists($fullpath_original_file_osencoded)) {
254 print
"ErrorFileDoesNotExists: ".$original_file;
260 header(
'Content-Type: '.$type);
261 header(
'Content-Description: File Transfer');
263 header(
'Content-Encoding: '.$encoding);
267 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
269 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
271 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
273 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.
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.