Skip to content
Snippets Groups Projects
Unverified Commit 8d800ae8 authored by DaveD's avatar DaveD Committed by GitHub
Browse files

Merge pull request #23318 from seamuslee001/php81_preg_replace

[REF] Fix handling of NULL values in count_characters smarty modifier…
parents d409829f e0ee1699
Branches
Tags
No related merge requests found
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty count_characters modifier plugin
*
* Type: modifier<br>
* Name: crmCountCharacteres<br>
* Purpose: count the number of characters in a text with handling for NULL values
* @link http://smarty.php.net/manual/en/language.modifier.count.characters.php
* count_characters (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string $string
* @param boolean $include_spaces include whitespace in the character count
* @return integer
*/
function smarty_modifier_crmCountCharacters($string, $include_spaces = FALSE) {
if ($include_spaces) {
return(strlen($string));
}
if (is_null($string)) {
return 0;
}
return preg_match_all("/[^\s]/", $string, $match);
}
/* vim: set expandtab: */
......@@ -17,7 +17,7 @@
<a href="{$ev.url}">{$ev.title}</a><br />
{$ev.start_date|truncate:10:""|crmDate}<br />
{assign var=evSummary value=$ev.summary|truncate:80:""}
<em>{$evSummary}{if $ev.summary|count_characters:true GT 80} (<a href="{$ev.url}">{ts}more{/ts}...</a>){/if}</em>
<em>{$evSummary}{if $ev.summary|crmCountCharacters:true GT 80} (<a href="{$ev.url}">{ts}more{/ts}...</a>){/if}</em>
</p>
{/foreach}
{else}
......
......@@ -224,7 +224,7 @@
<td class="crm-note-note">
{$note.note|mb_truncate:80:"...":false|nl2br}
{* Include '(more)' link to view entire note if it has been truncated *}
{assign var="noteSize" value=$note.note|count_characters:true}
{assign var="noteSize" value=$note.note|crmCountCharacters:true}
{if $noteSize GT 80}
<a class="crm-popup" href="{crmURL p='civicrm/contact/view/note' q="action=view&selectedChild=note&reset=1&cid=`$contactId`&id=`$note.id`"}">{ts}(more){/ts}</a>
{/if}
......
......@@ -32,7 +32,7 @@ CREATE TABLE `{$table.name}` ({assign var='first' value=true}
{foreach from=$table.fields item=field}
{if ! $first},{/if}{assign var='first' value=false}
`{$field.name}` {$field.sqlType}{if $field.collate} COLLATE {$field.collate}{/if}{if $field.required} {if $field.required == "false"}NULL{else}NOT NULL{/if}{/if}{if isset($field.autoincrement)} AUTO_INCREMENT{/if}{if $field.default|count_characters} DEFAULT {$field.default}{/if}{if $field.comment} COMMENT '{ts escape=sql}{$field.comment}{/ts}'{/if}
`{$field.name}` {$field.sqlType}{if $field.collate} COLLATE {$field.collate}{/if}{if $field.required} {if $field.required == "false"}NULL{else}NOT NULL{/if}{/if}{if isset($field.autoincrement)} AUTO_INCREMENT{/if}{if $field.default|crmCountCharacters} DEFAULT {$field.default}{/if}{if $field.comment} COMMENT '{ts escape=sql}{$field.comment}{/ts}'{/if}
{/foreach}{* table.fields *}{strip}
{/strip}{if $table.primaryKey}{if !$first},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment