can add basic auth credentials to load image file from protected shop

This commit is contained in:
2025-05-14 13:27:29 +02:00
parent 10c08da415
commit c097e06ac1
4 changed files with 53 additions and 0 deletions

View File

@ -196,6 +196,27 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
self::$_blIsAdmin = $blCurrentRenderFromAdmin;
$content = $this->addBasicAuth($content);
return $content;
}
protected function addBasicAuth($content)
{
$username = trim(Registry::getConfig()->getConfigParam('d3PdfDocumentsbasicAuthUserName'));
$password = trim(Registry::getConfig()->getConfigParam('d3PdfDocumentsbasicAuthPassword'));
if ($username && $password) {
$shopUrl = parse_url( Registry::getConfig()->getShopCurrentUrl() );
$pattern = '/(["|\'])'.
'(' . preg_quote( $shopUrl['scheme'], '/' ) . ':\/\/)'.
'(' . preg_quote( $shopUrl['host'], '/' ) . '.*?)'.
'\1/m';
$replace = "$1$2" . urlencode($username). ":" . urlencode($password) . "@$3$1";
$content = preg_replace( $pattern, $replace, $content );
}
return $content;
}