]>
Commit | Line | Data |
---|---|---|
1cd17194 | 1 | <? |
4356293a | 2 | session_start(); |
090e250b | 3 | |
262bd8ea AD |
4 | $op = $_REQUEST["op"]; |
5 | ||
a2770077 | 6 | if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) { |
262bd8ea AD |
7 | header("Content-Type: application/xml"); |
8 | } | |
9 | ||
a2770077 | 10 | if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") { |
262bd8ea | 11 | |
a2770077 | 12 | if ($op == "rpc") { |
262bd8ea AD |
13 | print "<error error-code=\"6\"/>"; |
14 | } | |
15 | exit; | |
16 | } | |
1c7f75ed | 17 | |
a2770077 AD |
18 | if (!$op) { |
19 | print "<error error-code=\"7\"/>"; | |
20 | exit; | |
21 | } | |
22 | ||
4356293a | 23 | define(SCHEMA_VERSION, 2); |
1cd17194 | 24 | |
82baad4a | 25 | require_once "config.php"; |
648472a7 | 26 | require_once "db.php"; |
3bac89ad | 27 | require_once "db-prefs.php"; |
82baad4a AD |
28 | require_once "functions.php"; |
29 | require_once "magpierss/rss_fetch.inc"; | |
1cd17194 | 30 | |
406d9489 AD |
31 | $script_started = getmicrotime(); |
32 | ||
648472a7 | 33 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
d76a3b03 | 34 | |
5136011e AD |
35 | if (!$link) { |
36 | if (DB_TYPE == "mysql") { | |
37 | print mysql_error(); | |
38 | } | |
39 | // PG seems to display its own errors just fine by default. | |
40 | return; | |
41 | } | |
42 | ||
648472a7 AD |
43 | if (DB_TYPE == "pgsql") { |
44 | pg_query("set client_encoding = 'utf-8'"); | |
45 | } | |
7ec2a838 | 46 | |
331900c6 | 47 | $fetch = $_GET["fetch"]; |
175847de | 48 | |
8143ae1f AD |
49 | /* FIXME this needs reworking */ |
50 | ||
fc69e641 | 51 | function getGlobalCounters($link) { |
4c193675 AD |
52 | $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries |
53 | WHERE unread = true AND | |
54 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
55 | owner_uid = " . $_SESSION["uid"]); | |
fc69e641 AD |
56 | $c_id = db_fetch_result($result, 0, "c_id"); |
57 | print "<counter id='global-unread' counter='$c_id'/>"; | |
58 | } | |
59 | ||
8143ae1f | 60 | function getTagCounters($link) { |
05732aa0 | 61 | |
8143ae1f | 62 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count |
4c193675 AD |
63 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE |
64 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
4356293a | 65 | ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND |
05732aa0 | 66 | post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name |
8143ae1f | 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 | ||
4c193675 AD |
87 | $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries |
88 | WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND | |
89 | unread = true AND owner_uid = ".$_SESSION["uid"]); | |
090e250b | 90 | |
d61fd764 | 91 | $count = db_fetch_result($result, 0, "count"); |
090e250b AD |
92 | |
93 | print "<label id=\"-1\" counter=\"$count\"/>"; | |
94 | ||
4356293a AD |
95 | $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM |
96 | ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); | |
090e250b AD |
97 | |
98 | while ($line = db_fetch_assoc($result)) { | |
99 | ||
100 | $id = -$line["id"] - 11; | |
101 | ||
102 | error_reporting (0); | |
d61fd764 | 103 | |
4c193675 | 104 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries |
655be073 | 105 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND |
4c193675 | 106 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
655be073 | 107 | owner_uid = ".$_SESSION["uid"]); |
090e250b | 108 | |
d61fd764 | 109 | $count = db_fetch_result($tmp_result, 0, "count"); |
090e250b | 110 | |
ab3f3f72 | 111 | print "<label id=\"$id\" counter=\"$count\"/>"; |
090e250b AD |
112 | |
113 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
114 | ||
115 | } | |
116 | } | |
117 | ||
8073cce7 AD |
118 | function getFeedCounter($link, $id) { |
119 | ||
120 | $result = db_query($link, "SELECT | |
4c193675 AD |
121 | count(id) as count FROM ttrss_entries,ttrss_user_entries |
122 | WHERE feed_id = '$id' AND unread = true | |
123 | AND ttrss_user_entries.ref_id = ttrss_entries.id"); | |
8073cce7 AD |
124 | |
125 | $count = db_fetch_result($result, 0, "count"); | |
126 | ||
127 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
128 | } | |
090e250b | 129 | |
8073cce7 AD |
130 | function getFeedCounters($link) { |
131 | ||
090e250b | 132 | $result = db_query($link, "SELECT id, |
4c193675 AD |
133 | (SELECT count(id) |
134 | FROM ttrss_entries,ttrss_user_entries | |
135 | WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id | |
b88917af | 136 | AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count |
4356293a | 137 | FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); |
090e250b AD |
138 | |
139 | while ($line = db_fetch_assoc($result)) { | |
140 | ||
141 | $id = $line["id"]; | |
142 | $count = $line["count"]; | |
143 | ||
144 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
145 | } | |
146 | } | |
147 | ||
8143ae1f | 148 | function outputFeedList($link, $tags = false) { |
175847de | 149 | |
1a66d16e AD |
150 | print "<html><head> |
151 | <title>Tiny Tiny RSS : Feedlist</title> | |
430bf183 AD |
152 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; |
153 | ||
4769ddaf | 154 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { |
430bf183 AD |
155 | print "<link rel=\"stylesheet\" type=\"text/css\" |
156 | href=\"tt-rss_compact.css\"/>"; | |
157 | } else { | |
158 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
159 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
160 | } | |
161 | ||
162 | print "<script type=\"text/javascript\" src=\"functions.js\"></script> | |
1a66d16e AD |
163 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> |
164 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
3745788e | 165 | </head><body onload=\"init()\">"; |
254e0e4b AD |
166 | |
167 | print "<ul class=\"feedList\" id=\"feedList\">"; | |
168 | ||
4356293a AD |
169 | $owner_uid = $_SESSION["uid"]; |
170 | ||
8143ae1f | 171 | if (!$tags) { |
254e0e4b | 172 | |
8143ae1f | 173 | /* virtual feeds */ |
254e0e4b | 174 | |
91ff844a AD |
175 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
176 | print "<li class=\"feedCat\">Special</li>"; | |
177 | print "<ul class=\"feedCatList\">"; | |
178 | } | |
179 | ||
8143ae1f | 180 | $result = db_query($link, "SELECT count(id) as num_starred |
4c193675 AD |
181 | FROM ttrss_entries,ttrss_user_entries |
182 | WHERE marked = true AND | |
183 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
184 | unread = true AND owner_uid = '$owner_uid'"); | |
8143ae1f | 185 | $num_starred = db_fetch_result($result, 0, "num_starred"); |
254e0e4b | 186 | |
3745788e | 187 | $class = "virt"; |
8add756a AD |
188 | |
189 | if ($num_starred > 0) $class .= "Unread"; | |
190 | ||
191 | printFeedEntry(-1, $class, "Starred articles", $num_starred, | |
4668523d | 192 | "images/mark_set.png", $link); |
48f0adb0 | 193 | |
91ff844a AD |
194 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
195 | print "</ul>"; | |
196 | } | |
197 | ||
4769ddaf | 198 | if (get_pref($link, 'ENABLE_LABELS')) { |
8143ae1f AD |
199 | |
200 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
4356293a | 201 | ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); |
8143ae1f AD |
202 | |
203 | if (db_num_rows($result) > 0) { | |
91ff844a AD |
204 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
205 | print "<li class=\"feedCat\">Labels</li>"; | |
206 | print "<ul class=\"feedCatList\">"; | |
207 | } else { | |
208 | print "<li><hr></li>"; | |
209 | } | |
8143ae1f AD |
210 | } |
211 | ||
212 | while ($line = db_fetch_assoc($result)) { | |
48f0adb0 | 213 | |
8143ae1f AD |
214 | error_reporting (0); |
215 | ||
4c193675 AD |
216 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries |
217 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND | |
218 | ttrss_user_entries.ref_id = ttrss_entries.id | |
655be073 | 219 | AND owner_uid = '$owner_uid'"); |
8143ae1f AD |
220 | |
221 | $count = db_fetch_result($tmp_result, 0, "count"); | |
222 | ||
3745788e | 223 | $class = "label"; |
8143ae1f AD |
224 | |
225 | if ($count > 0) { | |
226 | $class .= "Unread"; | |
227 | } | |
228 | ||
229 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
230 | ||
231 | printFeedEntry(-$line["id"]-11, | |
4668523d | 232 | $class, $line["description"], $count, "images/label.png", $link); |
8143ae1f AD |
233 | |
234 | } | |
91ff844a AD |
235 | |
236 | if (db_num_rows($result) > 0) { | |
237 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
238 | print "</ul>"; | |
239 | } | |
240 | } | |
241 | ||
242 | } | |
243 | ||
244 | // if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
245 | print "<li><hr></li>"; | |
246 | // } | |
247 | ||
248 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
249 | $order_by_qpart = "category,title"; | |
250 | } else { | |
251 | $order_by_qpart = "title"; | |
48f0adb0 | 252 | } |
8143ae1f AD |
253 | |
254 | $result = db_query($link, "SELECT *, | |
4c193675 AD |
255 | (SELECT count(id) FROM ttrss_entries,ttrss_user_entries |
256 | WHERE feed_id = ttrss_feeds.id AND | |
257 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
258 | owner_uid = '$owner_uid') AS total, | |
259 | (SELECT count(id) FROM ttrss_entries,ttrss_user_entries | |
b88917af | 260 | WHERE feed_id = ttrss_feeds.id AND unread = true |
4c193675 | 261 | AND ttrss_user_entries.ref_id = ttrss_entries.id |
91ff844a AD |
262 | AND owner_uid = '$owner_uid') as unread, |
263 | (SELECT title FROM ttrss_feed_categories | |
264 | WHERE id = cat_id) AS category | |
265 | FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart"); | |
8143ae1f AD |
266 | |
267 | $actid = $_GET["actid"]; | |
268 | ||
269 | /* real feeds */ | |
270 | ||
271 | $lnum = 0; | |
272 | ||
273 | $total_unread = 0; | |
91ff844a AD |
274 | |
275 | $category = ""; | |
8143ae1f | 276 | |
48f0adb0 | 277 | while ($line = db_fetch_assoc($result)) { |
8143ae1f AD |
278 | |
279 | $feed = $line["title"]; | |
280 | $feed_id = $line["id"]; | |
281 | ||
282 | $subop = $_GET["subop"]; | |
283 | ||
284 | $total = $line["total"]; | |
285 | $unread = $line["unread"]; | |
91ff844a AD |
286 | |
287 | $tmp_category = $line["category"]; | |
288 | ||
289 | if (!$tmp_category) { | |
290 | $tmp_category = "Uncategorized"; | |
291 | } | |
8143ae1f AD |
292 | |
293 | // $class = ($lnum % 2) ? "even" : "odd"; | |
48f0adb0 | 294 | |
3745788e | 295 | $class = "feed"; |
8143ae1f AD |
296 | |
297 | if ($unread > 0) $class .= "Unread"; | |
298 | ||
299 | if ($actid == $feed_id) { | |
300 | $class .= "Selected"; | |
392d4563 | 301 | } |
48f0adb0 | 302 | |
8143ae1f | 303 | $total_unread += $unread; |
91ff844a AD |
304 | |
305 | if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) { | |
306 | ||
307 | if ($category) { | |
308 | print "</li></ul></li>"; | |
309 | } | |
310 | ||
311 | $category = $tmp_category; | |
312 | ||
313 | print "<li class=\"feedCat\">$category</li>"; | |
314 | print "<li><ul class=\"feedCatList\">"; | |
315 | } | |
8143ae1f | 316 | |
91ff844a AD |
317 | printFeedEntry($feed_id, $class, $feed, $unread, |
318 | "icons/$feed_id.ico", $link); | |
8143ae1f AD |
319 | |
320 | ++$lnum; | |
48f0adb0 | 321 | } |
91ff844a | 322 | |
8143ae1f | 323 | } else { |
a1a8a2be | 324 | |
8143ae1f | 325 | // tags |
a1a8a2be | 326 | |
8143ae1f | 327 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count |
05732aa0 AD |
328 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE |
329 | post_int_id = ttrss_user_entries.int_id AND | |
330 | unread = true AND ref_id = ttrss_entries.id | |
3b0948c4 | 331 | AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name |
8143ae1f | 332 | UNION |
3b0948c4 AD |
333 | select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid' |
334 | ORDER BY tag_name"); | |
8143ae1f AD |
335 | |
336 | $tags = array(); | |
337 | ||
338 | while ($line = db_fetch_assoc($result)) { | |
339 | $tags[$line["tag_name"]] += $line["count"]; | |
1a66d16e | 340 | } |
8143ae1f AD |
341 | |
342 | foreach (array_keys($tags) as $tag) { | |
343 | ||
344 | $unread = $tags[$tag]; | |
345 | ||
346 | $class = "odd"; | |
347 | ||
348 | if ($unread > 0) { | |
349 | $class .= "Unread"; | |
350 | } | |
351 | ||
4668523d | 352 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); |
8143ae1f AD |
353 | |
354 | } | |
1a66d16e | 355 | |
e828e31e | 356 | } |
82baad4a | 357 | |
dc33ec95 | 358 | if (db_num_rows($result) == 0) { |
4356293a | 359 | print "<li>No tags/feeds to display.</li>"; |
dc33ec95 AD |
360 | } |
361 | ||
8143ae1f | 362 | print "</ul>"; |
1cd17194 | 363 | |
caa4e57f AD |
364 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; |
365 | ||
c3b81db0 AD |
366 | } |
367 | ||
368 | ||
369 | if ($op == "rpc") { | |
370 | ||
371 | $subop = $_GET["subop"]; | |
372 | ||
090e250b | 373 | if ($subop == "getLabelCounters") { |
8073cce7 | 374 | $aid = $_GET["aid"]; |
090e250b AD |
375 | print "<rpc-reply>"; |
376 | getLabelCounters($link); | |
8073cce7 AD |
377 | if ($aid) { |
378 | getFeedCounter($link, $aid); | |
379 | } | |
090e250b AD |
380 | print "</rpc-reply>"; |
381 | } | |
382 | ||
383 | if ($subop == "getFeedCounters") { | |
384 | print "<rpc-reply>"; | |
385 | getFeedCounters($link); | |
386 | print "</rpc-reply>"; | |
387 | } | |
388 | ||
389 | if ($subop == "getAllCounters") { | |
390 | print "<rpc-reply>"; | |
391 | getLabelCounters($link); | |
392 | getFeedCounters($link); | |
8143ae1f | 393 | getTagCounters($link); |
fc69e641 | 394 | getGlobalCounters($link); |
090e250b | 395 | print "</rpc-reply>"; |
090e250b AD |
396 | } |
397 | ||
f4c10d44 AD |
398 | if ($subop == "mark") { |
399 | $mark = $_GET["mark"]; | |
648472a7 | 400 | $id = db_escape_string($_GET["id"]); |
f4c10d44 AD |
401 | |
402 | if ($mark == "1") { | |
403 | $mark = "true"; | |
404 | } else { | |
405 | $mark = "false"; | |
406 | } | |
407 | ||
b5137506 AD |
408 | // FIXME this needs collision testing |
409 | ||
410 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
411 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
f4c10d44 AD |
412 | } |
413 | ||
caa4e57f | 414 | if ($subop == "updateFeed") { |
648472a7 | 415 | $feed_id = db_escape_string($_GET["feed"]); |
9cfc649a | 416 | |
648472a7 | 417 | $result = db_query($link, |
a5873b2e AD |
418 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id' |
419 | AND owner_uid = " . $_SESSION["uid"]); | |
9cfc649a | 420 | |
648472a7 AD |
421 | if (db_num_rows($result) > 0) { |
422 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
a5873b2e | 423 | update_rss_feed($link, $feed_url, $feed_id); |
caa4e57f | 424 | } |
9cfc649a | 425 | |
a5873b2e AD |
426 | print "<rpc-reply>"; |
427 | getFeedCounter($link, $feed_id); | |
428 | print "</rpc-reply>"; | |
429 | ||
caa4e57f | 430 | return; |
9cfc649a AD |
431 | } |
432 | ||
090e250b | 433 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { |
c5142cca | 434 | |
05732aa0 | 435 | update_all_feeds($link, $subop == "forceUpdateAllFeeds"); |
c3b81db0 | 436 | |
ab3f3f72 AD |
437 | $omode = $_GET["omode"]; |
438 | ||
439 | if (!$omode) $omode = "tfl"; | |
440 | ||
090e250b | 441 | print "<rpc-reply>"; |
ab3f3f72 AD |
442 | if (strchr($omode, "l")) getLabelCounters($link); |
443 | if (strchr($omode, "f")) getFeedCounters($link); | |
444 | if (strchr($omode, "t")) getTagCounters($link); | |
fc69e641 | 445 | getGlobalCounters($link); |
090e250b | 446 | print "</rpc-reply>"; |
c3b81db0 AD |
447 | } |
448 | ||
b018b49b | 449 | if ($subop == "catchupSelected") { |
c3b81db0 AD |
450 | |
451 | $ids = split(",", $_GET["ids"]); | |
452 | ||
453 | foreach ($ids as $id) { | |
454 | ||
b018b49b AD |
455 | db_query($link, "UPDATE ttrss_user_entries SET unread=false,last_read = NOW() |
456 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
c3b81db0 AD |
457 | |
458 | } | |
459 | ||
460 | print "Marked active page as read."; | |
461 | } | |
295f9b42 AD |
462 | |
463 | if ($subop == "sanityCheck") { | |
464 | ||
465 | $error_code = 0; | |
466 | ||
467 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
468 | ||
469 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
470 | ||
471 | if ($schema_version != SCHEMA_VERSION) { | |
472 | $error_code = 5; | |
473 | } | |
474 | ||
262bd8ea | 475 | print "<error error-code='$error_code'/>"; |
295f9b42 | 476 | } |
fefa6ca3 AD |
477 | |
478 | if ($subop == "globalPurge") { | |
479 | ||
480 | print "<rpc-reply>"; | |
481 | global_purge_old_posts($link, true); | |
482 | print "</rpc-reply>"; | |
483 | ||
484 | } | |
485 | ||
c3b81db0 AD |
486 | } |
487 | ||
488 | if ($op == "feeds") { | |
489 | ||
8143ae1f AD |
490 | $tags = $_GET["tags"]; |
491 | ||
c3b81db0 AD |
492 | $subop = $_GET["subop"]; |
493 | ||
494 | if ($subop == "catchupAll") { | |
b018b49b | 495 | db_query($link, "UPDATE ttrss_user_entries SET |
6d15e1ef | 496 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); |
c3b81db0 AD |
497 | } |
498 | ||
8143ae1f | 499 | outputFeedList($link, $tags); |
c3b81db0 | 500 | |
1cd17194 AD |
501 | } |
502 | ||
503 | if ($op == "view") { | |
504 | ||
d76a3b03 | 505 | $id = $_GET["id"]; |
8073cce7 | 506 | $feed_id = $_GET["feed"]; |
d76a3b03 | 507 | |
4c193675 AD |
508 | $result = db_query($link, "UPDATE ttrss_user_entries |
509 | SET unread = false,last_read = NOW() | |
510 | WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
a1a8a2be | 511 | |
70830c87 AD |
512 | $addheader = $_GET["addheader"]; |
513 | ||
648472a7 | 514 | $result = db_query($link, "SELECT title,link,content,feed_id,comments, |
b7f4bda2 | 515 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url |
4c193675 AD |
516 | FROM ttrss_entries,ttrss_user_entries |
517 | WHERE id = '$id' AND ref_id = id"); | |
1cd17194 | 518 | |
70830c87 | 519 | if ($addheader) { |
f0601b87 | 520 | print "<html><head> |
70830c87 AD |
521 | <title>Tiny Tiny RSS : Article $id</title> |
522 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
c05608c2 | 523 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
70830c87 | 524 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
f0601b87 | 525 | </head><body>"; |
70830c87 AD |
526 | } |
527 | ||
d76a3b03 | 528 | if ($result) { |
1cd17194 | 529 | |
648472a7 | 530 | $line = db_fetch_assoc($result); |
1cd17194 | 531 | |
b7f4bda2 AD |
532 | if ($line["icon_url"]) { |
533 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
534 | } else { | |
535 | $feed_icon = " "; | |
536 | } | |
d76a3b03 | 537 | |
f7181e9b AD |
538 | if ($line["comments"] && $line["link"] != $line["comments"]) { |
539 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
540 | } else { | |
541 | $entry_comments = ""; | |
542 | } | |
543 | ||
e828e31e AD |
544 | print "<div class=\"postReply\">"; |
545 | ||
546 | print "<div class=\"postHeader\"><table>"; | |
547 | ||
548 | print "<tr><td><b>Title:</b></td> | |
549 | <td width='100%'>" . $line["title"] . "</td></tr>"; | |
f7181e9b | 550 | |
e828e31e | 551 | print "<tr><td><b>Link:</b></td> |
f7181e9b AD |
552 | <td width='100%'> |
553 | <a href=\"" . $line["link"] . "\">".$line["link"]."</a> | |
554 | $entry_comments</td></tr>"; | |
e828e31e AD |
555 | |
556 | print "</table></div>"; | |
557 | ||
558 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
559 | print "<div class=\"postContent\">" . $line["content"] . "</div>"; | |
560 | ||
561 | print "</div>"; | |
562 | ||
090e250b | 563 | print "<script type=\"text/javascript\"> |
8143ae1f | 564 | update_label_counters('$feed_id'); |
090e250b | 565 | </script>"; |
d76a3b03 | 566 | } |
70830c87 AD |
567 | |
568 | if ($addheader) { | |
569 | print "</body></html>"; | |
570 | } | |
1cd17194 AD |
571 | } |
572 | ||
573 | if ($op == "viewfeed") { | |
574 | ||
575 | $feed = $_GET["feed"]; | |
d76a3b03 | 576 | $skip = $_GET["skip"]; |
476cac42 | 577 | $subop = $_GET["subop"]; |
f175937c | 578 | $view_mode = $_GET["view"]; |
f0601b87 | 579 | $addheader = $_GET["addheader"]; |
cb1083a1 | 580 | $limit = $_GET["limit"]; |
a1a8a2be | 581 | |
8d7008c7 AD |
582 | if (!$feed) { |
583 | print "Error: no feed to display."; | |
584 | return; | |
585 | } | |
586 | ||
ac53063a AD |
587 | if (!$skip) $skip = 0; |
588 | ||
476cac42 | 589 | if ($subop == "undefined") $subop = ""; |
1cd17194 | 590 | |
f0601b87 AD |
591 | if ($addheader) { |
592 | print "<html><head> | |
ac43eba1 | 593 | <title>Tiny Tiny RSS : Feed $feed</title> |
430bf183 AD |
594 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; |
595 | ||
4769ddaf | 596 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { |
430bf183 AD |
597 | print "<link rel=\"stylesheet\" |
598 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
599 | ||
600 | } else { | |
601 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
602 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
603 | } | |
604 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
f0601b87 AD |
605 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
606 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
b623b3ed | 607 | </head><body onload='init()'>"; |
f0601b87 AD |
608 | } |
609 | ||
dcee8f61 AD |
610 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { |
611 | ||
612 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
613 | WHERE id = '$feed'"); | |
614 | ||
615 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
616 | ||
617 | update_rss_feed($link, $feed_url, $feed); | |
618 | ||
619 | } | |
620 | ||
0e32076b | 621 | if ($subop == "MarkAllRead") { |
d76a3b03 | 622 | |
0e32076b AD |
623 | if (sprintf("%d", $feed) != 0) { |
624 | ||
625 | if ($feed > 0) { | |
f23a2177 | 626 | db_query($link, "UPDATE ttrss_user_entries |
0e32076b | 627 | SET unread = false,last_read = NOW() |
f23a2177 | 628 | WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]); |
0e32076b AD |
629 | |
630 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
631 | ||
632 | if ($feed == -1) { | |
f23a2177 | 633 | db_query($link, "UPDATE ttrss_user_entries |
0e32076b | 634 | SET unread = false,last_read = NOW() |
5859be02 | 635 | WHERE marked = true AND owner_uid = ".$_SESSION["uid"]); |
0e32076b AD |
636 | } |
637 | ||
638 | } else if ($feed < -10) { // label | |
639 | ||
f23a2177 AD |
640 | // TODO make this more efficient |
641 | ||
7db95187 | 642 | $label_id = -$feed - 11; |
0e32076b | 643 | |
7db95187 | 644 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels |
f23a2177 | 645 | WHERE id = '$label_id'"); |
7db95187 AD |
646 | |
647 | if ($tmp_result) { | |
648 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
649 | ||
f23a2177 AD |
650 | db_query($link, "BEGIN"); |
651 | ||
652 | $tmp2_result = db_query($link, | |
653 | "SELECT | |
654 | int_id | |
655 | FROM | |
656 | ttrss_user_entries,ttrss_entries | |
657 | WHERE | |
658 | ref_id = id AND | |
659 | $sql_exp AND | |
660 | owner_uid = " . $_SESSION["uid"]); | |
661 | ||
662 | while ($tmp_line = db_fetch_assoc($tmp2_result)) { | |
663 | db_query($link, "UPDATE | |
664 | ttrss_user_entries | |
665 | SET | |
666 | unread = false, last_read = NOW() | |
667 | WHERE | |
668 | int_id = " . $tmp_line["int_id"]); | |
669 | } | |
670 | ||
671 | db_query($link, "COMMIT"); | |
672 | ||
673 | /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries | |
7db95187 | 674 | SET unread = false,last_read = NOW() |
f23a2177 AD |
675 | WHERE $sql_exp |
676 | AND ref_id = id | |
677 | AND owner_uid = ".$_SESSION["uid"]); */ | |
7db95187 | 678 | } |
254e0e4b | 679 | } |
0e32076b AD |
680 | } else { // tag |
681 | // FIXME, implement catchup for tags | |
a1a8a2be | 682 | } |
0e32076b | 683 | |
a1a8a2be | 684 | } |
d76a3b03 | 685 | |
175847de | 686 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 687 | |
c374a3fe AD |
688 | $search = $_GET["search"]; |
689 | ||
52b51244 AD |
690 | $search_mode = $_GET["smode"]; |
691 | ||
f175937c | 692 | if ($search) { |
ac53063a AD |
693 | $search_query_part = "(upper(title) LIKE upper('%$search%') |
694 | OR content LIKE '%$search%') AND"; | |
f175937c AD |
695 | } else { |
696 | $search_query_part = ""; | |
697 | } | |
698 | ||
699 | $view_query_part = ""; | |
700 | ||
701 | if ($view_mode == "Starred") { | |
702 | $view_query_part = " marked = true AND "; | |
ac53063a AD |
703 | } |
704 | ||
ac43eba1 AD |
705 | if ($view_mode == "Unread") { |
706 | $view_query_part = " unread = true AND "; | |
707 | } | |
708 | ||
b5aa95e7 AD |
709 | if ($view_mode == "Unread or Starred") { |
710 | $view_query_part = " (unread = true OR marked = true) AND "; | |
711 | } | |
712 | ||
bdd01d3f AD |
713 | if ($view_mode == "Unread or Updated") { |
714 | $view_query_part = " (unread = true OR last_read is NULL) AND "; | |
715 | } | |
716 | ||
254e0e4b | 717 | /* $result = db_query($link, "SELECT count(id) AS total_entries |
36bf7496 AD |
718 | FROM ttrss_entries WHERE |
719 | $search_query_part | |
720 | feed_id = '$feed'"); | |
e6d1c0a0 | 721 | |
254e0e4b | 722 | $total_entries = db_fetch_result($result, 0, "total_entries"); */ |
e6d1c0a0 | 723 | |
648472a7 | 724 | /* $result = db_query("SELECT count(id) AS unread_entries |
ac43eba1 AD |
725 | FROM ttrss_entries WHERE |
726 | $search_query_part | |
727 | unread = true AND | |
728 | feed_id = '$feed'"); | |
729 | ||
648472a7 | 730 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ |
ac43eba1 | 731 | |
8d7008c7 | 732 | if ($limit && $limit != "All") { |
82c9223c | 733 | $limit_query_part = "LIMIT " . $limit; |
ad3cb710 | 734 | } |
f0601b87 | 735 | |
254e0e4b AD |
736 | $vfeed_query_part = ""; |
737 | ||
52b51244 | 738 | // override query strategy and enable feed display when searching globally |
d3416913 | 739 | if ($search && $search_mode == "All feeds") { |
52b51244 AD |
740 | $query_strategy_part = "id > 0"; |
741 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
742 | id = feed_id) as feed_title,"; | |
743 | } else if (sprintf("%d", $feed) == 0) { | |
8143ae1f AD |
744 | $query_strategy_part = "ttrss_entries.id > 0"; |
745 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
746 | id = feed_id) as feed_title,"; | |
747 | } else if ($feed >= 0) { | |
254e0e4b | 748 | $query_strategy_part = "feed_id = '$feed'"; |
48f0adb0 | 749 | } else if ($feed == -1) { // starred virtual feed |
254e0e4b | 750 | $query_strategy_part = "marked = true"; |
48f0adb0 AD |
751 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
752 | id = feed_id) as feed_title,"; | |
753 | } else if ($feed <= -10) { // labels | |
754 | $label_id = -$feed - 11; | |
755 | ||
756 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
757 | WHERE id = '$label_id'"); | |
758 | ||
759 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
760 | ||
254e0e4b AD |
761 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
762 | id = feed_id) as feed_title,"; | |
763 | } else { | |
48f0adb0 | 764 | $query_strategy_part = "id > 0"; // dumb |
254e0e4b AD |
765 | } |
766 | ||
52b51244 | 767 | |
f99321a3 AD |
768 | $order_by = "updated DESC"; |
769 | ||
770 | // if ($feed < -10) { | |
771 | // $order_by = "feed_id,updated DESC"; | |
772 | // } | |
773 | ||
48f0adb0 AD |
774 | if ($feed < -10) error_reporting (0); |
775 | ||
8143ae1f AD |
776 | if (sprintf("%d", $feed) != 0) { |
777 | ||
778 | $result = db_query($link, "SELECT | |
779 | id,title,updated,unread,feed_id,marked,link,last_read, | |
780 | SUBSTRING(last_read,1,19) as last_read_noms, | |
781 | $vfeed_query_part | |
782 | SUBSTRING(updated,1,19) as updated_noms | |
783 | FROM | |
4c193675 | 784 | ttrss_entries,ttrss_user_entries |
8143ae1f | 785 | WHERE |
4c193675 | 786 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
aee86c2e | 787 | owner_uid = '".$_SESSION["uid"]."' AND |
8143ae1f AD |
788 | $search_query_part |
789 | $view_query_part | |
790 | $query_strategy_part ORDER BY $order_by | |
791 | $limit_query_part"); | |
792 | ||
793 | } else { | |
794 | // browsing by tag | |
795 | ||
796 | $result = db_query($link, "SELECT | |
797 | ttrss_entries.id as id,title,updated,unread,feed_id, | |
798 | marked,link,last_read, | |
c05a19f3 | 799 | SUBSTRING(last_read,1,19) as last_read_noms, |
254e0e4b | 800 | $vfeed_query_part |
c05a19f3 | 801 | SUBSTRING(updated,1,19) as updated_noms |
8143ae1f | 802 | FROM |
05732aa0 | 803 | ttrss_entries,ttrss_user_entries,ttrss_tags |
8143ae1f | 804 | WHERE |
05732aa0 AD |
805 | ref_id = ttrss_entries.id AND |
806 | ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND | |
807 | post_int_id = int_id AND tag_name = '$feed' AND | |
8143ae1f AD |
808 | $view_query_part |
809 | $search_query_part | |
810 | $query_strategy_part ORDER BY $order_by | |
811 | $limit_query_part"); | |
812 | } | |
d76a3b03 | 813 | |
48f0adb0 AD |
814 | if (!$result) { |
815 | print "<tr><td colspan='4' align='center'> | |
816 | Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>"; | |
817 | return; | |
818 | } | |
819 | ||
a1a8a2be | 820 | $lnum = 0; |
48f0adb0 AD |
821 | |
822 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
823 | ||
e1123aee | 824 | $num_unread = 0; |
d76a3b03 | 825 | |
648472a7 | 826 | while ($line = db_fetch_assoc($result)) { |
d76a3b03 | 827 | |
a1a8a2be | 828 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 829 | |
ad99045e AD |
830 | $id = $line["id"]; |
831 | $feed_id = $line["feed_id"]; | |
832 | ||
c43f77f5 | 833 | // printf("L %d (%s) > U %d (%s) = %d<br>", |
c05a19f3 | 834 | // strtotime($line["last_read_noms"]), $line["last_read_noms"], |
c43f77f5 AD |
835 | // strtotime($line["updated"]), $line["updated"], |
836 | // strtotime($line["last_read"]) >= strtotime($line["updated"])); | |
837 | ||
ecb14114 | 838 | /* if ($line["last_read"] != "" && $line["updated"] != "" && |
c05a19f3 | 839 | strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) { |
c43f77f5 AD |
840 | |
841 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
842 | alt=\"Updated\">"; | |
843 | ||
844 | } else { | |
845 | ||
5bfef089 | 846 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" |
c43f77f5 AD |
847 | alt=\"Updated\">"; |
848 | ||
ecb14114 AD |
849 | } */ |
850 | ||
4cc6ea5e AD |
851 | if ($line["last_read"] == "" && |
852 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
853 | ||
ecb14114 AD |
854 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" |
855 | alt=\"Updated\">"; | |
856 | } else { | |
857 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
858 | alt=\"Updated\">"; | |
c43f77f5 | 859 | } |
b197f117 | 860 | |
8158c57a | 861 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
a1a8a2be | 862 | $class .= "Unread"; |
e1123aee AD |
863 | ++$num_unread; |
864 | } | |
d76a3b03 | 865 | |
8158c57a | 866 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
f4c10d44 AD |
867 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" |
868 | alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>"; | |
869 | } else { | |
870 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
871 | alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>"; | |
872 | } | |
873 | ||
ac43eba1 | 874 | $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" . |
b197f117 AD |
875 | $line["title"] . "</a>"; |
876 | ||
d5224f0d | 877 | print "<tr class='$class' id='RROW-$id'>"; |
5f89f780 | 878 | // onclick=\"javascript:view($id,$feed_id)\"> |
b197f117 | 879 | |
8d7008c7 AD |
880 | print "<td valign='center' align='center'>$update_pic</td>"; |
881 | print "<td valign='center' align='center'>$marked_pic</td>"; | |
b197f117 | 882 | |
8d7008c7 | 883 | print "<td width='25%'> |
a3ee2a38 | 884 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; |
254e0e4b AD |
885 | |
886 | if ($line["feed_title"]) { | |
887 | print "<td width='50%'>$content_link</td>"; | |
2db4190c AD |
888 | print "<td width='20%'> |
889 | <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>"; | |
254e0e4b AD |
890 | } else { |
891 | print "<td width='70%'>$content_link</td>"; | |
892 | } | |
d76a3b03 | 893 | |
a1a8a2be | 894 | print "</tr>"; |
d76a3b03 | 895 | |
a1a8a2be AD |
896 | ++$lnum; |
897 | } | |
d76a3b03 | 898 | |
ac53063a | 899 | if ($lnum == 0) { |
a82065a1 | 900 | print "<tr><td align='center'>No articles found.</td></tr>"; |
047bae73 | 901 | } |
a2015351 | 902 | |
a1a8a2be | 903 | print "</table>"; |
6113ef7d AD |
904 | |
905 | print "<script type=\"text/javascript\"> | |
bb7cface | 906 | document.onkeydown = hotkey_handler; |
8143ae1f | 907 | update_label_counters('$feed'); |
6113ef7d | 908 | </script>"; |
d76a3b03 | 909 | |
f0601b87 AD |
910 | if ($addheader) { |
911 | print "</body></html>"; | |
912 | } | |
913 | ||
1cd17194 AD |
914 | } |
915 | ||
0e091d38 | 916 | if ($op == "pref-rpc") { |
331900c6 | 917 | |
0e091d38 | 918 | $subop = $_GET["subop"]; |
331900c6 | 919 | |
83fe4d6d AD |
920 | if ($subop == "unread") { |
921 | $ids = split(",", $_GET["ids"]); | |
922 | foreach ($ids as $id) { | |
a5873b2e AD |
923 | db_query($link, "UPDATE ttrss_user_entries SET unread = true |
924 | WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
83fe4d6d | 925 | } |
0e091d38 | 926 | |
a5873b2e | 927 | print "Marked selected feeds as unread."; |
83fe4d6d AD |
928 | } |
929 | ||
930 | if ($subop == "read") { | |
931 | $ids = split(",", $_GET["ids"]); | |
932 | foreach ($ids as $id) { | |
a5873b2e AD |
933 | db_query($link, "UPDATE ttrss_user_entries |
934 | SET unread = false,last_read = NOW() WHERE | |
935 | feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
83fe4d6d | 936 | } |
0e091d38 | 937 | |
a5873b2e | 938 | print "Marked selected feeds as read."; |
0e091d38 AD |
939 | |
940 | } | |
941 | ||
942 | } | |
943 | ||
944 | if ($op == "pref-feeds") { | |
945 | ||
946 | $subop = $_GET["subop"]; | |
947 | ||
508a81e1 | 948 | if ($subop == "editSave") { |
648472a7 AD |
949 | $feed_title = db_escape_string($_GET["t"]); |
950 | $feed_link = db_escape_string($_GET["l"]); | |
d148926e | 951 | $upd_intl = db_escape_string($_GET["ui"]); |
5d73494a | 952 | $purge_intl = db_escape_string($_GET["pi"]); |
91ff844a AD |
953 | $feed_id = db_escape_string($_GET["id"]); |
954 | $cat_id = db_escape_string($_GET["catid"]); | |
508a81e1 | 955 | |
d148926e AD |
956 | if (strtoupper($upd_intl) == "DEFAULT") |
957 | $upd_intl = 0; | |
958 | ||
5d73494a AD |
959 | if (strtoupper($purge_intl) == "DEFAULT") |
960 | $purge_intl = 0; | |
961 | ||
140aae81 AD |
962 | if (strtoupper($purge_intl) == "DISABLED") |
963 | $purge_intl = -1; | |
964 | ||
91ff844a AD |
965 | if ($cat_id != 0) { |
966 | $category_qpart = "cat_id = '$cat_id'"; | |
967 | } else { | |
968 | $category_qpart = 'cat_id = NULL'; | |
969 | } | |
970 | ||
648472a7 | 971 | $result = db_query($link, "UPDATE ttrss_feeds SET |
91ff844a | 972 | $category_qpart, |
d148926e | 973 | title = '$feed_title', feed_url = '$feed_link', |
5d73494a | 974 | update_interval = '$upd_intl', |
91ff844a | 975 | purge_interval = '$purge_intl' |
f72dbbde | 976 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); |
508a81e1 | 977 | |
83fe4d6d AD |
978 | } |
979 | ||
331900c6 | 980 | if ($subop == "remove") { |
331900c6 | 981 | |
b0b4abcf | 982 | if (!WEB_DEMO_MODE) { |
331900c6 | 983 | |
b0b4abcf AD |
984 | $ids = split(",", $_GET["ids"]); |
985 | ||
986 | foreach ($ids as $id) { | |
f72dbbde AD |
987 | db_query($link, "DELETE FROM ttrss_feeds |
988 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
4769ddaf | 989 | |
273a2f6b | 990 | $icons_dir = ICONS_DIR; |
d5caaae5 | 991 | |
4769ddaf AD |
992 | if (file_exists($icons_dir . "/$id.ico")) { |
993 | unlink($icons_dir . "/$id.ico"); | |
d5caaae5 | 994 | } |
b0b4abcf | 995 | } |
331900c6 AD |
996 | } |
997 | } | |
998 | ||
999 | if ($subop == "add") { | |
b0b4abcf AD |
1000 | |
1001 | if (!WEB_DEMO_MODE) { | |
331900c6 | 1002 | |
b6b535ca | 1003 | $feed_link = db_escape_string(trim($_GET["link"])); |
331900c6 | 1004 | |
648472a7 | 1005 | $result = db_query($link, |
7e9a3986 AD |
1006 | "SELECT id FROM ttrss_feeds |
1007 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
1008 | ||
1009 | if (db_num_rows($result) == 0) { | |
1010 | ||
1011 | $result = db_query($link, | |
1012 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) | |
1013 | VALUES ('".$_SESSION["uid"]."', '$feed_link', '')"); | |
331900c6 | 1014 | |
7e9a3986 AD |
1015 | $result = db_query($link, |
1016 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' | |
1017 | AND owner_uid = " . $_SESSION["uid"]); | |
1018 | ||
1019 | $feed_id = db_fetch_result($result, 0, "id"); | |
1020 | ||
1021 | if ($feed_id) { | |
1022 | update_rss_feed($link, $feed_link, $feed_id); | |
1023 | } | |
1024 | } else { | |
331900c6 | 1025 | |
7e9a3986 AD |
1026 | print "<div class=\"warning\"> |
1027 | Feed <b>$feed_link</b> already exists in the database. | |
1028 | </div>"; | |
b0b4abcf AD |
1029 | } |
1030 | } | |
331900c6 | 1031 | } |
a0d53889 | 1032 | |
91ff844a AD |
1033 | if ($subop == "addCat") { |
1034 | ||
1035 | if (!WEB_DEMO_MODE) { | |
1036 | ||
1037 | $feed_cat = db_escape_string(trim($_GET["cat"])); | |
1038 | ||
1039 | $result = db_query($link, | |
1040 | "SELECT id FROM ttrss_feed_categories | |
1041 | WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); | |
1042 | ||
1043 | if (db_num_rows($result) == 0) { | |
1044 | ||
1045 | $result = db_query($link, | |
1046 | "INSERT INTO ttrss_feed_categories (owner_uid,title) | |
1047 | VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); | |
1048 | ||
1049 | } else { | |
1050 | ||
1051 | print "<div class=\"warning\"> | |
1052 | Category <b>$feed_cat</b> already exists in the database. | |
1053 | </div>"; | |
1054 | } | |
1055 | ||
1056 | ||
1057 | } | |
1058 | } | |
1059 | ||
1060 | if ($subop == "removeCats") { | |
1061 | ||
1062 | if (!WEB_DEMO_MODE) { | |
1063 | ||
1064 | $ids = split(",", $_GET["ids"]); | |
1065 | ||
1066 | foreach ($ids as $id) { | |
1067 | ||
1068 | db_query($link, "BEGIN"); | |
1069 | ||
1070 | $result = db_query($link, | |
1071 | "SELECT count(id) as num_feeds FROM ttrss_feeds | |
1072 | WHERE cat_id = '$id'"); | |
1073 | ||
1074 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
1075 | ||
1076 | if ($num_feeds == 0) { | |
1077 | db_query($link, "DELETE FROM ttrss_feed_categories | |
1078 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1079 | } else { | |
1080 | ||
1081 | print "<div class=\"warning\"> | |
1082 | Unable to delete non empty feed categories.</div>"; | |
1083 | ||
1084 | } | |
1085 | ||
1086 | db_query($link, "COMMIT"); | |
1087 | } | |
1088 | } | |
1089 | } | |
1090 | ||
ab3d0b99 | 1091 | $result = db_query($link, "SELECT id,title,feed_url,last_error |
131f94e4 | 1092 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); |
ab3d0b99 AD |
1093 | |
1094 | if (db_num_rows($result) > 0) { | |
1095 | ||
1096 | print "<div class=\"warning\">"; | |
1097 | ||
1098 | print "<b>Feeds with update errors:</b>"; | |
1099 | ||
1100 | print "<ul class=\"nomarks\">"; | |
1101 | ||
1102 | while ($line = db_fetch_assoc($result)) { | |
1103 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
1104 | $line["last_error"]; | |
1105 | } | |
1106 | ||
1107 | print "</ul>"; | |
1108 | print "</div>"; | |
1109 | ||
1110 | } | |
1111 | ||
91ff844a AD |
1112 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
1113 | ||
1114 | // print "<h3>Categories</h3>"; | |
1115 | ||
1116 | print "<div class=\"prefGenericAddBox\"> | |
1117 | <input id=\"fadd_cat\" size=\"40\"> <input | |
1118 | type=\"submit\" class=\"button\" | |
1119 | onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>"; | |
1120 | ||
1121 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
1122 | WHERE owner_uid = ".$_SESSION["uid"]." | |
1123 | ORDER BY title"); | |
1124 | ||
1125 | print "<p><table width=\"100%\" class=\"prefFeedCatList\" id=\"prefFeedCatList\">"; | |
1126 | print "<tr class=\"title\"> | |
1127 | <td width=\"10%\">Select</td><td width=\"80%\">Title</td> | |
1128 | </tr>"; | |
1129 | ||
1130 | $lnum = 0; | |
1131 | ||
1132 | while ($line = db_fetch_assoc($result)) { | |
1133 | ||
1134 | $class = ($lnum % 2) ? "even" : "odd"; | |
1135 | ||
1136 | $cat_id = $line["id"]; | |
1137 | ||
1138 | $edit_cat_id = $_GET["id"]; | |
1139 | ||
1140 | if ($subop == "editCat" && $cat_id != $edit_cat_id) { | |
1141 | $class .= "Grayed"; | |
1142 | } | |
1143 | ||
1144 | print "<tr class=\"$class\" id=\"FCATR-$cat_id\">"; | |
1145 | ||
1146 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
1147 | ||
1148 | if (!$edit_cat_id || $subop != "editCat") { | |
1149 | ||
1150 | print "<td><input onclick='toggleSelectRow(this);' | |
1151 | type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>"; | |
1152 | ||
1153 | print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . | |
1154 | $edit_title . "</a></td>"; | |
1155 | ||
1156 | } else if ($cat_id != $edit_cat_id) { | |
1157 | ||
1158 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1159 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
1160 | ||
1161 | print "<td>$edit_title</td>"; | |
1162 | ||
1163 | } else { | |
1164 | ||
1165 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
1166 | ||
1167 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; | |
1168 | ||
1169 | } | |
1170 | ||
1171 | print "</tr>"; | |
1172 | ||
1173 | ++$lnum; | |
1174 | } | |
1175 | ||
1176 | if ($lnum == 0) { | |
1177 | print "<tr><td colspan=\"5\" align=\"center\">No categories defined.</td></tr>"; | |
1178 | } | |
1179 | ||
1180 | print "</table>"; | |
1181 | ||
1182 | print "<p>"; | |
1183 | ||
1184 | if ($subop == "editCat") { | |
1185 | print "Edit category: | |
1186 | <input type=\"submit\" class=\"button\" | |
1187 | onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\"> | |
1188 | <input type=\"submit\" class=\"button\" | |
1189 | onclick=\"javascript:feedCatEditSave()\" value=\"Save\">"; | |
1190 | } else { | |
1191 | ||
1192 | print " | |
1193 | Selection: | |
1194 | <input type=\"submit\" class=\"button\" | |
1195 | onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\"> | |
1196 | <input type=\"submit\" class=\"button\" | |
1197 | onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">"; | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | // print "<h3>Feeds</h3>"; | |
1202 | ||
1203 | print "<hr><p>"; | |
1204 | ||
2c7070b5 AD |
1205 | print "<div class=\"prefGenericAddBox\"> |
1206 | <input id=\"fadd_link\" size=\"40\"> <input | |
1207 | type=\"submit\" class=\"button\" | |
1208 | onclick=\"javascript:addFeed()\" value=\"Add feed\"></div>"; | |
a0d53889 | 1209 | |
648472a7 | 1210 | $result = db_query($link, "SELECT |
d148926e | 1211 | id,title,feed_url,substring(last_updated,1,16) as last_updated, |
91ff844a AD |
1212 | update_interval,purge_interval, |
1213 | (SELECT title FROM ttrss_feed_categories | |
1214 | WHERE id = cat_id) AS category | |
c0e5a40e | 1215 | FROM |
4356293a | 1216 | ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title"); |
1cd17194 | 1217 | |
2317ffaa | 1218 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
c6c3a07f | 1219 | |
331900c6 | 1220 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 | 1221 | print "<tr class=\"title\"> |
91ff844a AD |
1222 | <td> </td><td>Select</td><td width=\"20%\">Title</td> |
1223 | <td width=\"20%\">Link</td>"; | |
1224 | ||
1225 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1226 | print "<td width=\"10%\">Category</td>"; | |
1227 | } | |
1228 | ||
1229 | print "<td width=\"10%\">Update Interval</td> | |
5d73494a | 1230 | <td width=\"10%\">Purge Days</td> |
d148926e | 1231 | <td>Last updated</td></tr>"; |
007bda35 AD |
1232 | |
1233 | $lnum = 0; | |
1234 | ||
648472a7 | 1235 | while ($line = db_fetch_assoc($result)) { |
007bda35 AD |
1236 | |
1237 | $class = ($lnum % 2) ? "even" : "odd"; | |
9b307248 | 1238 | |
331900c6 | 1239 | $feed_id = $line["id"]; |
603c27f8 AD |
1240 | |
1241 | $edit_feed_id = $_GET["id"]; | |
1242 | ||
9b307248 AD |
1243 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
1244 | $class .= "Grayed"; | |
1245 | } | |
1246 | ||
331900c6 | 1247 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
007bda35 | 1248 | |
273a2f6b | 1249 | $icon_file = ICONS_DIR . "/$feed_id.ico"; |
c0e5a40e AD |
1250 | |
1251 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1252 | $feed_icon = "<img width=\"16\" height=\"16\" | |
273a2f6b | 1253 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; |
c0e5a40e AD |
1254 | } else { |
1255 | $feed_icon = " "; | |
1256 | } | |
1257 | print "<td align='center'>$feed_icon</td>"; | |
1258 | ||
6e0584e9 AD |
1259 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); |
1260 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
91ff844a AD |
1261 | $edit_cat = htmlspecialchars(db_unescape_string($line["category"])); |
1262 | ||
1263 | if (!$edit_cat) $edit_cat = "Uncategorized"; | |
6e0584e9 | 1264 | |
9b307248 | 1265 | if (!$edit_feed_id || $subop != "edit") { |
603c27f8 AD |
1266 | |
1267 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 | 1268 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
603c27f8 AD |
1269 | |
1270 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
5d73494a | 1271 | $edit_title . "</a></td>"; |
91ff844a | 1272 | |
603c27f8 | 1273 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
5d73494a | 1274 | $edit_link . "</a></td>"; |
d148926e | 1275 | |
91ff844a AD |
1276 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
1277 | $edit_cat . "</a></td>"; | |
1278 | ||
d148926e AD |
1279 | if ($line["update_interval"] == "0") |
1280 | $line["update_interval"] = "Default"; | |
1281 | ||
5d73494a AD |
1282 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
1283 | $line["update_interval"] . "</a></td>"; | |
d148926e | 1284 | |
5d73494a AD |
1285 | if ($line["purge_interval"] == "0") |
1286 | $line["purge_interval"] = "Default"; | |
1287 | ||
140aae81 AD |
1288 | if ($line["purge_interval"] < 0) |
1289 | $line["purge_interval"] = "Disabled"; | |
1290 | ||
5d73494a AD |
1291 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
1292 | $line["purge_interval"] . "</a></td>"; | |
9b307248 AD |
1293 | |
1294 | } else if ($feed_id != $edit_feed_id) { | |
1295 | ||
e9c54861 AD |
1296 | print "<td><input disabled=\"true\" type=\"checkbox\" |
1297 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
9b307248 | 1298 | |
6e0584e9 AD |
1299 | print "<td>$edit_title</td>"; |
1300 | print "<td>$edit_link</td>"; | |
91ff844a | 1301 | print "<td>$edit_cat</td>"; |
9b307248 | 1302 | |
d148926e AD |
1303 | if ($line["update_interval"] == "0") |
1304 | $line["update_interval"] = "Default"; | |
1305 | ||
1306 | print "<td>" . $line["update_interval"] . "</td>"; | |
1307 | ||
5d73494a AD |
1308 | if ($line["purge_interval"] == "0") |
1309 | $line["purge_interval"] = "Default"; | |
1310 | ||
140aae81 AD |
1311 | if ($line["purge_interval"] < 0) |
1312 | $line["purge_interval"] = "Disabled"; | |
1313 | ||
5d73494a AD |
1314 | print "<td>" . $line["purge_interval"] . "</td>"; |
1315 | ||
603c27f8 AD |
1316 | } else { |
1317 | ||
e6cb77a0 | 1318 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; |
603c27f8 | 1319 | |
6e0584e9 AD |
1320 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; |
1321 | print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>"; | |
91ff844a AD |
1322 | |
1323 | print "<td>"; | |
1324 | ||
1325 | print "<select id=\"iedit_fcat\">"; | |
1326 | ||
1327 | print "<option id=\"0\">Uncategorized</option>"; | |
1328 | ||
1329 | if (db_num_rows($result) > 0) { | |
1330 | print "<option disabled>--------</option>"; | |
1331 | } | |
1332 | ||
1333 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
1334 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1335 | ||
1336 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1337 | if ($tmp_line["id"] == $line["cat_id"]) { | |
1338 | $is_selected = "selected"; | |
1339 | } else { | |
1340 | $is_selected = ""; | |
1341 | } | |
1342 | printf("<option $is_selected id='%d'>%s</option>", | |
1343 | $tmp_line["id"], $tmp_line["title"]); | |
1344 | } | |
1345 | ||
1346 | print "</select></td>"; | |
1347 | ||
1348 | print "</td>"; | |
1349 | ||
1350 | print "<td><input id=\"iedit_updintl\" | |
1351 | value=\"".$line["update_interval"]."\"></td>"; | |
1352 | print "<td><input id=\"iedit_purgintl\" | |
1353 | value=\"".$line["purge_interval"]."\"></td>"; | |
d148926e | 1354 | |
603c27f8 | 1355 | } |
0afbd851 AD |
1356 | |
1357 | if (!$line["last_updated"]) $line["last_updated"] = "Never"; | |
1358 | ||
007bda35 | 1359 | print "<td>" . $line["last_updated"] . "</td>"; |
603c27f8 | 1360 | |
007bda35 AD |
1361 | print "</tr>"; |
1362 | ||
1363 | ++$lnum; | |
1364 | } | |
1365 | ||
0afbd851 AD |
1366 | if ($lnum == 0) { |
1367 | print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>"; | |
1368 | } | |
1369 | ||
007bda35 AD |
1370 | print "</table>"; |
1371 | ||
603c27f8 AD |
1372 | print "<p>"; |
1373 | ||
1374 | if ($subop == "edit") { | |
1375 | print "Edit feed: | |
e828e31e AD |
1376 | <input type=\"submit\" class=\"button\" |
1377 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
1378 | <input type=\"submit\" class=\"button\" | |
8158c57a | 1379 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
603c27f8 AD |
1380 | } else { |
1381 | ||
603c27f8 AD |
1382 | print " |
1383 | Selection: | |
c6c3a07f AD |
1384 | <input type=\"submit\" class=\"button\" |
1385 | onclick=\"javascript:selectedFeedDetails()\" value=\"Details\"> | |
e828e31e AD |
1386 | <input type=\"submit\" class=\"button\" |
1387 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
1388 | <input type=\"submit\" class=\"button\" | |
1389 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
1390 | ||
4769ddaf | 1391 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { |
f92db4f5 | 1392 | print " |
e828e31e AD |
1393 | <input type=\"submit\" class=\"button\" |
1394 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
1395 | <input type=\"submit\" class=\"button\" | |
1396 | onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> "; | |
f92db4f5 AD |
1397 | } |
1398 | print " | |
e828e31e AD |
1399 | All feeds: |
1400 | <input type=\"submit\" | |
8158c57a | 1401 | class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">"; |
10c5820d | 1402 | |
603c27f8 AD |
1403 | } |
1404 | ||
f5a50b25 AD |
1405 | print "<h3>OPML Import</h3> |
1406 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> | |
1407 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
1408 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
1409 | type=\"submit\" value=\"Import\"> | |
1410 | </form>"; | |
1411 | ||
007bda35 AD |
1412 | } |
1413 | ||
a0d53889 AD |
1414 | if ($op == "pref-filters") { |
1415 | ||
1416 | $subop = $_GET["subop"]; | |
1417 | ||
1418 | if ($subop == "editSave") { | |
a0d53889 | 1419 | |
648472a7 AD |
1420 | $regexp = db_escape_string($_GET["r"]); |
1421 | $descr = db_escape_string($_GET["d"]); | |
1422 | $match = db_escape_string($_GET["m"]); | |
1423 | $filter_id = db_escape_string($_GET["id"]); | |
ead60402 AD |
1424 | $feed_id = db_escape_string($_GET["fid"]); |
1425 | ||
1426 | if (!$feed_id) { | |
1427 | $feed_id = 'NULL'; | |
1428 | } else { | |
1429 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
1430 | } | |
0afbd851 | 1431 | |
648472a7 | 1432 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 1433 | reg_exp = '$regexp', |
0afbd851 | 1434 | description = '$descr', |
ead60402 | 1435 | feed_id = $feed_id, |
0afbd851 AD |
1436 | filter_type = (SELECT id FROM ttrss_filter_types WHERE |
1437 | description = '$match') | |
1438 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
1439 | } |
1440 | ||
1441 | if ($subop == "remove") { | |
1442 | ||
1443 | if (!WEB_DEMO_MODE) { | |
1444 | ||
1445 | $ids = split(",", $_GET["ids"]); | |
1446 | ||
1447 | foreach ($ids as $id) { | |
648472a7 | 1448 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
1449 | |
1450 | } | |
1451 | } | |
1452 | } | |
1453 | ||
1454 | if ($subop == "add") { | |
1455 | ||
de435974 | 1456 | if (!WEB_DEMO_MODE) { |
a0d53889 | 1457 | |
b6b535ca AD |
1458 | $regexp = db_escape_string(trim($_GET["regexp"])); |
1459 | $match = db_escape_string(trim($_GET["match"])); | |
ead60402 AD |
1460 | $feed_id = db_escape_string($_GET["fid"]); |
1461 | ||
1462 | if (!$feed_id) { | |
1463 | $feed_id = 'NULL'; | |
1464 | } else { | |
1465 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
1466 | } | |
4401bf04 | 1467 | |
648472a7 | 1468 | $result = db_query($link, |
ead60402 | 1469 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES |
de435974 | 1470 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
ead60402 | 1471 | description = '$match'),'".$_SESSION["uid"]."', $feed_id)"); |
de435974 | 1472 | } |
a0d53889 AD |
1473 | } |
1474 | ||
648472a7 | 1475 | $result = db_query($link, "SELECT description |
a0d53889 AD |
1476 | FROM ttrss_filter_types ORDER BY description"); |
1477 | ||
1478 | $filter_types = array(); | |
1479 | ||
648472a7 | 1480 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1481 | array_push($filter_types, $line["description"]); |
1482 | } | |
1483 | ||
2c7070b5 AD |
1484 | print "<div class=\"prefGenericAddBox\"> |
1485 | <input id=\"fadd_regexp\" size=\"40\"> "; | |
1486 | ||
ead60402 AD |
1487 | print_select("fadd_match", "Title", $filter_types); |
1488 | ||
1489 | print " <select id=\"fadd_feed\">"; | |
1490 | ||
1491 | print "<option selected id=\"0\">All feeds</option>"; | |
1492 | ||
1493 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
1494 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1495 | ||
1496 | if (db_num_rows($result) > 0) { | |
1497 | print "<option disabled>--------</option>"; | |
1498 | } | |
1499 | ||
1500 | while ($line = db_fetch_assoc($result)) { | |
1501 | printf("<option id='%d'>%s</option>", $line["id"], $line["title"]); | |
1502 | } | |
1503 | ||
2c7070b5 | 1504 | print "</select> "; |
a0d53889 | 1505 | |
2c7070b5 AD |
1506 | print "<input type=\"submit\" |
1507 | class=\"button\" onclick=\"javascript:addFilter()\" | |
1508 | value=\"Add filter\">"; | |
a0d53889 | 1509 | |
648472a7 | 1510 | $result = db_query($link, "SELECT |
ead60402 AD |
1511 | ttrss_filters.id AS id,reg_exp, |
1512 | ttrss_filters.description AS description, | |
1513 | ttrss_filter_types.name AS filter_type_name, | |
1514 | ttrss_filter_types.description AS filter_type_descr, | |
1515 | feed_id, | |
1516 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
a0d53889 | 1517 | FROM |
ead60402 | 1518 | ttrss_filters,ttrss_filter_types |
4356293a | 1519 | WHERE |
ead60402 AD |
1520 | filter_type = ttrss_filter_types.id AND |
1521 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." | |
4356293a | 1522 | ORDER by reg_exp"); |
a0d53889 AD |
1523 | |
1524 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
1525 | ||
1526 | print "<tr class=\"title\"> | |
ead60402 | 1527 | <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td> |
2c7070b5 AD |
1528 | <td width=\"30%\">Feed</td><td width=\"10%\">Match</td> |
1529 | <td width=\"30%\">Description</td></tr>"; | |
a0d53889 AD |
1530 | |
1531 | $lnum = 0; | |
1532 | ||
648472a7 | 1533 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1534 | |
1535 | $class = ($lnum % 2) ? "even" : "odd"; | |
1536 | ||
1537 | $filter_id = $line["id"]; | |
1538 | $edit_filter_id = $_GET["id"]; | |
1539 | ||
1540 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
1541 | $class .= "Grayed"; | |
1542 | } | |
1543 | ||
1544 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
1545 | ||
4b3dff6e | 1546 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); |
ea6774cf AD |
1547 | $line["description"] = htmlspecialchars($line["description"]); |
1548 | ||
ead60402 AD |
1549 | if (!$line["feed_title"]) $line["feed_title"] = "All feeds"; |
1550 | ||
a0d53889 AD |
1551 | if (!$edit_filter_id || $subop != "edit") { |
1552 | ||
0afbd851 AD |
1553 | if (!$line["description"]) $line["description"] = "[No description]"; |
1554 | ||
a0d53889 AD |
1555 | print "<td><input onclick='toggleSelectRow(this);' |
1556 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
1557 | ||
1558 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
4b3dff6e | 1559 | $line["reg_exp"] . "</td>"; |
2c7070b5 | 1560 | |
a0d53889 | 1561 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . |
2c7070b5 | 1562 | $line["feed_title"] . "</td>"; |
a0d53889 | 1563 | |
ead60402 AD |
1564 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . |
1565 | $line["filter_type_descr"] . "</td>"; | |
1566 | ||
1567 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2c7070b5 | 1568 | $line["description"] . "</td>"; |
a0d53889 AD |
1569 | |
1570 | } else if ($filter_id != $edit_filter_id) { | |
1571 | ||
0afbd851 AD |
1572 | if (!$line["description"]) $line["description"] = "[No description]"; |
1573 | ||
a0d53889 AD |
1574 | print "<td><input disabled=\"true\" type=\"checkbox\" |
1575 | id=\"FICHK-".$line["id"]."\"></td>"; | |
1576 | ||
4b3dff6e | 1577 | print "<td>".$line["reg_exp"]."</td>"; |
ead60402 | 1578 | print "<td>".$line["feed_title"]."</td>"; |
2c7070b5 AD |
1579 | print "<td>".$line["filter_type_descr"]."</td>"; |
1580 | print "<td>".$line["description"]."</td>"; | |
a0d53889 AD |
1581 | |
1582 | } else { | |
1583 | ||
e6cb77a0 | 1584 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; |
a0d53889 | 1585 | |
4b3dff6e | 1586 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. |
a0d53889 AD |
1587 | "\"></td>"; |
1588 | ||
ead60402 AD |
1589 | print "<td>"; |
1590 | ||
1591 | print "<select id=\"iedit_feed\">"; | |
1592 | ||
1593 | print "<option id=\"0\">All feeds</option>"; | |
1594 | ||
1595 | if (db_num_rows($result) > 0) { | |
1596 | print "<option disabled>--------</option>"; | |
1597 | } | |
1598 | ||
1599 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
1600 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1601 | ||
1602 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1603 | if ($tmp_line["id"] == $line["feed_id"]) { | |
1604 | $is_selected = "selected"; | |
1605 | } else { | |
1606 | $is_selected = ""; | |
1607 | } | |
1608 | printf("<option $is_selected id='%d'>%s</option>", | |
1609 | $tmp_line["id"], $tmp_line["title"]); | |
1610 | } | |
1611 | ||
2c7070b5 AD |
1612 | print "</select></td>"; |
1613 | ||
1614 | print "<td>"; | |
1615 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
1616 | print "</td>"; | |
1617 | ||
1618 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1619 | "\"></td>"; | |
ead60402 AD |
1620 | |
1621 | print "</td>"; | |
a0d53889 | 1622 | } |
a0d53889 AD |
1623 | |
1624 | print "</tr>"; | |
1625 | ||
1626 | ++$lnum; | |
1627 | } | |
1628 | ||
0afbd851 AD |
1629 | if ($lnum == 0) { |
1630 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
1631 | } | |
1632 | ||
a0d53889 AD |
1633 | print "</table>"; |
1634 | ||
1635 | print "<p>"; | |
1636 | ||
1637 | if ($subop == "edit") { | |
e828e31e AD |
1638 | print "Edit feed: |
1639 | <input type=\"submit\" class=\"button\" | |
1640 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
1641 | <input type=\"submit\" class=\"button\" | |
1642 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
a0d53889 AD |
1643 | |
1644 | } else { | |
1645 | ||
1646 | print " | |
e828e31e AD |
1647 | Selection: |
1648 | <input type=\"submit\" class=\"button\" | |
1649 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
1650 | <input type=\"submit\" class=\"button\" | |
1651 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
a0d53889 AD |
1652 | } |
1653 | } | |
1654 | ||
48f0adb0 AD |
1655 | if ($op == "pref-labels") { |
1656 | ||
1657 | $subop = $_GET["subop"]; | |
1658 | ||
1659 | if ($subop == "editSave") { | |
1660 | ||
1661 | $sql_exp = $_GET["s"]; | |
1662 | $descr = $_GET["d"]; | |
1663 | $label_id = db_escape_string($_GET["id"]); | |
1664 | ||
1665 | // print "$sql_exp : $descr : $label_id"; | |
1666 | ||
1667 | $result = db_query($link, "UPDATE ttrss_labels SET | |
1668 | sql_exp = '$sql_exp', | |
1669 | description = '$descr' | |
1670 | WHERE id = '$label_id'"); | |
1671 | } | |
1672 | ||
1673 | if ($subop == "remove") { | |
1674 | ||
1675 | if (!WEB_DEMO_MODE) { | |
1676 | ||
1677 | $ids = split(",", $_GET["ids"]); | |
1678 | ||
1679 | foreach ($ids as $id) { | |
1680 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
1681 | ||
1682 | } | |
1683 | } | |
1684 | } | |
1685 | ||
1686 | if ($subop == "add") { | |
1687 | ||
1688 | if (!WEB_DEMO_MODE) { | |
1689 | ||
4401bf04 AD |
1690 | // no escaping is done here on purpose |
1691 | $exp = trim($_GET["exp"]); | |
48f0adb0 AD |
1692 | |
1693 | $result = db_query($link, | |
4356293a AD |
1694 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) |
1695 | VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')"); | |
48f0adb0 AD |
1696 | } |
1697 | } | |
1698 | ||
2c7070b5 AD |
1699 | print "<div class=\"prefGenericAddBox\"> |
1700 | <input size=\"40\" id=\"ladd_expr\"> "; | |
48f0adb0 | 1701 | |
2c7070b5 AD |
1702 | print"<input type=\"submit\" class=\"button\" |
1703 | onclick=\"javascript:addLabel()\" value=\"Add label\"></div>"; | |
48f0adb0 AD |
1704 | |
1705 | $result = db_query($link, "SELECT | |
1706 | id,sql_exp,description | |
1707 | FROM | |
4356293a AD |
1708 | ttrss_labels |
1709 | WHERE | |
1710 | owner_uid = ".$_SESSION["uid"]." | |
1711 | ORDER by description"); | |
48f0adb0 AD |
1712 | |
1713 | print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">"; | |
1714 | ||
1715 | print "<tr class=\"title\"> | |
7dc66a61 AD |
1716 | <td width=\"5%\">Select</td><td width=\"40%\">SQL expression |
1717 | <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a> | |
1718 | </td> | |
48f0adb0 AD |
1719 | <td width=\"40%\">Caption</td></tr>"; |
1720 | ||
1721 | $lnum = 0; | |
1722 | ||
1723 | while ($line = db_fetch_assoc($result)) { | |
1724 | ||
1725 | $class = ($lnum % 2) ? "even" : "odd"; | |
1726 | ||
1727 | $label_id = $line["id"]; | |
1728 | $edit_label_id = $_GET["id"]; | |
1729 | ||
1730 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
1731 | $class .= "Grayed"; | |
1732 | } | |
1733 | ||
1734 | print "<tr class=\"$class\" id=\"LILRR-$label_id\">"; | |
1735 | ||
1736 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
1737 | $line["description"] = htmlspecialchars($line["description"]); | |
1738 | ||
1739 | if (!$edit_label_id || $subop != "edit") { | |
1740 | ||
1741 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
1742 | ||
1743 | print "<td><input onclick='toggleSelectRow(this);' | |
1744 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
1745 | ||
1746 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1747 | $line["sql_exp"] . "</td>"; | |
1748 | ||
1749 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1750 | $line["description"] . "</td>"; | |
1751 | ||
1752 | } else if ($label_id != $edit_label_id) { | |
1753 | ||
1754 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1755 | ||
1756 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1757 | id=\"LICHK-".$line["id"]."\"></td>"; | |
1758 | ||
1759 | print "<td>".$line["sql_exp"]."</td>"; | |
1760 | print "<td>".$line["description"]."</td>"; | |
1761 | ||
1762 | } else { | |
1763 | ||
e6cb77a0 | 1764 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; |
48f0adb0 AD |
1765 | |
1766 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
1767 | "\"></td>"; | |
1768 | ||
1769 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1770 | "\"></td>"; | |
1771 | ||
1772 | } | |
1773 | ||
1774 | ||
1775 | print "</tr>"; | |
1776 | ||
1777 | ++$lnum; | |
1778 | } | |
1779 | ||
1780 | if ($lnum == 0) { | |
1781 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
1782 | } | |
1783 | ||
1784 | print "</table>"; | |
1785 | ||
1786 | print "<p>"; | |
1787 | ||
1788 | if ($subop == "edit") { | |
1789 | print "Edit label: | |
1790 | <input type=\"submit\" class=\"button\" | |
1791 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
1792 | <input type=\"submit\" class=\"button\" | |
1793 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
1794 | ||
1795 | } else { | |
1796 | ||
1797 | print " | |
1798 | Selection: | |
1799 | <input type=\"submit\" class=\"button\" | |
1800 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> | |
1801 | <input type=\"submit\" class=\"button\" | |
1802 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; | |
1803 | } | |
1804 | } | |
1805 | ||
e828e31e AD |
1806 | if ($op == "error") { |
1807 | print "<div width=\"100%\" align='center'>"; | |
1808 | $msg = $_GET["msg"]; | |
1809 | print $msg; | |
1810 | print "</div>"; | |
1811 | } | |
1812 | ||
7dc66a61 AD |
1813 | if ($op == "help") { |
1814 | print "<html><head> | |
1815 | <title>Tiny Tiny RSS : Help</title> | |
1816 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
1817 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
7dc66a61 AD |
1818 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
1819 | </head><body>"; | |
1820 | ||
1821 | $tid = sprintf("%d", $_GET["tid"]); | |
1822 | ||
1823 | /* FIXME this badly needs real implementation */ | |
1824 | ||
1825 | print "<div class='helpResponse'>"; | |
1826 | ||
1827 | ?> | |
1828 | ||
1829 | <h1>Help for SQL expressions</h1> | |
1830 | ||
1831 | <h2>Description</h2> | |
1832 | ||
1833 | <p>The «SQL expression» is added to WHERE clause of | |
d1f948d1 | 1834 | view feed query. You can match on ttrss_entries table fields |
7dc66a61 AD |
1835 | and even use subselect to query additional information. This |
1836 | functionality is considered to be advanced and requires basic | |
1837 | understanding of SQL.</p> | |
1838 | ||
1839 | <h2>Examples</h2> | |
1840 | ||
1841 | <pre>unread = true</pre> | |
1842 | ||
1843 | Matches all unread articles | |
1844 | ||
1845 | <pre>title like '%Linux%'</pre> | |
1846 | ||
1847 | Matches all articles which mention Linux in the title. You get the idea. | |
1848 | ||
1849 | <p>See the database schema included in the distribution package for gruesome | |
1850 | details.</p> | |
1851 | ||
1852 | <? | |
1853 | ||
1854 | print "<div align='center'> | |
1855 | <a class=\"helpLink\" | |
1856 | href=\"javascript:window.close()\">(Close this window)</a></div>"; | |
1857 | ||
1858 | print "</div>"; | |
1859 | ||
1860 | print "</body></html>"; | |
1861 | ||
1862 | } | |
1863 | ||
f84a97a3 AD |
1864 | if ($op == "dlg") { |
1865 | $id = $_GET["id"]; | |
6de5d056 | 1866 | $param = $_GET["param"]; |
f84a97a3 AD |
1867 | |
1868 | if ($id == "quickAddFeed") { | |
033e47e0 AD |
1869 | print "Feed URL: <input |
1870 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
1871 | id=\"qafInput\"> | |
f84a97a3 AD |
1872 | <input class=\"button\" |
1873 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> | |
1874 | <input class=\"button\" | |
1875 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1876 | value=\"Cancel\">"; | |
1877 | } | |
6de5d056 AD |
1878 | |
1879 | if ($id == "quickDelFeed") { | |
1880 | ||
1881 | $param = db_escape_string($param); | |
1882 | ||
1883 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
1884 | ||
1885 | if ($result) { | |
1886 | ||
1887 | $f_title = db_fetch_result($result, 0, "title"); | |
1888 | ||
1889 | print "Remove current feed ($f_title)? | |
1890 | <input class=\"button\" | |
1891 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
1892 | <input class=\"button\" | |
1893 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1894 | value=\"Cancel\">"; | |
1895 | } else { | |
1896 | print "Error: Feed $param not found. | |
1897 | <input class=\"button\" | |
1898 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1899 | value=\"Cancel\">"; | |
1900 | } | |
1901 | } | |
1902 | ||
033e47e0 AD |
1903 | if ($id == "search") { |
1904 | ||
1905 | print "<input id=\"searchbox\" class=\"extSearch\" | |
1906 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
1907 | onchange=\"javascript:search()\"> | |
1908 | <select id=\"searchmodebox\"> | |
1909 | <option selected>All feeds</option> | |
1910 | <option>This feed</option> | |
1911 | </select> | |
1912 | <input type=\"submit\" | |
1913 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
1914 | <input class=\"button\" | |
1915 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1916 | value=\"Close\">"; | |
1917 | ||
1918 | } | |
1919 | ||
f84a97a3 AD |
1920 | } |
1921 | ||
a2770077 AD |
1922 | // update feeds of all users, may be used anonymously |
1923 | if ($op == "globalUpdateFeeds") { | |
1924 | ||
1925 | $result = db_query($link, "SELECT id FROM ttrss_users"); | |
1926 | ||
1927 | while ($line = db_fetch_assoc($result)) { | |
1928 | $user_id = $line["id"]; | |
1929 | // print "<!-- updating feeds of uid $user_id -->"; | |
1930 | update_all_feeds($link, false, $user_id); | |
1931 | } | |
e65af9c1 | 1932 | |
a2770077 AD |
1933 | print "<rpc-reply> |
1934 | <message msg=\"All feeds updated\"/> | |
1935 | </rpc-reply>"; | |
e65af9c1 AD |
1936 | |
1937 | } | |
1938 | ||
77e96719 AD |
1939 | if ($op == "pref-prefs") { |
1940 | ||
b1895692 | 1941 | $subop = $_REQUEST["subop"]; |
77e96719 AD |
1942 | |
1943 | if ($subop == "Save configuration") { | |
1944 | ||
d2892032 AD |
1945 | if (WEB_DEMO_MODE) { |
1946 | header("Location: prefs.php"); | |
1947 | return; | |
1948 | } | |
01d68cf9 | 1949 | |
93cb4442 AD |
1950 | $_SESSION["prefs_op_result"] = "save-config"; |
1951 | ||
77e96719 AD |
1952 | foreach (array_keys($_POST) as $pref_name) { |
1953 | ||
1954 | $pref_name = db_escape_string($pref_name); | |
1955 | $value = db_escape_string($_POST[$pref_name]); | |
1956 | ||
1957 | $result = db_query($link, "SELECT type_name | |
1958 | FROM ttrss_prefs,ttrss_prefs_types | |
1959 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
1960 | ||
1961 | if (db_num_rows($result) > 0) { | |
1962 | ||
1963 | $type_name = db_fetch_result($result, 0, "type_name"); | |
1964 | ||
5da169d9 AD |
1965 | // print "$pref_name : $type_name : $value<br>"; |
1966 | ||
77e96719 | 1967 | if ($type_name == "bool") { |
5da169d9 | 1968 | if ($value == "1") { |
77e96719 AD |
1969 | $value = "true"; |
1970 | } else { | |
1971 | $value = "false"; | |
1972 | } | |
1973 | } else if ($type_name == "integer") { | |
1974 | $value = sprintf("%d", $value); | |
1975 | } | |
1976 | ||
1977 | // print "$pref_name : $type_name : $value<br>"; | |
1978 | ||
ff485f1d AD |
1979 | db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' |
1980 | WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); | |
77e96719 AD |
1981 | |
1982 | } | |
1983 | ||
1984 | header("Location: prefs.php"); | |
1985 | ||
1986 | } | |
1987 | ||
b1895692 AD |
1988 | } else if ($subop == "getHelp") { |
1989 | ||
1990 | $pref_name = db_escape_string($_GET["pn"]); | |
1991 | ||
1992 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
1993 | WHERE pref_name = '$pref_name'"); | |
1994 | ||
1995 | if (db_num_rows($result) > 0) { | |
1996 | $help_text = db_fetch_result($result, 0, "help_text"); | |
1997 | print $help_text; | |
1998 | } else { | |
1999 | print "Unknown option: $pref_name"; | |
2000 | } | |
2001 | ||
1c7f75ed AD |
2002 | } else if ($subop == "Change password") { |
2003 | ||
d2892032 AD |
2004 | if (WEB_DEMO_MODE) { |
2005 | header("Location: prefs.php"); | |
2006 | return; | |
2007 | } | |
1c7f75ed AD |
2008 | |
2009 | $old_pw = $_POST["OLD_PASSWORD"]; | |
2010 | $new_pw = $_POST["OLD_PASSWORD"]; | |
2011 | ||
2012 | $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]); | |
2013 | $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]); | |
2014 | ||
2015 | $active_uid = $_SESSION["uid"]; | |
2016 | ||
2017 | if ($old_pw && $new_pw) { | |
2018 | ||
2019 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
2020 | ||
2021 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
2022 | id = '$active_uid' AND (pwd_hash = '$old_pw' OR | |
2023 | pwd_hash = '$old_pw_hash')"); | |
2024 | ||
2025 | if (db_num_rows($result) == 1) { | |
2026 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
2027 | WHERE id = '$active_uid'"); | |
b791095d AD |
2028 | |
2029 | $_SESSION["pwd_change_result"] = "ok"; | |
2030 | } else { | |
2031 | $_SESSION["pwd_change_result"] = "failed"; | |
1c7f75ed AD |
2032 | } |
2033 | } | |
2034 | ||
2035 | header("Location: prefs.php"); | |
b791095d | 2036 | |
77e96719 AD |
2037 | } else if ($subop == "Reset to defaults") { |
2038 | ||
d2892032 AD |
2039 | if (WEB_DEMO_MODE) { |
2040 | header("Location: prefs.php"); | |
2041 | return; | |
2042 | } | |
01d68cf9 | 2043 | |
93cb4442 AD |
2044 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
2045 | ||
e1aa0559 AD |
2046 | if (DB_TYPE == "pgsql") { |
2047 | db_query($link,"UPDATE ttrss_user_prefs | |
2048 | SET value = ttrss_prefs.def_value | |
2049 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
2050 | ttrss_prefs.pref_name = ttrss_user_prefs.pref_name"); | |
2051 | } else { | |
2052 | db_query($link, "DELETE FROM ttrss_user_prefs | |
2053 | WHERE owner_uid = ".$_SESSION["uid"]); | |
2054 | initialize_user_prefs($link, $_SESSION["uid"]); | |
2055 | } | |
5da169d9 | 2056 | |
77e96719 AD |
2057 | header("Location: prefs.php"); |
2058 | ||
2059 | } else { | |
2060 | ||
7d4c898a | 2061 | if (!SINGLE_USER_MODE) { |
1c7f75ed | 2062 | |
a029d530 AD |
2063 | $result = db_query($link, "SELECT id FROM ttrss_users |
2064 | WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR | |
2065 | pwd_hash = 'SHA1:".sha1("password")."')"); | |
2066 | ||
2067 | if (db_num_rows($result) != 0) { | |
b791095d | 2068 | print "<div class=\"warning\"> |
a029d530 AD |
2069 | Your password is at default value, please change it. |
2070 | </div>"; | |
2071 | } | |
2072 | ||
b791095d AD |
2073 | if ($_SESSION["pwd_change_result"] == "failed") { |
2074 | print "<div class=\"warning\"> | |
2075 | There was an error while changing your password. | |
2076 | </div>"; | |
2077 | } | |
2078 | ||
2079 | if ($_SESSION["pwd_change_result"] == "ok") { | |
2080 | print "<div class=\"notice\"> | |
2081 | Password changed successfully. | |
2082 | </div>"; | |
2083 | } | |
2084 | ||
2085 | $_SESSION["pwd_change_result"] = ""; | |
2086 | ||
93cb4442 AD |
2087 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { |
2088 | print "<div class=\"notice\"> | |
2089 | Your configuration was reset to defaults. | |
2090 | </div>"; | |
2091 | } | |
2092 | ||
2093 | if ($_SESSION["prefs_op_result"] == "save-config") { | |
2094 | print "<div class=\"notice\"> | |
2095 | Your configuration was saved successfully. | |
2096 | </div>"; | |
2097 | } | |
2098 | ||
2099 | $_SESSION["prefs_op_result"] = ""; | |
2100 | ||
7d4c898a AD |
2101 | print "<form action=\"backend.php\" method=\"POST\">"; |
2102 | ||
2103 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
2104 | print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>"; | |
2105 | ||
2106 | print "<tr><td width=\"40%\">Old password</td>"; | |
2107 | print "<td><input class=\"editbox\" type=\"password\" | |
2108 | name=\"OLD_PASSWORD\"></td></tr>"; | |
2109 | ||
2110 | print "<tr><td width=\"40%\">New password</td>"; | |
2111 | ||
2112 | print "<td><input class=\"editbox\" type=\"password\" | |
2113 | name=\"NEW_PASSWORD\"></td></tr>"; | |
2114 | ||
2115 | print "</table>"; | |
2116 | ||
2117 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
2118 | ||
2119 | print "<p><input class=\"button\" type=\"submit\" | |
2120 | value=\"Change password\" name=\"subop\">"; | |
2121 | ||
2122 | print "</form>"; | |
1c7f75ed | 2123 | |
7d4c898a | 2124 | } |
1c7f75ed | 2125 | |
77e96719 | 2126 | $result = db_query($link, "SELECT |
ff485f1d | 2127 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, |
77e96719 | 2128 | section_name,def_value |
ff485f1d | 2129 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
77e96719 | 2130 | WHERE type_id = ttrss_prefs_types.id AND |
ff485f1d | 2131 | section_id = ttrss_prefs_sections.id AND |
a2411bd9 AD |
2132 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
2133 | owner_uid = ".$_SESSION["uid"]." | |
650bc435 | 2134 | ORDER BY section_id,short_desc"); |
77e96719 AD |
2135 | |
2136 | print "<form action=\"backend.php\" method=\"POST\">"; | |
2137 | ||
77e96719 AD |
2138 | $lnum = 0; |
2139 | ||
2140 | $active_section = ""; | |
2141 | ||
2142 | while ($line = db_fetch_assoc($result)) { | |
2143 | ||
2144 | if ($active_section != $line["section_name"]) { | |
59a654ba AD |
2145 | |
2146 | if ($active_section != "") { | |
1c7f75ed | 2147 | print "</table>"; |
59a654ba | 2148 | } |
1c7f75ed AD |
2149 | |
2150 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
59a654ba AD |
2151 | |
2152 | $active_section = $line["section_name"]; | |
2153 | ||
77e96719 | 2154 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; |
59a654ba AD |
2155 | // print "<tr class=\"title\"> |
2156 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
7268adf7 AD |
2157 | |
2158 | $lnum = 0; | |
77e96719 AD |
2159 | } |
2160 | ||
650bc435 | 2161 | // $class = ($lnum % 2) ? "even" : "odd"; |
77e96719 | 2162 | |
650bc435 | 2163 | print "<tr>"; |
77e96719 | 2164 | |
77e96719 AD |
2165 | $type_name = $line["type_name"]; |
2166 | $pref_name = $line["pref_name"]; | |
2167 | $value = $line["value"]; | |
2168 | $def_value = $line["def_value"]; | |
b1895692 AD |
2169 | $help_text = $line["help_text"]; |
2170 | ||
2171 | print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"]; | |
2172 | ||
2173 | if ($help_text) print "<div class=\"prefHelp\">$help_text</div>"; | |
2174 | ||
2175 | print "</td>"; | |
77e96719 AD |
2176 | |
2177 | print "<td>"; | |
2178 | ||
2179 | if ($type_name == "bool") { | |
2180 | // print_select($pref_name, $value, array("true", "false")); | |
2181 | ||
2182 | if ($value == "true") { | |
2183 | $value = "Yes"; | |
2184 | } else { | |
2185 | $value = "No"; | |
2186 | } | |
2187 | ||
2188 | print_radio($pref_name, $value, array("Yes", "No")); | |
2189 | ||
2190 | } else { | |
2191 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
2192 | } | |
2193 | ||
2194 | print "</td>"; | |
2195 | ||
2196 | print "</tr>"; | |
2197 | ||
2198 | $lnum++; | |
2199 | } | |
2200 | ||
2201 | print "</table>"; | |
2202 | ||
2203 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
2204 | ||
2205 | print "<p><input class=\"button\" type=\"submit\" | |
2206 | name=\"subop\" value=\"Save configuration\">"; | |
2207 | ||
2208 | print " <input class=\"button\" type=\"submit\" | |
2209 | name=\"subop\" value=\"Reset to defaults\"></p>"; | |
2210 | ||
2211 | print "</form>"; | |
2212 | ||
2213 | } | |
2214 | ||
2215 | } | |
2216 | ||
e6cb77a0 AD |
2217 | if ($op == "pref-users") { |
2218 | ||
2219 | $subop = $_GET["subop"]; | |
2220 | ||
2221 | if ($subop == "editSave") { | |
2222 | ||
2223 | if (!WEB_DEMO_MODE) { | |
2224 | ||
2225 | $login = db_escape_string($_GET["l"]); | |
2226 | $uid = db_escape_string($_GET["id"]); | |
2227 | $access_level = sprintf("%d", $_GET["al"]); | |
2228 | ||
2229 | db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'"); | |
2230 | ||
2231 | } | |
2232 | } else if ($subop == "remove") { | |
2233 | ||
2234 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
2235 | ||
2236 | $ids = split(",", $_GET["ids"]); | |
2237 | ||
2238 | foreach ($ids as $id) { | |
2239 | db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]); | |
2240 | ||
2241 | } | |
2242 | } | |
2243 | } else if ($subop == "add") { | |
2244 | ||
2245 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
2246 | ||
b6b535ca | 2247 | $login = db_escape_string(trim($_GET["login"])); |
e6cb77a0 AD |
2248 | $tmp_user_pwd = make_password(8); |
2249 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
2250 | ||
2251 | db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level) | |
2252 | VALUES ('$login', '$pwd_hash', 0)"); | |
2253 | ||
2254 | ||
2255 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
2256 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
2257 | ||
2258 | if (db_num_rows($result) == 1) { | |
2259 | ||
2260 | $new_uid = db_fetch_result($result, 0, "id"); | |
2261 | ||
2262 | print "<div class=\"notice\">Added user <b>".$_GET["login"]. | |
2263 | "</b> with password <b>$tmp_user_pwd</b>.</div>"; | |
2264 | ||
2265 | initialize_user($link, $new_uid); | |
2266 | ||
2267 | } else { | |
2268 | ||
2269 | print "<div class=\"warning\">Error while adding user <b>". | |
2270 | $_GET["login"].".</b></div>"; | |
2271 | ||
2272 | } | |
2273 | } | |
2274 | } else if ($subop == "resetPass") { | |
2275 | ||
2276 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
2277 | ||
2278 | $uid = db_escape_string($_GET["id"]); | |
2279 | ||
2280 | $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'"); | |
2281 | ||
2282 | $login = db_fetch_result($result, 0, "login"); | |
2283 | $tmp_user_pwd = make_password(8); | |
2284 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
2285 | ||
2286 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
2287 | WHERE id = '$uid'"); | |
2288 | ||
2289 | print "<div class=\"notice\">Changed password of | |
2290 | user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>"; | |
2291 | ||
2292 | } | |
2293 | } | |
2294 | ||
2c7070b5 AD |
2295 | print "<div class=\"prefGenericAddBox\"> |
2296 | <input id=\"uadd_box\" size=\"40\"> "; | |
e6cb77a0 | 2297 | |
2c7070b5 AD |
2298 | print"<input type=\"submit\" class=\"button\" |
2299 | onclick=\"javascript:addUser()\" value=\"Add user\"></div>"; | |
e6cb77a0 AD |
2300 | |
2301 | $result = db_query($link, "SELECT | |
fe99ab12 AD |
2302 | id,login,access_level, |
2303 | SUBSTRING(last_login,1,16) as last_login | |
e6cb77a0 AD |
2304 | FROM |
2305 | ttrss_users | |
2306 | ORDER by login"); | |
2307 | ||
2317ffaa | 2308 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
1a7572cb | 2309 | |
e6cb77a0 AD |
2310 | print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">"; |
2311 | ||
2312 | print "<tr class=\"title\"> | |
f6f32198 AD |
2313 | <td width=\"5%\">Select</td> |
2314 | <td width='30%'>Username</td> | |
2315 | <td width='30%'>Access Level</td> | |
2316 | <td width='30%'>Last login</td></tr>"; | |
e6cb77a0 AD |
2317 | |
2318 | $lnum = 0; | |
2319 | ||
2320 | while ($line = db_fetch_assoc($result)) { | |
2321 | ||
2322 | $class = ($lnum % 2) ? "even" : "odd"; | |
2323 | ||
2324 | $uid = $line["id"]; | |
2325 | $edit_uid = $_GET["id"]; | |
2326 | ||
2327 | if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) { | |
2328 | $class .= "Grayed"; | |
2329 | } | |
2330 | ||
2331 | print "<tr class=\"$class\" id=\"UMRR-$uid\">"; | |
2332 | ||
2333 | $line["login"] = htmlspecialchars($line["login"]); | |
2334 | ||
2335 | if ($uid == $_SESSION["uid"]) { | |
2336 | ||
2337 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2338 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
2339 | ||
2340 | print "<td>".$line["login"]."</td>"; | |
2341 | print "<td>".$line["access_level"]."</td>"; | |
e6cb77a0 AD |
2342 | |
2343 | } else if (!$edit_uid || $subop != "edit") { | |
2344 | ||
2345 | print "<td><input onclick='toggleSelectRow(this);' | |
1a7572cb | 2346 | type=\"checkbox\" id=\"UMCHK-$uid\"></td>"; |
e6cb77a0 AD |
2347 | |
2348 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
2349 | $line["login"] . "</td>"; | |
2350 | ||
2351 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
2352 | $line["access_level"] . "</td>"; | |
2353 | ||
2354 | } else if ($uid != $edit_uid) { | |
2355 | ||
2356 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2357 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
2358 | ||
2359 | print "<td>".$line["login"]."</td>"; | |
2360 | print "<td>".$line["access_level"]."</td>"; | |
2361 | ||
2362 | } else { | |
2363 | ||
2364 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2365 | ||
2366 | print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"]. | |
2367 | "\"></td>"; | |
2368 | ||
2369 | print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"]. | |
2370 | "\"></td>"; | |
2371 | ||
2372 | } | |
2373 | ||
f6f32198 AD |
2374 | print "<td>".$line["last_login"]."</td>"; |
2375 | ||
e6cb77a0 AD |
2376 | print "</tr>"; |
2377 | ||
2378 | ++$lnum; | |
2379 | } | |
2380 | ||
2381 | print "</table>"; | |
2382 | ||
2383 | print "<p>"; | |
2384 | ||
2385 | if ($subop == "edit") { | |
2386 | print "Edit label: | |
2387 | <input type=\"submit\" class=\"button\" | |
2388 | onclick=\"javascript:userEditCancel()\" value=\"Cancel\"> | |
2389 | <input type=\"submit\" class=\"button\" | |
2390 | onclick=\"javascript:userEditSave()\" value=\"Save\">"; | |
2391 | ||
2392 | } else { | |
2393 | ||
2394 | print " | |
2395 | Selection: | |
2396 | <input type=\"submit\" class=\"button\" | |
717f5e64 | 2397 | onclick=\"javascript:selectedUserDetails()\" value=\"User details\"> |
e6cb77a0 AD |
2398 | <input type=\"submit\" class=\"button\" |
2399 | onclick=\"javascript:editSelectedUser()\" value=\"Edit\"> | |
2400 | <input type=\"submit\" class=\"button\" | |
717f5e64 AD |
2401 | onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\"> |
2402 | <input type=\"submit\" class=\"button\" | |
2403 | onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">"; | |
2404 | ||
2405 | } | |
2406 | } | |
2407 | ||
2408 | if ($op == "user-details") { | |
2409 | ||
2410 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { | |
2411 | return; | |
2412 | } | |
2413 | ||
1a7572cb | 2414 | /* print "<html><head> |
717f5e64 AD |
2415 | <title>Tiny Tiny RSS : User Details</title> |
2416 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
2417 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
1a7572cb | 2418 | </head><body>"; */ |
717f5e64 AD |
2419 | |
2420 | $uid = sprintf("%d", $_GET["id"]); | |
2421 | ||
c6c3a07f | 2422 | print "<div class='infoBoxContents'>"; |
717f5e64 | 2423 | |
fe99ab12 AD |
2424 | $result = db_query($link, "SELECT login, |
2425 | SUBSTRING(last_login,1,16) AS last_login, | |
2426 | access_level, | |
c6c3a07f AD |
2427 | (SELECT COUNT(int_id) FROM ttrss_user_entries |
2428 | WHERE owner_uid = id) AS stored_articles | |
717f5e64 AD |
2429 | FROM ttrss_users |
2430 | WHERE id = '$uid'"); | |
2431 | ||
2432 | if (db_num_rows($result) == 0) { | |
2433 | print "<h1>User not found</h1>"; | |
2434 | return; | |
2435 | } | |
2436 | ||
2437 | print "<h1>User Details</h1>"; | |
2438 | ||
2439 | print "<table width='100%'>"; | |
2440 | ||
2441 | $login = db_fetch_result($result, 0, "login"); | |
2442 | $last_login = db_fetch_result($result, 0, "last_login"); | |
2443 | $access_level = db_fetch_result($result, 0, "access_level"); | |
c6c3a07f | 2444 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); |
717f5e64 AD |
2445 | |
2446 | print "<tr><td>Username</td><td>$login</td></tr>"; | |
2447 | print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
2448 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
c6c3a07f | 2449 | print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>"; |
717f5e64 AD |
2450 | |
2451 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
2452 | WHERE owner_uid = '$uid'"); | |
2453 | ||
2454 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
2455 | ||
2456 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; | |
2457 | ||
5d15d3ea | 2458 | /* $result = db_query($link, "SELECT |
717f5e64 | 2459 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size |
c6c3a07f AD |
2460 | FROM ttrss_user_entries,ttrss_entries |
2461 | WHERE owner_uid = '$uid' AND ref_id = id"); | |
717f5e64 | 2462 | |
d9f115c3 | 2463 | $db_size = round(db_fetch_result($result, 0, "db_size") / 1024); |
717f5e64 | 2464 | |
c6c3a07f | 2465 | print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */ |
717f5e64 AD |
2466 | |
2467 | print "</table>"; | |
2468 | ||
2469 | print "<h1>Subscribed feeds</h1>"; | |
2470 | ||
2471 | $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds | |
d9f115c3 | 2472 | WHERE owner_uid = '$uid' ORDER BY title"); |
717f5e64 AD |
2473 | |
2474 | print "<ul class=\"nomarks\">"; | |
2475 | ||
2476 | while ($line = db_fetch_assoc($result)) { | |
2477 | ||
2478 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
2479 | ||
2480 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
6c56687e | 2481 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; |
717f5e64 | 2482 | } else { |
5951ded1 | 2483 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; |
717f5e64 AD |
2484 | } |
2485 | ||
2486 | print "<li>$feed_icon <a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>"; | |
e6cb77a0 | 2487 | } |
717f5e64 AD |
2488 | |
2489 | print "</ul>"; | |
2490 | ||
717f5e64 AD |
2491 | print "</div>"; |
2492 | ||
1a7572cb AD |
2493 | print "<div align='center'> |
2494 | <input type='submit' class='button' | |
c6c3a07f | 2495 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; |
1a7572cb AD |
2496 | |
2497 | // print "</body></html>"; | |
717f5e64 | 2498 | |
e6cb77a0 AD |
2499 | } |
2500 | ||
c6c3a07f AD |
2501 | if ($op == "feed-details") { |
2502 | ||
2503 | $feed_id = $_GET["id"]; | |
2504 | ||
2505 | $result = db_query($link, | |
2506 | "SELECT | |
f324892e | 2507 | title,feed_url,last_updated,icon_url,site_url, |
c6c3a07f AD |
2508 | (SELECT COUNT(int_id) FROM ttrss_user_entries |
2509 | WHERE feed_id = id) AS total, | |
2510 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
2511 | WHERE feed_id = id AND unread = true) AS unread, | |
2512 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
2513 | WHERE feed_id = id AND marked = true) AS marked | |
2514 | FROM ttrss_feeds | |
2515 | WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]); | |
2516 | ||
2517 | if (db_num_rows($result) == 0) return; | |
2518 | ||
2519 | $title = db_fetch_result($result, 0, "title"); | |
2520 | $last_updated = db_fetch_result($result, 0, "last_updated"); | |
2521 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
4fec9fd7 | 2522 | $icon_url = db_fetch_result($result, 0, "icon_url"); |
c6c3a07f AD |
2523 | $total = db_fetch_result($result, 0, "total"); |
2524 | $unread = db_fetch_result($result, 0, "unread"); | |
2525 | $marked = db_fetch_result($result, 0, "marked"); | |
f324892e | 2526 | $site_url = db_fetch_result($result, 0, "site_url"); |
4fec9fd7 AD |
2527 | |
2528 | $result = db_query($link, "SELECT COUNT(id) AS subscribed | |
2529 | FROM ttrss_feeds WHERE feed_url = '$feed_url'"); | |
2530 | ||
2531 | $subscribed = db_fetch_result($result, 0, "subscribed"); | |
2532 | ||
2533 | print "<div class=\"infoBoxContents\">"; | |
2534 | ||
2535 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
2536 | ||
2537 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
2538 | $feed_icon = "<img width=\"16\" height=\"16\" | |
2539 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
2540 | } else { | |
2541 | $feed_icon = ""; | |
2542 | } | |
2543 | ||
2544 | print "<h1>$feed_icon $title</h1>"; | |
c6c3a07f AD |
2545 | |
2546 | print "<table width='100%'>"; | |
2547 | ||
f324892e AD |
2548 | if ($site_url) { |
2549 | print "<tr><td width='30%'>Link</td> | |
2550 | <td><a href=\"$site_url\">$site_url</a> | |
2551 | <a href=\"$feed_url\">(feed)</a></td> | |
2552 | </td></tr>"; | |
2553 | } else { | |
2554 | print "<tr><td width='30%'>Feed URL</td> | |
2555 | <td><a href=\"$feed_url\">$feed_url</a></td></tr>"; | |
2556 | } | |
c6c3a07f AD |
2557 | print "<tr><td>Last updated</td><td>$last_updated</td></tr>"; |
2558 | print "<tr><td>Total articles</td><td>$total</td></tr>"; | |
2559 | print "<tr><td>Unread articles</td><td>$unread</td></tr>"; | |
2560 | print "<tr><td>Starred articles</td><td>$marked</td></tr>"; | |
4fec9fd7 | 2561 | print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>"; |
c6c3a07f AD |
2562 | |
2563 | print "</table>"; | |
2564 | ||
bffdddd0 AD |
2565 | $result = db_query($link, "SELECT title, |
2566 | SUBSTRING(updated,1,16) AS updated,unread | |
bca02305 AD |
2567 | FROM ttrss_entries,ttrss_user_entries |
2568 | WHERE ref_id = id AND feed_id = '$feed_id' | |
c565e1ef | 2569 | ORDER BY date_entered DESC LIMIT 5"); |
c6c3a07f | 2570 | |
bca02305 AD |
2571 | if (db_num_rows($result) > 0) { |
2572 | ||
2573 | print "<h1>Latest headlines</h1>"; | |
c6c3a07f | 2574 | |
bca02305 AD |
2575 | print "<ul class=\"nomarks\">"; |
2576 | ||
2577 | while ($line = db_fetch_assoc($result)) { | |
c565e1ef AD |
2578 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
2579 | $line["title"] = "<b>" . $line["title"] . "</b>"; | |
2580 | } | |
bca02305 AD |
2581 | print "<li>" . $line["title"]. |
2582 | " <span class=\"insensitive\">(" .$line["updated"].")</span></li>"; | |
2583 | } | |
2584 | ||
2585 | print "</ul>"; | |
2586 | ||
2587 | print "</div>"; | |
2588 | ||
2589 | print "<div align='center'> | |
2590 | <input type='submit' class='button' | |
2591 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
2592 | } | |
c6c3a07f AD |
2593 | } |
2594 | ||
4b3dff6e | 2595 | db_close($link); |
1cd17194 | 2596 | ?> |
406d9489 AD |
2597 | |
2598 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
2599 |