Changeset 1164 for trunk/www/wiki/Textile.php
- Timestamp:
- 01/14/12 16:18:10 (4 months ago)
- File:
-
- 1 edited
-
trunk/www/wiki/Textile.php (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/wiki/Textile.php
r918 r1164 773 773 774 774 // preserve contents of the '==', 'pre', 'blockcode' sections 775 $me =& $this; 775 776 $str = preg_replace_callback('/( (?<=\n\n)== | (?<=^)== ) (.+?) ( ==(?=\n\n) | ==(?=$) ) /sx', 776 $this->_cb('$me->_repl($me->repl[0], $me->format_block(array("text" => $m[2])))'), $str); 777 function($m) use ($me) { 778 return $me->_repl($me->repl[0], $me->format_block(array("text" => $m[2]))); 779 }, $str); 777 780 778 781 if (!$this->disable_html()) { 779 782 // preserve style, script tag contents 780 $str = preg_replace_callback('!(<(style|script)(?:>| .+?>).*?</\2>)!s', $this->_cb('$me->_repl($me->repl[0], $m[1])'), $str); 783 $str = preg_replace_callback('!(<(style|script)(?:>| .+?>).*?</\2>)!s', 784 function($m) use ($me) { 785 return $me->_repl($me->repl[0], $m[1]); 786 }, $str); 781 787 782 788 // preserve HTML comments 783 $str = preg_replace_callback('|(<!--.+?-->)|s', $this->_cb('$me->_repl($me->repl[0], $m[1])'), $str); 789 $str = preg_replace_callback('|(<!--.+?-->)|s', 790 function($m) use ($me) { 791 return $me->_repl($me->repl[0], $m[1]); 792 }, $str); 784 793 785 794 // preserve pre block contents, encode contents by default 786 795 $pre_start = count($this->repl[0]); 787 796 $str = preg_replace_callback('{(<pre(?: [^>]*)?>)(.+?)(</pre>)}s', 788 $this->_cb('"\n\n" . $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]) . "\n\n"'), $str); 797 function($m) use ($me) { 798 return "\n\n" . $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]) . "\n\n"; 799 }, $str); 789 800 // fix code tags within pre blocks we just saved. 790 801 for ($i = $pre_start; $i < count($this->repl[0]); $i++) { … … 794 805 // preserve code blocks by default, encode contents 795 806 $str = preg_replace_callback('{(<code(?: [^>]+)?>)(.+?)(</code>)}s', 796 $this->_cb('$me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3])'), $str); 807 function($m) use ($me) { 808 return $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]); 809 }, $str); 797 810 798 811 // encode blockcode tag (an XHTML 2 tag) and encode it's 799 812 // content by default 800 813 $str = preg_replace_callback('{(<blockcode(?: [^>]+)?>)(.+?)(</blockcode>)}s', 801 $this->_cb('"\n\n" . $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]) . "\n\n"'), $str); 814 function($m) use ($me) { 815 return "\n\n" . $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]) . "\n\n"; 816 }, $str); 802 817 } 803 818 804 819 // LaTeX code 805 $str = preg_replace_callback('!((<tex>)(.*?)(<\/tex>))!s', $this->_cb('$me->_repl($me->repl[0], $me->format_latex(array("text" => $m[3])))'), $str); 820 $str = preg_replace_callback('!((<tex>)(.*?)(<\/tex>))!s', 821 function($m) use ($me) { 822 return $me->_repl($me->repl[0], $me->format_latex(array("text" => $m[3]))); 823 }, $str); 806 824 807 825 // pass through and remove links that follow this format … … 811 829 //$links = array(); 812 830 $str = preg_replace_callback('{(?:\n|^) [ ]* \[ ([^ ]+?) [ ]*? (?:\( (.+?) \) )? \] ((?:(?:ftp|https?|telnet|nntp)://|/)[^ ]+?) [ ]* (\n|$)}mx', 813 $this->_cb('($me->links[$m[1]] = array("url" => $m[3], "title" => $m[2])) ? $m[4] : $m[4]'), $str); 831 function($m) use ($me) { 832 return ($me->links[$m[1]] = array("url" => $m[3], "title" => $m[2])) ? $m[4] : $m[4]; 833 }, $str); 814 834 //$this->links = $links; 815 835 … … 1032 1052 // ==(.+?)== 1033 1053 // (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s))}sx', 1034 // $this->_cb('$me->_repl($me->repl[0], $me->format_block(array("text" => $m[2], "inline" => 1, "pre" => $m[1], "post" => $m[3])))'), $para); 1054 // function($m) use ($me) { 1055 // return $me->_repl($me->repl[0], $me->format_block(array("text" => $m[2], "inline" => 1, "pre" => $m[1], "post" => $m[3]))); 1056 // }, $para); 1035 1057 $buffer .= $this->encode_html_basic($para, 1); 1036 1058 $buffer = preg_replace('/<textile#(\d+)>/', '<textile#$1>', $buffer); … … 1209 1231 1210 1232 array_unshift($this->repl, array()); 1233 $me =& $this; 1211 1234 $buffer = preg_replace_callback('{(?:^|(?<=[\s>])|([{[])) 1212 1235 ==(.+?)== 1213 1236 (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s))}sx', 1214 $this->_cb('$me->_repl($me->repl[0], $me->format_block(array("text" => $m[2], "inline" => 1, "pre" => $m[1], "post" => $m[3])))'), $buffer); 1237 function($m) use ($me) { 1238 return $me->_repl($me->repl[0], $me->format_block(array("text" => $m[2], "inline" => 1, "pre" => $m[1], "post" => $m[3]))); 1239 }, $buffer); 1215 1240 1216 1241 unset($tokens); … … 1317 1342 array_unshift($this->repl, array()); 1318 1343 1319 $text = preg_replace_callback('{' . $this->codere . '}mx', $this->_cb('$me->_repl($me->repl[0], $me->format_code(array("text" => $m[2] . $m[4], "lang" => $m[1] . $m[3])))'), $text); 1344 $me =& $this; 1345 $text = preg_replace_callback('{' . $this->codere . '}mx', 1346 function($m) use ($me) { 1347 return $me->_repl($me->repl[0], $me->format_code(array("text" => $m[2] . $m[4], "lang" => $m[1] . $m[3]))); 1348 }, $text); 1320 1349 1321 1350 // images must be processed before encoding the text since they might … … 1334 1363 (?::(\d+|' . $this->urlre . '))? # $7: optional URL 1335 1364 (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s)) # $8: closing brace/bracket 1336 }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_image(array("pre" => $m[1], "src" => $m[5], "align" => ($m[2] ? $m[2] : $m[4]), "extra" => $m[6], "url" => $m[7], "clsty" => $m[3], "post" => $m[8])))'), $text); 1365 }mx', 1366 function($m) use ($me) { 1367 return $me->_repl($me->repl[0], $me->format_image(array("pre" => $m[1], "src" => $m[5], "align" => ($m[2] ? $m[2] : $m[4]), "extra" => $m[6], "url" => $m[7], "clsty" => $m[3], "post" => $m[8]))); 1368 }, $text); 1337 1369 1338 1370 $text = preg_replace_callback('{(?:^|(?<=[\s>])|([{[])) # $1: open brace/bracket … … 1346 1378 (?::(\d+|' . $this->urlre . '))? # $6: optional URL 1347 1379 (?:$|([]}])|(?=' . $this->punct . '{1,2}|\s)) # $7: closing brace/bracket 1348 }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_span(array("pre" => $m[1], "text" => $m[5], "align" => ($m[2] ? $m[2] : $m[4]), "cite" => $m[6], "clsty" => $m[3], "post" => $m[7])))'), $text); 1380 }mx', 1381 function($m) use ($me) { 1382 return $me->_repl($me->repl[0], $me->format_span(array("pre" => $m[1], "text" => $m[5], "align" => ($m[2] ? $m[2] : $m[4]), "cite" => $m[6], "clsty" => $m[3], "post" => $m[7]))); 1383 }, $text); 1349 1384 1350 1385 $text = $this->encode_html($text); … … 1378 1413 [\]}] 1379 1414 ) 1380 }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_link(array("text" => $m[1], "linktext" => $m[3] . $m[6], "title" => $me->encode_html_basic($m[4] . $m[7]), "url" => $m[8], "clsty" => $m[2] . $m[5])))'), $text); 1415 }mx', 1416 function($m) use ($me) { 1417 return $me->_repl($me->repl[0], $me->format_link(array("text" => $m[1], "linktext" => $m[3] . $m[6], "title" => $me->encode_html_basic($m[4] . $m[7]), "url" => $m[8], "clsty" => $m[2] . $m[5]))); 1418 }, $text); 1381 1419 1382 1420 $text = preg_replace_callback('{((?:^|(?<=[\s>\(])) # $1: open brace/bracket … … 1397 1435 :(\d+|' . $this->urlre . ') # $8: URL suffix 1398 1436 (?:$|(?=' . $this->punct . '{1,2}|\s))) # $9: closing brace/bracket 1399 }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_link(array("text" => $m[1], "linktext" => $m[3] . $m[6], "title" => $me->encode_html_basic($m[4] . $m[7]), "url" => $m[8], "clsty" => $m[2] . $m[5])))'), $text); 1437 }mx', 1438 function($m) use ($me) { 1439 return $me->_repl($me->repl[0], $me->format_link(array("text" => $m[1], "linktext" => $m[3] . $m[6], "title" => $me->encode_html_basic($m[4] . $m[7]), "url" => $m[8], "clsty" => $m[2] . $m[5]))); 1440 }, $text); 1400 1441 1401 1442 if (preg_match('/^xhtml2/', $this->flavor())) { … … 1407 1448 :(\d+|' . $this->urlre . ') # $3: optional citation URL 1408 1449 (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s)) # $4: closing brace/bracket 1409 }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_cite(array("pre" => $m[1], "text" => $m[2], "cite" => $m[3], "post" => $m[4])))'), $text); 1450 }mx', 1451 function($m) use ($me) { 1452 return $me->_repl($me->repl[0], $me->format_cite(array("pre" => $m[1], "text" => $m[2], "cite" => $m[3], "post" => $m[4]))); 1453 }, $text); 1410 1454 } 1411 1455 … … 1420 1464 // translate macros: 1421 1465 $text = preg_replace_callback('{(\{)(.+?)(\})}x', 1422 $this->_cb('$me->format_macro(array("pre" => $m[1], "post" => $m[3], "macro" => $m[2]))'), $text); 1466 function($m) use ($me) { 1467 return $me->format_macro(array("pre" => $m[1], "post" => $m[3], "macro" => $m[2])); 1468 }, $text); 1423 1469 1424 1470 // these were present with textile 1 and are common enough … … 1450 1496 (?<=\S)' . $qf . ' # 1451 1497 (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s)) # $4 - post 1452 }mx', $this->_cb('$me->format_tag(array("tag" => end($me->tmp["r"]), "marker" => end($me->tmp["f"]), "pre" => $m[1], "text" => $m[3], "clsty" => $m[2], "post" => $m[4]))'), $text))) { 1498 }mx', 1499 function($m) use ($me) { 1500 return $me->format_tag(array("tag" => end($me->tmp["r"]), "marker" => end($me->tmp["f"]), "pre" => $m[1], "text" => $m[3], "clsty" => $m[2], "post" => $m[4])); 1501 }, $text))) { 1453 1502 $redo = ($redo || ($last != $text)); 1454 1503 $last = $text; … … 1463 1512 // ABC(Aye Bee Cee) -> acronym 1464 1513 $text = preg_replace_callback('{\b([A-Z][A-Za-z0-9]*?[A-Z0-9]+?)\b(?:[(]([^)]*)[)])}', 1465 $this->_cb('$me->_repl($me->repl[0],"<acronym title=\"" . $me->encode_html_basic($m[2]) . "\">$m[1]</acronym>")'), $text); 1514 function($m) use ($me) { 1515 return $me->_repl($me->repl[0],"<acronym title=\"" . $me->encode_html_basic($m[2]) . "\">$m[1]</acronym>"); 1516 }, $text); 1466 1517 1467 1518 // ABC -> 'capped' span … … 1470 1521 ((?:[A-Z](?:[A-Z0-9\.,\']|\&){2,}\ *)+?) # \' 1471 1522 (?=[^A-Z\.0-9]|$) 1472 /mx', $this->_cb('$m[1] . $me->_repl($me->repl[0], "<span class=\"" . end($me->tmp["caps"]) . "\">$m[2]</span>")'), $text); 1523 /mx', 1524 function($m) use ($me) { 1525 return $m[1] . $me->_repl($me->repl[0], "<span class=\"" . end($me->tmp["caps"]) . "\">$m[2]</span>"); 1526 }, $text); 1473 1527 } 1474 1528 array_pop($this->tmp['caps']); … … 2102 2156 $url = preg_replace('/&(?!amp;)/', '&', $url); 2103 2157 $url = preg_replace('/\ /', '+', $url); 2104 $url = preg_replace_callback('/^((?:.+?)\?)(.+)$/', $this->_cb('$m[1] . $me->encode_url($m[2])'), $url); 2158 $me =& $this; 2159 $url = preg_replace_callback('/^((?:.+?)\?)(.+)$/', 2160 function($m) use ($me) { 2161 return $m[1] . $me->encode_url($m[2]); 2162 }, $url); 2105 2163 return $url; 2106 2164 } // function format_url … … 2629 2687 */ 2630 2688 function apply_filters($args) { 2689 log_error("Filters are not supported in infoarena's fork of Textile.php " . 2690 "because they use old-style anonymous functions."); 2631 2691 $text = $args['text']; 2632 2692 if (!$text) { return ''; } … … 2639 2699 if (!isset($filters[$filter])) { continue; } 2640 2700 if (is_string($filters[$filter])) { 2641 $text = (($f = create_function _cached('$text, $param', $filters[$filter])) ? $f($text, $param) : $text);2701 $text = (($f = create_function('$text, $param', $filters[$filter])) ? $f($text, $param) : $text); 2642 2702 } 2643 2703 } … … 2769 2829 */ 2770 2830 function encode_url($str) { 2831 $me =& $this; 2771 2832 $str = preg_replace_callback('!([^A-Za-z0-9_\.\-\+\&=%;])!x', 2772 $this->_cb('ord($m[1]) > 255 ? \'%u\' . sprintf("%04X", ord($m[1])) 2773 : \'%\' . sprintf("%02X", ord($m[1]))'), $str); 2833 function($m) use ($me) { 2834 return ord($m[1]) > 255 ? '%u' . sprintf("%04X", ord($m[1])) : '%' . sprintf("%02X", ord($m[1])); 2835 }, $str); 2774 2836 return $str; 2775 2837 } // function encode_url … … 2786 2848 function mail_encode($addr) { 2787 2849 // granted, this is simple, but it gives off warm fuzzies 2850 $me =& $this; 2788 2851 $addr = preg_replace_callback('!([^\$])!x', 2789 $this->_cb('ord($m[1]) > 255 ? \'%u\' . sprintf("%04X", ord($m[1])) 2790 : \'%\' . sprintf("%02X", ord($m[1]))'), $addr); 2852 function($m) use ($me) { 2853 return ord($m[1]) > 255 ? '%u' . sprintf("%04X", ord($m[1])) : '%' . sprintf("%02X", ord($m[1])); 2854 }, $addr); 2791 2855 return $addr; 2792 2856 } // function mail_encode … … 3241 3305 return array("text" => "2.0.8", "build" => 2005032100); 3242 3306 } // function version 3243 3244 /**3245 * Creates a custom callback function from the provided PHP3246 * code. The result is used as the callback in3247 * @c preg_replace_callback calls. *JHR*3248 *3249 * @param $function A @c string specifying the PHP code for the3250 * function body.3251 *3252 * @return A @c function to be used for the callback.3253 *3254 * @private3255 */3256 function _cb($function) {3257 $current =& Textile::_current_store($this);3258 return create_function_cached('$m',3259 '$me =& Textile::_current(); return '.$function .';');3260 } // function _cb3261 3262 /**3263 * Stores a static variable for the Textile class. This helper3264 * function is used by @c _current to simulate a static3265 * class variable in PHP. *JHR*3266 *3267 * @param $new If a non-@c NULL object reference, the Textile object3268 * to be set as the current object.3269 *3270 * @return The @c array containing a reference to the current3271 * Textile object at index 0. An array is used because PHP3272 * does not allow static variables to be references.3273 *3274 * @static3275 * @private3276 */3277 /* static */ function &_current_store(&$new) {3278 static $current = array();3279 3280 if ($new != NULL) {3281 $current = array(&$new);3282 }3283 3284 return $current;3285 } // function _current_store3286 3287 /**3288 * Returns the "current" Textile object. This is used within3289 * anonymous callback functions which cannot have the scope of a3290 * specific object. *JHR*3291 *3292 * @return An @c object reference to the current Textile object.3293 *3294 * @static3295 * @private3296 */3297 /* static */ function &_current() {3298 $current =& Textile::_current_store($null = NULL);3299 return $current[0];3300 } // function _current3301 3307 } // class Textile 3302 3308 … … 3464 3470 * A pre-formatted block of text. Textile will not add any 3465 3471 * HTML tags for individual lines. Whitespace is also preserved. 3466 * 3472 * 3467 3473 * Note that within a "pre" block, \< and \> are 3468 3474 * translated into HTML entities automatically.</li> … … 3474 3480 * gets a \<code\> tag (or for XHTML 2, a \<blockcode\> 3475 3481 * tag is used instead). 3476 * 3482 * 3477 3483 * Note that within a "bc" block, \< and \> are 3478 3484 * translated into HTML entities automatically.</li>
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)