Changeset 138 for devel/web/UNews.pas


Ignore:
Timestamp:
Jan 15, 2009, 9:57:44 PM (16 years ago)
Author:
george
Message:
  • Přidáno: Zobrazení RSS kanálu aktualit.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/web/UNews.pas

    r137 r138  
    66
    77uses
    8   USqlDatabase, SysUtils, UCore, Classes;
     8  USqlDatabase, SysUtils, UCore, Classes, DOM;
    99
    1010type
     11
     12  { TNewsCategory }
     13
    1114  TNewsCategory = class
     15    Id: Integer;
     16    Title: string;
     17    Permission: Integer;
     18    procedure LoadFromDbRecord(DbRow: TAssocArray);
    1219  end;
    1320 
     
    1623    Title: string;
    1724    Content: string;
    18     Date: TDateTime;
     25    Time: TDateTime;
    1926    Author: string;
    2027    IPAddress: string;
     
    2330  end;
    2431
     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
    2543implementation
     44
     45uses
     46  URSS, pwmain, dateutils;
    2647
    2748{ TNewsItem }
     
    3253  Title := DbRow.Values['title'];
    3354  Content := DbRow.Values['content'];
    34   Date := Now;
     55  Time := UnixToDateTime(StrToInt(DbRow.Values['time']));
    3556  Author := DbRow.Values['author'];
    3657  IPAddress := DbRow.Values['ip'];
     
    3859end;
    3960
     61function GenerateRSS: string;
     62const
     63  MaxNewsItemCount = 15;
     64  UploadedFilesFolder = 'uploads/';
     65var
     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;
     75begin
     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;
     127end;
     128
     129{ TNews }
     130
     131constructor TNews.Create;
     132begin
     133  NewsCategoryList := TList.Create;
     134end;
     135
     136destructor TNews.Destroy;
     137var
     138  I: Integer;
     139begin
     140  for I := 0 to NewsCategoryList.Count - 1 do
     141    TNewsCategory(NewsCategoryList[I]).Free;
     142  NewsCategoryList.Free;
     143  inherited Destroy;
     144end;
     145
     146procedure TNews.LoadFromDb;
     147var
     148  DbRows: TDbRows;
     149  I: Integer;
     150  NewCategory: TNewsCategory;
     151begin
     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;
     159end;
     160
     161{ TNewsCategory }
     162
     163procedure TNewsCategory.LoadFromDbRecord(DbRow: TAssocArray);
     164begin
     165  Id := StrToInt(DbRow.Values['id']);
     166  Title := DbRow.Values['caption'];
     167  Permission := StrToInt(DbRow.Values['permission']);
     168end;
     169
    40170end.
Note: See TracChangeset for help on using the changeset viewer.