Files
zurawik.pl/core/plugins/Smarty/function.formatText.php
2026-05-15 18:33:51 +02:00

79 lines
1.7 KiB
PHP

<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.formatText.php
* Type: function
* Name: formatText
* Purpose: Formatuje tekst - wstawia <br /> za znaki koñca linii, przycina, prawdopodobnie bêdzie wstawiaæ
* -------------------------------------------------------------
*/
function smarty_function_formatText($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('modifier', 'truncate');
if (!isset($params['lenght'])) {
$lenght = CONTENT_MAX_DISP_LEN;
} else {
$lenght = $params['lenght'];
unset($params['lenght']);
}
if (!isset($params['etc'])) {
$etc = '...';
} else {
$etc = $params['etc'];
unset($params['etc']);
}
$string = $params['text'];
unset($params['text']);
if (!isset($params['moreTitle'])) {
$wiecejT = "Zobacz wiêcej";
} else {
$wiecejT = $params['moreTitle'];
unset($params['moreTitle']);
}
if (!isset($params['moreName'])) {
$wiecejN = "&nbsp;";
} else {
$wiecejN = $params['moreName'];
unset($params['moreName']);
}
$string = nl2br($string);
if(isset($params['urlWiecej']))
$params['moreUrl'] = $params['urlWiecej'];
if (is_integer($lenght)) {
if (!isset($params['moreUrl']) && !isset($params['noMoreUrl'])) {
$moreArr = array();
foreach ($params as $key => $val) {
if($key != "limit")
$moreArr[] = "$key,$val";
}
$params['moreUrl'] = implode(',', $moreArr);
$params['moreUrl'] .= ".html";
}
$string = smarty_modifier_truncate($string, $lenght, $etc);
}
if (isset($params['moreUrl']) && $params['moreUrl']) {
$more = ' <a class="more" href="' . $params['moreUrl'] . '" title="' . $wiecejT . '" rel="nofollow">'.$wiecejN.'</a>';
} else {
$more = '';
}
return $string . $more;
}
?>