-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPostRaw.xxm
205 lines (200 loc) · 6.34 KB
/
PostRaw.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
[[@DataLank,xxmSession,VBScript_RegExp_55_TLB,fCommon]][[!var
qr:TQueryResult;
id,i,j,l:integer;
db:TDataConnection;
d1:TDateTime;
s:UTF8String;
d:AnsiChar;
function u(a,b:integer):WideString;
begin
//Result:=UTF8Decode(Copy(s,a,b));
Result:=UTF8ToWideString(Copy(s,a,b));
end;
]][[
Context.Include('dHead.xxmi');
id:=Context['id'].AsInteger;
db:=Session.Connection;
qr:=TQueryResult.Create(db,
'select P.*, S.label, S.color, S.readwidth'+
' from "Post" P'+
' 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
//TODO: sanitize HTML (either here or in eater)
d1:=double(qr['pubdate'])+Session.TimeBias;
<<div style="padding-bottom:4pt;">
<div class="date" title="[[=FormatDateTime('ddd yyyy-mm-dd hh:nn:ss',d1)]]">>=FormatDateTime('mm-dd hh:nn',d1)<</div>
[[#ShowLabel(qr.GetStr('label'),qr.GetStr('color'),'')]]
<b>>=qr['title']<</b>
</div>>
if Context['raw'].AsInteger<>0 then
begin
<<div>>=qr['content']<</div>>
end
else
begin
<<style>
SPAN.e{color:#999;}
SPAN.a{color:#990;}
SPAN.v{color:#009;}
SPAN.x{color:#090;}
SPAN.d{color:#900;}
SPAN.c{color:#CCC;}
</style><div>>
s:=UTF8Encode(qr.GetStr('content'));
l:=Length(s);
i:=1;
while i<=l do
begin
case s[i] of
'<'://start element
begin
if (i+4<=l) and (Copy(s,i,4)='<!--') then
begin
//comment
j:=i+4;
while (j+3<=l) and not((s[j]='-') and (s[j+1]='-') and (s[j+2]='>')) do inc(j);
inc(j,2);
<<span class="c">>=u(i,j-i+1)<</span>>
i:=j;
end
else
if (i+9<=l) and (Copy(s,i,9)='<![CDATA[') then
begin
//cdata section
j:=i+8;
while (j+3<=l) and not((s[j]=']') and (s[j+1]=']') and (s[j+2]='>')) do inc(j);
inc(j,2);
<<span class="d">>=u(i,j-i+1)<</span>>
i:=j;
end
else
if (i+1<=l) and (s[i+1]='/') then
begin
//closing element
j:=i+2;
while (j<=l) and (s[j]<>'>') do inc(j);
<<span class="e">>=u(i,j-i+1)<</span>>
i:=j;
end
else
begin
//element
j:=i+1;
while (j<=l) and (s[j]<>'>') and (s[j]>' ') do inc(j);
while (j<=l) and (s[j]<' ') do inc(j);
if (j<=l) and (s[j]='>') then
begin
<<span class="e">>=u(i,j-i+1)<</span>>
i:=j;
end
else
if (j+1<=l) and (s[j]='/') and (s[j+1]='>') then
begin
inc(j);
<<span class="e">>=u(i,j-i+1)<</span>>
i:=j;
end;
if i<>j then
begin
<<span class="e">>=u(i,j-i)<</span>>
i:=j;
while (i<=l) and (s[i]<>'>') and (s[i]<>'/') do
begin
//attributes
j:=i;
while (j<=l) and (s[j]<>'=') and (s[j]<>'>') and (s[j]>' ') do inc(j);
<<span class="a">>=u(i,j-i)<</span>>
if (j+1<=l) and (s[j]='=') and ((s[j+1]='"') or (s[j+1]='''')) then
begin
d:=s[j+1];
//attribute value enclosed in double or single quotes
<<span class="c">>=u(j,2)<</span><span class="v">>
inc(j,2);
i:=j;
while (j<=l) and (s[j]<>d) do
if s[j]='&' then
begin
Context.Send(u(i,j-i));
i:=j;
inc(j);//'&'
while (j<=l) and not(s[j]=';') and not(s[j]='>') and not(s[j]='&') and not(s[j]<=' ') and (j-i<=8) do inc(j);
if (j-i<=8) then
begin
if (j<=l) and (s[j]=';') then inc(j);
<</span><span class="x">>=u(i,j-i)<</span><span class="v">>
i:=j;
end;
end
else
inc(j);
Context.Send(u(i,j-i));
<</span>>
if (j<=l) then
begin
<<span class="c">>=s[j]<</span>> //assert s[j]=d
inc(j);
end;
end
else
if (j<=l) and (s[j]='=') then
begin
//attribute value not enclosed
<<span class="c">>=s[j]<</span>>
inc(j);
i:=j;
while (j<=l) and (s[j]<>'>') and (s[j]<>'/') and (s[j]>' ') do inc(j);
<<span class="v">>=u(i,j-i)<</span>>
end;
//else no value?
i:=j;
while (j<=l) and (s[j]<=' ') do inc(j);
if i<>j then
begin
Context.Send(u(i,j-i));
i:=j;
end;
end;
if (i<=l) then
begin
<<span class="e">>
if (i<=l) and (s[i]='/') then
begin
Context.Send(s[i]);
inc(i);
end;
Context.Send(s[i]);//assert '>'
<</span>>
end;
end;
end;
inc(i);
end;
'&'://start entity
begin
j:=i;
inc(j);//'&'
while (j<=l) and not(s[j]=';') and not(s[j]='<') and not(s[j]='&') and not(s[j]<=' ') do inc(j);
if (j<=l) and (s[j]=';') then inc(j);
<<span class="x">>=u(i,j-i)<</span>>
i:=j;
end;
else
begin
j:=i;
while (j<=l) and not(s[j]='<') and not(s[j]='&') do inc(j);
Context.Send(u(i,j-i));
i:=j;
end;
end;
end;
<</div>>
end;
<<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="Post.xxm?[[=Context.ContextString(csQueryString)]]"> ℹ </a>
</div>>
finally
qr.Free;
end;
Context.Include('dFoot.xxmi');