? CUSTOMFLAG ? hide_code_from_other_filters.patch Index: bbcode-filter.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bbcode/bbcode-filter.inc,v retrieving revision 1.62 diff -u -p -r1.62 bbcode-filter.inc --- bbcode-filter.inc 3 Aug 2007 05:38:35 -0000 1.62 +++ bbcode-filter.inc 23 Oct 2007 09:07:12 -0000 @@ -11,6 +11,8 @@ function _bbcode_filter_process(&$body, // Find all [code] tags and check if they contain a newline. If we find a newline, // that [code] should be rendered as a block, otherwise it will still be inline + + $body = preg_replace('#\[code(?::\w+)?\](?:[\r\n])*(.*?)\[/code(?::\w+)?\]#sie', '\'[code]\'. _code_store(NULL, \'get\', \'\\1\') .\'[/code]\'', $body); $mode = variable_get("bbcode_paragraph_breaks_$format", 2); $pre = array(); $i = 0; if (preg_match_all('#\[code(?::\w+)?\](.*?)\[/code(?::\w+)?\]#si', $body, $code_tags, PREG_SET_ORDER)) { @@ -21,10 +23,10 @@ function _bbcode_filter_process(&$body, elseif ($mode) { // Strip preformatted code blocks from text during line break processing, replaced below $body = str_replace($code_tag[0], "***pRe_sTrInG$i***", $body); - $pre[$i++] = '
'. $code_tag[1] .''; + $pre[$i++] = '
'. $code_tag[1] .''; } else - $body = str_replace($code_tag[0], '
'. $code_tag[1] .'', $body); + $body = str_replace($code_tag[0], '
'. $code_tag[1] .'', $body); } } @@ -186,11 +188,13 @@ function _bbcode_filter_process(&$body, '#\[/quote(?::\w+)?\]#si' => '', // PHP code blocks (syntax highlighted) - '#\[php(?::\w+)?\](?:[\r\n])*(.*?)\[/php(?::\w+)?\]#sie' => '_bbcode_php_tag(\'\\1\')', + '#\[php(?::\w+)?\](?:[\r\n])*(.*?)\[/php(?::\w+)?\]#sie' => '_bbcode_php_tag(_code_store(NULL, \'get\', \'\\1\'))', + '#\[html(?::\w+)?\](?:[\r\n])*(.*?)\[/html(?::\w+)?\]#sie' => '_bbcode_html_tag(_code_store(NULL, \'get\', \'\\1\'))', // Links to popular sites '#\[google(?::\w+)?\]([\w\s-]+?)\[/google(?::\w+)?\]#si' => '\\1', '#\[wikipedia(?::\w+)?\]([\w\s-]+?)\[/wikipedia(?::\w+)?\]#si' => '\\1', + '#\[youtube\]([0-9a-zA-Z]+)\[/youtube\]#si' => '', // Table tags '#\[table\](.+?)\[/table\]#si' => '
'. highlight_string( str_replace('
', '', stripslashes($text)), true) .'';
+ $text = "', '', trim($text)) ."\n?>";
+ $text = highlight_string(decode_entities($text), TRUE);
+ // Remove newlines to avoid clashing with the linebreak filter
+ $text = str_replace("\n", '', $text);
+ return ''. $text .''; +} + +function _bbcode_html_tag($text = NULL) { + $text = str_replace('
'. $text .''; } function _bbcode_round_size_val($size) { Index: bbcode.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bbcode/bbcode.module,v retrieving revision 1.46 diff -u -p -r1.46 bbcode.module --- bbcode.module 26 May 2007 06:58:31 -0000 1.46 +++ bbcode.module 23 Oct 2007 09:07:13 -0000 @@ -28,6 +28,16 @@ function bbcode_filter($op, $delta = 0, case 'description': return t('Converts BBCode to HTML.'); + case 'prepare': + // Strip the special PHP start and end tags out of any [php] BBCode + // statements (be nice to the codefilter module) + $preg = array( + '#\[php(?::\w+)?\](?:[\r\n])*(.*?)\[/php(?::\w+)?\]#sie' => '\'[php]\'. _code_store(\'\\1\', "set") .\'[/php]\'', + '#\[code(?::\w+)?\](?:[\r\n])*(.*?)\[/code(?::\w+)?\]#sie' => '\'[code]\'. _code_store(\'\\1\', "set") .\'[/code]\'', + '#\[html(?::\w+)?\](?:[\r\n])*(.*?)\[/html(?::\w+)?\]#sie' => '\'[html]\'. _code_store(\'\\1\', "set") .\'[/html]\'', + ); + return stripslashes(preg_replace(array_keys($preg), array_values($preg), $text)); + case 'process': include_once(drupal_get_path('module', 'bbcode') .'/bbcode-filter.inc'); if (variable_get("bbcode_debug_$format", 0)) { @@ -129,3 +139,23 @@ function bbcode_quicktags_alter($items) return $items; } +function _strip_php($text) { + return trim(str_replace(array(''), array('', ''), $text)); +} + +function _code_store($text = NULL, $op = 'get', $pos = 0) { + static $code_store; + + if(!is_array($code_store)) { + $code_store = array(); + } + + switch($op) { + case 'set': + $code_store[] = _strip_php($text); + return count($code_store) -1; + break; + case 'get': + return stripslashes($code_store[(int) $pos]); + } +}