
Comparing changes: https://github.com/smarty-php/smarty/compare/v4.3.1...v4.4.1 It is noticeable that Smarty 4.3.1 does not officially support PHP 8.3. Is only supported with 4.4.0. Remark: During tests with Smarty 4.5.1, it was noticed that the following warning occurs: Deprecated: Using the unregistered function "function_exists" in a template is deprecated and will be removed in a future version. Use Smarty::registerPlugin to explicitly register a custom modifier. As of Smarty 5.X.X, templates must be revised again. The Smarty release 5.0.2 is already officially available. However, integration into FlatPress is not entirely trivial.
37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* Smarty plugin
|
|
*
|
|
* @package Smarty
|
|
* @subpackage PluginsModifier
|
|
*/
|
|
/**
|
|
* Smarty count modifier plugin
|
|
* Type: modifier
|
|
* Name: count
|
|
* Purpose: counts all elements in an array or in a Countable object
|
|
* Input:
|
|
* - Countable|array: array or object to count
|
|
* - mode: int defaults to 0 for normal count mode, if set to 1 counts recursive
|
|
*
|
|
* @param mixed $arrayOrObject input array/object
|
|
* @param int $mode count mode
|
|
*
|
|
* @return int
|
|
*/
|
|
function smarty_modifier_count($arrayOrObject, $mode = 0)
|
|
{
|
|
/*
|
|
* @see https://www.php.net/count
|
|
* > Prior to PHP 8.0.0, if the parameter was neither an array nor an object that implements the Countable interface,
|
|
* > 1 would be returned, unless value was null, in which case 0 would be returned.
|
|
*/
|
|
|
|
if ($arrayOrObject instanceof Countable || is_array($arrayOrObject)) {
|
|
return count($arrayOrObject, (int) $mode);
|
|
} elseif ($arrayOrObject === null) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|