|
From: FlorinCB <ory...@us...> - 2008-06-10 03:35:24
|
Update of /cvsroot/mxbb/core/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv27232/includes Modified Files: mx_functions_phpbb.php Added Files: mx_functions_bbcode.php Log Message: new bbcode in his own include file! Index: mx_functions_phpbb.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions_phpbb.php,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** mx_functions_phpbb.php 27 Mar 2008 14:06:18 -0000 1.59 --- mx_functions_phpbb.php 10 Jun 2008 03:35:19 -0000 1.60 *************** *** 139,630 **** /** - * phpBB Smilies pass. - * - * Hacking smilies_pass from phpbb/includes/bbcode.php - * - * @param string $message - * @return string - */ - - function mx_smilies_pass_old($message) - { - global $mx_page, $board_config, $phpbb_root_path, $phpEx; - - if( !function_exists('generate_smilies') ) - { - mx_page::load_file('functions_post'); - } - - if( !function_exists('smilies_pass') && (PORTAL_BACKEND == 'phpbb2') ) - { - include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx); - } - - $smilies_path = $board_config['smilies_path']; - $board_config['smilies_path'] = PHPBB_URL . $board_config['smilies_path']; - $message = smilies_pass($message); - $board_config['smilies_path'] = $smilies_path; - return $message; - } - - - /** - * phpBB Smilies pass. - * - * Hacking smilies_pass from phpbb/includes/bbcode.php - * - * @param string $message - * @return string - * - */ - function mx_smilies_pass($message) - { - static $orig, $repl; - global $board_config, $mx_root_path, $phpbb_root_path, $phpEx; - - switch (PORTAL_BACKEND) - { - case 'internal': - $smiley_path_url = PHPBB_URL; //change this to PORTAL_URL when shared folder will be removed - $smiley_url = 'smile_url'; - break; - case 'phpbb2': - $smiley_path_url = PHPBB_URL; - $smiley_url = 'smile_url'; - break; - case 'phpbb3': - $smiley_path_url = PHPBB_URL; - $smiley_url = 'smiley_url'; - $board_config['smilies_path'] = str_replace("smiles", "smilies", $board_config['smilies_path']); - break; - } - - $smilies_path = $board_config['smilies_path']; - $board_config['smilies_path'] = $smiley_path_url . $board_config['smilies_path']; - - if (!isset($orig)) - { - global $db; - $orig = $repl = array(); - - $sql = 'SELECT * FROM ' . SMILIES_TABLE; - if( !$result = $db->sql_query($sql) ) - { - mx_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[] = '<img src="'. $board_config['smilies_path'] . '/' . $smilies[$i][$smiley_url] . '" alt="' . $smilies[$i]['emoticon'] . '" border="0" />'; - } - } - - if (count($orig)) - { - $message = preg_replace($orig, $repl, ' ' . $message . ' '); - $message = substr($message, 1, -1); - } - - $board_config['smilies_path'] = $smilies_path; - - return $message; - } - - /** - * Generate phpBB smilies. - * - * Hacking generate_smilies from phpbb/includes/functions_post.php - * - * @param string $mode - * @param integer $page_id - */ - function mx_generate_smilies($mode, $page_id) - { - global $mx_page, $board_config, $template, $mx_root_path, $phpbb_root_path, $phpEx; - - if( !function_exists('generate_smilies') ) - { - mx_page::load_file('functions_post'); - } - - $smilies_path = $board_config['smilies_path']; - $board_config['smilies_path'] = PHPBB_URL . $board_config['smilies_path']; - generate_smilies($mode, $page_id); - $board_config['smilies_path'] = $smilies_path; - $template->assign_vars(array( - 'U_MORE_SMILIES' => mx3_append_sid(PHPBB_URL . "posting.$phpEx", "mode=smilies")) - ); - } - - //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. - * - * Convert the bbcode to html - * - * @param string $bbtext - * @param string $bbcode_uid - * @param boolean $smilies_on - * @return string - */ - function mx_decode($bbtext, $bbcode_uid, $smilies_on = true) - { - 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); - } - - $mytext = stripslashes($bbtext); - if (!empty($bbcode_uid)) - { - $mytext = mx_bbencode_second_pass($mytext, $bbcode_uid); - } - if ($smilies_on) - { - $mytext = mx_smilies_pass($mytext); - } - $mytext = str_replace("\n", "\n<br />\n", $mytext); - return mx_make_clickable($mytext); - } - - /** * General replacement for die(). * --- 139,142 ---- --- NEW FILE: mx_functions_bbcode.php --- <?php /** * * @package Functions_phpBB * @version $Id: mx_functions_bbcode.php,v 1.1 2008/06/10 03:35:19 orynider Exp $ * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * @link http://www.mx-publisher.com * */ if (!defined('IN_PORTAL')) { exit; } /** * phpBB Smilies pass. * * Hacking smilies_pass from phpbb/includes/bbcode.php * * @param string $message * @return string */ function mx_smilies_pass_old($message) { global $mx_page, $board_config, $phpbb_root_path, $phpEx; if( !function_exists('generate_smilies') ) { mx_page::load_file('functions_post'); } if( !function_exists('smilies_pass') && (PORTAL_BACKEND == 'phpbb2') ) { include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx); } $smilies_path = $board_config['smilies_path']; $board_config['smilies_path'] = PHPBB_URL . $board_config['smilies_path']; $message = smilies_pass($message); $board_config['smilies_path'] = $smilies_path; return $message; } /** * phpBB Smilies pass. * * Hacking smilies_pass from phpbb/includes/bbcode.php * * @param string $message * @return string * */ function mx_smilies_pass($message) { static $orig, $repl; global $board_config, $mx_root_path, $phpbb_root_path, $phpEx; switch (PORTAL_BACKEND) { case 'internal': $smiley_path_url = PHPBB_URL; //change this to PORTAL_URL when shared folder will be removed $smiley_url = 'smile_url'; break; case 'phpbb2': $smiley_path_url = PHPBB_URL; $smiley_url = 'smile_url'; break; case 'phpbb3': $smiley_path_url = PHPBB_URL; $smiley_url = 'smiley_url'; $board_config['smilies_path'] = str_replace("smiles", "smilies", $board_config['smilies_path']); break; } $smilies_path = $board_config['smilies_path']; $board_config['smilies_path'] = $smiley_path_url . $board_config['smilies_path']; if (!isset($orig)) { global $db; $orig = $repl = array(); $sql = 'SELECT * FROM ' . SMILIES_TABLE; if( !$result = $db->sql_query($sql) ) { mx_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[] = '<img src="'. $board_config['smilies_path'] . '/' . $smilies[$i][$smiley_url] . '" alt="' . $smilies[$i]['emoticon'] . '" border="0" />'; } } if (count($orig)) { $message = preg_replace($orig, $repl, ' ' . $message . ' '); $message = substr($message, 1, -1); } $board_config['smilies_path'] = $smilies_path; return $message; } /** * Generate phpBB smilies. * * Hacking generate_smilies from phpbb/includes/functions_post.php * * @param string $mode * @param integer $page_id */ function mx_generate_smilies($mode, $page_id) { global $mx_page, $board_config, $template, $mx_root_path, $phpbb_root_path, $phpEx; if( !function_exists('generate_smilies') ) { mx_page::load_file('functions_post'); } $smilies_path = $board_config['smilies_path']; $board_config['smilies_path'] = PHPBB_URL . $board_config['smilies_path']; generate_smilies($mode, $page_id); $board_config['smilies_path'] = $smilies_path; $template->assign_vars(array( 'U_MORE_SMILIES' => mx3_append_sid(PHPBB_URL . "posting.$phpEx", "mode=smilies")) ); } //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. * * Convert the bbcode to html * * @param string $bbtext * @param string $bbcode_uid * @param boolean $smilies_on * @return string */ function mx_decode($bbtext, $bbcode_uid, $smilies_on = true) { 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); } $mytext = stripslashes($bbtext); if (!empty($bbcode_uid)) { $mytext = mx_bbencode_second_pass($mytext, $bbcode_uid); } if ($smilies_on) { $mytext = mx_smilies_pass($mytext); } $mytext = str_replace("\n", "\n<br />\n", $mytext); return mx_make_clickable($mytext); } ?> |