From ece4f4a8b520261b5a7647838c5574e6dbcfaac5 Mon Sep 17 00:00:00 2001 From: Alexei Karpenko Date: Wed, 15 Jan 2025 16:52:11 +0100 Subject: [PATCH] sancho mails: enabled removing of header/footer and custom header/footer images in code igniter code, legacy code: global ids for images are created only if config is set --- application/config/mail.php | 9 ++++ application/helpers/hlp_sancho_helper.php | 51 ++++++++++++++++++----- include/sancho.inc.php | 10 +++-- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/application/config/mail.php b/application/config/mail.php index 9d577720d..c89400ed1 100644 --- a/application/config/mail.php +++ b/application/config/mail.php @@ -32,3 +32,12 @@ $config['validate'] = false; // If true then the email address will be validated // If enabled will be logged info about emails in Codeigniter error logs $config['enable_debug'] = false; + +// If to use images for custom mails +$config['custom_mail_use_images'] = CUSTOM_MAIL_USE_IMAGES; + +// header image for custom mails +$config['custom_mail_header_img'] = CUSTOM_MAIL_HEADER_IMG; + +// footer image for custom mails +$config['custom_mail_footer_img'] = CUSTOM_MAIL_FOOTER_IMG; diff --git a/application/helpers/hlp_sancho_helper.php b/application/helpers/hlp_sancho_helper.php index f101ce89d..d11b6522e 100644 --- a/application/helpers/hlp_sancho_helper.php +++ b/application/helpers/hlp_sancho_helper.php @@ -23,9 +23,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); // Functions needed in the view FHC-Header // ------------------------------------------------------------------------ -const DEFAULT_SANCHO_HEADER_IMG = 'sancho_header_DEFAULT.jpg'; -const DEFAULT_SANCHO_FOOTER_IMG = 'sancho_footer_DEFAULT.jpg'; - /** * Send single Mail with Sancho Design and Layout. * @param string $vorlage_kurzbz Name of the template for specific mail content. @@ -43,8 +40,8 @@ function sendSanchoMail( $vorlage_data, $to, $subject, - $headerImg = DEFAULT_SANCHO_HEADER_IMG, - $footerImg = DEFAULT_SANCHO_FOOTER_IMG, + $headerImg = '', + $footerImg = '', $from = null, $cc = null, $bcc = null @@ -54,8 +51,8 @@ function sendSanchoMail( $ci->load->library('email'); $ci->load->library('MailLib'); - $sanchoHeader_img = 'skin/images/sancho/'. $headerImg; - $sanchoFooter_img = 'skin/images/sancho/'. $footerImg; + $custom_mail_use_images = $ci->config->item('mail'); + if ($from == '') { @@ -65,10 +62,42 @@ function sendSanchoMail( // Embed sancho header and footer image // reset important to ensure embedding of images when called in a loop $ci->email->clear(true); // clear vars and attachments - $ci->email->attach($sanchoHeader_img); - $ci->email->attach($sanchoFooter_img); - $cid_header = $ci->email->attachment_cid($sanchoHeader_img); // sets unique content id for embedding - $cid_footer = $ci->email->attachment_cid($sanchoFooter_img); // sets unique content id for embedding + + $cid_header = ''; + $cid_footer = ''; + + if (isset($custom_mail_use_images['custom_mail_use_images']) && $custom_mail_use_images['custom_mail_use_images']) + { + $sanchoHeader_img = ''; + $sanchoFooter_img = ''; + + if (isset($headerImg) && $headerImg != '') + { + // use provided header image + $sanchoHeader_img = $headerImg; + } + elseif (isset($custom_mail_use_images['custom_mail_header_img']) && $custom_mail_use_images['custom_mail_header_img']) + { + // use default header image + $sanchoHeader_img = 'skin/images/sancho/'. $custom_mail_use_images['custom_mail_header_img']; + } + + if (isset($footerImg) && $footerImg != '') + { + // use provided footer image + $sanchoFooter_img = $footerImg; + } + elseif (isset($custom_mail_use_images['custom_mail_footer_img']) && $custom_mail_use_images['custom_mail_footer_img']) + { + // use default footer image + $sanchoFooter_img = 'skin/images/sancho/'. $custom_mail_use_images['custom_mail_footer_img']; + } + + $ci->email->attach($sanchoHeader_img); + $ci->email->attach($sanchoFooter_img); + $cid_header = $ci->email->attachment_cid($sanchoHeader_img); // sets unique content id for embedding + $cid_footer = $ci->email->attachment_cid($sanchoFooter_img); // sets unique content id for embedding + } // Set specific mail content into specific content template $content = _parseMailContent($vorlage_kurzbz, $vorlage_data); diff --git a/include/sancho.inc.php b/include/sancho.inc.php index 120315eac..4fdf467e0 100644 --- a/include/sancho.inc.php +++ b/include/sancho.inc.php @@ -47,6 +47,8 @@ function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerIm $footer_image_path_prefix = dirname(__FILE__). '/../skin/images/sancho/'; $sanchoHeader_img = ''; $sanchoFooter_img = ''; + $cid_header = ''; + $cid_footer = ''; if (!defined('CUSTOM_MAIL_USE_IMAGES') || CUSTOM_MAIL_USE_IMAGES) { @@ -83,11 +85,11 @@ function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerIm // set full image path $sanchoFooter_img = $footer_image_path_prefix.$sanchoFooter_img; } - } - // Set unique content id for embedding header and footer image - $cid_header = uniqid(); - $cid_footer = uniqid(); + // Set unique content id for embedding header and footer image + $cid_header = uniqid(); + $cid_footer = uniqid(); + } // Set specific mail content into specific content template $content = parseMailContent($vorlage_kurzbz, $vorlage_data);