Changeset 139 for devel/web/UNews.pas
Legend:
- Unmodified
- Added
- Removed
-
devel/web
- Property svn:ignore
-
old new 7 7 8 8 index.compiled 9 10 UConfig.pas
-
- Property svn:ignore
-
devel/web/UNews.pas
r138 r139 6 6 7 7 uses 8 USqlDatabase, SysUtils, UCore, Classes, DOM;8 USqlDatabase, SysUtils, UCore, Classes, UDatabase; 9 9 10 10 type … … 12 12 { TNewsCategory } 13 13 14 TNewsCategory = class 15 Id: Integer; 14 TNewsCategory = class(TDbObject) 16 15 Title: string; 17 16 Permission: Integer; 18 17 procedure LoadFromDbRecord(DbRow: TAssocArray); 18 procedure Store; override; 19 19 end; 20 20 21 TNewsItem = class 22 Id: Integer; 21 { TNewsItem } 22 23 TNewsItem = class(TDbObject) 23 24 Title: string; 24 25 Content: string; … … 28 29 Category: Integer; 29 30 procedure LoadFromDbRecord(DbRow: TAssocArray); 31 procedure Store; override; 30 32 end; 31 33 … … 37 39 destructor Destroy; override; 38 40 procedure LoadFromDb; 41 function ShowNews(Category: Integer): string; 39 42 end; 40 43 … … 59 62 end; 60 63 64 procedure TNewsItem.Store; 65 var 66 Values: TAssocArray; 67 begin 68 Values := TAssocArray.Create; 69 Values.AddKeyValue('content', Content); 70 Values.AddKeyValue('title', Title); 71 Values.AddKeyValue('author', Author); 72 Values.AddKeyValue('ip', IPAddress); 73 Values.AddKeyValue('time', IntToStr(DateTimeToUnix(Time))); 74 Values.AddKeyValue('category', IntToStr(Category)); 75 Database.Update('news', Values, 'id=' + IntToStr(Id)); 76 Values.Free; 77 inherited; 78 end; 79 61 80 function GenerateRSS: string; 62 81 const 63 82 MaxNewsItemCount = 15; 64 UploadedFilesFolder = 'uploads/';83 // UploadedFilesFolder = 'uploads/'; 65 84 var 66 85 RSSChannel: TRSSChannel; … … 168 187 end; 169 188 189 procedure TNewsCategory.Store; 190 var 191 Values: TAssocArray; 192 begin 193 Values := TAssocArray.Create; 194 Values.AddKeyValue('permission', IntToStr(Permission)); 195 Values.AddKeyValue('title', Title); 196 Database.Update('news_category', Values, 'id=' + IntToStr(Id)); 197 Values.Free; 198 inherited; 199 end; 200 201 function TNews.ShowNews(Category: Integer): string; 202 var 203 DbRows: TDbRows; 204 FontSize: Integer; 205 I: Integer; 206 II: Integer; 207 Enclosures: TArrayOfString; 208 Content: string; 209 const 210 NewsCountPerCategory = 5; 211 // UploadedFilesFolder = 'aktuality/uploads/'; 212 begin 213 // global $NewsCategoryNames, $NewsCountPerCategory, $UploadedFilesFolder; 214 Result := '<table class="MainTable"><tr>' + 215 '<td>' + TNewsCategory(NewsCategoryList[Category]).Title + '</td><td align="right">'+ 216 '<a href="?p=news-list&category=' + IntToStr(Category) + '">Zobrazit všechny aktuality</a> '; 217 if TNewsCategory(NewsCategoryList[Category]).Permission = 1 then 218 Result := Result + '<a href="?p=news-add&category=' + IntToStr(Category) + '">Přidat aktualitu</a> '; 219 Result := Result + '</td></tr><tr><td colspan="2" style="NewsTable">' + 220 '<table class="NewsTable" cellspacing="0" cellpadding="0">'; 221 FontSize := 12; 222 DbRows := Database.Select('news', '*', 'category=' + IntToStr(Category) + ' ORDER BY date DESC LIMIT 0,' + IntToStr(NewsCountPerCategory)); 223 for I := 0 to DbRows.Count - 1 do with DbRows[I] do begin 224 Content := Values['content']; 225 Content := StringReplace(Content, '<br>', '<br />', [rfReplaceAll]); 226 Result := Result + '<tr><td onclick="window.location=''?p=news-item&id=' + Values['id'] + '''" onmouseover="zobraz(''new' + Values['id'] + ''')" class="NewsTableItemTitle">' + 227 '<table class="NewsTableItemTitle">' + 228 '<tr><td style="font-size: ' + IntToStr(FontSize) + 'pt"><strong>' + Values['title'] + '</strong></td>'+ 229 '<td align="right" style="font-size: ' + IntToStr(FontSize) + 'pt">' + Values['author'] + ' (' + HumanDate(Values['date']) + ')' + 230 '</td></tr></table>' + 231 '<div id="new' + Values['id'] + '" class="NewsTableItem">' + Content; 232 233 if Values['enclosure'] <> '' then begin 234 Result := Result + '<br />Přílohy: '; 235 Enclosures := Explode(';', Values['enclosure']); 236 for II := 0 to High(Enclosures) do begin 237 // if(file_exists($UploadedFilesFolder.$Enclosure)) echo(' <a href="'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>') 238 end; 239 end; 240 Result := Result + '</div></td></tr>'; 241 FontSize := FontSize - 1; 242 end; 243 Result := Result + '</table></td></tr></table>'; 244 end; 245 170 246 end.
Note:
See TracChangeset
for help on using the changeset viewer.