[ PHPXref.com ] [ Generated: Sun Jul 20 20:37:06 2008 ] [ TextilePHP 2.0.8 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/doc/ -> Textile_8php-source.html (source)

   1  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
   2  <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
   3  <title>TextilePHP: Textile.php Source File</title>
   4  <link href="doxygen.css" rel="stylesheet" type="text/css">
   5  </head><body>
   6  <!-- Generated by Doxygen 1.3.7 -->
   7  <div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a></div>
   8  <h1>Textile.php</h1><a href="Textile_8php.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 &lt;?php
   9  00002 <span class="comment">// @(#) $Id: Textile_8php-source.html,v 1.12 2005/03/21 14:38:52 jhriggs Exp $</span>
  10  00003 
  11  00004 <span class="comment">/* This program is free software; you can redistribute it and/or modify</span>
  12  00005 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
  13  00006 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
  14  00007 <span class="comment"> * (at your option) any later version.</span>
  15  00008 <span class="comment"> *</span>
  16  00009 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
  17  00010 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
  18  00011 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
  19  00012 <span class="comment"> * GNU General Public License for more details.</span>
  20  00013 <span class="comment"> *</span>
  21  00014 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
  22  00015 <span class="comment"> * along with this program; if not, write to the Free Software</span>
  23  00016 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA</span>
  24  00017 <span class="comment"> */</span>
  25  00018 
  26  <a name="l00030"></a><a class="code" href="classTextile.html">00030</a> <span class="keyword">class </span><a class="code" href="classTextile.html">Textile</a> {
  27  <a name="l00037"></a><a class="code" href="classTextile.html#r0">00037</a>   var <a class="code" href="classTextile.html#r0">$options</a> = array();
  28  00038 
  29  <a name="l00046"></a><a class="code" href="classTextile.html#r1">00046</a>   var <a class="code" href="classTextile.html#r1">$urlre</a>;
  30  00047 
  31  <a name="l00055"></a><a class="code" href="classTextile.html#r2">00055</a>   var <a class="code" href="classTextile.html#r2">$punct</a>;
  32  00056 
  33  <a name="l00064"></a><a class="code" href="classTextile.html#r3">00064</a>   var <a class="code" href="classTextile.html#r3">$valignre</a>;
  34  00065 
  35  <a name="l00073"></a><a class="code" href="classTextile.html#r4">00073</a>   var <a class="code" href="classTextile.html#r4">$tblalignre</a>;
  36  00074 
  37  <a name="l00082"></a><a class="code" href="classTextile.html#r5">00082</a>   var <a class="code" href="classTextile.html#r5">$halignre</a>;
  38  00083 
  39  <a name="l00091"></a><a class="code" href="classTextile.html#r6">00091</a>   var <a class="code" href="classTextile.html#r6">$alignre</a>;
  40  00092 
  41  <a name="l00100"></a><a class="code" href="classTextile.html#r7">00100</a>   var <a class="code" href="classTextile.html#r7">$imgalignre</a>;
  42  00101 
  43  <a name="l00109"></a><a class="code" href="classTextile.html#r8">00109</a>   var <a class="code" href="classTextile.html#r8">$clstypadre</a>;
  44  00110 
  45  <a name="l00118"></a><a class="code" href="classTextile.html#r9">00118</a>   var <a class="code" href="classTextile.html#r9">$clstyre</a>;
  46  00119 
  47  <a name="l00127"></a><a class="code" href="classTextile.html#r10">00127</a>   var <a class="code" href="classTextile.html#r10">$clstyfiltre</a>;
  48  00128 
  49  <a name="l00136"></a><a class="code" href="classTextile.html#r11">00136</a>   var <a class="code" href="classTextile.html#r11">$codere</a>;
  50  00137 
  51  <a name="l00145"></a><a class="code" href="classTextile.html#r12">00145</a>   var <a class="code" href="classTextile.html#r12">$blocktags</a>;
  52  00146 
  53  <a name="l00152"></a><a class="code" href="classTextile.html#r13">00152</a>   var <a class="code" href="classTextile.html#r13">$links</a> = array();
  54  00153 
  55  <a name="l00165"></a><a class="code" href="classTextile.html#r14">00165</a>   var <a class="code" href="classTextile.html#r14">$repl</a> = array();
  56  00166 
  57  <a name="l00173"></a><a class="code" href="classTextile.html#r15">00173</a>   var <a class="code" href="classTextile.html#r15">$tmp</a> = array();
  58  00174 
  59  <a name="l00186"></a><a class="code" href="classTextile.html#a0">00186</a>   function <a class="code" href="classTextile.html">Textile</a>($options = array()) {
  60  00187     $this-&gt;options = <a class="code" href="classTextile.html#r0">$options</a>;
  61  00188     $this-&gt;options['<a class="code" href="classTextile.html#a12">filters</a>'] = ($this-&gt;options['<a class="code" href="classTextile.html#a12">filters</a>'] ? $this-&gt;options['<a class="code" href="classTextile.html#a12">filters</a>'] : array());
  62  00189     $this-&gt;options['<a class="code" href="classTextile.html#a7">charset</a>'] = ($this-&gt;options['<a class="code" href="classTextile.html#a7">charset</a>'] ? $this-&gt;options['<a class="code" href="classTextile.html#a7">charset</a>'] : 'iso-8859-1');
  63  00190     $this-&gt;options['<a class="code" href="classTextile.html#a13">char_encoding</a>'] = (isset($this-&gt;options['<a class="code" href="classTextile.html#a13">char_encoding</a>']) ? $this-&gt;options['<a class="code" href="classTextile.html#a13">char_encoding</a>'] : 1);
  64  00191     $this-&gt;options['do_quotes'] = (isset($this-&gt;options['do_quotes']) ? $this-&gt;options['do_quotes'] : 1);
  65  00192     $this-&gt;options['<a class="code" href="classTextile.html#a9">trim_spaces</a>'] = (isset($this-&gt;options['<a class="code" href="classTextile.html#a9">trim_spaces</a>']) ? $this-&gt;options['<a class="code" href="classTextile.html#a9">trim_spaces</a>'] : 0);
  66  00193     $this-&gt;options['smarty_mode'] = (isset($this-&gt;options['smarty_mode']) ? $this-&gt;options['smarty_mode'] : 1);
  67  00194     $this-&gt;options['<a class="code" href="classTextile.html#a11">preserve_spaces</a>'] = (iset($this-&gt;options['<a class="code" href="classTextile.html#a11">preserve_spaces</a>']) ? $this-&gt;options['preserve_spaaces'] : 0);
  68  00195     $this-&gt;options['<a class="code" href="classTextile.html#a4">head_offset</a>'] = (isset($this-&gt;options['<a class="code" href="classTextile.html#a4">head_offset</a>']) ? $this-&gt;options['<a class="code" href="classTextile.html#a4">head_offset</a>'] : 0);
  69  00196 
  70  00197     <span class="keywordflow">if</span> (is_array($this-&gt;options['<a class="code" href="classTextile.html#a6">css</a>'])) {
  71  00198       $this-&gt;<a class="code" href="classTextile.html#a6">css</a>($this-&gt;options['<a class="code" href="classTextile.html#a6">css</a>']);
  72  00199     }
  73  00200     $this-&gt;options['macros'] = ($this-&gt;options['macros'] ? $this-&gt;options['macros'] : $this-&gt;<a class="code" href="classTextile.html#d25">default_macros</a>());
  74  00201     <span class="keywordflow">if</span> (isset($this-&gt;options['<a class="code" href="classTextile.html#a5">flavor</a>'])) {
  75  00202       $this-&gt;<a class="code" href="classTextile.html#a5">flavor</a>($this-&gt;options['<a class="code" href="classTextile.html#a5">flavor</a>']);
  76  00203     } <span class="keywordflow">else</span> {
  77  00204       $this-&gt;<a class="code" href="classTextile.html#a5">flavor</a>('xhtml1/<a class="code" href="classTextile.html#a6">css</a>');
  78  00205     }
  79  00206     $this-&gt;<a class="code" href="classTextile.html#d0">_create_re</a>();
  80  00207   } <span class="comment">// function Textile</span>
  81  00208 
  82  00209   <span class="comment">// getter/setter methods...</span>
  83  00210 
  84  <a name="l00221"></a><a class="code" href="classTextile.html#a1">00221</a>   function <a class="code" href="classTextile.html#a1">set</a>($opt, $value = NULL) {
  85  00222     <span class="keywordflow">if</span> (is_array($opt)) {
  86  00223       foreach ($opt as $opt =&gt; $value) {
  87  00224         $this-&gt;set($opt, $value);
  88  00225       }
  89  00226     } <span class="keywordflow">else</span> {
  90  00227       <span class="comment">// the following options have special set methods</span>
  91  00228       <span class="comment">// that activate upon setting:</span>
  92  00229       <span class="keywordflow">if</span> ($opt == '<a class="code" href="classTextile.html#a7">charset</a>') {
  93  00230         $this-&gt;<a class="code" href="classTextile.html#a7">charset</a>($value);
  94  00231       } elseif ($opt == '<a class="code" href="classTextile.html#a6">css</a>') {
  95  00232         $this-&gt;css($value);
  96  00233       } elseif ($opt == '<a class="code" href="classTextile.html#a5">flavor</a>') {
  97  00234         $this-&gt;flavor($value);
  98  00235       } <span class="keywordflow">else</span> {
  99  00236         $this-&gt;options[$opt] = $value;
 100  00237       }
 101  00238     }
 102  00239   } <span class="comment">// function set</span>
 103  00240 
 104  <a name="l00251"></a><a class="code" href="classTextile.html#a2">00251</a>   function <a class="code" href="classTextile.html#a2">get</a>($opt) {
 105  00252     <span class="keywordflow">return</span> $this-&gt;options[$opt];
 106  00253   } <span class="comment">// function get</span>
 107  00254 
 108  <a name="l00269"></a><a class="code" href="classTextile.html#a3">00269</a>   function <a class="code" href="classTextile.html#a3">disable_html</a>($disable_html = NULL) {
 109  00270     <span class="keywordflow">if</span> ($disable_html != NULL) {
 110  00271       $this-&gt;options['disable_html'] = $disable_html;
 111  00272     }
 112  00273     <span class="keywordflow">return</span> ($this-&gt;options['disable_html'] ? $this-&gt;options['disable_html'] : 0);
 113  00274   } <span class="comment">// function disable_html</span>
 114  00275 
 115  <a name="l00290"></a><a class="code" href="classTextile.html#a4">00290</a>   function <a class="code" href="classTextile.html#a4">head_offset</a>($head_offset = NULL) {
 116  00291     <span class="keywordflow">if</span> ($head_offset != NULL) {
 117  00292       $this-&gt;options['head_offset'] = $head_offset;
 118  00293     }
 119  00294     <span class="keywordflow">return</span> ($this-&gt;options['head_offset'] ? $this-&gt;options['head_offset'] : 0);
 120  00295   } <span class="comment">// function head_offset</span>
 121  00296 
 122  <a name="l00313"></a><a class="code" href="classTextile.html#a5">00313</a>   function <a class="code" href="classTextile.html#a5">flavor</a>($flavor = NULL) {
 123  00314     <span class="keywordflow">if</span> ($flavor != NULL) {
 124  00315       $this-&gt;options['flavor'] = $flavor;
 125  00316       <span class="keywordflow">if</span> (preg_match('/^xhtml(\d)?(\D|$)/', $flavor, $matches)) {
 126  00317         <span class="keywordflow">if</span> ($matches[1] == <span class="charliteral">'2'</span>) {
 127  00318           $this-&gt;options['_line_open'] = '&lt;l&gt;';
 128  00319           $this-&gt;options['_line_close'] = '&lt;/l&gt;';
 129  00320           $this-&gt;options['_blockcode_open'] = '&lt;blockcode&gt;';
 130  00321           $this-&gt;options['_blockcode_close'] = '&lt;/blockcode&gt;';
 131  00322           $this-&gt;options['css_mode'] = 1;
 132  00323         } <span class="keywordflow">else</span> {
 133  00324           <span class="comment">// xhtml 1.x</span>
 134  00325           $this-&gt;options['_line_open'] = '';
 135  00326           $this-&gt;options['_line_close'] = '&lt;br /&gt;';
 136  00327           $this-&gt;options['_blockcode_open'] = '&lt;pre&gt;&lt;code&gt;';
 137  00328           $this-&gt;options['_blockcode_close'] = '&lt;/code&gt;&lt;/pre&gt;';
 138  00329           $this-&gt;options['css_mode'] = 1;
 139  00330         }
 140  00331       } elseif (preg_match('/^html/', $flavor)) {
 141  00332         $this-&gt;options['_line_open'] = '';
 142  00333         $this-&gt;options['_line_close'] = '&lt;br&gt;';
 143  00334         $this-&gt;options['_blockcode_open'] = '&lt;pre&gt;&lt;code&gt;';
 144  00335         $this-&gt;options['_blockcode_close'] = '&lt;/code&gt;&lt;/pre&gt;';
 145  00336         $this-&gt;options['css_mode'] = preg_match('/\/<a class="code" href="classTextile.html#a6">css</a>/', $flavor);
 146  00337       }
 147  00338       <span class="keywordflow">if</span> ($this-&gt;options['css_mode'] &amp;&amp; !isset($this-&gt;options['<a class="code" href="classTextile.html#a6">css</a>'])) { $this-&gt;<a class="code" href="classTextile.html#d26">_css_defaults</a>(); }
 148  00339     }
 149  00340     <span class="keywordflow">return</span> $this-&gt;options['flavor'];
 150  00341   } <span class="comment">// function flavor</span>
 151  00342 
 152  <a name="l00404"></a><a class="code" href="classTextile.html#a6">00404</a>   function <a class="code" href="classTextile.html#a6">css</a>($css = NULL) {
 153  00405     <span class="keywordflow">if</span> ($css != NULL) {
 154  00406       <span class="keywordflow">if</span> (is_array($css)) {
 155  00407         $this-&gt;options['css'] = $css;
 156  00408         $this-&gt;options['css_mode'] = 1;
 157  00409       } <span class="keywordflow">else</span> {
 158  00410         $this-&gt;options['css_mode'] = $css;
 159  00411         <span class="keywordflow">if</span> ($this-&gt;options['css_mode'] &amp;&amp; !isset($this-&gt;options['css'])) { $this-&gt;<a class="code" href="classTextile.html#d26">_css_defaults</a>(); }
 160  00412       }
 161  00413     }
 162  00414     <span class="keywordflow">return</span> ($this-&gt;options['css_mode'] ? $this-&gt;options['css'] : 0);
 163  00415   } <span class="comment">// function css</span>
 164  00416 
 165  <a name="l00433"></a><a class="code" href="classTextile.html#a7">00433</a>   function <a class="code" href="classTextile.html#a7">charset</a>($charset = NULL) {
 166  00434     <span class="keywordflow">if</span> ($charset != NULL) {
 167  00435         $this-&gt;options['charset'] = $charset;
 168  00436         <span class="keywordflow">if</span> (preg_match('/^utf-?8$/i', $this-&gt;options['charset'])) {
 169  00437           $this-&gt;<a class="code" href="classTextile.html#a13">char_encoding</a>(0);
 170  00438         } <span class="keywordflow">else</span> {
 171  00439           $this-&gt;<a class="code" href="classTextile.html#a13">char_encoding</a>(1);
 172  00440         }
 173  00441     }
 174  00442     <span class="keywordflow">return</span> $this-&gt;options['charset'];
 175  00443   } <span class="comment">// function charset</span>
 176  00444 
 177  <a name="l00458"></a><a class="code" href="classTextile.html#a8">00458</a>   function <a class="code" href="classTextile.html#a8">docroot</a>($docroot = NULL) {
 178  00459     <span class="keywordflow">if</span> ($docroot != NULL) {
 179  00460       $this-&gt;options['docroot'] = $docroot;
 180  00461     }
 181  00462     <span class="keywordflow">return</span> $this-&gt;options['docroot'];
 182  00463   } <span class="comment">// function docroot</span>
 183  00464 
 184  <a name="l00478"></a><a class="code" href="classTextile.html#a9">00478</a>   function <a class="code" href="classTextile.html#a9">trim_spaces</a>($trim_spaces = NULL) {
 185  00479     <span class="keywordflow">if</span> ($trim_spaces != NULL) {
 186  00480       $this-&gt;options['trim_spaces'] = $trim_spaces;
 187  00481     }
 188  00482     <span class="keywordflow">return</span> $this-&gt;options['trim_spaces'];
 189  00483   } <span class="comment">// function trim_spaces</span>
 190  00484 
 191  <a name="l00495"></a><a class="code" href="classTextile.html#a10">00495</a>   function <a class="code" href="classTextile.html#a10">filter_param</a>($filter_param = NULL) {
 192  00496     <span class="keywordflow">if</span> ($filter_param != NULL) {
 193  00497       $this-&gt;options['filter_param'] = $filter_param;
 194  00498     }
 195  00499     <span class="keywordflow">return</span> $this-&gt;options['filter_param'];
 196  00500   } <span class="comment">// function filter_param</span>
 197  00501 
 198  <a name="l00518"></a><a class="code" href="classTextile.html#a11">00518</a>   function <a class="code" href="classTextile.html#a11">preserve_spaces</a>($preserve_spaces = NULL) {
 199  00519     <span class="keywordflow">if</span> ($preserve_spaces != NULL) {
 200  00520       $this-&gt;options['preserve_spaces'] = $preserve_spaces;
 201  00521     }
 202  00522     <span class="keywordflow">return</span> $this-&gt;options['preserve_spaces'];
 203  00523   } <span class="comment">// function preserve_spaces</span>
 204  00524 
 205  <a name="l00537"></a><a class="code" href="classTextile.html#a12">00537</a>   function <a class="code" href="classTextile.html#a12">filters</a>($filters = NULL) {
 206  00538     <span class="keywordflow">if</span> ($filters != NULL) {
 207  00539       $this-&gt;options['filters'] = $filters;
 208  00540     }
 209  00541     <span class="keywordflow">return</span> $this-&gt;options['filters'];
 210  00542   } <span class="comment">// function filters</span>
 211  00543 
 212  <a name="l00558"></a><a class="code" href="classTextile.html#a13">00558</a>   function <a class="code" href="classTextile.html#a13">char_encoding</a>($char_encoding = NULL) {
 213  00559     <span class="keywordflow">if</span> ($char_encoding != NULL) {
 214  00560       $this-&gt;options['char_encoding'] = $char_encoding;
 215  00561     }
 216  00562     <span class="keywordflow">return</span> $this-&gt;options['char_encoding'];
 217  00563   } <span class="comment">// function char_encoding</span>
 218  00564 
 219  <a name="l00577"></a><a class="code" href="classTextile.html#a14">00577</a>   function <a class="code" href="classTextile.html#a14">handle_quotes</a>($do_quotes = NULL) {
 220  00578     <span class="keywordflow">if</span> ($do_quotes != NULL) {
 221  00579       $this-&gt;options['do_quotes'] = $do_quotes;
 222  00580     }
 223  00581     <span class="keywordflow">return</span> $this-&gt;options['do_quotes'];
 224  00582   } <span class="comment">// function handle_quotes</span>
 225  00583 
 226  00584   <span class="comment">// end of getter/setter methods</span>
 227  00585 
 228  <a name="l00599"></a><a class="code" href="classTextile.html#d0">00599</a>   function <a class="code" href="classTextile.html#d0">_create_re</a>() {
 229  00600     <span class="comment">// a URL discovery regex. This is from Mastering Regex from O'Reilly.</span>
 230  00601     <span class="comment">// Some modifications by Brad Choate &lt;brad at bradchoate dot com&gt;</span>
 231  00602     $this-&gt;urlre = '(?:
 232  00603 <span class="preprocessor">    # Must start out right...</span>
 233  00604 <span class="preprocessor"></span>    (?=[a-zA-Z0-9./#])
 234  00605 <span class="preprocessor">    # Match the leading part (proto://hostname, or just hostname)</span>
 235  00606 <span class="preprocessor"></span>    (?:
 236  00607 <span class="preprocessor">        # ftp://, http://, or https:// leading part</span>
 237  00608 <span class="preprocessor"></span>        (?:ftp|https?|telnet|nntp):<span class="comment">//(?:\w+(?::\w+)?@)?[-\w]+(?:\.\w[-\w]*)+</span>
 238  00609         |
 239  00610         (?:mailto:)?[-\+\w]+@[-\w]+(?:\.\w[-\w]*)+
 240  00611         |
 241  00612 <span class="preprocessor">        # or, try to find a hostname with our more specific sub-expression</span>
 242  00613 <span class="preprocessor"></span>        (?i: [a-z0-9] (?:[-a-z0-9]*[a-z0-9])? \. )+ # sub domains
 243  00614 <span class="preprocessor">        # Now ending .com, etc. For these, require lowercase</span>
 244  00615 <span class="preprocessor"></span>        (?-i: com\b
 245  00616             | edu\b
 246  00617             | biz\b
 247  00618             | gov\b
 248  00619             | in(?:t|fo)\b # .int or .info
 249  00620             | mil\b
 250  00621             | net\b
 251  00622             | org\b
 252  00623             | museum\b
 253  00624             | aero\b
 254  00625             | coop\b
 255  00626             | name\b
 256  00627             | pro\b
 257  00628             | [a-z][a-z]\b # two-letter country codes
 258  00629         )
 259  00630     )?
 260  00631 
 261  00632 <span class="preprocessor">    # Allow an optional port number</span>
 262  00633 <span class="preprocessor"></span>    (?: : \d+ )?
 263  00634 
 264  00635 <span class="preprocessor">    # The rest of the URL is optional, and begins with / . . .</span>
 265  00636 <span class="preprocessor"></span>    (?:
 266  00637      /?
 267  00638 <span class="preprocessor">     # The rest are heuristics for what seems to work well</span>
 268  00639 <span class="preprocessor"></span>     [^.!,?;:<span class="stringliteral">"\'&lt;&gt;()\[\]{}\s\x7F-\xFF]*</span>
 269  00640 <span class="stringliteral">     (?:</span>
 270  00641 <span class="stringliteral">        [.!,?;:]+  [^.!,?;:"</span>\'&lt;&gt;()\[\]{}\s\x7F-\xFF]+ #\'<span class="stringliteral">"</span>
 271  00642 <span class="stringliteral">     )*</span>
 272  00643 <span class="stringliteral">    )?</span>
 273  00644 <span class="stringliteral">)';</span>
 274  00645 <span class="stringliteral"></span>
 275  00646 <span class="stringliteral">    $this-&gt;punct = '[\!"</span>\#\$%&amp;\'()\*\+,\-\./:;&lt;=&gt;\?@\[\\\\\]\^_`{\|}\~]';
 276  00647     $this-&gt;valignre = '[\-^~]';
 277  00648     $this-&gt;tblalignre = '[&lt;&gt;=]';
 278  00649     $this-&gt;halignre = '(?:&lt;&gt;|[&lt;&gt;=])';
 279  00650     $this-&gt;alignre = '(?:(?:' . $this-&gt;valignre . '|&lt;&gt;' . $this-&gt;valignre . '?|' . $this-&gt;valignre . '?&lt;&gt;|' . $this-&gt;valignre . <span class="charliteral">'?'</span> . $this-&gt;halignre . '?|' . $this-&gt;halignre . <span class="charliteral">'?'</span> . $this-&gt;valignre . '?)(?!\w))';
 280  00651     $this-&gt;imgalignre = '(?:(?:[&lt;&gt;]|' . $this-&gt;valignre . '){1,2})';
 281  00652 
 282  00653     $this-&gt;clstypadre = '(?:
 283  00654   (?:\([A-Za-z0-9_\- \#]+\))
 284  00655   |
 285  00656   (?:{
 286  00657       (?: \( [^)]+ \) | [^\}] )+
 287  00658      })
 288  00659   |
 289  00660   (?:\(+? (?![A-Za-z0-9_\-\#]) )
 290  00661   |
 291  00662   (?:\)+?)
 292  00663   |
 293  00664   (?: \[ [a-zA-Z\-]+? \] )
 294  00665 )';
 295  00666 
 296  00667     $this-&gt;clstyre = '(?:
 297  00668   (?:\([A-Za-z0-9_\- \#]+\))
 298  00669   |
 299  00670   (?:{
 300  00671       [A-Za-z0-9_\-](?: \( [^)]+ \) | [^\}] )+
 301  00672      })
 302  00673   |
 303  00674   (?: \[ [a-zA-Z\-]+? \] )
 304  00675 )';
 305  00676 
 306  00677     $this-&gt;clstyfiltre = '(?:
 307  00678   (?:\([A-Za-z0-9_\- \#]+\))
 308  00679   |
 309  00680   (?:{
 310  00681       [A-Za-z0-9_\-](?: \( [^)]+ \) | [^\}] )+
 311  00682      })
 312  00683   |
 313  00684   (?:\|[^\|]+\|)
 314  00685   |
 315  00686   (?:\(+?(?![A-Za-z0-9_\-\#]))
 316  00687   |
 317  00688   (?:\)+)
 318  00689   |
 319  00690   (?: \[ [a-zA-Z]+? \] )
 320  00691 )';
 321  00692 
 322  00693     $this-&gt;codere = '(?:
 323  00694     (?:
 324  00695       [\[{]
 325  00696       @                           # opening
 326  00697       (?:\[([A-Za-z0-9]+)\])?     # $1: language <span class="keywordtype">id</span>
 327  00698       (.+?)                       # $2: code
 328  00699       @                           # closing
 329  00700       [\]}]
 330  00701     )
 331  00702     |
 332  00703     (?:
 333  00704       (?:^|(?&lt;=[\s\(]))
 334  00705       @                           # opening
 335  00706       (?:\[([A-Za-z0-9]+)\])?     # $3: language <span class="keywordtype">id</span>
 336  00707       ([^\s].+?[^\s])             # $4: code itself
 337  00708       @                           # closing
 338  00709       (?:$|(?=' . $this-&gt;punct . '{1,2}|\s))
 339  00710     )
 340  00711 )';
 341  00712 
 342  00713     $this-&gt;blocktags = '
 343  00714     &lt;
 344  00715     (( /? ( h[1-6]
 345  00716      | p
 346  00717      | pre
 347  00718      | div
 348  00719      | table
 349  00720      | t[rdh]
 350  00721      | [ou]l
 351  00722      | li
 352  00723      | block(?:quote|code)
 353  00724      | form
 354  00725      | input
 355  00726      | select
 356  00727      | option
 357  00728      | textarea
 358  00729      )
 359  00730     [ &gt;]
 360  00731     )
 361  00732     | !--
 362  00733     )
 363  00734 ';
 364  00735   } <span class="comment">// function _create_re</span>
 365  00736 
 366  <a name="l00746"></a><a class="code" href="classTextile.html#a15">00746</a>   function process($str) {
 367  00747     <span class="comment">/*</span>
 368  00748 <span class="comment">     * Function names in PHP are case insensitive, so function</span>
 369  00749 <span class="comment">     * textile() cannot be redefined.  Thus, this PHP implementation</span>
 370  00750 <span class="comment">     * will only use process().</span>
 371  00751 <span class="comment">     *</span>
 372  00752 <span class="comment">     *   return $this-&gt;textile($str);</span>
 373  00753 <span class="comment">     * } // function process</span>
 374  00754 <span class="comment">     *</span>
 375  00755 <span class="comment">     * function textile($str) {</span>
 376  00756 <span class="comment">     */</span>
 377  00757 
 378  00758     <span class="comment">// quick translator for abbreviated block names</span>
 379  00759     <span class="comment">// to their tag</span>
 380  00760     $macros = array('bq' =&gt; 'blockquote');
 381  00761 
 382  00762     <span class="comment">// an array to hold any portions of the text to be preserved</span>
 383  00763     <span class="comment">// without further processing by Textile</span>
 384  00764     array_unshift($this-&gt;repl, array());
 385  00765 
 386  00766     <span class="comment">// strip out extra newline characters. we're only matching for \n herein</span>
 387  00767     <span class="comment">//$str = preg_replace('!(?:\r?\n|\r)!', "\n", $str);</span>
 388  00768     $str = preg_replace('!(?:\015?\012|\015)!', <span class="stringliteral">"\n"</span>, $str);
 389  00769 
 390  00770     <span class="comment">// optionally remove trailing spaces</span>
 391  00771     <span class="keywordflow">if</span> ($this-&gt;options['trim_spaces']) { $str = preg_replace('/ +$/m', '', $str); }
 392  00772 
 393  00773     <span class="comment">// preserve contents of the '==', 'pre', 'blockcode' sections</span>
 394  00774     $str = preg_replace_callback('{(^|\n\n)==(.+?)==($|\n\n)}s',
 395  00775                                  $this-&gt;_cb('<span class="stringliteral">"$m[1]\n\n"</span> . $me-&gt;_repl($me-&gt;repl[0], $me-&gt;format_block(array(<span class="stringliteral">"text"</span> =&gt; $m[2]))) . <span class="stringliteral">"\n\n$m[3]"</span>'), $str);
 396  00776 
 397  00777     <span class="keywordflow">if</span> (!$this-&gt;disable_html()) {
 398  00778       <span class="comment">// preserve style, script tag contents</span>
 399  00779       $str = preg_replace_callback('!(&lt;(style|script)(?:&gt;| .+?&gt;).*?&lt;/\2&gt;)!s', $this-&gt;_cb('$me-&gt;_repl($me-&gt;repl[0], $m[1])'), $str);
 400  00780 
 401  00781       <span class="comment">// preserve HTML comments</span>
 402  00782       $str = preg_replace_callback('|(&lt;!--.+?--&gt;)|s', $this-&gt;_cb('$me-&gt;_repl($me-&gt;repl[0], $m[1])'), $str);
 403  00783 
 404  00784       <span class="comment">// preserve pre block contents, encode contents by default</span>
 405  00785       $pre_start = count($this-&gt;repl[0]);
 406  00786       $str = preg_replace_callback('{(&lt;pre(?: [^&gt;]*)?&gt;)(.+?)(&lt;/pre&gt;)}s',
 407  00787                                    $this-&gt;_cb('<span class="stringliteral">"\n\n"</span> . $me-&gt;_repl($me-&gt;repl[0], $m[1] . $me-&gt;encode_html($m[2], 1) . $m[3]) . <span class="stringliteral">"\n\n"</span>'), $str);
 408  00788       <span class="comment">// fix code tags within pre blocks we just saved.</span>
 409  00789       <span class="keywordflow">for</span> ($i = $pre_start; $i &lt; count($this-&gt;repl[0]); $i++) {
 410  00790         $this-&gt;repl[0][$i] = preg_replace('|&amp;lt;(/?)code(.*?)&amp;gt;|s', '&lt;$1code$2&gt;', $this-&gt;repl[0][$i]);
 411  00791       }
 412  00792 
 413  00793       <span class="comment">// preserve code blocks by default, encode contents</span>
 414  00794       $str = preg_replace_callback('{(&lt;code(?: [^&gt;]+)?&gt;)(.+?)(&lt;/code&gt;)}s',
 415  00795                                    $this-&gt;_cb('$me-&gt;_repl($me-&gt;repl[0], $m[1] . $me-&gt;encode_html($m[2], 1) . $m[3])'), $str);
 416  00796 
 417  00797       <span class="comment">// encode blockcode tag (an XHTML 2 tag) and encode it's</span>
 418  00798       <span class="comment">// content by default</span>
 419  00799       $str = preg_replace_callback('{(&lt;blockcode(?: [^&gt;]+)?&gt;)(.+?)(&lt;/blockcode&gt;)}s',
 420  00800                                    $this-&gt;_cb('<span class="stringliteral">"\n\n"</span> . $me-&gt;_repl($me-&gt;repl[0], $m[1] . $me-&gt;encode_html($m[2], 1) . $m[3]) . <span class="stringliteral">"\n\n"</span>'), $str);
 421  00801 
 422  00802       <span class="comment">// preserve PHPish, ASPish code</span>
 423  00803       $str = preg_replace_callback('!(&lt;([\?%]).*?(\2)&gt;)!s', $this-&gt;_cb('$me-&gt;_repl($me-&gt;repl[0], $m[1])'), $str);
 424  00804     }
 425  00805 
 426  00806     <span class="comment">// pass through and remove links that follow this format</span>
 427  00807     <span class="comment">// [id_without_spaces (optional title text)]url</span>
 428  00808     <span class="comment">// lines like this are stripped from the content, and can be</span>
 429  00809     <span class="comment">// referred to using the "link text":id_without_spaces syntax</span>
 430  00810     <span class="comment">//$links = array();</span>
 431  00811     $str = preg_replace_callback('{(?:\n|^) [ ]* \[ ([^ ]+?) [ ]*? (?:\( (.+?) \) )?  \] ((?:(?:ftp|https?|telnet|nntp):<span class="comment">//|/)[^ ]+?) [ ]* (\n|$)}mx',</span>
 432  00812                                  $this-&gt;_cb('($me-&gt;links[$m[1]] = array(<span class="stringliteral">"url"</span> =&gt; $m[3], <span class="stringliteral">"title"</span> =&gt; $m[2])) ? $m[4] : $m[4]'), $str);
 433  00813     <span class="comment">//$this-&gt;links = $links;</span>
 434  00814 
 435  00815     <span class="comment">// eliminate starting/ending blank lines</span>
 436  00816     $str = preg_replace('/^\n+/s', '', $str, 1);
 437  00817     $str = preg_replace('/\n+$/s', '', $str, 1);
 438  00818 
 439  00819     <span class="comment">// split up text into paragraph blocks, capturing newlines too</span>
 440  00820     $para = preg_split('/(\n{2,})/', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
 441  00821     unset($block, $bqlang, $filter, $<span class="keyword">class</span>, $sticky, $lines,
 442  00822           $style, $stickybuff, $lang, $clear);
 443  00823 
 444  00824     $out = '';
 445  00825 
 446  00826     foreach ($para as $para) {
 447  00827       <span class="keywordflow">if</span> (preg_match('/^\n+$/s', $para)) {
 448  00828         <span class="keywordflow">if</span> ($sticky &amp;&amp; $stickybuff) {
 449  00829           $stickybuff .= $para;
 450  00830         } <span class="keywordflow">else</span> {
 451  00831           $out .= $para;
 452  00832         }
 453  00833         <span class="keywordflow">continue</span>;
 454  00834       }
 455  00835 
 456  00836       <span class="keywordflow">if</span> ($sticky) {
 457  00837         $sticky++;
 458  00838       } <span class="keywordflow">else</span> {
 459  00839         unset($block);
 460  00840         unset($<span class="keyword">class</span>);
 461  00841         $style = '';
 462  00842         unset($lang);
 463  00843       }
 464  00844 
 465  00845       unset($<span class="keywordtype">id</span>, $cite, $align, $padleft, $padright, $lines, $buffer);
 466  00846       <span class="keywordflow">if</span> (preg_match('{^(h[1-6]|p|bq|bc|fn\d+)
 467  00847                         ((?:' . $this-&gt;clstyfiltre . '*|' . $this-&gt;halignre . ')*)
 468  00848                         (\.\.?)
 469  00849                         (?::(\d+|' . $this-&gt;urlre . '))?\ (.*)$}sx', $para, $matches)) {
 470  00850         <span class="keywordflow">if</span> ($sticky) {
 471  00851           <span class="keywordflow">if</span> ($block == 'bc') {
 472  00852             <span class="comment">// close our blockcode section</span>
 473  00853             $out = preg_replace('/\n\n$/', '', $out, 1);
 474  00854             $out .= $this-&gt;options['_blockcode_close'] . <span class="stringliteral">"\n\n"</span>;
 475  00855           } elseif ($block == 'bq') {
 476  00856             $out = preg_replace('/\n\n$/', '', $out, 1);
 477  00857             $out .= '&lt;/blockquote&gt;' . <span class="stringliteral">"\n\n"</span>;
 478  00858           } elseif ($block == 'table') {
 479  00859             $table_out = $this-&gt;format_table(array('text' =&gt; $stickybuff));
 480  00860             <span class="keywordflow">if</span> (!$table_out) { $table_out = ''; }
 481  00861             $out .= $table_out;
 482  00862             unset($stickybuff);
 483  00863           } elseif ($block == 'dl') {
 484  00864             $dl_out = $this-&gt;format_deflist(array('text' =&gt; $stickybuff));
 485  00865             <span class="keywordflow">if</span> (!$dl_out) { $dl_out = ''; }
 486  00866             $out .= $dl_out;
 487  00867             unset($stickybuff);
 488  00868           }
 489  00869           $sticky = 0;
 490  00870         }
 491  00871         <span class="comment">// block macros: h[1-6](class)., bq(class)., bc(class)., p(class).</span>
 492  00872         <span class="comment">//warn "paragraph: [[$para]]\n\tblock: $1\n\tparams: $2\n\tcite: $4";</span>
 493  00873         $block = $matches[1];
 494  00874         $params = $matches[2];
 495  00875