TranslitManager implemented; verbose thread and board urls

main
Inga 🏳‍🌈 14 years ago
parent 5de8eb789e
commit 70a8952ca8
  1. 2
      Builder/IISMainHandler/build.txt
  2. 5
      Common/Common.csproj
  3. 66
      Common/TranslitManager.cs
  4. 34
      Common/URL/forum/board/Abstract.cs
  5. 15
      Common/URL/forum/board/Headlines.cs
  6. 15
      Common/URL/forum/board/NewThread.cs
  7. 15
      Common/URL/forum/board/Threads.cs
  8. 35
      Common/URL/forum/board/thread/Abstract.cs
  9. 15
      Common/URL/forum/board/thread/Posts.cs
  10. 37
      Common/URL/forum/board/thread/post/Abstract.cs
  11. 15
      Common/URL/forum/board/thread/post/Edit.cs
  12. 15
      Common/URL/forum/board/thread/post/PMReply.cs
  13. 15
      Common/URL/forum/board/thread/post/Punish.cs
  14. 15
      Common/URL/forum/board/thread/post/Reply.cs
  15. 15
      Common/URL/forum/board/thread/post/Show.cs
  16. 5
      Common/dataobjects/Board.cs
  17. 5
      Common/dataobjects/Thread.cs
  18. 1
      IISMainHandler/HandlersFactory.cs

