PEEL Shopping
Open source ecommerce : PEEL Shopping
block.textformat.php
Go to the documentation of this file.
1 <?php
35 function smarty_block_textformat($params, $content, $template, &$repeat)
36 {
37  if (is_null($content)) {
38  return;
39  }
40 
41  $style = null;
42  $indent = 0;
43  $indent_first = 0;
44  $indent_char = ' ';
45  $wrap = 80;
46  $wrap_char = "\n";
47  $wrap_cut = false;
48  $assign = null;
49 
50  foreach ($params as $_key => $_val) {
51  switch ($_key) {
52  case 'style':
53  case 'indent_char':
54  case 'wrap_char':
55  case 'assign':
56  $$_key = (string)$_val;
57  break;
58 
59  case 'indent':
60  case 'indent_first':
61  case 'wrap':
62  $$_key = (int)$_val;
63  break;
64 
65  case 'wrap_cut':
66  $$_key = (bool)$_val;
67  break;
68 
69  default:
70  trigger_error("textformat: unknown attribute '$_key'");
71  }
72  }
73 
74  if ($style == 'email') {
75  $wrap = 72;
76  }
77  // split into paragraphs
78  $_paragraphs = preg_split('![\r\n]{2}!', $content);
79  $_output = '';
80 
81 
82  foreach ($_paragraphs as &$_paragraph) {
83  if (!$_paragraph) {
84  continue;
85  }
86  // convert mult. spaces & special chars to single space
87  $_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph);
88  // indent first line
89  if ($indent_first > 0) {
90  $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
91  }
92  // wordwrap sentences
93  if (Smarty::$_MBSTRING) {
94  require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
95  $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
96  } else {
97  $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
98  }
99  // indent lines
100  if ($indent > 0) {
101  $_paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraph);
102  }
103  }
104  $_output = implode($wrap_char . $wrap_char, $_paragraphs);
105 
106  if ($assign) {
107  $template->assign($assign, $_output);
108  } else {
109  return $_output;
110  }
111 }
112 
113 ?>
static $_UTF8_MODIFIER
Flag denoting if PCRE should run in UTF-8 mode.
static $_MBSTRING
Flag denoting if Multibyte String functions are available.
smarty_block_textformat($params, $content, $template, &$repeat)
Smarty {textformat}{/textformat} block plugin.

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:16 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.