summaryrefslogtreecommitdiff
path: root/lib/smarty3/plugins/modifier.truncate.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/smarty3/plugins/modifier.truncate.php')
-rw-r--r--lib/smarty3/plugins/modifier.truncate.php24
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/smarty3/plugins/modifier.truncate.php b/lib/smarty3/plugins/modifier.truncate.php
index 6fe8442..bb881bf 100644
--- a/lib/smarty3/plugins/modifier.truncate.php
+++ b/lib/smarty3/plugins/modifier.truncate.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifier
*/
-
/**
* Smarty truncate modifier plugin
- * Type: modifier<br>
- * Name: truncate<br>
+ * Type: modifier
+ * Name: truncate
* Purpose: Truncate a string to a certain length if necessary,
* optionally splitting in the middle of a word, and
* appending the $etc string or inserting $etc into the middle.
@@ -27,28 +26,27 @@
*/
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
- if ($length == 0) {
+ if ($length === 0) {
return '';
}
-
if (Smarty::$_MBSTRING) {
if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
$length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
if (!$break_words && !$middle) {
- $string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '',
- mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
+ $string = preg_replace(
+ '/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER,
+ '',
+ mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)
+ );
}
if (!$middle) {
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
}
-
return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc .
- mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET);
+ mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET);
}
-
return $string;
}
-
// no MBString fallback
if (isset($string[ $length ])) {
$length -= min($length, strlen($etc));
@@ -58,9 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (!$middle) {
return substr($string, 0, $length) . $etc;
}
-
- return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
+ return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
}
-
return $string;
}