/
Default.xxm
351 lines (330 loc) · 12.3 KB
/
Default.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
[[@DataLank,xxmSession,fCommon,Variants]][[!var
qr:TQueryResult;
xx:array of Variant;
s,sql0,sql1,sql2,sql2b,sql3,sqlPostID,sqlPubDate,cat:string;
d,d0,f,l,id,id0,lx,qrTimeout:integer;
d1:TDateTime;
loadMore,cList:boolean;
const
descasc:array[boolean] of string=('desc','asc');
lessthan:array[boolean] of string=('<','>');
procedure CheckCList;
begin
if not cList then
begin
Context.SendHTML('<div style="padding-bottom:2pt;">');
Context.SendHTML('<div class="date">');
Context.Send(FormatDateTime('ddd yyyy-mm-dd hh:nn',UtcNow+Session.TimeBias));
Context.SendHTML('</div>'#13#10);
cList:=true;
end;
end;
]][[
if Session.UserID=0 then
begin
Context.Include('dHead.xxmi');
<<h1 style="background-color:gold;"> feeder</h1>
<h2>a simple feed reader the way I like it</h2>
<h3>and I hope you do too</h3>
<p>To authenticate, please login or register with <i>tx</i>:</p>
<p><a href="/tx/Auth.xxm[[?'app','feeder','key',Session.Key]]" style="font-size:2em;font-weight:bold;font-style:italic;">tx...</a></p>
<p>More about feeder: <a href="https://github.com/stijnsanders/feeder">GitHub...</a></p>
<div style="border-bottom:4px solid gold;"></div>>
loadMore:=false;
end
else
begin
loadMore:=Context['x'].Value<>'';
qrTimeout:=30;//default, see below
cat:=Context['c'].Value;
f:=Context['f'].AsInteger;
if not loadMore then
begin
Context.Include('dHead.xxmi');
<<div style="z-index:5;position:fixed;top:0;right:1.2em;background-color:gold;padding:4pt;">
[[
if Context.ContextString(csQueryString)<>'' then
begin
<<a href="." style="font-weight:bold;"><img src="img_l.png" width="16" height="16" alt="All"/> All</a><br />>
end;
]]
<span id="postcount" onclick="document.location.reload(false);">>
qr:=TQueryResult.Create(Session.Connection,'select count(*) from "UserPost" where user_id=$1',[Session.UserID]);
try
Context.Send(qr.GetInt(0));
finally
qr.Free;
end;
<</span>
<a href="Feeds.xxm"><img src="img_c.png" width="16" height="16" border="0" alt="Feeds..." /></a>
</div>
[[
if Context['nowrap'].AsInteger<>0 then
begin
<<style type="text/css">
DIV.post{white-space:nowrap;}
DIV.postread{white-space:nowrap;}
</style>>
end;
]]
<script src="feeder.js?v=12"></script>
<div id="black" style="z-index:6;position:fixed;display:none;top:0;left:0;width:100vw;height:100vh;background-color:black;filter:opacity(0.5);user-select:none;" onclick="return doClose();"></div>
<div id="postbox" class="postbox" style="z-index:8;position:fixed;display:none;top:0.5em;right:1em;user-select:none;">
<a href="#" onclick="return doExpress();"><img src="img_e.png" width="16" height="16" alt="express" /></a>
<a href="#" onclick="return doHere();"><img src="img_d.png" width="16" height="16" alt="load here" /></a>
<a href="#" id="postlink" target="_blank" rel="noreferrer" onclick="doClose();"><img src="img_u.png" width="16" height="16" alt="load new tab" /></a>
<a href="#" id="nextlink" rel="noreferrer" onclick="return doNext();"><img src="img_r.png" width="16" height="16" alt="load next post" /></a>
<a href="#" onclick="return doClose();" style="width:4em;"><img src="img_x.png" width="16" height="16" alt="close post view" /></a>
</div>
<iframe id="postview" name="postview" style="z-index:7;position:fixed;display:none;left:1em;top:2em;background-color:#DDDDDD;border:1px solid black;" onload="doPostLoad();" src="about:blank"></iframe>
<script>
window.open("about:blank","postview");
document.body.onscroll=doScroll;
window.onbeforeunload=function(){window.scrollTo(0,0);}
</script>>
end;
sql0:='select S.label, S.color, S.readwidth, P.id, P.title, P.pubdate, P.url, X.id as ReadID';
sql1:=' from "UserPost" X left outer join "Post" P on P.id=X.post_id';
sql2:=' left outer join "Subscription" S on S.id=X.subscription_id';
sql2b:='';
sql3:=' where X.user_id=$1';
sqlPostID:='X.post_id';
sqlPubDate:='X.pubdate';
if loadMore then lx:=2 else lx:=0;
SetLength(xx,1+lx);
if Context['hl'].Value<>'' then
sql2b:=' inner join "HotListSubscription" HLS on HLS.hotlist_id='+IntToStr(Context['hl'].AsInteger)+' and HLS.subscription_id=S.id';
if cat='' then
if f=0 then
if (Context['search'].Value='') and (Context['title'].Value='') then
if (Context['d'].Value='') and (Context['h'].Value='') then
begin
//show category links
if not loadMore then
begin
cList:=false;
Context.Flush;
qr:=TQueryResult.Create(Session.Connection,
'select distinct S.Category from "Subscription" S where S.user_id=$1 and S.Category<>'''' order by 1',[Session.UserID]);
try
if not qr.EOF then
begin
CheckCList;
while qr.Read do
begin
s:=qr.GetStr(0);
<<div class="catlink"><a href="?c=[[=s]]">>=s<</a></div>
[[
end;
end;
finally
qr.Free;
end;
qr:=TQueryResult.Create(Session.Connection,
'select H.* from "HotList" H where H.user_id=$1 order by lower(H.label)',[Session.UserID]);
try
if not qr.EOF then
begin
CheckCList;
while qr.Read do
begin
<<a href="?hl=[[.id]]" style="text-decoration:none;color:black;">>#ShowLabel(qr.GetStr('label'),qr.GetStr('color'),'')<</a>
[[
end;
end;
finally
qr.Free;
end;
if cList then
begin
Context.SendHTML('</div>'#13#10);
Context.Flush;
end;
end;
//query: no extra criteria
SetLength(xx,2+lx);
xx[1]:=Session.UserID;
end
else
if Context['d'].Value='' then
begin
sql3:=sql3+' and floor((X.pubdate+$2)*24)::int%24=$3';
SetLength(xx,3+lx);
xx[1]:=double(Session.TimeBias);
xx[2]:=Context['h'].AsInteger;
end
else
begin
sql3:=sql3+' and X.pubdate>$2 and X.pubdate<$3';
SetLength(xx,3+lx);
d1:=UtcNow-Context['d'].AsInteger;
xx[1]:=double(VarFromDateTime(d1-4.0/24.0));
xx[2]:=double(VarFromDateTime(d1+4.0/24.0));
end
else
begin
sql1:=' from "Post" P left outer join "UserPost" X on X.post_id=P.id and X.user_id=$1';
sql2:=' left outer join "Subscription" S on S.feed_id=P.feed_id and S.user_id=$1';
sqlPostID:='P.id';
sqlPubDate:='P.pubdate';
SetLength(xx,2+lx);
if Context['title'].Value='' then
begin
sql3:=' where P.title||'' ''||P.content ilike $2';
xx[1]:='%'+StringReplace(Context['search'].Value,' ','%',[rfReplaceAll])+'%';
end
else
begin
sql3:=' where P.title ilike $2';
xx[1]:='%'+StringReplace(Context['title'].Value,' ','%',[rfReplaceAll])+'%';
end;
end
else
begin
sql1:=' from "Post" P left outer join "UserPost" X on X.post_id=P.id and X.user_id=$1';
sql2:=' left outer join "Subscription" S on S.feed_id=P.feed_id and S.user_id=$1';
sql3:=' where P.feed_id=$2';
sqlPostID:='P.id';
sqlPubDate:='P.pubdate';
SetLength(xx,2+lx);
xx[1]:=f;
if Context['search'].Value<>'' then
begin
sql3:=sql3
+' and P.title||'' ''||P.content ilike $3';
SetLength(xx,3+lx);
xx[2]:='%'+StringReplace(Context['search'].Value,' ','%',[rfReplaceAll])+'%';
qrTimeout:=300;
end
else
if Context['title'].Value<>'' then
begin
sql3:=sql3
+' and P.title ilike $3';
SetLength(xx,3+lx);
xx[2]:='%'+StringReplace(Context['title'].Value,' ','%',[rfReplaceAll])+'%';
end;
end
else
if (Context['search'].Value='') and (Context['title'].Value='') then
begin
sql3:=sql3+' and S.category=$2';
SetLength(xx,2+lx);
xx[1]:=cat;
end
else
begin
sql1:=' from "Post" P inner join "Subscription" S on S.feed_id=P.feed_id and S.user_id=$1';
sql2:=' left outer join "UserPost" X on X.post_id=P.id and X.user_id=$1';
sql3:=' where S.category=$2';
sqlPostID:='P.id';
sqlPubDate:='P.pubdate';
SetLength(xx,2+lx);
xx[1]:=cat;
if Context['search'].Value<>'' then
begin
sql3:=sql3
+' and P.title||'' ''||P.content ilike $3';
SetLength(xx,3+lx);
xx[2]:='%'+StringReplace(Context['search'].Value,' ','%',[rfReplaceAll])+'%';
qrTimeout:=300;
end
else
if Context['title'].Value<>'' then
begin
sql3:=sql3
+' and P.title ilike $3';
SetLength(xx,3+lx);
xx[2]:='%'+StringReplace(Context['title'].Value,' ','%',[rfReplaceAll])+'%';
end;
end;
if Context['q'].Value='' then l:=0 else l:=Context['q'].AsInteger;
if l=0 then l:=Session.DefaultBatchSize;//default
xx[0]:=Session.UserID;
if loadMore then
begin
id0:=Context['x'].AsInteger;
Session.Connection.Execute('set statement_timeout=90000',[]);
qr:=TQueryResult.Create(Session.Connection,'select pubdate from "Post" where id=$1',[id0]);
try
d1:=double(qr[0]);
finally
qr.Free;
end;
d:=Trunc(d1+Session.TimeBias);
sql3:=sql3+' and (('+sqlPubDate+'=$'+IntToStr(Length(xx)-1)+' and '+sqlPostID+'>$'+IntToStr(Length(xx))+
') or ('+sqlPubDate+lessthan[Context['a'].AsInteger<>0]+'$'+IntToStr(Length(xx)-1)+'))';
xx[Length(xx)-2]:=double(d1);
xx[Length(xx)-1]:=id0;
end
else
begin
d:=Trunc(UtcNow+Session.TimeBias);
Context.Flush;
Session.Connection.Execute('set statement_timeout='+IntToStr(qrTimeout)+'000',[]);
end;
if false then begin
<<p style="border:2px solid red;">>=sql0+sql1+sql2+sql3+' order by '+sqlPubDate+' '+descasc[Context['a'].AsInteger<>0]+', '+sqlPostID+' limit '+IntToStr(l)<</p>>
end;
qr:=TQueryResult.Create(Session.Connection,
sql0+sql1+sql2+sql2b+sql3+' order by '+sqlPubDate+' '+descasc[Context['a'].AsInteger<>0]+', '+sqlPostID+' limit '+IntToStr(l),xx);
try
if qr.EOF then
begin
if loadMore then Context.SendHTML('-') else
begin
FreeAndNil(qr);
qr:=TQueryResult.Create(Session.Connection,'select S.id from "Subscription" S where S.user_id=$1 limit 1',[Session.UserID]);
if qr.EOF then
begin
d1:=Now;//UtcNow?
<<div class="post" id="p0">
<div class="date" title="[[=FormatDateTime('ddd yyyy-mm-dd hh:nn:ss',d1)]]">>=FormatDateTime('hh:nn',d1)<</div>
<div class="label" title="feeder: system message" style="background-color:#FFCC00;color:#000000;border:1px solid #000000;border-radius:0;">feeder</div>
<a href="welcome.html" postqs="?id=0" onclick="return doPost(this,event);">Welcome! (click here)</a>
</div>>
end
else
begin
<<div class="date">no posts found</div>>
end;
end;
end
else
begin
id:=0;
while qr.Read do
begin
id:=qr.GetInt('id');
d1:=double(qr['pubdate'])+Session.TimeBias;
d0:=Trunc(d1);
if d0<>d then
begin
<<div>
<div class="date">>=FormatDateTime('ddd yyyy-mm-dd',d1)<</div>
</div>>
d:=d0;
end;
<<div class="post[[if qr.IsNull('ReadID') then Context.SendHTML('read');]]" id="p[[=qr['id']]]">
<div class="date" title="[[=FormatDateTime('ddd yyyy-mm-dd hh:nn:ss',d1)]]">>=FormatDateTime('hh:nn',d1)<</div>
[[#ShowLabel(qr.GetStr('label'),qr.GetStr('color'),'')]]
<a href="[[=qr['url']]]" postqs="[[?'id',qr['id']]]" onclick="return doPost(this,event);">>#qr['title']<</a>
</div>>
end;
if loadMore then
Context.SendHTML(';'+IntToStr(id))
else
begin
<<div id="trailer" style="height:100vh;border-bottom:4px solid gold;" x="[[=id]]"></div>>
end;
end;
finally
qr.Free;
end;
end;
if not loadMore then
Context.Include('dFoot.xxmi');