OSDN Git Service

bf3d8544380a95520080f8964c71284e4cfe64e1
[gikonavigoeson/gikonavi.git] / Editor.pas
1 unit Editor;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
7         Dialogs, StdCtrls, ComCtrls, ExtCtrls, ToolWin, Menus, OleCtrls, Registry,
8 {$IF Defined(DELPRO) }
9         SHDocVw,
10         MSHTML,
11 {$ELSE}
12         SHDocVw_TLB,
13         MSHTML_TLB,
14 {$IFEND}
15         ActiveX, {HTTPApp,} YofUtils, Trip, IniFiles, StrUtils,
16         GikoSystem, GikoUtil, ImgList, Clipbrd, BoardGroup,
17         IdAntiFreezeBase,       IdAntiFreeze, IdBaseComponent, IdComponent,
18         IdTCPConnection, IdTCPClient, IdHTTP, ActnList, StdActns, IdIntercept,
19         IdLogBase, IdLogDebug, IdException, DateUtils, MojuUtils, bmRegExp;
20
21 type
22 //      TSetLayeredWindowAttributes = function(wnd: HWND; crKey: DWORD; bAlpha: BYTE; dwFlag: DWORD): Boolean; stdcall;
23         //\8f\91\82«\8d\9e\82Ý\96ß\82è\92l\83^\83C\83v
24         TGikoResultType = (grtOK, grtCookie, grtCheck, grtError);
25
26         TEditorForm = class(TForm)
27                 MainMenu: TMainMenu;
28                 FileMenu: TMenuItem;
29                 PostMessage: TMenuItem;
30                 SaveMessage: TMenuItem;
31                 CloseMenu: TMenuItem;
32                 N01: TMenuItem;
33                 StatusBar: TStatusBar;
34         EditorPage: TPageControl;
35                 EditorTab: TTabSheet;
36                 PreviewTab: TTabSheet;
37                 Browser: TWebBrowser;
38                 EditMenu: TMenuItem;
39                 UndoMenu: TMenuItem;
40                 CutMenu: TMenuItem;
41                 CopyMenu: TMenuItem;
42                 PasteMenu: TMenuItem;
43                 N02: TMenuItem;
44                 ToolBarImageList: TImageList;
45                 HotToobarImageList: TImageList;
46                 BodyEdit: TMemo;
47                 NameBasePanel: TPanel;
48                 NameLabel: TLabel;
49                 MailLabel: TLabel;
50                 NameComboBox: TComboBox;
51                 MailComboBox: TComboBox;
52                 ToolBar: TToolBar;
53                 SendToolButton: TToolButton;
54                 OutBoxToolButton: TToolButton;
55                 ToolButton5: TToolButton;
56                 UndoToolButton: TToolButton;
57                 CutToolButton: TToolButton;
58                 CopyToolButton: TToolButton;
59                 PasteToolButton: TToolButton;
60                 ToolButton3: TToolButton;
61                 TransToolButton: TToolButton;
62                 TopToolButton: TToolButton;
63                 Indy: TIdHTTP;
64                 IdAntiFreeze: TIdAntiFreeze;
65                 ToolButton1: TToolButton;
66                 ToolButton2: TToolButton;
67                 ActionList: TActionList;
68                 SendAction: TAction;
69                 SaveAction: TAction;
70                 CloseAction: TAction;
71                 UndoAction: TAction;
72                 CutAction: TAction;
73                 CopyAction: TAction;
74                 PasteAction: TAction;
75                 AbortAction: TAction;
76                 TopAction: TAction;
77                 Show1: TMenuItem;
78                 T1: TMenuItem;
79                 N1: TMenuItem;
80                 S1: TMenuItem;
81                 SageCheckBox: TCheckBox;
82                 IdLogDebug: TIdLogDebug;
83                 TransAction: TAction;
84                 A1: TMenuItem;
85                 KotehanCheckBox: TCheckBox;
86                 TitlePanel: TPanel;
87                 Label1: TLabel;
88                 TitleEdit: TEdit;
89                 SelectAllAction: TAction;
90                 N2: TMenuItem;
91                 SelectAll1: TMenuItem;
92         Timer1: TTimer;
93         QuotePasteAction: TAction;
94         QuotePasteMenuItem: TMenuItem;
95         C1: TMenuItem;
96         SpaceToNBSPAction: TAction;
97         AmpToCharRefAction: TAction;
98         SpaceTabnbsp1: TMenuItem;
99         amp1: TMenuItem;
100         BoardInformationTab: TTabSheet;
101                                 BoardtopTab: TTabSheet;
102         TitlePictureBrowser: TWebBrowser;
103         BoardTop: TMenuItem;
104         BoardInformationMemo: TMemo;
105         GetSETTINGTXTAction: TAction;
106         N3: TMenuItem;
107         SETTINGTXT2: TMenuItem;
108         GetTitlePictureAction: TAction;
109         OP1: TMenuItem;
110     GetHeadTXTAction: TAction;
111     HeadTXT1: TMenuItem;
112     RocalRuleTab: TTabSheet;
113     WebBrowser1: TWebBrowser;
114     CalcCapasityAction: TAction;
115     N4: TMenuItem;
116     N5: TMenuItem;
117     Rule: TMenuItem;
118     LocalEdit: TMemo;
119
120                 procedure EditorPageChange(Sender: TObject);
121                 procedure FormCreate(Sender: TObject);
122                 procedure BrowserStatusTextChange(Sender: TObject;
123                         const Text: WideString);
124                 procedure FormClose(Sender: TObject; var Action: TCloseAction);
125                 procedure FormDestroy(Sender: TObject);
126                 procedure SendActionExecute(Sender: TObject);
127                 procedure SaveActionExecute(Sender: TObject);
128                 procedure AbortActionExecute(Sender: TObject);
129                 procedure CloseActionExecute(Sender: TObject);
130                 procedure UndoActionExecute(Sender: TObject);
131                 procedure CutActionExecute(Sender: TObject);
132                 procedure CopyActionExecute(Sender: TObject);
133                 procedure PasteActionExecute(Sender: TObject);
134                 procedure SendActionUpdate(Sender: TObject);
135                 procedure SaveActionUpdate(Sender: TObject);
136                 procedure CloseActionUpdate(Sender: TObject);
137                 procedure UndoActionUpdate(Sender: TObject);
138                 procedure CutActionUpdate(Sender: TObject);
139                 procedure CopyActionUpdate(Sender: TObject);
140                 procedure PasteActionUpdate(Sender: TObject);
141                 procedure TopActionExecute(Sender: TObject);
142                 procedure TopActionUpdate(Sender: TObject);
143                 procedure SageCheckBoxClick(Sender: TObject);
144                 procedure MailComboBoxChange(Sender: TObject);
145                 procedure TransActionExecute(Sender: TObject);
146                 procedure TransActionUpdate(Sender: TObject);
147                 procedure IdLogDebugReceive(ASender: TIdConnectionIntercept;
148                         AStream: TStream);
149                 procedure IdLogDebugSend(ASender: TIdConnectionIntercept;
150                         AStream: TStream);
151                 procedure SelectAllActionExecute(Sender: TObject);
152         procedure StatusBarResize(Sender: TObject);
153         procedure Timer1Timer(Sender: TObject);
154         procedure FormActivate(Sender: TObject);
155         procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
156                 procedure QuotePasteActionExecute(Sender: TObject);
157         procedure SpaceToNBSPActionExecute(Sender: TObject);
158         procedure AmpToCharRefActionExecute(Sender: TObject);
159         procedure BoardTopClick(Sender: TObject);
160         procedure GetSETTINGTXTActionExecute(Sender: TObject);
161         procedure GetTitlePictureActionUpdate(Sender: TObject);
162         procedure GetTitlePictureActionExecute(Sender: TObject);
163     procedure GetHeadTXTActionExecute(Sender: TObject);
164     procedure CalcCapasityActionExecute(Sender: TObject);
165     procedure RuleClick(Sender: TObject);
166     procedure FormDeactivate(Sender: TObject);
167         private
168                 FThreadItem: TThreadItem;
169                 FBoard: TBoard;
170                 FNameComboEdit: THandle;
171                 FMailComboEdit: THandle;
172                 FAbort: Boolean;
173                 FWork: Boolean;
174                 FStatusCode: Integer;
175                 FDebugStrReceive: string;
176                 FDebugStrSend: string;
177                 FSambaTime: TDateTime;
178                 FHost: string;
179                 FNow: TDateTime;
180                 procedure Preview;
181                 function RepHtml(s: string): string;
182                 function Check: Boolean;
183                 procedure SetNameList(sName, sMail: string);
184 //              procedure Send(SendType: TGikoSendType; SPID: string; PON: string; FirstWriting: Boolean);
185                 procedure Send(SPID: string; PON: string; FirstWriting: Boolean);
186
187                 function GetActiveControlHandle: THandle;
188 //              function GetSendData: string;
189 //              procedure GetSendData(Source: TStringStream);
190                 procedure GetSendData(Source: TStringStream);
191                 procedure SaveSendFile;
192                 procedure SetContent(Content: string; ABrowser: TWebBrowser);
193                 function GetSPID(CookieLine: string): string;
194                 function GetPON(CookieLine: string): string;
195                 function GetResultType(ResponseText: string): TGikoResultType;
196                 procedure ReadSambaTime(const AHost: string);
197                 procedure WriteSambaTime(const AHost: string; ATime: TDateTime);
198                 function ReadSettingTime(const AHost: string): Integer;
199                 function CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
200                                 procedure SetSamba24(AURL: string);
201                 /// \88ø\97p\95\84\82Ì\8eæ\93¾
202                 function GetOEIndentChar : string;
203                 /// \96{\95\82Ì\8eæ\93¾
204                 function GetBody : string;
205                 //IdHttp\82Ì\8f\89\8aú\89»
206                 procedure InitIdHTTP(http: TIdHTTP);
207                 procedure ShowBoardInformation(ABoard: TBoard; AMemo: TMemo);
208                 function GetTitlePictureURL(body: TStringList; ABoard: TBoard): string;
209                 procedure ShowTitlePicture();
210                                 function GetFusianaName(body: TStringList; ABoard: TBoard): String;
211                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8aJ\8en
212                 procedure OnGestureStart(Sender: TObject);
213                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\92\86
214                 procedure OnGestureMove(Sender: TObject);
215                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8fI\97¹
216                 procedure OnGestureEnd(Sender: TObject);
217                 //HEAD.TXT\8e©\93®\95\\8e¦
218                 procedure ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
219         protected
220                 procedure CreateParams(var Params: TCreateParams); override;
221         public
222                                 FBBSID: String;
223                 procedure SetFont;
224                 procedure SetThreadItem(Item: TThreadItem);
225                 procedure SetBoard(Item: TBoard);
226                                 property BBSID: string read FBBSID write FBBSID;
227
228         end;
229
230 implementation
231
232 uses
233         Giko, ItemDownload, Gesture;
234 const
235         CAPTION_NAME_NEW: string = '\83M\83R\83i\83\83X\83\8c\97§\82Ä\83G\83f\83B\83^';
236         CAPTION_NAME_RES: string = '\83M\83R\83i\83\83\8c\83X\83G\83f\83B\83^';
237
238     // \83G\83f\83B\83b\83g\83E\83B\83\93\83h\83E\82ð\89E\89º\82É\82¸\82ç\82µ\82Ä\8aJ\82­\88Ú\93®\97Ê
239     WINDOWMOVE_H = 30;
240     WINDOWMOVE_V = 30;
241
242         //DAX\82³\82ñ±Ø¶ÞÄ!(\81L\81¤\81M)
243         READCGI_ERR                     = '-ERR';
244         READCGI_INCR            = '-INCR';
245         READCGI_OK                      = '+OK';
246         READCGI_PARTIAL = '+PARTIAL';
247         READCGI_ERR_FOUND_KAKO  = '-ERR \89ß\8b\8e\83\8d\83O\91q\8cÉ\82Å\94­\8c©';
248         READCGI_ERR_NOT_HTML            = '-ERR html\89»\91Ò\82¿';
249         READCGI_ERR_NOT_FOUND           = '-ERR \82»\82ñ\82È\94Âor\83X\83\8c\83b\83h\82È\82¢\82Å\82·\81B';
250         READCGI_ERR_ABONE                               = '-ERR \82Ç\82±\82©\82Å\82 \82Ú\81[\82ñ\82ª\82 \82Á\82½\82Ý\82½\82¢\82Å\82·\81B';
251         READCGI_ERR_TIMEOUT                     = '-ERR \8ew\92è\8e\9e\8aÔ\82ª\89ß\82¬\82Ü\82µ\82½\81B';
252         READCGI_ERR_CANTUSE                     = '-ERR \82à\82¤\81@\82Â\82©\82¦\82Ü\82¹\82ñ';
253         RES2CH_TRUE                             = '<!-- 2ch_X:true -->';
254         RES2CH_FALSE                    = '<!-- 2ch_X:false -->';
255         RES2CH_ERROR                    = '<!-- 2ch_X:error -->';
256         RES2CH_CHECK                    = '<!-- 2ch_X:check -->';
257         RES2CH_COOKIE                   = '<!-- 2ch_X:cookie -->';
258
259
260         BBS2CH_NAME:                                     string = '\82Q\82¿\82á\82ñ\82Ë\82é';
261         BBS2CH_LOG_FOLDER:               string = '2ch';
262         EXTERNAL_LOG_FOLDER:            string  = 'exboard';
263
264         FOLDER_INI_FILENAME:     string = 'Folder.ini';
265         FOLDER_INDEX_FILENAME: string   = 'Folder.idx';
266         SUBJECT_FILENAME:                       string  = 'subject.txt';
267         PATH_DELIM:                                             string  = '\';
268
269
270 type
271         TSelection = record
272                 StartPos, EndPos: Integer;
273         end;
274
275 {$R *.DFM}
276
277 {constructor TEditorForm.Create(AOwner: TComponent; Item: TBoard);
278 begin
279         inherited Create(AOwner);
280 end;}
281
282 procedure TEditorForm.CreateParams(var Params: TCreateParams);
283 begin
284         inherited;
285         if FormStyle in [fsNormal, fsStayOnTop] then
286                 if BorderStyle in [bsSingle, bsSizeable] then begin
287                         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
288                         Params.WndParent := 0;
289                 end;
290 end;
291
292 {procedure TEditorForm.CreateParams(var Params: TCreateParams);
293 begin
294         inherited CreateParams(Params);
295         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
296 end;}
297
298 procedure TEditorForm.FormCreate(Sender: TObject);
299 var
300         wp: TWindowPlacement;
301                 hUser32 : HINST;
302         ini: TIniFile;
303 begin
304         FWork := False;
305         Browser.Navigate('about:blank');
306         TitlePictureBrowser.Navigate('about:blank');
307         FBoard := nil;
308         FThreadItem := nil;
309
310         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
311         wp.length := sizeof(wp);
312         wp.rcNormalPosition.Top := GikoSys.Setting.EditWindowTop;
313         wp.rcNormalPosition.Left := GikoSys.Setting.EditWindowLeft;
314
315         wp.rcNormalPosition.Bottom := GikoSys.Setting.EditWindowTop + GikoSys.Setting.EditWindowHeight;
316         wp.rcNormalPosition.Right := GikoSys.Setting.EditWindowLeft + GikoSys.Setting.EditWindowWidth;
317         wp.showCmd := SW_HIDE;
318         SetWindowPlacement(Handle, @wp);
319
320         if GikoSys.Setting.EditWindowMax then
321                 WindowState := wsMaximized;
322
323         //\83E\83B\83\93\83h\83E\82ª\89æ\96Ê\8aO\82È\82ç\89æ\96Ê\93à\82É\88Ú\93®\82·\82é
324         if (Left + Width) > Screen.Width then
325 //              Left := Screen.Width - Width;
326                 Left := 0;
327         if (Top + Height) > Screen.Height then
328 //              Top := Screen.Height - Height;
329                 Top := 0;
330         if Left < 0 then
331                 Left := 0;
332         if Top < 0 then
333                 Top := 0;
334
335     //\8c»\8dÝ\82Ì\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\82ð\95Û\91
336     GikoSys.Setting.EditWindowTop := Top  + WINDOWMOVE_V;   // \8e\9f\82É\8aJ\82­\83E\83B\83\93\83h\83E\82Í
337     GikoSys.Setting.EditWindowLeft := Left + WINDOWMOVE_H;  // \81@\81@\81@\89E\8eÎ\82ß\89º\82É\82¸\82ç\82·
338     //\83E\83B\83\93\83h\83E\82Ì\95\9d\82Æ\8d\82\82³\82ª\8f¬\82³\82·\82¬\82¢\82ê\82Î\8c³\82É\96ß\82·
339         if GikoSys.Setting.EditWindowHeight < 144 then
340                 Height := 400;
341         if GikoSys.Setting.EditWindowWidth < 144 then
342                 Width := 640;
343
344         EditorPage.ActivePage := EditorTab;
345         FNameComboEdit := GetWindow(NameComboBox.Handle, GW_CHILD);
346         FMailComboEdit := GetWindow(MailComboBox.Handle, GW_CHILD);
347         NameComboBox.Items.Assign(GikoSys.Setting.NameList);
348         MailComboBox.Items.Assign(GikoSys.Setting.MailList);
349         SetFont;
350         hUser32 := 0;
351         try
352                 try
353                         hUser32 := LoadLibrary('User32.dll');
354                         if hUser32 <> 0 then
355                                 TransAction.Enabled := true
356                         else
357                                 TransAction.Enabled := false;
358                 except
359                 TransAction.Enabled := false;
360                 end;
361         finally
362                 FreeLibrary(hUser32);
363         end;
364
365     // \83E\83B\83\93\83h\83E\82Ì\83X\83e\83C\8fó\91Ô
366         if GikoSys.Setting.EditWindowStay then begin    // \83X\83e\83C\8fó\91Ô
367                 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
368                 TopAction.Checked := true;
369                 TopToolButton.Down := true;
370         end else begin                                  // \83X\83e\83C\82µ\82È\82¢
371                 SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
372                 TopAction.Checked := false;
373                 TopToolButton.Down := false;
374         end;
375
376     // \83E\83B\83\93\83h\83E\82Ì\94¼\93§\96¾\8fó\91Ô
377         if(GikoSys.Setting.EditWindowTranslucent) and (TransAction.Enabled) then begin // \94¼\93§\96¾\81i\83g\83\89\83\93\83X\83\8b\81[\83Z\83\93\83g\81j\8fó\91Ô
378         AlphaBlend := true;
379         TransAction.Checked := true;
380         TransToolButton.Down := true;
381     end else begin                                      // \95s\93§\96¾
382         AlphaBlend := false;
383         TransAction.Checked := false;
384         TransToolButton.Down := false;
385     end;
386         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
387         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
388
389         SpaceToNBSPAction.Checked               := GikoSys.Setting.SpaceToNBSP;
390         AmpToCharRefAction.Checked      := GikoSys.Setting.AmpToCharRef;
391
392                 ini := TIniFile.Create(GikoSys.Setting.GetFileName);
393
394                 try
395                         BoardtopTab.TabVisible := ini.Readbool('EditorForm', 'BoardTopTab', False);
396                         BoardTop.Checked := BoardtopTab.TabVisible;
397                         RocalRuleTab.TabVisible := ini.Readbool('EditorForm', 'RocalRureTab', False);
398                         HeadTXT1.Checked := RocalRuleTab.TabVisible;
399                 finally
400                         ini.Free;
401                 end;
402
403         // \83}\83E\83X\83W\83F\83X\83`\83\83\81[\82Ì\83C\83\93\83X\83g\81[\83\8b
404         if GikoSys.Setting.GestureEnabled then begin
405                 MouseGesture.UnHook;
406                 MouseGesture.OnGestureStart := OnGestureStart;
407                 MouseGesture.OnGestureMove := OnGestureMove;
408                 MouseGesture.OnGestureEnd := OnGestureEnd;
409                 MouseGesture.SetHook( Handle );
410         end;
411
412 end;
413
414 procedure TEditorForm.SetBoard(Item: TBoard);
415 begin
416         FBoard := Item;
417         Caption := CAPTION_NAME_NEW + ' - [' + Item.Title + ']';
418         NameComboBox.Text := FBoard.KotehanName;
419         MailComboBox.Text := FBoard.KotehanMail;
420         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
421         TitlePanel.Visible := True;
422         SetSamba24(FBoard.URL);
423         ShowBoardInformation(FBoard, BoardInformationMemo);
424         ShowTitlePicture();
425 end;
426
427 procedure TEditorForm.SetThreadItem(Item: TThreadItem);
428 begin
429         FThreadItem := Item;
430         Caption := CAPTION_NAME_RES + ' - [' + FThreadItem.Title + ']';
431         NameComboBox.Text := FThreadItem.ParentBoard.KotehanName;
432         MailComboBox.Text := FThreadItem.ParentBoard.KotehanMail;
433         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
434         TitlePanel.Visible := False;
435         SetSamba24(FThreadItem.ParentBoard.URL);
436         ShowBoardInformation(FThreadItem.ParentBoard, BoardInformationMemo);
437         ShowTitlePicture();
438 end;
439
440 function TEditorForm.GetBody : string;
441 var
442         body, tmp               : string;
443         p, tail                 : PChar;
444         len                                     : Integer;
445 const
446         TAB_LENGTH      = 4;
447 begin
448
449         body := BodyEdit.Text;
450         if AmpToCharRefAction.Checked then
451                 // & \82Ì\92u\8a·\82Í\88ê\94Ô\8dÅ\8f\89\82É\82â\82é\82±\82Æ
452                 body := CustomStringReplace( body, '&', '&amp;' );
453         if SpaceToNBSPAction.Checked then begin
454                 p                       := PChar( body );
455                 tail    := p + Length( body );
456                 len             := 0;
457                 while p < tail do begin
458                         case p^ of
459                         #09:
460                                 begin
461                                         Inc( p );
462                                         repeat
463                                                 Inc( len );
464                                                 tmp := tmp + '&nbsp;';
465                                         until (len mod TAB_LENGTH) = 0;
466                                 end;
467
468                         #10, #13:
469                                 begin
470                                         tmp := tmp + p^;        Inc( p );
471                                         len     := 0;
472                                 end;
473
474                         ' ':
475                                 begin
476                                         tmp     := tmp + '&nbsp;';
477                                         Inc( p );
478                                         Inc( len );
479                                 end;
480                                 
481                         '&':
482                                 // \8eÀ\91Ì\8eQ\8fÆ\82Í 1 \95\8e\9a\95ª
483                                 begin
484                                         tmp := tmp + '&';
485                                         Inc( p );
486                                         Inc( len );
487                                         while p < tail do begin
488                                                 if p^ in ['a'..'z', 'A'..'Z', '0'..'9', '#'] then begin
489                                                         tmp := tmp + p^;
490                                                 end else if p^ = ';' then begin
491                                                         tmp := tmp + p^;
492                                                         Inc( p );
493                                                         Break;
494                                                 end else begin
495                                                         Break;
496                                                 end;
497                                                 Inc( p );
498                                         end;
499                                 end;
500
501                         else
502                                 if p^ in kYofKanji then begin
503                                         tmp := tmp + p^;        Inc( p );
504                                         tmp     := tmp + p^;    Inc( p );
505                                         len     := len + 2;
506                                 end else begin
507                                         tmp := tmp + p^;        Inc( p );
508                                         Inc( len );
509                                 end;
510                         end;
511                 end;
512                 body := tmp;
513         end;
514
515         Result  := body;
516
517 end;
518
519 procedure TEditorForm.SetFont;
520 begin
521         BodyEdit.Font.Name := GikoSys.Setting.EditorFontName;
522         BodyEdit.Font.Size := GikoSys.Setting.EditorFontSize;
523         BodyEdit.Font.Color := GikoSys.Setting.EditorFontColor;
524         BodyEdit.Color := GikoSys.Setting.EditorBackColor;
525 end;
526
527 procedure TEditorForm.Preview;
528 var
529         Title: string;
530         No: string;
531         Mail: string;
532         Namae: string;
533         DateTime: string;
534         Body: string;
535         s: string;
536
537                                 posTrip : Integer;
538                                 tripOrigin : string;
539 begin
540         if FThreadItem = nil then begin
541                 No := '1';
542                 Title := RepHtml(TitleEdit.Text);
543         end else begin
544                 No := IntToStr(FThreadItem.Count + 1);
545                 Title := RepHtml(FThreadItem.Title);
546         end;
547
548         body := GetBody;
549         Namae := RepHtml(NameComboBox.Text);
550         Mail := RepHtml(MailComboBox.Text);
551         Body := RepHtml(body);
552         Body := StringReplace(Body, #13#10, '<br>', [rfReplaceAll]);
553         DateTime := FormatDateTime('yyyy/mm/dd(aaa) hh:nn', now);
554
555         if Trim(Namae) = '' then
556                 Namae := '\96¼\96³\82µ\82³\82ñ';
557
558         s := '<HTML><HEAD>' + #13#10
559                         + '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">' + #13#10
560                         + '<TITLE>' + title + '</TITLE>' + #13#10
561 //                      + '<STYLE><!--BODY{font-size : 9pt;font-family : "\82l\82\82o\83S\83V\83b\83N";}--></STYLE>' + #13#10
562                         + '</HEAD>' + #13#10
563                         + '<BODY text="#000000" bgcolor="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">' + #13#10
564                         + '<FONT COLOR="#FF0000">' + title + '</FONT>' + #13#10
565                         + '<DL>' + #13#10;
566                                 posTrip := AnsiPos( '#', Namae );
567                                 if posTrip > 0 then
568                                 begin
569                                                                 tripOrigin := Copy( Namae, posTrip + 1, Length( Namae ) );
570                                                                 Namae :=
571                                                                                                 Copy( Namae, 1, posTrip - 1 ) + '</B> \81\9f' +
572                                                                                                 get_2ch_trip( PChar( tripOrigin ) ) + '<B>';
573                                 end;
574         if Mail = '' then
575                 s := s + '<DT>' + No + ' \81F <FONT color="forestgreen"><B>' + Namae + '</B></FONT> \81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10
576         else
577                 s := s + '<DT>' + No + ' \81F <A href="mailto:' + Mail + '"><B>' + Namae + '</B></A> [' + Mail + ']\81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10;
578         s := s + '</BODY></HTML>';
579         SetContent(s, Browser);
580 end;
581
582 function TEditorForm.RepHtml(s: string): string;
583 begin
584 //      s := StringReplace(s, '&', '&amp;', [rfReplaceAll]);
585         s := StringReplace(s, '<', '&lt;', [rfReplaceAll]);
586         s := StringReplace(s, '>', '&gt;', [rfReplaceAll]);
587 //      s := StringReplace(s, ' ', '&nbsp;', [rfReplaceAll]);   //\8ed\97l\95Ï\8dX\82É\82æ\82è&nbsp;\8eg\97p\95s\89Â
588         s := StringReplace(s, '"', '&quot;', [rfReplaceAll]);
589         Result := s;
590 end;
591
592 procedure TEditorForm.EditorPageChange(Sender: TObject);
593 var
594         tmpBoard: TBoard;
595 begin
596         if FThreadItem = nil then
597                 tmpBoard := FBoard
598         else
599                 tmpBoard := FThreadItem.ParentBoard;
600
601         if tmpBoard = nil then Exit;
602
603         if EditorPage.ActivePage = PreviewTab then begin
604                 Preview;
605         end else if EditorPage.ActivePage = RocalRuleTab then begin
606                 ShowBoardHead(tmpBoard, LocalEdit);
607         end else begin
608                 Browser.Navigate('about:blank');
609         end;
610 end;
611
612 procedure TEditorForm.BrowserStatusTextChange(Sender: TObject;
613         const Text: WideString);
614 begin
615         if EditorPage.ActivePage = PreviewTab then begin
616                 StatusBar.Panels[0].Text := Text;
617         end else begin
618                 StatusBar.Panels[0].Text := '';
619         end;
620 end;
621
622 function TEditorForm.Check: Boolean;
623 var
624         Msg: string;
625         rc: Integer;
626         Board: TBoard;
627 begin
628         Result := True;
629         if FThreadItem = nil then
630                 Board := FBoard
631         else
632                 Board := FThreadItem.ParentBoard;
633
634         if (not GikoSys.Setting.UseMachineTime) and
635                  ((Board.LastGetTime = 0) or
636                         (Board.LastGetTime = ZERO_DATE)) then begin
637                 Msg := '\83T\81[\83o\82Ì\8e\9e\8d\8f\82ª\95ª\82©\82ç\82È\82¢\82½\82ß\81A\91\97\90M\8fo\97\88\82Ü\82¹\82ñ'#13#10
638                                  + '\83X\83\8c\83b\83h\82ð\8dX\90V\81i\8eæ\93¾\81j\8cã\81A15\95b\91Ò\82Á\82Ä\82©\82ç\91\97\90M\82µ\82Ä\82­\82¾\82³\82¢';
639                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
640                 Result := False;
641         end else if BodyEdit.Text = '' then begin
642                 Msg := '\96{\95\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
643                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
644                 Result := False;
645         end else if (FBoard <> nil) and (Trim(TitleEdit.Text) = '') then begin
646                 Msg := '\83^\83C\83g\83\8b\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
647                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
648                 Result := False;
649         end else begin
650                 if (not GikoSys.Dolib.Connected) and (AnsiPos('\81\9c', NameComboBox.Text) <> 0) then begin
651                         Msg := '\83\8d\83O\83C\83\93\82µ\82Ä\82¢\82È\82¢\82Ì\82Å\81\9c\82Ì\8b@\94\\82Í\97\98\97p\8fo\97\88\82Ü\82¹\82ñ\81B'#13#10
652                                          + '\82±\82Ì\82Ü\82Ü\91\97\90M\82µ\82Ä\82à\82æ\82ë\82µ\82¢\82Å\82·\82©\81H';
653                         rc := MsgBox(Handle, Msg, '\8am\94F', MB_YESNO or MB_ICONQUESTION);
654                         Result := (rc = IDYES);
655                 end;
656         end;
657 end;
658
659 procedure TEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
660 begin
661         Action := caFree;
662 end;
663
664 procedure TEditorForm.FormDestroy(Sender: TObject);
665 var
666         wp: TWindowPlacement;
667 begin
668         //\8dÅ\91å\89»\81E\83E\83B\83\93\83h\83E\88Ê\92u\95Û\91
669         wp.length := sizeof(wp);
670         GetWindowPlacement(Handle, @wp);
671
672         GikoSys.Setting.EditWindowTop := wp.rcNormalPosition.Top;
673         GikoSys.Setting.EditWindowLeft := wp.rcNormalPosition.Left;
674         GikoSys.Setting.EditWindowHeight := wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top;
675         GikoSys.Setting.EditWindowWidth := wp.rcNormalPosition.Right - wp.rcNormalPosition.Left;
676         GikoSys.Setting.EditWindowMax := WindowState = wsMaximized;
677         //GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;      // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
678         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;   // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
679
680 end;
681
682 procedure TEditorForm.SetNameList(sName, sMail: string);
683 begin
684         if Trim(sName) <> '' then begin
685                 if GikoSys.Setting.NameList.IndexOf(sName) = -1 then
686                         GikoSys.Setting.NameList.Insert(0, sName);
687         end;
688         if Trim(sMail) <> '' then begin
689                 if GikoSys.Setting.MailList.IndexOf(sMail) = -1 then
690                         GikoSys.Setting.MailList.Insert(0, sMail);
691         end;
692 end;
693
694 function TEditorForm.GetActiveControlHandle: THandle;
695 begin
696         if EditorPage.ActivePage = EditorTab then begin
697                 if ActiveControl = NameComboBox then
698                         Result := FNameComboEdit
699                 else if ActiveControl = MailComboBox then
700                         Result := FMailComboEdit
701                 else if ActiveControl = BodyEdit then
702                         Result := BodyEdit.Handle
703                 else if ActiveControl = TitleEdit then
704                         Result := TitleEdit.Handle
705                 else
706                         Result := 0;
707         end else if Editorpage.ActivePage = BoardInformationTab then begin
708                 if ActiveControl = BoardInformationMemo then
709                         Result := BoardInformationMemo.Handle
710                 else
711                         Result := 0;
712         end else
713                 Result := 0;
714 end;
715
716 procedure TEditorForm.SetContent(Content: string; ABrowser: TWebBrowser);
717 var
718         doc: Variant;
719 begin
720         if ABrowser.Document <> nil then begin
721                 doc := Idispatch( olevariant(ABrowser.ControlInterface).Document) as IHTMLDocument2;
722                 doc.Clear;
723                 doc.open;
724                 doc.charset := 'Shift_JIS';
725                 doc.Write(Content);
726                 doc.Close;
727         end;
728 end;
729 procedure TEditorForm.InitIdHTTP(http: TIdHTTP);
730 begin
731         http.Request.Clear;
732         http.ProxyParams.BasicAuthentication := False;
733         if GikoSys.Setting.WriteProxy then begin
734                 http.ProxyParams.ProxyServer := GikoSys.Setting.WriteProxyAddress;
735                 http.ProxyParams.ProxyPort := GikoSys.Setting.WriteProxyPort;
736                 http.ProxyParams.ProxyUsername := GikoSys.Setting.WriteProxyUserID;
737                 http.ProxyParams.ProxyPassword := GikoSys.Setting.WriteProxyPassword;
738                 if GikoSys.Setting.ReadProxyUserID <> '' then
739                         http.ProxyParams.BasicAuthentication := True;
740         end else begin
741                 http.ProxyParams.ProxyServer := '';
742                 http.ProxyParams.ProxyPort := 80;
743                 http.ProxyParams.ProxyUsername := '';
744                 http.ProxyParams.ProxyPassword := '';
745         end;
746         Indy.Request.UserAgent := GikoSys.GetUserAgent;
747         Indy.Request.AcceptEncoding := '';
748 end;
749
750 procedure TEditorForm.Send(SPID: string; PON: string; FirstWriting: Boolean);
751 var
752         TextStream: TStringStream;
753         Source: TStringStream;
754         ResponseText: string;
755         URL: string;
756         RefURL: string;
757         State: TGikoDownloadState;
758         ResultType: TGikoResultType;
759         MsgResult: Integer;
760         Cookie: string;
761         Board: TBoard;
762         sysMenu : HMENU;
763         //fusianasan\83g\83\89\83b\83v by\92è\8aú\95Ö
764         Namae: String;
765 //      SettingTxt: String;
766 //        RefeURL: string;
767 //        RuleURL: String;
768 //        RuleTxt: String;
769 //        Name: String;
770 //        SettingBody: TStringList;
771 //        tmpBoard: TBoard;
772 begin
773         FAbort := False;
774         State := gdsError;
775         Namae := RepHtml(NameComboBox.Text);
776         if FThreadItem = nil then
777                 Board := FBoard
778         else
779                 Board := FThreadItem.ParentBoard;
780
781
782         InitIdHTTP(Indy);
783         if FThreadItem = nil then begin
784                 URL := FBoard.GetSendURL;
785                 RefURL := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
786         end else begin
787                 URL := FThreadItem.GetSendURL;
788                 RefURL := FThreadItem.URL;
789         end;
790 //      Indy.Request.UserAgent := GikoSys.GetUserAgent;
791         Indy.Request.Referer := RefURL;
792 //      Indy.Request.AcceptEncoding := '';
793
794         Cookie := '';
795         if SPID <> '' then
796                 Cookie := Cookie + 'SPID=' + SPID + '; ';
797         if PON <> '' then
798                 Cookie := Cookie + 'PON=' + PON + '; ';
799         Cookie := 'Cookie: ' + Cookie + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
800
801         sysMenu := GetSystemMenu( Handle, false );
802         EnableMenuItem( sysMenu, SC_CLOSE, MF_GRAYED );
803 {
804   EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
805   DrawMenuBar(Handle);
806 }
807         Indy.Request.CustomHeaders.Clear;
808 //      Indy.Request.CacheControl := 'no-cache';
809         Indy.Request.CustomHeaders.Add('Pragma: no-cache');
810         Indy.Request.AcceptLanguage := 'ja';
811         Indy.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
812         Indy.Request.ContentType := 'application/x-www-form-urlencoded';
813         Indy.Request.CustomHeaders.Add(Cookie);
814         TextStream := TStringStream.Create('');
815         Source := TStringStream.Create('');
816         try
817                 try
818                         FDebugStrReceive := '';
819                         FDebugStrSend := '';
820                         GetSendData(Source);
821                         Indy.Post(URL, Source, TextStream);
822                         ResponseText := TextStream.DataString;
823
824                         ResultType := GetResultType(ResponseText);
825
826                         //MsgResult\8f\89\8aú\89»
827                         MsgResult := IDNO;
828                         //\83t\83V\83A\83i\83g\83\89\83b\83v\8cx\8d\90(LocalMode) by \92è\8aú\95Ö
829                         if ((Namae = '\8eR\8dè\8fÂ') or (Namae = 'fusianasan')) and (FirstWriting) then begin
830                                 MsgResult := MsgBox(
831                                                 Handle,
832                                         '\83\8a\83\82\81[\83g\83z\83X\83g\82ð\95\\8e¦\82·\82é\8b@\94\\82ª\8eg\82í\82ê\82Ä\82¢\82Ü\82·' + #13#10 +
833                                         '\82à\82µ\82à\8aÔ\88á\82Á\82Ä\82±\82Ì\95û\96@\82Å\83z\83X\83g\82ª\95\\8e¦\82³\82ê\82½\82Æ\82µ\82Ä\82à\81A\8e©\8cÈ\90Ó\94C\82È\82Ì\82Å\8dí\8f\9c\88Ë\97\8a\82É\82Í\89\9e\82\82Ü\82¹\82ñ\81B' + #13#10#13#10 +
834                                         '\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
835                                         '\8fî\95ñ',
836                                         MB_YESNO or MB_ICONQUESTION);
837                                 if MsgResult = IDNO  then begin
838                                         Board.SPID := '';
839                                         Board.PON := '';
840                                         FWork := false;
841                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
842                                         DrawMenuBar(Handle);
843                                         Exit;
844                                 end;
845                         end;
846
847                         if ResultType = grtOK then begin
848                                 WriteSambaTime(FHost, Now());
849                                 State := gdsComplete;
850                         end else if ResultType = grtCookie then begin
851                                 //\83\8b\81[\83v\96h\8e~
852                                 if not FirstWriting then
853                                         raise Exception.Create('');
854                                 MsgResult := MsgBox(
855                                         Handle,
856                                         '\81E\93\8a\8de\82³\82ê\82½\93à\97e\82Í\83R\83s\81[\81A\95Û\91\81A\88ø\97p\81A\93]\8dÚ\93\99\82³\82ê\82é\8fê\8d\87\82ª\82 \82è\82Ü\82·\81B' + #13#10 +
857                                         '\81E\93\8a\8de\82É\8aÖ\82µ\82Ä\94­\90\82·\82é\90Ó\94C\82Í\91S\82Ä\93\8a\8de\8eÒ\82É\8bA\82µ\82Ü\82·\81B' + #13#10#13#10 +
858                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
859                                         '\8fî\95ñ',
860                                         MB_YESNO or MB_ICONQUESTION);
861                                 if MsgResult = IDYES then begin
862                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
863                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
864                                         if (Board.SPID = '') and (Board.PON = '') then
865                                                 raise Exception.Create('');
866                                         //\82à\82¤\88ê\89ñ\82±\82Ì\83\81\83\\83b\83h
867                                         Send(Board.SPID, Board.PON, False);
868                                         Exit;
869                                 end else begin
870                                         Board.SPID := '';
871                                         Board.PON := '';
872                                         FWork := false;
873                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
874                                         DrawMenuBar(Handle);
875                                         Exit;
876                                 end;
877                         end else if ResultType = grtCheck then begin
878                                 //
879                                 //\83\8b\81[\83v\96h\8e~
880                                 if not FirstWriting then
881                                         raise Exception.Create('');
882
883                                 MsgResult := MsgBox(
884                                         Handle,
885                                         '\8f\91\82«\8d\9e\82Ý\82É\8aÖ\82µ\82Ä\82Í\97l\81X\82È\83\8d\83O\8fî\95ñ\82ª\8bL\98^\82³\82ê\82Ä\82¢\82Ü\82·\81B' + #13#10 +
886                                         '\93\8a\8de\82É\8aÖ\82µ\82Ä\94­\90\82·\82é\90Ó\94C\82Í\91S\82Ä\93\8a\8de\8eÒ\82É\8bA\82µ\82Ü\82·\81B' + #13#10 +
887                                         '\8cö\8f\98\97Ç\91­\82É\94½\82µ\82½\82è\81A\91¼\90l\82É\96À\98f\82ð\82©\82¯\82é\8f\91\82«\8d\9e\82Ý\82Í\8dT\82¦\82Ä\89º\82³\82¢\81B' + #13#10 +
888                                         '\93\8a\8de\82³\82ê\82½\93à\97e\82Í\83R\83s\81[\81E\95Û\91\81E\88ø\97p\81E\93]\8dÚ\93\99\82³\82ê\82é\8fê\8d\87\82ª\82 \82è\82Ü\82·\81B' + #13#10 +
889                                         #13#10 +
890                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
891                                         '\8am\94F',
892                                         MB_YESNO or MB_ICONQUESTION);
893
894                                 if MsgResult = IDYES then begin
895                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
896                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
897                                         if (Board.SPID = '') and (Board.PON = '') then
898                                                 raise Exception.Create('');
899                                         Send(Board.SPID, Board.PON, False);
900                                         Exit;
901                                 end else begin
902                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
903                                         DrawMenuBar(Handle);
904                                         Board.SPID := '';
905                                         Board.PON := '';
906                                         FWork := false;
907                                         Exit;
908                                         end;
909                         end else begin
910                 WriteSambaTime(FHost, Now());
911                                 State := gdsError;
912                                 raise Exception.Create('');
913                         end;
914
915                 except
916                         on E: EIdConnectException do begin
917                                 State := gdsError;
918                                 ResponseText := '<html><body>'
919                                                                                         + '<div>\90Ú\91±\82ª\8e¸\94s\82µ\82Ü\82µ\82½<br>'
920                                                                                         + '\89ñ\90ü\82â\83v\83\8d\83L\83V\82Ì\8fó\91Ô\82ð\92²\82×\82Ä\82­\82¾\82³\82¢<br></div>'
921                                                                                         + '<br><br><div>' + E.Message + '</div>'
922                                                                                         + '</body></html>';
923                         end;
924                         on E: Exception do begin
925                                 State := gdsError;
926
927                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '<', '&lt;');
928                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '>', '&gt;');
929                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '<', '&lt;');
930                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '>', '&gt;');
931
932                                 ResponseText := '<html><body>' + TextStream.DataString;
933                                 ResponseText := AnsiReplaceText(ResponseText, '</body>', '');
934                                 ResponseText := AnsiReplaceText(ResponseText, '</html>', '');
935                                 ResponseText := ResponseText + '<hr><div align="left"><pre>';
936                                 ResponseText := ResponseText + '<b>\82±\82±\82©\82ç\83M\83R\83i\83r\82Ì\8fî\95ñ</b>'#13#10;
937                                 ResponseText := ResponseText + #13#10'\81\9c\91\97\90M'#13#10;
938                                 ResponseText := ResponseText + FDebugStrSend;
939                                 ResponseText := ResponseText + #13#10'\81\9c\8eó\90M'#13#10;
940                                 ResponseText := ResponseText + FDebugStrReceive;
941                                 ResponseText := ResponseText + '</pre></div></body></html>';
942                         end;
943                 end;
944                 FStatusCode := Indy.ResponseCode;
945                 if FAbort then
946                         State := gdsAbort;
947         finally
948                 Source.Free;
949                 TextStream.Free;
950                 //sysMenu := GetSystemMenu( Handle, true );
951                 EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
952                 DrawMenuBar(Handle);
953         end;
954         FWork := false;
955         //\94ñ\8cö\8e®\83M\83R\83i\83r\94Â\82È\82Ç\82Ì\83X\83N\83\8a\83v\83g\97p
956         //ResponceCode\82ª302Found\82Å\8f\91\82«\8d\9e\82Ý\8a®\97¹
957         if FStatusCode = 302 then begin
958                 GikoForm.PlaySound('ResEnd');
959                 SaveSendFile;
960                 if FThreadItem = nil then
961                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
962                 else
963                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
964                 Close;
965                 Exit;
966         end;
967         if State = gdsComplete then begin
968                 GikoForm.PlaySound('ResEnd');
969                 SaveSendFile;
970                 if FThreadItem = nil then
971                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
972                 else
973                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
974                 Close;
975         end else if State = gdsError then begin
976                 if FThreadItem = nil then
977                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG)
978                 else
979                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
980                 EditorPage.ActivePage := PreviewTab;
981                 SetContent(ResponseText, Browser);
982         end else if State = gdsAbort then begin
983                 GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
984         end;
985 end;
986
987 function TEditorForm.GetResultType(ResponseText: string): TGikoResultType;
988 begin
989         if AnsiPos('\8f\91\82«\82±\82Ý\82ª\8fI\82í\82è\82Ü\82µ\82½', ResponseText) <> 0 then
990                 Result := grtOK
991         else if (AnsiPos('\83N\83b\83L\81[\82ª\82È\82¢\82©\8aú\8cÀ\90Ø\82ê\82Å\82·', ResponseText) > 0) or
992                                         (AnsiPos('<title>\83N\83b\83L\81[\8am\94F\81I</title>', ResponseText) > 0)    or
993                                         (AnsiPos('<title>\81¡\83N\83b\83L\81[\8am\94F\81I\81¡</title>', ResponseText) > 0)        or
994                                         //(AnsiPos('\83N\83b\83L\81[\8am\94F', ResponseText) > 0) or
995                                         (AnsiPos(RES2CH_COOKIE, ResponseText) > 0)      then
996                 Result := grtCookie
997         else if (AnsiPos('<font size=+2 color=#FF0000>\8f\91\82«\8d\9e\82Ý\83`\83F\83b\83N\81I </font>', ResponseText) > 0)   or
998                                         (AnsiPos('<title>\81¡ \8f\91\82«\8d\9e\82Ý\8am\94F\82µ\82Ü\82· \81¡</title>', ResponseText) > 0)  or
999                                         (AnsiPos('<title>\93\8a\8de\8am\94F</title>', ResponseText) > 0)  or
1000                                         (AnsiPos('<b>\8f\91\82«\82±\82Ý\8am\94F</b>', ResponseText) > 0)      or
1001                                         (AnsiPos('="../test/subbbs.cgi">', ResponseText) > 0)   or
1002                                         (AnsiPos(RES2CH_FALSE, ResponseText) > 0)       then
1003                 Result := grtCheck
1004         else
1005                 Result := grtError;
1006 end;
1007
1008
1009 procedure TEditorForm.GetSendData(Source: TStringStream);
1010 var
1011         SessionID: string;
1012         s: string;
1013         SendTime: Integer;
1014         Adjust: Integer;
1015         Board: TBoard;
1016         body            : string;
1017 begin
1018         if FThreadItem = nil then
1019                 Board := FBoard
1020         else
1021                 Board := FThreadItem.ParentBoard;
1022
1023         if GikoSys.Setting.UseMachineTime then begin
1024                 if GikoSys.Setting.TimeAdjust then
1025                         Adjust := Gikosys.Setting.TimeAdjustSec
1026                 else
1027                         Adjust := GikoSys.Setting.TimeAdjustSec * -1;
1028                 SendTime := GikoSys.DateTimeToInt(Now) - (9 * 60 * 60) + Adjust
1029         end else begin
1030                 if (Board.LastGetTime = 0) or (Board.LastGetTime = ZERO_DATE) then
1031                         SendTime := GikoSys.DateTimeToInt(Now)
1032                 else
1033                         SendTime := GikoSys.DateTimeToInt(Board.LastGetTime);
1034         end;
1035
1036         body := GetBody;
1037
1038         SessionID := GikoSys.Dolib.SessionID;
1039         if SessionID <> '' then
1040                 s := 'sid=' + HttpEncode(SessionID) + '&'
1041         else
1042                 s := '';
1043         s := s + 'subject=&'
1044                                  + 'FROM=' + HttpEncode(NameComboBox.Text) + '&'
1045                                  + 'mail=' + HttpEncode(MailComboBox.Text) + '&'
1046                                  + 'MESSAGE=' + HttpEncode(body) + '&'
1047                                  + 'bbs=' + Board.BBSID + '&'
1048                                  + 'time=' + IntToStr(SendTime) + '&';
1049         if FThreadItem = nil then begin
1050                 s := s + 'subject=' + HttpEncode(TitleEdit.Text) + '&';
1051                 s := s + 'submit=' + HttpEncode('\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Þ') + #13#10;
1052         end else begin
1053                 s := s + 'key=' + ChangeFileExt(FThreadItem.FileName, '') + '&';
1054                 s := s + 'submit=' + HttpEncode('\8f\91\82«\8d\9e\82Þ') + #13#10;
1055         end;
1056         Source.WriteString(s);
1057 end;
1058
1059 procedure TEditorForm.SaveSendFile;
1060 var
1061         sDate: string;
1062         ini: TMemIniFile;
1063 begin
1064         ini := TMemIniFile.Create(GikoSys.GetSentFileName);
1065         try
1066                 sDate := IntToStr(GikoSys.DateTimeToInt(Now));
1067
1068                 ini.WriteString(sDate, 'Name', NameComboBox.Text);
1069                 ini.WriteString(sDate, 'EMail', MailComboBox.Text);
1070                 ini.WriteString(sDate, 'Body', HttpEncode(BodyEdit.Text));
1071                 ini.WriteInteger(sDate, 'Status', FStatusCode);
1072                 ini.WriteDateTime(sDate, 'Date', Now);
1073                 if FThreadItem = nil then begin
1074                         ini.WriteString(sDate, 'Title', TitleEdit.Text);
1075                         ini.WriteString(sDate, 'BBS', FBoard.BBSID);
1076                         ini.WriteInteger(sDate, 'NewThread', 1);
1077                 end else begin
1078                         ini.WriteString(sDate, 'Title', FThreadItem.Title);
1079                         ini.WriteString(sDate, 'BBS', FThreadItem.ParentBoard.BBSID);
1080                         ini.WriteString(sDate, 'Key', ChangeFileExt(FThreadItem.FileName, ''));
1081                 end;
1082
1083                 ini.UpdateFile;
1084         finally
1085                 ini.Free;
1086         end;
1087 end;
1088
1089 procedure TEditorForm.SendActionExecute(Sender: TObject);
1090 var
1091         Board: TBoard;
1092         rc: Integer;
1093         state : TGikoDownloadState;
1094         body            : string;
1095 begin
1096         if FWork then
1097                 Exit;
1098         try
1099                 FWork := True;
1100                 SendAction.Enabled := False;
1101                 Application.ProcessMessages;
1102                 if not Check then Exit;
1103
1104                 if FThreadItem = nil then
1105                         Board := FBoard
1106                 else
1107                         Board := FThreadItem.ParentBoard;
1108
1109                 if FThreadItem = nil then begin
1110                         rc := GikoUtil.MsgBox(Handle,
1111                                                                                                         '\81u' + Board.Title + '\81v\94Â\82É\90V\82µ\82¢\83X\83\8c\83b\83h\97§\82Ä\82Ü\82·'#13#10#13#10
1112                                                                                                         + '\81E\94Â\82Ì\83\8b\81[\83\8b\82ð\8eç\82Á\82½\8f\91\82«\8d\9e\82Ý\82Å\82 \82é\82±\82Æ\82ð\8am\94F\82µ\82Ü\82µ\82½\82©\81H'#13#10
1113                                                                                                         + '\81E\91¼\82É\93¯\82\82æ\82¤\82È\83X\83\8c\83b\83h\82ª\96³\82©\82Á\82½\82±\82Æ\82ð\8am\94F\82µ\82Ü\82µ\82½\82©\81H'#13#10#13#10
1114                                                                                                         + '\81u\82Í\82¢\81v\82ð\89\9f\82·\82Æ\91\97\90M\82µ\82Ü\82·',
1115                                                                                                         '\8am\94F',
1116                                                                                                         MB_ICONQUESTION or MB_YESNO);
1117                         if rc <> ID_YES then
1118                                 Exit;
1119                 end;
1120
1121                 SetNameList(NameComboBox.Text, MailComboBox.Text);
1122                 if KotehanCheckBox.Checked then begin
1123                         Board.KotehanName := NameComboBox.Text;
1124                         Board.KotehanMail := MailComboBox.Text;
1125                 end;
1126
1127                 if Board.IsBoardPlugInAvailable then begin
1128                         body := GetBody;
1129
1130                         if FThreadItem = nil then begin
1131                                 // \83X\83\8c\97§\82Ä
1132                                 state := TGikoDownloadState( Board.BoardPlugIn.CreateThread(
1133                                         DWORD( Board ), TitleEdit.Text, NameComboBox.Text, MailComboBox.Text, body ) );
1134
1135                                 if state = gdsComplete then begin
1136                                         GikoForm.PlaySound('ResEnd');
1137                                         SaveSendFile;
1138                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK);
1139                                         FWork := False;
1140                                         Close;
1141                                 end else if State = gdsError then begin
1142                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG);
1143                                 end else if State = gdsAbort then begin
1144                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
1145                                 end;
1146                         end else begin
1147                                 // \83\8c\83X
1148                                 state := TGikoDownloadState( FThreadItem.BoardPlugIn.WriteThread(
1149                                         DWORD( FThreadItem ), NameComboBox.Text, MailComboBox.Text, body ) );
1150
1151                                 if state = gdsComplete then begin
1152                                         GikoForm.PlaySound('ResEnd');
1153                                         SaveSendFile;
1154                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
1155                     FWork := False;
1156                                         Close;
1157                                 end else if State = gdsError then begin
1158                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
1159                                 end else if State = gdsAbort then begin
1160                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
1161                                 end;
1162                         end;
1163                 end else begin
1164                         if not Timer1.Enabled then
1165                                 Send(Board.SPID, Board.PON, True)
1166                         else begin
1167                                 if not CheckSambaTime(FHost, Now()) then begin
1168                                         rc := GikoUtil.MsgBox(Handle,
1169                                                                 'Samba24\82Ì\8bK\92è\92l\96¢\96\9e\82Ì\95b\90\94\82µ\82©\8co\89ß\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B'#13#10
1170                                                                 + '\91\97\90M\82ð\92\86\8e~\82µ\82Ü\82·\82©\81H' + #13#10
1171                                                                 + '(\81u\82¢\82¢\82¦\81v\82¾\82Æ\91\97\90M\82µ\82Ü\82·)', 'Samba24\8cx\8d\90',
1172                                                                 MB_YESNO or MB_ICONQUESTION);
1173                                         if rc = IDYES then begin
1174                                                 FWork := false;
1175                                                 Exit;
1176                                         end;
1177                                 end;
1178                                 Send(Board.SPID, Board.PON, True);
1179                         end;
1180                 end;
1181         finally
1182                 FWork := False;
1183                 if Timer1.Enabled then
1184                         ReadSambaTime(FHost);
1185         end;
1186 end;
1187
1188 procedure TEditorForm.SaveActionExecute(Sender: TObject);
1189 begin
1190 //
1191 end;
1192
1193 procedure TEditorForm.CloseActionExecute(Sender: TObject);
1194 begin
1195         Close;
1196 end;
1197
1198 procedure TEditorForm.UndoActionExecute(Sender: TObject);
1199 begin
1200         SendMessage(GetActiveControlHandle, WM_UNDO, 0, 0);
1201 end;
1202
1203 procedure TEditorForm.CutActionExecute(Sender: TObject);
1204 begin
1205         SendMessage(GetActiveControlHandle, WM_CUT, 0, 0);
1206 end;
1207
1208 procedure TEditorForm.CopyActionExecute(Sender: TObject);
1209 begin
1210         SendMessage(GetActiveControlHandle, WM_COPY, 0, 0);
1211 end;
1212
1213 procedure TEditorForm.PasteActionExecute(Sender: TObject);
1214 begin
1215         SendMessage(GetActiveControlHandle, WM_PASTE, 0, 0);
1216 end;
1217
1218 procedure TEditorForm.SelectAllActionExecute(Sender: TObject);
1219 begin
1220         SendMessage(GetActiveControlHandle, EM_SETSEL, 0, GetWindowTextLength(GetActiveControlHandle));
1221 end;
1222
1223 procedure TEditorForm.TopActionExecute(Sender: TObject);     // \83E\83B\83\93\83h\83E\8dÅ\91O\96Ê(Stay)\83{\83^\83\93\82Ì\8f\88\97\9d
1224 begin
1225         if not (fsShowing in Self.FormState) then begin
1226                 if TopAction.Checked then begin // \83X\83e\83C\8fó\91Ô\82É\90Ý\92è
1227                         SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1228                         GikoSys.Setting.EditWindowStay := true;
1229                 end     else begin   // \83X\83e\83C\8fó\91Ô\89ð\8f\9c
1230                         SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1231                         GikoSys.Setting.EditWindowStay := false;
1232                 end;
1233                 // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
1234                 //GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;
1235         end;
1236 end;
1237
1238 procedure TEditorForm.AbortActionExecute(Sender: TObject);
1239 begin
1240         FAbort := True;
1241 end;
1242
1243 procedure TEditorForm.SendActionUpdate(Sender: TObject);
1244 begin
1245         SendAction.Enabled := not FWork;
1246 end;
1247
1248 procedure TEditorForm.SaveActionUpdate(Sender: TObject);
1249 begin
1250         SaveAction.Enabled := False;
1251 end;
1252
1253 procedure TEditorForm.CloseActionUpdate(Sender: TObject);
1254 begin
1255         CloseAction.Enabled := not FWork;
1256 end;
1257
1258 procedure TEditorForm.UndoActionUpdate(Sender: TObject);
1259 begin
1260         UndoAction.Enabled := (GetActiveControlHandle <> 0)
1261                                                                                                 and (SendMessage(GetActiveControlHandle, EM_CANUNDO, 0, 0) <> 0)
1262                                                                                                 and (not FWork);
1263 end;
1264
1265 procedure TEditorForm.CutActionUpdate(Sender: TObject);
1266 var
1267         Selection: TSelection;
1268         AHandle: THandle;
1269 begin
1270         AHandle := GetActiveControlHandle;
1271         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1272         CutAction.Enabled := (AHandle <> 0)
1273                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1274                                                                                 and (not FWork);
1275 end;
1276
1277 procedure TEditorForm.CopyActionUpdate(Sender: TObject);
1278 var
1279         Selection: TSelection;
1280         AHandle: THandle;
1281 begin
1282         AHandle := GetActiveControlHandle;
1283         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1284         CopyAction.Enabled := (AHandle <> 0)
1285                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1286                                                                                 and (not FWork);
1287 end;
1288
1289 procedure TEditorForm.PasteActionUpdate(Sender: TObject);
1290 begin
1291         PasteAction.Enabled := (GetActiveControlHandle <> 0)
1292                                                                                         and (Clipboard.HasFormat(CF_TEXT))
1293                                                                                         and (not FWork);
1294 end;
1295
1296 procedure TEditorForm.TopActionUpdate(Sender: TObject);
1297 begin
1298         TopAction.Enabled := not FWork;
1299 end;
1300
1301 procedure TEditorForm.SageCheckBoxClick(Sender: TObject);
1302 begin
1303         if SageCheckBox.Checked then begin
1304                 if AnsiPos('sage', MailComboBox.Text) = 0 then
1305                         MailComboBox.Text := 'sage' + MailComboBox.Text;
1306         end else begin
1307                 if AnsiPos('sage', MailComboBox.Text) <> 0 then
1308                         MailComboBox.Text := StringReplace(MailComboBox.Text, 'sage', '', [rfReplaceAll]);
1309         end;
1310 end;
1311
1312 procedure TEditorForm.MailComboBoxChange(Sender: TObject);
1313 begin
1314         if AnsiPos('sage', MailComboBox.Text) = 0 then
1315                 SageCheckBox.Checked := False
1316         else
1317                 SageCheckBox.Checked := True;
1318 end;
1319
1320
1321 function TEditorForm.GetSPID(CookieLine: string): string;
1322 var
1323         s: string;
1324         i: Integer;
1325 begin
1326         Result := '';
1327         i := 0;
1328         while True do begin
1329                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1330                 if s = '' then
1331                         Break
1332                 else begin
1333                         if Pos('SPID=', s) = 1 then begin
1334                                 Result := Trim(Copy(s, 6, Length(s)));
1335                                 Break;
1336                         end;
1337                 end;
1338                 inc(i);
1339         end;
1340 end;
1341
1342 function TEditorForm.GetPON(CookieLine: string): string;
1343 var
1344         s: string;
1345         i: Integer;
1346 begin
1347         Result := '';
1348         i := 0;
1349         while True do begin
1350                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1351                 if s = '' then
1352                         Break
1353                 else begin
1354                         if Pos('PON=', s) = 1 then begin
1355                                 Result := Trim(Copy(s, 5, Length(s)));
1356                                 Break;
1357                         end;
1358                 end;
1359                 inc(i);
1360         end;
1361 end;
1362
1363 procedure TEditorForm.IdLogDebugReceive(ASender: TIdConnectionIntercept;
1364         AStream: TStream);
1365 var
1366         StringStream: TStringStream;
1367 begin
1368         StringStream := TStringStream.Create('');
1369         try
1370                 StringStream.CopyFrom(AStream, AStream.Size);
1371                 FDebugStrReceive := FDebugStrReceive + StringStream.DataString;
1372         finally
1373                 StringStream.Free;
1374         end;
1375 end;
1376
1377 procedure TEditorForm.IdLogDebugSend(ASender: TIdConnectionIntercept;
1378         AStream: TStream);
1379 var
1380         StringStream: TStringStream;
1381 begin
1382         StringStream := TStringStream.Create('');
1383         try
1384                 StringStream.CopyFrom(AStream, AStream.Size);
1385                 FDebugStrSend := FDebugStrSend + StringStream.DataString;
1386         finally
1387                 StringStream.Free;
1388         end;
1389 end;
1390
1391 procedure TEditorForm.TransActionExecute(Sender: TObject);
1392 begin
1393         AlphaBlend := TransAction.Checked;
1394         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
1395         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
1396 end;
1397
1398 procedure TEditorForm.TransActionUpdate(Sender: TObject);
1399 begin
1400         TransAction.Enabled := not FWork;
1401 end;
1402 //StatusBar\82ÌPanels[0]\82Ì\95\9d\82ð\89Â\95Ï\81B\8ec\82è\82ð\8cÅ\92è\82É\82·\82é
1403 procedure TEditorForm.StatusBarResize(Sender: TObject);
1404 begin
1405         StatusBar.Panels[0].Width := StatusBar.Width
1406                                                                         - StatusBar.Panels[1].Width - StatusBar.Panels[2].Width;
1407
1408 end;
1409
1410 procedure TEditorForm.Timer1Timer(Sender: TObject);
1411 begin
1412         if FSambaTime = ZERO_DATE then
1413                 StatusBar.Panels[1].Text := '\8f\89\8f\91'
1414         else begin
1415                 FNow := IncMilliSecond(FNow, 500);
1416                 StatusBar.Panels[1].Text := Format('%8.0f\95b\8co\89ß', [SecondSpan(FNow, FSambaTime)]);
1417         end;
1418
1419 end;
1420 //Samba.ini\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1421 procedure TEditorForm.ReadSambaTime(const AHost: string);
1422 var
1423         ini :TMemIniFile;
1424         tmp: string;
1425 begin
1426         Timer1.Enabled := false; //\8co\89ß\95b\90\94\95\\8e¦Timer\82ðOff\82É\82·\82é\81i\82±\82ê\82ªON\82Ì\82Æ\82«Samba24\91Î\8dôOn\81j
1427         FNow := Now();   //\8c»\8dÝ\8e\9e\8aÔ\82ð\8eæ\93¾\81iTimer\95\\8e¦\97p\82Å\81ACheck\82·\82é\82Æ\82«\82Í\8dÄ\82ÑNow()\82ð\8cÄ\82Ô\81j
1428         Timer1.Enabled := true; //\8co\89ß\95b\90\94\95\\8e¦Timer\82ðOn\82É\82·\82é\81i\82±\82ê\82ªON\82Ì\82Æ\82«Samba24\91Î\8dôOn\81j
1429         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1430         try
1431                  //\95\8e\9a\97ñ\82Å\93Ç\82Ý\8eæ\82Á\82Ä\81A\95Ï\8a·\8aÖ\90\94\82ÅTDateTime\82Ö
1432                  tmp := ini.ReadString('Send', AHost, DateTimeToStr(ZERO_DATE));
1433                  FSambaTime := ConvertDateTimeString(tmp);
1434         finally
1435                 ini.Free;
1436         end;
1437 end;
1438 //Samba.ini\82É\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\8f\91\82«\8d\9e\82Þ
1439 procedure TEditorForm.WriteSambaTime(const AHost: string; ATime: TDateTime);
1440 var
1441         ini :TMemIniFile;
1442 begin
1443         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1444         try
1445                 ini.WriteDateTime('Send', AHost, ATime);
1446                 ini.UpdateFile;
1447         finally
1448                 ini.Free;
1449         end;
1450 end;
1451 //\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82Æ\8c»\8dÝ\8e\9e\82ð\94ä\8ar\82·\82é\81i\90^\81F\8bK\92è\92l\88È\8fã\81@\8bU\81F\8bK\92è\92l\96¢\96\9e\81j
1452 function TEditorForm.CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
1453 var
1454         pastsec: double;
1455         SettingTime: Integer;
1456 begin
1457         SettingTime := ReadSettingTime(AHost);
1458         ReadSambaTime(AHost);
1459         pastsec := SecondSpan(ATime, FSambaTime);
1460         if pastsec > SettingTime then
1461                 Result := true
1462         else
1463                 Result := false;
1464 end;
1465 //AHost\81i\8eI\96¼\81j\82ÌSamba\82Ì\8bK\92è\92l\82ð\93Ç\82Ý\8d\9e\82Þ
1466 function TEditorForm.ReadSettingTime(const AHost: string): Integer;
1467 var
1468         ini :TMemIniFile;
1469 begin
1470         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1471         try
1472                 Result := ini.ReadInteger('Setting', AHost, 0);
1473                 //\8bK\92è\92l\82ª\82O\82Ì\82Æ\82«\81A\82à\82µ\82­\82Í\90Ý\92è\82³\82ê\82Ä\82¢\82È\82¢\82Æ\82«\82Í\81A\83t\83@\83C\83\8b\82É\8f\91\82«\82½\82·\81B
1474                 if Result = 0 then begin
1475                         ini.WriteInteger('Setting', AHost, 0);
1476                         ini.UpdateFile;
1477                 end;
1478         finally
1479                 ini.Free;
1480         end;
1481 end;
1482 //Form\82ªActive\82É\82È\82Á\82½\82ç\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1483 procedure TEditorForm.FormActivate(Sender: TObject);
1484 begin
1485         if ( Timer1.Enabled ) and ( FThreadItem <> nil )then
1486                 ReadSambaTime(FHost);
1487         if GikoSys.Setting.GestureEnabled then begin
1488                 MouseGesture.UnHook;
1489                 MouseGesture.OnGestureStart := OnGestureStart;
1490                 MouseGesture.OnGestureMove := OnGestureMove;
1491                 MouseGesture.OnGestureEnd := OnGestureEnd;
1492                 MouseGesture.SetHook( Handle );
1493         end;
1494 end;
1495 //Samba24\91Î\8dô\82ð\8eg\82¤\82©\82Ç\82¤\82©\8c\88\82ß\82é\8aÖ\90\94
1496 //ReadSambaTime \82ð\8cÄ\82Ñ\8fo\82·\82ÆTimer\82ªOn\82É\82È\82é
1497 procedure TEditorForm.SetSamba24(AURL: string);
1498 var
1499         Protocol, Host, Path, Document, Port, Bookmark : string;
1500 begin
1501         //Samba24\91Î\8dô\82ð\82µ\82È\82¢\82È\82ç\8fI\97¹
1502         if not GikoSys.Setting.UseSamba then
1503                 Exit;
1504         //Host\82ÌURL\82É'.2ch.'\82©'.bbspink.'\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çSamba24\91Î\8dô\82ð\82·\82é
1505         GikoSys.ParseURI( AURL, Protocol,Host, Path, Document, Port, Bookmark );
1506         if GikoSys.Is2chHost(Host) then begin
1507                 Host := Copy(Host, 1, AnsiPos('.', Host) - 1);
1508                 FHost := Host;   //FHost=\8eI\96¼
1509                 ReadSambaTime(FHost); //\88È\91O\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1510                 //StatusBar\82É\82±\82Ì\8eI\82Ì\8bK\92è\92l\82ð\95\\8e¦\82·\82é
1511                 StatusBar.Panels[2].Text := 'Samba24\8bK\92è\92l' + IntToStr(ReadSettingTime(FHost));
1512         end;
1513 end;
1514 procedure TEditorForm.FormCloseQuery(Sender: TObject;
1515   var CanClose: Boolean);
1516 begin
1517         CanClose := not FWork;
1518 end;
1519
1520 function TEditorForm.GetOEIndentChar : string;
1521 var
1522         regKey                  : TRegistry;
1523         Identities      : string;
1524         IndentChar      : DWORD;
1525 const
1526         DEFAULT_CHAR    = '> ';
1527         OE_MAIL_PATH    = '\Software\Microsoft\Outlook Express\5.0\Mail';
1528         INDENT_CHAR             = 'Indent Char';
1529 begin
1530
1531         Result  := DEFAULT_CHAR;
1532         regKey  := TRegistry.Create;
1533         try
1534                 try
1535                         regKey.RootKey  := HKEY_CURRENT_USER;
1536                         if not regKey.OpenKey( 'Identities', False ) then
1537                                 Exit;
1538                         Identities                      := regKey.ReadString( 'Default User ID' );
1539                         if Identities = '' then
1540                                 Exit;
1541                         if not regKey.OpenKey( Identities + OE_MAIL_PATH, False ) then
1542                                 Exit;
1543                         IndentChar := regKey.ReadInteger( INDENT_CHAR );
1544                         Result := Char( IndentChar ) + ' ';
1545                 except
1546                 end;
1547         finally
1548                 regKey.Free;
1549         end;
1550
1551 end;
1552
1553 procedure TEditorForm.QuotePasteActionExecute(Sender: TObject);
1554 var
1555         s                       : TStringList;
1556         i                       : Integer;
1557         quote   : string;
1558 begin
1559
1560         quote   := GetOEIndentChar;
1561         s                       := TStringList.Create;
1562         try
1563                 s.Text  := Clipboard.AsText;
1564
1565                 for i := s.Count - 1 downto 0 do
1566                         s[ i ]  := quote + s[ i ];
1567
1568                 BodyEdit.SelText        := s.Text;
1569         finally
1570                 s.Free;
1571         end;
1572
1573 end;
1574
1575 procedure TEditorForm.SpaceToNBSPActionExecute(Sender: TObject);
1576 begin
1577         GikoSys.Setting.SpaceToNBSP := SpaceToNBSPAction.Checked;
1578         if EditorPage.ActivePage = PreviewTab then
1579                 Preview;
1580 end;
1581
1582 procedure TEditorForm.AmpToCharRefActionExecute(Sender: TObject);
1583 begin
1584         GikoSys.Setting.AmpToCharRef := AmpToCharRefAction.Checked;
1585         if EditorPage.ActivePage = PreviewTab then
1586                 Preview;
1587 end;
1588
1589 procedure TEditorForm.BoardTopClick(Sender: TObject);
1590 var
1591         ini: TIniFile;
1592 begin
1593         ini := TIniFile.Create(GikoSys.Setting.GetFileName);
1594         try
1595                 BoardtopTab.TabVisible := BoardTop.Checked;
1596                 ini.WriteBool('EditorForm', 'BoardTopTab', BoardtopTab.TabVisible);
1597         finally
1598                 ini.Free;
1599         end;
1600 end;
1601
1602
1603 procedure TEditorForm.GetSETTINGTXTActionExecute(Sender: TObject);
1604 var
1605         URL, RefURL: string;
1606         settingBody: TStringList;
1607         tmpBoard: TBoard;
1608 begin
1609         InitIdHTTP(Indy);
1610         if FThreadItem = nil then
1611                 tmpBoard := FBoard
1612         else
1613                 tmpBoard := FThreadItem.ParentBoard;
1614
1615         if tmpBoard = nil then Exit;
1616
1617         RefURL  := tmpBoard.URL;
1618         if RefURL[Length(RefURL)] <> '/' then
1619                 URL     := RefURL + '/' + 'SETTING.TXT'
1620         else
1621                 URL     := RefURL + 'SETTING.TXT';
1622
1623         Indy.Request.LastModified := tmpBoard.SETTINGTXTTime;
1624         Indy.Request.Referer := RefURL;
1625         Screen.Cursor := crHourGlass;
1626         settingBody := TStringList.Create;
1627         try
1628                 StatusBar.Panels[0].Text := 'SETTING.TXT\83_\83E\83\93\83\8d\81[\83h\92\86';
1629                 try
1630                         settingBody.Text := Indy.Get(URL);
1631                         if( Indy.ResponseCode = 200 ) then begin
1632                                 settingBody.SaveToFile(tmpBoard.GetSETTINGTXTFileName);
1633                                 tmpBoard.SETTINGTXTTime := Indy.Response.LastModified;
1634                                 tmpBoard.IsSETTINGTXT := true;
1635                                 tmpBoard.TitlePictureURL := GetTitlePictureURL(settingBody, tmpBoard);
1636                                 tmpBoard.Modified := true;
1637                                 StatusBar.Panels[0].Text := 'SETTING.TXT\8eæ\93¾\8a®\97¹(' + IntToStr(Indy.ResponseCode) + ')';
1638                         end;
1639                 except
1640                         on E: EIdException do begin
1641                                 if( AnsiPos('304', E.Message) > 0 ) then
1642                                         StatusBar.Panels[0].Text := 'SETTING.TXT\8dX\90V\96³\82µ(' + IntToStr(Indy.ResponseCode) + ')'
1643                                 else
1644                                         StatusBar.Panels[0].Text := 'SETTING.TXT\8eæ\93¾\83G\83\89\81[(' + IntToStr(Indy.ResponseCode) + ')';
1645                         end;
1646                 end;
1647         finally
1648                 settingBody.Free;
1649                 Screen.Cursor := crDefault;
1650         end;
1651         ShowBoardInformation(tmpBoard, BoardInformationMemo);
1652 end;
1653
1654 procedure TEditorForm.ShowBoardInformation(ABoard: TBoard; AMemo: TMemo);
1655 var
1656         body: TStringList;
1657 begin
1658         AMemo.Clear;
1659         AMemo.Lines.Add('[SETTING.TXT]');
1660         if ABoard.IsSETTINGTXT then begin
1661                 if FileExists(ABoard.GetSETTINGTXTFileName)  then begin
1662                         AMemo.Lines.Add(DateTimeToStr(ABoard.SETTINGTXTTime) + ' \8dX\90V');
1663                         body := TStringList.Create;
1664                         try
1665                                 body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
1666                                 AMemo.Lines.AddStrings(body);
1667                         finally
1668                                 body.Free;
1669                         end;
1670                 end else begin
1671                         ABoard.IsSETTINGTXT := false;
1672                         ABoard.SETTINGTXTTime := ZERO_DATE;
1673                         AMemo.Lines.Add('Local\82É\95Û\91\82³\82ê\82½SETTING.TXT\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ');
1674                         AMemo.Lines.Add('\83\81\83j\83\85\81[\82æ\82è\8dÄ\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B');
1675                 end;
1676         end else begin
1677                 AMemo.Lines.Add('SETTING.TXT\82ð\8eæ\93¾\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B');
1678                 AMemo.Lines.Add('\83\81\83j\83\85\81[\82æ\82è\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B');
1679         end;
1680 end;
1681 function TEditorForm.GetTitlePictureURL(body: TStringList; ABoard: TBoard): string;
1682 //BBS_TITLE_PICTURE=
1683 //BBS_FIGUREHEAD=
1684 var
1685         i: Integer;
1686         tmp: string;
1687 begin
1688         Result := '';
1689         for i := 0 to body.Count - 1 do begin
1690                 if (AnsiPos('BBS_TITLE_PICTURE=', body[i]) > 0) or
1691                    (AnsiPos('BBS_FIGUREHEAD=', body[i]) > 0) then begin
1692                         tmp := body[i];
1693                         Delete(tmp, 1, AnsiPos('=', tmp));
1694                         if AnsiPos('../', tmp) > 0 then begin
1695                                 tmp := CustomStringReplace(tmp, '../', GikoSys.UrlToServer(ABoard.URL));
1696                         end;
1697                         Result := tmp;
1698                         Exit;
1699                 end;
1700         end;
1701 end;
1702
1703 procedure TEditorForm.GetTitlePictureActionUpdate(Sender: TObject);
1704 begin
1705         if FThreadItem = nil then
1706                 GetTitlePictureAction.Enabled :=  FBoard.IsSETTINGTXT
1707         else
1708                 GetTitlePictureAction.Enabled :=  FThreadItem.ParentBoard.IsSETTINGTXT;
1709
1710 end;
1711
1712 procedure TEditorForm.GetTitlePictureActionExecute(Sender: TObject);
1713 var
1714         memStream: TMemoryStream;
1715         tmpBoard: TBoard;
1716 begin
1717         InitIdHTTP(Indy);
1718         memStream := TMemoryStream.Create;
1719         try
1720                 if FThreadItem = nil then
1721                         tmpBoard := FBoard
1722                 else
1723                         tmpBoard := FThreadItem.ParentBoard;
1724
1725                 Indy.Request.Referer := tmpBoard.URL;
1726                 if      tmpBoard.TitlePictureURL <> '' then begin
1727                         StatusBar.Panels[0].Text := '\94Â\83g\83b\83v\89æ\91\9c\83_\83E\83\93\83\8d\81[\83h\92\86';
1728                         Screen.Cursor := crHourGlass;
1729                         try
1730                                 Indy.Get(tmpBoard.TitlePictureURL, memStream);
1731                                 if Indy.ResponseCode = 200 then begin
1732                                         memStream.SaveToFile(tmpBoard.GetTitlePictureFileName);
1733                                         ShowTitlePicture();
1734                                         tmpBoard.Modified := true;
1735                                 end;
1736                         except
1737                         end;
1738                 end;
1739         finally
1740                 Screen.Cursor := crDefault;
1741                 StatusBar.Panels[0].Text := '\94Â\83g\83b\83v\89æ\91\9c (' + IntToStr(Indy.ResponseCode) + ')';
1742                 memStream.Free;
1743         end;
1744
1745 end;
1746 procedure TEditorForm.ShowTitlePicture();
1747 var
1748         tmpBoard: TBoard;
1749         s: String;
1750 begin
1751         if FThreadItem = nil then
1752                 tmpBoard := FBoard
1753         else
1754                 tmpBoard := FThreadItem.ParentBoard;
1755
1756         if FileExists(tmpBoard.GetTitlePictureFileName) then begin
1757                 TitlePictureBrowser.Navigate(tmpBoard.GetTitlePictureFileName);
1758         end else begin
1759                 s := '\94Â\83g\83b\83v\89æ\91\9c\96¢\8eæ\93¾\82Å\82·\81B<br>\83\81\83j\83\85\81[\82æ\82è\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B';
1760                 SetContent(s, TitlePictureBrowser);
1761         end;
1762 end;
1763
1764 function TEditorForm.GetFusianaName(body: TStringList; ABoard: TBoard): String;
1765 var
1766         i: Integer;
1767         tmp: string;
1768 begin
1769         for i := 0 to body.Count - 1 do begin
1770                 if (AnsiPos('BBS_NONAME_NAME=', body[i]) > 0) then begin
1771                         tmp := body[i];
1772                         Delete(tmp, 1, AnsiPos('=', tmp));
1773                         Result := tmp;
1774                         Exit;
1775                 end;
1776         end;
1777 end;
1778
1779 procedure TEditorForm.GetHeadTXTActionExecute(Sender: TObject);
1780 var
1781         URL, RefURL: string;
1782         settingBody: TStringList;
1783         tmpBoard: TBoard;
1784 begin
1785         InitIdHTTP(Indy);
1786         if FThreadItem = nil then
1787                 tmpBoard := FBoard
1788         else
1789                 tmpBoard := FThreadItem.ParentBoard;
1790
1791         if tmpBoard = nil then Exit;
1792
1793         RefURL  := tmpBoard.URL;
1794         if RefURL[Length(RefURL)] <> '/' then
1795                 URL     := RefURL + '/' + 'head.txt'
1796         else
1797                 URL     := RefURL + 'head.txt';
1798
1799         if FileExists(tmpBoard.GETHEADTXTFileName) then
1800                 Indy.Request.LastModified := tmpBoard.HEADTXTTime
1801         else
1802                 Indy.Request.LastModified := ZERO_DATE;
1803
1804         Indy.Request.Referer := RefURL;
1805         Screen.Cursor := crHourGlass;
1806         settingBody := TStringList.Create;
1807         try
1808                 StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b(head.txt)\83_\83E\83\93\83\8d\81[\83h\92\86';
1809                 try
1810                         settingBody.Text := Indy.Get(URL);
1811                         if( Indy.ResponseCode = 200 ) then begin
1812                                 settingBody.Insert(0, '<HTML lang="ja"><HEAD>');
1813                                 settingBody.Insert(1, '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');
1814                                 settingBody.Insert(2, '<TITLE>' + tmpBoard.Title + '</TITLE>');
1815                                 settingBody.Insert(3, '<base href="' + RefURL + '"></HEAD><BODY>');
1816                                 settingBody.Add('</BODY></HTML>');
1817                                 settingBody.SaveToFile(tmpBoard.GETHEADTXTFileName);
1818                                 tmpBoard.HEADTXTTime := Indy.Response.LastModified;
1819                                 tmpBoard.IsHEADTXT := true;
1820                                 tmpBoard.Modified := true;
1821                                 StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾\8a®\97¹(' + IntToStr(Indy.ResponseCode) + ')';
1822                         end;
1823                 except
1824                         on E: EIdException do begin
1825                                 if( AnsiPos('304', E.Message) > 0 ) then
1826                                         StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8dX\90V\96³\82µ(' + IntToStr(Indy.ResponseCode) + ')'
1827                                 else
1828                                         StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾\83G\83\89\81[(' + IntToStr(Indy.ResponseCode) + ')';
1829                         end;
1830                 end;
1831         finally
1832                 settingBody.Free;
1833                 Screen.Cursor := crDefault;
1834         end;
1835         if tmpBoard.IsHEADTXT then begin
1836                 ShowBoardHead(tmpboard, LocalEdit);
1837         end;
1838
1839 end;
1840
1841 procedure TEditorForm.CalcCapasityActionExecute(Sender: TObject);
1842 var
1843         body: String;
1844 begin
1845         body := GetBody;
1846         StatusBar.Panels[0].Text := '\97e\97Ê:' + IntToStr(Length(body)) + ' byte';
1847 end;
1848
1849 procedure TEditorForm.RuleClick(Sender: TObject);
1850 var
1851   ini: TIniFile;
1852 begin
1853         ini := TIniFile.Create(GikoSys.Setting.GetFileName);
1854         try
1855                 RocalRuleTab.TabVisible := Rule.Checked;
1856                 ini.WriteBool('EditorForm', 'LocalRuleTab', RocalRuleTab.TabVisible);
1857         finally
1858                 ini.Free;
1859         end;
1860 end;
1861
1862 procedure TEditorForm.FormDeactivate(Sender: TObject);
1863 begin
1864         if GikoSys.Setting.GestureEnabled then begin
1865                 MouseGesture.UnHook;
1866                 MouseGesture.SetHook( GikoForm.Handle );
1867         end;
1868 end;
1869
1870 procedure TEditorForm.OnGestureStart(Sender: TObject);
1871 begin
1872 //
1873 end;
1874
1875 procedure TEditorForm.OnGestureMove(Sender: TObject);
1876 var
1877         s: string;
1878         Action: TAction;
1879         ActStr: string;
1880 begin
1881         s := MouseGesture.GetGestureStr;
1882         ActStr := '';
1883         Action := GikoSys.Setting.Gestures.GetGestureAction(s);
1884         if Action <> nil then
1885                 ActStr := '\81i' + Action.Caption + '\81j';
1886         s := '\83W\83F\83X\83`\83\83\81[: ' + s + ActStr;
1887         StatusBar.Panels[2].Text := s;
1888 end;
1889
1890 procedure TEditorForm.OnGestureEnd(Sender: TObject);
1891 var
1892         s: string;
1893         Action: TAction;
1894 begin
1895         s := MouseGesture.GetGestureStr;
1896         Action := GikoSys.Setting.Gestures.GetGestureAction(s);
1897         if Action <> nil then
1898                 Action.Execute;
1899         StatusBar.Panels[2].Text := '';
1900 end;
1901
1902 procedure TEditorForm.ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
1903 var
1904         wDoc, WTex, le: OLEVariant;
1905 begin
1906                 //\8eQ\8dl\8c³
1907                 //http://www.campus.ne.jp/~ishigami/CREATION/TECHNIC/WEBAP-2.htm
1908                 WebBrowser1.Navigate(ABoard.GETHEADTXTFileName,le,le,le,le);
1909                 //\83\8c\83^\83\8a\83\93\83O\82ª\92x\82·\82¬\82ÄTXT\82É\88Ú\82¹\82È\82¢\81B\82Ê\82é\82Ûorz
1910                 //\89º\82Ì\82æ\82¤\82É\82¿\82á\82ñ\82Æ\93Ç\82Ý\8d\9e\82Ý\82ª\8fI\82í\82Á\82Ä\82¢\82é\82©\81A\83`\83F\83b\83N\82·\82ê\82Î\82¢\82¢\82ñ\82¾\82æ\81B
1911                 //\82±\82ê\82Å\82¢\82¯\82Ü\82µ\82½\81B\82 \82è\82ª\82Æ\82¤\82²\82´\82¢\82Ü\82µ\82½\81B
1912                 while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) and
1913                                 (WebBrowser1.ReadyState <> READYSTATE_INTERACTIVE) do begin
1914                         Application.ProcessMessages;
1915                 end;
1916                 wDoc := WebBrowser1.Document;
1917                 wTex := wDoc.body.createTextRange;
1918                 LocalEdit.Text := wTex.text;
1919 end;
1920
1921 end.