Some basic UBBCodes implemented

main
Inga 🏳‍🌈 14 years ago
parent a0340e7ebe
commit f2252093c6
  1. 2
      Builder/IISMainHandler/build.txt
  2. 2
      Builder/IISUploadHandler/build.txt
  3. 19
      Common/BBCodes/B.cs
  4. 19
      Common/BBCodes/Code.cs
  5. 25
      Common/BBCodes/FUrl.cs
  6. 19
      Common/BBCodes/I.cs
  7. 23
      Common/BBCodes/Image.cs
  8. 19
      Common/BBCodes/S.cs
  9. 19
      Common/BBCodes/U.cs
  10. 25
      Common/BBCodes/Url.cs
  11. 35
      Common/BBCodes/helpers/BBCode.cs
  12. 57
      Common/BBCodes/helpers/UrlProcessor.cs
  13. 14
      Common/Common.csproj
  14. 30
      Common/UBBParser.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 B : BBCode {
public B()
: base("b") {
}
public override string Format(ITextFormatter formatter) {
return "<b>" + this.GetInnerHTML(formatter) + "</b>";
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class Code : BBCode {
public Code()
: base("code") {
}
public override string Format(ITextFormatter formatter) {
return "<pre>" + this.InnerBBCode + "</pre>";
}
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class FUrl : BBCode {
public FUrl()
: base("furl") {
}
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;
}
Uri uri = new Uri(rawUrl);
return "<a href=\"" + uri.ToString() + "\">" + this.GetInnerHTML(formatter) + "</a>";
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class I : BBCode {
public I()
: base("i") {
}
public override string Format(ITextFormatter formatter) {
return "<i>" + this.GetInnerHTML(formatter) + "</i>";
}
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class Image : BBCode {
public Image() : base("image") {
}
public override string Format(ITextFormatter formatter) {
var urlInfo = UrlProcessor.Process(this.InnerText);
if (urlInfo.isLocal && urlInfo.relativeUrl.StartsWith("/user/upload/")) {
return "<f:img><f:src>" + urlInfo.relativeUrl + "</f:src><f:alt>" + urlInfo.relativeUrl + "</f:alt></f:img>";
} else {
return "<a href=\"" + urlInfo.relativeUrl + "\">" + urlInfo.relativeUrl + "</a>";
}
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class S : BBCode {
public S()
: base("s") {
}
public override string Format(ITextFormatter formatter) {
return "<s>" + this.GetInnerHTML(formatter) + "</s>";
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class U : BBCode {
public U()
: base("u") {
}
public override string Format(ITextFormatter formatter) {
return "<u>" + this.GetInnerHTML(formatter) + "</u>";
}
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class Url : BBCode {
public Url()
: base("url") {
}
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;
}
var urlInfo = UrlProcessor.Process(rawUrl);
return "<a href=\"" + urlInfo.relativeUrl + "\">" + this.GetInnerHTML(formatter) + "</a>";
}
}
}

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Common.BBCodes {
abstract class BBCode : PJonDevelopment.BBCode.BBCodeElement {
public BBCode(string name)
: base(name) {
}
protected string GetInnerHTML(PJonDevelopment.BBCode.ITextFormatter formatter) {
StringBuilder builder = new StringBuilder();
foreach (var node in this.Nodes) {
builder.Append(node.Format(formatter));
}
return builder.ToString();
}
protected string Default {
get {
if(!this.Attributes.ContainsKey("DEFAULT")) {
return null;
}
string result = this.Attributes["DEFAULT"];
if(result == null || result == "") {
return null;
}
return result;
}
}
}
}

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace FLocal.Common.BBCodes {
class UrlProcessor {
public struct UrlInfo {
public readonly bool isLocal;
private readonly string rawRelativeUrl;
public string relativeUrl {
get {
return this.rawRelativeUrl;
//return HttpUtility.UrlEncode(this.rawRelativeUrl);
}
}
public UrlInfo(bool isLocal, string relativeUrl) {
this.isLocal = isLocal;
this.rawRelativeUrl = relativeUrl;
}
}
public static HashSet<string> KnownAliases = new HashSet<string> {
"forum.local",
"forum.b.gz.ru",
"www.snto-msu.net",
"hq.sectorb.msk.ru",
"petaflop.b.gz.ru",
"194.88.210.5",
"forumlocal.ru",
"forumbgz.ru",
"forum.hn",
};
public const string DOMAIN = ".forum.hn";
public static UrlInfo Process(string url) {
if (url.StartsWith("/")) {
return new UrlInfo(true, url);
}
Uri uri;
try {
uri = new Uri(url);
} catch(UriFormatException) {
throw new Core.FLocalException("wrong url: " + url);
}
if (KnownAliases.Contains(uri.Host.ToLower()) || uri.Host.ToLower().EndsWith(DOMAIN)) {
return new UrlInfo(true, uri.PathAndQuery);
} else {
return new UrlInfo(false, uri.ToString());
}
}
}
}

@ -57,6 +57,15 @@
<Compile Include="actions\TwoWayReferenceFieldValue.cs" />
<Compile Include="actions\UpdateChange.cs" />
<Compile Include="actions\ChangeSetUtil.cs" />
<Compile Include="BBCodes\B.cs" />
<Compile Include="BBCodes\helpers\BBCode.cs" />
<Compile Include="BBCodes\Code.cs" />
<Compile Include="BBCodes\FUrl.cs" />
<Compile Include="BBCodes\Image.cs" />
<Compile Include="BBCodes\S.cs" />
<Compile Include="BBCodes\U.cs" />
<Compile Include="BBCodes\Url.cs" />
<Compile Include="BBCodes\helpers\UrlProcessor.cs" />
<Compile Include="Config.cs" />
<Compile Include="dataobjects\Account.cs" />
<Compile Include="dataobjects\AccountIndicator.cs" />
@ -79,6 +88,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlObject.cs" />
<Compile Include="UBBParser.cs" />
<Compile Include="BBCodes\I.cs" />
<Compile Include="UploadManager.cs" />
<Compile Include="UserContext.cs" />
<Compile Include="UserSettingsGateway.cs" />
@ -92,6 +102,10 @@
<Project>{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}</Project>
<Name>MySQLConnector</Name>
</ProjectReference>
<ProjectReference Include="..\ThirdParty\BBCode\BBCode.vbproj">
<Project>{ACDDD5D1-119F-4B82-8FE6-6515C812795B}</Project>
<Name>BBCode</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

@ -3,12 +3,40 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using PJonDevelopment.BBCode;
namespace FLocal.Common {
public static class UBBParser {
private class BBParserGateway {
public static readonly BBParserGateway instance = new BBParserGateway();
private BBCodeParser parser;
private ITextFormatter formatter;
private BBParserGateway() {
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("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("s", typeof(BBCodes.S), true);
this.parser.ElementTypes.Add("u", typeof(BBCodes.U), true);
this.parser.ElementTypes.Add("url", typeof(BBCodes.Url), true);
this.formatter = new BBCodeHtmlFormatter();
}
public string Parse(string input) {
return this.parser.Parse(input).Format(this.formatter);
}
}
public static string UBBToIntermediate(string UBB) {
return HttpUtility.HtmlEncode(UBB).Replace("\r\n", "<br/>\r\n");
//return HttpUtility.HtmlEncode(UBB).Replace("\r\n", "<br/>\r\n");
return BBParserGateway.instance.Parse(UBB);
}
public static string ShallerToUBB(string shaller) {

Loading…
Cancel
Save