source: branches/DirectWeb/URSS.pas

Last change on this file was 91, checked in by george, 15 years ago
  • Upraveno: Třída TWebServer oddělena do samostatné jednotky.
File size: 2.4 KB
Line 
1unit URSS;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, DateUtils;
9
10type
11 TRSSChannelItem = class
12 Title: string;
13 Description: string;
14 Time: TDateTime;
15 Link: string;
16 end;
17
18 { TRSSCannel }
19
20 { TRSSChannel }
21
22 TRSSChannel = class
23 Title: string;
24 Link: string;
25 Description: string;
26 PublishDate: TDateTime;
27 WebMasterEmail: string;
28 Language: string;
29 TTL: Integer;
30 Items: TList;
31 function ProduceOutput: string;
32 constructor Create;
33 destructor Destroy; override;
34 function RFC2822TimeFormat(Time: TDateTime): string;
35 end;
36
37implementation
38
39{ TRSSCannel }
40
41function TRSSChannel.ProduceOutput: string;
42var
43 I: Integer;
44begin
45 Result := '<?xml version="1.0" encoding="utf-8"?>' +
46 '<rss version="2.0">' +
47 '<channel>' +
48 '<title>' + Title + '</title>' +
49 '<link>' + Link + '</link>' +
50 '<description>' + Description + '</description>' +
51 '<language>' + Language + '</language>' +
52 '<webMaster>' + WebMasterEmail + '</webMaster>' +
53 '<pubDate>' + DateToStr(PublishDate) + '</pubDate>' +
54 '<ttl>' + IntToStr(TTL) + '</ttl>';
55 for I := 0 to Items.Count - 1 do
56 with TRSSChannelItem(Items[I]) do begin
57 Result := Result + '<item>' +
58 '<title>' + Title + '</title>' +
59 '<description>' + Description + '</description>' +
60 '<pubDate>' + RFC2822TimeFormat(Time) + '</pubDate>' +
61 '<link>' + Link + '</link>' +
62 '</item>';
63 end;
64 Result := Result + '</channel>' +
65 '</rss>';
66end;
67
68constructor TRSSChannel.Create;
69begin
70 TTL := 20;
71 Language := 'cs';
72 PublishDate := Now;
73 Items := TList.Create;
74end;
75
76destructor TRSSChannel.Destroy;
77var
78 I: Integer;
79begin
80 for I := 0 to Items.Count - 1 do
81 TRSSChannelItem(Items[I]).Free;
82 Items.Free;
83 inherited Destroy;
84end;
85
86function TRSSChannel.RFC2822TimeFormat(Time: TDateTime): string;
87const
88 WeekName: array[1..7] of string = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
89 MonthName: array[1..12] of string = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
90 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
91 TimeZone = '+0100';
92begin
93 Result := WeekName[DayOfTheWeek(Time)] + ', ' + IntToStr(DayOfTheMonth(Time)) + ' ' +
94 MonthName[MonthOf(Time)] + ' ' + IntToStr(YearOf(Time)) + ' ' +
95 IntToStr(HourOf(Time)) + ':' + IntToStr(MinuteOf(Time)) + ':' +
96 IntToStr(SecondOf(Time)) + ' ' + TimeZone;
97end;
98
99end.
100
Note: See TracBrowser for help on using the repository browser.