1 | unit URSS;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, DateUtils;
|
---|
9 |
|
---|
10 | type
|
---|
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 |
|
---|
37 | implementation
|
---|
38 |
|
---|
39 | { TRSSCannel }
|
---|
40 |
|
---|
41 | function TRSSChannel.ProduceOutput: string;
|
---|
42 | var
|
---|
43 | I: Integer;
|
---|
44 | begin
|
---|
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>';
|
---|
66 | end;
|
---|
67 |
|
---|
68 | constructor TRSSChannel.Create;
|
---|
69 | begin
|
---|
70 | TTL := 20;
|
---|
71 | Language := 'cs';
|
---|
72 | PublishDate := Now;
|
---|
73 | Items := TList.Create;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | destructor TRSSChannel.Destroy;
|
---|
77 | var
|
---|
78 | I: Integer;
|
---|
79 | begin
|
---|
80 | for I := 0 to Items.Count - 1 do
|
---|
81 | TRSSChannelItem(Items[I]).Free;
|
---|
82 | Items.Free;
|
---|
83 | inherited Destroy;
|
---|
84 | end;
|
---|
85 |
|
---|
86 | function TRSSChannel.RFC2822TimeFormat(Time: TDateTime): string;
|
---|
87 | const
|
---|
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';
|
---|
92 | begin
|
---|
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;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | end.
|
---|
100 |
|
---|