$Date: 2006-09-22 06:28:54 -0400 (Fri, 22 Sep 2006) $
| > $Revision: 567 $
| > $Author: matt $
+---------------------------------------------------------------------------
|
| > Text processor module
| > Module written by Matt Mecham
| > Official Version: 2.0 - Number of changes to date 3 billion (estimated)
| > DBA Checked: Mon 24th May 2004
|
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_IPB' ) )
{
print "
$html = preg_replace( "#<([^&<>]+)=#" , "<\\1=" , $html ); //Matches \\1>" , $html ); //Matches
$html = preg_replace( "!=("|')(.+?)?("|')(\s|>)!" , "=\\1\\2\\3\\4" , $html ); //Matches ='this'
$html = preg_replace( "!<!--(.+?)-->!" , "<!--\\1-->", $html );
$wrap = $this->wrap_style( 'html' );
return "{$wrap['START']}$html{$wrap['END']}";
}
/*-------------------------------------------------------------------------*/
// regex_sql_tag: SQL syntax highlighting
//
/*-------------------------------------------------------------------------*/
function regex_sql_tag($sql="") {
if ($sql == "") return;
//-----------------------------------------
// Too many embedded code/quote/html/sql tags can crash Opera and Moz
//-----------------------------------------
if (preg_match( "/\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\]/i", $sql) ) {
return $default;
}
//-----------------------------------------
// Knock off any preceeding newlines (which have
// since been converted into
)
//-----------------------------------------
$sql = preg_replace( "/^
/" , "", $sql );
$sql = preg_replace( "#^
#", "", $sql );
$sql = preg_replace( "/^\s+/" , "", $sql );
//-----------------------------------------
// Make certain regex work..
//-----------------------------------------
if (! preg_match( "/\s+$/" , $sql) )
{
$sql = $sql.' ';
}
$sql = preg_replace( "#(=|\+|\-|>|<|~|==|\!=|LIKE|NOT LIKE|REGEXP)#i" , "\\1", $sql );
$sql = preg_replace( "#(MAX|AVG|SUM|COUNT|MIN)\(#i" , "\\1(" , $sql );
$sql = preg_replace( "!("|'|')(.+?)("|'|')!i" , "\\1\\2\\3" , $sql );
$sql = preg_replace( "#\s{1,}(AND|OR)\s{1,}#i" , " \\1 " , $sql );
$sql = preg_replace( "#(LEFT|JOIN|WHERE|MODIFY|CHANGE|AS|DISTINCT|IN|ASC|DESC|ORDER BY)\s{1,}#i" , "\\1 " , $sql );
$sql = preg_replace( "#LIMIT\s*(\d+)\s*,\s*(\d+)#i" , "LIMIT \\1, \\2" , $sql );
$sql = preg_replace( "#(FROM|INTO)\s{1,}(\S+?)\s{1,}#i" , "\\1 \\2 ", $sql );
$sql = preg_replace( "#(SELECT|INSERT|UPDATE|DELETE|ALTER TABLE|DROP)#i" , "\\1" , $sql );
$html = $this->wrap_style( 'sql' );
return "{$html['START']}{$sql}{$html['END']}";
}
/*-------------------------------------------------------------------------*/
// regex_code_tag: Builds this code tag HTML
//
/*-------------------------------------------------------------------------*/
function regex_code_tag($txt="")
{
global $ibforums;
$default = "\[code\]$txt\[/code\]";
if ($txt == "") return;
//-----------------------------------------
// Too many embedded code/quote/html/sql tags can crash Opera and Moz
//-----------------------------------------
if (preg_match( "/\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\]/i", $txt) ) {
return $default;
}
//-----------------------------------------
// Take a stab at removing most of the common
// smilie characters.
//-----------------------------------------
//$txt = str_replace( "&" , "&", $txt );
$txt = preg_replace( "#<#" , "<", $txt );
$txt = preg_replace( "#>#" , ">", $txt );
$txt = preg_replace( "#"#" , """, $txt );
$txt = preg_replace( "#:#" , ":", $txt );
$txt = preg_replace( "#\[#" , "[", $txt );
$txt = preg_replace( "#\]#" , "]", $txt );
$txt = preg_replace( "#\)#" , ")", $txt );
$txt = preg_replace( "#\(#" , "(", $txt );
$txt = preg_replace( "#\r#" , "
", $txt );
$txt = preg_replace( "#\n#" , "
", $txt );
$txt = preg_replace( "#\s{1};#" , ";", $txt );
//-----------------------------------------
// Ensure that spacing is preserved
//-----------------------------------------
$txt = preg_replace( "#\s{2}#", " ", $txt );
$html = $this->wrap_style( 'code' );
return "{$html['START']}$txt{$html['END']}";
}
/*-------------------------------------------------------------------------*/
// regex_parse_quotes: Builds this quote tag HTML
// [QUOTE] .. [/QUOTE] - allows for embedded quotes
/*-------------------------------------------------------------------------*/
function regex_parse_quotes($the_txt="") {
if ($the_txt == "") return;
$txt = $the_txt;
if ( substr_count( strtolower($txt), '[quote' ) > $this->max_embed_quotes )
{
return $txt;
}
$txt = str_replace( chr(173).']', ']', $txt );
$this->quote_html = $this->wrap_style('quote');
$txt = preg_replace( "#\[quote\]#ie" , "\$this->regex_simple_quote_tag()" , $txt );
$txt = preg_replace( "#\[quote=([^\],]+?),([^\]]+?)\]#ie" , "\$this->regex_quote_tag('\\1', '\\2')" , $txt );
$txt = preg_replace( "#\[quote=([^\]]+?)\]#ie" , "\$this->regex_quote_tag('\\1', '')" , $txt );
$txt = preg_replace( "#\[/quote\]#ie" , "\$this->regex_close_quote()" , $txt );
$txt = str_replace( "\n", "
", $txt );
if ( ($this->quote_open == $this->quote_closed) and ($this->quote_error == 0) )
{
$txt = preg_replace( "#(.+?)#es", "\$this->regex_preserve_spacing('\\1')", trim($txt) );
return $txt;
}
else
{
return $the_txt;
}
}
/*-------------------------------------------------------------------------*/
// regex_preserve_spacing: keeps double spaces
// without CSS killing tags
/*-------------------------------------------------------------------------*/
function regex_preserve_spacing($txt="")
{
$txt = preg_replace( "#^(?:
|
)#", "", trim($txt) );
$txt = preg_replace( "#\s{2}#", " ", $txt );
return $txt;
}
/*-------------------------------------------------------------------------*/
// regex_simple_quote_tag: Builds this quote tag HTML
// [QUOTE] .. [/QUOTE]
/*-------------------------------------------------------------------------*/
function regex_simple_quote_tag()
{
global $ibforums;
$this->quote_open++;
return "{$this->quote_html['START']}";
}
/*-------------------------------------------------------------------------*/
// regex_close_quote: closes a quote tag
//
/*-------------------------------------------------------------------------*/
function regex_close_quote() {
if ($this->quote_open == 0)
{
$this->quote_error++;
return;
}
$this->quote_closed++;
return "{$this->quote_html['END']}";
}
/*-------------------------------------------------------------------------*/
// regex_quote_tag: Builds this quote tag HTML
// [QUOTE=Matthew,14 February 2002]
/*-------------------------------------------------------------------------*/
function regex_quote_tag($name="", $date="")
{
global $ibforums;
if ( $date != "" )
{
$default = "\[quote=$name,$date\]";
}
else
{
$default = "\[quote=$name\]";
}
if ( strstr( $name, '' ) or strstr( $date, '' ) )
{
//-----------------------------------------
// Code tag detected...
//-----------------------------------------
$this->quote_error++;
return $default;
}
$name = str_replace( "+", "+", $name );
$name = str_replace( "-", "-", $name );
$name = str_replace( '[', "[", $name );
$name = str_replace( ']', "]", $name );
$this->quote_open++;
if ($date == "")
{
$html = $this->wrap_style( 'quote', "($name)");
}
else
{
$html = $this->wrap_style( 'quote', "($name @ $date)" );
}
$extra = "-".$name.'+'.$date;
return "{$html['START']}";
}
/*-------------------------------------------------------------------------*/
// regex_check_flash: Checks, and builds the