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