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