Changeset 138 for devel/web/UNews.pas
- Timestamp:
- Jan 15, 2009, 9:57:44 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/web/UNews.pas
r137 r138 6 6 7 7 uses 8 USqlDatabase, SysUtils, UCore, Classes ;8 USqlDatabase, SysUtils, UCore, Classes, DOM; 9 9 10 10 type 11 12 { TNewsCategory } 13 11 14 TNewsCategory = class 15 Id: Integer; 16 Title: string; 17 Permission: Integer; 18 procedure LoadFromDbRecord(DbRow: TAssocArray); 12 19 end; 13 20 … … 16 23 Title: string; 17 24 Content: string; 18 Date: TDateTime;25 Time: TDateTime; 19 26 Author: string; 20 27 IPAddress: string; … … 23 30 end; 24 31 32 { TNews } 33 34 TNews = class 35 NewsCategoryList: TList; 36 constructor Create; 37 destructor Destroy; override; 38 procedure LoadFromDb; 39 end; 40 41 function GenerateRSS: string; 42 25 43 implementation 44 45 uses 46 URSS, pwmain, dateutils; 26 47 27 48 { TNewsItem } … … 32 53 Title := DbRow.Values['title']; 33 54 Content := DbRow.Values['content']; 34 Date := Now;55 Time := UnixToDateTime(StrToInt(DbRow.Values['time'])); 35 56 Author := DbRow.Values['author']; 36 57 IPAddress := DbRow.Values['ip']; … … 38 59 end; 39 60 61 function GenerateRSS: string; 62 const 63 MaxNewsItemCount = 15; 64 UploadedFilesFolder = 'uploads/'; 65 var 66 RSSChannel: TRSSChannel; 67 Select: string; 68 SelectParts: TArrayOfString; 69 Where: string; 70 DbRows: TDbRows; 71 NewItem: TRSSChannelItem; 72 I: Integer; 73 News: TNews; 74 NewsItem: TNewsItem; 75 begin 76 News := TNews.Create; 77 News.LoadFromDb; 78 NewsItem := TNewsItem.Create; 79 RSSChannel := TRSSChannel.Create; 80 with RSSChannel do begin 81 Title := 'ZděchovNET - Aktuality'; 82 Link := 'http://centrala.zdechov.net/'; 83 Description := 'Aktuality komunitní počítačové sítě ZděchovNET'; 84 WebMasterEmail := 'robie@centrum.cz'; 85 86 (* 87 $Category = ''; 88 $CategoryOption = ''; 89 $CategoryOptionURL = ''; 90 $CategoryName = ''; 91 *) 92 93 if GetCgiVar('select') = '' then Select := '' else Select := GetCgiVar('select'); 94 SelectParts := Explode('-', Select); 95 Where := ''; 96 for I := 0 to High(SelectParts) do 97 Where := Where + 'OR (category=' + SelectParts[I] + ')'; 98 Where := Copy(Where, 3, Length(Where)); 99 if Where = '' then Where := '1'; 100 101 DbRows := Database.Query('SELECT *,UNIX_TIMESTAMP(date) as time FROM news WHERE ' + Where + ' ORDER BY date DESC LIMIT 0,' + IntToStr(MaxNewsItemCount)); for I := 0 to DbRows.Count - 1 do begin 102 NewsItem.LoadFromDbRecord(DbRows[I]); 103 NewItem := TRSSChannelItem.Create; 104 with NewItem do begin 105 (* 106 EnclosuresText := ''; 107 if Values['enclosure'] <> '' then begin 108 EnclosuresText := EnclosureText + '<br />Přílohy: '; 109 Enclosures := explode(';', $Row['enclosure']); 110 foreach($Enclosures as $Enclosure) 111 { 112 if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>'; 113 } 114 } 115 *) 116 Title := TNewsCategory(News.NewsCategoryList[NewsItem.Category]).Title + ' - ' + NewsItem.Title; 117 Link := 'http://centrala.zdechov.net/aktuality/index.php?category=' + IntToStr(NewsItem.Category); 118 Description := NewsItem.Content + ' (' + NewsItem.Author + ')'; // + EnclosuresText; 119 Time := NewsItem.Time; 120 end; 121 Items.Add(NewItem); 122 end; 123 end; 124 NewsItem.Free; 125 News.Free; 126 Result := RSSChannel.ProduceOutput; 127 end; 128 129 { TNews } 130 131 constructor TNews.Create; 132 begin 133 NewsCategoryList := TList.Create; 134 end; 135 136 destructor TNews.Destroy; 137 var 138 I: Integer; 139 begin 140 for I := 0 to NewsCategoryList.Count - 1 do 141 TNewsCategory(NewsCategoryList[I]).Free; 142 NewsCategoryList.Free; 143 inherited Destroy; 144 end; 145 146 procedure TNews.LoadFromDb; 147 var 148 DbRows: TDbRows; 149 I: Integer; 150 NewCategory: TNewsCategory; 151 begin 152 DbRows := Database.Select('news_category', '*'); 153 for I := 0 to DbRows.Count - 1 do begin 154 NewCategory := TNewsCategory.Create; 155 NewCategory.LoadFromDbRecord(DbRows[I]); 156 NewsCategoryList.Add(NewCategory); 157 end; 158 DbRows.Free; 159 end; 160 161 { TNewsCategory } 162 163 procedure TNewsCategory.LoadFromDbRecord(DbRow: TAssocArray); 164 begin 165 Id := StrToInt(DbRow.Values['id']); 166 Title := DbRow.Values['caption']; 167 Permission := StrToInt(DbRow.Values['permission']); 168 end; 169 40 170 end.
Note:
See TracChangeset
for help on using the changeset viewer.