📄 ucmddisp.pas
字号:
if Trim(s_expiredate) <> '' then
d_expiredate := Str2DateTime(s_expiredate)
else
d_expiredate := Now;
expired := Trunc(d_expiredate) < Trunc(Now);
Row.Condition['expired'] := expired;
if expired then
PackExpired(packname, extend_lic_link)
else
PackFiles(pack_id, packname, s_expiredate);
end
else
PackBuy(packname, order_link);
S := S + Row.Output;
end;
finally
DoneRows;
end;
Page['table_rows'] := S;
end
else
begin
// TODO: show 'no packages' message
end;
Packs.Free;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoRedir: string;
var
URL : string;
begin
URL := GetRequestValue('url');
Relocation(URL);
end;
function TCommandsDispatcher.GetSessionLogin: string;
begin
if assigned(Session) then
Result := Session.asString['user_name']
else
Result:=LOGIN_GUEST;
end;
function TCommandsDispatcher.DoSectionView: string;
var
Page : TRtcParseEx;
TableRow : TRtcParseEx;
section_id : string;
Section : PSectionRecord;
login : string;
UserAL : TUserAccessLevel;
I : integer;
S : string;
ed_topic_id : integer;
TopicsList : TList;
PreviousLogon : TDateTime;
filter : string;
begin
//http://localhost:8080/?cmd=viewsection§ion_id=4&sid=93C0D0AC68224F2E860E8FBD1092EA69
ForumData.Lock;
try
ForumData.LoadSections;
ForumData.LoadRights;
login := GetSessionLogin;
section_id := GetRequestValue('section_id');
Section := ForumData.Sections.ItemsByID[StrToIntDef(section_id, 0)];
if not Assigned(Section) then begin
Result:=RelocationOnError('error_object_not_exists');
Exit;
end;
UserAL := ForumData.Rights.GetUserAccessLevel(LowerCase(login), Section^.ID);
if not IsSectionVisible(Section^.VisibilityLevel, UserAL) then begin
Result:=RelocationOnError('error_access_denied');
Exit;
end;
if assigned(Session) then
begin
PreviousLogon := Session.asDateTime['previous logon'];
filter := LowerCase(Session.asString['forum_filter']);
end
else
begin
PreviousLogon := Now;
filter := '';
end;
ForumData.LoadTopics(Section^.ID);
Page := TRtcParseEx.Create(TemplatePath + 'topics.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea(GetMsg('title_viewsection'));
Page['forum_page_header'] := GetMsg('Forum');
Page['sid'] := SessionID;
Page['section_id'] := section_id;
Page['section_name'] := Section^.Name;
Page.Condition['write_access'] := IsSectionWritable(Section^.AccessLevel, UserAL);
Page.Condition['moderator_access'] := IsSectionModeratable(Section^.AccessLevel, UserAL);
Page['topics_count'] := IntToStr(Section^.TopicsCount);
Page['posts_count'] := IntToStr(Section^.PostCount);
ed_topic_id := StrToIntDef(GetRequestValue('ed_topic_id'), -1);
S := '';
TableRow := TRtcParseEx.Create(TemplatePath + 'topics_row.htm');
try
TopicsList := ForumData.Topics.GetOrderedList;
for I := 0 to TopicsList.Count - 1 do
with PTopicRecord(TopicsList[I])^ do begin
//if not Deleted then begin
if (filter <> '') and (Pos(filter, LowerCase(Name)) = 0) then
Continue;
TableRow.Clear;
TableRow['section_id'] := section_id;
TableRow['topic_id'] := IntToStr(ID);
TableRow['topic_subject'] := Name;
TableRow['topic_user_creator'] := CreatorUser;
TableRow['topic_replies_cnt'] := IntToStr(RepliesCount);
TableRow['topic_last_post_timestamp'] := DateTimeToStr(LastPostTimeStamp);
TableRow['topic_last_post_user'] := LastPostUser;
TableRow['sid'] := SessionID;
TableRow.Condition['moderator_access'] := IsSectionModeratable(Section^.AccessLevel, UserAL);
TableRow.Condition['view'] := not (ed_topic_id = ID);
TableRow.Condition['new_posts'] := assigned(Session) and not (ed_topic_id = ID) and (PreviousLogon < LastPostTimeStamp);
TableRow['reply_id'] := IntToStr(First_Reply_ID);
S := S + TableRow.Output;
//end; //if not Deleted
end;
finally
TableRow.Free;
end;
Page['table_row'] := S;
Result := Page.Output;
finally
Page.Free;
end;
finally
ForumData.Unlock;
end;
end;
function TCommandsDispatcher.DoNewTopic: string;
var
Page, PagePreview : TRtcParseEx;
section_id : string;
Section : PSectionRecord;
login : string;
UserAL : TUserAccessLevel;
preview : boolean;
preview_text : string;
begin
// http://localhost:8080/?cmd=newtopic§ion_id=9&sid=19D13E35CE234D0DB15A5F13288F6EBE
ForumData.Lock;
try
login := GetSessionLogin;
section_id := GetRequestValue('section_id');
ForumData.LoadSections;
ForumData.LoadRights;
Section := ForumData.Sections.ItemsByID[StrToIntDef(section_id, 0)];
if not Assigned(Section) then begin
Result:=RelocationOnError('error_object_not_exists');
Exit;
end;
UserAL := ForumData.Rights.GetUserAccessLevel(LowerCase(login), Section^.ID);
if not IsSectionVisible(Section^.VisibilityLevel, UserAL) or
not IsSectionWritable(Section^.AccessLevel, UserAL) then begin
Result:=RelocationOnError('error_access_denied');
Exit;
end;
Page := TRtcParseEx.Create(TemplatePath + 'new_topic.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea(GetMsg('title_newtopic'));
Page['forum_page_header'] := GetMsg('Forum');
Page['sid'] := SessionID;
Page['section_id'] := section_id;
Page['section_name'] := Section^.Name;
Page.Condition['guest_access'] := not assigned(Session);
Page.Condition['new_topic'] := True;
Page.Condition['alone'] := True;
Page.Condition['formvisible'] := True;
preview_text := GetRequestValue('reply_text');
preview := preview_text <> '';
if preview then begin
Page['topic_subject'] := GetRequestValue('topic_subject');
Page['reply_text'] := preview_text;
if not assigned(Session) then
Page['user_name'] := GetRequestValue('user_name');
PagePreview := TRtcParseEx.Create(TemplatePath + 'replies_row.htm');
try
if not assigned(Session) then
begin
PagePreview['user_name'] := Copy(GetRequestValue('user_name'), 1, SizeOf(TUserName));
PagePreview['user_type'] := Format(GetMsg('guest_details'), [Srv.PeerAddr]);
end
else
begin
PagePreview['user_name'] := Copy(GetUserName(login), 1, SizeOf(TUserName));
PagePreview['user_type'] := GetMsg('user_details');
end;
PagePreview['post_timestamp'] := DateTimeToStr(Now);
PagePreview['reply_text'] := BBCode2HTML(HTMLEncode( preview_text ));
PagePreview.Condition['view'] := True;
PagePreview.Condition['moderator_access'] := False;
PagePreview.Condition['preview'] := true;
Page['table_row'] := PagePreview.Output;
finally
PagePreview.Free;
end;
Page['reply_text'] := preview_text;
Page.Condition['preview'] := true;
end;
Result := Page.Output;
finally
Page.Free;
end;
finally
ForumData.Unlock;
end;
end;
function TCommandsDispatcher.DoSaveTopic: string;
var
login : string;
section_id : string;
topic_id : string;
reply_id : string;
Topic : PTopicRecord;
Section : PSectionRecord;
UserAL : TUserAccessLevel;
Reply : PReplyRecord;
tmpReply : TReplyRecord;
msg : string;
topic_subject : string;
new_topic : boolean;
new_reply : boolean;
edit_topic : boolean;
begin
section_id := GetRequestValue('section_id');
topic_id := GetRequestValue('topic_id');
reply_id := GetRequestValue('reply_id');
login := GetSessionLogin;
edit_topic := False;
ForumData.Lock;
try
ForumData.LoadSections;
Section := ForumData.Sections.ItemsByID[StrToIntDef(section_id, 0)];
if not Assigned(Section) then begin
Result:=RelocationOnError('error_object_not_exists');
Exit;
end;
ForumData.LoadRights;
UserAL := ForumData.Rights.GetUserAccessLevel(LowerCase(login), Section^.ID);
if not IsSectionVisible(Section^.VisibilityLevel, UserAL) or
not IsSectionWritable(Section^.AccessLevel, UserAL) then begin
Result:=RelocationOnError('error_access_denied');
Exit;
end;
msg := Trim(GetRequestValue('reply_text'));
topic_subject := GetRequestValue('topic_subject');
ForumData.LoadTopics(Section^.ID);
if topic_id = '' then
begin
Topic:=nil;
new_topic := True;
end
else
begin
Topic := ForumData.Topics.ItemsByID[StrToIntDef(topic_id, 0)];
if not Assigned(Topic) then
new_topic := True
else
begin
new_topic := False;
ForumData.LoadReplies(Section^.ID, Topic^.ID);
end;
end;
//create topic text in "topic.replies.data" file
if new_topic or (reply_id = '') then
begin
Reply:=nil;
new_reply := True;
end
else
begin
Reply := ForumData.Replies.ItemsByID[StrToIntDef(reply_id, 0)];
if not Assigned(Reply) then
new_reply := True
else
begin
new_reply := False;
if msg<>'' then
begin
tmpReply := Reply^;
Reply^.ID := -1 * Reply^.ID;
ForumData.Replies.Delete(Reply);
Reply := ForumData.Replies.New(msg);
with Reply^ do
begin
ID := tmpReply.ID;
ID_Topic := tmpReply.ID_Topic;
User := tmpReply.User;
UserType := tmpReply.UserType;
UserIP := tmpReply.UserIP;
TimeStamp := tmpReply.TimeStamp;
end;
end;
end;
end;
if new_topic then begin
Topic := ForumData.Topics.New;
with Topic^ do begin
if SameText(login, LOGIN_GUEST) then
begin
CreatorUser := Copy(GetRequestValue('user_name'), 1, Sizeof(TUserName));
CreatorUserType := utGuest;
end
else
begin
CreatorUser := Copy(GetUserName(login), 1, Sizeof(TUserName));
CreatorUserType := utRegistered;
end;
end;
ForumData.LoadReplies(Section^.ID, Topic^.ID);
with Section^ do begin
Inc(TopicsCount);
end;
end;
if (topic_subject <> '') and (topic_subject <> Topic^.Name) then begin
Topic^.Name := topic_subject;
edit_topic := True;
end;
if new_reply then
begin
Reply := ForumData.Replies.New(msg);
with Topic^ do begin
Inc(RepliesCount);
LastPostTimeStamp := Now;
if SameText(login, LOGIN_GUEST) then
begin
LastPostUser := Copy(GetRequestValue('user_name'), 1, SizeOf(TUserName));
LastPostUserType := utGuest;
end
else
begin
LastPostUser := Copy(GetUserName(login), 1, SizeOf(TUserName));
LastPostUserType := utRegistered;
end;
end;
with Section^ do begin
Inc(PostCount);
LastPostTimeStamp := Now;
LastPostTopicID := Topic^.Id;
LastPostTopicName := Topic^.Name;
LastPostUserName := Topic^.LastPostUser;
LastPostUserType := Topic^.LastPostUserType;
end;
with Reply^ do
begin
ID_Topic := Topic^.ID;
if SameText(login, LOGIN_GUEST) then
begin
User := Copy(GetRequestValue('user_name'), 1, SizeOf(TUserName));
UserType := utGuest;
end
else
begin
User := Copy(GetUserName(login), 1, SizeOf(TUserName));
UserType := utRegistered;
end;
TimeStamp := Now;
UserIP := Srv.PeerAddr;
end;
end;
if new_topic and new_reply then
Topic^.First_Reply_ID := Reply^.ID;
finally
ForumData.Unlock;
end;
//Result := DoSectionView;
if new_topic or edit_topic then
Relocation(Format('?cmd=viewsection§ion_id=%s&sid=%s', [section_id, SessionID]))
else
Relocation(Format('?cmd=viewtopic§ion_id=%s&topic_id=%s&sid=%s', [section_id, topic_id, SessionID]))
end;
function TCommandsDispatcher.DoTopicView: string;
var
Page : TRtcParseEx;
TableRow : TRtcParseEx;
section_id : string;
topic_id : string;
tID : integer;
Section : PSectionRecord;
Topic : PTopicRecord;
login : string;
UserAL : TUserAccessLevel;
I : integer;
S : string;
Reply : PReplyRecord;
PreviewReply : TReplyRecord;
ed_reply_id : integer;
RepliesList : TList;
is_view : boolean;
nn : integer;
preview : boolean;
preview_text : string;
begin
// http://localhost:8080/?cmd=viewtopic§ion_id=1&topic_id=1&sid=B1CDA2069C9F4F838420FC52F3B54F28
ForumData.Lock;
try
login := GetSessionLogin;
section_id := GetRequestValue('section_id');
ForumData.LoadSections;
Section := ForumData.Sections.ItemsByID[StrToIntDef(section_id, 0)];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -