|
From: OryNider <ory...@us...> - 2008-02-29 00:54:18
|
Update of /cvsroot/mxbb/core/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23747 Modified Files: mx_functions_phpbb.php mx_functions_tools.php Log Message: This will make awaylable phpbb3 backend again. some funtions are added as temporary solution for now till we find someting else for phpbb3 backend. Index: mx_functions_phpbb.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions_phpbb.php,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** mx_functions_phpbb.php 23 Feb 2008 19:36:12 -0000 1.50 --- mx_functions_phpbb.php 29 Feb 2008 00:54:10 -0000 1.51 *************** *** 217,221 **** if (count($smilies)) { ! usort($smilies, 'smiley_sort'); } --- 217,221 ---- if (count($smilies)) { ! @usort($smilies, 'smiley_sort'); } *************** *** 264,267 **** --- 264,579 ---- } + //phpBB Temporary code start + + /** + * Loads bbcode templates from the bbcode.tpl file of the current template set. + * Creates an array, keys are bbcode names like "b_open" or "url", values + * are the associated template. + * Probably pukes all over the place if there's something really screwed + * with the bbcode.tpl file. + * + * Nathan Codding, Sept 26 2001. + * This a temporary function + */ + function mx_load_bbcode_template() + { + global $template; + $tpl_filename = $template->make_filename('bbcode.tpl'); + $tpl = fread(fopen($tpl_filename, 'r'), filesize($tpl_filename)); + + // replace \ with \\ and then ' with \'. + $tpl = str_replace('\\', '\\\\', $tpl); + $tpl = str_replace('\'', '\\\'', $tpl); + + // strip newlines. + $tpl = str_replace("\n", '', $tpl); + + // Turn template blocks into PHP assignment statements for the values of $bbcode_tpls.. + $tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . '$bbcode_tpls[\'\\1\'] = \'\\2\';', $tpl); + + $bbcode_tpls = array(); + + eval($tpl); + + return $bbcode_tpls; + } + + /** + * Prepares the loaded bbcode templates for insertion into preg_replace() + * or str_replace() calls in the bbencode_second_pass functions. This + * means replacing template placeholders with the appropriate preg backrefs + * or with language vars. NOTE: If you change how the regexps work in + * bbencode_second_pass(), you MUST change this function. + * + * Nathan Codding, Sept 26 2001 + * + * This a temporary function + */ + function mx_prepare_bbcode_template($bbcode_tpl) + { + global $lang; + + $bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']); + + $bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']); + + $bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']); + + $bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']); + + $bbcode_tpl['quote_username_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_username_open']); + $bbcode_tpl['quote_username_open'] = str_replace('{L_WROTE}', $lang['wrote'], $bbcode_tpl['quote_username_open']); + $bbcode_tpl['quote_username_open'] = str_replace('{USERNAME}', '\\1', $bbcode_tpl['quote_username_open']); + + $bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']); + + $bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']); + + // We do URLs in several different ways.. + $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); + $bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']); + + $bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); + $bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']); + + $bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); + $bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']); + + $bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); + $bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']); + + $bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']); + + define("BBCODE_TPL_READY", true); + + return $bbcode_tpl; + } + + /** + * Does second-pass bbencoding. This should be used before displaying the message in + * a thread. Assumes the message is already first-pass encoded, and we are given the + * correct UID as used in first-pass encoding. + * This a temporary function + */ + function mx_bbencode_second_pass($text, $uid) + { + global $lang, $bbcode_tpl; + + $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); + + // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). + // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. + $text = " " . $text; + + // First: If there isn't a "[" and a "]" in the message, don't bother. + if (! (strpos($text, "[") && strpos($text, "]")) ) + { + // Remove padding, return. + $text = substr($text, 1); + return $text; + } + + // Only load the templates ONCE.. + if (!defined("BBCODE_TPL_READY")) + { + // load templates from file into array. + $bbcode_tpl = mx_load_bbcode_template(); + + // prepare array for use in regexps. + $bbcode_tpl = mx_prepare_bbcode_template($bbcode_tpl); + } + + // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts. + $text = mx_bbencode_second_pass_code($text, $uid, $bbcode_tpl); + + // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff. + $text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text); + $text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text); + + // New one liner to deal with opening quotes with usernames... + // replaces the two line version that I had here before.. + $text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text); + + // [list] and [list=x] for (un)ordered lists. + // unordered lists + $text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text); + // li tags + $text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text); + // ending tags + $text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text); + $text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text); + // Ordered lists + $text = preg_replace("/\[list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + + // colours + $text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text); + $text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text); + + // size + $text = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text); + $text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text); + + // [b] and [/b] for bolding text. + $text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text); + $text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text); + + // [u] and [/u] for underlining text. + $text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text); + $text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text); + + // [i] and [/i] for italicizing text. + $text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text); + $text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text); + + // Patterns and replacements for URL and email tags.. + $patterns = array(); + $replacements = array(); + + // [img]image_url_here[/img] code.. + // This one gets first-passed.. + $patterns[] = "#\[img:$uid\]([^?](?:[^\[]+|\[(?!url))*?)\[/img:$uid\]#i"; + $replacements[] = $bbcode_tpl['img']; + + // matches a [url]xxxx://www.phpbb.com[/url] code.. + $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url1']; + + // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix). + $patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url2']; + + // [url=xxxx://www.phpbb.com]phpBB[/url] code.. + $patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url3']; + + // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix). + $patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url4']; + + // [email]us...@do...[/email] code.. + $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"; + $replacements[] = $bbcode_tpl['email']; + + $text = preg_replace($patterns, $replacements, $text); + + // Remove our padding from the string.. + $text = substr($text, 1); + + return $text; + + } // bbencode_second_pass() + + /** + * Does second-pass bbencoding of the [code] tags. This includes + * running htmlspecialchars() over the text contained between + * any pair of [code] tags that are at the first level of + * nesting. Tags at the first level of nesting are indicated + * by this format: [code:1:$uid] ... [/code:1:$uid] + * Other tags are in this format: [code:$uid] ... [/code:$uid] + * This a temporary function + */ + function mx_bbencode_second_pass_code($text, $uid, $bbcode_tpl) + { + 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() + + //phpBB Temporary code ends + + /** + * Rewritten by Nathan Codding - Feb 6, 2001. + * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking + * to that URL + * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking + * to http://www.xxxx.yyyy[/zzzz] + * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking + * to that email address + * - Only matches these 2 patterns either after a space, or at the beginning of a line + * + * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe + * have it require something like xx...@yy... or such. We'll see. + * We can add here more phpBB3 stuff in time - Ory + */ + function mx_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; + + // 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<a href=\"\\2\" target=\"_blank\">\\2</a>", $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<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $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<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); + + // Remove our 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 mx_undo_make_clickable($text) + { + $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); + $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); + + return $text; + + } + /** * bbcode to html. *************** *** 278,284 **** global $mx_root_path, $phpbb_root_path, $phpEx, $mx_page; ! if( !function_exists('bbencode_second_pass') ) ! { ! mx_page::load_file('bbcode'); } --- 590,613 ---- global $mx_root_path, $phpbb_root_path, $phpEx, $mx_page; ! if ((PORTAL_BACKEND !== 'phpbb3') && !function_exists('bbencode_second_pass')) ! { ! mx_page::load_file('bbcode'); ! } ! ! if (PORTAL_BACKEND == 'phpbb3') ! { ! /* ! if (!class_exists('bbcode')) ! { ! mx_page::load_file('bbcode'); ! } ! ! if( !is_object($bbcode)) ! { ! $bbcode = new bbcode(); ! } ! */ ! //Temporary solutution ! //require($mx_root_path . 'includes/shared/phpbb2/includes/bbcode.'.$phpEx); } *************** *** 286,290 **** if (!empty($bbcode_uid)) { ! $mytext = bbencode_second_pass($mytext, $bbcode_uid); } if ($smilies_on) --- 615,619 ---- if (!empty($bbcode_uid)) { ! $mytext = mx_bbencode_second_pass($mytext, $bbcode_uid); } if ($smilies_on) *************** *** 293,297 **** } $mytext = str_replace("\n", "\n<br />\n", $mytext); ! return make_clickable($mytext); } --- 622,626 ---- } $mytext = str_replace("\n", "\n<br />\n", $mytext); ! return mx_make_clickable($mytext); } Index: mx_functions_tools.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions_tools.php,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** mx_functions_tools.php 22 Feb 2008 23:02:49 -0000 1.23 --- mx_functions_tools.php 29 Feb 2008 00:54:10 -0000 1.24 *************** *** 18,24 **** // This 'include' is needed for the mx_text class // ! if( !function_exists('bbencode_second_pass') ) ! { ! mx_page::load_file('bbcode'); } --- 18,24 ---- // This 'include' is needed for the mx_text class // ! if ((PORTAL_BACKEND !== 'phpbb3') && !function_exists('bbencode_second_pass')) ! { ! mx_page::load_file('bbcode'); } *************** *** 130,133 **** --- 130,134 ---- function display($text, $bbcode_uid = '') { + global $mx_root_path; // // strip html if reqd *************** *** 141,155 **** } // // BBCode if reqd ! // if ($text != '' && $bbcode_uid != '') { ! $text = ($this->bbcode_on) ? bbencode_second_pass($text, $bbcode_uid) : preg_replace("/\:$bbcode_uid/si", '', $text); } if ( $text != '' ) { ! $text = make_clickable($text); } --- 142,177 ---- } + if ((PORTAL_BACKEND !== 'phpbb3') && !function_exists('bbencode_second_pass')) + { + mx_page::load_file('bbcode'); + } + // // BBCode if reqd ! // ! if (PORTAL_BACKEND == 'phpbb3') ! { ! /* ! if (!class_exists('bbcode')) ! { ! mx_page::load_file('bbcode'); ! } ! ! if( !is_object($bbcode)) ! { ! $bbcode = new bbcode(); ! } ! */ ! //require($mx_root_path . 'includes/shared/phpbb2/includes/bbcode.'.$phpEx); ! } ! if ($text != '' && $bbcode_uid != '') { ! $text = ($this->bbcode_on) ? mx_bbencode_second_pass($text, $bbcode_uid) : preg_replace("/\:$bbcode_uid/si", '', $text); } if ( $text != '' ) { ! $text = mx_make_clickable($text); } |