From e65322965fd750fe38b1438eb10632106e103d7a Mon Sep 17 00:00:00 2001 From: Alexei Karpenko Date: Mon, 20 Jan 2025 16:24:56 +0100 Subject: [PATCH] sancho mail: added config for haeder/footer image path, renamed custom mail config entries to sancho mail config entries, images are always attached inline (when using Code Igniter) --- application/config/mail.php | 9 ++++--- application/helpers/hlp_sancho_helper.php | 31 +++++++++++++++++------ config/global.config-default.inc.php | 9 ++++--- include/sancho.inc.php | 17 ++++++------- 4 files changed, 43 insertions(+), 23 deletions(-) diff --git a/application/config/mail.php b/application/config/mail.php index c89400ed1..2ac9a53c3 100644 --- a/application/config/mail.php +++ b/application/config/mail.php @@ -34,10 +34,13 @@ $config['validate'] = false; // If true then the email address will be validated $config['enable_debug'] = false; // If to use images for custom mails -$config['custom_mail_use_images'] = CUSTOM_MAIL_USE_IMAGES; +$config['sancho_mail_use_images'] = SANCHO_MAIL_USE_IMAGES; + +// image path for sancho mail, relativ to document root +$config['sancho_mail_img_path'] = SANCHO_MAIL_IMG_PATH; // header image for custom mails -$config['custom_mail_header_img'] = CUSTOM_MAIL_HEADER_IMG; +$config['sancho_mail_header_img'] = SANCHO_MAIL_HEADER_IMG; // footer image for custom mails -$config['custom_mail_footer_img'] = CUSTOM_MAIL_FOOTER_IMG; +$config['sancho_mail_footer_img'] = SANCHO_MAIL_FOOTER_IMG; diff --git a/application/helpers/hlp_sancho_helper.php b/application/helpers/hlp_sancho_helper.php index d11b6522e..768447eb2 100644 --- a/application/helpers/hlp_sancho_helper.php +++ b/application/helpers/hlp_sancho_helper.php @@ -51,7 +51,7 @@ function sendSanchoMail( $ci->load->library('email'); $ci->load->library('MailLib'); - $custom_mail_use_images = $ci->config->item('mail'); + $sancho_mail_use_images = $ci->config->item('mail'); if ($from == '') @@ -66,7 +66,7 @@ function sendSanchoMail( $cid_header = ''; $cid_footer = ''; - if (isset($custom_mail_use_images['custom_mail_use_images']) && $custom_mail_use_images['custom_mail_use_images']) + if (isset($sancho_mail_use_images['sancho_mail_use_images']) && $sancho_mail_use_images['sancho_mail_use_images']) { $sanchoHeader_img = ''; $sanchoFooter_img = ''; @@ -76,10 +76,10 @@ function sendSanchoMail( // 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']) + elseif (isset($sancho_mail_use_images['sancho_mail_header_img']) && $sancho_mail_use_images['sancho_mail_header_img']) { // use default header image - $sanchoHeader_img = 'skin/images/sancho/'. $custom_mail_use_images['custom_mail_header_img']; + $sanchoHeader_img = $sancho_mail_use_images['sancho_mail_header_img']; } if (isset($footerImg) && $footerImg != '') @@ -87,14 +87,29 @@ function sendSanchoMail( // 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']) + elseif (isset($sancho_mail_use_images['sancho_mail_footer_img']) && $sancho_mail_use_images['sancho_mail_footer_img']) { // use default footer image - $sanchoFooter_img = 'skin/images/sancho/'. $custom_mail_use_images['custom_mail_footer_img']; + $sanchoFooter_img = $sancho_mail_use_images['sancho_mail_footer_img']; } - $ci->email->attach($sanchoHeader_img); - $ci->email->attach($sanchoFooter_img); + // add image file paths + if (isset($sancho_mail_use_images['sancho_mail_img_path'])) + { + if ($sanchoHeader_img != '') + { + $sanchoHeader_img = $sancho_mail_use_images['sancho_mail_img_path'].$sanchoHeader_img; + } + + if ($sanchoFooter_img != '') + { + $sanchoFooter_img = $sancho_mail_use_images['sancho_mail_img_path'].$sanchoFooter_img; + } + } + + // attach header and footer + $ci->email->attach($sanchoHeader_img, 'inline'); + $ci->email->attach($sanchoFooter_img, 'inline'); $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 } diff --git a/config/global.config-default.inc.php b/config/global.config-default.inc.php index 9446bf5ba..bb9ec0069 100644 --- a/config/global.config-default.inc.php +++ b/config/global.config-default.inc.php @@ -340,11 +340,14 @@ define('DIENSTVERHAELTNIS_SUPPORT', false); define('FAS_STUDSTATUS_SHOW_KOMM_PRFG_HINT', false); // header und footer Bilder für eigene Mails verwenden -define('CUSTOM_MAIL_USE_IMAGES', true); +define('SANCHO_MAIL_USE_IMAGES', true); + +// Pfad für Bilder für eigene Mails, relativ zu document root +define('SANCHO_MAIL_IMG_PATH', 'skin/images/sancho/'); // header Bild für eigene Mails -define('CUSTOM_MAIL_HEADER_IMG', 'sancho_header_DEFAULT.jpg'); +define('SANCHO_MAIL_HEADER_IMG', 'sancho_header_DEFAULT.jpg'); // footer image for eigene Mails -define('CUSTOM_MAIL_FOOTER_IMG', 'sancho_footer_DEFAULT.jpg'); +define('SANCHO_MAIL_FOOTER_IMG', 'sancho_footer_DEFAULT.jpg'); ?> diff --git a/include/sancho.inc.php b/include/sancho.inc.php index 4fdf467e0..e5a9d172f 100644 --- a/include/sancho.inc.php +++ b/include/sancho.inc.php @@ -43,30 +43,29 @@ function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerIm { $from = DEFAULT_SENDER.'@'. DOMAIN; - $header_image_path_prefix = dirname(__FILE__). '/../skin/images/sancho/'; - $footer_image_path_prefix = dirname(__FILE__). '/../skin/images/sancho/'; + $image_path_prefix = dirname(__DIR__).'/'.(defined('SANCHO_MAIL_IMG_PATH') ? SANCHO_MAIL_IMG_PATH : ''); $sanchoHeader_img = ''; $sanchoFooter_img = ''; $cid_header = ''; $cid_footer = ''; - if (!defined('CUSTOM_MAIL_USE_IMAGES') || CUSTOM_MAIL_USE_IMAGES) + if (!defined('SANCHO_MAIL_USE_IMAGES') || SANCHO_MAIL_USE_IMAGES) { if (isset($headerImg) && $headerImg != '') { // use provided header image $sanchoHeader_img = $headerImg; } - elseif (defined('CUSTOM_MAIL_HEADER_IMG') && CUSTOM_MAIL_HEADER_IMG != '') + elseif (defined('SANCHO_MAIL_HEADER_IMG') && SANCHO_MAIL_HEADER_IMG != '') { // use default header image - $sanchoHeader_img = CUSTOM_MAIL_HEADER_IMG; + $sanchoHeader_img = SANCHO_MAIL_HEADER_IMG; } if ($sanchoHeader_img != '') { // set full image path - $sanchoHeader_img = $header_image_path_prefix.$sanchoHeader_img; + $sanchoHeader_img = $image_path_prefix.$sanchoHeader_img; } if (isset($footerImg) && $footerImg != '') @@ -74,16 +73,16 @@ function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerIm // use provided footer image $sanchoFooter_img = $footerImg; } - elseif (defined('CUSTOM_MAIL_FOOTER_IMG') && CUSTOM_MAIL_FOOTER_IMG != '') + elseif (defined('SANCHO_MAIL_FOOTER_IMG') && SANCHO_MAIL_FOOTER_IMG != '') { // use default footer image - $sanchoFooter_img = CUSTOM_MAIL_FOOTER_IMG; + $sanchoFooter_img = SANCHO_MAIL_FOOTER_IMG; } if ($sanchoFooter_img !== '') { // set full image path - $sanchoFooter_img = $footer_image_path_prefix.$sanchoFooter_img; + $sanchoFooter_img = $image_path_prefix.$sanchoFooter_img; } // Set unique content id for embedding header and footer image