diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 7ad8022..6efca19 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -480 \ No newline at end of file +481 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index 0acdeb5..e99fdcc 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -216 \ No newline at end of file +217 \ No newline at end of file diff --git a/Common/dataobjects/Board.cs b/Common/dataobjects/Board.cs index 0ad92ad..ac68561 100644 --- a/Common/dataobjects/Board.cs +++ b/Common/dataobjects/Board.cs @@ -22,6 +22,7 @@ namespace FLocal.Common.dataobjects { public const string FIELD_NAME = "Name"; public const string FIELD_DESCRIPTION = "Comment"; public const string FIELD_PARENTBOARDID = "ParentBoardId"; + public const string FIELD_LEGACYNAME = "LegacyName"; public static readonly TableSpec instance = new TableSpec(); public string name { get { return TABLE; } } public string idName { get { return FIELD_ID; } } @@ -121,6 +122,14 @@ namespace FLocal.Common.dataobjects { } } + private string _legacyName; + public string legacyName { + get { + this.LoadIfNotLoaded(); + return this._legacyName; + } + } + protected override void doFromHash(Dictionary data) { this._sortOrder = int.Parse(data[TableSpec.FIELD_SORTORDER]); this._categoryId = Util.ParseInt(data[TableSpec.FIELD_CATEGORYID]); @@ -130,6 +139,7 @@ namespace FLocal.Common.dataobjects { this._name = data[TableSpec.FIELD_NAME]; this._description = data[TableSpec.FIELD_DESCRIPTION]; this._parentBoardId = Util.ParseInt(data[TableSpec.FIELD_PARENTBOARDID]); + this._legacyName = data[TableSpec.FIELD_LEGACYNAME]; } private readonly object subBoards_Locker = new object(); @@ -216,6 +226,21 @@ namespace FLocal.Common.dataobjects { return result; } + private static readonly IEnumerable allBoardsIds = from stringId in Config.instance.mainConnection.LoadIdsByConditions(TableSpec.instance, new EmptyCondition(), Diapasone.unlimited) select int.Parse(stringId); + + private static Dictionary legacyName2Id = new Dictionary(); + public static Board LoadByLegacyName(string legacy) { + if((legacy == null) || (legacy == "")) throw new FLocalException("legacy name is empty"); + if(!legacyName2Id.ContainsKey(legacy)) { + lock(legacyName2Id) { + if(!legacyName2Id.ContainsKey(legacy)) { + legacyName2Id[legacy] = (from boardId in allBoardsIds let board = Board.LoadById(boardId) where board.legacyName == legacy select boardId).Single(); + } + } + } + return Board.LoadById(legacyName2Id[legacy]); + } + public IEnumerable getThreads(Diapasone diapasone, SortSpec[] sortBy) { return Thread.LoadByIds( from stringId in Config.instance.mainConnection.LoadIdsByConditions( diff --git a/IISMainHandler/HandlersFactory.cs b/IISMainHandler/HandlersFactory.cs index 9f601dc..66b85f2 100644 --- a/IISMainHandler/HandlersFactory.cs +++ b/IISMainHandler/HandlersFactory.cs @@ -19,6 +19,9 @@ namespace FLocal.IISHandler { if(context.httprequest.Path.ToLower().StartsWith("/user/upload/")) { return new handlers.response.LegacyUploadHandler(); } + if(context.httprequest.Path.EndsWith(".php")) { + return new handlers.response.LegacyPHPHandler(); + } #endregion switch(context.requestParts[0].ToLower()) { diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index bd5b96f..fa2496d 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -74,12 +74,14 @@ + + diff --git a/IISMainHandler/handlers/response/LegacyPHPHandler.cs b/IISMainHandler/handlers/response/LegacyPHPHandler.cs new file mode 100644 index 0000000..bb1f5c7 --- /dev/null +++ b/IISMainHandler/handlers/response/LegacyPHPHandler.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FLocal.Core; +using FLocal.Common; +using FLocal.Common.dataobjects; + +namespace FLocal.IISHandler.handlers.response { + class LegacyPHPHandler : RedirectGetHandler { + + protected override string getRedirectUrl(WebContext context) { + string[] scriptParts = context.requestParts[0].Split('.'); + if(scriptParts.Length != 2) { + throw new FLocalException("wrong url"); + } + if(scriptParts[1].ToLower() != "php") { + throw new FLocalException("wrong url"); + } + + switch(scriptParts[0].ToLower()) { + case "showflat": + Post post = Post.LoadById(int.Parse(context.httprequest.QueryString["Number"])); + return "/Thread/" + post.thread.id.ToString() + "/p" + post.id.ToString(); + case "showthreaded": + return "/Post/" + int.Parse(context.httprequest.QueryString["Number"]).ToString() + "/"; + case "postlist": + return "/Board/" + Board.LoadByLegacyName(context.httprequest.QueryString["Board"]).id.ToString() + "/"; + default: + throw new NotImplementedException("unknown script " + scriptParts[0]); + } + } + + } +} diff --git a/IISMainHandler/handlers/response/LegacyUploadHandler.cs b/IISMainHandler/handlers/response/LegacyUploadHandler.cs index 368189c..e5fe415 100644 --- a/IISMainHandler/handlers/response/LegacyUploadHandler.cs +++ b/IISMainHandler/handlers/response/LegacyUploadHandler.cs @@ -4,19 +4,11 @@ using System.Linq; using System.Text; using FLocal.Core; using FLocal.Common; -using System.Xml.Linq; -using FLocal.Common.dataobjects; namespace FLocal.IISHandler.handlers.response { - class LegacyUploadHandler : AbstractGetHandler { + class LegacyUploadHandler : RedirectGetHandler { - protected override string templateName { - get { - return null; - } - } - - protected override System.Xml.Linq.XElement[] getSpecificData(WebContext context) { + protected override string getRedirectUrl(WebContext context) { if(context.requestParts.Length != 3) throw new FLocalException("wrong url"); string[] parts = context.requestParts[2].Split('.'); if(parts.Length != 2) throw new FLocalException("wrong url"); @@ -36,7 +28,7 @@ namespace FLocal.IISHandler.handlers.response { default: throw new FLocalException("wrong url"); } - throw new RedirectException("/Upload/Item/" + fileNum + "/"); + return "/Upload/Item/" + fileNum + "/"; } } diff --git a/IISMainHandler/handlers/response/RedirectGetHandler.cs b/IISMainHandler/handlers/response/RedirectGetHandler.cs new file mode 100644 index 0000000..1031747 --- /dev/null +++ b/IISMainHandler/handlers/response/RedirectGetHandler.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace FLocal.IISHandler.handlers.response { + abstract class RedirectGetHandler : AbstractGetHandler { + + protected override string templateName { + get { + return null; + } + } + + abstract protected string getRedirectUrl(WebContext context); + + protected override XElement[] getSpecificData(WebContext context) { + throw new RedirectException(this.getRedirectUrl(context)); + } + + } +}