OSDN Git Service

作りかけの新NGワード機能が入ってしまっていたので、
[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
775                         DivideStrLine(ReadList[i], @Res);
776 {$IFDEF NEWNGWORD}
777             if (NGWordList.IsNG(@Res) = -1) then begin
778 {$ENDIF}
779                         AddAnchorTag(@Res);
780                         ConvRes(@Res, @ResLink);
781                         Res.FDateTime := AddBeProfileLink(Res.FDateTime, i + 1);
782
783                             if NewReceiveNo <= (i + 1) then
784                                     // \90V\92\85\83\8c\83X
785                                 html.Add(SkinedRes(SkinNewRes, @Res, IntToStr(i + 1)))
786                         else
787                                 // \92Ê\8fí\82Ì\83\8c\83X
788                                 html.Add(SkinedRes(SkinRes, @Res, IntToStr(i + 1)));
789 {$IFDEF NEWNGWORD}
790             end else begin
791                 html.Add('<h4>\82 \82Ú\81`\82ñ</h4>');
792             end;
793 {$ENDIF}
794                 end;
795
796                 if ThreadItem.Kokomade = (i + 1) then begin
797                         // \82±\82±\82Ü\82Å\93Ç\82ñ\82¾
798                         if FileExists( GikoSys.GetSkinBookmarkFileName ) then
799                                 html.Add( LoadFromSkin( GikoSys.GetSkinBookmarkFileName, ThreadItem, ThreadItem.Size ))
800                         else
801                                 html.Add( KOKO_TAG );
802                 end;
803         end;
804     html.Add(getKeywordLink(ThreadItem));
805         html.Add('<a name="bottom"></a>');
806         // \83X\83L\83\93(\83t\83b\83^)
807         html.Add( LoadFromSkin( GikoSys.GetSkinFooterFileName, ThreadItem, ThreadItem.Size ) );
808 end;
809
810 procedure THTMLCreate.CreateUseCSSHTML(html:TBufferedWebBrowser; ThreadItem: TThreadItem; ReadList: TStringList; sTitle: string );
811 const
812         FORMAT_NOMAIL  = '<a name="%s"></a><div class="header"><span class="no"><a href="menu:%s">%s</a></span>'
813                                         + '<span class="name_label"> \96¼\91O\81F </span> <span class="name"><b>%s</b></span>'
814                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span> <span class="date">%s</span></div>'
815                                         + '<div class="mes">%s</div>';
816
817         FORMAT_SHOWMAIL = '<a name="%s"></a><div class="header"><span class="no"><a href="menu:%s">%s</a></span>'
818                                         + '<span class="name_label"> \96¼\91O\81F </span><a class="name_mail" href="mailto:%s">'
819                                         + '<b>%s</b></a><span class="mail"> [%s]</span><span class="date_label"> \93\8a\8de\93ú\81F</span>'
820                                         + '<span class="date"> %s</span></div><div class="mes">%s</div>';
821
822         FORMAT_NOSHOW = '<a name="%s"></a><div class="header"><span class="no"><a href="menu:%s">%s</a></span>'
823                                         + '<span class="name_label"> \96¼\91O\81F </span><a class="name_mail" href="mailto:%s">'
824                                         + '<b>%s</b></a><span class="date_label"> \93\8a\8de\93ú\81F</span><span class="date"> %s</span></div>'
825                                         + '<div class="mes">%s</div>';
826 var
827         i: integer;
828         No: string;
829         CSSFileName: string;
830         NewReceiveNo: Integer;
831         Res: TResRec;
832         UserOptionalStyle: string;
833         ThreadName :String;
834         ResLink :TResLinkRec;
835 begin
836         NewReceiveNo := ThreadItem.NewReceive;
837         ThreadName := ChangeFileExt(ThreadItem.FileName, '');
838         ResLink.FBbs := ThreadItem.ParentBoard.BBSID;
839         ResLink.FKey := ThreadName;
840         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
841         UserOptionalStyle := GikoSys.SetUserOptionalStyle;
842         CSSFileName := GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName;
843         if GikoSys.Setting.UseCSS and FileExists(CSSFileName) then begin
844                 //CSS\8eg\97p
845                 html.Add('<html><head>');
846                 html.Add('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
847                 html.Add('<title>' + sTitle + '</title>');
848                 html.Add('<link rel="stylesheet" href="'+CSSFileName+'" type="text/css">');
849                 if Length( UserOptionalStyle ) > 0 then
850                         html.Add('<style type="text/css">body {' + UserOptionalStyle + '}</style>');
851                 html.Add('</head>'#13#10'<body>');
852                 html.Add('<a name="top"></a>'#13#10'<p id="idSearch"></p>');
853                 html.Add('<div class="title">' + sTitle + '</div>');
854                 html.Flush;
855                 for i := 0 to ReadList.Count - 1 do begin
856                         // 1 \82Í\95K\82¸\95\\8e¦
857                         if i <> 0 then begin
858                         // \95\\8e¦\94Í\88Í\82ð\8cÀ\92è
859                 if (isOutsideRange(ThreadItem, i)) then begin
860                     Continue;
861                 end;
862                         end;
863
864                         if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
865                                 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>');
866                         end;
867
868                         if (Trim(ReadList[i]) <> '') then begin
869                                 No := IntToStr(i + 1);
870                                 DivideStrLine(ReadList[i], @Res);
871 {$IFDEF NEWNGWORD}
872                 if (NGWordList.IsNG(@Res) = -1) then begin
873 {$ENDIF}
874                     AddAnchorTag(@Res);
875                     ConvRes(@Res, @ResLink);
876                     Res.FDateTime := AddBeProfileLink(Res.FDateTime, i + 1);
877                     if Res.FMailTo = '' then
878                         html.Add(Format(FORMAT_NOMAIL, [No, No, No, Res.FName, Res.FDateTime, Res.FBody]))
879                     else if GikoSys.Setting.ShowMail then
880                         html.Add(Format(FORMAT_SHOWMAIL, [No, No, No, Res.FMailTo, Res.FName, Res.FMailTo, Res.FDateTime, Res.FBody]))
881                     else
882                         html.Add(Format(FORMAT_NOSHOW, [No, No, No, Res.FMailTo, Res.FName, Res.FDateTime, Res.FBody]));
883 {$IFDEF NEWNGWORD}
884                             end else begin
885                     html.Add('<h4>\82 \82Ú\81`\82ñ</h4>');
886                 end;
887 {$ENDIF}
888             end;
889                         if ThreadItem.Kokomade = (i + 1) then begin
890                                 html.Add('<a name="koko"></a><div class="koko">\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</div>');
891                         end;
892
893                 end;
894         html.Add(getKeywordLink(ThreadItem));
895                 html.Add('<a name="bottom"></a>');
896                 html.Add('<a name="last"></a>');
897                 html.Add('</body></html>');
898         end;
899 end;
900
901 procedure THTMLCreate.CreateDefaultHTML (html:TBufferedWebBrowser; ThreadItem: TThreadItem; ReadList: TStringList; sTitle: string );
902 var
903         i: integer;
904         No: string;
905         NewReceiveNo: Integer;
906         Res: TResRec;
907         ThreadName: String;
908         ResLink : TResLinkRec;
909 begin
910         NewReceiveNo := ThreadItem.NewReceive;
911         ThreadName := ChangeFileExt(ThreadItem.FileName, '');
912         ResLink.FBbs := ThreadItem.ParentBoard.BBSID;
913         ResLink.FKey := ThreadName;
914         html.Add('<html><head>');
915         html.Add('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
916         html.Add('<title>' + sTitle + '</title></head>');
917         html.Add('<body TEXT="#000000" BGCOLOR="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">');
918         html.Add('<a name="top"></a>');
919         html.Add('<font size=+1 color="#FF0000">' + sTitle + '</font>');
920         html.Add('<dl>');
921         html.Add('<p id="idSearch"></p>');
922         html.Flush;
923         for i := 0 to ReadList.Count - 1 do begin
924                 // 1 \82Í\95K\82¸\95\\8e¦
925                 if i <> 0 then begin
926                         // \95\\8e¦\94Í\88Í\82ð\8cÀ\92è
927             if (isOutsideRange(ThreadItem, i)) then begin
928                 Continue;
929             end;
930                 end;
931
932                 if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
933                         html.Add('</dl>');
934                         html.Add('<a name="new"></a>');
935                         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>');
936                         html.Add('<dl>');
937                 end;
938
939                 if (Trim(ReadList[i]) <> '') then begin
940                         No := IntToStr(i + 1);
941                         DivideStrLine(ReadList[i], @Res);
942 {$IFDEF NEWNGWORD}
943             if (NGWordList.IsNG(@Res) = -1) then begin
944 {$ENDIF}
945                             AddAnchorTag(@Res);
946                         ConvRes(@Res, @ResLink);
947                         Res.FDateTime := AddBeProfileLink(Res.FDateTime, i + 1);
948                         if Res.FMailTo = '' then
949                                 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)
950                         else if GikoSys.Setting.ShowMail then
951                                 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)
952                         else
953                                 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);
954 {$IFDEF NEWNGWORD}
955             end else begin
956                 html.Add('<h4>\82 \82Ú\81`\82ñ</h4>');
957             end;
958 {$ENDIF}
959         end;
960                 if ThreadItem.Kokomade = (i + 1) then begin
961                         html.Add('</dl>');
962                         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>');
963                         html.Add('<dl>');
964                 end;
965         end;
966     html.Add(getKeywordLink(ThreadItem));
967         html.Add('</dl>'#13#10'<a name="bottom"></a>'#13#10'</body></html>');
968 end;
969
970 procedure THTMLCreate.CreateHTML2(Browser: TWebBrowser; ThreadItem: TThreadItem; var sTitle: string);
971 var
972         ReadList: TStringList;
973         CSSFileName: string;
974         FileName: string;
975         Res: TResRec;
976         body : TBufferedWebBrowser;
977 {$IFDEF DEBUG}
978         st, rt: Cardinal;
979 {$ENDIF}
980 begin
981 {$IFDEF DEBUG}
982         Writeln('Create HTML');
983         st := GetTickCount;
984 {$ENDIF}
985         if ThreadItem <> nil then begin
986                 body := TBufferedWebBrowser.Create(Browser, 100);
987                 try
988                         body.Open;
989                         if ThreadItem.ParentBoard.IsBoardPlugInAvailable then begin
990                                 CreateUsePluginHTML(body, ThreadItem, sTitle);
991                         end else begin
992                                 ShortDayNames[1] := '\93ú';               ShortDayNames[2] := '\8c\8e';
993                                 ShortDayNames[3] := '\89Î';               ShortDayNames[4] := '\90\85';
994                                 ShortDayNames[5] := '\96Ø';               ShortDayNames[6] := '\8bà';
995                                 ShortDayNames[7] := '\93y';
996
997                                 ReadList := TStringList.Create;
998                                 try
999                                         if ThreadItem.IsLogFile then begin
1000                                                 ReadList.BeginUpdate;
1001                                                 FileName := ThreadItem.GetThreadFileName;
1002                                                 ReadList.LoadFromFile(FileName);
1003                                                 ReadList.EndUpdate;
1004                                                 GikoSys.FAbon.IndividualAbon(ReadList, ChangeFileExt(FileName,'.NG'));
1005                         {$IFNDEF NEWNGWORD}
1006                                                 GikoSys.FAbon.Execute(ReadList);                //       \82 \82Ú\81`\82ñ\82µ\82Ä
1007                         {$ENDIF}
1008                                                 GikoSys.FSelectResFilter.Execute(ReadList); //\83\8c\83X\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\82·\82é
1009                                                 if ThreadItem.Title = '' then begin
1010                                                         DivideStrLine(ReadList[0], @Res);
1011                                                         sTitle := Res.FTitle;
1012                                                 end else
1013                                                         sTitle := ThreadItem.Title
1014                                         end else begin
1015                                                 sTitle := CustomStringReplace(ThreadItem.Title, '\81\97\81M', ',');
1016                                         end;
1017                                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1018                                         CSSFileName := GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName;
1019                                         if GikoSys.Setting.UseSkin then begin
1020                                                 CreateUseSKINHTML(body, ThreadItem, ReadList);
1021                                         end else if GikoSys.Setting.UseCSS and FileExists(CSSFileName) then begin
1022                                                 CreateUseCSSHTML(body, ThreadItem, ReadList, sTitle);
1023                                         end else begin
1024                                                 CreateDefaultHTML(body, ThreadItem, ReadList, sTitle);
1025                                         end;
1026                                 finally
1027                                         ReadList.Free;
1028                                 end;
1029                         end;
1030                 finally
1031                         body.Close;
1032                         body.Free;
1033                 end;
1034         end;
1035 {$IFDEF DEBUG}
1036         rt := GetTickCount - st;
1037         Writeln('Done.');
1038         Writeln(IntToStr(rt) + ' ms');
1039 {$ENDIF}
1040 end;
1041
1042 procedure THTMLCreate.CreateHTML3(var html: TStringList; ThreadItem: TThreadItem; var sTitle: string);
1043 var
1044         i: integer;
1045         No: string;
1046         //bufList : TStringList;
1047         ReadList: TStringList;
1048 //      SaveList: TStringList;
1049         CSSFileName: string;
1050         BBSID: string;
1051         FileName: string;
1052         Res: TResRec;
1053         boardPlugIn : TBoardPlugIn;
1054
1055         UserOptionalStyle: string;
1056         SkinHeader: string;
1057         SkinRes: string;
1058         tmp, tmp1: string;
1059         ThreadName: String;
1060         ResLink : TResLinkRec;
1061         function LoadSkin( fileName: string ): string;
1062         begin
1063                 Result := LoadFromSkin( fileName, ThreadItem, ThreadItem.Size );
1064         end;
1065         function ReplaceRes( skin: string ): string;
1066         begin
1067                 Result := SkinedRes( skin, @Res, No );
1068         end;
1069
1070 begin
1071         if ThreadItem <> nil then begin
1072                 CSSFileName := GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName;
1073                 ThreadName := ChangeFileExt(ThreadItem.FileName, '');
1074                 ResLink.FBbs := ThreadItem.ParentBoard.BBSID;
1075                 ResLink.FKey := ThreadName;
1076                 html.Clear;
1077                 html.BeginUpdate;
1078                 //if ThreadItem.IsBoardPlugInAvailable then begin
1079                 if ThreadItem.ParentBoard.IsBoardPlugInAvailable then begin
1080                         //===== \83v\83\89\83O\83C\83\93\82É\82æ\82é\95\\8e¦
1081                         //boardPlugIn           := ThreadItem.BoardPlugIn;
1082                         boardPlugIn             := ThreadItem.ParentBoard.BoardPlugIn;
1083                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1084                         UserOptionalStyle := GikoSys.SetUserOptionalStyle;
1085                         try
1086                                 // \95\8e\9a\83R\81[\83h\82Í\83v\83\89\83O\83C\83\93\82É\94C\82¹\82é
1087                                 // \83w\83b\83_
1088                                 tmp := boardPlugIn.GetHeader( DWORD( threadItem ),
1089                                         '<style type="text/css">body {' + UserOptionalStyle + '}</style>' );
1090                                 //\90â\91Î\8eQ\8fÆ\82©\82ç\91\8a\91Î\8eQ\8fÆ\82Ö
1091                                 if GikoSys.Setting.UseSkin then begin
1092                                         tmp1 := './' + GikoSys.Setting.CSSFileName;
1093                                         tmp1 := CustomStringReplace(tmp1, GikoSys.GetConfigDir, '');
1094                                         tmp1 := CustomStringReplace(tmp1, '\', '/');
1095                                         tmp := CustomStringReplace(tmp, ExtractFilePath(GikoSys.Setting.CSSFileName),  tmp1);
1096                                 end else if GikoSys.Setting.UseCSS then begin
1097                                         tmp1 := './' + CSSFileName;
1098                                         tmp1 := CustomStringReplace(tmp1, GikoSys.GetConfigDir, '');
1099                                         tmp1 := CustomStringReplace(tmp1, '\', '/');
1100                                         tmp := CustomStringReplace(tmp, CSSFileName,  tmp1);
1101                                 end;
1102                                 html.Append( tmp );
1103
1104                                 for i := 0 to threadItem.Count - 1 do begin
1105
1106                                         // \83\8c\83X
1107                                         Res.FBody := boardPlugIn.GetRes( DWORD( threadItem ), i + 1 );
1108                                         ConvertResAnchor(@Res);
1109                                         html.Append( Res.FBody );
1110
1111                                 end;
1112                                 // \83X\83L\83\93(\83t\83b\83^)
1113                                 html.Append( boardPlugIn.GetFooter( DWORD( threadItem ), '<a name="bottom"></a>' ) );
1114                         finally
1115                         end;
1116                         html.EndUpdate;
1117                         //Exit;
1118                 end else begin
1119                         ShortDayNames[1] := '\93ú';               ShortDayNames[2] := '\8c\8e';
1120                         ShortDayNames[3] := '\89Î';               ShortDayNames[4] := '\90\85';
1121                         ShortDayNames[5] := '\96Ø';               ShortDayNames[6] := '\8bà';
1122                         ShortDayNames[7] := '\93y';
1123                         BBSID := ThreadItem.ParentBoard.BBSID;
1124                         ReadList := TStringList.Create;
1125                         try
1126                                 if ThreadItem.IsLogFile then begin
1127                                         FileName := ThreadItem.GetThreadFileName;
1128                                         ReadList.LoadFromFile(FileName);
1129                                         GikoSys.FAbon.IndividualAbon(ReadList, ChangeFileExt(FileName,'.NG'));
1130                                         GikoSys.FAbon.Execute(ReadList);                //       \82 \82Ú\81`\82ñ\82µ\82Ä
1131                                         GikoSys.FSelectResFilter.Execute(ReadList); //\83\8c\83X\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\82·\82é
1132                                         DivideStrLine(ReadList[0], @Res);
1133                                         //Res.FTitle := CustomStringReplace(Res.FTitle, '\81\97\81M', ',');
1134                                         sTitle := Res.FTitle;
1135                                 end else begin
1136                                         sTitle := CustomStringReplace(ThreadItem.Title, '\81\97\81M', ',');
1137                                 end;
1138                                 try
1139                                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1140                                         UserOptionalStyle := GikoSys.SetUserOptionalStyle;
1141
1142                                         if GikoSys.Setting.UseSkin then begin
1143                                                 // \83X\83L\83\93\8eg\97p
1144                                                 // \83X\83L\83\93\82Ì\90Ý\92è
1145                                                 try
1146                                                         SkinHeader := LoadSkin( GikoSys.GetSkinHeaderFileName );
1147                                                         if Length( UserOptionalStyle ) > 0 then
1148                                                                 SkinHeader := CustomStringReplace( SkinHeader, '</head>',
1149                                                                         '<style type="text/css">body {' + UserOptionalStyle + '}</style></head>');
1150                                                         //\90â\91Î\8eQ\8fÆ\82©\82ç\91\8a\91Î\8eQ\8fÆ\82Ö
1151                                                         tmp1 := './' + GikoSys.Setting.CSSFileName;
1152                                                         tmp1 := CustomStringReplace(tmp1, GikoSys.GetConfigDir, '');
1153                                                         tmp1 := CustomStringReplace(tmp1, '\', '/');
1154                                                         SkinHeader := CustomStringReplace(SkinHeader, ExtractFilePath(GikoSys.Setting.CSSFileName),  tmp1);
1155                                                         html.Append( SkinHeader );
1156                                                 except
1157                                                 end;
1158                                                 try
1159                                                         SkinRes := LoadSkin( GikoSys.GetSkinResFileName );
1160                                                 except
1161                                                 end;
1162                                                 html.Append('<a name="top"></a>');
1163                                                 for i := 0 to ReadList.Count - 1 do begin
1164                                                         if (Trim(ReadList[i]) <> '') then begin
1165                                                                 No := IntToStr(i + 1);
1166
1167                                                                 DivideStrLine(ReadList[i], @Res);
1168                                                                 AddAnchorTag(@Res);
1169                                                                 ConvRes(@Res, @ResLink, true);
1170                                                                 ConvertResAnchor(@Res);
1171
1172                                                                 try
1173                                                                         html.Append( ReplaceRes( SkinRes ) );
1174                                                                 except
1175                                                                 end;
1176                                                         end;
1177
1178                                                 end;
1179                                                 html.Append('<a name="bottom"></a>');
1180                                                 // \83X\83L\83\93(\83t\83b\83^)
1181                                                 try
1182                                                         html.Append( LoadSkin( GikoSys.GetSkinFooterFileName ) );
1183                                                 except
1184                                                 end;
1185                                         end else if GikoSys.Setting.UseCSS and FileExists(CSSFileName) then begin
1186                                                 //CSS\8eg\97p
1187                                                 //CSSFileName := GetAppDir + CSS_FILE_NAME;
1188                                                 html.Append('<html><head>');
1189                                                 html.Append('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
1190                                                 html.Append('<title>' + sTitle + '</title>');
1191                                                 //\90â\91Î\8eQ\8fÆ\82©\82ç\91\8a\91Î\8eQ\8fÆ\82Ö
1192                                                 tmp1 := './' + CSSFileName;
1193                                                 tmp1 := CustomStringReplace(tmp1, GikoSys.GetConfigDir, '');
1194                                                 tmp1 := CustomStringReplace(tmp1, '\', '/');
1195
1196                                                 html.Append('<link rel="stylesheet" href="'+tmp1+'" type="text/css">');
1197                                                 if Length( UserOptionalStyle ) > 0 then
1198                                                         html.Append('<style type="text/css">body {' + UserOptionalStyle + '}</style>');
1199                                                 html.Append('</head>');
1200                                                 html.Append('<body>');
1201                                                 html.Append('<a name="top"></a>');
1202                                                 html.Append('<div class="title">' + sTitle + '</div>');
1203                                                 for i := 0 to ReadList.Count - 1 do begin
1204                                                         if (Trim(ReadList[i]) <> '') then begin
1205                                                                 No := IntToStr(i + 1);
1206                                                                 DivideStrLine(ReadList[i], @Res);
1207                                                                 AddAnchorTag(@Res);
1208                                                                 ConvRes(@Res, @ResLink, true);
1209                                                                 ConvertResAnchor(@Res);
1210                                                                 if Res.FMailTo = '' 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                                                                                                         + '<span class="name"><b>' + Res.FName + '</b></span> '
1215                                                                                                         + '<span class="date_label">\93\8a\8de\93ú\81F</span> '
1216                                                                                                         + '<span class="date">' + Res.FDateTime+ '</span></div>'
1217                                                                                                                                                                                                 + '<div class="mes">' + Res.FBody + ' </div>')
1218                                                                 else if GikoSys.Setting.ShowMail then
1219                                                                         html.Append('<a name="' + No + '"></a>'
1220                                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span>'
1221                                                                                                                                                                                                 + '<span class="name_label"> \96¼\91O\81F </span>'
1222                                                                                                         + '<a class="name_mail" href="mailto:' + Res.FMailTo + '">'
1223                                                                                                         + '<b>' + Res.FName + '</b></a><span class="mail"> [' + Res.FMailTo + ']</span>'
1224                                                                                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span>'
1225                                                                                                         + '<span class="date"> ' + Res.FDateTime+ '</span></div>'
1226                                                                                                         + '<div class="mes">' + Res.FBody + ' </div>')
1227                                                                 else
1228                                                                         html.Append('<a name="' + No + '"></a>'
1229                                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span>'
1230                                                                                                         + '<span class="name_label"> \96¼\91O\81F </span>'
1231                                                                                                         + '<a class="name_mail" href="mailto:' + Res.FMailTo + '">'
1232                                                                                                         + '<b>' + Res.FName + '</b></a>'
1233                                                                                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span>'
1234                                                                                                         + '<span class="date"> ' + Res.FDateTime+ '</span></div>'
1235                                                                                                                                                                                                 + '<div class="mes">' + Res.FBody + ' </div>');
1236                                                         end;
1237                                                 end;
1238                                                 html.Append('<a name="bottom"></a>');
1239                                                 html.Append('<a name="last"></a>');
1240                                                 html.Append('</body></html>');
1241                                         end else begin
1242                                                 //CSS\94ñ\8eg\97p
1243                                                 html.Append('<html><head>');
1244                                                 html.Append('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
1245                                                 html.Append('<title>' + sTitle + '</title></head>');
1246                                                 html.Append('<body TEXT="#000000" BGCOLOR="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">');
1247                                                 html.Append('<a name="top"></a>');
1248                                                 html.Append('<font size=+1 color="#FF0000">' + sTitle + '</font>');
1249                                                 html.Append('<dl>');
1250                                                 for i := 0 to ReadList.Count - 1 do begin
1251                                                         if (Trim(ReadList[i]) <> '') then begin
1252                                                                 No := IntToStr(i + 1);
1253                                                                 DivideStrLine(ReadList[i], @Res);
1254                                                                 AddAnchorTag(@Res);
1255                                                                 ConvRes(@Res, @ResLink, true);
1256                                                                 ConvertResAnchor(@Res);
1257                                                                 if Res.FMailTo = '' then
1258                                                                         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>')
1259                                                                 else if GikoSys.Setting.ShowMail then
1260                                                                         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>')
1261                                                                 else
1262                                                                         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>');
1263                                                         end;
1264                                                 end;
1265                                                 html.Append('</dl>');
1266                                                 html.Append('<a name="bottom"></a>');
1267                                                 html.Append('</body></html>');
1268                                         end;
1269                                 finally
1270                                         html.EndUpdate;
1271                                 end;
1272                         finally
1273                                 ReadList.Free;
1274                         end;
1275                 end;
1276         end;
1277 end;
1278
1279 procedure THTMLCreate.SetResPopupText(Hint : TResPopup; threadItem: TThreadItem; StNum, ToNum: Integer; Title, First: Boolean);
1280 var
1281         i: Integer;
1282         tmp: string;
1283         FileName: string;
1284         Line: Integer;
1285
1286         wkInt: Integer;
1287
1288         Res: TResRec;
1289         Header: string;
1290         Body: string;
1291     boardPlugIn : TBoardPlugIn;
1292 begin
1293         try
1294                 if StNum > ToNum then begin
1295                         wkInt := StNum;
1296                         StNum := ToNum;
1297                         ToNum := wkInt;
1298                 end;
1299
1300                 //\8dÅ\91å10\83\8c\83X\82Ü\82Å\95\\8e¦
1301                 if StNum + MAX_POPUP_RES < ToNum then
1302                         ToNum := StNum + MAX_POPUP_RES;
1303
1304                 //\83^\83C\83g\83\8b\95\\8e¦
1305                 if Title then
1306                                 if ThreadItem <> nil then
1307                                         Hint.Title := ThreadItem.Title;
1308
1309         if ThreadItem <> nil then begin
1310             //if ThreadItem.IsBoardPlugInAvailable then begin
1311             if ThreadItem.ParentBoard.IsBoardPlugInAvailable then begin
1312                 //===== \83v\83\89\83O\83C\83\93\82É\82æ\82é\95\\8e¦
1313                 //boardPlugIn           := ThreadItem.BoardPlugIn;
1314                 boardPlugIn             := ThreadItem.ParentBoard.BoardPlugIn;
1315
1316                 // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1317                 // \95\8e\9a\83R\81[\83h\82Í\83v\83\89\83O\83C\83\93\82É\94C\82¹\82é
1318                 for i := StNum to ToNum do begin
1319                     Line := i;
1320                                         //\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½
1321                                         tmp := boardPlugIn.GetDat( DWORD( threadItem ), i );
1322                     if (tmp <> '') And ( not GikoSys.FAbon.CheckAbonPopupRes(tmp) And( not GikoSys.FAbon.CheckIndividualAbonList(line))) then begin
1323                                                 DivideStrLine(tmp, @Res);
1324                         if (GikoSys.Setting.ShowMail = false) or (Length(res.FMailTo) = 0) then
1325                                 Header := IntToStr(Line) + ' \96¼\91O\81F ' + Res.FName + ' \93\8a\8de\93ú\81F ' + Res.FDateTime
1326                         else
1327                                 Header := IntToStr(Line) + ' \96¼\91O\81F ' + Res.FName + ' [' + res.FMailTo + '] \93\8a\8de\93ú\81F ' + Res.FDateTime;
1328                                                 Header := DeleteFontTag(Header);
1329                                                 Header := CustomStringReplace(Header, '<br>', '',true);
1330
1331                                                 Body := CustomStringReplace(Res.FBody, '<br> ', #10,true);
1332                                                 Body := CustomStringReplace(Body, '<br>', #10,true);
1333                         Body := CustomStringReplace(Body, '</a>', '',true);
1334                                                 Body := THTMLCreate.DeleteLink(Body);
1335                         Body := CustomStringReplace(Body, '&lt;', '<');
1336                         Body := CustomStringReplace(Body, '&gt;', '>');
1337                         Body := CustomStringReplace(Body, '&quot;', '"');
1338                         Body := CustomStringReplace(Body, '&amp;', '&');
1339                         Body := CustomStringReplace(Body, '&nbsp;', ' ');
1340
1341                                                 Hint.Add(Header, Body);
1342                                         end;
1343                                 end;
1344                         end else begin
1345                                 for i := StNum to ToNum do begin
1346                                         Line := i;
1347                                         FileName := ThreadItem.FilePath;
1348                                         tmp := GikoSys.ReadThreadFile(FileName, Line);
1349                                         if (tmp <> '') And ( not GikoSys.FAbon.CheckAbonPopupRes(tmp) And( not GikoSys.FAbon.CheckIndividualAbonList(line))) then begin
1350                                                 DivideStrLine(tmp, @Res);
1351                                                 if (GikoSys.Setting.ShowMail = false) or (Length(res.FMailTo) = 0) then
1352                                                         Header := IntToStr(Line) + ' \96¼\91O\81F ' + Res.FName + ' \93\8a\8de\93ú\81F ' + Res.FDateTime
1353                                                 else
1354                                                         Header := IntToStr(Line) + ' \96¼\91O\81F ' + Res.FName + ' [' + res.FMailTo + '] \93\8a\8de\93ú\81F ' + Res.FDateTime;
1355
1356                                                 Body := DeleteFontTag(Res.FBody);
1357                                                 Body := CustomStringReplace(Body, '<br> ', #10,true);
1358                                                 Body := CustomStringReplace(Body, '<br>', #10,true);
1359                                                 Body := CustomStringReplace(Body, '</a>', '',true);
1360                                                 Body := THTMLCreate.DeleteLink(Body);
1361                                                 Body := CustomStringReplace(Body, '&lt;', '<');
1362                                                 Body := CustomStringReplace(Body, '&gt;', '>');
1363                                                 Body := CustomStringReplace(Body, '&quot;', '"');
1364                                                 Body := CustomStringReplace(Body, '&amp;', '&');
1365                                                  Body := CustomStringReplace(Body, '&nbsp;', ' ');
1366                                                 Hint.Add(Header, Body);
1367                                         end;
1368                                 end;
1369                         end;
1370                 end;
1371         finally
1372         end;
1373 end;
1374
1375 //\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é
1376 class function THTMLCreate.GetRespopupURL(AText, AThreadURL : string): string;
1377 var
1378         wkInt: Integer;
1379 begin
1380         Result := '';
1381         if Pos('about:blank..', AText) = 1 then begin
1382                 wkInt := LastDelimiter( '/', AThreadURL );
1383                 if Pos( '?', Copy( AThreadURL, wkInt, MaxInt ) ) = 0 then begin
1384                         // Thread.URL \82Í PATH_INFO \93n\82µ
1385                         Result := Copy( AThreadURL, 1,  LastDelimiter( '/', AThreadURL ) );
1386                         wkInt := LastDelimiter( '/', AText );
1387                         if Pos( '?', Copy( AText, wkInt, MaxInt ) ) = 0 then
1388                                 // Text \82à PATH_INFO \93n\82µ
1389                                 Result := Result + Copy( AText, LastDelimiter( '/', AText ) + 1, MaxInt )
1390                         else
1391                                 // Text \82Í QUERY_STRING \93n\82µ
1392                                 Result := Result + Copy( AText, LastDelimiter( '?', AText ) + 1, MaxInt );
1393                 end else begin
1394                         // Thread.URL \82Í QUERY_STRING \93n\82µ
1395                         Result := Copy( AThreadURL, 1,  LastDelimiter( '?', AThreadURL ) );
1396                         wkInt := LastDelimiter( '/', AText );
1397                         if Pos( '?', Copy( AText, wkInt, MaxInt ) ) = 0 then begin
1398                                 // Text \82Í PATH_INFO \93n\82µ
1399                                 // URL \82É\94Â\82Æ\83L\81[\82ª\91«\82ç\82È\82¢\82Ì\82Å Text \82©\82ç\92¸\91Õ\82·\82é
1400                                 wkInt := LastDelimiter( '/', Copy( AText, 1, wkInt - 1 ) );
1401                                 wkInt := LastDelimiter( '/', Copy( AText, 1, wkInt - 1 ) );
1402                                 Result := Copy( Result, 1, Length( Result ) - 1 ) + Copy( AText, wkInt, MaxInt );
1403                         end else begin
1404                                 // Text \82à QUERY_STRING \93n\82µ
1405                                 Result := Result + Copy( AText, LastDelimiter( '?', AText ) + 1, MaxInt )
1406                         end;
1407                 end;
1408         end else if Pos('about:blank/bbs/', AText) = 1 then begin
1409                 //\82µ\82½\82ç\82ÎJBBS\82Ì\8ed\95Ï\82Ì\8bz\8eû
1410                 AText := CustomStringReplace(AText, 'about:blank/bbs/', 'about:blank../../bbs/');
1411                 Result := GetRespopupURL(AText, AThreadURL);
1412         end else begin
1413                 Result := AText;
1414         end;
1415
1416 end;
1417 //\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é
1418 class procedure THTMLCreate.SkinorCSSFilesCopy(path: string);
1419 var
1420         tmp, tmpD, tmpF: string;
1421         current: string;
1422         dirs: TStringList;
1423         files: TStringList;
1424         i, j: Integer;
1425 begin
1426         if GikoSys.Setting.UseSkin then begin
1427                 current := ExtractFilePath(GikoSys.GetSkinDir);
1428                 tmp := GikoSys.Setting.CSSFileName;
1429         end else if GikoSys.Setting.UseCSS then begin
1430                 current := ExtractFilePath(GikoSys.GetStyleSheetDir);
1431                 tmp := ExtractFilePath(GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName);
1432         end else begin
1433         Exit;
1434     end;
1435         dirs := TStringList.Create;
1436         try
1437                 dirs.Add(tmp);
1438                 if tmp <> current then begin
1439                         GikoSys.GetDirectoryList(current, '*.*', dirs, true);
1440                         for i := 0 to dirs.Count - 1 do begin
1441                                 files := TStringList.Create;
1442                                 try
1443                                         files.BeginUpdate;
1444                                         gikoSys.GetFileList(dirs[i], '*.*', files, true);
1445                                         files.EndUpdate;
1446                                         tmpD := CustomStringReplace(dirs[i], GikoSys.GetConfigDir, path);
1447                                         if (AnsiPos(dirs[i], tmp) <> 0) and not (DirectoryExists(tmpD)) then
1448                                                 ForceDirectories(tmpD);
1449
1450                                         if(dirs[i] = tmp) and (dirs[i] <> current) then begin
1451                                                 for j := 0 to files.Count - 1 do begin
1452                                                         tmpF := CustomStringReplace(files[j], GikoSys.GetConfigDir, path);
1453                                                         if not FileExists(tmpF) then begin
1454                                                                 CopyFile(PChar(files[j]), PChar(tmpF),True);
1455                                                         end;
1456                                                 end;
1457                                         end;
1458                                 finally
1459                                         files.Free;
1460                                 end;
1461                         end;
1462                 end else begin
1463                         tmpD := CustomStringReplace(dirs[0], GikoSys.GetConfigDir, path);
1464                         if not DirectoryExists(tmpD) then
1465                                 ForceDirectories(tmpD);
1466                         tmpF := CustomStringReplace(GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName
1467                                         , GikoSys.GetConfigDir, path);
1468                         if not FileExists(tmpF) then begin
1469                                 CopyFile(PChar(GikoSys.GetStyleSheetDir + GikoSys.Setting.CSSFileName)
1470                                         , PChar(tmpF), True);
1471                         end;
1472                 end;
1473         finally
1474                 dirs.Free;
1475         end;
1476 end;
1477 {!
1478 \brief dat\83t\83@\83C\83\8b\82Ì\88ê\83\89\83C\83\93\82ð\95ª\89ð
1479 \param Line dat\83t\83@\83C\83\8b\82ð\8d\\90¬\82·\82é 1 \8ds
1480 \return     \83\8c\83X\8fî\95ñ
1481 }
1482 class procedure THTMLCreate.DivideStrLine(Line: string; PRes: PResRec);
1483 const
1484         delimiter = '<>';
1485 var
1486         pds, pde : PChar;
1487         pss, pse : PChar;
1488         ppos : PChar;
1489 begin
1490         //\8cÅ\92è
1491         PRes.FType := glt2chNew;
1492
1493         pss := PChar(Line);
1494         pse := pss + Length(Line);
1495         pds := PChar(delimiter);
1496         pde := pds + Length(delimiter);
1497
1498         ppos := AnsiStrPosEx(pss, pse, pds, pde);
1499         if (ppos = nil) then begin
1500                 Line := CustomStringReplace(Line, '<>', '&lt;&gt;');
1501                 Line := CustomStringReplace(Line, ',', '<>');
1502                 Line := CustomStringReplace(Line, '\81\97\81M', ',');
1503         end;
1504         //Trim\82µ\82Ä\82Í\82¢\82¯\82È\82¢\8bC\82ª\82·\82é\81@by\82à\82\82ã
1505         PRes.FName := RemoveToken(Line, delimiter);
1506         PRes.FMailTo := RemoveToken(Line, delimiter);
1507         PRes.FDateTime := RemoveToken(Line, delimiter);
1508         PRes.FBody := RemoveToken(Line, delimiter);
1509         //\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é
1510         //\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é
1511         PRes.FBody := TrimLeft(PRes.FBody);
1512         //\8bó\82¾\82Æ\96â\91è\82ª\8bN\82«\82é\82©\82ç\81A\8bó\94\92\82ð\90Ý\92è\82·\82é
1513         if PRes.FBody = '' then
1514                 PRes.FBody := '&nbsp;';
1515
1516         PRes.FTitle := RemoveToken(Line, delimiter);
1517 end;
1518
1519 {!
1520 \brief HTML \82©\82ç\83A\83\93\83J\81[\83^\83O\82ð\8dí\8f\9c
1521 \param s \8c³\82É\82È\82é HTML
1522 \return  \83A\83\93\83J\81[\83^\83O\82ª\8dí\8f\9c\82³\82ê\82½ HTML
1523 }
1524 class function THTMLCreate.DeleteLink(const s: string): string;
1525 var
1526         s1: string;
1527         s2: string;
1528         idx: Integer;
1529         i: Integer;
1530 begin
1531         i := 0;
1532         Result := '';
1533         while True do begin
1534                 s1 := GikoSys.GetTokenIndex(s, '<a href="', i);
1535                 s2 := GikoSys.GetTokenIndex(s, '<a href="', i + 1);
1536
1537                 idx := Pos('">', s1);
1538                 if idx <> 0 then
1539                         Delete(s1, 1, idx + 1);
1540                 idx := Pos('">', s2);
1541                 if idx <> 0 then
1542                         Delete(s2, 1, idx + 1);
1543
1544                 Result := Result + s1 + s2;
1545
1546                 if s2 = '' then
1547                         Break;
1548
1549                 inc(i, 2);
1550         end;
1551 end;
1552 {
1553 \brief  HTML\89»\82Ì\82½\82ß\82Ì\92u\8a·
1554 \param  s   \8c³\82É\82È\82é\95\8e\9a\97ñ
1555 \return HTML\82ÌinnerText\82Æ\82µ\82Ä\82ä\82é\82³\82ê\82é\95\8e\9a\97ñ
1556 }
1557 class function THTMLCreate.RepHtml(const s: string): string;
1558 begin
1559 //      s := StringReplace(s, '&', '&amp;', [rfReplaceAll]);
1560     Result := s;
1561         Result := CustomStringReplace(Result, '<', '&lt;');
1562         Result := CustomStringReplace(Result, '>', '&gt;');
1563 //      s := StringReplace(s, ' ', '&nbsp;', [rfReplaceAll]);   //\8ed\97l\95Ï\8dX\82É\82æ\82è&nbsp;\8eg\97p\95s\89Â
1564         Result := CustomStringReplace(Result, '"', '&quot;');
1565 end;
1566 {
1567 \brief  \83\8c\83X\83G\83f\83B\83^\82Å\82Ì\83v\83\8c\83r\83\85\81[\97pHTML\8dì\90¬
1568 \param  Title   \83X\83\8c\83b\83h\83^\83C\83g\83\8b
1569 \param  No  \83\8c\83X\94Ô\8d\86
1570 \param  Mail    \83\81\81[\83\8b\97\93
1571 \param  Name    \96¼\91O\97\93
1572 \param  Body    \96{\95
1573 \return \83v\83\8c\83r\83\85\81[\97pHTML
1574 }
1575 class function THTMLCreate.CreatePreviewHTML(
1576         const Title: string;
1577         const No: string;
1578         const Mail: string;
1579         const Namae: string;
1580         const Body: string
1581 ) : string;
1582 var
1583     posTrip : Integer;
1584     tripOrigin : string;
1585     NameWithTrip: string;
1586     DateTime: string;
1587 begin
1588         Result := '<HTML><HEAD>'#13#10
1589                         + '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">'#13#10
1590                         + '<TITLE>' + title + '</TITLE>'#13#10
1591                         + '</HEAD>'#13#10
1592                         + '<BODY text="#000000" bgcolor="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">'#13#10
1593                         + '<FONT COLOR="#FF0000">' + title + '</FONT>'#13#10
1594                         + '<DL>'#13#10;
1595
1596         DateTime := FormatDateTime('yyyy/mm/dd(aaa) hh:nn', Now());
1597
1598     NameWithTrip := Namae;
1599     posTrip := AnsiPos( '#', Namae );
1600     if posTrip > 0 then begin
1601         tripOrigin := Copy( Namae, posTrip + 1, Length( Namae ) );
1602         NameWithTrip := Copy( Namae, 1, posTrip - 1 ) + '</B> \81\9f' +
1603                     get_2ch_trip( PChar( tripOrigin ) ) + '<B>';
1604     end;
1605     if Mail = '' then begin
1606         Result := Result + '<DT>' + No + ' \81F <FONT color="forestgreen"><B>' + NameWithTrip
1607                  + '</B></FONT> \81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10
1608     end else begin
1609                 Result := Result + '<DT>' + No + ' \81F <A href="mailto:' + Mail + '"><B>' + NameWithTrip
1610                  + '</B></A> [' + Mail + ']\81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10;
1611     end;
1612         Result := Result + '</BODY></HTML>';
1613
1614 end;
1615 {
1616 \brief  \95\\8e¦\94Í\88Í\8aO\83\8c\83X\94Ô\8d\86\94»\92è\8f\88\97\9d
1617 \param  item    \95\\8e¦\83X\83\8c\83b\83h
1618 \param  index   \83\8c\83X\94Ô\8d\86
1619 \return ture:\95\\8e¦\94Í\88Í\8aO false:\95\\8e¦\94Í\88Í\93à
1620 }
1621 function THTMLCreate.isOutsideRange( item: TThreadItem; index: Integer ): Boolean;
1622 begin
1623     Result := False;
1624     // \95\\8e¦\94Í\88Í\82ð\8cÀ\92è
1625     case GikoSys.ResRange of
1626     Ord( grrKoko ):
1627         if item.Kokomade > (index + 1) then
1628             Result := True;
1629     Ord( grrNew ):
1630         if item.NewReceive > (index + 1) then
1631             Result := True;
1632     10..65535:
1633         if (GikoSys.Setting.HeadResCount) < (index + 1)  then begin
1634             if (item.Count - index) > GikoSys.ResRange then begin
1635                 Result := True;
1636             end;
1637         end;
1638     end;
1639 end;
1640 constructor TBufferedWebBrowser.Create(Browser: TWebBrowser; BuffSize: Integer);
1641 begin
1642         inherited Create;
1643         Self.Sorted := False;
1644         if (Browser = nil) then
1645                 Raise  Exception.Create('Browser is NULL');
1646         FBrowser := Browser;
1647
1648         // \83o\83b\83t\83@\82·\82é\8ds\90\94\82ð
1649         if (BuffSize < 0) then begin
1650                 FBuffSize := 100;
1651         end else begin
1652                 FBuffSize := BuffSize;
1653         end;
1654         Self.Capacity := FBuffSize + 10;
1655 end;
1656 procedure TBufferedWebBrowser.Open;
1657 begin
1658         FBrowserDoc := Idispatch( olevariant(FBrowser.ControlInterface).Document);
1659         FBrowserDoc.open;
1660         FBrowserDoc.charset := 'Shift_JIS';
1661 end;
1662 procedure TBufferedWebBrowser.Close;
1663 begin
1664         Self.Flush;
1665         try
1666                 FBrowserDoc.Close;
1667         except
1668         end;
1669         FBrowser := nil;
1670 end;
1671 function TBufferedWebBrowser.Add(const S: string): Integer;
1672 begin
1673         Result := inherited Add(TrimRight(s));
1674         if (Self.Count > FBuffSize) then begin
1675                 FBrowserDoc.Write(Self.Text);
1676                 Self.Clear;
1677         end;
1678 end;
1679 procedure TBufferedWebBrowser.Flush ;
1680 begin
1681         if (Self.Count > 0) then begin
1682                 FBrowserDoc.Write(Self.Text);
1683                 Self.Clear;
1684         end;
1685 end;
1686 destructor TBufferedWebBrowser.Destory;
1687 begin
1688         try
1689                 if (FBrowserDoc <> 0) then begin
1690                         FBrowserDoc.close;
1691                         FBrowserDoc := 0;
1692                 end;
1693         except
1694         end;
1695         inherited;
1696 end;
1697 //! \8aÖ\98A\83L\81[\83\8f\81[\83h\83\8a\83\93\83N\8fo\97Í
1698 function THTMLCreate.getKeywordLink(item: TThreadItem): String;
1699 const
1700     PARA_URL = 'http://p2.2ch.io/getf.cgi?';
1701 begin
1702     Result := '';
1703     if (GikoSys.Setting.AddKeywordLink) and (item.ParentBoard.Is2ch) then begin
1704         Result := '<p><span id="keyword"><a href="' + PARA_URL
1705             + item.URL + '" target="_blank">\8aÖ\98A\83L\81[\83\8f\81[\83h</a></span></p>';
1706     end;
1707 end;
1708 initialization
1709          HTMLCreater := THTMLCreate.Create;
1710
1711 finalization
1712         if HTMLCreater <> nil then begin
1713                 HTMLCreater.Free;
1714                 HTMLCreater := nil;
1715         end;
1716
1717 end.