1 | unit Utils;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | SqlDatabase, Classes, SysUtils, StrUtils;
|
---|
7 |
|
---|
8 | function NavigationLink(URL: string): string;
|
---|
9 | function MakeLink(Text, URL: string): string;
|
---|
10 | function InsertIcon(FileName: string): string;
|
---|
11 | function IconedLink(Link, Text: string): string;
|
---|
12 | function HtmlLink(Text, Target: string): string;
|
---|
13 | function ShowHeader(Title, Path: string): string;
|
---|
14 | function ShowFooter: string;
|
---|
15 | function HumanDate(Date: TDateTime): string;
|
---|
16 | function PagesList(URL: string; Page, TotalCount, CountPerPage: Integer): string;
|
---|
17 |
|
---|
18 |
|
---|
19 | implementation
|
---|
20 |
|
---|
21 | uses
|
---|
22 | Core;
|
---|
23 |
|
---|
24 | function HtmlLink(Text, Target: string): string;
|
---|
25 | begin
|
---|
26 | Result := '<a href="' + Target + '">' + Text + '</a>';
|
---|
27 | end;
|
---|
28 |
|
---|
29 | function ShowHeader(Title, Path: string): string;
|
---|
30 | var
|
---|
31 | Navigace: string;
|
---|
32 | begin
|
---|
33 | Navigace := '';
|
---|
34 | //Navigace := CgiEnvVar.RequestURI;
|
---|
35 | Result := '<?xml version="1.0" encoding="utf-8"?>' +
|
---|
36 | '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' +
|
---|
37 | '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' +
|
---|
38 | '<head>' +
|
---|
39 | ' <meta http-equiv="Content-Language" content="cs" />' +
|
---|
40 | ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' +
|
---|
41 | ' <link rel="stylesheet" href="style/style.css" type="text/css" media="all" />' +
|
---|
42 | ' <script type="text/javascript" src="style/global.js"></script>' +
|
---|
43 | ' <title>Centrála - ' + Path + '</title>' +
|
---|
44 | ' </head><body>' +
|
---|
45 | '<div class="PageTitle">' + Title + '</div>'+
|
---|
46 | '<div class="Navigation"><strong>Navigace >></strong> ' + Navigace + '</div>';
|
---|
47 | end;
|
---|
48 |
|
---|
49 | function ShowFooter: string;
|
---|
50 | var
|
---|
51 | UpdateDate: string;
|
---|
52 | GenerateTime: string;
|
---|
53 | begin
|
---|
54 | UpdateDate := '2.5.2007';
|
---|
55 | GenerateTime := '1 s';
|
---|
56 | Result := '<div class="Footer">| Web mistr: Jiří Hajda | e-mail: robie@centrum.cz | ICQ: 277158770 | Vygenerováno za ' + GenerateTime + ' s | Verze: 1.0 | Naposledy aktualizováno: ' + UpdateDate + ' |' +
|
---|
57 | '</div>';
|
---|
58 | //ShowArray($GLOBALS);
|
---|
59 | Result := Result + '</body></html>';
|
---|
60 | end;
|
---|
61 |
|
---|
62 | function HumanDate(Date: TDateTime): string;
|
---|
63 | begin
|
---|
64 | Result := FormatDateTime('d.m.yyyy', Date);
|
---|
65 | end;
|
---|
66 |
|
---|
67 | function InsertIcon(FileName: string): string;
|
---|
68 | begin
|
---|
69 | Result := '<img alt="" src="' + NavigationLink('/images/favicons/' + FileName) + '" width="16" height="16" />';
|
---|
70 | end;
|
---|
71 |
|
---|
72 | function LastPos(const SubStr: String; const S: String): Integer;
|
---|
73 | begin
|
---|
74 | Result := Pos(ReverseString(SubStr), ReverseString(S));
|
---|
75 |
|
---|
76 | if (Result <> 0) then
|
---|
77 | Result := ((Length(S) - Length(SubStr)) + 1) - Result + 1;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | function IconedLink(Link, Text: string): string;
|
---|
81 | var
|
---|
82 | Extension: string;
|
---|
83 | Icon: string;
|
---|
84 | begin
|
---|
85 | Extension := Copy(Link, LastPos('.', Link) + 1, Length(Link));
|
---|
86 | Icon := '<img src="' + NavigationLink('/images/icons/' + Extension + '.gif') + '" alt="' + Extension + '"> ';
|
---|
87 | Result := Icon + '<a href="' + Link + '">' + Text + '</a>';
|
---|
88 | end;
|
---|
89 |
|
---|
90 | function MakeLink(Text, URL: string): string;
|
---|
91 | begin
|
---|
92 | Result := '<a href="' + URL + '">' + Text + '</a>';
|
---|
93 | end;
|
---|
94 |
|
---|
95 | function NavigationLink(URL: string): string;
|
---|
96 | begin
|
---|
97 | if (Length(URL) > 0) and (URL[1] = '/') then
|
---|
98 | Result := Core.Core.BaseURL + URL
|
---|
99 | else Result := URL;
|
---|
100 | end;
|
---|
101 |
|
---|
102 | function PagesList(URL: string; Page, TotalCount, CountPerPage: Integer): string;
|
---|
103 | const
|
---|
104 | Around: Integer = 10;
|
---|
105 | var
|
---|
106 | Count: Integer;
|
---|
107 | PagesMax: Integer;
|
---|
108 | PagesMin: Integer;
|
---|
109 | I: Integer;
|
---|
110 | begin
|
---|
111 | Count := Round(TotalCount / CountPerPage);
|
---|
112 | Result := '';
|
---|
113 | if Count > 1 then begin
|
---|
114 | if Page > 0 then begin
|
---|
115 | Result := Result + '<a href="' + URL + '0"><<</a> ';
|
---|
116 | Result := Result + '<a href="' + URL + IntToStr(Page - 1) + '"><</a> ';
|
---|
117 | end;
|
---|
118 | PagesMax := Count - 1;
|
---|
119 | PagesMin := 0;
|
---|
120 | if PagesMax > (Page + Around) then PagesMax := Page + Around;
|
---|
121 | if PagesMin < (Page - Around) then begin
|
---|
122 | Result := Result + ' .. ';
|
---|
123 | PagesMin := Page - Around;
|
---|
124 | end;
|
---|
125 | for I := PagesMin to PagesMax do begin
|
---|
126 | if I = Page then Result := Result + '<strong>';
|
---|
127 | Result := Result + '<a href="' + URL + IntToStr(I) + '">' + IntToStr(I + 1) + '</a> ';
|
---|
128 | if I = Page then Result := Result + '</strong>';
|
---|
129 | end;
|
---|
130 | if PagesMax < (Count - 1) then Result := Result + ' .. ';
|
---|
131 | if Page < (Count - 1) then begin
|
---|
132 | Result := Result + '<a href="' + URL + IntToStr(Page + 1) + '">></a> ';
|
---|
133 | Result := Result + '<a href="' + URL + IntToStr(Count - 1) + '">>></a>';
|
---|
134 | end;
|
---|
135 | end;
|
---|
136 | end;
|
---|
137 |
|
---|
138 | end.
|
---|