Changeset 139 for devel/web/UNews.pas


Ignore:
Timestamp:
Jan 16, 2009, 1:41:07 PM (16 years ago)
Author:
george
Message:
  • Opraveno: Zobrazní aktualit na hlavní stránce.
  • Přidáno: Nástřel databázové objektové vrstvy.
Location:
devel/web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel/web

    • Property svn:ignore
      •  

        old new  
        77
        88index.compiled
         9
         10UConfig.pas
  • devel/web/UNews.pas

    r138 r139  
    66
    77uses
    8   USqlDatabase, SysUtils, UCore, Classes, DOM;
     8  USqlDatabase, SysUtils, UCore, Classes, UDatabase;
    99
    1010type
     
    1212  { TNewsCategory }
    1313
    14   TNewsCategory = class
    15     Id: Integer;
     14  TNewsCategory = class(TDbObject)
    1615    Title: string;
    1716    Permission: Integer;
    1817    procedure LoadFromDbRecord(DbRow: TAssocArray);
     18    procedure Store; override;
    1919  end;
    2020 
    21   TNewsItem = class
    22     Id: Integer;
     21  { TNewsItem }
     22
     23  TNewsItem = class(TDbObject)
    2324    Title: string;
    2425    Content: string;
     
    2829    Category: Integer;
    2930    procedure LoadFromDbRecord(DbRow: TAssocArray);
     31    procedure Store; override;
    3032  end;
    3133
     
    3739    destructor Destroy; override;
    3840    procedure LoadFromDb;
     41    function ShowNews(Category: Integer): string;
    3942  end;
    4043
     
    5962end;
    6063
     64procedure TNewsItem.Store;
     65var
     66  Values: TAssocArray;
     67begin
     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;
     78end;
     79
    6180function GenerateRSS: string;
    6281const
    6382  MaxNewsItemCount = 15;
    64   UploadedFilesFolder = 'uploads/';
     83//  UploadedFilesFolder = 'uploads/';
    6584var
    6685  RSSChannel:  TRSSChannel;
     
    168187end;
    169188
     189procedure TNewsCategory.Store;
     190var
     191  Values: TAssocArray;
     192begin
     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;
     199end;
     200
     201function TNews.ShowNews(Category: Integer): string;
     202var
     203  DbRows: TDbRows;
     204  FontSize: Integer;
     205  I: Integer;
     206  II: Integer;
     207  Enclosures: TArrayOfString;
     208  Content: string;
     209const
     210  NewsCountPerCategory = 5;
     211//  UploadedFilesFolder = 'aktuality/uploads/';
     212begin
     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&amp;category=' + IntToStr(Category) + '">Zobrazit všechny aktuality</a>&nbsp;';
     217  if TNewsCategory(NewsCategoryList[Category]).Permission = 1 then
     218    Result := Result + '<a href="?p=news-add&amp;category=' + IntToStr(Category) + '">Přidat aktualitu</a>&nbsp;';
     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&amp;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>';
     244end;
     245
    170246end.
Note: See TracChangeset for help on using the changeset viewer.