) { global $lang; $code_start_html = $bbcode_tpl['code_open']; $code_end_html = $bbcode_tpl['code_close']; // First, do all the 1st-level matches. These need an htmlspecialchars() run, // so they have to be handled differently. $match_count = preg_match_all("#\[code:1:$uid\](.*?)\[/code:1:$uid\]#si", $text, $matches); for ($i = 0; $i < $match_count; $i++) { $before_replace = $matches[1][$i]; $after_replace = $matches[1][$i]; // Replace 2 spaces with " " so non-tabbed code indents without making huge long lines. $after_replace = str_replace(" ", " ", $after_replace); // now Replace 2 spaces with " " to catch odd #s of spaces. $after_replace = str_replace(" ", " ", $after_replace); // Replace tabs with " " so tabbed code indents sorta right without making huge long lines. $after_replace = str_replace("\t", " ", $after_replace); // now Replace space occurring at the beginning of a line $after_replace = preg_replace("/^ {1}/m", ' ', $after_replace); $str_to_match = "[code:1:$uid]" . $before_replace . "[/code:1:$uid]"; $replacement = $code_start_html; $replacement .= $after_replace; $replacement .= $code_end_html; $text = str_replace($str_to_match, $replacement, $text); } // Now, do all the non-first-level matches. These are simple. $text = str_replace("[code:$uid]", $code_start_html, $text); $text = str_replace("[/code:$uid]", $code_end_html, $text); return $text; } // bbencode_second_pass_code() // Returns a file size formatted in a more human-friendly format, rounded // to the nearest Gb, Mb, Kb, or byte. function ed2k_humanize_size ($size, $rounder = 0, $min = '') { $sizes = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $rounders = array(0, 0, 0, 2, 2, 3, 3, 3, 3); $ext = $sizes[0]; $rnd = $rounders[0]; if ($min == 'KB' && $size < 1024) { $size = $size / 1024; $ext = 'KB'; $rounder = 1; } else { for ($i=1, $cnt=count($sizes); ($i < $cnt && $size >= 1024); $i++) { $size = $size / 1024; $ext = $sizes[$i]; $rnd = $rounders[$i]; } } if (!$rounder) { $rounder = $rnd; } return round($size, $rounder) . ' ' . $ext; } function ed2k_link_callback ($m) { /*********************************************************** * SPUD: DIE SPACES! Max length to 200 * ***********************************************************/ $m = str_replace("%20",".", $m); $m = str_replace("_",".", $m); $max_len = 200; // ******* RESUME NORMAL ********* $href = 'href="' . $m[2] . '" class="postlink"'; $size = ed2k_humanize_size($m[4]); $fname = urldecode($m[3]); if (strlen($fname) > $max_len) { $fname = substr($fname, 0, $max_len - 19) . '...' . substr($fname, -16); } if (preg_match('#[<>"]#', $fname)) { $fname = htmlspecialchars($fname); } // [Stats] return "$fname ($size)"; } function make_clickable($text) { $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); // pad it with a space so we can match things at the start of the 1st line. $ret = ' ' . $text; /*********************************************************** * SPUD: Anonymous URLS - Just incase its HTML already
* ***********************************************************/ $ret = str_replace("http://www.bothanspies.com/publicscripts/index.php?http://","http://", $ret); $ret = str_replace("\*\?\"]+?)\|(\d+?)\|([a-f0-9]{32})\|(.*?)/?)(?![\"'])(?=([,\.]*?[\s<\[])|[,\.]*?$)#i", "ed2k_link_callback", $ret); // ed2k server links: // ed2k://|server|serverIP|serverPort $ret = preg_replace("#(^|(?<=[^\w\"']))(ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)#i", "\\3:\\4", $ret); // matches an "xxxx://yyyy" URL at the start of a line, or after a space. // xxxx can only be alpha characters. // yyyy is anything up to the first space, newline, comma, double quote or < $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1\\2", $ret); // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing // Must contain at least 2 dots. xxxx contains either alphanum, or "-" // zzzz is optional.. will contain everything up to the first space, newline, // comma, double quote or <. $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1\\2", $ret); // matches an email@domain type address at the start of a line, or after a space. // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1\\2@\\3", $ret); /*********************************************************** * SPUD: Fix local URLS
* ***********************************************************/ $ret = str_replace("http://www.bothanspies.com/publicscripts/index.php?http://dead-donkey","http://dead-donkey", $ret); $ret = str_replace("http://www.bothanspies.com/publicscripts/index.php?http://www.dead-donkey","http://www.dead-donkey", $ret); $ret = str_replace("http://www.bothanspies.com/publicscripts/index.php?http://forum.dead-donkey","http://forum.dead-donkey", $ret); $ret = str_replace("http://www.bothanspies.com/publicscripts/index.php?http://scifi.dead-donkey","http://scifi.dead-donkey", $ret); // ****** RESUME NORMAL ********* // Remove our padding.. $ret = substr($ret, 1); return($ret); } /** * Christian Riesen - Jun 27, 2004 * Adds the "Add all links to ed2k client" link to the end of the post text */ function make_addalled2k_link($text,$post_id) { // padding $ret = ' ' . $text; // dig through the message for all ed2k links! // split up by "ed2k:" $t_ed2k_raw = explode("ed2k:",$text); // The first item is garbage unset($t_ed2k_raw[0]); // no need to dig through it if there are not at least 2 links! $t_ed2k_possibles = count($t_ed2k_raw); if ($t_ed2k_possibles > 1) { unset($t_ed2k_reallinks); foreach ($t_ed2k_raw as $t_ed2k_raw_line) { $t_ed2k_parts = explode("|",$t_ed2k_raw_line); // This looks now like this (only important parts included /* [1]=> string(4) "file" [2]=> string(46) "some-filename-here.txt" [3]=> string(9) "321456789" [4]=> string(32) "112233445566778899AABBCCDDEEFF11" */ /*********************************************************** * SPUD: Fix %20 with "." * ***********************************************************/ $t_ed2k_parts[2] = str_replace("%20",".",$t_ed2k_parts[2]); // ****** RESUME NORMAL ********* /*********************************************************** * SPUD: Fix fileheaven clown gayness * ***********************************************************/ $t_ed2k_parts[2] = str_replace("-span style=color--#ff0000--b-","",$t_ed2k_parts[2]); $t_ed2k_parts[2] = str_replace("--b---span-","",$t_ed2k_parts[2]); // ****** RESUME NORMAL ********* // Check the obvious things if (strlen($t_ed2k_parts[1]) == 4 AND $t_ed2k_parts[1] === "file" AND strlen($t_ed2k_parts[2]) > 0 AND strlen($t_ed2k_parts[4]) == 32 AND floatval($t_ed2k_parts[3]) > 0) { // This is a true link, lets paste it together and put it in an array $t_ed2k_reallinks[] = "ed2k://|file|".str_replace("'","\'",$t_ed2k_parts[2])."|".$t_ed2k_parts[3]."|".$t_ed2k_parts[4]."|/"; } } // Now lets see if we have 2 or more links // Only then, we do our little trick, because otherwise, it would be wasted for one link alone! $t_ed2k_confirmed = count($t_ed2k_reallinks); if ($t_ed2k_confirmed > 1) { $t_ed2kinsert = " \n"; $t_ed2kinsert .= " "; $t_ed2kinsert .= "
Add ".$t_ed2k_confirmed." links to ed2k client
"; $ret = $ret . $t_ed2kinsert; } } // remove padding $ret = substr($ret, 1); return($ret); } /** * Nathan Codding - Feb 6, 2001 * Reverses the effects of make_clickable(), for use in editpost. * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. * */ function undo_make_clickable($text) { $text = preg_replace("#.*?#i", "\\1", $text); $text = preg_replace("#.*?#i", "\\1", $text); return $text; } /** * Nathan Codding - August 24, 2000. * Takes a string, and does the reverse of the PHP standard function * htmlspecialchars(). */ function undo_htmlspecialchars($input) { $input = preg_replace("/>/i", ">", $input); $input = preg_replace("/</i", "<", $input); $input = preg_replace("/"/i", "\"", $input); $input = preg_replace("/&/i", "&", $input); return $input; } /** * This is used to change a [*] tag into a [*:$uid] tag as part * of the first-pass bbencoding of [list] tags. It fits the * standard required in order to be passed as a variable * function into bbencode_first_pass_pda(). */ function replace_listitems($text, $uid) { $text = str_replace("[*]", "[*:$uid]", $text); return $text; } /** * Escapes the "/" character with "\/". This is useful when you need * to stick a runtime string into a PREG regexp that is being delimited * with slashes. */ function escape_slashes($input) { $output = str_replace('/', '\/', $input); return $output; } /** * This function does exactly what the PHP4 function array_push() does * however, to keep phpBB compatable with PHP 3 we had to come up with our own * method of doing it. * This function was deprecated in phpBB 2.0.18 */ function bbcode_array_push(&$stack, $value) { $stack[] = $value; return(sizeof($stack)); } /** * This function does exactly what the PHP4 function array_pop() does * however, to keep phpBB compatable with PHP 3 we had to come up with our own * method of doing it. * This function was deprecated in phpBB 2.0.18 */ function bbcode_array_pop(&$stack) { $arrSize = count($stack); $x = 1; while(list($key, $val) = each($stack)) { if($x < count($stack)) { $tmpArr[] = $val; } else { $return_val = $val; } $x++; } $stack = $tmpArr; return($return_val); } // // Smilies code ... would this be better tagged on to the end of bbcode.php? // Probably so and I'll move it before B2 // function smilies_pass($message) { static $orig, $repl; if (!isset($orig)) { global $db, $board_config; $orig = $repl = array(); $sql = 'SELECT * FROM ' . SMILIES_TABLE; if( !$result = $db->sql_query($sql) ) { message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql); } $smilies = $db->sql_fetchrowset($result); if (count($smilies)) { usort($smilies, 'smiley_sort'); } for ($i = 0; $i < count($smilies); $i++) { $orig[] = "/(?<=.\W|\W.|^\W)" . preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/"; $repl[] = '' . $smilies[$i]['emoticon'] . ''; } } if (count($orig)) { $message = preg_replace($orig, $repl, ' ' . $message . ' '); $message = substr($message, 1, -1); } return $message; } function smiley_sort($a, $b) { if ( strlen($a['code']) == strlen($b['code']) ) { return 0; } return ( strlen($a['code']) > strlen($b['code']) ) ? -1 : 1; } ?>
Warning: Cannot modify header information - headers already sent by (output started at /home/www/forum.dead-donkey.com/includes/bbcode.php:1026) in /home/www/forum.dead-donkey.com/includes/page_header.php on line 484
Warning: Cannot modify header information - headers already sent by (output started at /home/www/forum.dead-donkey.com/includes/bbcode.php:1026) in /home/www/forum.dead-donkey.com/includes/page_header.php on line 490
Warning: Cannot modify header information - headers already sent by (output started at /home/www/forum.dead-donkey.com/includes/bbcode.php:1026) in /home/www/forum.dead-donkey.com/includes/page_header.php on line 491