]>
Commit | Line | Data |
---|---|---|
1cd17194 | 1 | <? |
4356293a | 2 | session_start(); |
090e250b | 3 | |
1c7f75ed AD |
4 | if (!$_SESSION["uid"]) { exit; } |
5 | ||
4356293a | 6 | define(SCHEMA_VERSION, 2); |
1cd17194 | 7 | |
82baad4a | 8 | require_once "config.php"; |
648472a7 | 9 | require_once "db.php"; |
3bac89ad | 10 | require_once "db-prefs.php"; |
82baad4a AD |
11 | require_once "functions.php"; |
12 | require_once "magpierss/rss_fetch.inc"; | |
1cd17194 | 13 | |
4356293a AD |
14 | $op = $_REQUEST["op"]; |
15 | ||
16 | if ($op == "rpc" || $op == "updateAllFeeds") { | |
17 | header("Content-Type: application/xml"); | |
18 | } | |
19 | ||
406d9489 AD |
20 | $script_started = getmicrotime(); |
21 | ||
648472a7 | 22 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
d76a3b03 | 23 | |
5136011e AD |
24 | if (!$link) { |
25 | if (DB_TYPE == "mysql") { | |
26 | print mysql_error(); | |
27 | } | |
28 | // PG seems to display its own errors just fine by default. | |
29 | return; | |
30 | } | |
31 | ||
648472a7 AD |
32 | if (DB_TYPE == "pgsql") { |
33 | pg_query("set client_encoding = 'utf-8'"); | |
34 | } | |
7ec2a838 | 35 | |
295f9b42 | 36 | /* |
7ec2a838 AD |
37 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); |
38 | ||
39 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
40 | ||
41 | if ($schema_version != SCHEMA_VERSION) { | |
42 | print "Error: database schema is invalid | |
43 | (got version $schema_version; expected ".SCHEMA_VERSION.")"; | |
44 | return; | |
45 | } | |
295f9b42 AD |
46 | */ |
47 | ||
331900c6 | 48 | $fetch = $_GET["fetch"]; |
175847de | 49 | |
8143ae1f AD |
50 | /* FIXME this needs reworking */ |
51 | ||
fc69e641 AD |
52 | function getGlobalCounters($link) { |
53 | $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries | |
4356293a | 54 | WHERE unread = true AND owner_uid = " . $_SESSION["uid"]); |
fc69e641 AD |
55 | $c_id = db_fetch_result($result, 0, "c_id"); |
56 | print "<counter id='global-unread' counter='$c_id'/>"; | |
57 | } | |
58 | ||
8143ae1f AD |
59 | function getTagCounters($link) { |
60 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
61 | FROM ttrss_tags,ttrss_entries WHERE | |
4356293a | 62 | ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND |
8143ae1f AD |
63 | post_id = ttrss_entries.id AND unread = true GROUP BY tag_name |
64 | UNION | |
4356293a AD |
65 | select tag_name,0 as count FROM ttrss_tags |
66 | WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); | |
8143ae1f AD |
67 | |
68 | $tags = array(); | |
69 | ||
70 | while ($line = db_fetch_assoc($result)) { | |
71 | $tags[$line["tag_name"]] += $line["count"]; | |
72 | } | |
73 | ||
74 | foreach (array_keys($tags) as $tag) { | |
75 | $unread = $tags[$tag]; | |
76 | ||
77 | $tag = htmlspecialchars($tag); | |
78 | print "<tag id=\"$tag\" counter=\"$unread\"/>"; | |
79 | } | |
80 | } | |
81 | ||
090e250b AD |
82 | function getLabelCounters($link) { |
83 | ||
84 | $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
4356293a | 85 | WHERE marked = true AND unread = true AND owner_uid = ".$_SESSION["uid"]); |
090e250b | 86 | |
d61fd764 | 87 | $count = db_fetch_result($result, 0, "count"); |
090e250b AD |
88 | |
89 | print "<label id=\"-1\" counter=\"$count\"/>"; | |
90 | ||
4356293a AD |
91 | $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM |
92 | ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); | |
090e250b AD |
93 | |
94 | while ($line = db_fetch_assoc($result)) { | |
95 | ||
96 | $id = -$line["id"] - 11; | |
97 | ||
98 | error_reporting (0); | |
d61fd764 AD |
99 | |
100 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
655be073 AD |
101 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND |
102 | owner_uid = ".$_SESSION["uid"]); | |
090e250b | 103 | |
d61fd764 | 104 | $count = db_fetch_result($tmp_result, 0, "count"); |
090e250b | 105 | |
ab3f3f72 | 106 | print "<label id=\"$id\" counter=\"$count\"/>"; |
090e250b AD |
107 | |
108 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
109 | ||
110 | } | |
111 | } | |
112 | ||
8073cce7 AD |
113 | function getFeedCounter($link, $id) { |
114 | ||
115 | $result = db_query($link, "SELECT | |
116 | count(id) as count FROM ttrss_entries | |
4356293a | 117 | WHERE feed_id = '$id' AND unread = true"); |
8073cce7 AD |
118 | |
119 | $count = db_fetch_result($result, 0, "count"); | |
120 | ||
121 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
122 | } | |
090e250b | 123 | |
8073cce7 AD |
124 | function getFeedCounters($link) { |
125 | ||
090e250b AD |
126 | $result = db_query($link, "SELECT id, |
127 | (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id | |
128 | AND unread = true) as count | |
4356293a | 129 | FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); |
090e250b AD |
130 | |
131 | while ($line = db_fetch_assoc($result)) { | |
132 | ||
133 | $id = $line["id"]; | |
134 | $count = $line["count"]; | |
135 | ||
136 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
137 | } | |
138 | } | |
139 | ||
8143ae1f | 140 | function outputFeedList($link, $tags = false) { |
175847de | 141 | |
1a66d16e AD |
142 | print "<html><head> |
143 | <title>Tiny Tiny RSS : Feedlist</title> | |
430bf183 AD |
144 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; |
145 | ||
4769ddaf | 146 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { |
430bf183 AD |
147 | print "<link rel=\"stylesheet\" type=\"text/css\" |
148 | href=\"tt-rss_compact.css\"/>"; | |
149 | } else { | |
150 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
151 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
152 | } | |
153 | ||
154 | print "<script type=\"text/javascript\" src=\"functions.js\"></script> | |
1a66d16e AD |
155 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> |
156 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
3745788e | 157 | </head><body onload=\"init()\">"; |
254e0e4b AD |
158 | |
159 | print "<ul class=\"feedList\" id=\"feedList\">"; | |
160 | ||
4356293a AD |
161 | $owner_uid = $_SESSION["uid"]; |
162 | ||
8143ae1f | 163 | if (!$tags) { |
254e0e4b | 164 | |
8143ae1f | 165 | /* virtual feeds */ |
254e0e4b | 166 | |
8143ae1f | 167 | $result = db_query($link, "SELECT count(id) as num_starred |
4356293a | 168 | FROM ttrss_entries WHERE marked = true AND unread = true AND owner_uid = '$owner_uid'"); |
8143ae1f | 169 | $num_starred = db_fetch_result($result, 0, "num_starred"); |
254e0e4b | 170 | |
3745788e | 171 | $class = "virt"; |
8add756a AD |
172 | |
173 | if ($num_starred > 0) $class .= "Unread"; | |
174 | ||
175 | printFeedEntry(-1, $class, "Starred articles", $num_starred, | |
4668523d | 176 | "images/mark_set.png", $link); |
48f0adb0 | 177 | |
4769ddaf | 178 | if (get_pref($link, 'ENABLE_LABELS')) { |
8143ae1f AD |
179 | |
180 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
4356293a | 181 | ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); |
8143ae1f AD |
182 | |
183 | if (db_num_rows($result) > 0) { | |
184 | print "<li><hr></li>"; | |
185 | } | |
186 | ||
187 | while ($line = db_fetch_assoc($result)) { | |
48f0adb0 | 188 | |
8143ae1f AD |
189 | error_reporting (0); |
190 | ||
191 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
655be073 AD |
192 | WHERE (" . $line["sql_exp"] . ") AND unread = true |
193 | AND owner_uid = '$owner_uid'"); | |
8143ae1f AD |
194 | |
195 | $count = db_fetch_result($tmp_result, 0, "count"); | |
196 | ||
3745788e | 197 | $class = "label"; |
8143ae1f AD |
198 | |
199 | if ($count > 0) { | |
200 | $class .= "Unread"; | |
201 | } | |
202 | ||
203 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
204 | ||
205 | printFeedEntry(-$line["id"]-11, | |
4668523d | 206 | $class, $line["description"], $count, "images/label.png", $link); |
8143ae1f AD |
207 | |
208 | } | |
48f0adb0 AD |
209 | } |
210 | ||
8143ae1f AD |
211 | print "<li><hr></li>"; |
212 | ||
213 | $result = db_query($link, "SELECT *, | |
214 | (SELECT count(id) FROM ttrss_entries | |
215 | WHERE feed_id = ttrss_feeds.id) AS total, | |
216 | (SELECT count(id) FROM ttrss_entries | |
217 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
4356293a | 218 | FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title"); |
8143ae1f AD |
219 | |
220 | $actid = $_GET["actid"]; | |
221 | ||
222 | /* real feeds */ | |
223 | ||
224 | $lnum = 0; | |
225 | ||
226 | $total_unread = 0; | |
227 | ||
48f0adb0 | 228 | while ($line = db_fetch_assoc($result)) { |
8143ae1f AD |
229 | |
230 | $feed = $line["title"]; | |
231 | $feed_id = $line["id"]; | |
232 | ||
233 | $subop = $_GET["subop"]; | |
234 | ||
235 | $total = $line["total"]; | |
236 | $unread = $line["unread"]; | |
237 | ||
238 | // $class = ($lnum % 2) ? "even" : "odd"; | |
48f0adb0 | 239 | |
3745788e | 240 | $class = "feed"; |
8143ae1f AD |
241 | |
242 | if ($unread > 0) $class .= "Unread"; | |
243 | ||
244 | if ($actid == $feed_id) { | |
245 | $class .= "Selected"; | |
392d4563 | 246 | } |
48f0adb0 | 247 | |
8143ae1f AD |
248 | $total_unread += $unread; |
249 | ||
4668523d | 250 | printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link); |
8143ae1f AD |
251 | |
252 | ++$lnum; | |
48f0adb0 | 253 | } |
8143ae1f | 254 | } else { |
a1a8a2be | 255 | |
8143ae1f | 256 | // tags |
a1a8a2be | 257 | |
8143ae1f AD |
258 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count |
259 | FROM ttrss_tags,ttrss_entries WHERE | |
4356293a AD |
260 | post_id = ttrss_entries.id AND unread = true |
261 | AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name | |
8143ae1f | 262 | UNION |
4356293a | 263 | select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'"); |
8143ae1f AD |
264 | |
265 | $tags = array(); | |
266 | ||
267 | while ($line = db_fetch_assoc($result)) { | |
268 | $tags[$line["tag_name"]] += $line["count"]; | |
1a66d16e | 269 | } |
8143ae1f AD |
270 | |
271 | foreach (array_keys($tags) as $tag) { | |
272 | ||
273 | $unread = $tags[$tag]; | |
274 | ||
275 | $class = "odd"; | |
276 | ||
277 | if ($unread > 0) { | |
278 | $class .= "Unread"; | |
279 | } | |
280 | ||
4668523d | 281 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); |
8143ae1f AD |
282 | |
283 | } | |
1a66d16e | 284 | |
e828e31e | 285 | } |
82baad4a | 286 | |
dc33ec95 | 287 | if (db_num_rows($result) == 0) { |
4356293a | 288 | print "<li>No tags/feeds to display.</li>"; |
dc33ec95 AD |
289 | } |
290 | ||
8143ae1f | 291 | print "</ul>"; |
1cd17194 | 292 | |
caa4e57f AD |
293 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; |
294 | ||
c3b81db0 AD |
295 | } |
296 | ||
297 | ||
298 | if ($op == "rpc") { | |
299 | ||
300 | $subop = $_GET["subop"]; | |
301 | ||
090e250b | 302 | if ($subop == "getLabelCounters") { |
8073cce7 | 303 | $aid = $_GET["aid"]; |
090e250b AD |
304 | print "<rpc-reply>"; |
305 | getLabelCounters($link); | |
8073cce7 AD |
306 | if ($aid) { |
307 | getFeedCounter($link, $aid); | |
308 | } | |
090e250b AD |
309 | print "</rpc-reply>"; |
310 | } | |
311 | ||
312 | if ($subop == "getFeedCounters") { | |
313 | print "<rpc-reply>"; | |
314 | getFeedCounters($link); | |
315 | print "</rpc-reply>"; | |
316 | } | |
317 | ||
318 | if ($subop == "getAllCounters") { | |
319 | print "<rpc-reply>"; | |
320 | getLabelCounters($link); | |
321 | getFeedCounters($link); | |
8143ae1f | 322 | getTagCounters($link); |
fc69e641 | 323 | getGlobalCounters($link); |
090e250b | 324 | print "</rpc-reply>"; |
090e250b AD |
325 | } |
326 | ||
f4c10d44 AD |
327 | if ($subop == "mark") { |
328 | $mark = $_GET["mark"]; | |
648472a7 | 329 | $id = db_escape_string($_GET["id"]); |
f4c10d44 AD |
330 | |
331 | if ($mark == "1") { | |
332 | $mark = "true"; | |
333 | } else { | |
334 | $mark = "false"; | |
335 | } | |
336 | ||
648472a7 | 337 | $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark |
f4c10d44 AD |
338 | WHERE id = '$id'"); |
339 | } | |
340 | ||
caa4e57f | 341 | if ($subop == "updateFeed") { |
648472a7 | 342 | $feed_id = db_escape_string($_GET["feed"]); |
9cfc649a | 343 | |
648472a7 | 344 | $result = db_query($link, |
caa4e57f | 345 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'"); |
9cfc649a | 346 | |
648472a7 AD |
347 | if (db_num_rows($result) > 0) { |
348 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
caa4e57f AD |
349 | // update_rss_feed($link, $feed_url, $feed_id); |
350 | } | |
9cfc649a | 351 | |
caa4e57f | 352 | print "DONE-$feed_id"; |
9cfc649a | 353 | |
caa4e57f | 354 | return; |
9cfc649a AD |
355 | } |
356 | ||
090e250b | 357 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { |
c5142cca | 358 | |
c3b81db0 | 359 | update_all_feeds($link, true); |
c3b81db0 | 360 | |
ab3f3f72 AD |
361 | $omode = $_GET["omode"]; |
362 | ||
363 | if (!$omode) $omode = "tfl"; | |
364 | ||
090e250b | 365 | print "<rpc-reply>"; |
ab3f3f72 AD |
366 | if (strchr($omode, "l")) getLabelCounters($link); |
367 | if (strchr($omode, "f")) getFeedCounters($link); | |
368 | if (strchr($omode, "t")) getTagCounters($link); | |
fc69e641 | 369 | getGlobalCounters($link); |
090e250b | 370 | print "</rpc-reply>"; |
c3b81db0 AD |
371 | } |
372 | ||
373 | if ($subop == "catchupPage") { | |
374 | ||
375 | $ids = split(",", $_GET["ids"]); | |
376 | ||
377 | foreach ($ids as $id) { | |
378 | ||
648472a7 | 379 | db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW() |
c3b81db0 AD |
380 | WHERE id = '$id'"); |
381 | ||
382 | } | |
383 | ||
384 | print "Marked active page as read."; | |
385 | } | |
295f9b42 AD |
386 | |
387 | if ($subop == "sanityCheck") { | |
388 | ||
389 | $error_code = 0; | |
390 | ||
391 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
392 | ||
393 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
394 | ||
395 | if ($schema_version != SCHEMA_VERSION) { | |
396 | $error_code = 5; | |
397 | } | |
398 | ||
399 | print "<error code='$error_code'/>"; | |
400 | } | |
fefa6ca3 AD |
401 | |
402 | if ($subop == "globalPurge") { | |
403 | ||
404 | print "<rpc-reply>"; | |
405 | global_purge_old_posts($link, true); | |
406 | print "</rpc-reply>"; | |
407 | ||
408 | } | |
409 | ||
c3b81db0 AD |
410 | } |
411 | ||
412 | if ($op == "feeds") { | |
413 | ||
8143ae1f AD |
414 | $tags = $_GET["tags"]; |
415 | ||
c3b81db0 AD |
416 | $subop = $_GET["subop"]; |
417 | ||
418 | if ($subop == "catchupAll") { | |
6d15e1ef AD |
419 | db_query($link, "UPDATE ttrss_entries SET |
420 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); | |
c3b81db0 AD |
421 | } |
422 | ||
8143ae1f | 423 | outputFeedList($link, $tags); |
c3b81db0 | 424 | |
1cd17194 AD |
425 | } |
426 | ||
427 | if ($op == "view") { | |
428 | ||
d76a3b03 | 429 | $id = $_GET["id"]; |
8073cce7 | 430 | $feed_id = $_GET["feed"]; |
d76a3b03 | 431 | |
648472a7 | 432 | $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); |
a1a8a2be | 433 | |
70830c87 AD |
434 | $addheader = $_GET["addheader"]; |
435 | ||
648472a7 | 436 | $result = db_query($link, "SELECT title,link,content,feed_id,comments, |
b7f4bda2 AD |
437 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url |
438 | FROM ttrss_entries | |
d76a3b03 | 439 | WHERE id = '$id'"); |
1cd17194 | 440 | |
70830c87 | 441 | if ($addheader) { |
f0601b87 | 442 | print "<html><head> |
70830c87 AD |
443 | <title>Tiny Tiny RSS : Article $id</title> |
444 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
c05608c2 | 445 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
70830c87 | 446 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
f0601b87 | 447 | </head><body>"; |
70830c87 AD |
448 | } |
449 | ||
d76a3b03 | 450 | if ($result) { |
1cd17194 | 451 | |
648472a7 | 452 | $line = db_fetch_assoc($result); |
1cd17194 | 453 | |
b7f4bda2 AD |
454 | if ($line["icon_url"]) { |
455 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
456 | } else { | |
457 | $feed_icon = " "; | |
458 | } | |
d76a3b03 | 459 | |
f7181e9b AD |
460 | if ($line["comments"] && $line["link"] != $line["comments"]) { |
461 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
462 | } else { | |
463 | $entry_comments = ""; | |
464 | } | |
465 | ||
e828e31e AD |
466 | print "<div class=\"postReply\">"; |
467 | ||
468 | print "<div class=\"postHeader\"><table>"; | |
469 | ||
470 | print "<tr><td><b>Title:</b></td> | |
471 | <td width='100%'>" . $line["title"] . "</td></tr>"; | |
f7181e9b | 472 | |
e828e31e | 473 | print "<tr><td><b>Link:</b></td> |
f7181e9b AD |
474 | <td width='100%'> |
475 | <a href=\"" . $line["link"] . "\">".$line["link"]."</a> | |
476 | $entry_comments</td></tr>"; | |
e828e31e AD |
477 | |
478 | print "</table></div>"; | |
479 | ||
480 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
481 | print "<div class=\"postContent\">" . $line["content"] . "</div>"; | |
482 | ||
483 | print "</div>"; | |
484 | ||
090e250b | 485 | print "<script type=\"text/javascript\"> |
8143ae1f | 486 | update_label_counters('$feed_id'); |
090e250b | 487 | </script>"; |
d76a3b03 | 488 | } |
70830c87 AD |
489 | |
490 | if ($addheader) { | |
491 | print "</body></html>"; | |
492 | } | |
1cd17194 AD |
493 | } |
494 | ||
495 | if ($op == "viewfeed") { | |
496 | ||
497 | $feed = $_GET["feed"]; | |
d76a3b03 | 498 | $skip = $_GET["skip"]; |
476cac42 | 499 | $subop = $_GET["subop"]; |
f175937c | 500 | $view_mode = $_GET["view"]; |
f0601b87 | 501 | $addheader = $_GET["addheader"]; |
cb1083a1 | 502 | $limit = $_GET["limit"]; |
a1a8a2be | 503 | |
8d7008c7 AD |
504 | if (!$feed) { |
505 | print "Error: no feed to display."; | |
506 | return; | |
507 | } | |
508 | ||
ac53063a AD |
509 | if (!$skip) $skip = 0; |
510 | ||
476cac42 | 511 | if ($subop == "undefined") $subop = ""; |
1cd17194 | 512 | |
f0601b87 AD |
513 | if ($addheader) { |
514 | print "<html><head> | |
ac43eba1 | 515 | <title>Tiny Tiny RSS : Feed $feed</title> |
430bf183 AD |
516 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; |
517 | ||
4769ddaf | 518 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { |
430bf183 AD |
519 | print "<link rel=\"stylesheet\" |
520 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
521 | ||
522 | } else { | |
523 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
524 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
525 | } | |
526 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
f0601b87 AD |
527 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
528 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
b623b3ed | 529 | </head><body onload='init()'>"; |
f0601b87 AD |
530 | } |
531 | ||
dcee8f61 AD |
532 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { |
533 | ||
534 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
535 | WHERE id = '$feed'"); | |
536 | ||
537 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
538 | ||
539 | update_rss_feed($link, $feed_url, $feed); | |
540 | ||
541 | } | |
542 | ||
0e32076b | 543 | if ($subop == "MarkAllRead") { |
d76a3b03 | 544 | |
0e32076b AD |
545 | if (sprintf("%d", $feed) != 0) { |
546 | ||
547 | if ($feed > 0) { | |
548 | db_query($link, "UPDATE ttrss_entries | |
549 | SET unread = false,last_read = NOW() | |
254e0e4b | 550 | WHERE feed_id = '$feed'"); |
0e32076b AD |
551 | |
552 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
553 | ||
554 | if ($feed == -1) { | |
555 | db_query($link, "UPDATE ttrss_entries | |
556 | SET unread = false,last_read = NOW() | |
557 | WHERE marked = true"); | |
558 | } | |
559 | ||
560 | } else if ($feed < -10) { // label | |
561 | ||
7db95187 | 562 | $label_id = -$feed - 11; |
0e32076b | 563 | |
7db95187 AD |
564 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels |
565 | WHERE id = '$label_id'"); | |
566 | ||
567 | if ($tmp_result) { | |
568 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
569 | ||
570 | db_query($link, "UPDATE ttrss_entries | |
571 | SET unread = false,last_read = NOW() | |
572 | WHERE $sql_exp"); | |
573 | } | |
254e0e4b | 574 | } |
0e32076b AD |
575 | } else { // tag |
576 | // FIXME, implement catchup for tags | |
a1a8a2be | 577 | } |
0e32076b | 578 | |
a1a8a2be | 579 | } |
d76a3b03 | 580 | |
175847de | 581 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 582 | |
c374a3fe AD |
583 | $search = $_GET["search"]; |
584 | ||
52b51244 AD |
585 | $search_mode = $_GET["smode"]; |
586 | ||
f175937c | 587 | if ($search) { |
ac53063a AD |
588 | $search_query_part = "(upper(title) LIKE upper('%$search%') |
589 | OR content LIKE '%$search%') AND"; | |
f175937c AD |
590 | } else { |
591 | $search_query_part = ""; | |
592 | } | |
593 | ||
594 | $view_query_part = ""; | |
595 | ||
596 | if ($view_mode == "Starred") { | |
597 | $view_query_part = " marked = true AND "; | |
ac53063a AD |
598 | } |
599 | ||
ac43eba1 AD |
600 | if ($view_mode == "Unread") { |
601 | $view_query_part = " unread = true AND "; | |
602 | } | |
603 | ||
b5aa95e7 AD |
604 | if ($view_mode == "Unread or Starred") { |
605 | $view_query_part = " (unread = true OR marked = true) AND "; | |
606 | } | |
607 | ||
bdd01d3f AD |
608 | if ($view_mode == "Unread or Updated") { |
609 | $view_query_part = " (unread = true OR last_read is NULL) AND "; | |
610 | } | |
611 | ||
254e0e4b | 612 | /* $result = db_query($link, "SELECT count(id) AS total_entries |
36bf7496 AD |
613 | FROM ttrss_entries WHERE |
614 | $search_query_part | |
615 | feed_id = '$feed'"); | |
e6d1c0a0 | 616 | |
254e0e4b | 617 | $total_entries = db_fetch_result($result, 0, "total_entries"); */ |
e6d1c0a0 | 618 | |
648472a7 | 619 | /* $result = db_query("SELECT count(id) AS unread_entries |
ac43eba1 AD |
620 | FROM ttrss_entries WHERE |
621 | $search_query_part | |
622 | unread = true AND | |
623 | feed_id = '$feed'"); | |
624 | ||
648472a7 | 625 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ |
ac43eba1 | 626 | |
8d7008c7 | 627 | if ($limit && $limit != "All") { |
82c9223c | 628 | $limit_query_part = "LIMIT " . $limit; |
ad3cb710 | 629 | } |
f0601b87 | 630 | |
254e0e4b AD |
631 | $vfeed_query_part = ""; |
632 | ||
52b51244 AD |
633 | // override query strategy and enable feed display when searching globally |
634 | if ($search_mode == "All feeds") { | |
635 | $query_strategy_part = "id > 0"; | |
636 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
637 | id = feed_id) as feed_title,"; | |
638 | } else if (sprintf("%d", $feed) == 0) { | |
8143ae1f AD |
639 | $query_strategy_part = "ttrss_entries.id > 0"; |
640 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
641 | id = feed_id) as feed_title,"; | |
642 | } else if ($feed >= 0) { | |
254e0e4b | 643 | $query_strategy_part = "feed_id = '$feed'"; |
48f0adb0 | 644 | } else if ($feed == -1) { // starred virtual feed |
254e0e4b | 645 | $query_strategy_part = "marked = true"; |
48f0adb0 AD |
646 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
647 | id = feed_id) as feed_title,"; | |
648 | } else if ($feed <= -10) { // labels | |
649 | $label_id = -$feed - 11; | |
650 | ||
651 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
652 | WHERE id = '$label_id'"); | |
653 | ||
654 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
655 | ||
254e0e4b AD |
656 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
657 | id = feed_id) as feed_title,"; | |
658 | } else { | |
48f0adb0 | 659 | $query_strategy_part = "id > 0"; // dumb |
254e0e4b AD |
660 | } |
661 | ||
52b51244 | 662 | |
f99321a3 AD |
663 | $order_by = "updated DESC"; |
664 | ||
665 | // if ($feed < -10) { | |
666 | // $order_by = "feed_id,updated DESC"; | |
667 | // } | |
668 | ||
48f0adb0 AD |
669 | if ($feed < -10) error_reporting (0); |
670 | ||
8143ae1f AD |
671 | if (sprintf("%d", $feed) != 0) { |
672 | ||
673 | $result = db_query($link, "SELECT | |
674 | id,title,updated,unread,feed_id,marked,link,last_read, | |
675 | SUBSTRING(last_read,1,19) as last_read_noms, | |
676 | $vfeed_query_part | |
677 | SUBSTRING(updated,1,19) as updated_noms | |
678 | FROM | |
679 | ttrss_entries | |
680 | WHERE | |
aee86c2e | 681 | owner_uid = '".$_SESSION["uid"]."' AND |
8143ae1f AD |
682 | $search_query_part |
683 | $view_query_part | |
684 | $query_strategy_part ORDER BY $order_by | |
685 | $limit_query_part"); | |
686 | ||
687 | } else { | |
688 | // browsing by tag | |
689 | ||
690 | $result = db_query($link, "SELECT | |
691 | ttrss_entries.id as id,title,updated,unread,feed_id, | |
692 | marked,link,last_read, | |
c05a19f3 | 693 | SUBSTRING(last_read,1,19) as last_read_noms, |
254e0e4b | 694 | $vfeed_query_part |
c05a19f3 | 695 | SUBSTRING(updated,1,19) as updated_noms |
8143ae1f AD |
696 | FROM |
697 | ttrss_entries,ttrss_tags | |
698 | WHERE | |
aee86c2e | 699 | ttrss_entries.owner_uid = '".$_SESSION["uid"]."' AND |
8143ae1f AD |
700 | post_id = ttrss_entries.id AND tag_name = '$feed' AND |
701 | $view_query_part | |
702 | $search_query_part | |
703 | $query_strategy_part ORDER BY $order_by | |
704 | $limit_query_part"); | |
705 | } | |
d76a3b03 | 706 | |
48f0adb0 AD |
707 | if (!$result) { |
708 | print "<tr><td colspan='4' align='center'> | |
709 | Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>"; | |
710 | return; | |
711 | } | |
712 | ||
a1a8a2be | 713 | $lnum = 0; |
48f0adb0 AD |
714 | |
715 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
716 | ||
e1123aee | 717 | $num_unread = 0; |
d76a3b03 | 718 | |
648472a7 | 719 | while ($line = db_fetch_assoc($result)) { |
d76a3b03 | 720 | |
a1a8a2be | 721 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 722 | |
ad99045e AD |
723 | $id = $line["id"]; |
724 | $feed_id = $line["feed_id"]; | |
725 | ||
c43f77f5 | 726 | // printf("L %d (%s) > U %d (%s) = %d<br>", |
c05a19f3 | 727 | // strtotime($line["last_read_noms"]), $line["last_read_noms"], |
c43f77f5 AD |
728 | // strtotime($line["updated"]), $line["updated"], |
729 | // strtotime($line["last_read"]) >= strtotime($line["updated"])); | |
730 | ||
ecb14114 | 731 | /* if ($line["last_read"] != "" && $line["updated"] != "" && |
c05a19f3 | 732 | strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) { |
c43f77f5 AD |
733 | |
734 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
735 | alt=\"Updated\">"; | |
736 | ||
737 | } else { | |
738 | ||
5bfef089 | 739 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" |
c43f77f5 AD |
740 | alt=\"Updated\">"; |
741 | ||
ecb14114 AD |
742 | } */ |
743 | ||
4cc6ea5e AD |
744 | if ($line["last_read"] == "" && |
745 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
746 | ||
ecb14114 AD |
747 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" |
748 | alt=\"Updated\">"; | |
749 | } else { | |
750 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
751 | alt=\"Updated\">"; | |
c43f77f5 | 752 | } |
b197f117 | 753 | |
8158c57a | 754 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
a1a8a2be | 755 | $class .= "Unread"; |
e1123aee AD |
756 | ++$num_unread; |
757 | } | |
d76a3b03 | 758 | |
8158c57a | 759 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
f4c10d44 AD |
760 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" |
761 | alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>"; | |
762 | } else { | |
763 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
764 | alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>"; | |
765 | } | |
766 | ||
ac43eba1 | 767 | $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" . |
b197f117 AD |
768 | $line["title"] . "</a>"; |
769 | ||
d5224f0d | 770 | print "<tr class='$class' id='RROW-$id'>"; |
5f89f780 | 771 | // onclick=\"javascript:view($id,$feed_id)\"> |
b197f117 | 772 | |
8d7008c7 AD |
773 | print "<td valign='center' align='center'>$update_pic</td>"; |
774 | print "<td valign='center' align='center'>$marked_pic</td>"; | |
b197f117 | 775 | |
8d7008c7 | 776 | print "<td width='25%'> |
a3ee2a38 | 777 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; |
254e0e4b AD |
778 | |
779 | if ($line["feed_title"]) { | |
780 | print "<td width='50%'>$content_link</td>"; | |
2db4190c AD |
781 | print "<td width='20%'> |
782 | <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>"; | |
254e0e4b AD |
783 | } else { |
784 | print "<td width='70%'>$content_link</td>"; | |
785 | } | |
d76a3b03 | 786 | |
a1a8a2be | 787 | print "</tr>"; |
d76a3b03 | 788 | |
a1a8a2be AD |
789 | ++$lnum; |
790 | } | |
d76a3b03 | 791 | |
ac53063a | 792 | if ($lnum == 0) { |
a82065a1 | 793 | print "<tr><td align='center'>No articles found.</td></tr>"; |
047bae73 | 794 | } |
a2015351 | 795 | |
a1a8a2be | 796 | print "</table>"; |
6113ef7d AD |
797 | |
798 | print "<script type=\"text/javascript\"> | |
bb7cface | 799 | document.onkeydown = hotkey_handler; |
8143ae1f | 800 | update_label_counters('$feed'); |
6113ef7d | 801 | </script>"; |
d76a3b03 | 802 | |
f0601b87 AD |
803 | if ($addheader) { |
804 | print "</body></html>"; | |
805 | } | |
806 | ||
1cd17194 AD |
807 | } |
808 | ||
0e091d38 | 809 | if ($op == "pref-rpc") { |
331900c6 | 810 | |
0e091d38 | 811 | $subop = $_GET["subop"]; |
331900c6 | 812 | |
83fe4d6d AD |
813 | if ($subop == "unread") { |
814 | $ids = split(",", $_GET["ids"]); | |
815 | foreach ($ids as $id) { | |
648472a7 | 816 | db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); |
83fe4d6d | 817 | } |
0e091d38 AD |
818 | |
819 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
820 | } |
821 | ||
822 | if ($subop == "read") { | |
823 | $ids = split(",", $_GET["ids"]); | |
824 | foreach ($ids as $id) { | |
648472a7 | 825 | db_query($link, "UPDATE ttrss_entries |
b197f117 | 826 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); |
83fe4d6d | 827 | } |
0e091d38 AD |
828 | |
829 | print "Marked selected feeds as unread."; | |
830 | ||
831 | } | |
832 | ||
833 | } | |
834 | ||
835 | if ($op == "pref-feeds") { | |
836 | ||
837 | $subop = $_GET["subop"]; | |
838 | ||
508a81e1 | 839 | if ($subop == "editSave") { |
648472a7 AD |
840 | $feed_title = db_escape_string($_GET["t"]); |
841 | $feed_link = db_escape_string($_GET["l"]); | |
d148926e | 842 | $upd_intl = db_escape_string($_GET["ui"]); |
5d73494a | 843 | $purge_intl = db_escape_string($_GET["pi"]); |
508a81e1 AD |
844 | $feed_id = $_GET["id"]; |
845 | ||
d148926e AD |
846 | if (strtoupper($upd_intl) == "DEFAULT") |
847 | $upd_intl = 0; | |
848 | ||
5d73494a AD |
849 | if (strtoupper($purge_intl) == "DEFAULT") |
850 | $purge_intl = 0; | |
851 | ||
140aae81 AD |
852 | if (strtoupper($purge_intl) == "DISABLED") |
853 | $purge_intl = -1; | |
854 | ||
648472a7 | 855 | $result = db_query($link, "UPDATE ttrss_feeds SET |
d148926e | 856 | title = '$feed_title', feed_url = '$feed_link', |
5d73494a AD |
857 | update_interval = '$upd_intl', |
858 | purge_interval = '$purge_intl' | |
859 | WHERE id = '$feed_id'"); | |
508a81e1 | 860 | |
83fe4d6d AD |
861 | } |
862 | ||
331900c6 | 863 | if ($subop == "remove") { |
331900c6 | 864 | |
b0b4abcf | 865 | if (!WEB_DEMO_MODE) { |
331900c6 | 866 | |
b0b4abcf AD |
867 | $ids = split(",", $_GET["ids"]); |
868 | ||
869 | foreach ($ids as $id) { | |
648472a7 | 870 | db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'"); |
4769ddaf | 871 | |
273a2f6b | 872 | $icons_dir = ICONS_DIR; |
d5caaae5 | 873 | |
4769ddaf AD |
874 | if (file_exists($icons_dir . "/$id.ico")) { |
875 | unlink($icons_dir . "/$id.ico"); | |
d5caaae5 | 876 | } |
b0b4abcf | 877 | } |
331900c6 AD |
878 | } |
879 | } | |
880 | ||
881 | if ($subop == "add") { | |
b0b4abcf AD |
882 | |
883 | if (!WEB_DEMO_MODE) { | |
331900c6 | 884 | |
648472a7 | 885 | $feed_link = db_escape_string($_GET["link"]); |
b0b4abcf | 886 | |
648472a7 | 887 | $result = db_query($link, |
4356293a | 888 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')"); |
331900c6 | 889 | |
648472a7 | 890 | $result = db_query($link, |
e9c54861 | 891 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); |
331900c6 | 892 | |
648472a7 | 893 | $feed_id = db_fetch_result($result, 0, "id"); |
331900c6 | 894 | |
b0b4abcf AD |
895 | if ($feed_id) { |
896 | update_rss_feed($link, $feed_link, $feed_id); | |
897 | } | |
898 | } | |
331900c6 | 899 | } |
a0d53889 | 900 | |
ab3d0b99 AD |
901 | $result = db_query($link, "SELECT id,title,feed_url,last_error |
902 | FROM ttrss_feeds WHERE last_error != ''"); | |
903 | ||
904 | if (db_num_rows($result) > 0) { | |
905 | ||
906 | print "<div class=\"warning\">"; | |
907 | ||
908 | print "<b>Feeds with update errors:</b>"; | |
909 | ||
910 | print "<ul class=\"nomarks\">"; | |
911 | ||
912 | while ($line = db_fetch_assoc($result)) { | |
913 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
914 | $line["last_error"]; | |
915 | } | |
916 | ||
917 | print "</ul>"; | |
918 | print "</div>"; | |
919 | ||
920 | } | |
921 | ||
a0d53889 AD |
922 | print "<table class=\"prefAddFeed\"><tr> |
923 | <td><input id=\"fadd_link\"></td> | |
924 | <td colspan=\"4\" align=\"right\"> | |
925 | <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr> | |
926 | </table>"; | |
927 | ||
648472a7 | 928 | $result = db_query($link, "SELECT |
d148926e | 929 | id,title,feed_url,substring(last_updated,1,16) as last_updated, |
5d73494a | 930 | update_interval,purge_interval |
c0e5a40e | 931 | FROM |
4356293a | 932 | ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title"); |
1cd17194 | 933 | |
331900c6 | 934 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 | 935 | print "<tr class=\"title\"> |
5d73494a AD |
936 | <td> </td><td>Select</td><td width=\"30%\">Title</td> |
937 | <td width=\"30%\">Link</td> | |
938 | <td width=\"10%\">Update Interval</td> | |
939 | <td width=\"10%\">Purge Days</td> | |
d148926e | 940 | <td>Last updated</td></tr>"; |
007bda35 AD |
941 | |
942 | $lnum = 0; | |
943 | ||
648472a7 | 944 | while ($line = db_fetch_assoc($result)) { |
007bda35 AD |
945 | |
946 | $class = ($lnum % 2) ? "even" : "odd"; | |
9b307248 | 947 | |
331900c6 | 948 | $feed_id = $line["id"]; |
603c27f8 AD |
949 | |
950 | $edit_feed_id = $_GET["id"]; | |
951 | ||
9b307248 AD |
952 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
953 | $class .= "Grayed"; | |
954 | } | |
955 | ||
331900c6 | 956 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
007bda35 | 957 | |
273a2f6b | 958 | $icon_file = ICONS_DIR . "/$feed_id.ico"; |
c0e5a40e AD |
959 | |
960 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
961 | $feed_icon = "<img width=\"16\" height=\"16\" | |
273a2f6b | 962 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; |
c0e5a40e AD |
963 | } else { |
964 | $feed_icon = " "; | |
965 | } | |
966 | print "<td align='center'>$feed_icon</td>"; | |
967 | ||
6e0584e9 AD |
968 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); |
969 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
970 | ||
9b307248 | 971 | if (!$edit_feed_id || $subop != "edit") { |
603c27f8 AD |
972 | |
973 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 | 974 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
603c27f8 AD |
975 | |
976 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
5d73494a | 977 | $edit_title . "</a></td>"; |
603c27f8 | 978 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
5d73494a | 979 | $edit_link . "</a></td>"; |
d148926e AD |
980 | |
981 | if ($line["update_interval"] == "0") | |
982 | $line["update_interval"] = "Default"; | |
983 | ||
5d73494a AD |
984 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
985 | $line["update_interval"] . "</a></td>"; | |
d148926e | 986 | |
5d73494a AD |
987 | if ($line["purge_interval"] == "0") |
988 | $line["purge_interval"] = "Default"; | |
989 | ||
140aae81 AD |
990 | if ($line["purge_interval"] < 0) |
991 | $line["purge_interval"] = "Disabled"; | |
992 | ||
5d73494a AD |
993 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
994 | $line["purge_interval"] . "</a></td>"; | |
9b307248 AD |
995 | |
996 | } else if ($feed_id != $edit_feed_id) { | |
997 | ||
e9c54861 AD |
998 | print "<td><input disabled=\"true\" type=\"checkbox\" |
999 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
9b307248 | 1000 | |
6e0584e9 AD |
1001 | print "<td>$edit_title</td>"; |
1002 | print "<td>$edit_link</td>"; | |
9b307248 | 1003 | |
d148926e AD |
1004 | if ($line["update_interval"] == "0") |
1005 | $line["update_interval"] = "Default"; | |
1006 | ||
1007 | print "<td>" . $line["update_interval"] . "</td>"; | |
1008 | ||
5d73494a AD |
1009 | if ($line["purge_interval"] == "0") |
1010 | $line["purge_interval"] = "Default"; | |
1011 | ||
140aae81 AD |
1012 | if ($line["purge_interval"] < 0) |
1013 | $line["purge_interval"] = "Disabled"; | |
1014 | ||
5d73494a AD |
1015 | print "<td>" . $line["purge_interval"] . "</td>"; |
1016 | ||
603c27f8 AD |
1017 | } else { |
1018 | ||
e6cb77a0 | 1019 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; |
603c27f8 | 1020 | |
6e0584e9 AD |
1021 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; |
1022 | print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>"; | |
d148926e | 1023 | print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>"; |
5d73494a | 1024 | print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>"; |
d148926e | 1025 | |
603c27f8 | 1026 | } |
0afbd851 AD |
1027 | |
1028 | if (!$line["last_updated"]) $line["last_updated"] = "Never"; | |
1029 | ||
007bda35 | 1030 | print "<td>" . $line["last_updated"] . "</td>"; |
603c27f8 | 1031 | |
007bda35 AD |
1032 | print "</tr>"; |
1033 | ||
1034 | ++$lnum; | |
1035 | } | |
1036 | ||
0afbd851 AD |
1037 | if ($lnum == 0) { |
1038 | print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>"; | |
1039 | } | |
1040 | ||
007bda35 AD |
1041 | print "</table>"; |
1042 | ||
603c27f8 AD |
1043 | print "<p>"; |
1044 | ||
1045 | if ($subop == "edit") { | |
1046 | print "Edit feed: | |
e828e31e AD |
1047 | <input type=\"submit\" class=\"button\" |
1048 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
1049 | <input type=\"submit\" class=\"button\" | |
8158c57a | 1050 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
603c27f8 AD |
1051 | } else { |
1052 | ||
603c27f8 AD |
1053 | print " |
1054 | Selection: | |
e828e31e AD |
1055 | <input type=\"submit\" class=\"button\" |
1056 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
1057 | <input type=\"submit\" class=\"button\" | |
1058 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
1059 | ||
4769ddaf | 1060 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { |
f92db4f5 | 1061 | print " |
e828e31e AD |
1062 | <input type=\"submit\" class=\"button\" |
1063 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
1064 | <input type=\"submit\" class=\"button\" | |
1065 | onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> "; | |
f92db4f5 AD |
1066 | } |
1067 | print " | |
e828e31e AD |
1068 | All feeds: |
1069 | <input type=\"submit\" | |
8158c57a | 1070 | class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">"; |
10c5820d | 1071 | |
603c27f8 AD |
1072 | } |
1073 | ||
f5a50b25 AD |
1074 | print "<h3>OPML Import</h3> |
1075 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> | |
1076 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
1077 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
1078 | type=\"submit\" value=\"Import\"> | |
1079 | </form>"; | |
1080 | ||
007bda35 AD |
1081 | } |
1082 | ||
a0d53889 AD |
1083 | if ($op == "pref-filters") { |
1084 | ||
1085 | $subop = $_GET["subop"]; | |
1086 | ||
1087 | if ($subop == "editSave") { | |
a0d53889 | 1088 | |
648472a7 AD |
1089 | $regexp = db_escape_string($_GET["r"]); |
1090 | $descr = db_escape_string($_GET["d"]); | |
1091 | $match = db_escape_string($_GET["m"]); | |
1092 | $filter_id = db_escape_string($_GET["id"]); | |
0afbd851 | 1093 | |
648472a7 | 1094 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 1095 | reg_exp = '$regexp', |
0afbd851 AD |
1096 | description = '$descr', |
1097 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
1098 | description = '$match') | |
1099 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
1100 | } |
1101 | ||
1102 | if ($subop == "remove") { | |
1103 | ||
1104 | if (!WEB_DEMO_MODE) { | |
1105 | ||
1106 | $ids = split(",", $_GET["ids"]); | |
1107 | ||
1108 | foreach ($ids as $id) { | |
648472a7 | 1109 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
1110 | |
1111 | } | |
1112 | } | |
1113 | } | |
1114 | ||
1115 | if ($subop == "add") { | |
1116 | ||
de435974 | 1117 | if (!WEB_DEMO_MODE) { |
a0d53889 | 1118 | |
8158c57a | 1119 | $regexp = db_escape_string($_GET["regexp"]); |
648472a7 | 1120 | $match = db_escape_string($_GET["match"]); |
a0d53889 | 1121 | |
648472a7 | 1122 | $result = db_query($link, |
4356293a | 1123 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES |
de435974 | 1124 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
4356293a | 1125 | description = '$match'),'".$_SESSION["uid"]."')"); |
de435974 | 1126 | } |
a0d53889 AD |
1127 | } |
1128 | ||
648472a7 | 1129 | $result = db_query($link, "SELECT description |
a0d53889 AD |
1130 | FROM ttrss_filter_types ORDER BY description"); |
1131 | ||
1132 | $filter_types = array(); | |
1133 | ||
648472a7 | 1134 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1135 | array_push($filter_types, $line["description"]); |
1136 | } | |
1137 | ||
1138 | print "<table class=\"prefAddFeed\"><tr> | |
ea6774cf | 1139 | <td><input id=\"fadd_regexp\"></td> |
a0d53889 | 1140 | <td>"; |
bdc00fe0 | 1141 | print_select("fadd_match", "Title", $filter_types); |
a0d53889 AD |
1142 | |
1143 | print"</td><td colspan=\"4\" align=\"right\"> | |
1144 | <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr> | |
1145 | </table>"; | |
1146 | ||
648472a7 | 1147 | $result = db_query($link, "SELECT |
4b3dff6e | 1148 | id,reg_exp,description, |
a0d53889 AD |
1149 | (SELECT name FROM ttrss_filter_types WHERE |
1150 | id = filter_type) as filter_type_name, | |
1151 | (SELECT description FROM ttrss_filter_types | |
1152 | WHERE id = filter_type) as filter_type_descr | |
1153 | FROM | |
4356293a AD |
1154 | ttrss_filters |
1155 | WHERE | |
1156 | owner_uid = ".$_SESSION["uid"]." | |
1157 | ORDER by reg_exp"); | |
a0d53889 AD |
1158 | |
1159 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
1160 | ||
1161 | print "<tr class=\"title\"> | |
0afbd851 AD |
1162 | <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td> |
1163 | <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>"; | |
a0d53889 AD |
1164 | |
1165 | $lnum = 0; | |
1166 | ||
648472a7 | 1167 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1168 | |
1169 | $class = ($lnum % 2) ? "even" : "odd"; | |
1170 | ||
1171 | $filter_id = $line["id"]; | |
1172 | $edit_filter_id = $_GET["id"]; | |
1173 | ||
1174 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
1175 | $class .= "Grayed"; | |
1176 | } | |
1177 | ||
1178 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
1179 | ||
4b3dff6e | 1180 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); |
ea6774cf AD |
1181 | $line["description"] = htmlspecialchars($line["description"]); |
1182 | ||
a0d53889 AD |
1183 | if (!$edit_filter_id || $subop != "edit") { |
1184 | ||
0afbd851 AD |
1185 | if (!$line["description"]) $line["description"] = "[No description]"; |
1186 | ||
a0d53889 AD |
1187 | print "<td><input onclick='toggleSelectRow(this);' |
1188 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
1189 | ||
1190 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
4b3dff6e | 1191 | $line["reg_exp"] . "</td>"; |
a0d53889 AD |
1192 | |
1193 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
1194 | $line["description"] . "</td>"; | |
1195 | ||
1196 | print "<td>".$line["filter_type_descr"]."</td>"; | |
1197 | ||
1198 | } else if ($filter_id != $edit_filter_id) { | |
1199 | ||
0afbd851 AD |
1200 | if (!$line["description"]) $line["description"] = "[No description]"; |
1201 | ||
a0d53889 AD |
1202 | print "<td><input disabled=\"true\" type=\"checkbox\" |
1203 | id=\"FICHK-".$line["id"]."\"></td>"; | |
1204 | ||
4b3dff6e | 1205 | print "<td>".$line["reg_exp"]."</td>"; |
a0d53889 AD |
1206 | print "<td>".$line["description"]."</td>"; |
1207 | print "<td>".$line["filter_type_descr"]."</td>"; | |
1208 | ||
1209 | } else { | |
1210 | ||
e6cb77a0 | 1211 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; |
a0d53889 | 1212 | |
4b3dff6e | 1213 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. |
a0d53889 AD |
1214 | "\"></td>"; |
1215 | ||
1216 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1217 | "\"></td>"; | |
1218 | ||
1219 | print "<td>"; | |
1220 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
1221 | print "</td>"; | |
1222 | ||
1223 | } | |
1224 | ||
1225 | ||
1226 | print "</tr>"; | |
1227 | ||
1228 | ++$lnum; | |
1229 | } | |
1230 | ||
0afbd851 AD |
1231 | if ($lnum == 0) { |
1232 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
1233 | } | |
1234 | ||
a0d53889 AD |
1235 | print "</table>"; |
1236 | ||
1237 | print "<p>"; | |
1238 | ||
1239 | if ($subop == "edit") { | |
e828e31e AD |
1240 | print "Edit feed: |
1241 | <input type=\"submit\" class=\"button\" | |
1242 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
1243 | <input type=\"submit\" class=\"button\" | |
1244 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
a0d53889 AD |
1245 | |
1246 | } else { | |
1247 | ||
1248 | print " | |
e828e31e AD |
1249 | Selection: |
1250 | <input type=\"submit\" class=\"button\" | |
1251 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
1252 | <input type=\"submit\" class=\"button\" | |
1253 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
a0d53889 AD |
1254 | } |
1255 | } | |
1256 | ||
48f0adb0 AD |
1257 | if ($op == "pref-labels") { |
1258 | ||
1259 | $subop = $_GET["subop"]; | |
1260 | ||
1261 | if ($subop == "editSave") { | |
1262 | ||
1263 | $sql_exp = $_GET["s"]; | |
1264 | $descr = $_GET["d"]; | |
1265 | $label_id = db_escape_string($_GET["id"]); | |
1266 | ||
1267 | // print "$sql_exp : $descr : $label_id"; | |
1268 | ||
1269 | $result = db_query($link, "UPDATE ttrss_labels SET | |
1270 | sql_exp = '$sql_exp', | |
1271 | description = '$descr' | |
1272 | WHERE id = '$label_id'"); | |
1273 | } | |
1274 | ||
1275 | if ($subop == "remove") { | |
1276 | ||
1277 | if (!WEB_DEMO_MODE) { | |
1278 | ||
1279 | $ids = split(",", $_GET["ids"]); | |
1280 | ||
1281 | foreach ($ids as $id) { | |
1282 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
1283 | ||
1284 | } | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | if ($subop == "add") { | |
1289 | ||
1290 | if (!WEB_DEMO_MODE) { | |
1291 | ||
1292 | $exp = $_GET["exp"]; | |
1293 | ||
1294 | $result = db_query($link, | |
4356293a AD |
1295 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) |
1296 | VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')"); | |
48f0adb0 AD |
1297 | } |
1298 | } | |
1299 | ||
1300 | print "<table class=\"prefAddFeed\"><tr> | |
1301 | <td><input id=\"ladd_expr\"></td>"; | |
1302 | ||
1303 | print"<td colspan=\"4\" align=\"right\"> | |
1304 | <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr> | |
1305 | </table>"; | |
1306 | ||
1307 | $result = db_query($link, "SELECT | |
1308 | id,sql_exp,description | |
1309 | FROM | |
4356293a AD |
1310 | ttrss_labels |
1311 | WHERE | |
1312 | owner_uid = ".$_SESSION["uid"]." | |
1313 | ORDER by description"); | |
48f0adb0 AD |
1314 | |
1315 | print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">"; | |
1316 | ||
1317 | print "<tr class=\"title\"> | |
7dc66a61 AD |
1318 | <td width=\"5%\">Select</td><td width=\"40%\">SQL expression |
1319 | <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a> | |
1320 | </td> | |
48f0adb0 AD |
1321 | <td width=\"40%\">Caption</td></tr>"; |
1322 | ||
1323 | $lnum = 0; | |
1324 | ||
1325 | while ($line = db_fetch_assoc($result)) { | |
1326 | ||
1327 | $class = ($lnum % 2) ? "even" : "odd"; | |
1328 | ||
1329 | $label_id = $line["id"]; | |
1330 | $edit_label_id = $_GET["id"]; | |
1331 | ||
1332 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
1333 | $class .= "Grayed"; | |
1334 | } | |
1335 | ||
1336 | print "<tr class=\"$class\" id=\"LILRR-$label_id\">"; | |
1337 | ||
1338 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
1339 | $line["description"] = htmlspecialchars($line["description"]); | |
1340 | ||
1341 | if (!$edit_label_id || $subop != "edit") { | |
1342 | ||
1343 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
1344 | ||
1345 | print "<td><input onclick='toggleSelectRow(this);' | |
1346 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
1347 | ||
1348 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1349 | $line["sql_exp"] . "</td>"; | |
1350 | ||
1351 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1352 | $line["description"] . "</td>"; | |
1353 | ||
1354 | } else if ($label_id != $edit_label_id) { | |
1355 | ||
1356 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1357 | ||
1358 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1359 | id=\"LICHK-".$line["id"]."\"></td>"; | |
1360 | ||
1361 | print "<td>".$line["sql_exp"]."</td>"; | |
1362 | print "<td>".$line["description"]."</td>"; | |
1363 | ||
1364 | } else { | |
1365 | ||
e6cb77a0 | 1366 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; |
48f0adb0 AD |
1367 | |
1368 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
1369 | "\"></td>"; | |
1370 | ||
1371 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1372 | "\"></td>"; | |
1373 | ||
1374 | } | |
1375 | ||
1376 | ||
1377 | print "</tr>"; | |
1378 | ||
1379 | ++$lnum; | |
1380 | } | |
1381 | ||
1382 | if ($lnum == 0) { | |
1383 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
1384 | } | |
1385 | ||
1386 | print "</table>"; | |
1387 | ||
1388 | print "<p>"; | |
1389 | ||
1390 | if ($subop == "edit") { | |
1391 | print "Edit label: | |
1392 | <input type=\"submit\" class=\"button\" | |
1393 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
1394 | <input type=\"submit\" class=\"button\" | |
1395 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
1396 | ||
1397 | } else { | |
1398 | ||
1399 | print " | |
1400 | Selection: | |
1401 | <input type=\"submit\" class=\"button\" | |
1402 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> | |
1403 | <input type=\"submit\" class=\"button\" | |
1404 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; | |
1405 | } | |
1406 | } | |
1407 | ||
e828e31e AD |
1408 | if ($op == "error") { |
1409 | print "<div width=\"100%\" align='center'>"; | |
1410 | $msg = $_GET["msg"]; | |
1411 | print $msg; | |
1412 | print "</div>"; | |
1413 | } | |
1414 | ||
7dc66a61 AD |
1415 | if ($op == "help") { |
1416 | print "<html><head> | |
1417 | <title>Tiny Tiny RSS : Help</title> | |
1418 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
1419 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
7dc66a61 AD |
1420 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
1421 | </head><body>"; | |
1422 | ||
1423 | $tid = sprintf("%d", $_GET["tid"]); | |
1424 | ||
1425 | /* FIXME this badly needs real implementation */ | |
1426 | ||
1427 | print "<div class='helpResponse'>"; | |
1428 | ||
1429 | ?> | |
1430 | ||
1431 | <h1>Help for SQL expressions</h1> | |
1432 | ||
1433 | <h2>Description</h2> | |
1434 | ||
1435 | <p>The «SQL expression» is added to WHERE clause of | |
d1f948d1 | 1436 | view feed query. You can match on ttrss_entries table fields |
7dc66a61 AD |
1437 | and even use subselect to query additional information. This |
1438 | functionality is considered to be advanced and requires basic | |
1439 | understanding of SQL.</p> | |
1440 | ||
1441 | <h2>Examples</h2> | |
1442 | ||
1443 | <pre>unread = true</pre> | |
1444 | ||
1445 | Matches all unread articles | |
1446 | ||
1447 | <pre>title like '%Linux%'</pre> | |
1448 | ||
1449 | Matches all articles which mention Linux in the title. You get the idea. | |
1450 | ||
1451 | <p>See the database schema included in the distribution package for gruesome | |
1452 | details.</p> | |
1453 | ||
1454 | <? | |
1455 | ||
1456 | print "<div align='center'> | |
1457 | <a class=\"helpLink\" | |
1458 | href=\"javascript:window.close()\">(Close this window)</a></div>"; | |
1459 | ||
1460 | print "</div>"; | |
1461 | ||
1462 | print "</body></html>"; | |
1463 | ||
1464 | } | |
1465 | ||
f84a97a3 AD |
1466 | if ($op == "dlg") { |
1467 | $id = $_GET["id"]; | |
6de5d056 | 1468 | $param = $_GET["param"]; |
f84a97a3 AD |
1469 | |
1470 | if ($id == "quickAddFeed") { | |
033e47e0 AD |
1471 | print "Feed URL: <input |
1472 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
1473 | id=\"qafInput\"> | |
f84a97a3 AD |
1474 | <input class=\"button\" |
1475 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> | |
1476 | <input class=\"button\" | |
1477 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1478 | value=\"Cancel\">"; | |
1479 | } | |
6de5d056 AD |
1480 | |
1481 | if ($id == "quickDelFeed") { | |
1482 | ||
1483 | $param = db_escape_string($param); | |
1484 | ||
1485 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
1486 | ||
1487 | if ($result) { | |
1488 | ||
1489 | $f_title = db_fetch_result($result, 0, "title"); | |
1490 | ||
1491 | print "Remove current feed ($f_title)? | |
1492 | <input class=\"button\" | |
1493 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
1494 | <input class=\"button\" | |
1495 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1496 | value=\"Cancel\">"; | |
1497 | } else { | |
1498 | print "Error: Feed $param not found. | |
1499 | <input class=\"button\" | |
1500 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1501 | value=\"Cancel\">"; | |
1502 | } | |
1503 | } | |
1504 | ||
033e47e0 AD |
1505 | if ($id == "search") { |
1506 | ||
1507 | print "<input id=\"searchbox\" class=\"extSearch\" | |
1508 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
1509 | onchange=\"javascript:search()\"> | |
1510 | <select id=\"searchmodebox\"> | |
1511 | <option selected>All feeds</option> | |
1512 | <option>This feed</option> | |
1513 | </select> | |
1514 | <input type=\"submit\" | |
1515 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
1516 | <input class=\"button\" | |
1517 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1518 | value=\"Close\">"; | |
1519 | ||
1520 | } | |
1521 | ||
f84a97a3 AD |
1522 | } |
1523 | ||
e65af9c1 AD |
1524 | if ($op == "updateAllFeeds") { |
1525 | update_all_feeds($link, true); | |
1526 | ||
1527 | print "<rpc-reply>"; | |
1528 | getLabelCounters($link); | |
1529 | getFeedCounters($link); | |
1530 | getTagCounters($link); | |
1531 | getGlobalCounters($link); | |
1532 | print "</rpc-reply>"; | |
1533 | ||
1534 | } | |
1535 | ||
77e96719 AD |
1536 | if ($op == "pref-prefs") { |
1537 | ||
b1895692 | 1538 | $subop = $_REQUEST["subop"]; |
77e96719 AD |
1539 | |
1540 | if ($subop == "Save configuration") { | |
1541 | ||
01d68cf9 AD |
1542 | if (WEB_DEMO_MODE) return; |
1543 | ||
77e96719 AD |
1544 | foreach (array_keys($_POST) as $pref_name) { |
1545 | ||
1546 | $pref_name = db_escape_string($pref_name); | |
1547 | $value = db_escape_string($_POST[$pref_name]); | |
1548 | ||
1549 | $result = db_query($link, "SELECT type_name | |
1550 | FROM ttrss_prefs,ttrss_prefs_types | |
1551 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
1552 | ||
1553 | if (db_num_rows($result) > 0) { | |
1554 | ||
1555 | $type_name = db_fetch_result($result, 0, "type_name"); | |
1556 | ||
5da169d9 AD |
1557 | // print "$pref_name : $type_name : $value<br>"; |
1558 | ||
77e96719 | 1559 | if ($type_name == "bool") { |
5da169d9 | 1560 | if ($value == "1") { |
77e96719 AD |
1561 | $value = "true"; |
1562 | } else { | |
1563 | $value = "false"; | |
1564 | } | |
1565 | } else if ($type_name == "integer") { | |
1566 | $value = sprintf("%d", $value); | |
1567 | } | |
1568 | ||
1569 | // print "$pref_name : $type_name : $value<br>"; | |
1570 | ||
ff485f1d AD |
1571 | db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' |
1572 | WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); | |
77e96719 AD |
1573 | |
1574 | } | |
1575 | ||
1576 | header("Location: prefs.php"); | |
1577 | ||
1578 | } | |
1579 | ||
b1895692 AD |
1580 | } else if ($subop == "getHelp") { |
1581 | ||
1582 | $pref_name = db_escape_string($_GET["pn"]); | |
1583 | ||
1584 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
1585 | WHERE pref_name = '$pref_name'"); | |
1586 | ||
1587 | if (db_num_rows($result) > 0) { | |
1588 | $help_text = db_fetch_result($result, 0, "help_text"); | |
1589 | print $help_text; | |
1590 | } else { | |
1591 | print "Unknown option: $pref_name"; | |
1592 | } | |
1593 | ||
1c7f75ed AD |
1594 | } else if ($subop == "Change password") { |
1595 | ||
1596 | if (WEB_DEMO_MODE) return; | |
1597 | ||
1598 | $old_pw = $_POST["OLD_PASSWORD"]; | |
1599 | $new_pw = $_POST["OLD_PASSWORD"]; | |
1600 | ||
1601 | $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]); | |
1602 | $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]); | |
1603 | ||
1604 | $active_uid = $_SESSION["uid"]; | |
1605 | ||
1606 | if ($old_pw && $new_pw) { | |
1607 | ||
1608 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
1609 | ||
1610 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
1611 | id = '$active_uid' AND (pwd_hash = '$old_pw' OR | |
1612 | pwd_hash = '$old_pw_hash')"); | |
1613 | ||
1614 | if (db_num_rows($result) == 1) { | |
1615 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
1616 | WHERE id = '$active_uid'"); | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | header("Location: prefs.php"); | |
1621 | ||
77e96719 AD |
1622 | } else if ($subop == "Reset to defaults") { |
1623 | ||
01d68cf9 AD |
1624 | if (WEB_DEMO_MODE) return; |
1625 | ||
e1aa0559 AD |
1626 | if (DB_TYPE == "pgsql") { |
1627 | db_query($link,"UPDATE ttrss_user_prefs | |
1628 | SET value = ttrss_prefs.def_value | |
1629 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
1630 | ttrss_prefs.pref_name = ttrss_user_prefs.pref_name"); | |
1631 | } else { | |
1632 | db_query($link, "DELETE FROM ttrss_user_prefs | |
1633 | WHERE owner_uid = ".$_SESSION["uid"]); | |
1634 | initialize_user_prefs($link, $_SESSION["uid"]); | |
1635 | } | |
5da169d9 | 1636 | |
77e96719 AD |
1637 | header("Location: prefs.php"); |
1638 | ||
1639 | } else { | |
1640 | ||
7d4c898a | 1641 | if (!SINGLE_USER_MODE) { |
1c7f75ed | 1642 | |
7d4c898a AD |
1643 | print "<form action=\"backend.php\" method=\"POST\">"; |
1644 | ||
1645 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
1646 | print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>"; | |
1647 | ||
1648 | print "<tr><td width=\"40%\">Old password</td>"; | |
1649 | print "<td><input class=\"editbox\" type=\"password\" | |
1650 | name=\"OLD_PASSWORD\"></td></tr>"; | |
1651 | ||
1652 | print "<tr><td width=\"40%\">New password</td>"; | |
1653 | ||
1654 | print "<td><input class=\"editbox\" type=\"password\" | |
1655 | name=\"NEW_PASSWORD\"></td></tr>"; | |
1656 | ||
1657 | print "</table>"; | |
1658 | ||
1659 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
1660 | ||
1661 | print "<p><input class=\"button\" type=\"submit\" | |
1662 | value=\"Change password\" name=\"subop\">"; | |
1663 | ||
1664 | print "</form>"; | |
1c7f75ed | 1665 | |
7d4c898a | 1666 | } |
1c7f75ed | 1667 | |
77e96719 | 1668 | $result = db_query($link, "SELECT |
ff485f1d | 1669 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, |
77e96719 | 1670 | section_name,def_value |
ff485f1d | 1671 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
77e96719 | 1672 | WHERE type_id = ttrss_prefs_types.id AND |
ff485f1d | 1673 | section_id = ttrss_prefs_sections.id AND |
a2411bd9 AD |
1674 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
1675 | owner_uid = ".$_SESSION["uid"]." | |
650bc435 | 1676 | ORDER BY section_id,short_desc"); |
77e96719 AD |
1677 | |
1678 | print "<form action=\"backend.php\" method=\"POST\">"; | |
1679 | ||
77e96719 AD |
1680 | $lnum = 0; |
1681 | ||
1682 | $active_section = ""; | |
1683 | ||
1684 | while ($line = db_fetch_assoc($result)) { | |
1685 | ||
1686 | if ($active_section != $line["section_name"]) { | |
59a654ba AD |
1687 | |
1688 | if ($active_section != "") { | |
1c7f75ed | 1689 | print "</table>"; |
59a654ba | 1690 | } |
1c7f75ed AD |
1691 | |
1692 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
59a654ba AD |
1693 | |
1694 | $active_section = $line["section_name"]; | |
1695 | ||
77e96719 | 1696 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; |
59a654ba AD |
1697 | // print "<tr class=\"title\"> |
1698 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
7268adf7 AD |
1699 | |
1700 | $lnum = 0; | |
77e96719 AD |
1701 | } |
1702 | ||
650bc435 | 1703 | // $class = ($lnum % 2) ? "even" : "odd"; |
77e96719 | 1704 | |
650bc435 | 1705 | print "<tr>"; |
77e96719 | 1706 | |
77e96719 AD |
1707 | $type_name = $line["type_name"]; |
1708 | $pref_name = $line["pref_name"]; | |
1709 | $value = $line["value"]; | |
1710 | $def_value = $line["def_value"]; | |
b1895692 AD |
1711 | $help_text = $line["help_text"]; |
1712 | ||
1713 | print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"]; | |
1714 | ||
1715 | if ($help_text) print "<div class=\"prefHelp\">$help_text</div>"; | |
1716 | ||
1717 | print "</td>"; | |
77e96719 AD |
1718 | |
1719 | print "<td>"; | |
1720 | ||
1721 | if ($type_name == "bool") { | |
1722 | // print_select($pref_name, $value, array("true", "false")); | |
1723 | ||
1724 | if ($value == "true") { | |
1725 | $value = "Yes"; | |
1726 | } else { | |
1727 | $value = "No"; | |
1728 | } | |
1729 | ||
1730 | print_radio($pref_name, $value, array("Yes", "No")); | |
1731 | ||
1732 | } else { | |
1733 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
1734 | } | |
1735 | ||
1736 | print "</td>"; | |
1737 | ||
1738 | print "</tr>"; | |
1739 | ||
1740 | $lnum++; | |
1741 | } | |
1742 | ||
1743 | print "</table>"; | |
1744 | ||
1745 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
1746 | ||
1747 | print "<p><input class=\"button\" type=\"submit\" | |
1748 | name=\"subop\" value=\"Save configuration\">"; | |
1749 | ||
1750 | print " <input class=\"button\" type=\"submit\" | |
1751 | name=\"subop\" value=\"Reset to defaults\"></p>"; | |
1752 | ||
1753 | print "</form>"; | |
1754 | ||
1755 | } | |
1756 | ||
1757 | } | |
1758 | ||
e6cb77a0 AD |
1759 | if ($op == "pref-users") { |
1760 | ||
1761 | $subop = $_GET["subop"]; | |
1762 | ||
1763 | if ($subop == "editSave") { | |
1764 | ||
1765 | if (!WEB_DEMO_MODE) { | |
1766 | ||
1767 | $login = db_escape_string($_GET["l"]); | |
1768 | $uid = db_escape_string($_GET["id"]); | |
1769 | $access_level = sprintf("%d", $_GET["al"]); | |
1770 | ||
1771 | db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'"); | |
1772 | ||
1773 | } | |
1774 | } else if ($subop == "remove") { | |
1775 | ||
1776 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
1777 | ||
1778 | $ids = split(",", $_GET["ids"]); | |
1779 | ||
1780 | foreach ($ids as $id) { | |
1781 | db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]); | |
1782 | ||
1783 | } | |
1784 | } | |
1785 | } else if ($subop == "add") { | |
1786 | ||
1787 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
1788 | ||
1789 | $login = db_escape_string($_GET["login"]); | |
1790 | $tmp_user_pwd = make_password(8); | |
1791 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
1792 | ||
1793 | db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level) | |
1794 | VALUES ('$login', '$pwd_hash', 0)"); | |
1795 | ||
1796 | ||
1797 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
1798 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
1799 | ||
1800 | if (db_num_rows($result) == 1) { | |
1801 | ||
1802 | $new_uid = db_fetch_result($result, 0, "id"); | |
1803 | ||
1804 | print "<div class=\"notice\">Added user <b>".$_GET["login"]. | |
1805 | "</b> with password <b>$tmp_user_pwd</b>.</div>"; | |
1806 | ||
1807 | initialize_user($link, $new_uid); | |
1808 | ||
1809 | } else { | |
1810 | ||
1811 | print "<div class=\"warning\">Error while adding user <b>". | |
1812 | $_GET["login"].".</b></div>"; | |
1813 | ||
1814 | } | |
1815 | } | |
1816 | } else if ($subop == "resetPass") { | |
1817 | ||
1818 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
1819 | ||
1820 | $uid = db_escape_string($_GET["id"]); | |
1821 | ||
1822 | $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'"); | |
1823 | ||
1824 | $login = db_fetch_result($result, 0, "login"); | |
1825 | $tmp_user_pwd = make_password(8); | |
1826 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
1827 | ||
1828 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
1829 | WHERE id = '$uid'"); | |
1830 | ||
1831 | print "<div class=\"notice\">Changed password of | |
1832 | user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>"; | |
1833 | ||
1834 | } | |
1835 | } | |
1836 | ||
1837 | print "<table class=\"prefAddFeed\"><tr> | |
1838 | <td><input id=\"uadd_box\"></td>"; | |
1839 | ||
1840 | print"<td colspan=\"4\" align=\"right\"> | |
1841 | <a class=\"button\" href=\"javascript:addUser()\">Add user</a></td></tr> | |
1842 | </table>"; | |
1843 | ||
1844 | $result = db_query($link, "SELECT | |
f6f32198 | 1845 | id,login,access_level,last_login |
e6cb77a0 AD |
1846 | FROM |
1847 | ttrss_users | |
1848 | ORDER by login"); | |
1849 | ||
1850 | print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">"; | |
1851 | ||
1852 | print "<tr class=\"title\"> | |
f6f32198 AD |
1853 | <td width=\"5%\">Select</td> |
1854 | <td width='30%'>Username</td> | |
1855 | <td width='30%'>Access Level</td> | |
1856 | <td width='30%'>Last login</td></tr>"; | |
e6cb77a0 AD |
1857 | |
1858 | $lnum = 0; | |
1859 | ||
1860 | while ($line = db_fetch_assoc($result)) { | |
1861 | ||
1862 | $class = ($lnum % 2) ? "even" : "odd"; | |
1863 | ||
1864 | $uid = $line["id"]; | |
1865 | $edit_uid = $_GET["id"]; | |
1866 | ||
1867 | if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) { | |
1868 | $class .= "Grayed"; | |
1869 | } | |
1870 | ||
1871 | print "<tr class=\"$class\" id=\"UMRR-$uid\">"; | |
1872 | ||
1873 | $line["login"] = htmlspecialchars($line["login"]); | |
1874 | ||
1875 | if ($uid == $_SESSION["uid"]) { | |
1876 | ||
1877 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1878 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
1879 | ||
1880 | print "<td>".$line["login"]."</td>"; | |
1881 | print "<td>".$line["access_level"]."</td>"; | |
e6cb77a0 AD |
1882 | |
1883 | } else if (!$edit_uid || $subop != "edit") { | |
1884 | ||
1885 | print "<td><input onclick='toggleSelectRow(this);' | |
1886 | type=\"checkbox\" id=\"UMCHK-".$line["id"]."\"></td>"; | |
1887 | ||
1888 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
1889 | $line["login"] . "</td>"; | |
1890 | ||
1891 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
1892 | $line["access_level"] . "</td>"; | |
1893 | ||
1894 | } else if ($uid != $edit_uid) { | |
1895 | ||
1896 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1897 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
1898 | ||
1899 | print "<td>".$line["login"]."</td>"; | |
1900 | print "<td>".$line["access_level"]."</td>"; | |
1901 | ||
1902 | } else { | |
1903 | ||
1904 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
1905 | ||
1906 | print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"]. | |
1907 | "\"></td>"; | |
1908 | ||
1909 | print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"]. | |
1910 | "\"></td>"; | |
1911 | ||
1912 | } | |
1913 | ||
f6f32198 AD |
1914 | print "<td>".$line["last_login"]."</td>"; |
1915 | ||
e6cb77a0 AD |
1916 | print "</tr>"; |
1917 | ||
1918 | ++$lnum; | |
1919 | } | |
1920 | ||
1921 | print "</table>"; | |
1922 | ||
1923 | print "<p>"; | |
1924 | ||
1925 | if ($subop == "edit") { | |
1926 | print "Edit label: | |
1927 | <input type=\"submit\" class=\"button\" | |
1928 | onclick=\"javascript:userEditCancel()\" value=\"Cancel\"> | |
1929 | <input type=\"submit\" class=\"button\" | |
1930 | onclick=\"javascript:userEditSave()\" value=\"Save\">"; | |
1931 | ||
1932 | } else { | |
1933 | ||
1934 | print " | |
1935 | Selection: | |
1936 | <input type=\"submit\" class=\"button\" | |
717f5e64 | 1937 | onclick=\"javascript:selectedUserDetails()\" value=\"User details\"> |
e6cb77a0 AD |
1938 | <input type=\"submit\" class=\"button\" |
1939 | onclick=\"javascript:editSelectedUser()\" value=\"Edit\"> | |
1940 | <input type=\"submit\" class=\"button\" | |
717f5e64 AD |
1941 | onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\"> |
1942 | <input type=\"submit\" class=\"button\" | |
1943 | onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">"; | |
1944 | ||
1945 | } | |
1946 | } | |
1947 | ||
1948 | if ($op == "user-details") { | |
1949 | ||
1950 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { | |
1951 | return; | |
1952 | } | |
1953 | ||
1954 | print "<html><head> | |
1955 | <title>Tiny Tiny RSS : User Details</title> | |
1956 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
1957 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
1958 | </head><body>"; | |
1959 | ||
1960 | $uid = sprintf("%d", $_GET["id"]); | |
1961 | ||
1962 | /* FIXME this badly needs real implementation */ | |
1963 | ||
1964 | print "<div class='userDetails'>"; | |
1965 | ||
1966 | $result = db_query($link, "SELECT login,last_login,access_level | |
1967 | FROM ttrss_users | |
1968 | WHERE id = '$uid'"); | |
1969 | ||
1970 | if (db_num_rows($result) == 0) { | |
1971 | print "<h1>User not found</h1>"; | |
1972 | return; | |
1973 | } | |
1974 | ||
1975 | print "<h1>User Details</h1>"; | |
1976 | ||
1977 | print "<table width='100%'>"; | |
1978 | ||
1979 | $login = db_fetch_result($result, 0, "login"); | |
1980 | $last_login = db_fetch_result($result, 0, "last_login"); | |
1981 | $access_level = db_fetch_result($result, 0, "access_level"); | |
1982 | ||
1983 | print "<tr><td>Username</td><td>$login</td></tr>"; | |
1984 | print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
1985 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
1986 | ||
1987 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
1988 | WHERE owner_uid = '$uid'"); | |
1989 | ||
1990 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
1991 | ||
1992 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; | |
1993 | ||
1994 | $result = db_query($link, "SELECT | |
1995 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size | |
1996 | FROM ttrss_entries WHERE owner_uid = '$uid'"); | |
1997 | ||
1998 | $db_size = db_fetch_result($result, 0, "db_size"); | |
1999 | ||
2000 | print "<tr><td>Approx. DB size</td><td>$db_size bytes</td></tr>"; | |
2001 | ||
2002 | print "</table>"; | |
2003 | ||
2004 | print "<h1>Subscribed feeds</h1>"; | |
2005 | ||
2006 | $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds | |
2007 | WHERE owner_uid = '$uid'"); | |
2008 | ||
2009 | print "<ul class=\"nomarks\">"; | |
2010 | ||
2011 | while ($line = db_fetch_assoc($result)) { | |
2012 | ||
2013 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
2014 | ||
2015 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
2016 | $feed_icon = "<img class=\"feedIcon\" src=\"$icon_file\">"; | |
2017 | } else { | |
2018 | $feed_icon = "<img class=\"feedIcon\" src=\"images/blank_icon.gif\">"; | |
2019 | } | |
2020 | ||
2021 | print "<li>$feed_icon <a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>"; | |
e6cb77a0 | 2022 | } |
717f5e64 AD |
2023 | |
2024 | print "</ul>"; | |
2025 | ||
2026 | print "<p align='center'> | |
2027 | <a href=\"javascript:window.close()\">(Close this window)</a></p>"; | |
2028 | ||
2029 | print "</div>"; | |
2030 | ||
2031 | print "</body></html>"; | |
2032 | ||
e6cb77a0 AD |
2033 | } |
2034 | ||
4b3dff6e | 2035 | db_close($link); |
1cd17194 | 2036 | ?> |
406d9489 AD |
2037 | |
2038 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
2039 |