From 70a8952ca82e5f3525e4f28fef6cc0028f739235 Mon Sep 17 00:00:00 2001
From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com>
Date: Sun, 19 Sep 2010 13:22:31 +0000
Subject: [PATCH] TranslitManager implemented; verbose thread and board urls
---
Builder/IISMainHandler/build.txt | 2 +-
Common/Common.csproj | 5 ++
Common/TranslitManager.cs | 66 +++++++++++++++++++
Common/URL/forum/board/Abstract.cs | 34 ++++++++++
Common/URL/forum/board/Headlines.cs | 15 +----
Common/URL/forum/board/NewThread.cs | 15 +----
Common/URL/forum/board/Threads.cs | 15 +----
Common/URL/forum/board/thread/Abstract.cs | 35 ++++++++++
Common/URL/forum/board/thread/Posts.cs | 15 +----
.../URL/forum/board/thread/post/Abstract.cs | 37 +++++++++++
Common/URL/forum/board/thread/post/Edit.cs | 15 +----
Common/URL/forum/board/thread/post/PMReply.cs | 15 +----
Common/URL/forum/board/thread/post/Punish.cs | 15 +----
Common/URL/forum/board/thread/post/Reply.cs | 15 +----
Common/URL/forum/board/thread/post/Show.cs | 15 +----
Common/dataobjects/Board.cs | 5 ++
Common/dataobjects/Thread.cs | 5 ++
IISMainHandler/HandlersFactory.cs | 1 +
18 files changed, 216 insertions(+), 109 deletions(-)
create mode 100644 Common/TranslitManager.cs
create mode 100644 Common/URL/forum/board/Abstract.cs
create mode 100644 Common/URL/forum/board/thread/Abstract.cs
create mode 100644 Common/URL/forum/board/thread/post/Abstract.cs
diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt
index 5bb1b74..6017717 100644
--- a/Builder/IISMainHandler/build.txt
+++ b/Builder/IISMainHandler/build.txt
@@ -1 +1 @@
-1423
\ No newline at end of file
+1451
\ No newline at end of file
diff --git a/Common/Common.csproj b/Common/Common.csproj
index ed74c9c..3846d18 100644
--- a/Common/Common.csproj
+++ b/Common/Common.csproj
@@ -58,6 +58,7 @@
+
@@ -125,6 +126,7 @@
+
@@ -132,9 +134,12 @@
+
+
+
diff --git a/Common/TranslitManager.cs b/Common/TranslitManager.cs
new file mode 100644
index 0000000..4bb79ac
--- /dev/null
+++ b/Common/TranslitManager.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 SAFE_REPLACEMENTS = Enumerable.Range(0, SAFE_SOURCE.Length).ToDictionary(i => SAFE_SOURCE[i], i => SAFE_DESTINATION[i]);
+
+/* private static readonly Dictionary replacements = new Dictionary {
+ { '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 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 dict = new Dictionary();
+ (
+ 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);
+ }
+
+ }
+}
diff --git a/Common/URL/forum/board/Abstract.cs b/Common/URL/forum/board/Abstract.cs
new file mode 100644
index 0000000..513cb54
--- /dev/null
+++ b/Common/URL/forum/board/Abstract.cs
@@ -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 + "/";
+ }
+ }
+ }
+}
diff --git a/Common/URL/forum/board/Headlines.cs b/Common/URL/forum/board/Headlines.cs
index b48fb45..e2168aa 100644
--- a/Common/URL/forum/board/Headlines.cs
+++ b/Common/URL/forum/board/Headlines.cs
@@ -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/";
}
}
}
diff --git a/Common/URL/forum/board/NewThread.cs b/Common/URL/forum/board/NewThread.cs
index d4cf2bf..fecbd0d 100644
--- a/Common/URL/forum/board/NewThread.cs
+++ b/Common/URL/forum/board/NewThread.cs
@@ -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/";
}
}
}
diff --git a/Common/URL/forum/board/Threads.cs b/Common/URL/forum/board/Threads.cs
index 0a58c25..d31fa4f 100644
--- a/Common/URL/forum/board/Threads.cs
+++ b/Common/URL/forum/board/Threads.cs
@@ -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/";
}
}
}
diff --git a/Common/URL/forum/board/thread/Abstract.cs b/Common/URL/forum/board/thread/Abstract.cs
new file mode 100644
index 0000000..6eebb4b
--- /dev/null
+++ b/Common/URL/forum/board/thread/Abstract.cs
@@ -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 + "/";
+ }
+ }
+ }
+}
diff --git a/Common/URL/forum/board/thread/Posts.cs b/Common/URL/forum/board/thread/Posts.cs
index 38cf831..c6dd50c 100644
--- a/Common/URL/forum/board/thread/Posts.cs
+++ b/Common/URL/forum/board/thread/Posts.cs
@@ -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/";
}
}
}
diff --git a/Common/URL/forum/board/thread/post/Abstract.cs b/Common/URL/forum/board/thread/post/Abstract.cs
new file mode 100644
index 0000000..e1ae520
--- /dev/null
+++ b/Common/URL/forum/board/thread/post/Abstract.cs
@@ -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 + "/";
+ }
+ }
+
+ }
+
+}
diff --git a/Common/URL/forum/board/thread/post/Edit.cs b/Common/URL/forum/board/thread/post/Edit.cs
index 7d341de..cf23f07 100644
--- a/Common/URL/forum/board/thread/post/Edit.cs
+++ b/Common/URL/forum/board/thread/post/Edit.cs
@@ -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/";
}
}
diff --git a/Common/URL/forum/board/thread/post/PMReply.cs b/Common/URL/forum/board/thread/post/PMReply.cs
index aad2b40..ba03d00 100644
--- a/Common/URL/forum/board/thread/post/PMReply.cs
+++ b/Common/URL/forum/board/thread/post/PMReply.cs
@@ -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/";
}
}
diff --git a/Common/URL/forum/board/thread/post/Punish.cs b/Common/URL/forum/board/thread/post/Punish.cs
index 0ccb2c2..4eecadd 100644
--- a/Common/URL/forum/board/thread/post/Punish.cs
+++ b/Common/URL/forum/board/thread/post/Punish.cs
@@ -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/";
}
}
diff --git a/Common/URL/forum/board/thread/post/Reply.cs b/Common/URL/forum/board/thread/post/Reply.cs
index 1822135..9b6b4fe 100644
--- a/Common/URL/forum/board/thread/post/Reply.cs
+++ b/Common/URL/forum/board/thread/post/Reply.cs
@@ -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/";
}
}
diff --git a/Common/URL/forum/board/thread/post/Show.cs b/Common/URL/forum/board/thread/post/Show.cs
index 33dbeea..bdd4de9 100644
--- a/Common/URL/forum/board/thread/post/Show.cs
+++ b/Common/URL/forum/board/thread/post/Show.cs
@@ -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/";
}
}
diff --git a/Common/dataobjects/Board.cs b/Common/dataobjects/Board.cs
index 0374aaf..9048517 100644
--- a/Common/dataobjects/Board.cs
+++ b/Common/dataobjects/Board.cs
@@ -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 {
diff --git a/Common/dataobjects/Thread.cs b/Common/dataobjects/Thread.cs
index ef07181..7d77596 100644
--- a/Common/dataobjects/Thread.cs
+++ b/Common/dataobjects/Thread.cs
@@ -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 {
diff --git a/IISMainHandler/HandlersFactory.cs b/IISMainHandler/HandlersFactory.cs
index a488f5a..eac400c 100644
--- a/IISMainHandler/HandlersFactory.cs
+++ b/IISMainHandler/HandlersFactory.cs
@@ -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);
}