Ignore:
Timestamp:
Sep 10, 2010, 8:09:21 AM (14 years ago)
Author:
george
Message:
  • Přidáno: Systém navigace pomocí "pěkných" URL.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/lazarus/Common/UCGIApplication.pas

    r23 r27  
    2828  TCGIApplication = class
    2929  private
    30     function FormatOutput(Data: string): string;
    3130  public
    3231    Headers: TStringList;
     
    3534    Output: TStringList;
    3635    Query: TQueryParameterList;
     36    QueryParts: TStringListEx;
     37    BaseURL: string;
    3738    constructor Create;
    3839    destructor Destroy; override;
     
    5455  Output := TStringList.Create;
    5556  Query := TQueryParameterList.Create;
     57  QueryParts := TStringListEx.Create;
    5658end;
    5759
     
    6365  Cookies.Free;
    6466  Query.Free;
     67  QueryParts.Free;
    6568  inherited Destroy;
    6669end;
     
    8083
    8184  // Parse query string
    82   Query.Parse(EnvVars.Values['QUERY_STRING']);
     85  if Length(EnvVars.Values['QUERY_STRING']) > 0 then
     86  if EnvVars.Values['QUERY_STRING'][Length(EnvVars.Values['QUERY_STRING'])] = '/' then
     87    EnvVars.Values['QUERY_STRING'] := Copy(EnvVars.Values['QUERY_STRING'], 1,
     88      Length(EnvVars.Values['QUERY_STRING']) - 1);
     89  QueryParts.Explode('/', EnvVars.Values['QUERY_STRING']);
     90  if Pos('?', EnvVars.Values['REQUEST_URI']) > 0 then
     91    Query.Parse(Copy(EnvVars.Values['REQUEST_URI'],
     92      Pos('?', EnvVars.Values['REQUEST_URI']) + 1,
     93      Length(EnvVars.Values['REQUEST_URI'])));
    8394
    8495  Execute;
     
    97108
    98109  // Emit page content
    99   //Output.Text := FormatOutput(Output.Text);
    100110  for I := 0 to Output.Count - 1 do begin
    101111    WriteLn(Output[I]);
     
    115125  Output.Add('</table>');
    116126end;
    117 
    118 function TCGIApplication.FormatOutput(Data: string): string;
    119 var
    120   BlockStart, BlockEnd: Integer;
    121   Indention: Integer;
    122   Indention2: Integer;
    123   Line: string;
    124   Command: string;
    125 begin
    126   Result := '';
    127   Indention := 0;
    128   Indention2 := 0;
    129   while Data <> '' do begin
    130     //WebWrite('.');
    131     BlockStart := Pos('<', Data);
    132         BlockEnd := Pos('>', Data);
    133     if BlockStart > 1 then begin
    134           BlockEnd := BlockStart - 1;
    135           BlockStart := 1;
    136         end;
    137         Line := Trim(Copy(Data, BlockStart, BlockEnd));
    138         //WebWriteLn(Line);
    139         if Length(Line) > 0 then
    140           if Line[1] = '<' then begin
    141             if Data[BlockStart + 1] = '/' then begin
    142               Indention := Indention - 2;
    143               Indention2 := Indention;
    144             end else begin
    145           if Pos(' ', Line) > 0 then Command := Copy(Line, 2, Pos(' ', Line) - 2)
    146                 else Command := Copy(Line, 2, Length(Line) - 2);
    147                   //WebWriteLn(Command + ' ' + IntToStr(Indention));
    148           if Pos('</' + Command + '>', Data) > 0 then Indention := Indention + 2;
    149                   //WebWriteLn(IntToStr(Indention) + ',' + IntToStr(Indention2));
    150             end;
    151           end;
    152           if Line <> '' then Result := Result + StrRepeat(' ', Indention2) + Line + #13#10;
    153           Data := Copy(Data, BlockEnd + 1, Length(Data));
    154           Indention2 := Indention;
    155   end;
    156 end;
    157 
    158127
    159128{ TCookieList }
Note: See TracChangeset for help on using the changeset viewer.