aboutsummaryrefslogtreecommitdiffstats
path: root/include/smarty/libs/plugins/block.textformat.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/smarty/libs/plugins/block.textformat.php76
1 files changed, 43 insertions, 33 deletions
diff --git a/include/smarty/libs/plugins/block.textformat.php b/include/smarty/libs/plugins/block.textformat.php
index 8cd010acb..b22b104a5 100644
--- a/include/smarty/libs/plugins/block.textformat.php
+++ b/include/smarty/libs/plugins/block.textformat.php
@@ -1,8 +1,9 @@
<?php
/**
- * Smarty plugin
+ * Smarty plugin to format text blocks
+ *
* @package Smarty
- * @subpackage plugins
+ * @subpackage PluginsBlock
*/
/**
@@ -12,23 +13,26 @@
* Name: textformat<br>
* Purpose: format text a certain way with preset styles
* or custom wrap/indent settings<br>
- * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
- * (Smarty online manual)
- * @param array
+ * Params:
* <pre>
- * Params: style: string (email)
- * indent: integer (0)
- * wrap: integer (80)
- * wrap_char string ("\n")
- * indent_char: string (" ")
- * wrap_boundary: boolean (true)
+ * - style - string (email)
+ * - indent - integer (0)
+ * - wrap - integer (80)
+ * - wrap_char - string ("\n")
+ * - indent_char - string (" ")
+ * - wrap_boundary - boolean (true)
* </pre>
+ *
+ * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat}
+ * (Smarty online manual)
+ * @param array $params parameters
+ * @param string $content contents of the block
+ * @param Smarty_Internal_Template $template template object
+ * @param boolean &$repeat repeat flag
+ * @return string content re-formatted
* @author Monte Ohrt <monte at ohrt dot com>
- * @param string contents of the block
- * @param Smarty clever simulation of a method
- * @return string string $content re-formatted
*/
-function smarty_block_textformat($params, $content, &$smarty)
+function smarty_block_textformat($params, $content, $template, &$repeat)
{
if (is_null($content)) {
return;
@@ -42,7 +46,7 @@ function smarty_block_textformat($params, $content, &$smarty)
$wrap_char = "\n";
$wrap_cut = false;
$assign = null;
-
+
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'style':
@@ -63,41 +67,47 @@ function smarty_block_textformat($params, $content, &$smarty)
break;
default:
- $smarty->trigger_error("textformat: unknown attribute '$_key'");
+ trigger_error("textformat: unknown attribute '$_key'");
}
}
if ($style == 'email') {
$wrap = 72;
}
-
// split into paragraphs
- $_paragraphs = preg_split('![\r\n][\r\n]!',$content);
+ $_paragraphs = preg_split('![\r\n]{2}!', $content);
$_output = '';
- for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) {
- if ($_paragraphs[$_x] == '') {
+
+ foreach ($_paragraphs as &$_paragraph) {
+ if (!$_paragraph) {
continue;
}
// convert mult. spaces & special chars to single space
- $_paragraphs[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]);
+ $_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph);
// indent first line
- if($indent_first > 0) {
- $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
+ if ($indent_first > 0) {
+ $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
}
// wordwrap sentences
- $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
+ if (Smarty::$_MBSTRING) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
+ $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
+ } else {
+ $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
+ }
// indent lines
- if($indent > 0) {
- $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
+ if ($indent > 0) {
+ $_paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraph);
}
}
$_output = implode($wrap_char . $wrap_char, $_paragraphs);
-
- return $assign ? $smarty->assign($assign, $_output) : $_output;
-
+
+ if ($assign) {
+ $template->assign($assign, $_output);
+ } else {
+ return $_output;
+ }
}
-/* vim: set expandtab: */
-
-?>
+?> \ No newline at end of file