Legacy PHP links support implemented

main
Inga 🏳‍🌈 14 years ago
parent f474658cef
commit 22ebc474e0
  1. 2
      Builder/IISMainHandler/build.txt
  2. 2
      Builder/IISUploadHandler/build.txt
  3. 25
      Common/dataobjects/Board.cs
  4. 3
      IISMainHandler/HandlersFactory.cs
  5. 2
      IISMainHandler/IISMainHandler.csproj
  6. 35
      IISMainHandler/handlers/response/LegacyPHPHandler.cs
  7. 14
      IISMainHandler/handlers/response/LegacyUploadHandler.cs
  8. 23
      IISMainHandler/handlers/response/RedirectGetHandler.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<string, string> 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<int> allBoardsIds = from stringId in Config.instance.mainConnection.LoadIdsByConditions(TableSpec.instance, new EmptyCondition(), Diapasone.unlimited) select int.Parse(stringId);
private static Dictionary<string, int> legacyName2Id = new Dictionary<string,int>();
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<Thread> getThreads(Diapasone diapasone, SortSpec[] sortBy) {
return Thread.LoadByIds(
from stringId in Config.instance.mainConnection.LoadIdsByConditions(

@ -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()) {

@ -74,12 +74,14 @@
<Compile Include="handlers\response\ConversationHandler.cs" />
<Compile Include="handlers\response\ConversationsHandler.cs" />
<Compile Include="handlers\response\CreateThreadHandler.cs" />
<Compile Include="handlers\response\LegacyPHPHandler.cs" />
<Compile Include="handlers\response\LegacyUploadHandler.cs" />
<Compile Include="handlers\response\LoginHandler.cs" />
<Compile Include="handlers\response\MigrateAccountHandler.cs" />
<Compile Include="handlers\response\PMReplyHandler.cs" />
<Compile Include="handlers\response\PMReplyToPostHandler.cs" />
<Compile Include="handlers\response\PMSendHandler.cs" />
<Compile Include="handlers\response\RedirectGetHandler.cs" />
<Compile Include="handlers\response\ReplyHandler.cs" />
<Compile Include="handlers\response\SettingsHandler.cs" />
<Compile Include="handlers\response\UploadHandler.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]);
}
}
}
}

@ -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 + "/";
}
}

@ -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));
}
}
}
Loading…
Cancel
Save