OSDN Git Service

スレッドの最後に関連キーワードのリンクを加えるオプションを追加
[gikonavigoeson/gikonavi.git] / HTMLCreate.pas
1 unit HTMLCreate;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, {Graphics,} Controls, {Forms,}
7         ComCtrls, IniFiles, ShellAPI, Math, GikoSystem,
8 {$IF Defined(DELPRO) }
9         SHDocVw,
10         MSHTML,
11 {$ELSE}
12         SHDocVw_TLB,
13         MSHTML_TLB,
14 {$IFEND}
15         {HttpApp,} YofUtils, {URLMon,} BoardGroup, {gzip,} {Dolib,}
16         {bmRegExp,} AbonUnit,   MojuUtils, Setting,
17         ExternalBoardManager, ExternalBoardPlugInMain{,}
18         {Sort,} ,GikoBayesian, HintWindow, ActiveX;
19
20 type
21
22         PResLinkRec = ^TResLinkRec;
23         TResLinkRec = record
24                 FBbs: string;
25                 FKey : string;
26         end;
27
28         TBufferedWebBrowser = class(TStringList)
29         private
30                 //! \8f\91\82«\8d\9e\82Þ\83u\83\89\83E\83U
31                 FBrowser: TWebBrowser;
32                 //! \89½\8ds\82Ü\82Å\82½\82ß\82é\82©\82Ì\83T\83C\83Y
33                 FBuffSize: Integer;
34                 //! \83u\83\89\83E\83U\82ÌIHTMLDocument2\83C\83\93\83^\83t\83F\81[\83X\82ð\95Û\8e\9d\82·\82é open\82©\82çclose\82Ì\8aÔ\82Å
35                 FBrowserDoc: Variant;
36         public
37                 constructor Create(Browser: TWebBrowser; BuffSize: Integer);
38                 destructor Destory;
39                 procedure Open;
40                 procedure Close;
41                 procedure Flush;
42                 function Add(const S: string): Integer; override;
43         end;
44         THTMLCreate = class(TObject)
45         private
46                 { Private \90é\8c¾ }
47                 anchorLen                       : Integer;
48                 pURLCHARs,pURLCHARe : PChar;
49                 pANCHORs, pANCHORe  : PChar;
50                 pCTAGLs,  pCTAGLe   : PChar;
51                 pCTAGUs,  pCTAGUe   : PChar;
52                 pREF_MARKSs : array[0..9] of PChar;
53                 pREF_MARKSe : array[0..9] of PChar;
54                 constructor Create;
55
56                 function AddBeProfileLink(AID : string; ANum: Integer):string ;
57                 procedure CreateUsePluginHTML(html:TBufferedWebBrowser; ThreadItem: TThreadItem; var sTitle: string);
58                 procedure CreateUseSKINHTML(html:TBufferedWebBrowser; ThreadItem: TThreadItem; ReadList: TStringList);
59                 procedure CreateUseCSSHTML(html:TBufferedWebBrowser; ThreadItem: TThreadItem; ReadList: TStringList; sTitle: string );
60                 procedure CreateDefaultHTML (html:TBufferedWebBrowser; ThreadItem: TThreadItem; ReadList: TStringList; sTitle: string );
61                 procedure ConvertResAnchor(PRes: PResRec);
62                 procedure separateNumber(var st: String; var et: String; const Text, Separator: String);
63                 function checkComma(const s : String; var j : Integer) : boolean;
64                 function addResAnchor(PAddRes: PResRec; PResLink : PResLinkRec; dat : boolean;
65                  var s : String; j : Integer; const No: String) : string;
66         function appendResAnchor(PAddRes: PResRec; PResLink : PResLinkRec;
67              dat : boolean;     var s : String) : string;
68         function getNumberString(const str: String;var index :Integer; var dbCharlen: Boolean;
69              sLen :Integer): String;
70         function isOutsideRange(item: TThreadItem; index: Integer ): Boolean;
71         function getKeywordLink(item: TThreadItem): String;
72         public
73                 { Public \90é\8c¾ }
74                 procedure AddAnchorTag(PRes: PResRec);
75                 function LoadFromSkin(fileName: string; ThreadItem: TThreadItem; SizeByte: Integer): string;
76                 function SkinedRes(const skin: string; PRes: PResRec; const No: string): string;
77                 procedure ConvRes( PRes : PResRec; PResLink : PResLinkRec; DatToHTML: boolean = false); overload;
78                 procedure CreateHTML2(Browser: TWebBrowser; ThreadItem: TThreadItem; var sTitle: string);
79                 procedure CreateHTML3(var html: TStringList; ThreadItem: TThreadItem; var sTitle: string);
80                 //\83\8c\83X\83|\83b\83v\83A\83b\83v\82Ì\8dì\90¬
81                 procedure SetResPopupText(Hint :TResPopup; threadItem: TThreadItem; StNum, ToNum: Integer; Title, First: Boolean);
82                 //\83\8a\83\93\83N\82Ì\95\8e\9a\97ñ\82©\82ç\83\8c\83X\83|\83b\83v\83A\83b\83v\97p\82ÌURL\82É\95Ï\8a·\82·\82é
83                 class function GetRespopupURL(AText, AThreadURL : string): string;
84                 //\8ew\92è\82µ\82½\83p\83X\82É\83X\83L\83\93\82à\82µ\82­\82ÍCSS\82Ì\83t\83@\83C\83\8b\82Ì\83R\83s\81[\82ð\8dì\82é
85                 class procedure SkinorCSSFilesCopy(path: string);
86                 //dat\82P\8ds\82ð\83\8c\83X\82É\95ª\89ð\82·\82é
87                 class procedure DivideStrLine(Line: string; PRes: PResRec);
88         //HTML\82©\82ç\83\8a\83\93\83N\83^\83O\82ð\8dí\8f\9c\82·\82é
89                 class function DeleteLink(const s: string): string;
90         //HTML\82Ì\83{\83f\83B\82É\8b\96\82³\82ê\82é\95\8e\9a\97ñ\82É\92u\8a·\82·\82é
91         class function RepHtml(const s: string): string;
92         //\83\8c\83X\83G\83f\83B\83^\82Ì\83v\83\8c\83r\83\85\81[\97pHTML\82ð\8dì\90¬\82·\82é
93         class function CreatePreviewHTML(const Title: string; const No: string;
94                 const Mail: string; const Namae: string; const Body: string ) : string;
95         end;
96
97 var
98         HTMLCreater: THTMLCreate;
99
100 implementation
101
102 uses
103     Trip, NGWordUnit;
104
105 const
106         URL_CHAR: string = '0123456789'
107                                                                          + 'abcdefghijklmnopqrstuvwxyz'
108                                                                          + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
109                                                                          + '#$%&()*+,-./:;=?@[]^_`{|}~!''\';
110         ANCHOR_REF      = 'href=';
111         CLOSE_TAGAL = '</a>';
112         CLOSE_TAGAU = '</A>';
113         RES_REF                 = '&gt;&gt;';
114         REF_MARK: array[0..9] of string = ('http://', 'ttp://', 'tp://',
115                                                                          'ms-help://','p://', 'https://',
116                                                                          'www.', 'ftp://','news://','rtsp://');
117
118 constructor THTMLCreate.Create;
119 var
120         j : Integer;
121 begin
122         // + 3 \82Í 'href="' ('"'\82Â\82«)\82È\82Ç\82Ì\83o\83\8a\83G\81[\83V\83\87\83\93\82É\97]\97T\82ð\8e\9d\82½\82¹\82é\82½\82ß
123         anchorLen := Length( ANCHOR_REF ) + 3;
124         pANCHORs  := PChar(ANCHOR_REF);
125         pANCHORe  := pANCHORs + Length(ANCHOR_REF);
126         pURLCHARs := PChar(URL_CHAR);
127         pURLCHARe := pURLCHARs + Length(URL_CHAR);
128         pCTAGLs   := PChar(CLOSE_TAGAL);
129         pCTAGLe   := pCTAGLs + 4;
130         pCTAGUs   := PChar(CLOSE_TAGAU);
131         pCTAGUe   := pCTAGUs + 4;
132         for j := 0 to 9 do begin
133                 pREF_MARKSs[j] := PChar(REF_MARK[j]);
134                 pREF_MARKSe[j] := pREF_MARKSs[j] + Length(REF_MARK[j]);
135         end;
136 end;
137 // \83X\83L\83\93\82ð\93Ç\82Ý\8d\9e\82Ý\81A\92l\82ð\92u\8a·\82·\82é
138 function THTMLCreate.LoadFromSkin(
139         fileName: string;
140         ThreadItem: TThreadItem;
141         SizeByte: Integer
142 ): string;
143 var
144         Skin: TStringList;
145 begin
146
147         Skin := TStringList.Create;
148         try
149                 if FileExists( fileName ) then begin
150                         Skin.LoadFromFile( fileName );
151
152                         // \82â\82è\82©\82½\82ª\8bê\82µ\82¢\82¯\82Ç\81A\83I\83v\83V\83\87\83\93\83_\83C\83A\83\8d\83O\82Ì\83v\83\8c\83r\83\85\81[\97p try
153                         try
154                                 if ThreadItem.ParentBoard <> nil then
155                                         if ThreadItem.ParentBoard.ParentCategory <> nil then
156                                                 CustomStringReplace( Skin, '<BBSNAME/>', ThreadItem.ParentBoard.ParentCategory.ParenTBBS.Title);
157                                         CustomStringReplace( Skin, '<THREADURL/>', ThreadItem.URL);
158                         except end;
159                         CustomStringReplace( Skin, '<BOARDNAME/>', ThreadItem.ParentBoard.Title);
160                         CustomStringReplace( Skin, '<BOARDURL/>', ThreadItem.ParentBoard.URL);
161                         CustomStringReplace( Skin, '<THREADNAME/>', ThreadItem.Title);
162                         CustomStringReplace( Skin, '<SKINPATH/>', GikoSys.Setting.CSSFileName);
163                         CustomStringReplace( Skin, '<GETRESCOUNT/>', IntToStr( ThreadItem.Count - ThreadItem.NewResCount ));
164                         CustomStringReplace( Skin, '<NEWRESCOUNT/>', IntToStr( ThreadItem.NewResCount ));
165                         CustomStringReplace( Skin, '<ALLRESCOUNT/>', IntToStr( ThreadItem.Count ));
166
167                         CustomStringReplace( Skin, '<NEWDATE/>',FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate));
168                         CustomStringReplace( Skin, '<SIZEKB/>', IntToStr( Floor( SizeByte / 1024 ) ));
169                         CustomStringReplace( Skin, '<SIZE/>', IntToStr( SizeByte ));
170
171                         //----- \82Æ\82è\82 \82¦\82¸\82©\82¿\82ã\81`\82µ\82á\8cÝ\8a·\97p\81B\83R\83\81\83\93\83g\83A\83E\83g\82µ\82Ä\82à\82æ\82µ
172                         // \82â\82è\82©\82½\82ª\8bê\82µ\82¢\82¯\82Ç\81A\83I\83v\83V\83\87\83\93\83_\83C\83A\83\8d\83O\82Ì\83v\83\8c\83r\83\85\81[\97p try
173                         if GikoSys.Setting.UseKatjushaType then begin
174                                 try
175                                         if ThreadItem.ParentBoard <> nil then
176                                                 if ThreadItem.ParentBoard.ParentCategory <> nil then
177                                                         CustomStringReplace( Skin, '&BBSNAME', ThreadItem.ParentBoard.ParentCategory.ParenTBBS.Title);
178                                                 CustomStringReplace( Skin, '&THREADURL', ThreadItem.URL);
179                                 except end;
180                                 CustomStringReplace( Skin, '&BOARDNAME', ThreadItem.ParentBoard.Title);
181                                 CustomStringReplace( Skin, '&BOARDURL', ThreadItem.ParentBoard.URL);
182                                 CustomStringReplace( Skin, '&THREADNAME', ThreadItem.Title);
183                                 CustomStringReplace( Skin, '&SKINPATH', GikoSys.Setting.CSSFileName);
184                                 CustomStringReplace( Skin, '&GETRESCOUNT', IntToStr( ThreadItem.NewReceive - 1 ));
185                                 CustomStringReplace( Skin, '&NEWRESCOUNT', IntToStr( ThreadItem.NewResCount ));
186                                 CustomStringReplace( Skin, '&ALLRESCOUNT', IntToStr( ThreadItem.AllResCount ));
187
188                                 CustomStringReplace( Skin, '&NEWDATE', FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate));
189                                 CustomStringReplace( Skin, '&SIZEKB', IntToStr( Floor( SizeByte / 1024 ) ));
190                                 CustomStringReplace( Skin, '&SIZE', IntToStr( SizeByte ));
191                         end
192                         //----- \82±\82±\82Ü\82Å
193                 end;
194                 Result := Skin.Text;
195         finally
196                 Skin.Free;
197         end;
198 end;
199
200 // \83\8c\83X\82Ì\92l\82ð\92u\8a·\82·\82é
201 function THTMLCreate.SkinedRes(
202         const skin: string;
203         PRes: PResRec;
204         const No: string
205 ): string;
206 const
207         FORMT_NAME = '<b>%s</b>';
208         FORMT_NUM  = '<a href="menu:%s" name="%s">%s</a>';
209         FORMT_MAILNAME  = '<a href="mailto:%s"><b>%s</b></a>';
210 var
211         spamminess      : Extended;
212 {$IFDEF SPAM_FILTER_ENABLED}
213         wordCount               : TWordCount;
214 {$ENDIF}
215 begin
216 {$IFDEF SPAM_FILTER_ENABLED}
217         wordCount := TWordCount.Create;
218         try
219                 spamminess := Floor( GikoSys.SpamParse(
220                         Res.FName + '<>' + Res.FMailTo + '<>' + Res.FBody, wordCount ) * 100 );
221 {$ELSE}
222         spamminess := 0;
223 {$ENDIF}
224                 Result := CustomStringReplace( skin, '<SPAMMINESS/>', FloatToStr( spamminess ) );
225                 Result := CustomStringReplace( Result, '<NONSPAMMINESS/>', FloatToStr( 100 - spamminess ) );
226                 Result := CustomStringReplace( Result, '<MAIL/>', PRes.FMailTo);
227                 Result := CustomStringReplace( Result, '<DATE/>', PRes.FDateTime);
228                 Result := CustomStringReplace( Result, '<PLAINNUMBER/>', No);
229                 Result := CustomStringReplace( Result, '<NAME/>',
230                         Format(FORMT_NAME, [PRes.FName]));
231                 Result := CustomStringReplace( Result, '<NUMBER/>',
232                         Format(FORMT_NUM, [No, No, No]));
233                 Result := CustomStringReplace( Result, '<MAILNAME/>',
234                         Format(FORMT_MAILNAME,[PRes.FMailTo, PRes.FName]));
235                 Result := CustomStringReplace( Result, '<MESSAGE/>', PRes.FBody);
236
237                 //----- \82©\82¿\82ã\81`\82µ\82á\8cÝ\8a·\97p\81B\83R\83\81\83\93\83g\83A\83E\83g\82µ\82Ä\82à\82æ\82µ
238                 if GikoSys.Setting.UseKatjushaType then begin
239                         Result := CustomStringReplace( Result, '&NUMBER',
240                                 '<a href="menu:' + No + '" name="' + No + '">' + No + '</a>');
241                         Result := CustomStringReplace( Result, '&PLAINNUMBER', No);
242                         Result := CustomStringReplace( Result, '&NAME', '<b>' + PRes.FName + '</b>');
243                         Result := CustomStringReplace( Result, '&MAILNAME',
244                                 '<a href="mailto:' + PRes.FMailTo + '"><b>' + PRes.FName + '</b></a>');
245                         Result := CustomStringReplace( Result, '&MAIL', PRes.FMailTo);
246                         Result := CustomStringReplace( Result, '&DATE', PRes.FDateTime);
247                         Result := CustomStringReplace( Result, '&MESSAGE', PRes.FBody);
248                         Result := CustomStringReplace( Result, '&SPAMMINESS', FloatToStr( spamminess ) );
249                         Result := CustomStringReplace( Result, '&NONSPAMMINESS', FloatToStr( 100 - spamminess ) );
250                 end;
251                 //----- \82±\82±\82Ü\82Å
252 {$IFDEF SPAM_FILTER_ENABLED}
253         finally
254                 wordCount.Free;
255         end;
256 {$ENDIF}
257
258 end;
259 (*************************************************************************
260  *http://\82Ì\95\8e\9a\97ñ\82ðanchor\83^\83O\95t\82«\82É\82·\82é\81B
261  *************************************************************************)
262 procedure THTMLCreate.AddAnchorTag(PRes: PResRec);
263 const
264         _HEAD : array[0..9] of String =
265                 ('', 'h', 'ht', '', 'htt', '', 'http://', '', '', '');
266 var
267         url: string;
268         href: string;
269         i, j, b: Integer;
270         tmp: Integer;
271         idx, idx2: Integer;
272         pos : PChar;
273         pp, pe : PChar;
274         s : String;
275         len : Integer;
276 begin
277         s := PRes.FBody;
278         PRes.FBody := '';
279
280         //while True do begin
281         repeat
282                 idx  := MaxInt;
283                 idx2 := MaxInt;
284                 pp := PChar(s);
285                 pe := pp + Length(s);
286
287                 for j := 0 to 9 do begin
288                         pos := AnsiStrPosEx(pp, pe, pREF_MARKSs[j], pREF_MARKSe[j]);
289                         if pos <> nil then begin
290                                 tmp := pos - pp + 1;
291                                 idx := Min(tmp, idx);
292                                 if idx = tmp then idx2 := j;   //\82Ç\82Ì\83}\81[\83N\82Å\88ø\82Á\82©\82©\82Á\82½\82©\82ð\95Û\91
293                         end;
294                 end;
295
296                 if idx = MaxInt then begin
297                         //\83\8a\83\93\83N\82ª\96³\82¢\82æ\81B
298                         len := Length(PRes.FBody);
299                         SetLength(PRes.FBody, Length(s) + len);
300                         Move(pp^, PRes.FBody[len + 1], Length(s));
301                 end else begin
302                         if (idx > anchorLen) and
303                                 (AnsiStrPosEx(pp + idx - 1 - anchorLen, pp + idx, pANCHORs, pANCHORe) <> nil) then begin
304                                 //\8aù\82É\83\8a\83\93\83N\83^\83O\82ª\82Â\82¢\82Ä\82¢\82é\82Á\82Û\82¢\82Æ\82«\82Í\83\80\83V
305                                 //</a></A>\82ð\92T\82·\81A\8f¬\95\8e\9a\82Å\8c©\82Â\82©\82ç\82È\82¯\82ê\82Î\91å\95\8e\9a\82Å\8c\9f\8dõ
306                                 pos := AnsiStrPosEx(pp + idx, pe, pCTAGLs, pCTAGLe);
307                                 if pos = nil then
308                                         pos := AnsiStrPosEx(pp + idx, pe, pCTAGUs, pCTAGUe);
309                                 if pos = nil then
310                                         b := Length(REF_MARK[idx2])
311                                 else
312                                         b := pos - (pp  + idx) + 1;
313
314                                 len := Length(PRes.FBody);
315                                 SetLength(PRes.FBody, len + idx + b );
316                                 Move(pp^, PRes.FBody[len + 1], idx + b);
317                                 Delete(s, 1, idx + b);
318                         end else begin
319                                 pp      := PChar(s);
320                                 len     := Length(PRes.FBody);
321                                 SetLength(PRes.FBody, len + idx - 1);
322                                 Move(pp^, PRes.FBody[len + 1], idx - 1);
323
324                                 Delete(s, 1, idx - 1);
325                                 b := Length( s ) + 1;
326                                 pp      := PChar(s);
327                                 for i := 1 to b do begin
328                                         //\82P\83o\83C\83g\95\8e\9a\82ÅURL\82É\8eg\82¦\82È\82¢\95\8e\9a\82È\82ç
329                                         if (AnsiStrPosEx(pURLCHARs, pURLCHARe, pp, pp + 1) = nil) then begin
330                                                 url := Copy(s, 1, i - 1);
331                                                 Delete(s, 1, i - 1);
332                                                 href := Format('%s%s', [_HEAD[idx2], url]);
333                                                 PRes.FBody
334                                                         := Format('%s<a href="%s" target="_blank">%s</a>', [PRes.FBody, href, url]);
335                                                 Break;
336                                         end;
337                                         //\88ê\95\8e\9a\90i\82ß\82é\81B
338                                         Inc(pp);
339                                 end;
340                         end;
341                 end;
342         until idx = MaxInt;
343 end;
344
345 //\88ø\90\94\81AAID\81F\91Î\8fÛ\82Æ\82È\82é\93ú\95tID\95\8e\9a\97ñ\81AANum:\83\8c\83X\94Ô AURL\81F\82»\82Ì\83X\83\8c\83b\83h\82ÌURL
346 function THTMLCreate.AddBeProfileLink(AID : string; ANum: Integer):string ;
347 const
348         BE_MARK : string = 'BE:';
349 var
350         p : integer;
351         BNum, BMark : string;
352 begin
353         p := AnsiPos(BE_MARK, AnsiUpperCase(AID));
354         if p > 0 then begin
355                 BNum := Copy(AID, p, Length(AID));
356                 AID := Copy(AID, 1, p - 1);
357                 p := AnsiPos('-', BNum);
358                 if p > 0 then begin
359                         BMark := '?' + Trim(Copy(BNum, p + 1, Length(BNum)));
360                         BNum := Copy(BNum, 1, p - 1);
361                 end;
362                 BNum := Trim(BNum);
363                 Result := AID + ' <a href="'  + BNum + '/' + IntToStr(ANum)
364                         + '" target=_blank>' + BMark + '</a>';
365         end else
366                 Result := AID;
367 end;
368 //! \83\8c\83X\83A\83\93\83J\81[\82Ì\83\8c\83X\94Ô\8d\86\82ð\95ª\8a\84\82·\82é
369 // Text = '1-9' -> st =  '1'; et = '9'
370 // Text = '10'  -> st = '10'; et = '10'
371 procedure THTMLCreate.separateNumber(var st: String; var et: String; const Text:String; const Separator: String);
372 var
373         p : Integer;
374 begin
375         p := Pos(Separator,Text);
376         if (p > 0 ) then begin
377                 st := Copy(Text, 1, p - 1);
378                 et := Copy(Text, p + Length(Separator), Length(Text));
379         end else begin
380                 st := Text;
381                 et := Text;
382         end;
383 end;
384 //! \83\8c\83X\83A\83\93\83J\81[\82ª\8ew\82µ\82Ä\82¢\82é\83\8c\83X\94Ô\8d\86\82Ì\95\8e\9a\97ñ\82ð\8eæ\93¾\82·\82é
385 function THTMLCreate.getNumberString(
386     const str: String;
387     var index :Integer; var dbCharlen: Boolean; sLen :Integer)
388 : String;
389 const
390         SN      = '0123456789';
391 var
392     ch : String;
393     sw : Boolean;
394 begin
395     Result := '';
396     sw := False;
397     while (index <= sLen) do begin
398         if (ByteType(str, index) = mbSingleByte) then begin
399             //1byte\95\8e\9a
400             ch := str[index];
401             Inc(index);
402             dbCharlen := false;
403         end else begin
404             //2byte\95\8e\9a
405             ch := ZenToHan(Copy(str, index, 2));
406             Inc(index, 2);
407             dbCharlen := true;
408         end;
409
410         if System.Pos(ch, SN) > 0 then begin
411             Result := Result + ch;
412         end else if (ch = '-') then begin
413             if sw then break;
414             if Result = '' then break;
415             Result := Result + ch;
416             sw := true;
417         end else begin
418             break;
419         end;
420     end;
421 end;
422
423 procedure THTMLCreate.ConvRes( PRes : PResRec; PResLink : PResLinkRec; DatToHTML: boolean = false);
424 const
425         GT      = '&gt;';
426         //\8c\9f\8dõ\91Î\8fÛ\82Ì\95\8e\9a\97ñ\8cS
427         TOKEN : array[0..5] of string = (GT+GT, GT, '\81\84\81\84', '\81\84', '<a ', '<A ');
428 var
429         i : integer;
430         s : string;
431         No: string;
432         pos, pmin : integer;
433         j : integer;
434         db : boolean;
435         rink : string;
436 begin
437         //s \82É\96{\95\82ð\91S\95\94\93ü\82ê\82é
438         s        :=     PRes.FBody;
439         //\8c\8b\89Ê\82ð\83N\83\8a\83A
440         PRes.FBody       :=     '';
441
442         //
443         while Length(s) > 2 do begin
444                 pmin := Length(s) + 1;
445                 i       := Length(token);
446                 for j := 0 to 5 do begin
447                         pos := AnsiPos(TOKEN[j], s);
448                         if pos <> 0 then begin
449                                 if pos < pmin then begin
450                                         //\82Ç\82ê\82Å\83q\83b\83g\82µ\82½\82©\95Û\91
451                                         i := j;
452                                         //\8dÅ\8f¬\92l\82ð\8dX\90V
453                                         pmin := pos;
454                                 end;
455                         end;
456                 end;
457
458                 //\83q\83b\83g\82µ\82½\95\8e\9a\97ñ\82Ì\88ê\82Â\8eè\91O\82Ü\82Å\8c\8b\89Ê\82É\83R\83s\81[
459                 PRes.FBody := PRes.FBody + Copy(s, 1, pmin - 1);
460                 Delete(s, 1, pmin - 1);
461
462                 if i = 6 then begin
463                         //\83q\83b\83g\82È\82µ
464                 end else if (i = 4) or (i = 5) then begin
465                         //'<a ' or '<A' \82Å\83q\83b\83g '</a>' or '</A>' \82Ü\82Å\83R\83s\81[
466                         pmin := AnsiPos('</a>' , s);
467                         pos := AnsiPos('</A>' , s);
468                         if (pmin <> 0) and (pos <> 0) then begin
469                                 if (pmin > pos) then begin
470                                         pmin := pos;
471                                 end;
472                         end else if (pos <> 0) then begin
473                                 pmin := pos;
474                         end;
475                         rink := Copy(s, 1, pmin + 3);
476                         PRes.FBody := PRes.FBody + rink;
477                         Delete(s, 1, pmin + 3);
478
479                         pmin := Length(rink);
480                         i       := Length(TOKEN);
481                         for j := 0 to 3 do begin
482                                 pos := AnsiPos(TOKEN[j], rink);
483                                 if pos <> 0 then begin
484                                         if pos < pmin then begin
485                                                 //\82Ç\82ê\82Å\83q\83b\83g\82µ\82½\82©\95Û\91
486                                                 i := j;
487                                                 //\8dÅ\8f¬\92l\82ð\8dX\90V
488                                                 pmin := pos;
489                                         end;
490                                 end;
491                         end;
492                         // \83\8c\83X\83A\83\93\83J\81[\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82ç,\82ª\91±\82­\8cÀ\82è\83A\83\93\83J\81[\82Æ\82µ\82Ä\88µ\82¤
493                         if i <= 3 then begin
494                 appendResAnchor(PRes, PResLink, DatToHTML, s );
495                         end;
496                 end else begin
497                         //\89½\82©\82µ\82ç\8c©\82Â\82©\82Á\82½\83p\83^\81[\83\93
498                         j := Length(TOKEN[i]) + 1;
499                         db := false;
500                 No := getNumberString(s, j, db, Length(s) );
501                         //\8fI\92[\82Ü\82Å\8ds\82Á\82Ä\82Ì\8fI\97¹\82©\83`\83F\83b\83N
502                         if j <= Length(s) then begin
503                                 if db then j := j - 2
504                                 else j := j - 1;
505                         end;
506                         addResAnchor(PRes, PResLink, DatToHTML, s, j, No);
507
508             // , \82ª\91±\82­\8cÀ\82è\83\8c\83X\83A\83\93\83J\81[\82Æ\82µ\82Ä\8f\88\97\9d\82·\82é
509             appendResAnchor(PRes, PResLink, DatToHTML, s );
510                 end;
511         end;
512         if Length(s) > 0 then begin
513                 PRes.FBody := PRes.FBody + s;
514         end;
515 end;
516 function THTMLCreate.checkComma(
517         const s : String;
518         var j : Integer
519 ) : boolean;
520 var
521         bType : TMbcsByteType;
522 begin
523         Result := false;
524         if (Length(s) > 0) then begin
525                 bType := ByteType(s, j);
526                 if ((bType = mbSingleByte) and (s[j] = ',') or
527                         ((bType = mbLeadByte) and (ZenToHan(Copy(s, j ,2)) = ','))) then begin
528                         Result := true;
529                         if (bType = mbSingleByte) then
530                                 Inc(j)
531                         else
532                                 Inc(j, 2);
533                 end;
534         end;
535 end;
536 function THTMLCreate.appendResAnchor(
537         PAddRes: PResRec; PResLink : PResLinkRec; dat : boolean;
538         var s : String) : string;
539 var
540     No{, ch, oc}: String;
541     len, j : Integer;
542     cm, {sw,} db : Boolean;
543
544 begin
545     No := '';
546     j := 1;
547     cm := checkComma(s, j);
548     len := Length(s);
549     while cm do begin
550         db := false;
551         No := getNumberString(s, j, db, len );
552
553         //\8fI\92[\82Ü\82Å\8ds\82Á\82Ä\82Ì\8fI\97¹\82©\83`\83F\83b\83N
554         if j <= len then begin
555             if db then j := j - 2
556             else j := j - 1;
557         end;
558         addResAnchor(PAddRes, PResLink, dat, s, j, No);
559         j := 1;
560         len := Length(s);
561         cm := checkComma(s, j);
562     end;
563 end;
564
565 function THTMLCreate.addResAnchor(
566         PAddRes: PResRec; PResLink : PResLinkRec; dat : boolean;
567         var s : String; j : Integer; const No: String) : string;
568 const
569         FORMAT_LINK = '<a href="../test/read.cgi?bbs=%s&key=%s&st=%s&to=%s&nofirst=true" target="_blank">';
570 var
571         st,et : string;
572 begin
573
574         //\89½\82à\90\94\8e\9a\82ª\8c©\82Â\82©\82ç\82È\82¢\82Æ\82«
575         if No = '' then begin
576                 PAddRes.FBody := PAddRes.FBody + Copy(s, 1, j - 1);
577         end else begin
578                 separateNumber(st, et, No, '-');
579
580                 if not dat then begin
581                         PAddRes.FBody := PAddRes.FBody +
582                                 Format(FORMAT_LINK, [PResLink.FBbs, PResLink.FKey, st, et]);
583                 end else begin
584                         PAddRes.FBody := PAddRes.FBody + Format('<a href="#%s">', [st]);
585                 end;
586                 PAddRes.FBody := PAddRes.FBody + Copy(s, 1, j - 1) + '</a>';
587         end;
588         Delete(s, 1, j - 1);
589 end;
590
591
592 procedure THTMLCreate.ConvertResAnchor(PRes: PResRec);
593 const
594         _HEAD : string = '<a href="../';
595         _TAIL : string = ' target="_blank">';
596         _ST: string = '&st=';
597         _TO: string = '&to=';
598         _STA: string = '&START=';
599         _END: string = '&END=';
600 var
601         i, j, k: Integer;
602         tmp: string;
603         res: string;
604 begin
605         res := PRes.FBody;
606         PRes.FBody := '';
607         i := AnsiPos(_HEAD, res);
608         while i <> 0 do begin
609                 PRes.FBody := PRes.FBody + Copy(res, 1, i -1);
610                 Delete(res, 1, i - 1);
611                 j := AnsiPos(_TAIL, res);
612                 if j = 0 then begin
613                         PRes.FBody := PRes.FBody + res;
614                         Exit;
615                 end;
616                 tmp := Copy(res, 1, j - 1);
617                 Delete(res, 1, j + 16);
618                 if (AnsiPos(_ST, tmp) <> 0) and (AnsiPos(_TO, tmp) <> 0) then begin
619                         Delete(tmp, 1, AnsiPos(_ST, tmp) + 3);
620                         Delete(tmp, AnsiPos(_TO, tmp), Length(tmp));
621                         PRes.FBody := PRes.FBody + '<a href="#' + tmp + '">';
622                 end else if (AnsiPos(_STA, tmp) <> 0) and (AnsiPos(_END, tmp) <> 0) then begin
623                         Delete(tmp, 1, AnsiPos(_STA, tmp) + 6);
624                         Delete(tmp, AnsiPos(_END, tmp), Length(tmp));
625                         PRes.FBody := PRes.FBody + '<a href="#' + tmp + '">';
626                 end else begin
627                         k := LastDelimiter('/', tmp);
628                         Delete(tmp, 1, k);
629                         if AnsiPos('-', tmp) < AnsiPos('"', tmp) then
630                                 Delete(tmp, AnsiPos('-', tmp), Length(tmp))
631                         else
632                                 Delete(tmp, AnsiPos('"', tmp), Length(tmp));
633
634                         PRes.FBody := PRes.FBody + '<a href="#' + tmp + '">';
635                 end;
636                 i := AnsiPos(_HEAD, res);
637         end;
638         PRes.FBody := PRes.FBody + res;
639
640 end;
641 //Plugin\82ð\97\98\97p\82·\82éBoard\82Ì\83X\83\8c\83b\83h\82ÌHTML\82ð\8dì\90¬\82µ\82Ädoc\82É\8f\91\82«\8d\9e\82Þ
642 procedure THTMLCreate.CreateUsePluginHTML(html:TBufferedWebBrowser; ThreadItem: TThreadItem; var sTitle: string);
643 var
644         i: integer;
645         NewReceiveNo: Integer;
646         boardPlugIn : TBoardPlugIn;
647         UserOptionalStyle: string;
648 begin
649         //===== \83v\83\89\83O\83C\83\93\82É\82æ\82é\95\\8e¦
650         boardPlugIn             := ThreadItem.ParentBoard.BoardPlugIn;
651         NewReceiveNo    := ThreadItem.NewReceive;
652         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
653         UserOptionalStyle := GikoSys.SetUserOptionalStyle;
654         html.add(boardPlugIn.GetHeader( DWORD( threadItem ),
655                 '<style type="text/css">body {' + UserOptionalStyle + '}</style>' ));
656         html.Add('<p id="idSearch"></p>');
657         html.Flush;
658         
659         for i := 0 to threadItem.Count - 1 do begin
660                 // 1 \82Í\95K\82¸\95\\8e¦
661                 if i <> 0 then begin
662                         // \95\\8e¦\94Í\88Í\82ð\8cÀ\92è
663             if (isOutsideRange(ThreadItem, i)) then begin
664                 Continue;
665             end;
666                 end;
667
668                 // \90V\92\85\83}\81[\83N
669                 if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
670                         try
671                                 if GikoSys.Setting.UseSkin then begin
672                                         if FileExists( GikoSys.GetSkinNewmarkFileName ) then
673                                                 html.Add( LoadFromSkin( GikoSys.GetSkinNewmarkFileName, ThreadItem, ThreadItem.Size ))
674                                         else
675                                                 html.Add( '<a name="new"></a>');
676                                 end else if GikoSys.Setting.UseCSS then begin
677                                         html.Add('<a name="new"></a><div class="new">\90V\92\85\83\8c\83X <span class="newdate">' + FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate) + '</span></div>');
678                                 end else begin
679                                         html.Add('</dl>');
680                                         html.Add('<a name="new"></a>');
681                                         html.Add('<table width="100%" bgcolor="#3333CC" cellpadding="0" cellspacing="1"><tr><td align="center" bgcolor="#6666FF" valign="middle"><font size="-1" color="#ffffff"><b>\90V\92\85\83\8c\83X ' + FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate) + '</b></font></td></tr></table>');
682                                         html.Add('<dl>');
683                                 end;
684                         except
685                                 html.Add( '<a name="new"></a>');
686                         end;
687                 end;
688
689                 // \83\8c\83X
690                 html.Add( boardPlugIn.GetRes( DWORD( threadItem ), i + 1 ));
691
692                 if ThreadItem.Kokomade = (i + 1) then begin
693                         // \82±\82±\82Ü\82Å\93Ç\82ñ\82¾
694                         try
695                                 if GikoSys.Setting.UseSkin then begin
696                                         if FileExists( GikoSys.GetSkinBookmarkFileName ) then
697                                                 html.Add( LoadFromSkin( GikoSys.GetSkinBookmarkFileName, ThreadItem, ThreadItem.Size ))
698                                         else
699                                                 html.Add( '<a name="koko"></a>');
700                                 end else if GikoSys.Setting.UseCSS then begin
701                                         html.Add('<a name="koko"></a><div class="koko">\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</div>');
702                                 end else begin
703                                         html.Add('</dl>');
704                                         html.Add('<a name="koko"></a><table width="100%" bgcolor="#55AA55" cellpadding="0" cellspacing="1"><tr><td align="center" bgcolor="#77CC77" valign="middle"><font size="-1" color="#ffffff"><b>\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</b></font></td></tr></table>');
705                                         html.Add('<dl>');
706                                 end;
707                         except
708                                 html.Add('<a name="koko"></a>');
709                         end;
710                 end;
711         end;
712
713
714         // \83X\83L\83\93(\83t\83b\83^)
715         html.Add( boardPlugIn.GetFooter( DWORD( threadItem ), '<a name="bottom"></a>' ));
716 end;
717
718
719 procedure THTMLCreate.CreateUseSKINHTML(html:TBufferedWebBrowser; ThreadItem: TThreadItem; ReadList: TStringList);
720 const
721         KOKO_TAG = '<a name="koko"></a>';
722         NEW_TAG = '<a name="new"></a>';
723 var
724         i: integer;
725         NewReceiveNo: Integer;
726         Res: TResRec;
727         UserOptionalStyle: string;
728         SkinHeader: string;
729         SkinNewRes: string;
730         SkinRes: string;
731         ThreadName : string;
732         ResLink :TResLinkRec;
733 begin
734         NewReceiveNo := ThreadItem.NewReceive;
735         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
736         UserOptionalStyle := GikoSys.SetUserOptionalStyle;
737         ThreadName := ChangeFileExt(ThreadItem.FileName, '');
738         ResLink.FBbs := ThreadItem.ParentBoard.BBSID;
739         ResLink.FKey := ThreadName;
740         // \83X\83L\83\93\82Ì\90Ý\92è
741         try
742                 SkinHeader := LoadFromSkin( GikoSys.GetSkinHeaderFileName, ThreadItem, ThreadItem.Size);
743                 if Length( UserOptionalStyle ) > 0 then
744                         SkinHeader := CustomStringReplace( SkinHeader, '</head>',
745                                 '<style type="text/css">body {' + UserOptionalStyle + '}</style></head>');
746                 html.Add( SkinHeader );
747         except
748         end;
749
750         SkinNewRes := LoadFromSkin( GikoSys.GetSkinNewResFileName, ThreadItem, ThreadItem.Size);
751         SkinRes := LoadFromSkin( GikoSys.GetSkinResFileName, ThreadItem, ThreadItem.Size );
752
753         html.Add('<p id="idSearch"></p>'#13#10'<a name="top"></a>');
754         html.Flush;
755
756         for i := 0 to ReadList.Count - 1 do begin
757                 // 1 \82Í\95K\82¸\95\\8e¦
758                 if i <> 0 then begin
759                         // \95\\8e¦\94Í\88Í\82ð\8cÀ\92è
760             if (isOutsideRange(ThreadItem, i)) then begin
761                 Continue;
762             end;
763                 end;
764
765                 // \90V\92\85\83}\81[\83N
766                 if (NewReceiveNo = i + 1) or ((NewReceiveNo = 0) and (i = 0)) then begin
767                         if FileExists( GikoSys.GetSkinNewmarkFileName ) then
768                                 html.Add( LoadFromSkin( GikoSys.GetSkinNewmarkFileName, ThreadItem, ThreadItem.Size ))
769                         else
770                                 html.Add( NEW_TAG );
771                 end;
772
773                 if (Trim(ReadList[i]) <> '') then begin
774                         DivideStrLine(ReadList[i], @Res);
775             if (NGWordList.IsNG(@Res) = -1) then begin
776                         AddAnchorTag(@Res);
777                         ConvRes(@Res, @ResLink);
778                         Res.FDateTime := AddBeProfileLink(Res.FDateTime, i + 1);
779
780                             if NewReceiveNo <= (i + 1) then
781                                     // \90V\92\85\83\8c\83X
782                                 html.Add(SkinedRes(SkinNewRes, @Res, IntToStr(i + 1)))
783                         else
784                                 // \92Ê\8fí\82Ì\83\8c\83X
785                                 html.Add(SkinedRes(SkinRes, @Res, IntToStr(i + 1)));
786             end else begin
787 {$IFDEF DEBUG}
788                 html.Add('<h4>\82 \82Ú\81`\82ñ</h4>');
789 {$ENDIF}
790             end;
791                 end;
792
793                 if ThreadItem.Kokomade = (i + 1) then begin
794                         // \82±\82±\82Ü\82Å\93Ç\82ñ\82¾
795                         if FileExists( GikoSys.GetSkinBookmarkFileName ) then
796                                 html.Add( LoadFromSkin( GikoSys.GetSkinBookmarkFileName, ThreadItem, ThreadItem.Size ))
797                         else
798                                 html.Add( KOKO_TAG );
799                 end;
800         end;
801     html.Add(getKeywordLink(ThreadItem));
802         html.Add('<a name="bottom"></a>');
803         // \83X\83L\83\93(\83t\83b\83^)
804         html.Add( LoadFromSkin( GikoSys.GetSkinFooterFileName, ThreadItem, ThreadItem.Size ) );
805 end;
806
807 procedure THTMLCreate.CreateUseCSSHTML(html:TBufferedWebBrowser; ThreadItem: TThreadItem; ReadList: TStringList; sTitle: string );
808 const
809         FORMAT_NOMAIL  = '<a name="%s"></a><div class="header"><span class="no"><a href="menu:%s">%s</a></span>'
810                                         + '<span class="name_label"> \96¼\91O\81F </span> <span class="name"><b>%s</b></span>'
811                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span> <span class="date">%s</span></div>'
812                                         + '<div class="mes">%s</div>';
813
814         FORMAT_SHOWMAIL = '<a name="%s"></a><div class="header"><span class="no"><a href="menu:%s">%s</a></span>'
815                                         + '<span class="name_label"> \96¼\91O\81F </span><a class="name_mail" href="mailto:%s">'
816                                         + '<b>%s</b></a><span class="mail"> [%s]</span><span class="date_label"> \93\8a\8de\93ú\81F</span>'
817                                         + '<span class="date"> %s</span></div><div class="mes">%s</div>';
818
819         FORMAT_NOSHOW = '<a name="%s"></a><div class="header"><span class="no"><a href="menu:%s">%s</a></span>'
820                                         + '<span class="name_label"> \96¼\91O\81F </span><a class="name_mail" href="mailto:%s">'
821                                         + '<b>%s</b></a><span class="date_label"> \93\8a\8de\93ú\81F</span><span class="date"> %s</span></div>'
822                                         + '<div class="mes">%s</div>';
823 var
824         i: integer;
825         No: string;
826         CSSFileName: string;
827         NewReceiveNo: Integer;
828         Res: TResRec;
829         UserOptionalStyle: string;
830         ThreadName :String;
831         ResLink :TResLinkRec;
832 begin
833         NewReceiveNo := ThreadItem.NewReceive;
834         ThreadName := ChangeFileExt(ThreadItem.FileName, '');
835         ResLink.FBbs := ThreadItem.ParentBoard.BBSID;
836         ResLink.FKey := ThreadName;
837         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
838         UserOptionalStyle := GikoSys.SetUserOptionalStyle;
839         CSSFileName := GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName;
840         if GikoSys.Setting.UseCSS and FileExists(CSSFileName) then begin
841                 //CSS\8eg\97p
842                 html.Add('<html><head>');
843                 html.Add('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
844                 html.Add('<title>' + sTitle + '</title>');
845                 html.Add('<link rel="stylesheet" href="'+CSSFileName+'" type="text/css">');
846                 if Length( UserOptionalStyle ) > 0 then
847                         html.Add('<style type="text/css">body {' + UserOptionalStyle + '}</style>');
848                 html.Add('</head>'#13#10'<body>');
849                 html.Add('<a name="top"></a>'#13#10'<p id="idSearch"></p>');
850                 html.Add('<div class="title">' + sTitle + '</div>');
851                 html.Flush;
852                 for i := 0 to ReadList.Count - 1 do begin
853                         // 1 \82Í\95K\82¸\95\\8e¦
854                         if i <> 0 then begin
855                         // \95\\8e¦\94Í\88Í\82ð\8cÀ\92è
856                 if (isOutsideRange(ThreadItem, i)) then begin
857                     Continue;
858                 end;
859                         end;
860
861                         if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
862                                 html.Add('<a name="new"></a><div class="new">\90V\92\85\83\8c\83X <span class="newdate">' + FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate) + '</span></div>');
863                         end;
864
865                         if (Trim(ReadList[i]) <> '') then begin
866                                 No := IntToStr(i + 1);
867                                 DivideStrLine(ReadList[i], @Res);
868                 if (NGWordList.IsNG(@Res) = -1) then begin
869                     AddAnchorTag(@Res);
870                     ConvRes(@Res, @ResLink);
871                     Res.FDateTime := AddBeProfileLink(Res.FDateTime, i + 1);
872                     if Res.FMailTo = '' then
873                         html.Add(Format(FORMAT_NOMAIL, [No, No, No, Res.FName, Res.FDateTime, Res.FBody]))
874                     else if GikoSys.Setting.ShowMail then
875                         html.Add(Format(FORMAT_SHOWMAIL, [No, No, No, Res.FMailTo, Res.FName, Res.FMailTo, Res.FDateTime, Res.FBody]))
876                     else
877                         html.Add(Format(FORMAT_NOSHOW, [No, No, No, Res.FMailTo, Res.FName, Res.FDateTime, Res.FBody]));
878                             end;
879             end else begin
880 {$IFDEF DEBUG}
881                 html.Add('<h4>\82 \82Ú\81`\82ñ</h4>');
882 {$ENDIF}
883             end;
884
885                         if ThreadItem.Kokomade = (i + 1) then begin
886                                 html.Add('<a name="koko"></a><div class="koko">\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</div>');
887                         end;
888
889                 end;
890         html.Add(getKeywordLink(ThreadItem));
891                 html.Add('<a name="bottom"></a>');
892                 html.Add('<a name="last"></a>');
893                 html.Add('</body></html>');
894         end;
895 end;
896
897 procedure THTMLCreate.CreateDefaultHTML (html:TBufferedWebBrowser; ThreadItem: TThreadItem; ReadList: TStringList; sTitle: string );
898 var
899         i: integer;
900         No: string;
901         NewReceiveNo: Integer;
902         Res: TResRec;
903         ThreadName: String;
904         ResLink : TResLinkRec;
905 begin
906         NewReceiveNo := ThreadItem.NewReceive;
907         ThreadName := ChangeFileExt(ThreadItem.FileName, '');
908         ResLink.FBbs := ThreadItem.ParentBoard.BBSID;
909         ResLink.FKey := ThreadName;
910         html.Add('<html><head>');
911         html.Add('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
912         html.Add('<title>' + sTitle + '</title></head>');
913         html.Add('<body TEXT="#000000" BGCOLOR="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">');
914         html.Add('<a name="top"></a>');
915         html.Add('<font size=+1 color="#FF0000">' + sTitle + '</font>');
916         html.Add('<dl>');
917         html.Add('<p id="idSearch"></p>');
918         html.Flush;
919         for i := 0 to ReadList.Count - 1 do begin
920                 // 1 \82Í\95K\82¸\95\\8e¦
921                 if i <> 0 then begin
922                         // \95\\8e¦\94Í\88Í\82ð\8cÀ\92è
923             if (isOutsideRange(ThreadItem, i)) then begin
924                 Continue;
925             end;
926                 end;
927
928                 if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
929                         html.Add('</dl>');
930                         html.Add('<a name="new"></a>');
931                         html.Add('<table width="100%" bgcolor="#3333CC" cellpadding="0" cellspacing="1"><tr><td align="center" bgcolor="#6666FF" valign="middle"><font size="-1" color="#ffffff"><b>\90V\92\85\83\8c\83X ' + FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate) + '</b></font></td></tr></table>');
932                         html.Add('<dl>');
933                 end;
934
935                 if (Trim(ReadList[i]) <> '') then begin
936                         No := IntToStr(i + 1);
937                         DivideStrLine(ReadList[i], @Res);
938
939                         AddAnchorTag(@Res);
940                         ConvRes(@Res, @ResLink);
941                         Res.FDateTime := AddBeProfileLink(Res.FDateTime, i + 1);
942                         if Res.FMailTo = '' then
943                                 html.Add('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<font color="forestgreen"><b> ' + Res.FName + ' </b></font> \93\8a\8de\93ú\81F <span class="date">' + Res.FDateTime+ '</span><br><dd>' + Res.Fbody + ' <br><br><br>'#13#10)
944                         else if GikoSys.Setting.ShowMail then
945                                 html.Add('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<a href="mailto:' + Res.FMailTo + '"><b> ' + Res.FName + ' </B></a> [' + Res.FMailTo + '] \93\8a\8de\93ú\81F <span class="date">' + Res.FDateTime+ '</span><br><dd>' + Res.Fbody + ' <br><br><br>'#13#10)
946                         else
947                                 html.Add('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<a href="mailto:' + Res.FMailTo + '"><b> ' + Res.FName + ' </B></a> \93\8a\8de\93ú\81F <span class="date">' + Res.FDateTime+ '</span><br><dd>' + Res.Fbody + ' <br><br><br>'#13#10);
948         end else begin
949 {$IFDEF DEBUG}
950                 html.Add('<h4>\82 \82Ú\81`\82ñ</h4>');
951 {$ENDIF}
952         end;
953
954                 if ThreadItem.Kokomade = (i + 1) then begin
955                         html.Add('</dl>');
956                         html.Add('<a name="koko"></a><table width="100%" bgcolor="#55AA55" cellpadding="0" cellspacing="1"><tr><td align="center" bgcolor="#77CC77" valign="middle"><font size="-1" color="#ffffff"><b>\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</b></font></td></tr></table>');
957                         html.Add('<dl>');
958                 end;
959         end;
960     html.Add(getKeywordLink(ThreadItem));
961         html.Add('</dl>'#13#10'<a name="bottom"></a>'#13#10'</body></html>');
962 end;
963
964 procedure THTMLCreate.CreateHTML2(Browser: TWebBrowser; ThreadItem: TThreadItem; var sTitle: string);
965 var
966         ReadList: TStringList;
967         CSSFileName: string;
968         FileName: string;
969         Res: TResRec;
970         body : TBufferedWebBrowser;
971 {$IFDEF DEBUG}
972         st, rt: Cardinal;
973 {$ENDIF}
974 begin
975 {$IFDEF DEBUG}
976         Writeln('Create HTML');
977         st := GetTickCount;
978 {$ENDIF}
979         if ThreadItem <> nil then begin
980                 body := TBufferedWebBrowser.Create(Browser, 100);
981                 try
982                         body.Open;
983                         if ThreadItem.ParentBoard.IsBoardPlugInAvailable then begin
984                                 CreateUsePluginHTML(body, ThreadItem, sTitle);
985                         end else begin
986                                 ShortDayNames[1] := '\93ú';               ShortDayNames[2] := '\8c\8e';
987                                 ShortDayNames[3] := '\89Î';               ShortDayNames[4] := '\90\85';
988                                 ShortDayNames[5] := '\96Ø';               ShortDayNames[6] := '\8bà';
989                                 ShortDayNames[7] := '\93y';
990
991                                 ReadList := TStringList.Create;
992                                 try
993                                         if ThreadItem.IsLogFile then begin
994                                                 ReadList.BeginUpdate;
995                                                 FileName := ThreadItem.GetThreadFileName;
996                                                 ReadList.LoadFromFile(FileName);
997                                                 ReadList.EndUpdate;
998                                                 GikoSys.FAbon.IndividualAbon(ReadList, ChangeFileExt(FileName,'.NG'));
999                                                 //GikoSys.FAbon.Execute(ReadList);              //       \82 \82Ú\81`\82ñ\82µ\82Ä
1000                                                 GikoSys.FSelectResFilter.Execute(ReadList); //\83\8c\83X\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\82·\82é
1001                                                 if ThreadItem.Title = '' then begin
1002                                                         DivideStrLine(ReadList[0], @Res);
1003                                                         sTitle := Res.FTitle;
1004                                                 end else
1005                                                         sTitle := ThreadItem.Title
1006                                         end else begin
1007                                                 sTitle := CustomStringReplace(ThreadItem.Title, '\81\97\81M', ',');
1008                                         end;
1009                                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1010                                         CSSFileName := GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName;
1011                                         if GikoSys.Setting.UseSkin then begin
1012                                                 CreateUseSKINHTML(body, ThreadItem, ReadList);
1013                                         end else if GikoSys.Setting.UseCSS and FileExists(CSSFileName) then begin
1014                                                 CreateUseCSSHTML(body, ThreadItem, ReadList, sTitle);
1015                                         end else begin
1016                                                 CreateDefaultHTML(body, ThreadItem, ReadList, sTitle);
1017                                         end;
1018                                 finally
1019                                         ReadList.Free;
1020                                 end;
1021                         end;
1022                 finally
1023                         body.Close;
1024                         body.Free;
1025                 end;
1026         end;
1027 {$IFDEF DEBUG}
1028         rt := GetTickCount - st;
1029         Writeln('Done.');
1030         Writeln(IntToStr(rt) + ' ms');
1031 {$ENDIF}
1032 end;
1033
1034 procedure THTMLCreate.CreateHTML3(var html: TStringList; ThreadItem: TThreadItem; var sTitle: string);
1035 var
1036         i: integer;
1037         No: string;
1038         //bufList : TStringList;
1039         ReadList: TStringList;
1040 //      SaveList: TStringList;
1041         CSSFileName: string;
1042         BBSID: string;
1043         FileName: string;
1044         Res: TResRec;
1045         boardPlugIn : TBoardPlugIn;
1046
1047         UserOptionalStyle: string;
1048         SkinHeader: string;
1049         SkinRes: string;
1050         tmp, tmp1: string;
1051         ThreadName: String;
1052         ResLink : TResLinkRec;
1053         function LoadSkin( fileName: string ): string;
1054         begin
1055                 Result := LoadFromSkin( fileName, ThreadItem, ThreadItem.Size );
1056         end;
1057         function ReplaceRes( skin: string ): string;
1058         begin
1059                 Result := SkinedRes( skin, @Res, No );
1060         end;
1061
1062 begin
1063         if ThreadItem <> nil then begin
1064                 CSSFileName := GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName;
1065                 ThreadName := ChangeFileExt(ThreadItem.FileName, '');
1066                 ResLink.FBbs := ThreadItem.ParentBoard.BBSID;
1067                 ResLink.FKey := ThreadName;
1068                 html.Clear;
1069                 html.BeginUpdate;
1070                 //if ThreadItem.IsBoardPlugInAvailable then begin
1071                 if ThreadItem.ParentBoard.IsBoardPlugInAvailable then begin
1072                         //===== \83v\83\89\83O\83C\83\93\82É\82æ\82é\95\\8e¦
1073                         //boardPlugIn           := ThreadItem.BoardPlugIn;
1074                         boardPlugIn             := ThreadItem.ParentBoard.BoardPlugIn;
1075                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1076                         UserOptionalStyle := GikoSys.SetUserOptionalStyle;
1077                         try
1078                                 // \95\8e\9a\83R\81[\83h\82Í\83v\83\89\83O\83C\83\93\82É\94C\82¹\82é
1079                                 // \83w\83b\83_
1080                                 tmp := boardPlugIn.GetHeader( DWORD( threadItem ),
1081                                         '<style type="text/css">body {' + UserOptionalStyle + '}</style>' );
1082                                 //\90â\91Î\8eQ\8fÆ\82©\82ç\91\8a\91Î\8eQ\8fÆ\82Ö
1083                                 if GikoSys.Setting.UseSkin then begin
1084                                         tmp1 := './' + GikoSys.Setting.CSSFileName;
1085                                         tmp1 := CustomStringReplace(tmp1, GikoSys.GetConfigDir, '');
1086                                         tmp1 := CustomStringReplace(tmp1, '\', '/');
1087                                         tmp := CustomStringReplace(tmp, ExtractFilePath(GikoSys.Setting.CSSFileName),  tmp1);
1088                                 end else if GikoSys.Setting.UseCSS then begin
1089                                         tmp1 := './' + CSSFileName;
1090                                         tmp1 := CustomStringReplace(tmp1, GikoSys.GetConfigDir, '');
1091                                         tmp1 := CustomStringReplace(tmp1, '\', '/');
1092                                         tmp := CustomStringReplace(tmp, CSSFileName,  tmp1);
1093                                 end;
1094                                 html.Append( tmp );
1095
1096                                 for i := 0 to threadItem.Count - 1 do begin
1097
1098                                         // \83\8c\83X
1099                                         Res.FBody := boardPlugIn.GetRes( DWORD( threadItem ), i + 1 );
1100                                         ConvertResAnchor(@Res);
1101                                         html.Append( Res.FBody );
1102
1103                                 end;
1104                                 // \83X\83L\83\93(\83t\83b\83^)
1105                                 html.Append( boardPlugIn.GetFooter( DWORD( threadItem ), '<a name="bottom"></a>' ) );
1106                         finally
1107                         end;
1108                         html.EndUpdate;
1109                         //Exit;
1110                 end else begin
1111                         ShortDayNames[1] := '\93ú';               ShortDayNames[2] := '\8c\8e';
1112                         ShortDayNames[3] := '\89Î';               ShortDayNames[4] := '\90\85';
1113                         ShortDayNames[5] := '\96Ø';               ShortDayNames[6] := '\8bà';
1114                         ShortDayNames[7] := '\93y';
1115                         BBSID := ThreadItem.ParentBoard.BBSID;
1116                         ReadList := TStringList.Create;
1117                         try
1118                                 if ThreadItem.IsLogFile then begin
1119                                         FileName := ThreadItem.GetThreadFileName;
1120                                         ReadList.LoadFromFile(FileName);
1121                                         GikoSys.FAbon.IndividualAbon(ReadList, ChangeFileExt(FileName,'.NG'));
1122                                         GikoSys.FAbon.Execute(ReadList);                //       \82 \82Ú\81`\82ñ\82µ\82Ä
1123                                         GikoSys.FSelectResFilter.Execute(ReadList); //\83\8c\83X\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\82·\82é
1124                                         DivideStrLine(ReadList[0], @Res);
1125                                         //Res.FTitle := CustomStringReplace(Res.FTitle, '\81\97\81M', ',');
1126                                         sTitle := Res.FTitle;
1127                                 end else begin
1128                                         sTitle := CustomStringReplace(ThreadItem.Title, '\81\97\81M', ',');
1129                                 end;
1130                                 try
1131                                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1132                                         UserOptionalStyle := GikoSys.SetUserOptionalStyle;
1133
1134                                         if GikoSys.Setting.UseSkin then begin
1135                                                 // \83X\83L\83\93\8eg\97p
1136                                                 // \83X\83L\83\93\82Ì\90Ý\92è
1137                                                 try
1138                                                         SkinHeader := LoadSkin( GikoSys.GetSkinHeaderFileName );
1139                                                         if Length( UserOptionalStyle ) > 0 then
1140                                                                 SkinHeader := CustomStringReplace( SkinHeader, '</head>',
1141                                                                         '<style type="text/css">body {' + UserOptionalStyle + '}</style></head>');
1142                                                         //\90â\91Î\8eQ\8fÆ\82©\82ç\91\8a\91Î\8eQ\8fÆ\82Ö
1143                                                         tmp1 := './' + GikoSys.Setting.CSSFileName;
1144                                                         tmp1 := CustomStringReplace(tmp1, GikoSys.GetConfigDir, '');
1145                                                         tmp1 := CustomStringReplace(tmp1, '\', '/');
1146                                                         SkinHeader := CustomStringReplace(SkinHeader, ExtractFilePath(GikoSys.Setting.CSSFileName),  tmp1);
1147                                                         html.Append( SkinHeader );
1148                                                 except
1149                                                 end;
1150                                                 try
1151                                                         SkinRes := LoadSkin( GikoSys.GetSkinResFileName );
1152                                                 except
1153                                                 end;
1154                                                 html.Append('<a name="top"></a>');
1155                                                 for i := 0 to ReadList.Count - 1 do begin
1156                                                         if (Trim(ReadList[i]) <> '') then begin
1157                                                                 No := IntToStr(i + 1);
1158
1159                                                                 DivideStrLine(ReadList[i], @Res);
1160                                                                 AddAnchorTag(@Res);
1161                                                                 ConvRes(@Res, @ResLink, true);
1162                                                                 ConvertResAnchor(@Res);
1163
1164                                                                 try
1165                                                                         html.Append( ReplaceRes( SkinRes ) );
1166                                                                 except
1167                                                                 end;
1168                                                         end;
1169
1170                                                 end;
1171                                                 html.Append('<a name="bottom"></a>');
1172                                                 // \83X\83L\83\93(\83t\83b\83^)
1173                                                 try
1174                                                         html.Append( LoadSkin( GikoSys.GetSkinFooterFileName ) );
1175                                                 except
1176                                                 end;
1177                                         end else if GikoSys.Setting.UseCSS and FileExists(CSSFileName) then begin
1178                                                 //CSS\8eg\97p
1179                                                 //CSSFileName := GetAppDir + CSS_FILE_NAME;
1180                                                 html.Append('<html><head>');
1181                                                 html.Append('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
1182                                                 html.Append('<title>' + sTitle + '</title>');
1183                                                 //\90â\91Î\8eQ\8fÆ\82©\82ç\91\8a\91Î\8eQ\8fÆ\82Ö
1184                                                 tmp1 := './' + CSSFileName;
1185                                                 tmp1 := CustomStringReplace(tmp1, GikoSys.GetConfigDir, '');
1186                                                 tmp1 := CustomStringReplace(tmp1, '\', '/');
1187
1188                                                 html.Append('<link rel="stylesheet" href="'+tmp1+'" type="text/css">');
1189                                                 if Length( UserOptionalStyle ) > 0 then
1190                                                         html.Append('<style type="text/css">body {' + UserOptionalStyle + '}</style>');
1191                                                 html.Append('</head>');
1192                                                 html.Append('<body>');
1193                                                 html.Append('<a name="top"></a>');
1194                                                 html.Append('<div class="title">' + sTitle + '</div>');
1195                                                 for i := 0 to ReadList.Count - 1 do begin
1196                                                         if (Trim(ReadList[i]) <> '') then begin
1197                                                                 No := IntToStr(i + 1);
1198                                                                 DivideStrLine(ReadList[i], @Res);
1199                                                                 AddAnchorTag(@Res);
1200                                                                 ConvRes(@Res, @ResLink, true);
1201                                                                 ConvertResAnchor(@Res);
1202                                                                 if Res.FMailTo = '' then
1203                                                                         html.Append('<a name="' + No + '"></a>'
1204                                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span> '
1205                                                                                                         + '<span class="name_label">\96¼\91O\81F</span> '
1206                                                                                                         + '<span class="name"><b>' + Res.FName + '</b></span> '
1207                                                                                                         + '<span class="date_label">\93\8a\8de\93ú\81F</span> '
1208                                                                                                         + '<span class="date">' + Res.FDateTime+ '</span></div>'
1209                                                                                                                                                                                                 + '<div class="mes">' + Res.FBody + ' </div>')
1210                                                                 else if GikoSys.Setting.ShowMail then
1211                                                                         html.Append('<a name="' + No + '"></a>'
1212                                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span>'
1213                                                                                                                                                                                                 + '<span class="name_label"> \96¼\91O\81F </span>'
1214                                                                                                         + '<a class="name_mail" href="mailto:' + Res.FMailTo + '">'
1215                                                                                                         + '<b>' + Res.FName + '</b></a><span class="mail"> [' + Res.FMailTo + ']</span>'
1216                                                                                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span>'
1217                                                                                                         + '<span class="date"> ' + Res.FDateTime+ '</span></div>'
1218                                                                                                         + '<div class="mes">' + Res.FBody + ' </div>')
1219                                                                 else
1220                                                                         html.Append('<a name="' + No + '"></a>'
1221                                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span>'
1222                                                                                                         + '<span class="name_label"> \96¼\91O\81F </span>'
1223                                                                                                         + '<a class="name_mail" href="mailto:' + Res.FMailTo + '">'
1224                                                                                                         + '<b>' + Res.FName + '</b></a>'
1225                                                                                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span>'
1226                                                                                                         + '<span class="date"> ' + Res.FDateTime+ '</span></div>'
1227                                                                                                                                                                                                 + '<div class="mes">' + Res.FBody + ' </div>');
1228                                                         end;
1229                                                 end;
1230                                                 html.Append('<a name="bottom"></a>');
1231                                                 html.Append('<a name="last"></a>');
1232                                                 html.Append('</body></html>');
1233                                         end else begin
1234                                                 //CSS\94ñ\8eg\97p
1235                                                 html.Append('<html><head>');
1236                                                 html.Append('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
1237                                                 html.Append('<title>' + sTitle + '</title></head>');
1238                                                 html.Append('<body TEXT="#000000" BGCOLOR="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">');
1239                                                 html.Append('<a name="top"></a>');
1240                                                 html.Append('<font size=+1 color="#FF0000">' + sTitle + '</font>');
1241                                                 html.Append('<dl>');
1242                                                 for i := 0 to ReadList.Count - 1 do begin
1243                                                         if (Trim(ReadList[i]) <> '') then begin
1244                                                                 No := IntToStr(i + 1);
1245                                                                 DivideStrLine(ReadList[i], @Res);
1246                                                                 AddAnchorTag(@Res);
1247                                                                 ConvRes(@Res, @ResLink, true);
1248                                                                 ConvertResAnchor(@Res);
1249                                                                 if Res.FMailTo = '' then
1250                                                                         html.Append('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<font color="forestgreen"><b> ' + Res.FName + ' </b></font> \93\8a\8de\93ú\81F ' + Res.FDateTime+ '<br><dd>' + Res.Fbody + ' <br><br><br>')
1251                                                                 else if GikoSys.Setting.ShowMail then
1252                                                                         html.Append('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<a href="mailto:' + Res.FMailTo + '"><b> ' + Res.FName + ' </B></a> [' + Res.FMailTo + '] \93\8a\8de\93ú\81F ' + Res.FDateTime+ '<br><dd>' + Res.Fbody + ' <br><br><br>')
1253                                                                 else
1254                                                                         html.Append('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<a href="mailto:' + Res.FMailTo + '"><b> ' + Res.FName + ' </B></a> \93\8a\8de\93ú\81F ' + Res.FDateTime+ '<br><dd>' + Res.Fbody + ' <br><br><br>');
1255                                                         end;
1256                                                 end;
1257                                                 html.Append('</dl>');
1258                                                 html.Append('<a name="bottom"></a>');
1259                                                 html.Append('</body></html>');
1260                                         end;
1261                                 finally
1262                                         html.EndUpdate;
1263                                 end;
1264                         finally
1265                                 ReadList.Free;
1266                         end;
1267                 end;
1268         end;
1269 end;
1270
1271 procedure THTMLCreate.SetResPopupText(Hint : TResPopup; threadItem: TThreadItem; StNum, ToNum: Integer; Title, First: Boolean);
1272 var
1273         i: Integer;
1274         tmp: string;
1275         FileName: string;
1276         Line: Integer;
1277
1278         wkInt: Integer;
1279
1280         Res: TResRec;
1281         Header: string;
1282         Body: string;
1283     boardPlugIn : TBoardPlugIn;
1284 begin
1285         try
1286                 if StNum > ToNum then begin
1287                         wkInt := StNum;
1288                         StNum := ToNum;
1289                         ToNum := wkInt;
1290                 end;
1291
1292                 //\8dÅ\91å10\83\8c\83X\82Ü\82Å\95\\8e¦
1293                 if StNum + MAX_POPUP_RES < ToNum then
1294                         ToNum := StNum + MAX_POPUP_RES;
1295
1296                 //\83^\83C\83g\83\8b\95\\8e¦
1297                 if Title then
1298                                 if ThreadItem <> nil then
1299                                         Hint.Title := ThreadItem.Title;
1300
1301         if ThreadItem <> nil then begin
1302             //if ThreadItem.IsBoardPlugInAvailable then begin
1303             if ThreadItem.ParentBoard.IsBoardPlugInAvailable then begin
1304                 //===== \83v\83\89\83O\83C\83\93\82É\82æ\82é\95\\8e¦
1305                 //boardPlugIn           := ThreadItem.BoardPlugIn;
1306                 boardPlugIn             := ThreadItem.ParentBoard.BoardPlugIn;
1307
1308                 // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1309                 // \95\8e\9a\83R\81[\83h\82Í\83v\83\89\83O\83C\83\93\82É\94C\82¹\82é
1310                 for i := StNum to ToNum do begin
1311                     Line := i;
1312                                         //\82±\82±\82Å\82Q\82¿\82á\82ñ\82Ë\82é\82Ìdat\82Ì\8c`\8e®\82Å\82P\8ds\93Ç\82Ý\8d\9e\82ß\82ê\82Î¥¥¥\81B\81«\93Ç\82ß\82é\82æ\82¤\82É\82È\82Á\82½
1313                                         tmp := boardPlugIn.GetDat( DWORD( threadItem ), i );
1314                     if (tmp <> '') And ( not GikoSys.FAbon.CheckAbonPopupRes(tmp) And( not GikoSys.FAbon.CheckIndividualAbonList(line))) then begin
1315                                                 DivideStrLine(tmp, @Res);
1316                         if (GikoSys.Setting.ShowMail = false) or (Length(res.FMailTo) = 0) then
1317                                 Header := IntToStr(Line) + ' \96¼\91O\81F ' + Res.FName + ' \93\8a\8de\93ú\81F ' + Res.FDateTime
1318                         else
1319                                 Header := IntToStr(Line) + ' \96¼\91O\81F ' + Res.FName + ' [' + res.FMailTo + '] \93\8a\8de\93ú\81F ' + Res.FDateTime;
1320                                                 Header := DeleteFontTag(Header);
1321                                                 Header := CustomStringReplace(Header, '<br>', '',true);
1322
1323                                                 Body := CustomStringReplace(Res.FBody, '<br> ', #10,true);
1324                                                 Body := CustomStringReplace(Body, '<br>', #10,true);
1325                         Body := CustomStringReplace(Body, '</a>', '',true);
1326                                                 Body := THTMLCreate.DeleteLink(Body);
1327                         Body := CustomStringReplace(Body, '&lt;', '<');
1328                         Body := CustomStringReplace(Body, '&gt;', '>');
1329                         Body := CustomStringReplace(Body, '&quot;', '"');
1330                         Body := CustomStringReplace(Body, '&amp;', '&');
1331                         Body := CustomStringReplace(Body, '&nbsp;', ' ');
1332
1333                                                 Hint.Add(Header, Body);
1334                                         end;
1335                                 end;
1336                         end else begin
1337                                 for i := StNum to ToNum do begin
1338                                         Line := i;
1339                                         FileName := ThreadItem.FilePath;
1340                                         tmp := GikoSys.ReadThreadFile(FileName, Line);
1341                                         if (tmp <> '') And ( not GikoSys.FAbon.CheckAbonPopupRes(tmp) And( not GikoSys.FAbon.CheckIndividualAbonList(line))) then begin
1342                                                 DivideStrLine(tmp, @Res);
1343                                                 if (GikoSys.Setting.ShowMail = false) or (Length(res.FMailTo) = 0) then
1344                                                         Header := IntToStr(Line) + ' \96¼\91O\81F ' + Res.FName + ' \93\8a\8de\93ú\81F ' + Res.FDateTime
1345                                                 else
1346                                                         Header := IntToStr(Line) + ' \96¼\91O\81F ' + Res.FName + ' [' + res.FMailTo + '] \93\8a\8de\93ú\81F ' + Res.FDateTime;
1347
1348                                                 Body := DeleteFontTag(Res.FBody);
1349                                                 Body := CustomStringReplace(Body, '<br> ', #10,true);
1350                                                 Body := CustomStringReplace(Body, '<br>', #10,true);
1351                                                 Body := CustomStringReplace(Body, '</a>', '',true);
1352                                                 Body := THTMLCreate.DeleteLink(Body);
1353                                                 Body := CustomStringReplace(Body, '&lt;', '<');
1354                                                 Body := CustomStringReplace(Body, '&gt;', '>');
1355                                                 Body := CustomStringReplace(Body, '&quot;', '"');
1356                                                 Body := CustomStringReplace(Body, '&amp;', '&');
1357                                                  Body := CustomStringReplace(Body, '&nbsp;', ' ');
1358                                                 Hint.Add(Header, Body);
1359                                         end;
1360                                 end;
1361                         end;
1362                 end;
1363         finally
1364         end;
1365 end;
1366
1367 //\83\8a\83\93\83N\82Ì\95\8e\9a\97ñ\82©\82ç\83\8c\83X\83|\83b\83v\83A\83b\83v\97p\82ÌURL\82É\95Ï\8a·\82·\82é
1368 class function THTMLCreate.GetRespopupURL(AText, AThreadURL : string): string;
1369 var
1370         wkInt: Integer;
1371 begin
1372         Result := '';
1373         if Pos('about:blank..', AText) = 1 then begin
1374                 wkInt := LastDelimiter( '/', AThreadURL );
1375                 if Pos( '?', Copy( AThreadURL, wkInt, MaxInt ) ) = 0 then begin
1376                         // Thread.URL \82Í PATH_INFO \93n\82µ
1377                         Result := Copy( AThreadURL, 1,  LastDelimiter( '/', AThreadURL ) );
1378                         wkInt := LastDelimiter( '/', AText );
1379                         if Pos( '?', Copy( AText, wkInt, MaxInt ) ) = 0 then
1380                                 // Text \82à PATH_INFO \93n\82µ
1381                                 Result := Result + Copy( AText, LastDelimiter( '/', AText ) + 1, MaxInt )
1382                         else
1383                                 // Text \82Í QUERY_STRING \93n\82µ
1384                                 Result := Result + Copy( AText, LastDelimiter( '?', AText ) + 1, MaxInt );
1385                 end else begin
1386                         // Thread.URL \82Í QUERY_STRING \93n\82µ
1387                         Result := Copy( AThreadURL, 1,  LastDelimiter( '?', AThreadURL ) );
1388                         wkInt := LastDelimiter( '/', AText );
1389                         if Pos( '?', Copy( AText, wkInt, MaxInt ) ) = 0 then begin
1390                                 // Text \82Í PATH_INFO \93n\82µ
1391                                 // URL \82É\94Â\82Æ\83L\81[\82ª\91«\82ç\82È\82¢\82Ì\82Å Text \82©\82ç\92¸\91Õ\82·\82é
1392                                 wkInt := LastDelimiter( '/', Copy( AText, 1, wkInt - 1 ) );
1393                                 wkInt := LastDelimiter( '/', Copy( AText, 1, wkInt - 1 ) );
1394                                 Result := Copy( Result, 1, Length( Result ) - 1 ) + Copy( AText, wkInt, MaxInt );
1395                         end else begin
1396                                 // Text \82à QUERY_STRING \93n\82µ
1397                                 Result := Result + Copy( AText, LastDelimiter( '?', AText ) + 1, MaxInt )
1398                         end;
1399                 end;
1400         end else if Pos('about:blank/bbs/', AText) = 1 then begin
1401                 //\82µ\82½\82ç\82ÎJBBS\82Ì\8ed\95Ï\82Ì\8bz\8eû
1402                 AText := CustomStringReplace(AText, 'about:blank/bbs/', 'about:blank../../bbs/');
1403                 Result := GetRespopupURL(AText, AThreadURL);
1404         end else begin
1405                 Result := AText;
1406         end;
1407
1408 end;
1409 //\8ew\92è\82µ\82½\83p\83X\82É\83X\83L\83\93\82à\82µ\82­\82ÍCSS\82Ì\83t\83@\83C\83\8b\82Ì\83R\83s\81[\82ð\8dì\82é
1410 class procedure THTMLCreate.SkinorCSSFilesCopy(path: string);
1411 var
1412         tmp, tmpD, tmpF: string;
1413         current: string;
1414         dirs: TStringList;
1415         files: TStringList;
1416         i, j: Integer;
1417 begin
1418         if GikoSys.Setting.UseSkin then begin
1419                 current := ExtractFilePath(GikoSys.GetSkinDir);
1420                 tmp := GikoSys.Setting.CSSFileName;
1421         end else if GikoSys.Setting.UseCSS then begin
1422                 current := ExtractFilePath(GikoSys.GetStyleSheetDir);
1423                 tmp := ExtractFilePath(GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName);
1424         end else begin
1425         Exit;
1426     end;
1427         dirs := TStringList.Create;
1428         try
1429                 dirs.Add(tmp);
1430                 if tmp <> current then begin
1431                         GikoSys.GetDirectoryList(current, '*.*', dirs, true);
1432                         for i := 0 to dirs.Count - 1 do begin
1433                                 files := TStringList.Create;
1434                                 try
1435                                         files.BeginUpdate;
1436                                         gikoSys.GetFileList(dirs[i], '*.*', files, true);
1437                                         files.EndUpdate;
1438                                         tmpD := CustomStringReplace(dirs[i], GikoSys.GetConfigDir, path);
1439                                         if (AnsiPos(dirs[i], tmp) <> 0) and not (DirectoryExists(tmpD)) then
1440                                                 ForceDirectories(tmpD);
1441
1442                                         if(dirs[i] = tmp) and (dirs[i] <> current) then begin
1443                                                 for j := 0 to files.Count - 1 do begin
1444                                                         tmpF := CustomStringReplace(files[j], GikoSys.GetConfigDir, path);
1445                                                         if not FileExists(tmpF) then begin
1446                                                                 CopyFile(PChar(files[j]), PChar(tmpF),True);
1447                                                         end;
1448                                                 end;
1449                                         end;
1450                                 finally
1451                                         files.Free;
1452                                 end;
1453                         end;
1454                 end else begin
1455                         tmpD := CustomStringReplace(dirs[0], GikoSys.GetConfigDir, path);
1456                         if not DirectoryExists(tmpD) then
1457                                 ForceDirectories(tmpD);
1458                         tmpF := CustomStringReplace(GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName
1459                                         , GikoSys.GetConfigDir, path);
1460                         if not FileExists(tmpF) then begin
1461                                 CopyFile(PChar(GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName)
1462                                         , PChar(tmpF), True);
1463                         end;
1464                 end;
1465         finally
1466                 dirs.Free;
1467         end;
1468 end;
1469 {!
1470 \brief dat\83t\83@\83C\83\8b\82Ì\88ê\83\89\83C\83\93\82ð\95ª\89ð
1471 \param Line dat\83t\83@\83C\83\8b\82ð\8d\\90¬\82·\82é 1 \8ds
1472 \return     \83\8c\83X\8fî\95ñ
1473 }
1474 class procedure THTMLCreate.DivideStrLine(Line: string; PRes: PResRec);
1475 const
1476         delimiter = '<>';
1477 var
1478         pds, pde : PChar;
1479         pss, pse : PChar;
1480         ppos : PChar;
1481 begin
1482         //\8cÅ\92è
1483         PRes.FType := glt2chNew;
1484
1485         pss := PChar(Line);
1486         pse := pss + Length(Line);
1487         pds := PChar(delimiter);
1488         pde := pds + Length(delimiter);
1489
1490         ppos := AnsiStrPosEx(pss, pse, pds, pde);
1491         if (ppos = nil) then begin
1492                 Line := CustomStringReplace(Line, '<>', '&lt;&gt;');
1493                 Line := CustomStringReplace(Line, ',', '<>');
1494                 Line := CustomStringReplace(Line, '\81\97\81M', ',');
1495         end;
1496         //Trim\82µ\82Ä\82Í\82¢\82¯\82È\82¢\8bC\82ª\82·\82é\81@by\82à\82\82ã
1497         PRes.FName := RemoveToken(Line, delimiter);
1498         PRes.FMailTo := RemoveToken(Line, delimiter);
1499         PRes.FDateTime := RemoveToken(Line, delimiter);
1500         PRes.FBody := RemoveToken(Line, delimiter);
1501         //\82Q\82¿\82á\82ñ\82Ë\82é\82Æ\82©\82¾\82Æ\81A\96{\95\82Ì\90æ\93ª\82É\82P\82Â\94¼\8ap\8bó\94\92\82ª\93ü\82Á\82Ä\82¢\82é\82Ì\82Å\8dí\8f\9c\82·\82é
1502         //\91¼\82Ì\8cf\8e¦\94Â\82Å\81A\83\8c\83X\8e©\91Ì\82Ì\8bó\94\92\82©\82à\82µ\82ê\82È\82¢\82¯\82Ç\82»\82ê\82Í\92ú\82ß\82é
1503         PRes.FBody := TrimLeft(PRes.FBody);
1504         //\8bó\82¾\82Æ\96â\91è\82ª\8bN\82«\82é\82©\82ç\81A\8bó\94\92\82ð\90Ý\92è\82·\82é
1505         if PRes.FBody = '' then
1506                 PRes.FBody := '&nbsp;';
1507
1508         PRes.FTitle := RemoveToken(Line, delimiter);
1509 end;
1510
1511 {!
1512 \brief HTML \82©\82ç\83A\83\93\83J\81[\83^\83O\82ð\8dí\8f\9c
1513 \param s \8c³\82É\82È\82é HTML
1514 \return  \83A\83\93\83J\81[\83^\83O\82ª\8dí\8f\9c\82³\82ê\82½ HTML
1515 }
1516 class function THTMLCreate.DeleteLink(const s: string): string;
1517 var
1518         s1: string;
1519         s2: string;
1520         idx: Integer;
1521         i: Integer;
1522 begin
1523         i := 0;
1524         Result := '';
1525         while True do begin
1526                 s1 := GikoSys.GetTokenIndex(s, '<a href="', i);
1527                 s2 := GikoSys.GetTokenIndex(s, '<a href="', i + 1);
1528
1529                 idx := Pos('">', s1);
1530                 if idx <> 0 then
1531                         Delete(s1, 1, idx + 1);
1532                 idx := Pos('">', s2);
1533                 if idx <> 0 then
1534                         Delete(s2, 1, idx + 1);
1535
1536                 Result := Result + s1 + s2;
1537
1538                 if s2 = '' then
1539                         Break;
1540
1541                 inc(i, 2);
1542         end;
1543 end;
1544 {
1545 \brief  HTML\89»\82Ì\82½\82ß\82Ì\92u\8a·
1546 \param  s   \8c³\82É\82È\82é\95\8e\9a\97ñ
1547 \return HTML\82ÌinnerText\82Æ\82µ\82Ä\82ä\82é\82³\82ê\82é\95\8e\9a\97ñ
1548 }
1549 class function THTMLCreate.RepHtml(const s: string): string;
1550 begin
1551 //      s := StringReplace(s, '&', '&amp;', [rfReplaceAll]);
1552     Result := s;
1553         Result := CustomStringReplace(Result, '<', '&lt;');
1554         Result := CustomStringReplace(Result, '>', '&gt;');
1555 //      s := StringReplace(s, ' ', '&nbsp;', [rfReplaceAll]);   //\8ed\97l\95Ï\8dX\82É\82æ\82è&nbsp;\8eg\97p\95s\89Â
1556         Result := CustomStringReplace(Result, '"', '&quot;');
1557 end;
1558 {
1559 \brief  \83\8c\83X\83G\83f\83B\83^\82Å\82Ì\83v\83\8c\83r\83\85\81[\97pHTML\8dì\90¬
1560 \param  Title   \83X\83\8c\83b\83h\83^\83C\83g\83\8b
1561 \param  No  \83\8c\83X\94Ô\8d\86
1562 \param  Mail    \83\81\81[\83\8b\97\93
1563 \param  Name    \96¼\91O\97\93
1564 \param  Body    \96{\95
1565 \return \83v\83\8c\83r\83\85\81[\97pHTML
1566 }
1567 class function THTMLCreate.CreatePreviewHTML(
1568         const Title: string;
1569         const No: string;
1570         const Mail: string;
1571         const Namae: string;
1572         const Body: string
1573 ) : string;
1574 var
1575     posTrip : Integer;
1576     tripOrigin : string;
1577     NameWithTrip: string;
1578     DateTime: string;
1579 begin
1580         Result := '<HTML><HEAD>'#13#10
1581                         + '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">'#13#10
1582                         + '<TITLE>' + title + '</TITLE>'#13#10
1583                         + '</HEAD>'#13#10
1584                         + '<BODY text="#000000" bgcolor="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">'#13#10
1585                         + '<FONT COLOR="#FF0000">' + title + '</FONT>'#13#10
1586                         + '<DL>'#13#10;
1587
1588         DateTime := FormatDateTime('yyyy/mm/dd(aaa) hh:nn', Now());
1589
1590     NameWithTrip := Namae;
1591     posTrip := AnsiPos( '#', Namae );
1592     if posTrip > 0 then begin
1593         tripOrigin := Copy( Namae, posTrip + 1, Length( Namae ) );
1594         NameWithTrip := Copy( Namae, 1, posTrip - 1 ) + '</B> \81\9f' +
1595                     get_2ch_trip( PChar( tripOrigin ) ) + '<B>';
1596     end;
1597     if Mail = '' then begin
1598         Result := Result + '<DT>' + No + ' \81F <FONT color="forestgreen"><B>' + NameWithTrip
1599                  + '</B></FONT> \81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10
1600     end else begin
1601                 Result := Result + '<DT>' + No + ' \81F <A href="mailto:' + Mail + '"><B>' + NameWithTrip
1602                  + '</B></A> [' + Mail + ']\81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10;
1603     end;
1604         Result := Result + '</BODY></HTML>';
1605
1606 end;
1607 {
1608 \brief  \95\\8e¦\94Í\88Í\8aO\83\8c\83X\94Ô\8d\86\94»\92è\8f\88\97\9d
1609 \param  item    \95\\8e¦\83X\83\8c\83b\83h
1610 \param  index   \83\8c\83X\94Ô\8d\86
1611 \return ture:\95\\8e¦\94Í\88Í\8aO false:\95\\8e¦\94Í\88Í\93à
1612 }
1613 function THTMLCreate.isOutsideRange( item: TThreadItem; index: Integer ): Boolean;
1614 begin
1615     Result := False;
1616     // \95\\8e¦\94Í\88Í\82ð\8cÀ\92è
1617     case GikoSys.ResRange of
1618     Ord( grrKoko ):
1619         if item.Kokomade > (index + 1) then
1620             Result := True;
1621     Ord( grrNew ):
1622         if item.NewReceive > (index + 1) then
1623             Result := True;
1624     10..65535:
1625         if (GikoSys.Setting.HeadResCount) < (index + 1)  then begin
1626             if (item.Count - index) > GikoSys.ResRange then begin
1627                 Result := True;
1628             end;
1629         end;
1630     end;
1631 end;
1632 constructor TBufferedWebBrowser.Create(Browser: TWebBrowser; BuffSize: Integer);
1633 begin
1634         inherited Create;
1635         Self.Sorted := False;
1636         if (Browser = nil) then
1637                 Raise  Exception.Create('Browser is NULL');
1638         FBrowser := Browser;
1639
1640         // \83o\83b\83t\83@\82·\82é\8ds\90\94\82ð
1641         if (BuffSize < 0) then begin
1642                 FBuffSize := 100;
1643         end else begin
1644                 FBuffSize := BuffSize;
1645         end;
1646         Self.Capacity := FBuffSize + 10;
1647 end;
1648 procedure TBufferedWebBrowser.Open;
1649 begin
1650         FBrowserDoc := Idispatch( olevariant(FBrowser.ControlInterface).Document);
1651         FBrowserDoc.open;
1652         FBrowserDoc.charset := 'Shift_JIS';
1653 end;
1654 procedure TBufferedWebBrowser.Close;
1655 begin
1656         Self.Flush;
1657         try
1658                 FBrowserDoc.Close;
1659         except
1660         end;
1661         FBrowser := nil;
1662 end;
1663 function TBufferedWebBrowser.Add(const S: string): Integer;
1664 begin
1665         Result := inherited Add(TrimRight(s));
1666         if (Self.Count > FBuffSize) then begin
1667                 FBrowserDoc.Write(Self.Text);
1668                 Self.Clear;
1669         end;
1670 end;
1671 procedure TBufferedWebBrowser.Flush ;
1672 begin
1673         if (Self.Count > 0) then begin
1674                 FBrowserDoc.Write(Self.Text);
1675                 Self.Clear;
1676         end;
1677 end;
1678 destructor TBufferedWebBrowser.Destory;
1679 begin
1680         try
1681                 if (FBrowserDoc <> 0) then begin
1682                         FBrowserDoc.close;
1683                         FBrowserDoc := 0;
1684                 end;
1685         except
1686         end;
1687         inherited;
1688 end;
1689 //! \8aÖ\98A\83L\81[\83\8f\81[\83h\83\8a\83\93\83N\8fo\97Í
1690 function THTMLCreate.getKeywordLink(item: TThreadItem): String;
1691 const
1692     PARA_URL = 'http://p2.2ch.io/getf.cgi?';
1693 begin
1694     Result := '';
1695     if (GikoSys.Setting.AddKeywordLink) and (item.ParentBoard.Is2ch) then begin
1696         Result := '<p><span id="keyword"><a href="' + PARA_URL
1697             + item.URL + '" target="_blank">\8aÖ\98A\83L\81[\83\8f\81[\83h</a></span></p>';
1698     end;
1699 end;
1700 initialization
1701          HTMLCreater := THTMLCreate.Create;
1702
1703 finalization
1704         if HTMLCreater <> nil then begin
1705                 HTMLCreater.Free;
1706                 HTMLCreater := nil;
1707         end;
1708
1709 end.