[php8-compact] Add in more protection for unset variables in various smarty templates
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 8 Jun 2021 01:08:01 +0000 (01:08 +0000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 11 Jun 2021 01:31:19 +0000 (01:31 +0000)
12 files changed:
templates/CRM/Batch/Form/Search.tpl
templates/CRM/Campaign/Page/SurveyType.tpl
templates/CRM/Contact/Form/DedupeRules.tpl
templates/CRM/Contact/Form/Task/Email.hlp
templates/CRM/Contact/Form/Task/EmailCommon.tpl
templates/CRM/Contribute/Form/ManagePremiums.tpl
templates/CRM/Contribute/Page/UserDashboard.tpl
templates/CRM/Event/Page/UserDashboard.tpl
templates/CRM/Financial/Form/Search.tpl
templates/CRM/Financial/Page/FinancialAccount.tpl
templates/CRM/Financial/Page/FinancialType.tpl
tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php

index 872cc172a3c728e9d5bad54a7969e5c6c76f2a32..ab14b308042ede39693af4162295ff0ae88eae8a 100644 (file)
@@ -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 = '<div class="status messages">{/literal}{ts escape="js"}No matching Data Entry Batches found for your search criteria.{/ts}{literal}</li></ul></div>';
index c7ac2f45889af7f8ec5c776b3a3d834d2a2d9d73..f446f1d57673dede90c58c0c3be15bbb2263bc8e 100644 (file)
@@ -31,7 +31,7 @@
         <tr id="option_value-{$row.id}" class="crm-entity crm-admin-options_{$row.id} {if NOT $row.is_active} disabled{/if}">
           <td class="crm-admin-options-label crm-editable" data-field="label">{$row.label}</td>
           <td class="crm-admin-options-value">{$row.value}</td>
-          <td class="crm-admin-options-description">{$row.description}</td>
+          <td class="crm-admin-options-description">{if !empty($row.description)}{$row.description}{/if}</td>
           <td class="nowrap crm-admin-options-order">{$row.weight}</td>
           <td class="crm-admin-options-is_reserved">{if $row.is_reserved eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
           <td class="crm-admin-options-is_active" id="row_{$row.id}_status">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
index cb3e851d5a9cbe7d5e97fe5bd6ab5e5a48621ce9..b16fc71643ad121c06804aff001a5d8c8c1d8b1a 100644 (file)
@@ -31,7 +31,7 @@
      <tr class="crm-dedupe-rules-form-block-is_reserved">
         <td class="label">{$form.is_reserved.label}</td>
         <td>{$form.is_reserved.html}
-          {if !$isReserved}
+          {if empty($isReserved)}
             <br />
             <span class="description">{ts}WARNING: Once a rule is marked as reserved it can not be deleted and the fields and weights can not be modified.{/ts}</span>
           {/if}
@@ -42,7 +42,7 @@
         <td>
           <table class="form-layout-compressed">
             {* 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')}
             <tr>
                 <td>
                   <div class="status message">
@@ -67,7 +67,7 @@
                 </td>
             </tr>
             {else}
-              {if $isReserved}
+              {if !empty($isReserved)}
                   <tr>
                       <td>
                         <div class="status message">
index 92d987b7b31efbffd04f520b72efb3fcbaf5593d..8fec104b60dd5eea9220bbde21c03a67b8b0eb81 100644 (file)
   {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"}
   <p>{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" &lt;clientservices@example.org&gt;{/ts}</p>
 {else}
   <p>{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}<p>
-  {if $params.isAdmin}
+  {if !empty($params.isAdmin)}
     {capture assign="smtpUrl"}{crmURL p="civicrm/admin/setting/smtp" q="reset=1"}{/capture}
     <p>{ts 1=$smtpUrl}Go to <a href='%1'>Settings - Outbound Mail</a> to enable the usage of the logged in contact's email address as the from email{/ts}</p>
   {/if}
 {/if}
-{if $params.isAdmin}
+{if !empty($params.isAdmin)}
    {capture assign="fromConfig"}{crmURL p="civicrm/admin/options/from_email_address" q="reset=1"}{/capture}
    <p>{ts 1=$fromConfig}Go to <a href='%1'>Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a> to add or edit general email addresses. Make sure these email addresses are valid email accounts with your email service provider.{/ts}</p>
 {/if}
@@ -51,7 +51,7 @@
 <p>{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}</p>
 <p>{ts 1='&#123;contact.first_name&#125;'}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. <em>Dear %1</em>{/ts}</p>
 <p>{ts}Place your cursor within the Message box where you want to the token to be inserted. Then click the &quot;Insert Tokens&quot; 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 &quot;First Name&quot;).{/ts}</p>
-{if $params.tplFile EQ 'CRM/Mailing/Form/Upload.tpl'}
+{if !empty($params.tplFile) and $params.tplFile EQ 'CRM/Mailing/Form/Upload.tpl'}
     <p>
     {ts}You will also use tokens to insert Unsubscribe, Opt out and Forwarding links in your message.{/ts}
     </p>
@@ -69,7 +69,7 @@ be an equal sign and a number (=12). The number (12 in this example) is the id o
 <p>{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}</p>
 <p>{ts 1='&#123;contact.first_name&#125;'}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. <em>Dear %1</em>{/ts}</p>
 <p>{ts}Place your cursor within the Message box where you want to the token to be inserted. Then click the &quot;Insert Tokens&quot; 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 &quot;First Name&quot;).{/ts}</p>
-{if $params.tplFile EQ 'CRM/Mailing/Form/Upload.tpl'}
+{if !empty($params.tplFile) and $params.tplFile EQ 'CRM/Mailing/Form/Upload.tpl'}
     <p>
     {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}
index d75f2365138bebfe1d7c9513a766a544b3cea026..3e54f294706a28dad147254070bc93fa772c3210 100644 (file)
@@ -21,7 +21,7 @@
   </div>
   <div class="clear"></div>
     <div class='html'>
-  {if $editor EQ 'textarea'}
+  {if !empty($editor) and $editor EQ 'textarea'}
       <div class="help description">{ts}NOTE: If you are composing HTML-formatted messages, you may want to enable a Rich Text (WYSIWYG) editor (Administer &raquo; Customize Data & Screens &raquo; Display Preferences).{/ts}</div>
   {/if}
   {$form.html_message.html}<br />
index 7e3f88661b7535c7705afbed52d052516f52b0be..24ab8af6036adc36847ae49b77d50b0bb74ec11b 100644 (file)
@@ -47,7 +47,7 @@
         <p>{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}</p>
                   </div>
   <table class="form-layout-compressed">
-    {if $thumbnailUrl}<tr class="odd-row"><td class="describe-image" colspan="2"><strong>Current Image Thumbnail</strong><br /><img src="{$thumbnailUrl}" /></td></tr>{/if}
+    {if !empty($thumbnailUrl)}<tr class="odd-row"><td class="describe-image" colspan="2"><strong>Current Image Thumbnail</strong><br /><img src="{$thumbnailUrl}" /></td></tr>{/if}
     <tr class="crm-contribution-form-block-imageOption"><td>{$form.imageOption.image.html}</td><td>{$form.uploadFile.html}</td></tr>
   <tr class="crm-contribution-form-block-imageOption-thumbnail"><td colspan="2">{$form.imageOption.thumbnail.html}</td></tr>
     <tr id="imageURL"{if $action neq 2} class="hiddenElement"{/if}>
@@ -83,7 +83,7 @@
      <tr class="crm-contribution-form-block-financial_type">
        <td class="label">{$form.financial_type_id.label}</td>
        <td class="html-adjust">
-       {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 <a href='%1'>click here</a> to configure financial types and accounts.{/ts}
        {else}
index d856cf4d9869a1bf05317ebd03c39d525110cbed..70034d749b1980ffafeffa91e6c4e25660a816d1 100644 (file)
@@ -28,9 +28,9 @@
 
                 {foreach from=$contribute_rows item=row}
                     <tr id='rowid{$row.contribution_id}'
-                        class="{cycle values="odd-row,even-row"}{if $row.cancel_date} disabled{/if}">
-                        <td>{$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}">
+                        <td>{$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)}
                                 <br/>
                                 {ts}(Recurring Contribution){/ts}
                             {/if}
@@ -50,7 +50,7 @@
                                 <a class="button no-popup nowrap"
                                    href="{crmURL p='civicrm/contribute/invoice' q=$urlParams}">
                                     <i class="crm-i fa-print" aria-hidden="true"></i>
-                                    {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') }
                                         <span>{ts}Print Invoice{/ts}</span>
                                     {else}
                                         <span>{ts}Print Invoice and Credit Note{/ts}</span>
                             {/if}
                           </td>
                         {/if}
+                        {if !empty($row.buttons)}
                         <td>
                         {foreach from=$row.buttons item=button}
                           <a class="{$button.class}" href="{$button.url}"><span class='nowrap'>{$button.label}</span></a>
                         {/foreach}
                         </td>
+                        {/if}
                     </tr>
                 {/foreach}
             </table>
         {/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}
                 <div class="help">
         {/if}
     {/if}
 
-    {if $recur}
+    {if !empty($recur)}
         {if $recurRows}
             {strip}
                 <div><label>{ts}Recurring Contribution(s){/ts}</label></div>
index 5da7e3a430f51d51e5a8ebeb4e8c5090335cd1bc..210ece0034e4f7b81e791b4aa31408a92e439b46 100644 (file)
@@ -40,7 +40,7 @@
                        </td>
                        <td class="crm-participant-participant_status">{$row.participant_status}</td>
                        <td class="crm-participant-showConfirmUrl">
-                            {if $row.showConfirmUrl}
+                            {if !empty($row.showConfirmUrl)}
                                 <a href="{crmURL p='civicrm/event/confirm' q="reset=1&participantId=`$row.participant_id`"}">{ts}Confirm Registration{/ts}</a>
                             {/if}
                         </td>
index 3c10417481ff58fa3ed772e58f9b61053a4e189c..7933d35978425454c012ecdf6a3bdd67adb8c3e0 100644 (file)
@@ -9,6 +9,9 @@
 *}
 
 {* Financial search component. *}
+{if !isset($batchStatus)}
+  {assign var="batchStatus" value="open"}
+{/if}
 <div id="enableDisableStatusMsg" class="crm-container" style="display:none"></div>
 <div class="action-link">
   <a accesskey="N" href="{crmURL p='civicrm/financial/batch' q="reset=1&action=add&context=$batchStatus"}" id="newBatch" class="button"><span><i class="crm-i fa-plus-circle" aria-hidden="true"></i> {ts}New Accounting Batch{/ts}</span></a>
@@ -21,6 +24,7 @@
     <div class="crm-accordion-body">
       <div id="financial-search-form" class="crm-block crm-form-block">
         <table class="form-layout-compressed">
+          {if !empty($elements)}
           {* Loop through all defined search criteria fields (defined in the buildForm() function). *}
           {foreach from=$elements item=element}
             <tr class="crm-financial-search-form-block-{$element}">
               <td>{$form.$element.html}</td>
             </tr>
           {/foreach}
+          {/if}
         </table>
       </div>
     </div>
   </div>
 </div>
-<div class="form-layout-compressed">{$form.batch_update.html}&nbsp;{$form.submit.html}</div><br/>
+{if !empty($form.batch_update)}<div class="form-layout-compressed">{$form.batch_update.html}&nbsp;{$form.submit.html}</div><br/>{/if}
 <table id="crm-batch-selector-{$batchStatus}" class="row-highlight">
   <thead>
     <tr>
-      <th class="crm-batch-checkbox">{$form.toggleSelect.html}</th>
+      <th class="crm-batch-checkbox">{if !empty($form.toggleSelect.html)}{$form.toggleSelect.html}{/if}</th>
       <th class="crm-batch-name">{ts}Batch Name{/ts}</th>
       <th class="crm-batch-payment_instrument">{ts}Payment Method{/ts}</th>
       <th class="crm-batch-item_count">{ts}Item Count{/ts}</th>
index 646255fe294fe5129eaaec8a56a7a58659fef539..65ebc0dc7fadd39b48ac778f5f6297ddf9f5c618 100644 (file)
@@ -45,9 +45,9 @@
           <th></th>
         </thead>
         {foreach from=$rows item=row}
-        <tr id="financial_account-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
+        <tr id="financial_account-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {if !empty($row.class)}{$row.class}{/if}{if NOT $row.is_active} disabled{/if}">
           <td class="crm-editable" data-field="name">{$row.name}</td>
-          <td class="crm-editable" data-field="description" data-type="textarea">{$row.description}</td>
+          <td class="crm-editable" data-field="description" data-type="textarea">{if !empty($row.description)}{$row.description}{/if}</td>
           <td class="crm-editable" data-field="accounting_code">{$row.accounting_code}</td>
           <td>{$row.financial_account_type_id}{if $row.account_type_code} ({$row.account_type_code}){/if}</td>
           <td>{if $row.is_deductible eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
index d42ca6f53b05634eb307abe9b3888a5438e9022f..c4f55f03ea519e547a5438030ced2b10441ed17c 100644 (file)
@@ -37,9 +37,9 @@
             <th></th>
           </thead>
          {foreach from=$rows item=row}
-        <tr id="financial_type-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
+        <tr id="financial_type-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {if !empty($row.class)}{$row.class}{/if}{if NOT $row.is_active} disabled{/if}">
           <td class="crm-editable" data-field="name">{$row.name}</td>
-          <td class="crm-editable" data-field="description" data-type="textarea">{$row.description}</td>
+          <td class="crm-editable" data-field="description" data-type="textarea">{if !empty($row.description)}{$row.description}{/if}</td>
           <td>{$row.financial_account}</td>
           <td class="crm-editable" data-field="is_deductible" data-type="boolean">{if $row.is_deductible eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
           <td>{if $row.is_reserved eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
index 9ae687e1a5c896f18ec2933ff3f313d2e5f9f147..34e057cec77a93d003a94f6196c4fb326c255908 100644 (file)
@@ -114,7 +114,7 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase {
     $expectedStrings = [
       'Your Contribution(s)',
       '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th><th></th>',
-      '<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&amp;reset=1&amp;id=1&amp;cid=' . $this->contactID . '"><i class="crm-i fa-print" aria-hidden="true"></i><span>Print Invoice</span></a></td><td></td></tr><tr id=\'rowid2\'',
+      '<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&amp;reset=1&amp;id=1&amp;cid=' . $this->contactID . '"><i class="crm-i fa-print" aria-hidden="true"></i><span>Print Invoice</span></a></td></tr><tr id=\'rowid2\'',
       'Pay Now',
     ];