Files
smarty/libs/plugins/modifiercompiler.wordwrap.php
T

40 lines
1.1 KiB
PHP
Raw Normal View History

2013-07-14 22:15:45 +00:00
<?php
/**
* Smarty plugin
*
* @package Smarty
2013-07-14 22:15:45 +00:00
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty wordwrap modifier plugin
2017-11-11 07:11:33 +01:00
* Type: modifier
* Name: wordwrap
2013-07-14 22:15:45 +00:00
* Purpose: wrap a string of text at a given length
*
* @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
2013-07-14 22:15:45 +00:00
* @author Uwe Tews
*
* @param array $params parameters
2017-10-26 10:25:41 +02:00
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*
2013-07-14 22:15:45 +00:00
* @return string with compiled code
2017-10-26 10:25:41 +02:00
* @throws \SmartyException
2013-07-14 22:15:45 +00:00
*/
function smarty_modifiercompiler_wordwrap($params, Smarty_Internal_TemplateCompilerBase $compiler)
2013-07-14 22:15:45 +00:00
{
2016-02-09 01:27:15 +01:00
if (!isset($params[ 1 ])) {
$params[ 1 ] = 80;
2013-07-14 22:15:45 +00:00
}
2016-02-09 01:27:15 +01:00
if (!isset($params[ 2 ])) {
$params[ 2 ] = '"\n"';
2013-07-14 22:15:45 +00:00
}
2016-02-09 01:27:15 +01:00
if (!isset($params[ 3 ])) {
$params[ 3 ] = 'false';
2013-07-14 22:15:45 +00:00
}
$function = 'wordwrap';
if (Smarty::$_MBSTRING) {
2018-06-12 09:58:15 +02:00
$function = $compiler->getPlugin('mb_wordwrap', 'modifier');
2013-07-14 22:15:45 +00:00
}
2016-02-09 01:27:15 +01:00
return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
2013-07-14 22:15:45 +00:00
}