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