From 6fc07742f8fca9d32db23243d374ea27e8ee4c1e Mon Sep 17 00:00:00 2001 From: rvelices Date: Thu, 20 Jun 2013 03:38:47 +0000 Subject: smarty 3 - first pass for tests git-svn-id: http://piwigo.org/svn/trunk@23384 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/smarty/libs/plugins/block.textformat.php | 76 ++++++++++++++---------- 1 file changed, 43 insertions(+), 33 deletions(-) (limited to 'include/smarty/libs/plugins/block.textformat.php') 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 @@ * Purpose: format text a certain way with preset styles * or custom wrap/indent settings
- * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat} - * (Smarty online manual) - * @param array + * Params: *
- * 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)
  * 
+ * + * @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 - * @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 -- cgit v1.2.3