From 16d7b9f41be5e1fee5415ea1030b1e9d57e71784 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 8 Jun 2021 01:08:01 +0000 Subject: [PATCH] [php8-compact] Add in more protection for unset variables in various smarty templates --- templates/CRM/Batch/Form/Search.tpl | 2 +- templates/CRM/Campaign/Page/SurveyType.tpl | 2 +- templates/CRM/Contact/Form/DedupeRules.tpl | 6 +++--- templates/CRM/Contact/Form/Task/Email.hlp | 10 +++++----- templates/CRM/Contact/Form/Task/EmailCommon.tpl | 2 +- templates/CRM/Contribute/Form/ManagePremiums.tpl | 4 ++-- templates/CRM/Contribute/Page/UserDashboard.tpl | 16 +++++++++------- templates/CRM/Event/Page/UserDashboard.tpl | 2 +- templates/CRM/Financial/Form/Search.tpl | 9 +++++++-- .../CRM/Financial/Page/FinancialAccount.tpl | 4 ++-- templates/CRM/Financial/Page/FinancialType.tpl | 4 ++-- .../CRM/Contact/Page/View/UserDashBoardTest.php | 2 +- 12 files changed, 35 insertions(+), 28 deletions(-) diff --git a/templates/CRM/Batch/Form/Search.tpl b/templates/CRM/Batch/Form/Search.tpl index 872cc172a3..ab14b30804 100644 --- a/templates/CRM/Batch/Form/Search.tpl +++ b/templates/CRM/Batch/Form/Search.tpl @@ -47,7 +47,7 @@ CRM.$(function($) { }); function buildBatchSelector( filterSearch ) { - var status = {/literal}{$status}{literal}; + var status = {/literal}{if !empty($status)}{$status}{else}0{/if}{literal}; if (filterSearch) { crmBatchSelector.fnDestroy(); var ZeroRecordText = '
{/literal}{ts escape="js"}No matching Data Entry Batches found for your search criteria.{/ts}{literal}
'; diff --git a/templates/CRM/Campaign/Page/SurveyType.tpl b/templates/CRM/Campaign/Page/SurveyType.tpl index c7ac2f4588..f446f1d576 100644 --- a/templates/CRM/Campaign/Page/SurveyType.tpl +++ b/templates/CRM/Campaign/Page/SurveyType.tpl @@ -31,7 +31,7 @@ {$row.label} {$row.value} - {$row.description} + {if !empty($row.description)}{$row.description}{/if} {$row.weight} {if $row.is_reserved eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} {if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} diff --git a/templates/CRM/Contact/Form/DedupeRules.tpl b/templates/CRM/Contact/Form/DedupeRules.tpl index cb3e851d5a..b16fc71643 100644 --- a/templates/CRM/Contact/Form/DedupeRules.tpl +++ b/templates/CRM/Contact/Form/DedupeRules.tpl @@ -31,7 +31,7 @@ {$form.is_reserved.label} {$form.is_reserved.html} - {if !$isReserved} + {if empty($isReserved)}
{ts}WARNING: Once a rule is marked as reserved it can not be deleted and the fields and weights can not be modified.{/ts} {/if} @@ -42,7 +42,7 @@ {* Hide fields and document match criteria for optimized reserved rules. *} - {if $ruleName EQ 'IndividualSupervised' OR $ruleName EQ 'IndividualUnsupervised' OR $ruleName EQ 'IndividualGeneral'} + {if !empty($ruleName) and ($ruleName EQ 'IndividualSupervised' OR $ruleName EQ 'IndividualUnsupervised' OR $ruleName EQ 'IndividualGeneral')} {else} - {if $isReserved} + {if !empty($isReserved)} diff --git a/templates/CRM/Financial/Form/Search.tpl b/templates/CRM/Financial/Form/Search.tpl index 3c10417481..7933d35978 100644 --- a/templates/CRM/Financial/Form/Search.tpl +++ b/templates/CRM/Financial/Form/Search.tpl @@ -9,6 +9,9 @@ *} {* Financial search component. *} +{if !isset($batchStatus)} + {assign var="batchStatus" value="open"} +{/if}
@@ -67,7 +67,7 @@
diff --git a/templates/CRM/Contact/Form/Task/Email.hlp b/templates/CRM/Contact/Form/Task/Email.hlp index 92d987b7b3..8fec104b60 100644 --- a/templates/CRM/Contact/Form/Task/Email.hlp +++ b/templates/CRM/Contact/Form/Task/Email.hlp @@ -12,16 +12,16 @@ {ts}From Address{/ts} {/htxt} {htxt id="id-from_email"} -{if $params.logged_in_email_setting == "1"} +{if !empty($params.logged_in_email_setting) and $params.logged_in_email_setting == "1"}

{ts}By default, CiviCRM uses the primary email address of the logged in user as the FROM address when sending emails to contacts. However, users with Administer CiviCRM permission can configure one or more general email addresses that can be selected as an alternative. EXAMPLE: "Client Services" <clientservices@example.org>{/ts}

{else}

{ts}CiviCRM is currently configured to only use the defined From Email addresses. If you wish to be able to use the email address of the logged in user as the From Address you will need to set the setting "Allow mail from loged in contact" setting. Users with Administer CiviCRM can set this setting in the SMTP settings.{/ts}

- {if $params.isAdmin} + {if !empty($params.isAdmin)} {capture assign="smtpUrl"}{crmURL p="civicrm/admin/setting/smtp" q="reset=1"}{/capture}

{ts 1=$smtpUrl}Go to Settings - Outbound Mail to enable the usage of the logged in contact's email address as the from email{/ts}

{/if} {/if} -{if $params.isAdmin} +{if !empty($params.isAdmin)} {capture assign="fromConfig"}{crmURL p="civicrm/admin/options/from_email_address" q="reset=1"}{/capture}

{ts 1=$fromConfig}Go to Administer CiviCRM » Communications » FROM Email Addresses to add or edit general email addresses. Make sure these email addresses are valid email accounts with your email service provider.{/ts}

{/if} @@ -51,7 +51,7 @@

{ts}Use tokens when you are sending mail to a number of recipients, and want to include their name and / or other values from their contact record automatically within your message.{/ts}

{ts 1='{contact.first_name}'}EXAMPLE: If you want your message to begin with "Dear " followed by the recipient's first name, you can use the %1 token in your message. Dear %1{/ts}

{ts}Place your cursor within the Message box where you want to the token to be inserted. Then click the "Insert Tokens" link in the upper right corner of the message box to see a list of available tokens. Insert the token by clicking the desired token name in the list (for example, click "First Name").{/ts}

-{if $params.tplFile EQ 'CRM/Mailing/Form/Upload.tpl'} +{if !empty($params.tplFile) and $params.tplFile EQ 'CRM/Mailing/Form/Upload.tpl'}

{ts}You will also use tokens to insert Unsubscribe, Opt out and Forwarding links in your message.{/ts}

@@ -69,7 +69,7 @@ be an equal sign and a number (=12). The number (12 in this example) is the id o

{ts}Use tokens when you are sending mail or generating PDF letters for a number of recipients, and want to include their name and / or other values from their contact record automatically within your message.{/ts}

{ts 1='{contact.first_name}'}EXAMPLE: If you want your message to begin with "Dear " followed by the recipient's first name, you can use the %1 token in your message. Dear %1{/ts}

{ts}Place your cursor within the Message box where you want to the token to be inserted. Then click the "Insert Tokens" link in the upper right corner of the message box to see a list of available tokens. Insert the token by clicking the desired token name in the list (for example, click "First Name").{/ts}

-{if $params.tplFile EQ 'CRM/Mailing/Form/Upload.tpl'} +{if !empty($params.tplFile) and $params.tplFile EQ 'CRM/Mailing/Form/Upload.tpl'}

{ts}You will also use tokens to insert Unsubscribe, Opt out and Forwarding links in your message.{/ts} {ts}Use these steps to insert clickable action links:{/ts} diff --git a/templates/CRM/Contact/Form/Task/EmailCommon.tpl b/templates/CRM/Contact/Form/Task/EmailCommon.tpl index d75f236513..3e54f29470 100644 --- a/templates/CRM/Contact/Form/Task/EmailCommon.tpl +++ b/templates/CRM/Contact/Form/Task/EmailCommon.tpl @@ -21,7 +21,7 @@

- {if $editor EQ 'textarea'} + {if !empty($editor) and $editor EQ 'textarea'}
{ts}NOTE: If you are composing HTML-formatted messages, you may want to enable a Rich Text (WYSIWYG) editor (Administer » Customize Data & Screens » Display Preferences).{/ts}
{/if} {$form.html_message.html}
diff --git a/templates/CRM/Contribute/Form/ManagePremiums.tpl b/templates/CRM/Contribute/Form/ManagePremiums.tpl index 7e3f88661b..24ab8af603 100644 --- a/templates/CRM/Contribute/Form/ManagePremiums.tpl +++ b/templates/CRM/Contribute/Form/ManagePremiums.tpl @@ -47,7 +47,7 @@

{ts}You can upload an image from your computer OR enter a URL for an image already on the Web. If you chose to upload an image file, a 'thumbnail' version will be automatically created for you. If you don't have an image available at this time, you may also choose to display a 'No Image Available' icon by selecting the 'default image'.{/ts}

- {if $thumbnailUrl}{/if} + {if !empty($thumbnailUrl)}{/if} @@ -83,7 +83,7 @@ - {/if} + {if !empty($row.buttons)} + {/if} {/foreach}
Current Image Thumbnail
Current Image Thumbnail
{$form.imageOption.image.html}{$form.uploadFile.html}
{$form.imageOption.thumbnail.html}
{$form.financial_type_id.label} - {if !$financialType} + {if empty($financialType)} {capture assign=ftUrl}{crmURL p='civicrm/admin/financial/financialType' q="reset=1"}{/capture} {ts 1=$ftUrl}There are no financial types configured with linked 'Cost of Sales Premiums' and 'Premiums Inventory Account' accounts. If you want to generate accounting transactions which track the cost of premiums used click here to configure financial types and accounts.{/ts} {else} diff --git a/templates/CRM/Contribute/Page/UserDashboard.tpl b/templates/CRM/Contribute/Page/UserDashboard.tpl index d856cf4d98..70034d749b 100644 --- a/templates/CRM/Contribute/Page/UserDashboard.tpl +++ b/templates/CRM/Contribute/Page/UserDashboard.tpl @@ -28,9 +28,9 @@ {foreach from=$contribute_rows item=row}
{$row.total_amount|crmMoney:$row.currency} {if $row.amount_level && !is_array($row.amount_level)} - {$row.amount_level} {/if} - {if $row.contribution_recur_id} + class="{cycle values="odd-row,even-row"}{if !empty($row.cancel_date)} disabled{/if}"> + {$row.total_amount|crmMoney:$row.currency} {if !empty($row.amount_level) && !is_array($row.amount_level)} - {$row.amount_level} {/if} + {if !empty($row.contribution_recur_id)}
{ts}(Recurring Contribution){/ts} {/if} @@ -50,7 +50,7 @@ - {if $row.contribution_status_name != 'Refunded' && $row.contribution_status_name != 'Cancelled' } + {if empty($row.contribution_status_name) || (!empty($row.contribution_status_name) && $row.contribution_status_name != 'Refunded' && $row.contribution_status_name != 'Cancelled') } {ts}Print Invoice{/ts} {else} {ts}Print Invoice and Credit Note{/ts} @@ -59,16 +59,18 @@ {/if}
{foreach from=$row.buttons item=button} {$button.label} {/foreach}
{/strip} - {if $contributionSummary.total.count gt 12} + {if !empty($contributionSummary.total) and $contributionSummary.total.count gt 12} {ts}Contact us for information about contributions prior to those listed above.{/ts} {/if} {else} @@ -79,7 +81,7 @@ {/if} - {if $honor} + {if !empty($honor)} {if $honorRows} {strip}
@@ -112,7 +114,7 @@ {/if} {/if} - {if $recur} + {if !empty($recur)} {if $recurRows} {strip}
diff --git a/templates/CRM/Event/Page/UserDashboard.tpl b/templates/CRM/Event/Page/UserDashboard.tpl index 5da7e3a430..210ece0034 100644 --- a/templates/CRM/Event/Page/UserDashboard.tpl +++ b/templates/CRM/Event/Page/UserDashboard.tpl @@ -40,7 +40,7 @@
{$row.participant_status} - {if $row.showConfirmUrl} + {if !empty($row.showConfirmUrl)} {ts}Confirm Registration{/ts} {/if}
+ {if !empty($elements)} {* Loop through all defined search criteria fields (defined in the buildForm() function). *} {foreach from=$elements item=element} @@ -28,16 +32,17 @@ {/foreach} + {/if}
{$form.$element.html}
-
{$form.batch_update.html} {$form.submit.html}

+{if !empty($form.batch_update)}
{$form.batch_update.html} {$form.submit.html}

{/if} - + diff --git a/templates/CRM/Financial/Page/FinancialAccount.tpl b/templates/CRM/Financial/Page/FinancialAccount.tpl index 646255fe29..65ebc0dc7f 100644 --- a/templates/CRM/Financial/Page/FinancialAccount.tpl +++ b/templates/CRM/Financial/Page/FinancialAccount.tpl @@ -45,9 +45,9 @@ {foreach from=$rows item=row} - + - + diff --git a/templates/CRM/Financial/Page/FinancialType.tpl b/templates/CRM/Financial/Page/FinancialType.tpl index d42ca6f53b..c4f55f03ea 100644 --- a/templates/CRM/Financial/Page/FinancialType.tpl +++ b/templates/CRM/Financial/Page/FinancialType.tpl @@ -37,9 +37,9 @@ {foreach from=$rows item=row} - + - + diff --git a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php index 9ae687e1a5..34e057cec7 100644 --- a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php +++ b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php @@ -114,7 +114,7 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase { $expectedStrings = [ 'Your Contribution(s)', '
{$form.toggleSelect.html}{if !empty($form.toggleSelect.html)}{$form.toggleSelect.html}{/if} {ts}Batch Name{/ts} {ts}Payment Method{/ts} {ts}Item Count{/ts}
{$row.name}{$row.description}{if !empty($row.description)}{$row.description}{/if} {$row.accounting_code} {$row.financial_account_type_id}{if $row.account_type_code} ({$row.account_type_code}){/if} {if $row.is_deductible eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}
{$row.name}{$row.description}{if !empty($row.description)}{$row.description}{/if} {$row.financial_account} {if $row.is_deductible eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} {if $row.is_reserved eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}
', - 'Completed
Total AmountFinancial TypeReceived dateReceipt SentBalanceStatusCompletedPrint Invoice
Print Invoice