Location: PHPKode > scripts > SA PHP Framework > sa/doc/html/block_8textformat_8php-source.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>SA PHP Application Framework: public_html/sa-v_0_3/lib/Smarty-2.6.14/libs/plugins/block.textformat.php Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.6 -->
<div class="tabs">
  <ul>
    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="namespaces.html"><span>Namespaces</span></a></li>
    <li><a href="classes.html"><span>Classes</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
  </ul></div>
<h1>public_html/sa-v_0_3/lib/Smarty-2.6.14/libs/plugins/block.textformat.php</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?php
<a name="l00031"></a>00031 function smarty_block_textformat($params, $content, &amp;$smarty)
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033     <span class="keywordflow">if</span> (is_null($content)) {
<a name="l00034"></a>00034         <span class="keywordflow">return</span>;
<a name="l00035"></a>00035     }
<a name="l00036"></a>00036 
<a name="l00037"></a>00037     $style = null;
<a name="l00038"></a>00038     $indent = 0;
<a name="l00039"></a>00039     $indent_first = 0;
<a name="l00040"></a>00040     $indent_char = <span class="charliteral">' '</span>;
<a name="l00041"></a>00041     $wrap = 80;
<a name="l00042"></a>00042     $wrap_char = <span class="stringliteral">"\n"</span>;
<a name="l00043"></a>00043     $wrap_cut = <span class="keyword">false</span>;
<a name="l00044"></a>00044     $assign = null;
<a name="l00045"></a>00045     
<a name="l00046"></a>00046     foreach ($params as $_key =&gt; $_val) {
<a name="l00047"></a>00047         <span class="keywordflow">switch</span> ($_key) {
<a name="l00048"></a>00048             <span class="keywordflow">case</span> 'style':
<a name="l00049"></a>00049             <span class="keywordflow">case</span> 'indent_char':
<a name="l00050"></a>00050             <span class="keywordflow">case</span> 'wrap_char':
<a name="l00051"></a>00051             <span class="keywordflow">case</span> 'assign':
<a name="l00052"></a>00052                 $$_key = (string)$_val;
<a name="l00053"></a>00053                 <span class="keywordflow">break</span>;
<a name="l00054"></a>00054 
<a name="l00055"></a>00055             <span class="keywordflow">case</span> 'indent':
<a name="l00056"></a>00056             <span class="keywordflow">case</span> 'indent_first':
<a name="l00057"></a>00057             <span class="keywordflow">case</span> 'wrap':
<a name="l00058"></a>00058                 $$_key = (int)$_val;
<a name="l00059"></a>00059                 <span class="keywordflow">break</span>;
<a name="l00060"></a>00060 
<a name="l00061"></a>00061             <span class="keywordflow">case</span> 'wrap_cut':
<a name="l00062"></a>00062                 $$_key = (bool)$_val;
<a name="l00063"></a>00063                 <span class="keywordflow">break</span>;
<a name="l00064"></a>00064 
<a name="l00065"></a>00065             <span class="keywordflow">default</span>:
<a name="l00066"></a>00066                 $smarty-&gt;trigger_error(<span class="stringliteral">"textformat: unknown attribute '$_key'"</span>);
<a name="l00067"></a>00067         }
<a name="l00068"></a>00068     }
<a name="l00069"></a>00069 
<a name="l00070"></a>00070     <span class="keywordflow">if</span> ($style == 'email') {
<a name="l00071"></a>00071         $wrap = 72;
<a name="l00072"></a>00072     }
<a name="l00073"></a>00073 
<a name="l00074"></a>00074     <span class="comment">// split into paragraphs</span>
<a name="l00075"></a>00075     $_paragraphs = preg_split('![\r\n][\r\n]!',$content);
<a name="l00076"></a>00076     $_output = '';
<a name="l00077"></a>00077 
<a name="l00078"></a>00078     <span class="keywordflow">for</span>($_x = 0, $_y = count($_paragraphs); $_x &lt; $_y; $_x++) {
<a name="l00079"></a>00079         <span class="keywordflow">if</span> ($_paragraphs[$_x] == '') {
<a name="l00080"></a>00080             <span class="keywordflow">continue</span>;
<a name="l00081"></a>00081         }
<a name="l00082"></a>00082         <span class="comment">// convert mult. spaces &amp; special chars to single space</span>
<a name="l00083"></a>00083         $_paragraphs[$_x] = preg_replace(array('!\s+!<span class="charliteral">','</span>!(^\s+)|(\s+$)!'), array(<span class="charliteral">' '</span>,''), $_paragraphs[$_x]);
<a name="l00084"></a>00084         <span class="comment">// indent first line</span>
<a name="l00085"></a>00085         <span class="keywordflow">if</span>($indent_first &gt; 0) {
<a name="l00086"></a>00086             $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
<a name="l00087"></a>00087         }
<a name="l00088"></a>00088         <span class="comment">// wordwrap sentences</span>
<a name="l00089"></a>00089         $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
<a name="l00090"></a>00090         <span class="comment">// indent lines</span>
<a name="l00091"></a>00091         <span class="keywordflow">if</span>($indent &gt; 0) {
<a name="l00092"></a>00092             $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
<a name="l00093"></a>00093         }
<a name="l00094"></a>00094     }
<a name="l00095"></a>00095     $_output = implode($wrap_char . $wrap_char, $_paragraphs);
<a name="l00096"></a>00096 
<a name="l00097"></a>00097     <span class="keywordflow">return</span> $assign ? $smarty-&gt;assign($assign, $_output) : $_output;
<a name="l00098"></a>00098 
<a name="l00099"></a>00099 }
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 <span class="comment">/* vim: set expandtab: */</span>
<a name="l00102"></a>00102 
<a name="l00103"></a>00103 ?&gt;
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Jun 18 17:46:25 2006 for SA PHP Application Framework by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>
</body>
</html>
Return current item: SA PHP Framework