--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+
+/**
+ * If the given string looks like HTML, do nothing and return it.
+ * If it doesn't, replace newlines with br tags.
+ * The HTML check is somewhat greedy and may not add br tags
+ * to some non-HTML text that contains angle brackets.
+ *
+ * @param string $text
+ *
+ * @return string
+ * Text with br tags if input was non-HTML.
+ */
+function smarty_modifier_nl2brIfNotHTML($text) {
+ if ($text && $text === strip_tags($text)) {
+ $text = nl2br($text);
+ }
+ return $text;
+}
<tr>
<td class="label">{ts}Added by{/ts}</td><td class="view-value">{$values.source_contact}</td>
</tr>
- {if $values.target_contact_value}
+ {if array_key_exists('target_contact_value', $values)}
<tr>
<td class="label">{ts}With Contact{/ts}</td><td class="view-value">{$values.target_contact_value}</td>
</tr>
{/if}
- {if $values.mailingId}
+ {if array_key_exists('mailingId', $values)}
<tr>
<td class="label">{ts}With Contact{/ts}</td><td class="view-value"><a href="{$values.mailingId}" title="{ts}View Mailing Report{/ts}"><i class="crm-i fa-chevron-right" aria-hidden="true"></i>{ts}Mailing Report{/ts}</a></td>
</tr>
<td class="label">{ts}Subject{/ts}</td><td class="view-value">{$values.subject}</td>
</tr>
- {if $values.campaign}
+ {if array_key_exists('campaign', $values)}
<tr>
<td class="label">{ts}Campaign{/ts}</td><td class="view-value">{$values.campaign}</td>
</tr>
{/if}
- {if $values.engagement_level AND
+ {if array_key_exists('engagement_level', $values) AND
call_user_func( array( 'CRM_Campaign_BAO_Campaign', 'isComponentEnabled' ) )}
<td class="label">{ts}Engagement Level{/ts}</td><td class="view-value">{$values.engagement_level}</td>
{/if}
<tr>
<td class="label">{ts}Date and Time{/ts}</td><td class="view-value">{$values.activity_date_time|crmDate }</td>
</tr>
- {if $values.mailingId}
+ {if array_key_exists('mailingId', $values)}
<tr>
<td class="label nowrap">
# of opens
</tr>
{else}
<tr>
- <td class="label">{ts}Details{/ts}</td><td class="view-value report">{$values.details|crmStripAlternatives|purify|nl2br}</td>
+ <td class="label">{ts}Details{/ts}</td><td class="view-value report">
+ {if array_key_exists('details', $values)}{$values.details|crmStripAlternatives|purify|nl2brIfNotHTML}{/if}
+ </td>
</tr>
{/if}
{if $values.attachment}
{if $parentID}<a class="open-inline-noreturn" href="{crmURL p='civicrm/case/activity/view' h=0 q="cid=$contactID&aid=$parentID"}"><i class="crm-i fa-chevron-right" aria-hidden="true"></i> {ts}Prompted by{/ts}</a>{/if}
</td>
{else}
- <td colspan="2">{if $row.label eq 'Details'}{$row.value|crmStripAlternatives|nl2br|purify}{elseif $row.type eq 'Date'}{$row.value|crmDate}{else}{$row.value}{/if}</td>
+ <td colspan="2">
+ {if $row.label eq 'Details'}{$row.value|crmStripAlternatives|nl2brIfNotHTML|purify}{elseif $row.type eq 'Date'}{$row.value|crmDate}{else}{$row.value}{/if}</td>
{/if}
</tr>
{/foreach}