@ -58,6 +58,7 @@
<Compile Include="actions\UpdateChange.cs" />
<Compile Include="actions\ChangeSetUtil.cs" />
<Compile Include="BBCodes\B.cs" />
<Compile Include="BBCodes\ECode.cs" />
<Compile Include="BBCodes\Font.cs" />
<Compile Include="BBCodes\FontColor.cs" />
<Compile Include="BBCodes\FontSize.cs" />
@ -125,6 +126,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlObject.cs" />
<Compile Include="TableManager.cs" />
<Compile Include="TranslitManager.cs" />
<Compile Include="UBBParser.cs" />
<Compile Include="BBCodes\I.cs" />
<Compile Include="UploadManager.cs" />
@ -132,9 +134,12 @@
<Compile Include="URL\forum\AllPosts.cs" />
<Compile Include="URL\forum\AllThreads.cs" />
<Compile Include="URL\forum\Boards.cs" />
<Compile Include="URL\forum\board\Abstract.cs" />
<Compile Include="URL\forum\board\Headlines.cs" />
<Compile Include="URL\forum\board\NewThread.cs" />
<Compile Include="URL\forum\board\Threads.cs" />
<Compile Include="URL\forum\board\thread\Abstract.cs" />
<Compile Include="URL\forum\board\thread\post\Abstract.cs" />
<Compile Include="URL\forum\board\thread\post\Edit.cs" />
<Compile Include="URL\forum\board\thread\post\PMReply.cs" />
<Compile Include="URL\forum\board\thread\post\Punish.cs" />

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Common {
static class TranslitManager {
private static readonly string SAFE_SOURCE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZабвгдеёжзийклмнопрстуфхцчшщьыъэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ -0123456789";
private static readonly string SAFE_DESTINATION = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYSabvgdeejziyklmnoprstufxc4ww'y'eu9ABVGDEEJZIJKLMNOPRSTUFXC4WW'Y'EU9--0123456789";
private static readonly Dictionary<char, char> SAFE_REPLACEMENTS = Enumerable.Range(0, SAFE_SOURCE.Length).ToDictionary(i => SAFE_SOURCE[i], i => SAFE_DESTINATION[i]);
/* private static readonly Dictionary<char, char> replacements = new Dictionary<char,char> {
{ 'a', 'a' },
{ 'b', 'b' },
{ 'c', 'c' },
{ 'd', 'd' },
{ 'e', 'e' },
{ 'f', 'f' },
{ 'g', 'g' },
{ 'h', 'h' },
{ 'i', 'i' },
{ 'j', 'j' },
{ 'k', 'k' },
{ 'l', 'l' },
{ 'm', 'm' },
{ 'n', 'n' },
{ 'o', 'o' },
{ 'p', 'p' },
{ 'q', 'q' },
{ 'r', 'r' },
{ 's', 's' },
{ 't', 't' },
{ 'u', 'u' },
{ 'v', 'v' },
{ 'w', 'w' },
{ 'x', 'x' },
{ 'y', 'y' },
{ 'z', 'z' },
{ 'A', 'A' },
{ 'B', 'B' },
{ 'C', 'C' },
{ 'D', 'D' },
// { '
};*/
private static string Transform(string source, Dictionary<char, char> transforms) {
return new string((from i in Enumerable.Range(0, source.Length) where transforms.ContainsKey(source[i]) select transforms[source[i]]).ToArray());
}
public static string Translit(string source) {
/*Dictionary<char, int> dict = new Dictionary<char,int>();
(
from i in Enumerable.Range(0, SAFE_SOURCE.Length)
select SAFE_SOURCE[i]
).Aggregate(0, (i, ch) => {
if(!dict.ContainsKey(ch)) dict[ch] = 0;
dict[ch]++;
return i;
});
throw new ApplicationException("!" + new string((from kvp in dict where kvp.Value > 1 select kvp.Key).ToArray()) + "@");*/
return Transform(source, SAFE_REPLACEMENTS);
}
}
}

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board {
public abstract class Abstract : AbstractUrl {
private static int extractBoardId(string boardId) {
return int.Parse(boardId.Contains('-') ? boardId.Substring(0, boardId.IndexOf('-')) : boardId);
}
public readonly Board board;
public Abstract(int boardId, string remainder) : base(remainder) {
this.board = Board.LoadById(boardId);
}
public Abstract(string boardId, string remainder) : this(extractBoardId(boardId), remainder) {
}
public override string title {
get {
return this.board.name;
}
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.board.id + "-" + this.board.nameTranslit + "/";
}
}
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board {
public class Headlines : AbstractUrl {
public class Headlines : Abstract {
public readonly Board board;
public Headlines(string boardId, string remainder) : base(remainder) {
this.board = Board.LoadById(int.Parse(boardId));
}
public override string title {
get {
return this.board.name;
}
public Headlines(string boardId, string remainder) : base(boardId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.board.id + "/Headlines/";
return base._canonical + "Headlines/";
}
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board {
public class NewThread : AbstractUrl {
public class NewThread : Abstract {
public readonly Board board;
public NewThread(string boardId, string remainder) : base(remainder) {
this.board = Board.LoadById(int.Parse(boardId));
}
public override string title {
get {
return this.board.name;
}
public NewThread(string boardId, string remainder) : base(boardId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.board.id + "/NewThread/";
return base._canonical + "NewThread/";
}
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board {
public class Threads : AbstractUrl {
public class Threads : Abstract {
public readonly Board board;
public Threads(string boardId, string remainder) : base(remainder) {
this.board = Board.LoadById(int.Parse(boardId));
}
public override string title {
get {
return this.board.name;
}
public Threads(string boardId, string remainder) : base(boardId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.board.id + "/Threads/";
return base._canonical + "Threads/";
}
}
}

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board.thread {
public abstract class Abstract : board.Abstract {
private static int extractThreadId(string threadId) {
return int.Parse(threadId.Contains('-') ? threadId.Substring(0, threadId.IndexOf('-')) : threadId);
}
public readonly Thread thread;
public Abstract(int threadId, string remainder)
: base(Thread.LoadById(threadId).boardId, remainder) {
this.thread = Thread.LoadById(threadId);
}
public Abstract(string threadId, string remainder) : this(extractThreadId(threadId), remainder) {
}
public override string title {
get {
return this.thread.title;
}
}
protected override string _canonical {
get {
return base._canonical + "Thread/" + this.thread.id + "-" + this.thread.titleTranslit + "/";
}
}
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board.thread {
public class Posts : AbstractUrl {
public class Posts : Abstract {
public readonly dataobjects.Thread thread;
public Posts(string threadId, string remainder) : base(remainder) {
this.thread = dataobjects.Thread.LoadById(int.Parse(threadId));
}
public override string title {
get {
return this.thread.title;
}
public Posts(string threadId, string remainder) : base(threadId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.thread.boardId + "/Thread/" + this.thread.id + "/Posts/";
return base._canonical + "Posts/";
}
}
}

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board.thread.post {
public abstract class Abstract : thread.Abstract {
private static int extractPostId(string postId) {
return int.Parse(postId);
}
public readonly Post post;
public Abstract(int postId, string remainder)
: base(Post.LoadById(postId).threadId, remainder) {
this.post = Post.LoadById(postId);
}
public Abstract(string postId, string remainder) : this(extractPostId(postId), remainder) {
}
public override string title {
get {
return this.post.title;
}
}
protected override string _canonical {
get {
return base._canonical + "Post/" + post.id + "/";
}
}
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board.thread.post {
public class Edit : AbstractUrl {
public class Edit : Abstract {
public Post post;
public Edit(string postId, string remainder) : base(remainder) {
this.post = Post.LoadById(int.Parse(postId));
}
public override string title {
get {
return post.title;
}
public Edit(string postId, string remainder) : base(postId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/Edit/";
return base._canonical + "Edit/";
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board.thread.post {
public class PMReply : AbstractUrl {
public class PMReply : Abstract {
public Post post;
public PMReply(string postId, string remainder) : base(remainder) {
this.post = Post.LoadById(int.Parse(postId));
}
public override string title {
get {
return post.title;
}
public PMReply(string postId, string remainder) : base(postId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/PMReply/";
return base._canonical + "PMReply/";
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board.thread.post {
public class Punish : AbstractUrl {
public class Punish : Abstract {
public Post post;
public Punish(string postId, string remainder) : base(remainder) {
this.post = Post.LoadById(int.Parse(postId));
}
public override string title {
get {
return post.title;
}
public Punish(string postId, string remainder) : base(postId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/Punish/";
return base._canonical + "Punish/";
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board.thread.post {
public class Reply : AbstractUrl {
public class Reply : Abstract {
public Post post;
public Reply(string postId, string remainder) : base(remainder) {
this.post = Post.LoadById(int.Parse(postId));
}
public override string title {
get {
return post.title;
}
public Reply(string postId, string remainder) : base(postId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/Reply/";
return base._canonical + "Reply/";
}
}

@ -5,23 +5,14 @@ using System.Text;
using FLocal.Common.dataobjects;
namespace FLocal.Common.URL.forum.board.thread.post {
public class Show : AbstractUrl {
public class Show : Abstract {
public Post post;
public Show(string postId, string remainder) : base(remainder) {
this.post = Post.LoadById(int.Parse(postId));
}
public override string title {
get {
return post.title;
}
public Show(string postId, string remainder) : base(postId, remainder) {
}
protected override string _canonical {
get {
return "/Forum/Board/" + this.post.thread.boardId + "/Thread/" + this.post.threadId + "/Post/" + post.id + "/Show/";
return base._canonical + "Show/";
}
}

@ -115,6 +115,11 @@ namespace FLocal.Common.dataobjects {
return this._name;
}
}
public string nameTranslit {
get {
return TranslitManager.Translit(this.name);
}
}
private string _description;
public string description {

@ -108,6 +108,11 @@ namespace FLocal.Common.dataobjects {
return this._title;
}
}
public string titleTranslit {
get {
return TranslitManager.Translit(this.title).PHPSubstring(0, 50);
}
}
private int _lastPostId;
public int lastPostId {

@ -118,6 +118,7 @@ namespace FLocal.IISHandler {
}
if(!context.httprequest.Path.StartsWith(url.canonical)) {
//throw new ApplicationException("Going to redirect to: '" + url.canonicalFull + "' (canonical='" + url.canonicalFull + "')");
throw new RedirectException(url.canonicalFull);
}

Loading…
Cancel
Save