2004-10-20 21:15:17 +00:00
< ? php
2005-07-22 15:39:59 +00:00
/* Copyright ( C ) 2004 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2016-02-08 14:49:38 +00:00
* Copyright ( C ) 2005 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 12:43:12 +00:00
* Copyright ( C ) 2005 - 2016 Regis Houssin < regis . houssin @ inodbox . com >
2025-11-11 07:58:29 +00:00
* Copyright ( C ) 2024 - 2025 Frédéric France < frederic . france @ free . fr >
2025-02-12 10:24:02 +00:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . com >
2004-10-07 09:36:56 +00:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2004-10-07 09:36:56 +00:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2004-10-07 09:36:56 +00:00
*/
2006-09-03 13:57:44 +00:00
/**
2009-07-19 16:34:13 +00:00
* \file htdocs / viewimage . php
2018-02-13 12:55:36 +00:00
* \brief Wrapper to show images into Dolibarr screens .
* \remarks Call to wrapper is :
* DOL_URL_ROOT . ' / viewimage . php ? modulepart = diroffile & file = relativepathofofile & cache = 0
* DOL_URL_ROOT . ' / viewimage . php ? hashp = sharekey
2009-07-19 16:34:13 +00:00
*/
2005-02-04 23:02:46 +00:00
2026-04-28 02:21:39 +00:00
define ( 'MAIN_SECURITY_FORCECSP' , " default-src 'none'; form-action 'none'; frame-ancestors 'self' " );
2023-04-06 14:36:33 +00:00
2016-01-06 15:18:52 +00:00
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
2021-02-23 19:23:21 +00:00
if ( ! defined ( 'NOREQUIRESOC' )) {
define ( 'NOREQUIRESOC' , '1' );
}
if ( ! defined ( 'NOREQUIRETRAN' )) {
define ( 'NOREQUIRETRAN' , '1' );
}
if ( ! defined ( 'NOCSRFCHECK' )) {
define ( 'NOCSRFCHECK' , '1' );
}
if ( ! defined ( 'NOTOKENRENEWAL' )) {
define ( 'NOTOKENRENEWAL' , '1' );
}
if ( ! defined ( 'NOREQUIREMENU' )) {
define ( 'NOREQUIREMENU' , '1' );
}
if ( ! defined ( 'NOREQUIREHTML' )) {
define ( 'NOREQUIREHTML' , '1' );
}
if ( ! defined ( 'NOREQUIREAJAX' )) {
define ( 'NOREQUIREAJAX' , '1' );
}
2018-04-21 10:00:55 +00:00
2016-07-03 18:50:28 +00:00
// Some value of modulepart can be used to get resources that are public so no login are required.
2018-09-09 10:53:30 +00:00
// Note that only directory logo is free to access without login.
2023-01-07 11:36:53 +00:00
$needlogin = 1 ;
2024-03-28 19:19:28 +00:00
// Keep $_GET here, GETPOST is not available yet
2023-01-07 11:36:53 +00:00
if ( isset ( $_GET [ " modulepart " ])) {
2023-09-06 16:35:40 +00:00
// Some value of modulepart can be used to get resources that are public so no login are required.
2025-11-09 18:19:49 +00:00
// For logo of company (by definition, the company logo is public)
2026-02-08 02:06:36 +00:00
if ( $_GET [ " modulepart " ] == 'mycompany' && isset ( $_GET [ 'file' ]) && preg_match ( '/^\/?logos\//' , $_GET [ 'file' ])) {
2023-01-07 11:36:53 +00:00
$needlogin = 0 ;
2021-02-23 19:23:21 +00:00
}
2025-11-09 18:19:49 +00:00
// For barcode live generation (barcode are just a graph of a value, so can be public)
2023-01-07 11:36:53 +00:00
if ( $_GET [ " modulepart " ] == 'barcode' ) {
$needlogin = 0 ;
2021-02-23 19:23:21 +00:00
}
2025-11-09 18:19:49 +00:00
// Medias files (by definition medias files are for website so are public)
2023-01-07 11:36:53 +00:00
if ( $_GET [ " modulepart " ] == 'medias' ) {
$needlogin = 0 ;
2021-02-23 19:23:21 +00:00
}
2025-11-09 18:19:49 +00:00
// Common files (public files embedded into /public/theme/common)
2024-01-12 12:05:14 +00:00
if ( $_GET [ " modulepart " ] == 'common' ) {
$needlogin = 0 ;
}
2025-11-09 18:19:49 +00:00
// User photo when user has made its profile public (for virtual credit card)
2023-01-07 16:00:39 +00:00
if ( $_GET [ " modulepart " ] == 'userphotopublic' ) {
$needlogin = 0 ;
}
2025-11-09 18:19:49 +00:00
// Used by TakePOS Auto Order. TODO Image product may became public in this case. A security check to check that product is in takepos tree must be done later.
2025-11-11 07:58:29 +00:00
// isModEnabled is not defined, DOL_DOCUMENT_ROOT is not defined
if ( $_GET [ " modulepart " ] == 'product' /* && isModEnabled('takepos') */ && isset ( $_GET [ " publictakepos " ])) {
2023-01-07 11:36:53 +00:00
$needlogin = 0 ;
2021-02-23 19:23:21 +00:00
}
2018-02-13 12:55:36 +00:00
}
2025-11-09 18:19:49 +00:00
// For direct external download link (when files was shared for download using a hash link), we don't need to load/check we are into a login session
2023-01-07 11:36:53 +00:00
if ( isset ( $_GET [ " hashp " ])) {
$needlogin = 0 ;
2016-11-04 09:06:53 +00:00
}
2023-01-07 11:36:53 +00:00
// If nologin required
if ( ! $needlogin ) {
2021-02-23 19:23:21 +00:00
if ( ! defined ( " NOLOGIN " )) {
define ( " NOLOGIN " , 1 );
}
if ( ! defined ( " NOCSRFCHECK " )) {
define ( " NOCSRFCHECK " , 1 ); // We accept to go on this page from external web site.
}
if ( ! defined ( " NOIPCHECK " )) {
define ( " NOIPCHECK " , 1 ); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
2020-05-14 16:03:22 +00:00
}
2026-07-10 12:22:08 +00:00
// For MultiCompany modules, if an entity is set in query parameters (required to point an object because a ref can exists
// in 2 entities), then if user is not already into a session, the user must be loaded on this entity, so permission will
// be the one of this entity.
2024-03-28 20:29:02 +00:00
// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
2026-07-10 12:22:08 +00:00
$entity = ( ! empty ( $_GET [ 'entity' ]) ? ( int ) $_GET [ 'entity' ] : ( ! empty ( $_POST [ 'entity' ]) ? ( int ) $_POST [ 'entity' ] : 0 ));
if ( is_numeric ( $entity ) && $entity > 0 ) {
// An entity was forced on param, so we force the constant to allow master.inc.php to use this entity if not already logged.
// It has no effect if already logged.
2021-02-23 19:23:21 +00:00
define ( " DOLENTITY " , $entity );
}
2018-08-30 00:33:22 +00:00
2011-07-09 00:15:16 +00:00
/**
2013-04-15 13:43:25 +00:00
* Header empty
2011-07-09 00:15:16 +00:00
*
2025-02-12 10:24:02 +00:00
* Note : also called by functions . lib : recordNotFound
*
2024-07-09 17:28:09 +00:00
* @ param string $head Optional head lines
* @ param string $title HTML title
* @ param string $help_url Url links to help page
* Syntax is : For a wiki page : EN : EnglishPage | FR : FrenchPage | ES : SpanishPage | DE : GermanPage
* For other external page : http :// server / url
* @ param string $target Target to use on links
* @ param int $disablejs More content into html header
* @ param int $disablehead More content into html header
2024-10-26 22:36:24 +00:00
* @ param string [] | string $arrayofjs Array of complementary js files
* @ param string [] | string $arrayofcss Array of complementary css files
2024-07-09 17:28:09 +00:00
* @ param string $morequerystring Query string to add to the link " print " to get same parameters ( use only if autodetect fails )
* @ param string $morecssonbody More CSS on body tag . For example 'classforhorizontalscrolloftabs' .
* @ param string $replacemainareaby Replace call to main_area () by a print of this string
* @ param int $disablenofollow Disable the " nofollow " on meta robot header
* @ param int $disablenoindex Disable the " noindex " on meta robot header
2013-04-15 13:43:25 +00:00
* @ return void
2011-07-09 00:15:16 +00:00
*/
2025-02-12 10:24:02 +00:00
function llxHeader ( $head = '' , $title = '' , $help_url = '' , $target = '' , $disablejs = 0 , $disablehead = 0 , $arrayofjs = '' , $arrayofcss = '' , $morequerystring = '' , $morecssonbody = '' , $replacemainareaby = '' , $disablenofollow = 0 , $disablenoindex = 0 ) // @phan-suppress-current-line PhanRedefineFunction
2018-08-15 12:28:34 +00:00
{
}
2013-04-15 13:43:25 +00:00
/**
* Footer empty
*
2025-02-12 10:24:02 +00:00
* Note : also called by functions . lib : recordNotFound
*
2024-07-09 17:28:09 +00:00
* @ param string $comment A text to add as HTML comment into HTML generated page
* @ param string $zone 'private' ( for private pages ) or 'public' ( for public pages )
* @ param int $disabledoutputofmessages Clear all messages stored into session without displaying them
2013-04-15 13:43:25 +00:00
* @ return void
*/
2025-02-12 10:24:02 +00:00
function llxFooter ( $comment = '' , $zone = 'private' , $disabledoutputofmessages = 0 ) // @phan-suppress-current-line PhanRedefineFunction
2018-08-15 12:28:34 +00:00
{
}
2008-01-02 22:11:50 +00:00
2020-04-10 08:59:32 +00:00
require 'main.inc.php' ; // Load $user and permissions
2024-11-04 22:53:20 +00:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
*/
2026-07-10 12:22:08 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2024-11-04 22:53:20 +00:00
2020-09-16 17:39:50 +00:00
$action = GETPOST ( 'action' , 'aZ09' );
2024-03-28 19:19:28 +00:00
$original_file = GETPOST ( 'file' , 'alphanohtml' );
$hashp = GETPOST ( 'hashp' , 'aZ09' , 1 );
2024-09-05 08:03:20 +00:00
$extname = GETPOST ( 'extname' , 'alpha' , 1 );
2024-03-28 19:19:28 +00:00
$modulepart = GETPOST ( 'modulepart' , 'alpha' , 1 );
2020-04-10 08:59:32 +00:00
$urlsource = GETPOST ( 'urlsource' , 'alpha' );
2026-07-10 12:22:08 +00:00
$entity = ( $entity > 0 ? $entity : $conf -> entity );
2012-01-11 19:31:40 +00:00
2011-06-15 11:35:33 +00:00
// Security check
2021-02-23 19:23:21 +00:00
if ( empty ( $modulepart ) && empty ( $hashp )) {
2022-09-09 11:58:54 +00:00
httponly_accessforbidden ( 'Bad link. Bad value for parameter modulepart' , 400 );
2021-02-23 19:23:21 +00:00
}
if ( empty ( $original_file ) && empty ( $hashp ) && $modulepart != 'barcode' ) {
2022-09-09 11:58:54 +00:00
httponly_accessforbidden ( 'Bad link. Missing identification to find file (param file or hashp)' , 400 );
2021-02-23 19:23:21 +00:00
}
if ( $modulepart == 'fckeditor' ) {
$modulepart = 'medias' ; // For backward compatibility
}
2011-06-15 11:35:33 +00:00
2012-01-11 19:31:40 +00:00
2011-06-15 11:35:33 +00:00
/*
* Actions
*/
// None
/*
* View
*/
2011-04-10 20:42:18 +00:00
2025-03-02 18:13:06 +00:00
$cachestring = GETPOST ( " cache " , 'aZ09' ); // May be 1, or an int, or a hash
if ( $cachestring ) {
2024-07-14 17:56:55 +00:00
// Important: The following code is to avoid a page request by the browser and PHP CPU at each Dolibarr page access.
// We are here when param cache=xxx to force a cache policy:
// xxx=1 means cache of 3600s
// xxx=abcdef or 123456789 means a cache of 1 week (the key will be modified to get break cache use)
2026-04-25 10:13:25 +00:00
$delaycache = (( is_numeric ( $cachestring ) && ( int ) $cachestring > 1 && ( int ) $cachestring < 999999 ) ? $cachestring : '3600' );
header ( 'Cache-Control: max-age=' . $delaycache . ', public, must-revalidate' );
header ( 'Pragma: cache' ); // This is to avoid to have Pragma: no-cache set by proxy or web server
header ( 'Expires: ' . gmdate ( 'D, d M Y H:i:s' , time () + ( int ) $delaycache ) . ' GMT' ); // This is to avoid to have Expires set by proxy or web server
2011-04-10 20:42:18 +00:00
}
2018-02-13 12:55:36 +00:00
// If we have a hash public (hashp), we guess the original_file.
2026-08-12 20:10:23 +00:00
if ( ! empty ( $hashp ) && $hashp != 'shared' ) {
2018-02-13 12:55:36 +00:00
include_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php' ;
2024-09-05 08:03:20 +00:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
2020-04-10 08:59:32 +00:00
$ecmfile = new EcmFiles ( $db );
2018-02-13 12:55:36 +00:00
$result = $ecmfile -> fetch ( 0 , '' , '' , '' , $hashp );
2021-02-23 19:23:21 +00:00
if ( $result > 0 ) {
2020-04-10 08:59:32 +00:00
$tmp = explode ( '/' , $ecmfile -> filepath , 2 ); // $ecmfile->filepath is relative to document directory
2018-12-17 14:35:20 +00:00
// filepath can be 'users/X' or 'X/propale/PR11111'
2021-02-23 19:23:21 +00:00
if ( is_numeric ( $tmp [ 0 ])) { // If first tmp is numeric, it is subdir of company for multicompany, we take next part.
2018-12-17 14:35:20 +00:00
$tmp = explode ( '/' , $tmp [ 1 ], 2 );
}
2020-04-10 08:59:32 +00:00
$moduleparttocheck = $tmp [ 0 ]; // moduleparttocheck is first part of path
2018-12-17 14:35:20 +00:00
2021-02-23 19:23:21 +00:00
if ( $modulepart ) { // Not required, so often not defined, for link using public hashp parameter.
if ( $moduleparttocheck == $modulepart ) {
2018-02-13 12:55:36 +00:00
// We remove first level of directory
2020-04-10 08:59:32 +00:00
$original_file = (( $tmp [ 1 ] ? $tmp [ 1 ] . '/' : '' ) . $ecmfile -> filename ); // this is relative to module dir
2018-02-13 12:55:36 +00:00
//var_dump($original_file); exit;
2020-05-20 23:03:03 +00:00
} else {
2022-09-09 11:58:54 +00:00
httponly_accessforbidden ( 'Bad link. File is from another module part.' , 403 );
2018-02-13 12:55:36 +00:00
}
2020-05-20 23:03:03 +00:00
} else {
2018-02-13 12:55:36 +00:00
$modulepart = $moduleparttocheck ;
2020-04-10 08:59:32 +00:00
$original_file = (( $tmp [ 1 ] ? $tmp [ 1 ] . '/' : '' ) . $ecmfile -> filename ); // this is relative to module dir
2018-02-13 12:55:36 +00:00
}
2024-09-05 08:03:20 +00:00
if ( $extname ) {
$original_file = getImageFileNameForSize ( $original_file , $extname );
}
2020-05-20 23:03:03 +00:00
} else {
2024-01-12 12:05:14 +00:00
httponly_accessforbidden ( " ErrorFileNotFoundWithSharedLink " , 403 , 1 );
2018-02-13 12:55:36 +00:00
}
}
2009-07-16 00:43:59 +00:00
// Define mime type
$type = 'application/octet-stream' ;
2021-02-23 19:23:21 +00:00
if ( GETPOST ( 'type' , 'alpha' )) {
$type = GETPOST ( 'type' , 'alpha' );
} else {
$type = dol_mimetype ( $original_file );
}
2008-01-02 22:11:50 +00:00
2019-04-25 21:36:19 +00:00
// Security: This wrapper is for images. We do not allow type/html
2021-02-23 19:23:21 +00:00
if ( preg_match ( '/html/i' , $type )) {
2022-09-09 11:58:54 +00:00
httponly_accessforbidden ( 'Error: Using the image wrapper to output a file with a mime type HTML is not possible.' );
2021-02-23 19:23:21 +00:00
}
2019-07-30 12:00:43 +00:00
// Security: This wrapper is for images. We do not allow files ending with .noexe
2021-02-23 19:23:21 +00:00
if ( preg_match ( '/\.noexe$/i' , $original_file )) {
2022-09-09 11:58:54 +00:00
httponly_accessforbidden ( 'Error: Using the image wrapper to output a file ending with .noexe is not allowed.' );
2021-02-23 19:23:21 +00:00
}
2019-04-25 21:36:19 +00:00
2021-08-23 14:03:34 +00:00
// Security: Delete string ../ or ..\ into $original_file
2021-10-22 08:49:01 +00:00
$original_file = preg_replace ( '/\.\.+/' , '..' , $original_file ); // Replace '... or more' with '..'
2021-08-23 14:03:34 +00:00
$original_file = str_replace ( '../' , '/' , $original_file );
$original_file = str_replace ( '..\\' , '/' , $original_file );
2004-10-07 09:36:56 +00:00
2013-06-05 14:12:07 +00:00
// Find the subdirectory name as the reference
2020-04-10 08:59:32 +00:00
$refname = basename ( dirname ( $original_file ) . " / " );
2022-12-06 18:25:56 +00:00
if ( $refname == 'thumbs' ) {
// If we get the thumbs directory, we must go one step higher. For example original_file='10/thumbs/myfile_small.jpg' -> refname='10'
$refname = basename ( dirname ( dirname ( $original_file )) . " / " );
}
2013-06-05 14:12:07 +00:00
2022-02-04 14:14:10 +00:00
// Check that file is allowed for view with viewimage.php
2022-02-15 10:37:24 +00:00
if ( ! empty ( $original_file ) && ! dolIsAllowedForPreview ( $original_file )) {
2024-01-12 12:05:14 +00:00
httponly_accessforbidden ( 'This file extension is not qualified for preview' , 403 );
2022-02-04 14:14:10 +00:00
}
2013-06-05 14:12:07 +00:00
// Security check
2021-02-23 19:23:21 +00:00
if ( empty ( $modulepart )) {
2022-09-09 11:58:54 +00:00
httponly_accessforbidden ( 'Bad value for parameter modulepart' , 400 );
2021-02-23 19:23:21 +00:00
}
2018-02-13 12:55:36 +00:00
2022-03-22 16:13:48 +00:00
// When logged in a different entity, medias cannot be accessed because $conf->$module->multidir_output
// is not set on the requested entity, but they are public documents, so reset entity
if ( $modulepart === 'medias' && $entity != $conf -> entity ) {
2022-03-23 16:23:01 +00:00
$conf -> entity = $entity ;
$conf -> setValues ( $db );
2022-03-22 16:13:48 +00:00
}
2022-02-22 16:13:26 +00:00
$check_access = dol_check_secure_access_document ( $modulepart , $original_file , $entity , $user , $refname );
2013-06-05 14:12:07 +00:00
$accessallowed = $check_access [ 'accessallowed' ];
$sqlprotectagainstexternals = $check_access [ 'sqlprotectagainstexternals' ];
2020-04-10 08:59:32 +00:00
$fullpath_original_file = $check_access [ 'original_file' ]; // $fullpath_original_file is now a full path name
2018-02-13 12:55:36 +00:00
2020-05-21 13:05:19 +00:00
if ( ! empty ( $hashp )) {
2020-04-10 08:59:32 +00:00
$accessallowed = 1 ; // When using hashp, link is public so we force $accessallowed
2018-02-13 12:55:36 +00:00
$sqlprotectagainstexternals = '' ;
2023-11-27 12:26:44 +00:00
} elseif ( GETPOSTINT ( " publictakepos " )) {
if ( getDolGlobalString ( 'TAKEPOS_AUTO_ORDER' ) && in_array ( $modulepart , array ( 'product' , 'category' ))) {
2024-01-12 12:05:14 +00:00
$accessallowed = 1 ; // When TakePOS Public Auto Order is enabled, we accept to see all images of product and categories with no login
2025-02-25 15:19:03 +00:00
// TODO Replace the use of link to viewimage with a call to get link by getPublicImageOfObject, like done by website templates so
2024-01-14 11:26:37 +00:00
// only shared images are visible
2020-05-15 12:34:24 +00:00
}
2020-05-20 23:03:03 +00:00
} else {
2018-02-13 12:55:36 +00:00
// Basic protection (against external users only)
2021-02-23 19:23:21 +00:00
if ( $user -> socid > 0 ) {
if ( $sqlprotectagainstexternals ) {
2018-02-13 12:55:36 +00:00
$resql = $db -> query ( $sqlprotectagainstexternals );
2021-02-23 19:23:21 +00:00
if ( $resql ) {
2020-04-10 08:59:32 +00:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 19:23:21 +00:00
while ( $i < $num ) {
2018-02-13 12:55:36 +00:00
$obj = $db -> fetch_object ( $resql );
2021-02-23 19:23:21 +00:00
if ( $user -> socid != $obj -> fk_soc ) {
2020-04-10 08:59:32 +00:00
$accessallowed = 0 ;
2018-02-13 12:55:36 +00:00
break ;
}
$i ++ ;
}
}
}
}
}
2004-10-07 09:36:56 +00:00
2007-04-12 19:47:50 +00:00
// Security:
2008-01-27 17:22:41 +00:00
// Limit access if permissions are wrong
2021-02-23 19:22:36 +00:00
if ( ! $accessallowed ) {
2018-02-13 12:55:36 +00:00
accessforbidden ();
2006-05-14 02:51:11 +00:00
}
2004-10-07 09:36:56 +00:00
2007-04-12 19:47:50 +00:00
// Security:
2011-07-06 16:56:01 +00:00
// On interdit les remontees de repertoire ainsi que les pipe dans les noms de fichiers.
2021-02-23 19:23:21 +00:00
if ( preg_match ( '/\.\./' , $fullpath_original_file ) || preg_match ( '/[<>|]/' , $fullpath_original_file )) {
2017-09-06 09:39:30 +00:00
dol_syslog ( " Refused to deliver file " . $fullpath_original_file );
2020-09-16 14:34:19 +00:00
print " ErrorFileNameInvalid: " . dol_escape_htmltag ( $original_file );
2018-02-13 12:55:36 +00:00
exit ;
2007-04-12 19:47:50 +00:00
}
2021-02-23 19:23:21 +00:00
if ( $modulepart == 'barcode' ) {
2021-08-17 11:08:03 +00:00
$generator = GETPOST ( " generator " , " aZ09 " );
$encoding = GETPOST ( " encoding " , " aZ09 " );
$readable = GETPOST ( " readable " , 'aZ09' ) ? GETPOST ( " readable " , " aZ09 " ) : " Y " ;
if ( in_array ( $encoding , array ( 'EAN8' , 'EAN13' ))) {
$code = GETPOST ( " code " , 'alphanohtml' );
} else {
2022-01-19 14:20:10 +00:00
$code = GETPOST ( " code " , 'restricthtml' ); // This can be rich content (qrcode, datamatrix, ...)
2021-08-17 11:08:03 +00:00
}
2020-10-31 13:32:18 +00:00
2024-08-31 16:18:45 +00:00
// If $code is virtualcard_xxx_999.vcf, it is a file to read to get code
$reg = array ();
2024-09-01 12:37:45 +00:00
if ( preg_match ( '/^virtualcard_([^_]+)_(\d+)\.vcf$/' , $code , $reg )) {
2024-08-31 16:18:45 +00:00
$vcffile = '' ;
2025-06-01 22:10:36 +00:00
$id = 0 ;
$login = '' ;
if ( $reg [ 1 ] == 'user' && ( int ) $reg [ 2 ] > 0 ) {
2024-08-31 16:18:45 +00:00
$vcffile = $conf -> user -> dir_temp . '/' . $code ;
2025-06-01 22:10:36 +00:00
$id = ( int ) $reg [ 2 ];
$tmpuser = new User ( $db );
$tmpuser -> fetch ( $id );
$login = $tmpuser -> login ;
} elseif ( $reg [ 1 ] == 'contact' && ( int ) $reg [ 2 ] > 0 ) {
2024-08-31 16:18:45 +00:00
$vcffile = $conf -> contact -> dir_temp . '/' . $code ;
2025-06-01 22:10:36 +00:00
$id = ( int ) $reg [ 2 ];
2024-08-31 16:18:45 +00:00
}
2025-06-01 22:10:36 +00:00
$code = '' ;
if ( $vcffile && $id ) {
// Case of use of viewimage to get the barcode for user pubic profile,
// we must check the securekey that protet against forging url
if ( $reg [ 1 ] == 'user' && ( int ) $reg [ 2 ] > 0 ) {
$encodedsecurekey = dol_hash ( $conf -> file -> instance_unique_id . 'uservirtualcard' . $id . '-' . $login , 'md5' );
if ( $encodedsecurekey != GETPOST ( 'securekey' )) {
$code = 'badvalueforsecurekey' ;
}
}
if ( empty ( $code )) {
$code = file_get_contents ( $vcffile );
}
2024-08-31 16:18:45 +00:00
}
}
2021-02-23 19:23:21 +00:00
if ( empty ( $generator ) || empty ( $encoding )) {
2020-10-31 13:32:18 +00:00
print 'Error: Parameter "generator" or "encoding" not defined' ;
exit ;
}
$dirbarcode = array_merge ( array ( " /core/modules/barcode/doc/ " ), $conf -> modules_parts [ 'barcode' ]);
$result = 0 ;
2021-02-23 19:23:21 +00:00
foreach ( $dirbarcode as $reldir ) {
2020-10-31 13:32:18 +00:00
$dir = dol_buildpath ( $reldir , 0 );
$newdir = dol_osencode ( $dir );
// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
2021-02-23 19:23:21 +00:00
if ( ! is_dir ( $newdir )) {
continue ;
}
2020-10-31 13:32:18 +00:00
$result = @ include_once $newdir . $generator . '.modules.php' ;
2021-02-23 19:23:21 +00:00
if ( $result ) {
break ;
}
2020-10-31 13:32:18 +00:00
}
// Load barcode class
$classname = " mod " . ucfirst ( $generator );
2024-03-31 21:48:29 +00:00
2020-10-31 13:32:18 +00:00
$module = new $classname ( $db );
2024-10-13 23:59:44 +00:00
'@phan-var-force ModeleBarCode $module' ;
2024-11-04 22:53:20 +00:00
/** @var ModeleBarCode $module */
2021-02-23 19:23:21 +00:00
if ( $module -> encodingIsSupported ( $encoding )) {
2026-04-28 00:59:35 +00:00
top_httphead ( 'none' ); // This add header like the Content-Security-Policy. We set content-type to 'none' so the content-type will be added by the $module->buildBarCode.
// Note that link to image can be shown as a direct link due to the MAIN_SECURITY_FORCECSP directive. Link must be into an img of a page in same domain.
2020-10-31 13:32:18 +00:00
$result = $module -> buildBarCode ( $code , $encoding , $readable );
}
2020-05-20 23:03:03 +00:00
} else {
2020-10-31 13:32:18 +00:00
// Open and return file
clearstatcache ();
2011-06-11 14:14:27 +00:00
2020-10-31 13:32:18 +00:00
$filename = basename ( $fullpath_original_file );
2018-02-13 12:55:36 +00:00
2020-10-31 13:32:18 +00:00
// Output files on browser
dol_syslog ( " viewimage.php return file $fullpath_original_file filename= $filename content-type= $type " );
2011-06-11 14:14:27 +00:00
2024-01-12 12:05:14 +00:00
if ( ! dol_is_file ( $fullpath_original_file ) && ! GETPOSTINT ( " noalt " , 1 )) {
// This test is to replace error images with a nice "notfound image" when image is not available (for example when thumbs not yet generated).
2020-10-31 13:32:18 +00:00
$fullpath_original_file = DOL_DOCUMENT_ROOT . '/public/theme/common/nophoto.png' ;
/* $error = 'Error: File ' . $_GET [ " file " ] . ' does not exists or filesystems permissions are not allowed' ;
2021-02-23 19:23:21 +00:00
print $error ;
exit ; */
2020-10-31 13:32:18 +00:00
}
2011-06-11 14:14:27 +00:00
2020-10-31 13:32:18 +00:00
// Permissions are ok and file found, so we return it
2021-02-23 19:23:21 +00:00
if ( $type ) {
2020-10-31 13:32:18 +00:00
top_httphead ( $type );
header ( 'Content-Disposition: inline; filename="' . basename ( $fullpath_original_file ) . '"' );
} else {
top_httphead ( 'image/png' );
header ( 'Content-Disposition: inline; filename="' . basename ( $fullpath_original_file ) . '"' );
}
2011-06-11 14:14:27 +00:00
2020-10-31 13:32:18 +00:00
$fullpath_original_file_osencoded = dol_osencode ( $fullpath_original_file );
2017-09-06 09:39:30 +00:00
2020-10-31 13:32:18 +00:00
readfile ( $fullpath_original_file_osencoded );
2005-02-04 23:02:46 +00:00
}
2011-11-01 14:06:03 +00:00
2021-02-23 19:23:21 +00:00
if ( is_object ( $db )) {
$db -> close ();
}