• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/plugins/block.textformat.php

00001 <?php
00030 function smarty_block_textformat($params, $content, &$smarty)
00031 {
00032     if (is_null($content)) {
00033         return;
00034     }
00035 
00036     $style = null;
00037     $indent = 0;
00038     $indent_first = 0;
00039     $indent_char = ' ';
00040     $wrap = 80;
00041     $wrap_char = "\n";
00042     $wrap_cut = false;
00043     $assign = null;
00044     
00045     foreach ($params as $_key => $_val) {
00046         switch ($_key) {
00047             case 'style':
00048             case 'indent_char':
00049             case 'wrap_char':
00050             case 'assign':
00051                 $$_key = (string)$_val;
00052                 break;
00053 
00054             case 'indent':
00055             case 'indent_first':
00056             case 'wrap':
00057                 $$_key = (int)$_val;
00058                 break;
00059 
00060             case 'wrap_cut':
00061                 $$_key = (bool)$_val;
00062                 break;
00063 
00064             default:
00065                 $smarty->trigger_error("textformat: unknown attribute '$_key'");
00066         }
00067     }
00068 
00069     if ($style == 'email') {
00070         $wrap = 72;
00071     }
00072 
00073     // split into paragraphs
00074     $_paragraphs = preg_split('![\r\n][\r\n]!',$content);
00075     $_output = '';
00076 
00077     for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) {
00078         if ($_paragraphs[$_x] == '') {
00079             continue;
00080         }
00081         // convert mult. spaces & special chars to single space
00082         $_paragraphs[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]);
00083         // indent first line
00084         if($indent_first > 0) {
00085             $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
00086         }
00087         // wordwrap sentences
00088         $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
00089         // indent lines
00090         if($indent > 0) {
00091             $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
00092         }
00093     }
00094     $_output = implode($wrap_char . $wrap_char, $_paragraphs);
00095 
00096     return $assign ? $smarty->assign($assign, $_output) : $_output;
00097 
00098 }
00099 
00100 /* vim: set expandtab: */
00101 
00102 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2