1 | unit UNewsPage;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | function NewsShowItemPage: string;
|
---|
8 | function NewsShowListPage: string;
|
---|
9 | function RSSChannel: string;
|
---|
10 |
|
---|
11 | implementation
|
---|
12 |
|
---|
13 | uses
|
---|
14 | USqlDatabase, UCore, SysUtils, UNews, UConfig;
|
---|
15 |
|
---|
16 | function NewsChannelBuild: string;
|
---|
17 | var
|
---|
18 | URL: string;
|
---|
19 | I: Integer;
|
---|
20 | Count: Integer;
|
---|
21 | Index: string;
|
---|
22 | begin
|
---|
23 | Result := ShowHeader('<strong>ZděchovNET</strong> - komunitní počítačová síť', 'Aktuality');
|
---|
24 | URL := '';
|
---|
25 | //Count := CountCgiVars;
|
---|
26 | for I := 0 to Count - 1 do begin
|
---|
27 | //Index := FetchCgiVarName(I);
|
---|
28 | if Copy(Index, 1, 8) = 'category' then URL := URL + '-' + Copy(Index, 9, Length(Index));
|
---|
29 | end;
|
---|
30 | URL := WebServerAddress + '?p=news-rss&select=' + Copy(URL, 2, Length(URL));
|
---|
31 | Result := Result + 'Výsledný RSS kanál: <a href="' + URL + '">' + URL + '</a>';
|
---|
32 | Result := Result + ShowFooter;
|
---|
33 | end;
|
---|
34 |
|
---|
35 | function NewsChannelSelection: string;
|
---|
36 | var
|
---|
37 | DbRows: TDbRows;
|
---|
38 | I: Integer;
|
---|
39 | begin
|
---|
40 | Result := ShowHeader('<strong>ZděchovNET</strong> - komunitní počítačová síť', 'Aktuality');
|
---|
41 | Result := Result + 'Vytvořte si vlastní RSS kanál, díky kterému budete moci automaticky sledovat novinky pomocí vaší RSS čtečky. ' +
|
---|
42 | 'Informace o technologii RSS a programech pro čtení kanálů najdete např. <a href="http://www.lupa.cz/clanky/prehled-rss-ctecek/">zde</a><br />' +
|
---|
43 | '<br />Kategorie:<br />';
|
---|
44 | Result := Result + '<form action="?p=news-build" method="post">';
|
---|
45 | DbRows := Database.Select('news_category', '*', '1 ORDER BY caption');
|
---|
46 | for I := 0 to DbRows.Count - 1 do
|
---|
47 | Result := Result + '<input type="checkbox" name="category' + DbRows[I].Values['id'] + '">' +
|
---|
48 | DbRows[I].Values['caption']+ '<br />';
|
---|
49 | Result := Result + '<input type="submit" value="Sestavit ">' +
|
---|
50 | '</form>';
|
---|
51 | Result := Result + ShowFooter;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | function RSSChannel: string;
|
---|
55 | begin
|
---|
56 | // Result := ShowHeader('<strong>ZděchovNET</strong> - komunitní počítačová síť', 'Aktuality');
|
---|
57 | Result := GenerateRSS;
|
---|
58 | // Result := Result + ShowFooter;
|
---|
59 | end;
|
---|
60 |
|
---|
61 | function NewsShowItemPage: string;
|
---|
62 | var
|
---|
63 | Id: Integer;
|
---|
64 | DbRows: TDbRows;
|
---|
65 | NewsItem: TNewsItem;
|
---|
66 | begin
|
---|
67 | NewsItem := TNewsItem.Create;
|
---|
68 | Result := ShowHeader('<strong>ZděchovNET</strong> - komunitní počítačová síť', 'Aktuality');
|
---|
69 | //if GetCgiVar('id') = '' then Id := 1 else Id := StrToInt(GetCgiVar('id'));
|
---|
70 | DbRows := Database.Query('SELECT `news`.*, UNIX_TIMESTAMP(`news`.date) as time, `User`.`Name` FROM `news` LEFT JOIN `User` ON `User`.`Id`=`news`.`User` WHERE `news`.`id`=' + IntToStr(Id));
|
---|
71 | if DbRows.Count > 0 then begin
|
---|
72 | NewsItem.LoadFromDbRecord(DbRows[0]);
|
---|
73 | Result := Result + '<div style="border: thin dotted #97ADFF; background: #F6F7FF; margin-top: 5px; ' +
|
---|
74 | 'padding: 0px 5px 5px 5px;"><div style="padding-bottom: 1px; border-bottom-width: 1; border-bottom-style: ' +
|
---|
75 | 'solid; border-bottom-color: silver;"><strong>' + NewsItem.Title + ' (' + DateToStr(NewsItem.Time) + ', ' + NewsItem.Author + ')</strong>';
|
---|
76 | (* if($this->System->Modules['User']->User['Id'] == $Row['User'])
|
---|
77 | {
|
---|
78 | $Output .= ' <a href="index.php?action=del&category='.$Category.'&id='.$Row['id'].'">Smazat</a>';
|
---|
79 | $Output .= ' <a href="index.php?action=edit&category='.$Category.'&id='.$Row['id'].'">Editovat</a>';
|
---|
80 | }
|
---|
81 | *)
|
---|
82 | Result := Result + '</div>' + NewsItem.Content + '<br />';
|
---|
83 | (* if($Row['enclosure'] != '')
|
---|
84 | {
|
---|
85 | $Output .= '<br />Přílohy: ';
|
---|
86 | $Enclosures = explode(';', $Row['enclosure']);
|
---|
87 | foreach($Enclosures as $Enclosure)
|
---|
88 | {
|
---|
89 | if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
|
---|
90 | }
|
---|
91 | }
|
---|
92 | *)
|
---|
93 | Result := Result + '</div>';
|
---|
94 | end else Result := Result + 'Položka nenalezena.';
|
---|
95 | Result := Result + ShowFooter;
|
---|
96 | NewsItem.Free;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | function NewsShowListPage: string;
|
---|
100 | const
|
---|
101 | PerPage: Integer = 20;
|
---|
102 | var
|
---|
103 | DbRows: TDbRows;
|
---|
104 | PageMax: Integer;
|
---|
105 | Page: Integer;
|
---|
106 | I: Integer;
|
---|
107 | NewsItem: TNewsItem;
|
---|
108 | Category: Integer;
|
---|
109 | CategoryName: string;
|
---|
110 | begin
|
---|
111 | Result := ShowHeader('<strong>ZděchovNET</strong> - komunitní počítačová síť', 'Aktuality');
|
---|
112 | // if GetCgiVar('category') = '' then Category := 1 else Category := StrToInt(GetCgiVar('category'));
|
---|
113 | NewsItem := TNewsItem.Create;
|
---|
114 | DbRows := TDbRows.Create;
|
---|
115 | DbRows := Database.Select('news', 'COUNT(*)', ' category=' + IntToStr(Category));
|
---|
116 | PageMax := StrToInt(DbRows[0].ValuesAtIndex[0]);
|
---|
117 | DbRows.Free;
|
---|
118 | // if GetCgiVar('page') = '' then Page := 0 else Page := StrToInt(GetCgiVar('page'));
|
---|
119 | CategoryName := '';
|
---|
120 | Result := Result + '<strong>Seznam aktualit kategorie ' + CategoryName + ':</strong><div style="font-size: small;">';
|
---|
121 | Result := Result + PagesList('?p=news-list&category=' + IntToStr(Category) + '&page=', Page, PageMax, PerPage);
|
---|
122 |
|
---|
123 | DbRows := Database.Query('SELECT `news`.*, UNIX_TIMESTAMP(`news`.date) as time, `User`.`Name` FROM `news` LEFT JOIN `User` ON `User`.`Id`=`news`.`User` WHERE `category`=' + IntToStr(Category) + ' ORDER BY `news`.`id` DESC LIMIT ' + IntToStr(Page * PerPage) + ',' + IntToStr(PerPage));
|
---|
124 | for I := 0 to DbRows.Count - 1 do begin
|
---|
125 | NewsItem.LoadFromDbRecord(DbRows[I]);
|
---|
126 | Result := Result + '<div style="border: thin dotted #97ADFF; background: #F6F7FF; margin-top: 5px; padding: 0px 5px 5px 5px;"><div style="padding-bottom: 1px; border-bottom-width: 1;' +
|
---|
127 | 'border-bottom-style: solid; border-bottom-color: silver;"><strong><a href="?p=news-item&id=' +
|
---|
128 | IntToStr(NewsItem.Id) + '">' + NewsItem.Title + '</a> (' + DateToStr(NewsItem.Time) + ', ' + NewsItem.Author + ')</strong>';
|
---|
129 | (*
|
---|
130 | if($this->System->Modules['User']->User['Id'] == $Row['User'])
|
---|
131 | {
|
---|
132 | $Output .= ' <a href="index.php?action=del&category='.$Category.'&id='.$Row['id'].'">Smazat</a>';
|
---|
133 | $Output .= ' <a href="index.php?action=edit&category='.$Category.'&id='.$Row['id'].'">Editovat</a>';
|
---|
134 | }
|
---|
135 | *)
|
---|
136 | Result := Result + '</div>' + NewsItem.Content + '<br />';
|
---|
137 | (*if($Row['enclosure'] != '')
|
---|
138 | {
|
---|
139 | $Output .= '<br />Přílohy: ';
|
---|
140 | $Enclosures = explode(';', $Row['enclosure']);
|
---|
141 | foreach($Enclosures as $Enclosure)
|
---|
142 | {
|
---|
143 | if(file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' <a href="'.$this->UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
|
---|
144 | }
|
---|
145 | } *)
|
---|
146 | Result := Result + '</div>';
|
---|
147 | end;
|
---|
148 | DbRows.Free;
|
---|
149 | Result := Result + PagesList('?p=news-list&category=' + IntToStr(Category) + '&page=', Page, PageMax, PerPage);
|
---|
150 | Result := Result + '</div>';
|
---|
151 | Result := Result + ShowFooter;
|
---|
152 | //end else Result := Result + 'Nemáte oprávnění.';
|
---|
153 | NewsItem.Free;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | initialization
|
---|
157 |
|
---|
158 | RegisterPage('news-item', @NewsShowItemPage);
|
---|
159 | RegisterPage('news-list', @NewsShowListPage);
|
---|
160 | RegisterPage('news-rss', @RSSChannel);
|
---|
161 | RegisterPage('news-selection', @NewsChannelSelection);
|
---|
162 | RegisterPage('news-build', @NewsChannelBuild);
|
---|
163 |
|
---|
164 | end.
|
---|