source: branches/web/Pages/UNewsPage.pas

Last change on this file was 283, checked in by george, 14 years ago
  • Upraveno: Soubory pro generování stránek přesunuty do podsložky Pages.
File size: 6.9 KB
Line 
1unit UNewsPage;
2
3{$mode delphi}{$H+}
4
5interface
6
7function NewsShowItemPage: string;
8function NewsShowListPage: string;
9function RSSChannel: string;
10
11implementation
12
13uses
14 USqlDatabase, UCore, SysUtils, UNews, UConfig;
15
16function NewsChannelBuild: string;
17var
18 URL: string;
19 I: Integer;
20 Count: Integer;
21 Index: string;
22begin
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&amp;select=' + Copy(URL, 2, Length(URL));
31 Result := Result + 'Výsledný RSS kanál: <a href="' + URL + '">' + URL + '</a>';
32 Result := Result + ShowFooter;
33end;
34
35function NewsChannelSelection: string;
36var
37 DbRows: TDbRows;
38 I: Integer;
39begin
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;
52end;
53
54function RSSChannel: string;
55begin
56// Result := ShowHeader('<strong>ZděchovNET</strong> - komunitní počítačová síť', 'Aktuality');
57 Result := GenerateRSS;
58// Result := Result + ShowFooter;
59end;
60
61function NewsShowItemPage: string;
62var
63 Id: Integer;
64 DbRows: TDbRows;
65 NewsItem: TNewsItem;
66begin
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 .= '&nbsp;<a href="index.php?action=del&amp;category='.$Category.'&amp;id='.$Row['id'].'">Smazat</a>';
79 $Output .= '&nbsp;<a href="index.php?action=edit&amp;category='.$Category.'&amp;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;
97end;
98
99function NewsShowListPage: string;
100const
101 PerPage: Integer = 20;
102var
103 DbRows: TDbRows;
104 PageMax: Integer;
105 Page: Integer;
106 I: Integer;
107 NewsItem: TNewsItem;
108 Category: Integer;
109 CategoryName: string;
110begin
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&amp;category=' + IntToStr(Category) + '&amp;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&amp;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 .= '&nbsp;<a href="index.php?action=del&amp;category='.$Category.'&amp;id='.$Row['id'].'">Smazat</a>';
133 $Output .= '&nbsp;<a href="index.php?action=edit&amp;category='.$Category.'&amp;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&amp;category=' + IntToStr(Category) + '&amp;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;
154end;
155
156initialization
157
158RegisterPage('news-item', @NewsShowItemPage);
159RegisterPage('news-list', @NewsShowListPage);
160RegisterPage('news-rss', @RSSChannel);
161RegisterPage('news-selection', @NewsChannelSelection);
162RegisterPage('news-build', @NewsChannelBuild);
163
164end.
Note: See TracBrowser for help on using the repository browser.