Changeset 137 for devel/web/UCore.pas


Ignore:
Timestamp:
Jan 14, 2009, 7:38:30 PM (16 years ago)
Author:
george
Message:
  • Přidáno: Ikony odkazů a soubor stylů a javaskriptů.
  • Přidáno: .htaccess pro přímé spouštění CGI z jiné složky web serveru.
  • Opraveno: Validace některých stránek na XHTML 1.0 strict.
  • Přidáno: Funkce pro pěkné formátování výstupního HTML kódu.
  • Přidáno: Zobrazení aktualit.
Location:
devel/web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel/web

    • Property svn:ignore
      •  

        old new  
        44backup
        55
        6 index
         6index.cgi
         7
         8index.compiled
  • devel/web/UCore.pas

    r135 r137  
    1919function HumanDate(Date: string): string;
    2020procedure RegisterPage(Name: string; Producer: TPageProducer);
     21function PagesList(URL: string; Page, TotalCount, CountPerPage: Integer): string;
     22function StrRepeat(Data: string; Count: Integer): string;
     23function FormatOutput(Data: string): string;
    2124 
    2225type
     
    5255begin
    5356  Navigace := CgiEnvVar.RequestURI;
    54   Result := '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' +
    55     '<html><head>' +
    56     '  <meta http-equiv="Content-Language" content="cs">' +
    57     '  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' +
     57  Result := '<?xml version="1.0" encoding="utf-8"?>' +
     58    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' +
     59        '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' +
     60    '<head>' +
     61    '  <meta http-equiv="Content-Language" content="cs" />' +
     62    '  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' +
     63        '  <link rel="stylesheet" href="style/style.css" type="text/css" media="all" />' +
     64    '  <script type="text/javascript" src="style/global.js"></script>' +
    5865    '  <title>Centrála - ' + Path + '</title>' +
    59     '  </head><body style="font-family: sans-serif;">' +
    60     '<div style="padding: 3px; font-size: 20px; border-style: solid; border-color: blue; border-width: 1; background-color: #F0F0FF; margin-bottom: 4px;">' + Title + '</div>'+
    61     '<div style="border-style: solid; border-bottom-color: gray; border-width: 0 0 1 0; margin-bottom: 3px; padding-bottom: 2px;"><strong>Navigace &gt;&gt;</strong> ' + Navigace + '</div>';
     66    '  </head><body>' +
     67    '<div id="Title">' + Title + '</div>'+
     68    '<div class="Navigation"><strong>Navigace &gt;&gt;</strong> ' + Navigace + '</div>';
    6269end;
    6370
     
    6976  UpdateDate := '2.5.2007';
    7077  GenerateTime := '1 s';
    71   Result := '<div style="border-style: solid; border-top-color: gray; border-width: 1 0 0 0; margin-top: 7px; padding-top: 2px;" align="center">'+
    72 '  <i style="font-size: 10;">| Web mistr: Jiří Hajda | e-mail: robie@centrum.cz | ICQ: 277158770 | Vygenerováno za ' + GenerateTime + ' s | Verze: 1.0 | Naposledy aktualizováno: ' + UpdateDate + ' |</i>'+
    73 '  </div>';
     78  Result := '<div id="Footer">| Web mistr: Jiří Hajda | e-mail: robie@centrum.cz | ICQ: 277158770 | Vygenerováno za ' + GenerateTime + ' s | Verze: 1.0 | Naposledy aktualizováno: ' + UpdateDate + ' |' +
     79    '</div>';
    7480  //ShowArray($GLOBALS);
    7581  Result := Result + '</body></html>';
     
    102108function InsertIcon(FileName: string): string;
    103109begin
    104   Result := '<img alt="" src="/dev/centrala/www/images/favicons/' + FileName + '" width="16" height="16">';
     110  Result := '<img alt="" src="images/favicons/' + FileName + '" width="16" height="16" />';
    105111end;
    106112
     
    126132end;
    127133
     134function PagesList(URL: string; Page, TotalCount, CountPerPage: Integer): string;
     135const
     136  Around: Integer = 10;
     137var
     138  Count: Integer;
     139  PagesMax: Integer;
     140  PagesMin: Integer;
     141  I: Integer;
     142begin
     143  Count := Round(TotalCount / CountPerPage);
     144  Result := '';
     145  if Count > 1 then begin
     146    if Page > 0 then begin
     147      Result := Result + '<a href="' + URL + '0">&lt;&lt;</a> ';
     148      Result := Result + '<a href="' + URL + IntToStr(Page - 1) + '">&lt;</a> ';
     149    end;
     150    PagesMax := Count - 1;
     151    PagesMin := 0;
     152    if PagesMax > (Page + Around) then PagesMax := Page + Around;
     153    if PagesMin < (Page - Around) then begin
     154      Result := Result + ' .. ';
     155      PagesMin := Page - Around;
     156    end;
     157    for I := PagesMin to PagesMax do begin
     158      if I = Page then Result := Result + '<strong>';
     159      Result := Result + '<a href="' + URL + IntToStr(I) + '">' + IntToStr(I + 1) + '</a> ';
     160      if I = Page then Result := Result + '</strong>';
     161    end;
     162    if PagesMax < (Count - 1) then Result := Result + ' .. ';
     163    if Page < (Count - 1) then begin
     164      Result := Result + '<a href="' + URL + IntToStr(Page + 1) + '">&gt;</a> ';
     165      Result := Result + '<a href="' + URL + IntToStr(Count - 1) + '">&gt;&gt;</a>';
     166    end;
     167  end;
     168end;
     169
     170function StrRepeat(Data: string; Count: Integer): string;
     171var
     172  I: Integer;
     173begin 
     174  Result := '';
     175  for I := 1 to Count do
     176    Result := Result + Data;
     177end;
     178
     179function FormatOutput(Data: string): string;
     180var
     181  BlockStart, BlockEnd: Integer;
     182  Indention: Integer;
     183  Indention2: Integer;
     184  Line: string;
     185  Command: string;
     186begin
     187  Result := '';
     188  Indention := 0;
     189  Indention2 := 0;
     190  while Data <> '' do begin
     191    //WebWrite('.');
     192    BlockStart := Pos('<', Data);
     193        BlockEnd := Pos('>', Data);
     194    if BlockStart > 1 then begin
     195          BlockEnd := BlockStart - 1;
     196          BlockStart := 1;
     197        end;
     198        Line := Trim(Copy(Data, BlockStart, BlockEnd));
     199        //WebWriteLn(Line);
     200        if Length(Line) > 0 then
     201          if Line[1] = '<' then begin
     202            if Data[BlockStart + 1] = '/' then begin
     203              Indention := Indention - 2;
     204              Indention2 := Indention;
     205            end else begin
     206          if Pos(' ', Line) > 0 then Command := Copy(Line, 2, Pos(' ', Line) - 2)
     207                else Command := Copy(Line, 2, Length(Line) - 2);
     208                  //WebWriteLn(Command + ' ' + IntToStr(Indention));
     209          if Pos('</' + Command + '>', Data) > 0 then Indention := Indention + 2;
     210                  //WebWriteLn(IntToStr(Indention) + ',' + IntToStr(Indention2));
     211            end;   
     212          end;
     213          if Line <> '' then Result := Result + StrRepeat(' ', Indention2) + Line + #13#10;
     214          Data := Copy(Data, BlockEnd + 1, Length(Data));
     215          Indention2 := Indention;
     216  end;
     217end;
     218
    128219initialization
    129220
Note: See TracChangeset for help on using the changeset viewer.