", arg );
else
tmp += "";
break;
case "/color":
tmp += "";
break;
case "code":
tmp += "";
bInCode = true;
break;
case "/code":
tmp += "
";
bInCode = false;
break;
default:
bNone = true;
break;
}
}
else
{
bNone = true;
}
if ( !bNone )
{
i = e1;
continue;
}
}
}
tmp += Message [i];
}
return tmp;
}
///
/// Adds smiles into the code.
///
/// Forum base page
/// Text to add smiles to.
/// Processed text with smiles added.
static public string iAddSmiles( yaf.pages.ForumPage basePage, string Message )
{
DataTable dtSmileys = GetSmilies( basePage );
string strTemp = Message;
foreach ( DataRow row in dtSmileys.Rows )
{
string code = row ["Code"].ToString();
code = code.Replace( "&", "&" );
code = code.Replace( "\"", """ );
strTemp = strTemp.Replace( code.ToLower(), String.Format( "
", basePage.Smiley( Convert.ToString( row ["Icon"] ) ), basePage.Server.HtmlEncode( row ["Emoticon"].ToString() ) ) );
strTemp = strTemp.Replace( code.ToUpper(), String.Format( "
", basePage.Smiley( Convert.ToString( row ["Icon"] ) ), basePage.Server.HtmlEncode( row ["Emoticon"].ToString() ) ) );
}
return strTemp;
}
///
/// Supposed to convert HTML to BBCode -- Doesn't function
///
///
///
[Obsolete( "Doesn't work" )]
static public string HtmlToForumCode( string html )
{
#if true
return html;
#else
html = html.Replace("","[list]"); // TODO
html = html.Replace("
","[/list]"); // TODO
html = html.Replace("","[list]"); // TODO
html = html.Replace("
","[/list]"); // TODO
html = html.Replace("","[*]"); // TODO
html = html.Replace("",""); // TODO
RegexOptions options = RegexOptions.IgnoreCase;
html = Regex.Replace(html,"(.*)","[url=\"$1\"]$2[/url]",options);
html = Regex.Replace(html,"
","[img]$1[/img]",options);
html = Regex.Replace(html,"","",options);
html = Regex.Replace(html,"
","
",options);
html = Regex.Replace(html,"
","\n",options);
html = Regex.Replace(html,"","[b]",options);
html = Regex.Replace(html,"","[/b]",options);
html = Regex.Replace(html,"","[b]",options);
html = Regex.Replace(html,"","[/b]",options);
html = Regex.Replace(html,"","[i]",options);
html = Regex.Replace(html,"","[/i]",options);
html = Regex.Replace(html,"","[i]",options);
html = Regex.Replace(html,"","[/i]",options);
html = Regex.Replace(html,"","[u]",options);
html = Regex.Replace(html,"","[/u]",options);
html = Regex.Replace(html,"","[block]",options);
html = Regex.Replace(html,"
","[/block]",options);
html = Regex.Replace(html,"<","<",options);
html = Regex.Replace(html,">",">",options);
// if(html.IndexOf('<')>=0 || html.IndexOf('>')>=0)
// html += "\n\nINVALID";
return html;
#endif
}
static public DataTable GetSmilies( yaf.pages.ForumPage basePage )
{
DataTable dt = ( DataTable ) System.Web.HttpContext.Current.Cache ["Smilies"];
if ( dt == null )
{
dt = DB.smiley_list( basePage.PageBoardID, null );
System.Web.HttpContext.Current.Cache.Insert( "Smilies", dt, null, DateTime.Now.AddMinutes( 60 ), TimeSpan.Zero );
}
return dt;
}
static public string FormatMessage( yaf.pages.ForumPage basePage, string Message, MessageFlags mFlags)
{
// do html damage control
Message = RepairHtml( basePage, Message, mFlags.IsHTML );
// convert spaces if bbcode (causes too many problems)
/*if (mFlags.IsBBCode)
{
Message = Message.Replace(" "," ");
}*/
// do BBCode and Smilies...
Message = BBCode.MakeHtml( basePage, Message, mFlags.IsBBCode, Mession.HideImages );
RegexOptions options = RegexOptions.IgnoreCase /*| RegexOptions.Singleline | RegexOptions.Multiline*/;
//Email -- RegEx VS.NET
Message = Regex.Replace( Message, @"(?^|[ ]|
)(?\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)", "${before}${email}", options );
//URL (http://) -- RegEx http://www.dotnet247.com/247reference/msgs/2/10022.aspx
Message = Regex.Replace( Message, "(?^|[ ]|
)(?(http://|https://|ftp://)(?:[\\w-]+\\.)+[\\w-]+(?:/[\\w-./?%&=;,]*)?)", "${before}${url}", options );
//URL (www) -- RegEx http://www.dotnet247.com/247reference/msgs/2/10022.aspx
Message = Regex.Replace( Message, @"(?^|[ ]|
)(?www\.(?:[\w-]+\.)+[\w-]+(?:/[\w-./?%&=;,]*)?)", "${before}${url}", options );
// jaben : moved word replace to reusable function in class utils
Message = Utils.BadWordReplace( Message );
return Message;
}
static private bool IsValidTag( string tag, string [] AllowedTags )
{
if ( tag.IndexOf( "javascript" ) >= 0 ) return false;
if ( tag.IndexOf( "vbscript" ) >= 0 ) return false;
if ( tag.IndexOf( "onclick" ) >= 0 ) return false;
char [] endchars = new char [] { ' ', '>', '/', '\t' };
int pos = tag.IndexOfAny( endchars, 1 );
if ( pos > 0 ) tag = tag.Substring( 0, pos );
if ( tag [0] == '/' ) tag = tag.Substring( 1 );
// check if it's a valid tag
foreach ( string aTag in AllowedTags )
{
if ( tag == aTag ) return true;
}
return false;
}
static public string RepairHtml( yaf.pages.ForumPage basePage, string html, bool bAllowHtml )
{
if ( !bAllowHtml )
{
html = BBCode.EncodeHTML( html );
}
else
{
// get allowable html tags
string tStr = basePage.BoardSettings.AcceptedHTML;
string [] AllowedTags = tStr.Split( ',' );
RegexOptions options = RegexOptions.IgnoreCase;
MatchCollection m = Regex.Matches( html, "<.*?>", options );
for ( int i = m.Count - 1; i >= 0; i-- )
{
string tag = html.Substring( m [i].Index + 1, m [i].Length - 1 ).Trim().ToLower();
if ( !IsValidTag( tag, AllowedTags ) )
{
html = html.Remove( m [i].Index, m [i].Length );
// just don't show this tag for now
//string tmp = System.Web.HttpContext.Current.Server.HtmlEncode(html.Substring(m[i].Index,m[i].Length));
//html = html.Insert(m[i].Index,tmp);
}
}
}
return html;
}
}
public class MessageFlags
{
int FBitValue;
public MessageFlags()
: this( 23 )
{
}
public MessageFlags( int bitValue )
{
FBitValue = bitValue;
}
static public bool GetBitAsBool( int bitValue, int bitShift )
{
if ( bitShift > 31 ) bitShift %= 31;
if ( ( ( bitValue >> bitShift ) & 0x00000001 ) == 1 ) return true;
return false;
}
static public int SetBitFromBool( int bitValue, int bitShift, bool bValue )
{
if ( bitShift > 31 ) bitShift %= 31;
if ( GetBitAsBool( bitValue, bitShift ) != bValue )
{
// toggle that value using XOR
int tV = 0x00000001 << bitShift;
bitValue ^= tV;
}
return bitValue;
}
public static implicit operator MessageFlags( int newBitValue )
{
MessageFlags mf = new MessageFlags( newBitValue );
return mf;
}
public int BitValue
{
get { return FBitValue; }
set { FBitValue = value; }
}
public bool this [int index]
{
get { return GetBitAsBool( FBitValue, index ); }
set { FBitValue = SetBitFromBool( FBitValue, index, value ); }
}
// actual flags here -- can be a total of 31
public bool IsHTML
{
get { return GetBitAsBool( FBitValue, 0 ); }
set { FBitValue = SetBitFromBool( FBitValue, 0, value ); }
}
public bool IsBBCode
{
get { return GetBitAsBool( FBitValue, 1 ); }
set { FBitValue = SetBitFromBool( FBitValue, 1, value ); }
}
public bool IsSmilies
{
get { return GetBitAsBool( FBitValue, 2 ); }
set { FBitValue = SetBitFromBool( FBitValue, 2, value ); }
}
public bool IsDeleted
{
get { return GetBitAsBool( FBitValue, 3 ); }
set { FBitValue = SetBitFromBool( FBitValue, 3, value ); }
}
public bool IsApproved
{
get { return GetBitAsBool( FBitValue, 4 ); }
set { FBitValue = SetBitFromBool( FBitValue, 4, value ); }
}
///
/// This post is locked -- nothing can be done to it
///
public bool IsLocked
{
get { return GetBitAsBool( FBitValue, 5 ); }
set { FBitValue = SetBitFromBool( FBitValue, 5, value ); }
}
///
/// Setting so that the message isn't formatted at all
///
public bool NotFormatted
{
get { return GetBitAsBool( FBitValue, 6 ); }
set { FBitValue = SetBitFromBool( FBitValue, 6, value ); }
}
}
}