OSDN Git Service

・板一覧更新の処理メッセージを追加
[gikonavigoeson/gikonavi.git] / BoardGroup.pas
index d2ca8f4..322ceed 100644 (file)
@@ -41,6 +41,8 @@ type
                function Find(key: string): TCategory;
                function FindBBSID(const BBSID: string): TBoard;
                function FindBoardFromTitle(const Title: string): TBoard;
+               function FindBoardFromTitleAndCategory(const CategoryTitle: string; const BoardTitle: string): TBoard;
+        function FindBoardFromURLAndCategory(const CategoryTitle: string; const BoardURL: string): TBoard;
                function FindBoardFromURL(const inURL: string): TBoard;
                function FindThreadFromURL(const inURL : string ) : TThreadItem;
                function FindThreadItem(const BBSID, FileName: string): TThreadItem;
@@ -84,6 +86,7 @@ type
                function FindBBSID(const BBSID: string): TBoard;
                function FindBoardFromTitle(const Title: string): TBoard;
                function FindBoardFromURL(const inURL: string): TBoard;
+        function FindBoardFromURL2(const inURL: string): TBoard;
                function FindThreadFromURL(const inURL : string ) : TThreadItem;
                function IsMidoku: Boolean;
 
@@ -279,7 +282,7 @@ type
        public
                constructor Create(const inPlugIn : TBoardPlugIn; const inBoard : TBoard; inURL : string ); overload;
                constructor Create(const inPlugIn : TBoardPlugIn; const inBoard : TBoard;
-                                        inURL : string; inExist: Boolean; const inFilename: string ); overload;
+                                        const inURL : string; inExist: Boolean; const inFilename: string ); overload;
 
                destructor Destroy; override;
 
@@ -287,6 +290,11 @@ type
                function GetDatgzURL: string;
 //             function GetOldDatgzURL: string;
                function GetOfflawCgiURL(const SessionID: string): string;
+//////////////// 2013/10/13 ShiroKuma\91Î\89\9e zako Start ///////////////////////////
+        function GetOfflaw2SoURL: string;
+//////////////// 2013/10/13 ShiroKuma\91Î\89\9e zako End /////////////////////////////
+        function GetRokkaURL(const SessionID: string): string;  // Rokka\91Î\89\9e  
+               function GetExternalBoardKakoDatURL: string; // \8aO\95\94\94Â\89ß\8b\8e\83\8d\83OURL\8eæ\93¾
                function GetSendURL: string;
                procedure DeleteLogFile;
                function GetThreadFileName: string;
@@ -334,6 +342,23 @@ type
         property       BoardPlugIn     : TBoardPlugIn  read FBoardPlugIn write FBoardPlugIn;
     end;
 
+    // \93Á\8eê\97p\93r\97pTBoard
+    TSpecialBoard = class(TBoard)
+    public
+        function Add(item: TThreadItem): integer; overload;
+        procedure Clear; overload;
+    end;
+
+    // \83X\83\8c\83b\83h\96¼NG\83\8f\81[\83h\83\8a\83X\83g
+       TThreadNgList = class(TStringList)
+    private
+        FFilePath: String;
+    public
+               constructor Create;
+        procedure Load;
+        procedure Save;
+        function IsNG(const Title: String): Boolean;
+    end;
 
        function        BBSsFindBoardFromBBSID( inBBSID : string ) : TBoard;
        function        BBSsFindBoardFromURL( inURL : string ) : TBoard;
@@ -341,9 +366,14 @@ type
        function        BBSsFindThreadFromURL(const inURL : string ) : TThreadItem;
        function        ConvertDateTimeString( inDateTimeString : string) : TDateTime;
 
+    procedure    DestorySpecialBBS( inBBS : TBBS );
+
 var
        BBSs            : array of TBBS;
     BoardGroups : array of TBoardGroup;
+    SpecialBBS  : TBBS;
+    SpecialBoard: TSpecialBoard;
+    ThreadNgList: TThreadNgList;
 
 implementation
 
@@ -362,6 +392,8 @@ const
        SETTINGTXT_FILENAME:            string = 'SETTING.TXT';
     HEADTXT_FILENAME:          string = 'head.html';
        //DEFAULT_LIST_COUNT:           Integer = 100;
+       THREAD_NG_FILE: String = 'ThreadNg.txt';
+    
 
 //! \83\8d\83O\82ð\8e\9d\82Á\82Ä\82¢\82é\82È\82ç\90^\82ð\95Ô\82·
 function CountLog(Item: TThreadItem): Boolean;
@@ -529,6 +561,28 @@ begin
        end;
 
 end;
