-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNew.xxm
216 lines (201 loc) · 6.63 KB
/
New.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
[[@xxmSession,DataLank,fCommon,Variants,Windows]][[!var
s,t,lbl,cat,c:string;
id,id1,sid,rw,i:integer;
ur:Variant;
qr:TQueryResult;
d:TDateTime;
h:THandle;
hl:array of integer;
const
DefaultReadWidth=32;
]][[
Context.Include('dHead.xxmi');
case Context['x'].AsInteger of
0://form
begin
<<form method="post" action="?">
<input type="hidden" name="x" value="1" />
<dl>
<dt>URL</dt>
<dd>
<input type="text" name="url" id="f1" style="width:80vw;" autocomplete="off" />
<br />
Optionally enter the URL of the home page here to have the header searched for a feed URL.
</dd>
<dt>name (optional)</dt>
<dd><input type="text" name="name" value="" autocomplete="off" /> (leave empty for default //TODO: from URL data)</dd>
<dt>category</dt>
<dd>
<select name="category">>
qr:=TQueryResult.Create(Session.Connection,'select distinct category from "Subscription" where user_id=$1 order by 1',[Session.UserID]);
try
while qr.Read do
begin
<<option>>=qr[0]<</option>>
end;
finally
qr.Free;
end;
<<option value="---" style="color:#006600;">→ new category</option>
</select>
<input type="text" name="categoryNew" />
</dd>
<dt>label text</dt>
<dd><input type="text" name="label" value="" autocomplete="off" /> (leave empty for default: feed name)</dd>
<dt>label color</dt>
<dd>>#ColorPicker('')<</dd>
<dt>read width</dt>
<dd><input type="text" name="readwidth" value="[[=integer(DefaultReadWidth)]]" style="width:4em;" /> M-width</dd>
<dt>auto-unread after (optional)</dt>
<dd><input type="text" name="autounread0" value="" style="width:4em;" />
<select name="autounread1">
<option value="0">hours</option>
<option value="1" selected="1">days</option>
<option vaule="2">weeks</option>
</select>
</dd>>
qr:=TQueryResult.Create(Session.Connection,
'select H.*'+
',(select count(*) from "HotListSubscription" HLS where HLS.hotlist_id=H.id) as HLS'+
' from "HotList" H'+
' where H.user_id=$1'+
' order by lower(H.label)',[Session.UserID]);
try
if not qr.EOF then
begin
<<dt>hot lists</dt><dd>>
while qr.Read do
begin
<<label>
<input type="checkbox" name="hl[[.id]]" value="1" />
[[#ShowLabel(qr.GetStr('label'),qr.GetStr('color'),'')]]
<span style="color:#CCCCCC;">([[.HLS]])</span>
</label>>
end;
<</dd>>
end;
finally
qr.Free;
end;
<</dl>
<p><input type="submit" value="Add Feed" /></p>
</form>
<script>document.getElementById("f1").focus();</script>
<p><a href="Feeds.xxm">back</a>,
<a href="OPML.xxm?x=1">OPML import...</a>
</p>>
end;
1://add new
begin
s:=Context['url'].Value;
//TODO: sanity checks?
//TODO: first GET here? (or IPC call to feeder eater)
if (Copy(s,1,7)<>'http://') and (Copy(s,1,8)<>'https://') then
//raise Exception.Create('HTTP/HTTPS URL required');
s:='http://'+s;
t:=Context['name'].Value;
qr:=TQueryResult.Create(Session.Connection,'select id, name from "Feed" where url=$1',[s]);
try
if qr.EOF then id:=0 else
begin
id:=qr.GetInt(0);
t:=qr.GetStr(1);
end;
finally
qr.Free;
end;
if id=0 then
begin
if t='' then t:=NameFromFeedURL(s);
id:=Session.Connection.Insert('Feed',['name',t,'url',s,'created',double(UtcNow)],'id');
<<p>Feed added. Posts may not appear until first time the fetching schedule loaded current posts.</p>>
//poke eater to check new feeds
h:=OpenEvent(EVENT_MODIFY_STATE,true,'Global\FeederEaterNewFeed');
SetEvent(h);
CloseHandle(h);
end
else
begin
Session.Connection.Execute('insert into "UserPost" (user_id,post_id,subscription_id,pubdate) select $1,P.id,S.id,P.pubdate'
+' from "Post" P'
+' inner join "Subscription" S on S.feed_id=P.feed_id and S.user_id=$1'
+' left outer join "UserPost" X on X.subscription_id=S.id and X.post_id=P.id and X.user_id=S.user_id'
+' where P.feed_id=$2 and P.pubDate>$3 and X.id is null',
[Session.UserID,id,double(UtcNow-366.0)]);
<<p>Feed found, listing posts up to one year old as unread.</p>>
end;
qr:=TQueryResult.Create(Session.Connection,'select id from "Subscription" where user_id=$1 and feed_id=$2',[Session.UserID,id]);
try
if qr.EOF then id1:=0 else id1:=qr.GetInt(0);
finally
qr.Free;
end;
if id1=0 then
begin
lbl:=Context['label'].Value;
if lbl='' then lbl:=t;
cat:=Context['category'].Value;
if cat='---' then cat:=Context['categoryNew'].Value;
c:=CheckColor(Context['color'].Value);
rw:=Context['readwidth'].AsInteger;
if Context['autounread0'].Value='' then
ur:=Null
else
case Context['autounread1'].AsInteger of
0:ur:=Context['autounread0'].AsInteger;//hours
1:ur:=Context['autounread0'].AsInteger*24;//days
2:ur:=Context['autounread0'].AsInteger*24*7;//weeks
end;
d:=UtcNow;
sid:=Session.Connection.Insert('Subscription',
['user_id',Session.UserID
,'feed_id',id
,'label',lbl
,'category',cat
,'color',c
,'readwidth',rw
,'autounread',ur
,'created',double(d)
],'id');
qr:=TQueryResult.Create(Session.Connection,
'select H.*'+
' from "HotList" H'+
' where H.user_id=$1'+
' order by lower(H.label)',[Session.UserID]);
try
i:=0;
SetLength(hl,qr.Count);
while qr.Read do
begin
hl[i]:=qr.GetInt('id');
inc(i);
end;
finally
qr.Free;
end;
for i:=0 to Length(hl)-1 do
if Context['hl'+IntToStr(hl[i])].AsInteger=1 then
Session.Connection.Execute('insert into "HotListSubscription" (hotlist_id,subscription_id) values ($1,$2)',[hl[i],sid]);
<<p>Subscription added</p>>
<<div class="post">
<div class="date">>=FormatDateTime('yyyy-mm-dd',double(d)+Session.TimeBias)<</div>
[[#ShowLabel(lbl,c,'')]]
"[[=t]]"
<span style="color:#CCCCCC;">>=s<</span>
</div>>
end
else
begin
//update category? (allow duplicates?)
<<p style="color:red;">Already subscribed, not adding</p>>
end;
<<p>
<a href="New.xxm">add another...</a><br />
<a href="Feeds.xxm">back to feeds...</a><br />
<a href=".">back to posts...</a><br />
</p>>
end;
else
raise Exception.Create('Unknown action');
end;
Context.Include('dFoot.xxmi');