source: trunk/Common/Utils.pas

Last change on this file was 151, checked in by chronos, 9 months ago
File size: 4.3 KB
Line 
1unit Utils;
2
3interface
4
5uses
6 SqlDatabase, Classes, SysUtils, StrUtils;
7
8function NavigationLink(URL: string): string;
9function MakeLink(Text, URL: string): string;
10function InsertIcon(FileName: string): string;
11function IconedLink(Link, Text: string): string;
12function HtmlLink(Text, Target: string): string;
13function ShowHeader(Title, Path: string): string;
14function ShowFooter: string;
15function HumanDate(Date: TDateTime): string;
16function PagesList(URL: string; Page, TotalCount, CountPerPage: Integer): string;
17
18
19implementation
20
21uses
22 Core;
23
24function HtmlLink(Text, Target: string): string;
25begin
26 Result := '<a href="' + Target + '">' + Text + '</a>';
27end;
28
29function ShowHeader(Title, Path: string): string;
30var
31 Navigace: string;
32begin
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 &gt;&gt;</strong> ' + Navigace + '</div>';
47end;
48
49function ShowFooter: string;
50var
51 UpdateDate: string;
52 GenerateTime: string;
53begin
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>';
60end;
61
62function HumanDate(Date: TDateTime): string;
63begin
64 Result := FormatDateTime('d.m.yyyy', Date);
65end;
66
67function InsertIcon(FileName: string): string;
68begin
69 Result := '<img alt="" src="' + NavigationLink('/images/favicons/' + FileName) + '" width="16" height="16" />';
70end;
71
72function LastPos(const SubStr: String; const S: String): Integer;
73begin
74 Result := Pos(ReverseString(SubStr), ReverseString(S));
75
76 if (Result <> 0) then
77 Result := ((Length(S) - Length(SubStr)) + 1) - Result + 1;
78end;
79
80function IconedLink(Link, Text: string): string;
81var
82 Extension: string;
83 Icon: string;
84begin
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>';
88end;
89
90function MakeLink(Text, URL: string): string;
91begin
92 Result := '<a href="' + URL + '">' + Text + '</a>';
93end;
94
95function NavigationLink(URL: string): string;
96begin
97 if (Length(URL) > 0) and (URL[1] = '/') then
98 Result := Core.Core.BaseURL + URL
99 else Result := URL;
100end;
101
102function PagesList(URL: string; Page, TotalCount, CountPerPage: Integer): string;
103const
104 Around: Integer = 10;
105var
106 Count: Integer;
107 PagesMax: Integer;
108 PagesMin: Integer;
109 I: Integer;
110begin
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">&lt;&lt;</a> ';
116 Result := Result + '<a href="' + URL + IntToStr(Page - 1) + '">&lt;</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) + '">&gt;</a> ';
133 Result := Result + '<a href="' + URL + IntToStr(Count - 1) + '">&gt;&gt;</a>';
134 end;
135 end;
136end;
137
138end.
Note: See TracBrowser for help on using the repository browser.