/
Post.xxm
94 lines (88 loc) · 2.81 KB
/
Post.xxm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[[@DataLank,xxmSession,VBScript_RegExp_55_TLB,fCommon]][[!var
qr:TQueryResult;
id,rw,sid,i:integer;
s,r:string;
rp1,rp2,rp3:IRegExp2;
db:TDataConnection;
d1:TDateTime;
dy,dm,dd:word;
]][[
id:=Context['id'].AsInteger;
r:=Context.URL;
i:=Length(r);
while (i<>0) and (r[i]<>'/') do dec(i);
SetLength(r,i);
db:=Session.Connection;
qr:=TQueryResult.Create(db,
'select P.*, S.label, S.color, S.readwidth, S.id as subid, F.htmlprefix'+
' from "Post" P'+
' inner join "Feed" F on F.id=P.feed_id'+
' left outer join "Subscription" S on S.feed_id=P.feed_id and S.user_id=$1'+
' where P.id=$2',[Session.UserID,id]);
try
Context.Include('dHead.xxmi',[r,qr['url']]);
//TODO: sanitize HTML (either here or in eater)
rw:=qr.GetInt('readwidth');
sid:=qr.GetInt('subid');
if rw=0 then s:='' else s:=' style="max-width:'+IntToStr(rw)+'em;"';
if rw<4 then rw:=32;
d1:=double(qr['pubdate'])+Session.TimeBias;
<<div style="padding-bottom:4pt;">>
if UtcNow+Session.TimeBias-d1>180 then
begin
<<div class="date">>=FormatDateTime('ddd yyyy-mm-dd hh:nn',d1)<</div>>
end
else
begin
<<div class="date" title="[[=FormatDateTime('ddd yyyy-mm-dd hh:nn:ss',d1)]]">>=FormatDateTime('mm-dd hh:nn',d1)<</div>>
end;
]]
[[#ShowLabel(qr.GetStr('label'),qr.GetStr('color'),'')]]
<b>>#qr['title']<</b>
</div>
[[#qr['htmlprefix']]]
<div[[#s]]>>
rp1:=CoRegExp.Create;
rp1.Pattern:='(<img[^>]+?)\swidth=[^ >]+([^>]*?>)';
rp1.Global:=true;
rp1.IgnoreCase:=true;
rp2:=CoRegExp.Create;
rp2.Pattern:='(<img[^>]+?)\sheight=[^ >]+([^>]*?>)';
rp2.Global:=true;
rp2.IgnoreCase:=true;
rp3:=CoRegExp.Create;
rp3.Pattern:='(<img)';
rp3.Global:=true;
rp3.IgnoreCase:=true;
Context.SendHTML(
rp3.Replace(
rp2.Replace(
rp1.Replace(
qr.GetStr('content')
,'$1$2')//rp1
,'$1$2')//rp2
,'$1 style="width:60wv;max-width:'+IntToStr(rw-4)+'em;"')
);
<</div>
<div style="height:75vh;margin-top:4pt;border-top:4px solid gold;color:#9999AA;font-size:0.8em;">
<span title="[[=qr['guid']]]">>=qr['url']<</span>
<a class="raw" target="postview" href="[[=r]]PostRaw.xxm?[[=Context.ContextString(csQueryString)]]"
title="[[=FormatDateTime('ddd yyyy-mm-dd hh:nn:ss',double(qr['created']))]]"> ℹ </a>
</div>>
finally
qr.Free;
end;
Context.Include('dFoot.xxmi');
db.BeginTrans;
try
DecodeDate(Date,dy,dm,dd);
if db.Execute('delete from "UserPost" where user_id=$1 and post_id=$2',[Session.UserID,id])=1 then
//db.Execute('update "Subscription" set postsopened=coalesce(postsopened,0)+1 where id=$1',[sid]);
db.Execute('insert into "SubCount" (month,subscription_id,postsopened) values ($1,$2,1)'+
' on conflict (month,subscription_id) do update set postsopened="SubCount".postsopened+1',
[dy*100+dm,sid]);
db.CommitTrans;
except
db.RollbackTrans;
//raise;
end;