+{!
+\brief \93Á\8eê\97p\93rBBS\8dí\8f\9c
+\param bbs \8dí\8f\9c\82·\82é\93Á\8eê\97p\93rBBS
+}
+procedure DestorySpecialBBS( inBBS : TBBS );
+var
+    sCategory : TCategory;
+    sBoard    : TSpecialBoard;
+begin
+    if inBBS <> nil then begin
+        sCategory := inBBS.Items[0];
+        if sCategory <> nil then begin
+            sBoard := TSpecialBoard(sCategory.Items[0]);
+            if sBoard <> nil then begin
+                sBoard.Modified := False;
+                sBoard.Clear;
+                FreeAndNil(sBoard);
+            end;
+        end;
+        FreeAndNil(inBBS);
+    end;
+end;
 
 (*************************************************************************
  *\8b@\94\\96¼\81FTBBS\83R\83\93\83X\83g\83\89\83N\83^
@@ -625,6 +679,44 @@ begin
 end;
 
 //*************************************************************************
+// \83J\83e\83S\83\8a\96¼\82Æ\94Â\96¼\82Ì\88ê\92v\82·\82é\94Â\82ð\92T\82·
+//*************************************************************************)
+function TBBS.FindBoardFromTitleAndCategory(const CategoryTitle: string; const BoardTitle: string): TBoard;
+var
+       i: Integer;
+begin
+       if not IsBoardFileRead then
+       GikoSys.ReadBoardFile( Self );
+       for i := Count - 1 downto 0 do begin
+        if AnsiCompareStr(Items[ i ].Title, CategoryTitle) = 0 then begin
+            Result := Items[ i ].FindBoardFromTitle(BoardTitle);
+            if Result <> nil then
+                Exit;
+       end;
+       end;
+       Result := nil;
+end;
+
+//*************************************************************************
+// \83J\83e\83S\83\8a\96¼\82Æ\94ÂURL\82Ì\88ê\92v\82·\82é\94Â\82ð\92T\82·
+//*************************************************************************)
+function TBBS.FindBoardFromURLAndCategory(const CategoryTitle: string; const BoardURL: string): TBoard;
+var
+       i: Integer;
+begin
+       if not IsBoardFileRead then
+       GikoSys.ReadBoardFile( Self );
+       for i := Count - 1 downto 0 do begin
+        if AnsiCompareStr(Items[ i ].Title, CategoryTitle) = 0 then begin
+            Result := Items[ i ].FindBoardFromURL2(BoardURL);
+            if Result <> nil then
+                Exit;
+       end;
+       end;
+       Result := nil;
+end;
+
+//*************************************************************************
 // URL \82ð\8eó\82¯\95t\82¯\82é\94Â\82ð\92T\82·
 //*************************************************************************)
 function TBBS.FindBoardFromURL(const inURL: string): TBoard;
@@ -800,6 +892,40 @@ begin
 end;
 
 //*************************************************************************
+// \83z\83X\83g\96¼\82ð\8f\9c\82¢\82½URL\82Å\94Â\82ð\92T\82·\81i2ch.net/bbspink.com\8cÀ\92è\81j
+//*************************************************************************)
+function TCategory.FindBoardFromURL2(const inURL: string): TBoard;
+const
+       HOST_NAME: array[0..1] of string = ('.2ch.net', '.bbspink.com');
+var
+       i       : Integer;
+    idx: Integer;
+    chkURL: String;
+    chkLen: Integer;
+begin
+    Result := nil;
+    for i := 0 to Length(HOST_NAME) - 1 do begin
+        idx := Pos(HOST_NAME[i], inURL);
+        if (idx > 0) then begin
+            chkLen := Length(inURL) - idx + 1;
+            chkURL := Copy(inURL, idx, chkLen);
+            Break;
+        end;
+    end;
+    if (chkLen > 0) then begin
+        for i := 0 to Count - 1 do begin
+            idx := Pos(ChkURL, Strings[i]);
+            if (idx > 0) then begin
+                if (Length(Strings[i]) - idx + 1 = chkLen) then begin
+                    Result := TBoard( Objects[ i ] );
+                    Break;
+                end;
+            end;
+        end;
+    end;
+end;
+
+//*************************************************************************
 // URL \82ð\8eó\82¯\95t\82¯\82é\83X\83\8c\83b\83h\82ð\92T\82·
 //*************************************************************************)
 function TCategory.FindThreadFromURL(const inURL: string): TThreadItem;
@@ -1542,7 +1668,7 @@ end;
 constructor TThreadItem.Create(
        const inPlugIn : TBoardPlugIn;
        const inBoard : TBoard;
-       inURL : string;
+       const inURL : string;
        inExist: Boolean;
        const inFilename: string
 );
@@ -1557,7 +1683,7 @@ begin
                // dat \82Ì\95Û\91\83p\83X\82ð\90Ý\92è
                FileName        := inFilename;
                IsLogFile       := inExist;
-               URL                             := GikoSys.Get2chBrowsableThreadURL( inURL );
+        URL                            := inURL;
        end else begin
                // \83v\83\89\83O\83C\83\93\82É TThreadItem \82ª\8dì\90¬\82³\82ê\82½\82±\82Æ\82ð\93`\82¦\82é
                inPlugIn.CreateThreadItem( DWORD( Self ) );
@@ -1656,6 +1782,66 @@ begin
        end;
 end;
 
+function TThreadItem.GetOfflaw2SoURL: string;
+begin
+    Result := GikoSys.UrlToServer(ParentBoard.URL)
+                    + 'test/offlaw2.so?shiro=kuma&bbs=' + ParentBoard.BBSID
+                    + '&key=' + ChangeFileExt(FileName, '');
+end;
+
+function TThreadItem.GetRokkaURL(const SessionID: string): string;
+var
+    Domain: string;
+    Host: string;
+    Idx: Integer;
+    HostPos: Integer;
+begin
+       if FDownloadHost = '' then begin
+        Idx := AnsiPos('.2ch.net/', ParentBoard.URL);
+        if (Idx > 0) then begin
+            Domain := '2ch.net';
+        end else begin
+            Idx := AnsiPos('.bbspink.com/', ParentBoard.URL);
+            if (Idx > 0) then
+                Domain := 'bbspink.com';
+        end;
+        if (Idx > 0) then begin
+            HostPos := AnsiPos('://', ParentBoard.URL) + 3;
+            Host := Copy(ParentBoard.URL, HostPos, Idx - HostPos);
+        end;
+    end else begin
+        Idx := AnsiPos('.2ch.net', FDownloadHost);
+        if (Idx > 0) then begin
+            Domain := '2ch.net';
+        end else begin
+            Idx := AnsiPos('.bbspink.com', FDownloadHost);
+            if (Idx > 0) then
+                Domain := 'bbspink.com';
+        end;
+        if (Idx > 0) then begin
+            Host := Copy(FDownloadHost, 1, Idx - 1);
+        end;
+    end;
+
+    if ((Domain = '') or (Host = '')) then
+        Result := ''
+    else
+        Result := 'http://rokka.' + Domain + '/' + Host + '/'
+                + ParentBoard.BBSID + '/' + ChangeFileExt(FileName, '')
+                + '/?sid=' + SessionID;
+end;
+
+// \8aO\95\94\94Â\89ß\8b\8e\83\8d\83OURL\8eæ\93¾
+function TThreadItem.GetExternalBoardKakoDatURL: string;
+var
+       DatNo: string;
+begin
+       DatNo := ChangeFileExt(FileName, '');
+       //http://xxx.vip2ch.com/xxx/kako/1234/12345/1234567890.dat
+       Result := Format('%s%s/%.4s/%.5s/%s.dat', [ParentBoard.URL, 'kako', DatNo, DatNo, DatNo]);
+end;
+// \8aO\95\94\94Â\89ß\8b\8e\83\8d\83OURL\8eæ\93¾
+
 function TThreadItem.GetSendURL: string;
 begin
        Result := GikoSys.UrlToServer(ParentBoard.URL)
@@ -1777,9 +1963,6 @@ begin
 end;
 
 function TThreadItem.GetCreateDate: TDateTime;
-var
-       unixtime: Int64;
-    tmp: string;
 begin
        // \83t\83@\83C\83\8b\96¼\82©\82ç\83X\83\8c\8dì\90¬\93ú\8e\9e\82ð\8b\81\82ß\82é
        try
@@ -1833,6 +2016,66 @@ begin
 
 end;
 
+function TSpecialBoard.Add(item: TThreadItem): integer;
+begin
+    Result := inherited AddObject(Item.URL, Item);
+end;
+
+procedure TSpecialBoard.Clear;
+var
+       i: integer;
+begin
+    for i := Count - 1 downto 0 do
+               DeleteList(i);
+    Capacity := 0;
+end;
+
+///////////////
+constructor TThreadNgList.Create;
+begin
+       inherited Create;
+
+       FFilePath := GikoSys.GetNGWordsDir;
+       if not DirectoryExists(FFilePath) then
+               ForceDirectories(FFilePath);
+       if (FFilePath[Length(FFilePath)] <> '\') then
+               FFilePath := FFilePath + '\';
+       FFilePath := FFilePath + THREAD_NG_FILE;
+       Load;
+end;
+
+procedure TThreadNgList.Load;
+begin
+       if (FileExists(FFilePath)) then begin
+               try
+                       LoadFromFile(FFilePath);
+               finally
+               end;
+       end;
+end;
+
+procedure TThreadNgList.Save;
+begin
+       try
+               SaveToFile(FFilePath);
+       finally
+       end;
+end;
+
+function TThreadNgList.IsNG(const Title: String): Boolean;
+var
+    Cnt: Integer;
+    MaxCnt: Integer;
+begin
+    MaxCnt := Count - 1;
+    for Cnt := 0 to MaxCnt do begin
+        if (Pos(Strings[Cnt], Title) > 0) then begin
+            Result := True;
+            Exit;
+        end;
+    end;
+    Result := False;
+end;
 
 end.