From f48701182210f9258181d2717362af8bb270e992 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 6 Oct 2023 10:32:57 +1100 Subject: [PATCH] [REF] Fix up Message template gencode to work with Smarty 3 --- CRM/Core/CodeGen/Util/MessageTemplates.php | 82 +++++++++++++++++++++ CRM/Core/CodeGen/Util/Smarty.php | 4 +- setup/src/Setup/SmartyUtil.php | 3 +- xml/templates/civicrm_msg_template.tpl | 86 ++-------------------- 4 files changed, 92 insertions(+), 83 deletions(-) create mode 100644 CRM/Core/CodeGen/Util/MessageTemplates.php diff --git a/CRM/Core/CodeGen/Util/MessageTemplates.php b/CRM/Core/CodeGen/Util/MessageTemplates.php new file mode 100644 index 0000000000..2df3165642 --- /dev/null +++ b/CRM/Core/CodeGen/Util/MessageTemplates.php @@ -0,0 +1,82 @@ + ts('Message Template Workflow for Cases', ['escape' => 'sql']), + 'contribution' => ts('Message Template Workflow for Contributions', ['escape' => 'sql']), + 'event' => ts('Message Template Workflow for Events', ['escape' => 'sql']), + 'friend' => ts('Message Template Workflow for Tell-a-Friend', ['escape' => 'sql']), + 'membership' => ts('Message Template Workflow for Memberships', ['escape' => 'sql']), + 'meta' => ts('Message Template Workflow for Meta Templates', ['escape' => 'sql']), + 'pledge' => ts('Message Template Workflow for Pledges', ['escape' => 'sql']), + 'uf' => ts('Message Template Workflow for Profiles', ['escape' => 'sql']), + 'petition' => ts('Message Template Workflow for Petition', ['escape' => 'sql']), + ]; + $ovNames = [ + 'case' => [ + 'case_activity' => ts('Cases - Send Copy of an Activity', ['escape' => 'sql']), + ], + 'contribution' => [ + 'contribution_dupalert' => ts('Contributions - Duplicate Organization Alert', ['escape' => 'sql']), + 'contribution_offline_receipt' => ts('Contributions - Receipt (off-line)', ['escape' => 'sql']), + 'contribution_online_receipt' => ts('Contributions - Receipt (on-line)', ['escape' => 'sql']), + 'contribution_invoice_receipt' => ts('Contributions - Invoice', ['escape' => 'sql']), + 'contribution_recurring_notify' => ts('Contributions - Recurring Start and End Notification', ['escape' => 'sql']), + 'contribution_recurring_cancelled' => ts('Contributions - Recurring Cancellation Notification', ['escape' => 'sql']), + 'contribution_recurring_billing' => ts('Contributions - Recurring Billing Updates', ['escape' => 'sql']), + 'contribution_recurring_edit' => ts('Contributions - Recurring Updates', ['escape' => 'sql']), + 'pcp_notify' => ts('Personal Campaign Pages - Admin Notification', ['escape' => 'sql']), + 'pcp_status_change' => ts('Personal Campaign Pages - Supporter Status Change Notification', ['escape' => 'sql']), + 'pcp_supporter_notify' => ts('Personal Campaign Pages - Supporter Welcome', ['escape' => 'sql']), + 'pcp_owner_notify' => ts('Personal Campaign Pages - Owner Notification', ['escape' => 'sql']), + 'payment_or_refund_notification' => ts('Additional Payment Receipt or Refund Notification', ['escape' => 'sql']), + ], + 'event' => [ + 'event_offline_receipt' => ts('Events - Registration Confirmation and Receipt (off-line)', ['escape' => 'sql']), + 'event_online_receipt' => ts('Events - Registration Confirmation and Receipt (on-line)', ['escape' => 'sql']), + 'event_registration_receipt' => ts('Events - Receipt only', ['escape' => 'sql']), + 'participant_cancelled' => ts('Events - Registration Cancellation Notice', ['escape' => 'sql']), + 'participant_confirm' => ts('Events - Registration Confirmation Invite', ['escape' => 'sql']), + 'participant_expired' => ts('Events - Pending Registration Expiration Notice', ['escape' => 'sql']), + 'participant_transferred' => ts('Events - Registration Transferred Notice', ['escape' => 'sql']), + ], + 'friend' => [ + 'friend' => ts('Tell-a-Friend Email', ['escape' => 'sql']), + ], + 'membership' => [ + 'membership_offline_receipt' => ts('Memberships - Signup and Renewal Receipts (off-line)', ['escape' => 'sql']), + 'membership_online_receipt' => ts('Memberships - Receipt (on-line)', ['escape' => 'sql']), + 'membership_autorenew_cancelled' => ts('Memberships - Auto-renew Cancellation Notification', ['escape' => 'sql']), + 'membership_autorenew_billing' => ts('Memberships - Auto-renew Billing Updates', ['escape' => 'sql']), + ], + 'meta' => [ + 'test_preview' => ts('Test-drive - Receipt Header', ['escape' => 'sql']), + ], + 'pledge' => [ + 'pledge_acknowledge' => ts('Pledges - Acknowledgement', ['escape' => 'sql']), + 'pledge_reminder' => ts('Pledges - Payment Reminder', ['escape' => 'sql']), + ], + 'uf' => [ + 'uf_notify' => ts('Profiles - Admin Notification', ['escape' => 'sql']), + ], + 'petition' => [ + 'petition_sign' => ts('Petition - signature added', ['escape' => 'sql']), + 'petition_confirmation_needed' => ts('Petition - need verification', ['escape' => 'sql']), + ], + ]; + $smarty->assign('ogNames', $ogNames); + $smarty->assign('ovNames', $ovNames); + $dir = $smarty->get_template_vars()['gencodeXmlDir'] . '/templates/message_templates/sample'; + $templates = []; + foreach (preg_grep('/\.tpl$/', scandir($dir)) as $filename) { + $templates[] = ['name' => basename($filename, '.tpl'), 'filename' => "$dir/$filename"]; + } + $smarty->assign('templates', $templates); + } + +} diff --git a/CRM/Core/CodeGen/Util/Smarty.php b/CRM/Core/CodeGen/Util/Smarty.php index d45989504d..a1eb1f29c9 100644 --- a/CRM/Core/CodeGen/Util/Smarty.php +++ b/CRM/Core/CodeGen/Util/Smarty.php @@ -59,9 +59,9 @@ class CRM_Core_CodeGen_Util_Smarty { require_once 'CRM/Core/Smarty/plugins/block.localize.php'; $smarty->register_block('localize', 'smarty_block_localize'); - $smarty->assign('gencodeXmlDir', dirname(dirname(dirname(dirname(__DIR__)))) . '/xml'); - + require_once 'CRM/Core/CodeGen/Util/MessageTemplates.php'; + CRM_Core_CodeGen_Util_MessageTemplates::assignSmartyVariables($smarty); return $smarty; } diff --git a/setup/src/Setup/SmartyUtil.php b/setup/src/Setup/SmartyUtil.php index ec0e775b52..a076ddb32f 100644 --- a/setup/src/Setup/SmartyUtil.php +++ b/setup/src/Setup/SmartyUtil.php @@ -27,7 +27,8 @@ class SmartyUtil { require_once implode(DIRECTORY_SEPARATOR, [$srcPath, 'CRM', 'Core', 'Smarty', 'plugins', 'block.localize.php']); $smarty->register_block('localize', 'smarty_block_localize'); $smarty->assign('gencodeXmlDir', "$srcPath/xml"); - + require_once implode(DIRECTORY_SEPARATOR, [$srcPath, 'CRM', 'Core', 'CodeGen', 'Util', 'MessageTemplates.php']); + \CRM_Core_CodeGen_Util_MessageTemplates::assignSmartyVariables($smarty); return $smarty; } diff --git a/xml/templates/civicrm_msg_template.tpl b/xml/templates/civicrm_msg_template.tpl index 8fcd5fe035..22f55527c1 100644 --- a/xml/templates/civicrm_msg_template.tpl +++ b/xml/templates/civicrm_msg_template.tpl @@ -9,74 +9,6 @@ -- Generated from {$smarty.template} -- {$generated} -- -{* not sure how to define the below in Smarty, so doing it in PHP instead *} -{php} - $ogNames = array( - 'case' => ts('Message Template Workflow for Cases', array('escape' => 'sql')), - 'contribution' => ts('Message Template Workflow for Contributions', array('escape' => 'sql')), - 'event' => ts('Message Template Workflow for Events', array('escape' => 'sql')), - 'friend' => ts('Message Template Workflow for Tell-a-Friend', array('escape' => 'sql')), - 'membership' => ts('Message Template Workflow for Memberships', array('escape' => 'sql')), - 'meta' => ts('Message Template Workflow for Meta Templates', array('escape' => 'sql')), - 'pledge' => ts('Message Template Workflow for Pledges', array('escape' => 'sql')), - 'uf' => ts('Message Template Workflow for Profiles', array('escape' => 'sql')), - 'petition' => ts('Message Template Workflow for Petition', array('escape' => 'sql')), - ); - $ovNames = array( - 'case' => array( - 'case_activity' => ts('Cases - Send Copy of an Activity', array('escape' => 'sql')), - ), - 'contribution' => array( - 'contribution_dupalert' => ts('Contributions - Duplicate Organization Alert', array('escape' => 'sql')), - 'contribution_offline_receipt' => ts('Contributions - Receipt (off-line)', array('escape' => 'sql')), - 'contribution_online_receipt' => ts('Contributions - Receipt (on-line)', array('escape' => 'sql')), - 'contribution_invoice_receipt' => ts('Contributions - Invoice', array('escape' => 'sql')), - 'contribution_recurring_notify' => ts('Contributions - Recurring Start and End Notification', array('escape' => 'sql')), - 'contribution_recurring_cancelled' => ts('Contributions - Recurring Cancellation Notification', array('escape' => 'sql')), - 'contribution_recurring_billing' => ts('Contributions - Recurring Billing Updates', array('escape' => 'sql')), - 'contribution_recurring_edit' => ts('Contributions - Recurring Updates', array('escape' => 'sql')), - 'pcp_notify' => ts('Personal Campaign Pages - Admin Notification', array('escape' => 'sql')), - 'pcp_status_change' => ts('Personal Campaign Pages - Supporter Status Change Notification', array('escape' => 'sql')), - 'pcp_supporter_notify' => ts('Personal Campaign Pages - Supporter Welcome', array('escape' => 'sql')), - 'pcp_owner_notify' => ts('Personal Campaign Pages - Owner Notification', array('escape' => 'sql')), - 'payment_or_refund_notification' => ts('Additional Payment Receipt or Refund Notification', array('escape' => 'sql')), - ), - 'event' => array( - 'event_offline_receipt' => ts('Events - Registration Confirmation and Receipt (off-line)', array('escape' => 'sql')), - 'event_online_receipt' => ts('Events - Registration Confirmation and Receipt (on-line)', array('escape' => 'sql')), - 'event_registration_receipt' => ts('Events - Receipt only', array('escape' => 'sql')), - 'participant_cancelled' => ts('Events - Registration Cancellation Notice', array('escape' => 'sql')), - 'participant_confirm' => ts('Events - Registration Confirmation Invite', array('escape' => 'sql')), - 'participant_expired' => ts('Events - Pending Registration Expiration Notice', array('escape' => 'sql')), - 'participant_transferred' => ts('Events - Registration Transferred Notice', array('escape' => 'sql')), - ), - 'friend' => array( - 'friend' => ts('Tell-a-Friend Email', array('escape' => 'sql')), - ), - 'membership' => array( - 'membership_offline_receipt' => ts('Memberships - Signup and Renewal Receipts (off-line)', array('escape' => 'sql')), - 'membership_online_receipt' => ts('Memberships - Receipt (on-line)', array('escape' => 'sql')), - 'membership_autorenew_cancelled' => ts('Memberships - Auto-renew Cancellation Notification', array('escape' => 'sql')), - 'membership_autorenew_billing' => ts('Memberships - Auto-renew Billing Updates', array('escape' => 'sql')), - ), - 'meta' => array( - 'test_preview' => ts('Test-drive - Receipt Header', array('escape' => 'sql')), - ), - 'pledge' => array( - 'pledge_acknowledge' => ts('Pledges - Acknowledgement', array('escape' => 'sql')), - 'pledge_reminder' => ts('Pledges - Payment Reminder', array('escape' => 'sql')), - ), - 'uf' => array( - 'uf_notify' => ts('Profiles - Admin Notification', array('escape' => 'sql')), - ), - 'petition' => array( - 'petition_sign' => ts('Petition - signature added', array('escape' => 'sql')), - 'petition_confirmation_needed' => ts('Petition - need verification', array('escape' => 'sql')), - ), - ); - $this->assign('ogNames', $ogNames); - $this->assign('ovNames', $ovNames); -{/php} INSERT INTO civicrm_option_group (name, {localize field='title'}title{/localize}, {localize field='description'}description{/localize}, is_reserved, is_active) VALUES @@ -106,23 +38,17 @@ INSERT INTO civicrm_msg_template (msg_title, msg_subject, msg_text, msg_html, workflow_name, workflow_id, is_default, is_reserved) VALUES {foreach from=$ovNames key=gName item=ovs name=for_groups} {foreach from=$ovs key=vName item=title name=for_values} - {fetch assign=subject file="`$gencodeXmlDir`/templates/message_templates/`$vName`_subject.tpl"} - {fetch assign=text file="`$gencodeXmlDir`/templates/message_templates/`$vName`_text.tpl"} - {fetch assign=html file="`$gencodeXmlDir`/templates/message_templates/`$vName`_html.tpl"} + {assign var="subject_file_name" value=$vName|cat:'_subject'} + {assign var="html_file_name" value=$vName|cat:'_html'} + {assign var="text_file_name" value=$vName|cat:'_text'} + {fetch assign=subject file="$gencodeXmlDir/templates/message_templates/$subject_file_name.tpl"} + {fetch assign=text file="$gencodeXmlDir/templates/message_templates/$text_file_name.tpl"} + {fetch assign=html file="$gencodeXmlDir/templates/message_templates/$html_file_name.tpl"} ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', '{$vName}', @tpl_ovid_{$vName}, 1, 0), ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', '{$vName}', @tpl_ovid_{$vName}, 0, 1) {if $smarty.foreach.for_groups.last and $smarty.foreach.for_values.last};{else},{/if} {/foreach} {/foreach} -{php} - $dir = $this->_tpl_vars['gencodeXmlDir'] . '/templates/message_templates/sample'; - $templates = array(); - foreach (preg_grep('/\.tpl$/', scandir($dir)) as $filename) { - $templates[] = array('name' => basename($filename, '.tpl'), 'filename' => "$dir/$filename"); - } - $this->assign('templates', $templates); -{/php} - {foreach from=$templates item=tpl} {fetch assign=content file=$tpl.filename} INSERT INTO civicrm_msg_template -- 2.25.1