Version 1.3.0

This commit is contained in:
Neo committed 2025-12-19 00:17:06 -08:00
1 parent 7ef3d1712a
commit f87d29ba65
290 files changed
+50206 -17930

No files matched your search

+388 -105
View File
@@ -2,19 +2,22 @@
/*
+--------------------------------------------------------------------------
| Invision Board v1.1
| Invision Power Board v1.3 Final
| ========================================
| by Matthew Mecham
| (c) 2001,2002 Invision Power Services
| http://www.ibforums.com
| (c) 2001 - 2003 Invision Power Services
| http://www.invisionpower.com
| ========================================
| Web: http://www.ibforums.com
| Email: phpboards@ibforums.com
| Licence Info: phpib-licence@ibforums.com
| Web: http://www.invisionboard.com
| Time: Sun, 04 Jan 2004 00:30:16 GMT
| Release: 28e7bfb25f08ac72a789cb1b172fa185
| Email: matt@invisionpower.com
| Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
|
| > Text processor module
| > Module written by Matt Mecham
| > Official Version: 1.2 - Number of changes to date 3 billion (estimated)
|
+--------------------------------------------------------------------------
*/
@@ -32,6 +35,8 @@ class post_parser {
var $emoticons = "";
var $badwords = "";
var $strip_quotes = "";
var $in_sig = "";
var $allow_unicode = 1;
function smilie_length_sort($a, $b)
{
@@ -75,6 +80,10 @@ class post_parser {
);
}
}
else
{
$this->no_bad_words = 1;
}
// Pre-load the smilies
@@ -125,21 +134,23 @@ class post_parser {
function convert($in=array( 'TEXT' => "", 'SMILIES' => 0, 'CODE' => 0, 'SIGNATURE' => 0, 'HTML' => 0)) {
global $ibforums, $DB;
$this->in_sig = $in['SIGNATURE'];
$txt = $in['TEXT'];
//--------------------------------------
// Returns any errors as $this->error
//--------------------------------------
// Remove session id's from any post
$txt = preg_replace( "#[?&;]s=([0-9a-zA-Z]){32}#", "", $txt );
$txt = preg_replace( "#(\?|&|;|&)s=([0-9a-zA-Z]){32}(&|;|&|$)?#e", "\$this->regex_bash_session('\\1', '\\3')", $txt );
//--------------------------------------
// convert <br> to \n
//--------------------------------------
$txt = preg_replace( "/<br>|<br\s*\/>/", "\n", $txt );
$txt = preg_replace( "/<br>|<br \/>/", "\n", $txt );
//--------------------------------------
// Are we parsing iB_CODE and do we have either '[' or ']' in the
@@ -148,26 +159,25 @@ class post_parser {
if ( $in['CODE'] == 1 ) {
//--------------------------------------
// Auto parse URLs
//--------------------------------------
$txt = preg_replace( "#(^|\s)((http|https|news|ftp)://\w+\S+)#ie" , "\$this->regex_build_url(array('html' => '\\2', 'show' => '\\2', 'st' => '\\1'))", $txt );
//---------------------------------
// Do [CODE] tag
//---------------------------------
$txt = preg_replace( "#\[code\](.+?)\[/code\]#ies", "\$this->regex_code_tag('\\1')", $txt );
//--------------------------------------
// Auto parse URLs
//--------------------------------------
$txt = preg_replace( "#(^|\s)((http|https|news|ftp)://\w+[^\s\[\]]+)#ie" , "\$this->regex_build_url(array('html' => '\\2', 'show' => '\\2', 'st' => '\\1'))", $txt );
//---------------------------------
// Do [QUOTE(name,date)] tags
//---------------------------------
// Find the first, and last quote tag (greedy match)...
$txt = preg_replace( "#(\[quote.*\].*\[/quote\])#ies" , "\$this->regex_parse_quotes('\\1')" , $txt );
$txt = preg_replace( "#(\[quote(.+?)?\].*\[/quote\])#ies" , "\$this->regex_parse_quotes('\\1')" , $txt );
/***********************************************/
// If we are not parsing a siggie, lets have a bash
@@ -179,12 +189,19 @@ class post_parser {
$txt = preg_replace( "#\[sql\](.+?)\[/sql\]#ies" , "\$this->regex_sql_tag('\\1')" , $txt );
$txt = preg_replace( "#\[html\](.+?)\[/html\]#ies" , "\$this->regex_html_tag('\\1')" , $txt );
//-------------------------
// [LIST] [*] [/LIST]
//-------------------------
$txt = preg_replace( "#\[list\]#i" , "<ul>" , $txt );
$txt = preg_replace( "#\[\*\]#" , "<li>" , $txt );
$txt = preg_replace( "#\[/list\]#i" , "</ul>", $txt );
while( preg_match( "#\n?\[list\](.+?)\[/list\]\n?#ies" , $txt ) )
{
$txt = preg_replace( "#\n?\[list\](.+?)\[/list\]\n?#ies", "\$this->regex_list('\\1')" , $txt );
}
while( preg_match( "#\n?\[list=(a|A|i|I|1)\](.+?)\[/list\]\n?#ies" , $txt ) )
{
$txt = preg_replace( "#\n?\[list=(a|A|i|I|1)\](.+?)\[/list\]\n?#ies", "\$this->regex_list('\\2','\\1')" , $txt );
}
}
//---------------------------------
@@ -211,6 +228,21 @@ class post_parser {
$txt = preg_replace( "#\(tm\)#i" , "&#153;" , $txt );
$txt = preg_replace( "#\(r\)#i" , "&reg;" , $txt );
// email tags
// [email]matt@index.com[/email] [email=matt@index.com]Email me[/email]
$txt = preg_replace( "#\[email\](\S+?)\[/email\]#i" , "<a href='mailto:\\1'>\\1</a>", $txt );
$txt = preg_replace( "#\[email\s*=\s*\&quot\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\&quot\;\s*\](.*?)\[\/email\]#i" , "<a href='mailto:\\1'>\\2</a>", $txt );
$txt = preg_replace( "#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i" , "<a href='mailto:\\1'>\\2</a>", $txt );
// url tags
// [url]http://www.index.com[/url] [url=http://www.index.com]ibforums![/url]
$txt = preg_replace( "#\[url\](\S+?)\[/url\]#ie" , "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\1'))", $txt );
$txt = preg_replace( "#\[url\s*=\s*\&quot\;\s*(\S+?)\s*\&quot\;\s*\](.*?)\[\/url\]#ie" , "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
$txt = preg_replace( "#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#ie" , "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
// font size, colour and font style
// [font=courier]Text here[/font] [size=6]Text here[/size] [color=red]Text here[/color]
@@ -229,19 +261,6 @@ class post_parser {
$txt = preg_replace( "#\[color=([^\]]+)\](.+?)\[/color\]#ies" , "\$this->regex_font_attr(array('s'=>'col' ,'1'=>'\\1','2'=>'\\2'))", $txt );
}
// email tags
// [email]matt@index.com[/email] [email=matt@index.com]Email me[/email]
$txt = preg_replace( "#\[email\](\S+?)\[/email\]#i" , "<a href='mailto:\\1'>\\1</a>", $txt );
$txt = preg_replace( "#\[email\s*=\s*\&quot\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\&quot\;\s*\](.*?)\[\/email\]#i" , "<a href='mailto:\\1'>\\2</a>", $txt );
$txt = preg_replace( "#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i" , "<a href='mailto:\\1'>\\2</a>", $txt );
// url tags
// [url]http://www.index.com[/url] [url=http://www.index.com]ibforums![/url]
$txt = preg_replace( "#\[url\](\S+?)\[/url\]#ie" , "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\1'))", $txt );
$txt = preg_replace( "#\[url\s*=\s*\&quot\;\s*(\S+?)\s*\&quot\;\s*\](.*?)\[\/url\]#ie" , "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
$txt = preg_replace( "#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#ie" , "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
}
@@ -249,6 +268,13 @@ class post_parser {
$txt = preg_replace( "/\n/", "<br>", $txt );
// Unicode?
if ( $this->allow_unicode )
{
$txt = preg_replace("/&amp;#([0-9]+);/s", "&#\\1;", $txt );
}
//+---------------------------------------------------------------------------------------------------
// Parse smilies (disallow smilies in siggies, or we'll have to query the DB for each post
// and each signature when viewing a topic, not something that we really want to do.
@@ -256,6 +282,8 @@ class post_parser {
if ($in['SMILIES'] != 0 and $in['SIGNATURE'] == 0) {
$txt = ' '.$txt.' ';
if ( ! is_array($this->emoticons) )
{
$DB->query("SELECT typed, image from ibf_emoticons");
@@ -285,19 +313,11 @@ class post_parser {
$code = $row['typed'];
$image = $row['image'];
/*$code = str_replace( "&", "&amp;", $code );
$code = str_replace( "<", "&lt;" , $code );
$code = str_replace( ">", "&gt;" , $code );
$code = str_replace( "\"", "&quot;", $code);
$code = str_replace( "'", "&#039;" , $code);
$code = str_replace( "!", "&#033;" , $code);
$code = str_replace( "|", "&#124;" , $code);*/
// Make safe for regex
$code = preg_quote($code, "/");
$txt = preg_replace( "!(?<=[^\w&])$code(?=.\W|\W.|\W$)!ei", "\$this->convert_emoticon('$code', '$image')", ' '.$txt.' ' );
$txt = preg_replace( "!(?<=[^\w&;/])$code(?=.\W|\W.|\W$)!ei", "\$this->convert_emoticon('$code', '$image')", $txt );
}
@@ -308,6 +328,10 @@ class post_parser {
if ($this->emoticon_count > $ibforums->vars['max_emos'])
{
$this->error = 'too_many_emoticons';
// Uncovert the little yellow chappies
//$txt = preg_replace( "#<!--emo&(.+?)-->.+?<!--endemo-->#", "\\1" , $txt );
}
}
@@ -315,22 +339,120 @@ class post_parser {
$txt = $this->bad_words($txt);
if ($in['HTML'] == 1)
{
$txt = str_replace( "&lt;" ,"<" , $txt );
$txt = str_replace( "&gt;" ,">" , $txt );
$txt = str_replace( "&quot;" ,"\"", $txt);
$txt = str_replace( "&#039;" ,"'" , $txt);
$txt = str_replace( "&amp;" ,"&" , $txt );
}
return $txt; //trim($txt);
return $txt;
}
/**************************************************/
//--------------------------------------------------------------
// Post DB parse tags
// ...................
//--------------------------------------------------------------
function post_db_parse($t="", $use_html=0)
{
global $ibforums, $DB;
if ( $use_html )
{
$t = preg_replace( "#\[dohtml\](.+?)\[/dohtml\]#ies", "\$this->parse_html('\\1')", $t );
}
else
{
$t = preg_replace( "#(\[dohtml\])(.+?)(\[/dohtml\])#ies", "\$this->my_strip_tags('\\2')", $t );
}
return $t;
}
//---------------------------------------------------------------
// My strip-tags. Converts HTML entities back before strippin' em
//---------------------------------------------------------------
function my_strip_tags($t="")
{
$t = str_replace( '&gt;', '>', $t );
$t = str_replace( '&lt;', '<', $t );
$t = strip_tags($t);
// Make sure nothing naughty is left...
$t = str_replace( '<', '&lt;', $t );
$t = str_replace( '>', '&gt;', $t );
return $t;
}
//--------------------------------------------------------------
// Word wrap, wraps 'da word innit
//--------------------------------------------------------------
function my_wordwrap($t="", $chrs=0, $replace="<br />")
{
if ( $t == "" )
{
return $t;
}
if ( $chrs < 1 )
{
return $t;
}
$t = preg_replace("#([^\s<>'\"/\.\\-\?&\n\r\%]{".$chrs."})#i", " \\1".$replace ,$t);
return $t;
}
//--------------------------------------------------------------
// parse_html
// Converts the doHTML tag
//--------------------------------------------------------------
function parse_html($t="", $do_br=1)
{
if ( $t == "" )
{
return $t;
}
// Remove <br>s 'cos we know they can't
// be user inputted, 'cos they are still
// &lt;br&gt; at this point :)
if ( $do_br == 1 )
{
$t = str_replace( "<br>" , "\n" , $t );
$t = str_replace( "<br />" , "\n" , $t );
}
$t = str_replace( "&#39;" , "'", $t );
$t = str_replace( "&#33;" , "!", $t );
$t = str_replace( "&#036;" , "$", $t );
$t = str_replace( "&#124;" , "|", $t );
$t = str_replace( "&amp;" , "&", $t );
$t = str_replace( "&gt;" , ">", $t );
$t = str_replace( "&lt;" , "<", $t );
$t = str_replace( "&quot;" , '"', $t );
// Take a crack at parsing some of the nasties
// NOTE: THIS IS NOT DESIGNED AS A FOOLPROOF METHOD
// AND SHOULD NOT BE RELIED UPON!
$t = preg_replace( "/alert/i" , "&#097;lert" , $t );
$t = preg_replace( "/onmouseover/i", "&#111;nmouseover", $t );
$t = preg_replace( "/onclick/i" , "&#111;nclick" , $t );
$t = preg_replace( "/onload/i" , "&#111;nload" , $t );
$t = preg_replace( "/onsubmit/i" , "&#111;nsubmit" , $t );
return $t;
}
//--------------------------------------------------------------
// Badwords:
// Swops naughty, naugty words and stuff
/**************************************************/
//--------------------------------------------------------------
function bad_words($text = "")
{
@@ -341,6 +463,11 @@ class post_parser {
return "";
}
if ( $this->no_bad_words == 1 )
{
return $text;
}
//--------------------------------
if ( ! is_array($this->badwords) )
@@ -409,46 +536,59 @@ class post_parser {
function unconvert($txt="", $code=1, $html=0) {
$txt = preg_replace( "#<!--emo&(.+?)-->.+?<!--endemo-->#", "\\1" , $txt );
if ($code == 1)
{
$txt = preg_replace( "#<!--emo&(.+?)-->.+?<!--endemo-->#", "\\1" , $txt );
$txt = preg_replace( "#<!--sql-->(.+?)<!--sql1-->(.+?)<!--sql2-->(.+?)<!--sql3-->#e" , "\$this->unconvert_sql(\"\\2\")", $txt);
$txt = preg_replace( "#<!--sql-->(.+?)<!--sql1-->(.+?)<!--sql2-->(.+?)<!--sql3-->#eis" , "\$this->unconvert_sql(\"\\2\")", $txt);
$txt = preg_replace( "#<!--html-->(.+?)<!--html1-->(.+?)<!--html2-->(.+?)<!--html3-->#e", "\$this->unconvert_htm(\"\\2\")", $txt);
$txt = preg_replace( "#<!--Flash (.+?)-->.+?<!--End Flash-->#e" , "\$this->unconvert_flash('\\1')", $txt );
$txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#" , "\[IMG\]\\1\[/IMG\]" , $txt );
$txt = preg_replace( "#<a href=[\"'](http://|https://|ftp://|news://)?(\S+?)['\"].+?".">(.+?)</a>#" , "\[URL=\\1\\2\]\\3\[/URL\]" , $txt );
$txt = preg_replace( "#<a href=[\"']mailto:(.+?)['\"]>(.+?)</a>#" , "\[EMAIL=\\1\]\\2\[/EMAIL\]" , $txt );
$txt = preg_replace( "#<a href=[\"'](http://|https://|ftp://|news://)?(\S+?)['\"].+?".">(.+?)</a>#" , "\[URL=\\1\\2\]\\3\[/URL\]" , $txt );
$txt = preg_replace( "#<i>(.+?)</i>#" , "\[i\]\\1\[/i\]" , $txt );
$txt = preg_replace( "#<b>(.+?)</b>#" , "\[b\]\\1\[/b\]" , $txt );
$txt = preg_replace( "#<s>(.+?)</s>#" , "\[s\]\\1\[/s\]" , $txt );
$txt = preg_replace( "#<u>(.+?)</u>#" , "\[u\]\\1\[/u\]" , $txt );
$txt = preg_replace( "#<!--QuoteBegin-->(.+?)<!--QuoteEBegin-->#" , '[QUOTE]' , $txt );
$txt = preg_replace( "#<!--QuoteBegin-{1,2}([^>]+?)\+([^>]+?)-->(.+?)<!--QuoteEBegin-->#" , "[QUOTE=\\1,\\2]" , $txt );
$txt = preg_replace( "#<!--QuoteBegin-{1,2}([^>]+?)\+-->(.+?)<!--QuoteEBegin-->#" , "[QUOTE=\\1]" , $txt );
$txt = preg_replace( "#<ul>#" , "\[LIST\]" , $txt );
$txt = preg_replace( "#<li>#" , "\[*\]" , $txt );
$txt = preg_replace( "#</ul>#", "\[/LIST\]" , $txt );
$txt = preg_replace( "#<!--me&(.+?)-->(.+?)<!--e--me-->#e" , "\$this->unconvert_me('\\1', '\\2')", $txt );
$txt = preg_replace( "#<span style=['\"]font-size:(.+?)pt;line-height:100%['\"]>(.+?)</span>#e" , "\$this->unconvert_size('\\1', '\\2')", $txt );
$txt = preg_replace( "#<span style=['\"]color:(.+?)['\"]>(.+?)</span>#" , "\[color=\\1\]\\2\[/color\]", $txt );
$txt = preg_replace( "#<span style=['\"]font-family:(.+?)['\"]>(.+?)</span>#" , "\[font=\\1\]\\2\[/font\]" , $txt );
$txt = preg_replace( "#<!--QuoteEnd-->(.+?)<!--QuoteEEnd-->#" , '[/QUOTE]' , $txt );
$txt = preg_replace( "#<!--c1-->(.+?)<!--ec1-->#", '[CODE]' , $txt );
$txt = preg_replace( "#<!--c2-->(.+?)<!--ec2-->#", '[/CODE]' , $txt );
$txt = preg_replace( "#<!--QuoteBegin-->(.+?)<!--QuoteEBegin-->#" , '[QUOTE]' , $txt );
$txt = preg_replace( "#<!--QuoteBegin--(.+?)\+(.+?)-->(.+?)<!--QuoteEBegin-->#" , "[QUOTE=\\1,\\2]" , $txt );
$txt = preg_replace( "#<!--QuoteEnd-->(.+?)<!--QuoteEEnd-->#" , '[/QUOTE]' , $txt );
$txt = preg_replace( "#<i>(.+?)</i>#is" , "\[i\]\\1\[/i\]" , $txt );
$txt = preg_replace( "#<b>(.+?)</b>#is" , "\[b\]\\1\[/b\]" , $txt );
$txt = preg_replace( "#<s>(.+?)</s>#is" , "\[s\]\\1\[/s\]" , $txt );
$txt = preg_replace( "#<u>(.+?)</u>#is" , "\[u\]\\1\[/u\]" , $txt );
$txt = preg_replace( "#(\n){0,}<ul>#" , "\\1\[LIST\]" , $txt );
$txt = preg_replace( "#(\n){0,}<ol type='(a|A|i|I|1)'>#" , "\\1\[LIST=\\2\]\n" , $txt );
$txt = preg_replace( "#(\n){0,}<li>#" , "\n\[*\]" , $txt );
$txt = preg_replace( "#(\n){0,}</ul>(\n){0,}#", "\n\[/LIST\]\\2" , $txt );
$txt = preg_replace( "#(\n){0,}</ol>(\n){0,}#", "\n\[/LIST\]\\2" , $txt );
$txt = preg_replace( "#<!--me&(.+?)-->(.+?)<!--e--me-->#e" , "\$this->unconvert_me('\\1', '\\2')", $txt );
$txt = preg_replace( "#<span style=['\"]font-size:(.+?)pt;line-height:100%['\"]>(.+?)</span>#se" , "\$this->unconvert_size('\\1', '\\2')", $txt );
while ( preg_match( "#<span style=['\"]color:(.+?)['\"]>(.+?)</span>#is", $txt ) )
{
$txt = preg_replace( "#<span style=['\"]color:(.+?)['\"]>(.+?)</span>#is" , "\[color=\\1\]\\2\[/color\]", $txt );
}
$txt = preg_replace( "#<span style=['\"]font-family:(.+?)['\"]>(.+?)</span>#is", "\[font=\\1\]\\2\[/font\]", $txt );
// Tidy up the end quote stuff
$txt = preg_replace( "#(\[/QUOTE\])\s*?<br>\s*#si", "\\1\n", $txt );
$txt = preg_replace( "#<!--EDIT\|.+?\|.+?-->#" , "" , $txt );
$txt = str_replace( "</li>", "", $txt );
$txt = str_replace( "&#153;", "(tm)", $txt );
}
if ($html == 1)
@@ -496,7 +636,12 @@ class post_parser {
function unconvert_sql($sql="") {
$sql = stripslashes($sql);
$sql = preg_replace( "#<span style='.+?'>(.+?)</span>#", "\\1", $sql );
while ( preg_match( "#<span style='.+?'>(.+?)</span>#is", $sql ) )
{
$sql = preg_replace( "#<span style='.+?'>(.+?)</span>#is", "\\1", $sql );
}
$sql = preg_replace( "#\s*$#" , "", $sql );
return '[SQL]'.$sql.'[/SQL]';
@@ -505,7 +650,12 @@ class post_parser {
function unconvert_htm($html="") {
$html = stripslashes($html);
$html = preg_replace( "#<span style='.+?'>(.+?)</span>#", "\\1", $html );
while ( preg_match( "#<span style='.+?'>(.+?)</span>#is", $html ) )
{
$html = preg_replace( "#<span style='.+?'>(.+?)</span>#is", "\\1", $html );
}
$html = preg_replace( "#\s*$#" , "", $html );
return '[HTML]'.$html.'[/HTML]';
@@ -534,7 +684,7 @@ class post_parser {
$this->emoticon_count++;
return "<!--emo&$code--><img src='{$ibforums->vars['EMOTICONS_URL']}/$image' border='0' valign='absmiddle' alt='$image'><!--endemo-->";
return "<!--emo&".trim($code)."--><img src='{$ibforums->vars['EMOTICONS_URL']}/$image' border='0' style='vertical-align:middle' alt='$image' /><!--endemo-->";
}
/**************************************************/
@@ -546,7 +696,7 @@ class post_parser {
global $ibforums;
if (! isset($in['TYPE']) ) $in['TYPE'] = 'class';
if (! isset($in['CSS']) ) $in['CSS'] = 'postcolor';
if (! isset($in['CSS']) ) $in['CSS'] = $this->in_sig == 1 ? 'signature' : 'postcolor';
if (! isset($in['STYLE']) ) $in['STYLE'] = 'QUOTE';
//-----------------------------
@@ -562,12 +712,49 @@ class post_parser {
'PHP' => array( 'CODE' , 'PHP')
);
return array( 'START' => "</span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>{$possible_use[$in[STYLE]][1]}</b> {$in[EXTRA]}</td></tr><tr><td id='{$possible_use[ $in[STYLE] ][0]}'>",
'END' => "</td></tr></table><span {$in[TYPE]}='{$in[CSS]}'>"
return array( 'START' => "</div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>{$possible_use[$in[STYLE]][1]}</b> {$in[EXTRA]}</td></tr><tr><td id='{$possible_use[ $in[STYLE] ][0]}'>",
'END' => "</td></tr></table><div {$in[TYPE]}='{$in[CSS]}'>"
);
}
/**************************************************/
// regex_list: List generation
//
/**************************************************/
function regex_list( $txt="", $type="" )
{
if ($txt == "")
{
return;
}
//$txt = str_replace( "\n", "", str_replace( "\r\n", "\n", $txt ) );
if ( $type == "" )
{
// Unordered list.
return "<ul>".$this->regex_list_item($txt)."</ul>";
}
else
{
return "<ol type='$type'>".$this->regex_list_item($txt)."</ol>";
}
}
function regex_list_item($txt)
{
$txt = preg_replace( "#\[\*\]#", "</li><li>" , trim($txt) );
$txt = preg_replace( "#^</?li>#" , "", $txt );
return str_replace( "\n</li>", "</li>", $txt."</li>" );
}
/**************************************************/
// regex_html_tag: HTML syntax highlighting
//
@@ -581,7 +768,8 @@ class post_parser {
// 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)\]/i", $html) ) {
if (preg_match( "/\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\]/i", $html) )
{
return $default;
}
@@ -592,13 +780,22 @@ class post_parser {
//$html = nl2br($html);
// Take a stab at removing most of the common
// smilie characters.
$html = preg_replace( "#:#" , "&#58;", $html );
$html = preg_replace( "#\[#" , "&#91;", $html );
$html = preg_replace( "#\]#" , "&#93;", $html );
$html = preg_replace( "#\)#" , "&#41;", $html );
$html = preg_replace( "#\(#" , "&#40;", $html );
$html = preg_replace( "/^<br>/", "", $html );
$html = preg_replace( "/^\s+/" , "", $html );
$html = preg_replace( "#&lt;([^&<>]+)&gt;#" , "&lt;<span style='color:blue'>\\1</span>&gt;" , $html ); //Matches <tag>
$html = preg_replace( "#&lt;([^&<>]+)=#" , "&lt;<span style='color:blue'>\\1</span>=" , $html ); //Matches <tag
$html = preg_replace( "#&lt;/([^&]+)&gt;#" , "&lt;/<span style='color:blue'>\\1</span>&gt;" , $html ); //Matches </tag>
$html = preg_replace( "!=(&quot;|&#39;)(.+?)(&quot;|&#39;)(\s|&gt;)!" , "=\\1<span style='color:orange'>\\2</span>\\3\\4" , $html ); //Matches ='this'
$html = preg_replace( "!=(&quot;|&#39;)(.+?)?(&quot;|&#39;)(\s|&gt;)!" , "=\\1<span style='color:orange'>\\2</span>\\3\\4" , $html ); //Matches ='this'
$html = preg_replace( "!&#60;&#33;--(.+?)--&#62;!" , "&lt;&#33;<span style='color:red'>--\\1--</span>&gt;", $html );
@@ -640,7 +837,7 @@ class post_parser {
$sql = preg_replace( "#(MAX|AVG|SUM|COUNT|MIN)\(#i" , "<span style='color:blue'>\\1</span>(" , $sql );
$sql = preg_replace( "!(&quot;|&#39;|&#039;)(.+?)(&quot;|&#39;|&#039;)!i" , "<span style='color:red'>\\1\\2\\3</span>" , $sql );
$sql = preg_replace( "#\s{1,}(AND|OR)\s{1,}#i" , " <span style='color:blue'>\\1</span> " , $sql );
$sql = preg_replace( "#(WHERE|MODIFY|CHANGE|AS|DISTINCT|IN|ASC|DESC|ORDER BY)\s{1,}#i" , "<span style='color:green'>\\1</span> " , $sql );
$sql = preg_replace( "#(LEFT|JOIN|WHERE|MODIFY|CHANGE|AS|DISTINCT|IN|ASC|DESC|ORDER BY)\s{1,}#i" , "<span style='color:green'>\\1</span> " , $sql );
$sql = preg_replace( "#LIMIT\s*(\d+)\s*,\s*(\d+)#i" , "<span style='color:green'>LIMIT</span> <span style='color:orange'>\\1, \\2</span>" , $sql );
$sql = preg_replace( "#(FROM|INTO)\s{1,}(\S+?)\s{1,}#i" , "<span style='color:green'>\\1</span> <span style='color:orange'>\\2</span> ", $sql );
$sql = preg_replace( "#(SELECT|INSERT|UPDATE|DELETE|ALTER TABLE|DROP)#i" , "<span style='color:blue;font-weight:bold'>\\1</span>" , $sql );
@@ -671,10 +868,10 @@ class post_parser {
// Take a stab at removing most of the common
// smilie characters.
//$txt = str_replace( "&" , "&amp;", $txt );
$txt = preg_replace( "#&lt;#" , "&#60;", $txt );
$txt = preg_replace( "#&gt;#" , "&#62;", $txt );
$txt = preg_replace( "#&quot;#" , "&#34;", $txt );
$txt = preg_replace( "#\s{1};#" , "&#59;", $txt );
$txt = preg_replace( "#:#" , "&#58;", $txt );
$txt = preg_replace( "#\[#" , "&#91;", $txt );
$txt = preg_replace( "#\]#" , "&#93;", $txt );
@@ -682,6 +879,7 @@ class post_parser {
$txt = preg_replace( "#\(#" , "&#40;", $txt );
$txt = preg_replace( "#\r#" , "<br>", $txt );
$txt = preg_replace( "#\n#" , "<br>", $txt );
$txt = preg_replace( "#\s{1};#" , "&#59;", $txt );
// Ensure that spacing is preserved
@@ -713,17 +911,21 @@ class post_parser {
$this->quote_html = $this->wrap_style( array( 'STYLE' => 'QUOTE' ) );
$txt = preg_replace( "#\[quote\]#ie" , "\$this->regex_simple_quote_tag()" , $txt );
$txt = preg_replace( "#\[quote=(.+?),\s*(.+?)\]#ie" , "\$this->regex_quote_tag('\\1', '\\2')" , $txt );
$txt = preg_replace( "#\[/quote\]#ie" , "\$this->regex_close_quote()" , $txt );
$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 = preg_replace( "/\n/", "<br>", $txt );
if ( ($this->quote_open == $this->quote_closed) and ($this->quote_error == 0) ) {
// Preserve spacing
if ( ($this->quote_open == $this->quote_closed) and ($this->quote_error == 0) )
{
$txt = preg_replace( "#(<!--QuoteEBegin-->.+?<!--QuoteEnd-->)#es", "\$this->regex_preserve_spacing('\\1')", trim($txt) );
return $txt;
} else {
}
else
{
return $the_txt;
}
@@ -734,8 +936,9 @@ class post_parser {
// without CSS killing <pre> tags
/**************************************************/
function regex_preserve_spacing($txt="") {
$txt = preg_replace( "#\s{2}#", " &nbsp;", trim($txt) );
function regex_preserve_spacing($txt="")
{
$txt = preg_replace( "#\s{2}#", "&nbsp; ", trim($txt) );
return $txt;
}
@@ -760,14 +963,15 @@ class post_parser {
function regex_close_quote() {
if ($this->quote_open == 0) {
if ($this->quote_open == 0)
{
$this->quote_error++;
return;
}
}
$this->quote_closed++;
$this->quote_closed++;
return "<!--QuoteEnd-->{$this->quote_html['END']}<!--QuoteEEnd-->";
return "<!--QuoteEnd-->{$this->quote_html['END']}<!--QuoteEEnd-->";
}
/**************************************************/
@@ -775,16 +979,44 @@ class post_parser {
// [QUOTE=Matthew,14 February 2002]
/**************************************************/
function regex_quote_tag($name="", $date="") {
function regex_quote_tag($name="", $date="")
{
global $ibforums;
$default = "\[quote=$name,$date\]";
if ( $date != "" )
{
$default = "\[quote=$name,$date\]";
}
else
{
$default = "\[quote=$name\]";
}
if ( strstr( $name, '<!--c1-->' ) or strstr( $date, '<!--c1-->' ) )
{
// Code tag detected...
$this->quote_error++;
return $default;
}
$name = str_replace( "+", "&#043;", $name );
$name = str_replace( "-", "&#045;", $name );
$name = str_replace( '[', "&#091;", $name );
$name = str_replace( ']', "&#093;", $name );
$this->quote_open++;
if ($date == "")
{
$html = $this->wrap_style( array( 'STYLE' => 'QUOTE', 'EXTRA' => "($name)" ) );
}
else
{
$html = $this->wrap_style( array( 'STYLE' => 'QUOTE', 'EXTRA' => "($name &#064; $date)" ) );
}
$html = $this->wrap_style( array( 'STYLE' => 'QUOTE', 'EXTRA' => "($name @ $date)" ) );
$extra = "--$name+$date";
$extra = "-".$name.'+'.$date;
return "<!--QuoteBegin".$extra."-->{$html['START']}<!--QuoteEBegin-->";
@@ -869,10 +1101,19 @@ class post_parser {
if ($ibforums->vars['img_ext'])
{
$extension = preg_replace( "/^.*\.(\S+)$/", "\\1", $url );
$extension = preg_replace( "#^.*\.(\S+)$#", "\\1", $url );
$extension = strtolower($extension);
if ( (! $extension) OR ( preg_match( "#/#", $extension ) ) )
{
$this->error = 'invalid_ext';
return $default;
}
$ibforums->vars['img_ext'] = strtolower($ibforums->vars['img_ext']);
if (!preg_match( "/$extension(\||$)/", $ibforums->vars['img_ext'] ))
if (!preg_match( "/".preg_quote($extension, '/')."(\||$)/", $ibforums->vars['img_ext'] ))
{
$this->error = 'invalid_ext';
return $default;
@@ -888,7 +1129,9 @@ class post_parser {
// If we are still here....
return "<img src='$url' border='0' alt='user posted image'>";
$url = str_replace( " ", "%20", $url );
return "<img src='$url' border='0' alt='user posted image' />";
}
@@ -910,6 +1153,8 @@ class post_parser {
$IN['1'] = $attr[0];
}
$IN['1'] = preg_replace( "/[&\(\)\.\%]/", "", $IN['1'] );
if ($IN['s'] == 'size')
{
$IN['1'] = $IN['1'] + 7;
@@ -979,7 +1224,7 @@ class post_parser {
$url['show'] = preg_replace( "/&amp;/" , "&" , $url['show'] );
$url['show'] = preg_replace( "/javascript:/i", "javascript&#58; ", $url['show'] );
if (strlen($url['show']) < 55) $skip_it = 1;
if ( (strlen($url['show']) -58 ) < 3 ) $skip_it = 1;
// Make sure it's a "proper" url
@@ -998,6 +1243,44 @@ class post_parser {
}
function regex_bash_session($start_tok, $end_tok)
{
// Bug fix :D
// Case 1: index.php?s=0000 :: Return nothing (parses: index.php)
// Case 2: index.php?s=0000&this=1 :: Return ? (parses: index.php?this=1)
// Case 3: index.php?this=1&s=0000 :: Return nothing (parses: index.php?this=1)
// Case 4: index.php?t=1&s=00&y=2 :: Return & (parses: index.php?t=1&y=2)
// Thanks to LavaSoft for spotting this one.
$start_tok = str_replace( '&amp;', '&', $start_tok );
$end_tok = str_replace( '&amp;', '&', $end_tok );
//1:
if ($start_tok == '?' and $end_tok == '')
{
return "";
}
//2:
else if ($start_tok == '?' and $end_tok == '&')
{
return '?';
}
//3:
else if ($start_tok == '&' and $end_tok == '')
{
return "";
}
else if ($start_tok == '&' and $end_tok == '&')
{
return "&";
}
else
{
return $start_tok.$end_tok;
}
}
}