From a08f4af51364343c2d94848dd7c0c53b59b61da9 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Sat, 3 Jul 2010 11:11:14 +0000 Subject: [PATCH] A bunch of new BBCodes implemented; smileys parsing implemented --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Common/BBCodes/Code.cs | 2 +- Common/BBCodes/FUrl.cs | 6 +--- Common/BBCodes/Font.cs | 19 ++++++++++ Common/BBCodes/FontColor.cs | 19 ++++++++++ Common/BBCodes/FontSize.cs | 19 ++++++++++ Common/BBCodes/List.cs | 19 ++++++++++ Common/BBCodes/ListElem.cs | 20 +++++++++++ Common/BBCodes/Quote.cs | 21 +++++++++++ Common/BBCodes/Spoiler.cs | 21 +++++++++++ Common/BBCodes/UploadImage.cs | 21 +++++++++++ Common/BBCodes/UploadLink.cs | 24 +++++++++++++ Common/BBCodes/Url.cs | 6 +--- Common/BBCodes/User.cs | 20 +++++++++++ Common/BBCodes/helpers/BBCode.cs | 14 ++++++++ Common/Common.csproj | 10 ++++++ Common/UBBParser.cs | 53 +++++++++++++++++++++++++++- static/css/global.css | 8 ++++- static/js/common.js | 8 +++++ templates/Full/elems/Main.xslt | 1 + templates/Full/elems/TextEditor.xslt | 14 ++++---- 22 files changed, 307 insertions(+), 22 deletions(-) create mode 100644 Common/BBCodes/Font.cs create mode 100644 Common/BBCodes/FontColor.cs create mode 100644 Common/BBCodes/FontSize.cs create mode 100644 Common/BBCodes/List.cs create mode 100644 Common/BBCodes/ListElem.cs create mode 100644 Common/BBCodes/Quote.cs create mode 100644 Common/BBCodes/Spoiler.cs create mode 100644 Common/BBCodes/UploadImage.cs create mode 100644 Common/BBCodes/UploadLink.cs create mode 100644 Common/BBCodes/User.cs create mode 100644 static/js/common.js diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index eed0d1a..82cf079 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -506 \ No newline at end of file +519 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index 9ce0f49..dd4a900 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -241 \ No newline at end of file +254 \ No newline at end of file diff --git a/Common/BBCodes/Code.cs b/Common/BBCodes/Code.cs index 83ad886..339a825 100644 --- a/Common/BBCodes/Code.cs +++ b/Common/BBCodes/Code.cs @@ -12,7 +12,7 @@ namespace FLocal.Common.BBCodes { } public override string Format(ITextFormatter formatter) { - return "
" + this.InnerBBCode + "
"; + return "
" + this.InnerBBCode.Trim() + "

"; } } diff --git a/Common/BBCodes/FUrl.cs b/Common/BBCodes/FUrl.cs index 8f82c6c..a0aa190 100644 --- a/Common/BBCodes/FUrl.cs +++ b/Common/BBCodes/FUrl.cs @@ -12,11 +12,7 @@ namespace FLocal.Common.BBCodes { } public override string Format(ITextFormatter formatter) { - string rawUrl = this.Default; - if(rawUrl == null) { - // throw new ApplicationException(String.Join("; ", (from kvp in this.Attributes select kvp.Key + "=" + kvp.Value).ToArray())); - rawUrl = this.InnerText; - } + string rawUrl = this.DefaultOrValue; Uri uri = new Uri(rawUrl); return "" + this.GetInnerHTML(formatter) + ""; } diff --git a/Common/BBCodes/Font.cs b/Common/BBCodes/Font.cs new file mode 100644 index 0000000..4cf6cfc --- /dev/null +++ b/Common/BBCodes/Font.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class Font : BBCode { + + public Font() + : base("font") { + } + + public override string Format(ITextFormatter formatter) { + return "" + this.GetInnerHTML(formatter) + ""; + } + + } +} diff --git a/Common/BBCodes/FontColor.cs b/Common/BBCodes/FontColor.cs new file mode 100644 index 0000000..8031296 --- /dev/null +++ b/Common/BBCodes/FontColor.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class FontColor : BBCode { + + public FontColor() + : base("color") { + } + + public override string Format(ITextFormatter formatter) { + return "" + this.GetInnerHTML(formatter) + ""; + } + + } +} diff --git a/Common/BBCodes/FontSize.cs b/Common/BBCodes/FontSize.cs new file mode 100644 index 0000000..dec1ecb --- /dev/null +++ b/Common/BBCodes/FontSize.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class FontSize : BBCode { + + public FontSize() + : base("size") { + } + + public override string Format(ITextFormatter formatter) { + return "" + this.GetInnerHTML(formatter) + ""; + } + + } +} diff --git a/Common/BBCodes/List.cs b/Common/BBCodes/List.cs new file mode 100644 index 0000000..c59ec03 --- /dev/null +++ b/Common/BBCodes/List.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class List : BBCode { + + public List() + : base("list") { + } + + public override string Format(ITextFormatter formatter) { + return ""; + } + + } +} diff --git a/Common/BBCodes/ListElem.cs b/Common/BBCodes/ListElem.cs new file mode 100644 index 0000000..6e6f670 --- /dev/null +++ b/Common/BBCodes/ListElem.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class ListElem : BBCode { + + public ListElem() + : base("*") { + } + + public override string Format(ITextFormatter formatter) { +// return "
  • " + this.GetInnerHTML(formatter) + "
  • "; + return "
  • "; + } + + } +} diff --git a/Common/BBCodes/Quote.cs b/Common/BBCodes/Quote.cs new file mode 100644 index 0000000..24fdf0a --- /dev/null +++ b/Common/BBCodes/Quote.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class Quote : BBCode { + + public Quote() + : base("quote") { + } + + public override string Format(ITextFormatter formatter) { + string marker = this.Default; + if(marker == null) marker = "Quote:"; + return "
    " + marker + "

    " + this.GetInnerHTML(formatter).Trim() + "



    "; + } + + } +} diff --git a/Common/BBCodes/Spoiler.cs b/Common/BBCodes/Spoiler.cs new file mode 100644 index 0000000..d5ccd46 --- /dev/null +++ b/Common/BBCodes/Spoiler.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class Spoiler : BBCode { + + public Spoiler() + : base("spoiler") { + } + + public override string Format(ITextFormatter formatter) { + string marker = this.Default; + if(marker == null) marker = "Spoiler"; + return "
    " + marker + "
    " + this.GetInnerHTML(formatter).Trim() + "


    "; + } + + } +} diff --git a/Common/BBCodes/UploadImage.cs b/Common/BBCodes/UploadImage.cs new file mode 100644 index 0000000..5688dcd --- /dev/null +++ b/Common/BBCodes/UploadImage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class UploadImage : BBCode { + + public UploadImage() + : base("uploadimage") { + } + + public override string Format(ITextFormatter formatter) { + var upload = dataobjects.Upload.LoadById(int.Parse(this.InnerText)); + var name = upload.filename; + return "/Upload/Item/" + upload.id.ToString() + "/" + this.Safe(upload.filename) + ""; + } + + } +} diff --git a/Common/BBCodes/UploadLink.cs b/Common/BBCodes/UploadLink.cs new file mode 100644 index 0000000..5333604 --- /dev/null +++ b/Common/BBCodes/UploadLink.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class UploadLink : BBCode { + + public UploadLink() + : base("uploadlink") { + } + + public override string Format(ITextFormatter formatter) { + var upload = dataobjects.Upload.LoadById(int.Parse(this.DefaultOrValue)); + var name = this.Safe(upload.filename); + if(this.Default != null) { + name = this.GetInnerHTML(formatter); + } + return "" + name + ""; + } + + } +} diff --git a/Common/BBCodes/Url.cs b/Common/BBCodes/Url.cs index 521fcd2..63aeb0a 100644 --- a/Common/BBCodes/Url.cs +++ b/Common/BBCodes/Url.cs @@ -12,11 +12,7 @@ namespace FLocal.Common.BBCodes { } public override string Format(ITextFormatter formatter) { - string rawUrl = this.Default; - if(rawUrl == null) { -// throw new ApplicationException(String.Join("; ", (from kvp in this.Attributes select kvp.Key + "=" + kvp.Value).ToArray())); - rawUrl = this.InnerText; - } + string rawUrl = this.DefaultOrValue; var urlInfo = UrlProcessor.Process(rawUrl); return "" + this.GetInnerHTML(formatter) + ""; } diff --git a/Common/BBCodes/User.cs b/Common/BBCodes/User.cs new file mode 100644 index 0000000..b898eb3 --- /dev/null +++ b/Common/BBCodes/User.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PJonDevelopment.BBCode; + +namespace FLocal.Common.BBCodes { + class User : BBCode { + + public User() + : base("user") { + } + + public override string Format(ITextFormatter formatter) { + var user = dataobjects.User.LoadByName(this.Default); + return "" + this.Safe(user.name) + ""; + } + + } +} diff --git a/Common/BBCodes/helpers/BBCode.cs b/Common/BBCodes/helpers/BBCode.cs index 552dd5c..82a0e15 100644 --- a/Common/BBCodes/helpers/BBCode.cs +++ b/Common/BBCodes/helpers/BBCode.cs @@ -31,5 +31,19 @@ namespace FLocal.Common.BBCodes { } } + protected string DefaultOrValue { + get { + string result = this.Default; + if(result == null) { + result = this.InnerText; + } + return result; + } + } + + protected string Safe(string str) { + return System.Web.HttpUtility.HtmlEncode(str); + } + } } diff --git a/Common/Common.csproj b/Common/Common.csproj index 518e1e4..dff83c5 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -58,14 +58,24 @@ + + + + + + + + + + diff --git a/Common/UBBParser.cs b/Common/UBBParser.cs index 2d37d52..724e986 100644 --- a/Common/UBBParser.cs +++ b/Common/UBBParser.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; +using System.Text.RegularExpressions; using PJonDevelopment.BBCode; namespace FLocal.Common { @@ -10,6 +11,46 @@ namespace FLocal.Common { private class BBParserGateway { + private class TextFormatter : ITextFormatter { + + public static readonly TextFormatter instance = new TextFormatter(); + + private static readonly Dictionary SMILEYS = new Dictionary { + { ":)", "smile" }, + { ":(", "frown" }, + { ":o", "blush" }, + { ":D", "laugh" }, + { ";)", "wink" }, + { ":p", "tongue" }, + { ":cool:", "cool" }, + { ":crazy:", "crazy" }, + { ":mad:", "mad" }, + { ":shocked:", "shocked" }, + { ":smirk:", "smirk" }, + { ":grin:", "grin" }, + { ":ooo:", "ooo" }, + { ":confused:", "confused" }, + { ":lol:", "lol" }, + }; + + private static readonly Dictionary SMILEYS_DATA = (from smile in SMILEYS select new KeyValuePair(new Regex("(\\s+)" + Regex.Escape(smile.Key) + "(\\s+)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => match.Groups[1] + "\""" + match.Groups[2])).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); + + private ITextFormatter inner; + + private TextFormatter() { + this.inner = new BBCodeHtmlFormatter(); + } + + public string Format(string source) { + string result = this.inner.Format(source); + foreach(var smile in SMILEYS_DATA) { + result = smile.Key.Replace(result, smile.Value); + } + return result; + } + + } + public static readonly BBParserGateway instance = new BBParserGateway(); private BBCodeParser parser; @@ -19,13 +60,23 @@ namespace FLocal.Common { this.parser = new BBCodeParser(); this.parser.ElementTypes.Add("b", typeof(BBCodes.B), true); this.parser.ElementTypes.Add("code", typeof(BBCodes.Code), true); + this.parser.ElementTypes.Add("font", typeof(BBCodes.Font), true); + this.parser.ElementTypes.Add("color", typeof(BBCodes.FontColor), true); + this.parser.ElementTypes.Add("size", typeof(BBCodes.FontSize), true); this.parser.ElementTypes.Add("furl", typeof(BBCodes.FUrl), true); this.parser.ElementTypes.Add("i", typeof(BBCodes.I), true); this.parser.ElementTypes.Add("image", typeof(BBCodes.Image), true); + this.parser.ElementTypes.Add("list", typeof(BBCodes.List), true); + this.parser.ElementTypes.Add("*", typeof(BBCodes.ListElem), false); + this.parser.ElementTypes.Add("quote", typeof(BBCodes.Quote), true);this.parser.ElementTypes.Add("q", typeof(BBCodes.Quote), true); this.parser.ElementTypes.Add("s", typeof(BBCodes.S), true); + this.parser.ElementTypes.Add("spoiler", typeof(BBCodes.Spoiler), true);this.parser.ElementTypes.Add("cut", typeof(BBCodes.Spoiler), true); this.parser.ElementTypes.Add("u", typeof(BBCodes.U), true); + this.parser.ElementTypes.Add("uploadimage", typeof(BBCodes.UploadImage), true); + this.parser.ElementTypes.Add("uploadlink", typeof(BBCodes.UploadLink), true); this.parser.ElementTypes.Add("url", typeof(BBCodes.Url), true); - this.formatter = new BBCodeHtmlFormatter(); + this.parser.ElementTypes.Add("user", typeof(BBCodes.User), false); + this.formatter = TextFormatter.instance; } public string Parse(string input) { diff --git a/static/css/global.css b/static/css/global.css index 7c8316d..c9c352d 100644 --- a/static/css/global.css +++ b/static/css/global.css @@ -75,4 +75,10 @@ pre [pseudolink] { cursor:hand; text-decoration:underline; -} \ No newline at end of file +} +[spoiler] [inner] { + display:none; +} +[spoiler] [opener] { + cursor:hand; +} diff --git a/static/js/common.js b/static/js/common.js new file mode 100644 index 0000000..18607de --- /dev/null +++ b/static/js/common.js @@ -0,0 +1,8 @@ +function showSpoiler(obj) { + var inner = obj.parentNode.getElementsByTagName("div")[0]; + if(inner.style.display == "none" || inner.style.display == null || inner.style.display == "") { + inner.style.display = "block"; + } else { + inner.style.display = "none"; + } +} \ No newline at end of file diff --git a/templates/Full/elems/Main.xslt b/templates/Full/elems/Main.xslt index a4cd180..a70a0c8 100644 --- a/templates/Full/elems/Main.xslt +++ b/templates/Full/elems/Main.xslt @@ -10,6 +10,7 @@ /static/css/.css + <xsl:value-of select="title"/> diff --git a/templates/Full/elems/TextEditor.xslt b/templates/Full/elems/TextEditor.xslt index fc6e18f..fcc2fc2 100644 --- a/templates/Full/elems/TextEditor.xslt +++ b/templates/Full/elems/TextEditor.xslt @@ -125,13 +125,13 @@ function insertInBody(str) { - Íà÷àëî
    ãîëîñîâàíèÿ
    + Íà÷àëî
    ãîëîñîâàíèÿ
    - Âàðèàíò
    ãîëîñîâàíèÿ
    + Âàðèàíò
    ãîëîñîâàíèÿ
    - Êîíåö
    ãîëîñîâàíèÿ
    + Êîíåö
    ãîëîñîâàíèÿ
    @@ -150,18 +150,18 @@ function insertInBody(str) { Ïîëüçîâàòåëü - Òàáëèöà + Òàáëèöà - Ecode + Ecode - YouTube + YouTube - Math + Math