]>
Commit | Line | Data |
---|---|---|
1 | <? | |
2 | session_start(); | |
3 | ||
4 | if ($_GET["debug"]) { | |
5 | define('DEFAULT_ERROR_LEVEL', E_ALL); | |
6 | } else { | |
7 | define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE); | |
8 | } | |
9 | ||
10 | error_reporting(DEFAULT_ERROR_LEVEL); | |
11 | ||
12 | $op = $_REQUEST["op"]; | |
13 | ||
14 | if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) { | |
15 | header("Content-Type: application/xml"); | |
16 | } | |
17 | ||
18 | if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") { | |
19 | ||
20 | if ($op == "rpc") { | |
21 | print "<error error-code=\"6\"/>"; | |
22 | } | |
23 | exit; | |
24 | } | |
25 | ||
26 | if (!$op) { | |
27 | print "<error error-code=\"7\"/>"; | |
28 | exit; | |
29 | } | |
30 | ||
31 | define('SCHEMA_VERSION', 2); | |
32 | ||
33 | require_once "sanity_check.php"; | |
34 | require_once "config.php"; | |
35 | require_once "db.php"; | |
36 | require_once "db-prefs.php"; | |
37 | require_once "functions.php"; | |
38 | require_once "magpierss/rss_fetch.inc"; | |
39 | ||
40 | $script_started = getmicrotime(); | |
41 | ||
42 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
43 | ||
44 | if (!$link) { | |
45 | if (DB_TYPE == "mysql") { | |
46 | print mysql_error(); | |
47 | } | |
48 | // PG seems to display its own errors just fine by default. | |
49 | return; | |
50 | } | |
51 | ||
52 | if (DB_TYPE == "pgsql") { | |
53 | pg_query("set client_encoding = 'utf-8'"); | |
54 | } | |
55 | ||
56 | $fetch = $_GET["fetch"]; | |
57 | ||
58 | setcookie("ttrss_icons_url", ICONS_URL); | |
59 | ||
60 | function getAllCounters($link) { | |
61 | getLabelCounters($link); | |
62 | getFeedCounters($link); | |
63 | getTagCounters($link); | |
64 | getGlobalCounters($link); | |
65 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
66 | getCategoryCounters($link); | |
67 | } | |
68 | } | |
69 | ||
70 | function getCategoryCounters($link) { | |
71 | $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id) | |
72 | FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id | |
73 | AND unread = true)) AS unread FROM ttrss_feeds | |
74 | WHERE owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id"); | |
75 | ||
76 | while ($line = db_fetch_assoc($result)) { | |
77 | $line["cat_id"] = sprintf("%d", $line["cat_id"]); | |
78 | print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"". | |
79 | $line["unread"]."\"/>"; | |
80 | } | |
81 | } | |
82 | ||
83 | function getFeedUnread($link, $feed) { | |
84 | $n_feed = sprintf("%d", $feed); | |
85 | ||
86 | if ($n_feed == -1) { | |
87 | $match_part = "marked = true"; | |
88 | } else if ($feed > 0) { | |
89 | $match_part = "feed_id = '$n_feed'"; | |
90 | } else if ($feed < -10) { | |
91 | $label_id = -$feed - 11; | |
92 | ||
93 | $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE | |
94 | id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); | |
95 | ||
96 | $match_part = db_fetch_result($result, 0, "sql_exp"); | |
97 | } | |
98 | ||
99 | if ($match_part) { | |
100 | ||
101 | $result = db_query($link, "SELECT count(int_id) AS unread | |
102 | FROM ttrss_user_entries | |
103 | WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]); | |
104 | ||
105 | } else { | |
106 | ||
107 | $result = db_query($link, "SELECT COUNT(post_int_id) AS unread | |
108 | FROM ttrss_tags,ttrss_user_entries | |
109 | WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND | |
110 | ttrss_tags.owner_uid = " . $_SESSION["uid"]); | |
111 | } | |
112 | ||
113 | $unread = db_fetch_result($result, 0, "unread"); | |
114 | return $unread; | |
115 | } | |
116 | ||
117 | /* FIXME this needs reworking */ | |
118 | ||
119 | function getGlobalCounters($link) { | |
120 | $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries | |
121 | WHERE unread = true AND | |
122 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
123 | owner_uid = " . $_SESSION["uid"]); | |
124 | $c_id = db_fetch_result($result, 0, "c_id"); | |
125 | print "<counter type=\"global\" id='global-unread' counter='$c_id'/>"; | |
126 | } | |
127 | ||
128 | function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
129 | ||
130 | if ($smart_mode) { | |
131 | if (!$_SESSION["tctr_last_value"]) { | |
132 | $_SESSION["tctr_last_value"] = array(); | |
133 | } | |
134 | } | |
135 | ||
136 | $old_counters = $_SESSION["tctr_last_value"]; | |
137 | ||
138 | $tctrs_modified = false; | |
139 | ||
140 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
141 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
142 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
143 | ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND | |
144 | post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name | |
145 | UNION | |
146 | select tag_name,0 as count FROM ttrss_tags | |
147 | WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */ | |
148 | ||
149 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) | |
150 | FROM ttrss_user_entries WHERE int_id = post_int_id | |
151 | AND unread = true)) AS count FROM ttrss_tags | |
152 | WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name"); | |
153 | ||
154 | $tags = array(); | |
155 | ||
156 | while ($line = db_fetch_assoc($result)) { | |
157 | $tags[$line["tag_name"]] += $line["count"]; | |
158 | } | |
159 | ||
160 | foreach (array_keys($tags) as $tag) { | |
161 | $unread = $tags[$tag]; | |
162 | ||
163 | $tag = htmlspecialchars($tag); | |
164 | ||
165 | if (!$smart_mode || $old_counters[$tag] != $unread) { | |
166 | $old_counters[$tag] = $unread; | |
167 | $tctrs_modified = true; | |
168 | print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>"; | |
169 | } | |
170 | ||
171 | } | |
172 | ||
173 | if ($smart_mode && $tctrs_modified) { | |
174 | $_SESSION["tctr_last_value"] = $old_counters; | |
175 | } | |
176 | ||
177 | } | |
178 | ||
179 | function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
180 | ||
181 | if ($smart_mode) { | |
182 | if (!$_SESSION["lctr_last_value"]) { | |
183 | $_SESSION["lctr_last_value"] = array(); | |
184 | } | |
185 | } | |
186 | ||
187 | $old_counters = $_SESSION["lctr_last_value"]; | |
188 | $lctrs_modified = false; | |
189 | ||
190 | $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries | |
191 | WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND | |
192 | unread = true AND owner_uid = ".$_SESSION["uid"]); | |
193 | ||
194 | $count = db_fetch_result($result, 0, "count"); | |
195 | ||
196 | print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>"; | |
197 | ||
198 | $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM | |
199 | ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); | |
200 | ||
201 | while ($line = db_fetch_assoc($result)) { | |
202 | ||
203 | $id = -$line["id"] - 11; | |
204 | ||
205 | error_reporting (0); | |
206 | ||
207 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries | |
208 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND | |
209 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
210 | owner_uid = ".$_SESSION["uid"]); | |
211 | ||
212 | $count = db_fetch_result($tmp_result, 0, "count"); | |
213 | ||
214 | if (!$smart_mode || $old_counters[$id] != $count) { | |
215 | $old_counters[$id] = $count; | |
216 | $lctrs_modified = true; | |
217 | print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>"; | |
218 | } | |
219 | ||
220 | error_reporting (DEFAULT_ERROR_LEVEL); | |
221 | } | |
222 | ||
223 | if ($smart_mode && $lctrs_modified) { | |
224 | $_SESSION["lctr_last_value"] = $old_counters; | |
225 | } | |
226 | } | |
227 | ||
228 | function getFeedCounter($link, $id) { | |
229 | ||
230 | $result = db_query($link, "SELECT | |
231 | count(id) as count,last_error | |
232 | FROM ttrss_entries,ttrss_user_entries,ttrss_feeds | |
233 | WHERE feed_id = '$id' AND unread = true | |
234 | AND ttrss_user_entries.feed_id = ttrss_feeds.id | |
235 | AND ttrss_user_entries.ref_id = ttrss_entries.id"); | |
236 | ||
237 | $count = db_fetch_result($result, 0, "count"); | |
238 | $last_error = db_fetch_result($result, 0, "last_error"); | |
239 | ||
240 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>"; | |
241 | } | |
242 | ||
243 | function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
244 | ||
245 | if ($smart_mode) { | |
246 | if (!$_SESSION["fctr_last_value"]) { | |
247 | $_SESSION["fctr_last_value"] = array(); | |
248 | } | |
249 | } | |
250 | ||
251 | $old_counters = $_SESSION["fctr_last_value"]; | |
252 | ||
253 | $result = db_query($link, "SELECT id,last_error, | |
254 | (SELECT count(id) | |
255 | FROM ttrss_entries,ttrss_user_entries | |
256 | WHERE feed_id = ttrss_feeds.id AND | |
257 | ttrss_user_entries.ref_id = ttrss_entries.id | |
258 | AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count | |
259 | FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); | |
260 | ||
261 | $fctrs_modified = false; | |
262 | ||
263 | while ($line = db_fetch_assoc($result)) { | |
264 | ||
265 | $id = $line["id"]; | |
266 | $count = $line["count"]; | |
267 | $last_error = $line["last_error"]; | |
268 | ||
269 | $has_img = is_file(ICONS_DIR . "/$id.ico"); | |
270 | ||
271 | if (!$smart_mode || $old_counters[$id] != $count) { | |
272 | $old_counters[$id] = $count; | |
273 | $fctrs_modified = true; | |
274 | ||
275 | if ($last_error) { | |
276 | $error_part = "error=\"$last_error\""; | |
277 | } else { | |
278 | $error_part = ""; | |
279 | } | |
280 | ||
281 | if ($has_img) { | |
282 | $has_img_part = "hi=\"$has_img\""; | |
283 | } else { | |
284 | $has_img_part = ""; | |
285 | } | |
286 | ||
287 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part/>"; | |
288 | } | |
289 | } | |
290 | ||
291 | if ($smart_mode && $fctrs_modified) { | |
292 | $_SESSION["fctr_last_value"] = $old_counters; | |
293 | } | |
294 | } | |
295 | ||
296 | function outputFeedList($link, $tags = false) { | |
297 | ||
298 | print "<html><head> | |
299 | <title>Tiny Tiny RSS : Feedlist</title> | |
300 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; | |
301 | ||
302 | $user_theme = $_SESSION["theme"]; | |
303 | if ($user_theme) { | |
304 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
305 | href=\"themes/$user_theme/theme.css\">"; | |
306 | } | |
307 | ||
308 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { | |
309 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
310 | href=\"tt-rss_compact.css\"/>"; | |
311 | } else { | |
312 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
313 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
314 | } | |
315 | ||
316 | print "<script type=\"text/javascript\" src=\"functions.js\"></script> | |
317 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> | |
318 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
319 | </head><body onload=\"init()\">"; | |
320 | ||
321 | print "<ul class=\"feedList\" id=\"feedList\">"; | |
322 | ||
323 | $owner_uid = $_SESSION["uid"]; | |
324 | ||
325 | if (!$tags) { | |
326 | ||
327 | /* virtual feeds */ | |
328 | ||
329 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
330 | print "<li class=\"feedCat\">Special</li>"; | |
331 | print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; | |
332 | } | |
333 | ||
334 | $result = db_query($link, "SELECT count(id) as num_starred | |
335 | FROM ttrss_entries,ttrss_user_entries | |
336 | WHERE marked = true AND | |
337 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
338 | unread = true AND owner_uid = '$owner_uid'"); | |
339 | $num_starred = db_fetch_result($result, 0, "num_starred"); | |
340 | ||
341 | $class = "virt"; | |
342 | ||
343 | if ($num_starred > 0) $class .= "Unread"; | |
344 | ||
345 | printFeedEntry(-1, $class, "Starred articles", $num_starred, | |
346 | "images/mark_set.png", $link); | |
347 | ||
348 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
349 | print "</li></ul>"; | |
350 | } | |
351 | ||
352 | if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) { | |
353 | ||
354 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
355 | ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); | |
356 | ||
357 | if (db_num_rows($result) > 0) { | |
358 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
359 | print "<li class=\"feedCat\">Labels</li>"; | |
360 | print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; | |
361 | } else { | |
362 | print "<li><hr></li>"; | |
363 | } | |
364 | } | |
365 | ||
366 | while ($line = db_fetch_assoc($result)) { | |
367 | ||
368 | error_reporting (0); | |
369 | ||
370 | $tmp_result = db_query($link, "SELECT count(id) as count | |
371 | FROM ttrss_entries,ttrss_user_entries | |
372 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND | |
373 | ttrss_user_entries.ref_id = ttrss_entries.id | |
374 | AND owner_uid = '$owner_uid'"); | |
375 | ||
376 | $count = db_fetch_result($tmp_result, 0, "count"); | |
377 | ||
378 | $class = "label"; | |
379 | ||
380 | if ($count > 0) { | |
381 | $class .= "Unread"; | |
382 | } | |
383 | ||
384 | error_reporting (DEFAULT_ERROR_LEVEL); | |
385 | ||
386 | printFeedEntry(-$line["id"]-11, | |
387 | $class, $line["description"], $count, "images/label.png", $link); | |
388 | ||
389 | } | |
390 | ||
391 | if (db_num_rows($result) > 0) { | |
392 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
393 | print "</li></ul>"; | |
394 | } | |
395 | } | |
396 | ||
397 | } | |
398 | ||
399 | // if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
400 | print "<li><hr></li>"; | |
401 | // } | |
402 | ||
403 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
404 | $order_by_qpart = "category,title"; | |
405 | } else { | |
406 | $order_by_qpart = "title"; | |
407 | } | |
408 | ||
409 | $result = db_query($link, "SELECT *, | |
410 | (SELECT count(id) FROM ttrss_entries,ttrss_user_entries | |
411 | WHERE feed_id = ttrss_feeds.id AND | |
412 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
413 | owner_uid = '$owner_uid') AS total, | |
414 | (SELECT count(id) FROM ttrss_entries,ttrss_user_entries | |
415 | WHERE feed_id = ttrss_feeds.id AND unread = true | |
416 | AND ttrss_user_entries.ref_id = ttrss_entries.id | |
417 | AND owner_uid = '$owner_uid') as unread, | |
418 | (SELECT title FROM ttrss_feed_categories | |
419 | WHERE id = cat_id) AS category, | |
420 | cat_id,last_error, | |
421 | (SELECT collapsed FROM ttrss_feed_categories | |
422 | WHERE id = cat_id) AS collapsed | |
423 | FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart"); | |
424 | ||
425 | $actid = $_GET["actid"]; | |
426 | ||
427 | /* real feeds */ | |
428 | ||
429 | $lnum = 0; | |
430 | ||
431 | $total_unread = 0; | |
432 | ||
433 | $category = ""; | |
434 | ||
435 | while ($line = db_fetch_assoc($result)) { | |
436 | ||
437 | $feed = db_unescape_string($line["title"]); | |
438 | $feed_id = $line["id"]; | |
439 | ||
440 | $subop = $_GET["subop"]; | |
441 | ||
442 | $total = $line["total"]; | |
443 | $unread = $line["unread"]; | |
444 | ||
445 | $cat_id = $line["cat_id"]; | |
446 | ||
447 | $tmp_category = $line["category"]; | |
448 | ||
449 | if (!$tmp_category) { | |
450 | $tmp_category = "Uncategorized"; | |
451 | } | |
452 | ||
453 | // $class = ($lnum % 2) ? "even" : "odd"; | |
454 | ||
455 | if ($line["last_error"]) { | |
456 | $class = "error"; | |
457 | } else { | |
458 | $class = "feed"; | |
459 | } | |
460 | ||
461 | if ($unread > 0) $class .= "Unread"; | |
462 | ||
463 | if ($actid == $feed_id) { | |
464 | $class .= "Selected"; | |
465 | } | |
466 | ||
467 | $total_unread += $unread; | |
468 | ||
469 | if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) { | |
470 | ||
471 | if ($category) { | |
472 | print "</li></ul></li>"; | |
473 | } | |
474 | ||
475 | $category = $tmp_category; | |
476 | ||
477 | $collapsed = $line["collapsed"]; | |
478 | ||
479 | // workaround for NULL category | |
480 | if ($category == "Uncategorized") { | |
481 | if ($_COOKIE["ttrss_vf_uclps"] == 1) { | |
482 | $collapsed = "t"; | |
483 | } | |
484 | } | |
485 | ||
486 | if ($collapsed == "t" || $collapsed == "1") { | |
487 | $holder_class = "invisible"; | |
488 | $ellipsis = "..."; | |
489 | } else { | |
490 | $holder_class = ""; | |
491 | $ellipsis = ""; | |
492 | } | |
493 | ||
494 | if ($cat_id) { | |
495 | $cat_id_qpart = "cat_id = '$cat_id'"; | |
496 | } else { | |
497 | $cat_id_qpart = "cat_id IS NULL"; | |
498 | } | |
499 | ||
500 | $tmp_result = db_query($link, "SELECT count(int_id) AS unread | |
501 | FROM ttrss_user_entries,ttrss_feeds WHERE | |
502 | unread = true AND | |
503 | feed_id = ttrss_feeds.id AND $cat_id_qpart AND | |
504 | ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); | |
505 | ||
506 | $cat_unread = db_fetch_result($tmp_result, 0, "unread"); | |
507 | ||
508 | $cat_id = sprintf("%d", $cat_id); | |
509 | ||
510 | print "<li class=\"feedCat\" id=\"FCAT-$cat_id\"> | |
511 | <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category | |
512 | <span id=\"FCATCTR-$cat_id\" | |
513 | class=\"$catctr_class\">($cat_unread unread)$ellipsis</span></a></li>"; | |
514 | ||
515 | // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function | |
516 | // -> keyboard navigation, etc. | |
517 | print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\">"; | |
518 | } | |
519 | ||
520 | printFeedEntry($feed_id, $class, $feed, $unread, | |
521 | "icons/$feed_id.ico", $link); | |
522 | ||
523 | ++$lnum; | |
524 | } | |
525 | ||
526 | } else { | |
527 | ||
528 | // tags | |
529 | ||
530 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
531 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
532 | post_int_id = ttrss_user_entries.int_id AND | |
533 | unread = true AND ref_id = ttrss_entries.id | |
534 | AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name | |
535 | UNION | |
536 | select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid' | |
537 | ORDER BY tag_name"); */ | |
538 | ||
539 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) | |
540 | FROM ttrss_user_entries WHERE int_id = post_int_id | |
541 | AND unread = true)) AS count FROM ttrss_tags | |
542 | WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name"); | |
543 | ||
544 | $tags = array(); | |
545 | ||
546 | while ($line = db_fetch_assoc($result)) { | |
547 | $tags[$line["tag_name"]] += $line["count"]; | |
548 | } | |
549 | ||
550 | foreach (array_keys($tags) as $tag) { | |
551 | ||
552 | $unread = $tags[$tag]; | |
553 | ||
554 | $class = "tag"; | |
555 | ||
556 | if ($unread > 0) { | |
557 | $class .= "Unread"; | |
558 | } | |
559 | ||
560 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); | |
561 | ||
562 | } | |
563 | ||
564 | } | |
565 | ||
566 | if (db_num_rows($result) == 0) { | |
567 | if ($tags) { | |
568 | $what = "tags"; | |
569 | } else { | |
570 | $what = "feeds"; | |
571 | } | |
572 | print "<li>No $what to display.</li>"; | |
573 | } | |
574 | ||
575 | print "</ul>"; | |
576 | ||
577 | } | |
578 | ||
579 | ||
580 | if ($op == "rpc") { | |
581 | ||
582 | $subop = $_GET["subop"]; | |
583 | ||
584 | if ($subop == "getLabelCounters") { | |
585 | $aid = $_GET["aid"]; | |
586 | print "<rpc-reply>"; | |
587 | getLabelCounters($link); | |
588 | if ($aid) { | |
589 | getFeedCounter($link, $aid); | |
590 | } | |
591 | print "</rpc-reply>"; | |
592 | } | |
593 | ||
594 | if ($subop == "getFeedCounters") { | |
595 | print "<rpc-reply>"; | |
596 | getFeedCounters($link); | |
597 | print "</rpc-reply>"; | |
598 | } | |
599 | ||
600 | if ($subop == "getAllCounters") { | |
601 | print "<rpc-reply>"; | |
602 | getAllCounters($link); | |
603 | print "</rpc-reply>"; | |
604 | } | |
605 | ||
606 | if ($subop == "mark") { | |
607 | $mark = $_GET["mark"]; | |
608 | $id = db_escape_string($_GET["id"]); | |
609 | ||
610 | if ($mark == "1") { | |
611 | $mark = "true"; | |
612 | } else { | |
613 | $mark = "false"; | |
614 | } | |
615 | ||
616 | // FIXME this needs collision testing | |
617 | ||
618 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
619 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
620 | } | |
621 | ||
622 | if ($subop == "updateFeed") { | |
623 | $feed_id = db_escape_string($_GET["feed"]); | |
624 | ||
625 | $result = db_query($link, | |
626 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id' | |
627 | AND owner_uid = " . $_SESSION["uid"]); | |
628 | ||
629 | if (db_num_rows($result) > 0) { | |
630 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
631 | update_rss_feed($link, $feed_url, $feed_id); | |
632 | } | |
633 | ||
634 | print "<rpc-reply>"; | |
635 | getFeedCounter($link, $feed_id); | |
636 | print "</rpc-reply>"; | |
637 | ||
638 | return; | |
639 | } | |
640 | ||
641 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { | |
642 | ||
643 | update_all_feeds($link, $subop == "forceUpdateAllFeeds"); | |
644 | ||
645 | $omode = $_GET["omode"]; | |
646 | ||
647 | if (!$omode) $omode = "tfl"; | |
648 | ||
649 | print "<rpc-reply>"; | |
650 | if (strchr($omode, "l")) getLabelCounters($link); | |
651 | if (strchr($omode, "f")) getFeedCounters($link); | |
652 | if (strchr($omode, "t")) getTagCounters($link); | |
653 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
654 | getCategoryCounters($link); | |
655 | } | |
656 | getGlobalCounters($link); | |
657 | print "</rpc-reply>"; | |
658 | } | |
659 | ||
660 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ | |
661 | if ($subop == "catchupSelected") { | |
662 | ||
663 | $ids = split(",", db_escape_string($_GET["ids"])); | |
664 | ||
665 | $cmode = sprintf("%d", $_GET["cmode"]); | |
666 | ||
667 | foreach ($ids as $id) { | |
668 | ||
669 | if ($cmode == 0) { | |
670 | db_query($link, "UPDATE ttrss_user_entries SET | |
671 | unread = false,last_read = NOW() | |
672 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
673 | } else if ($cmode == 1) { | |
674 | db_query($link, "UPDATE ttrss_user_entries SET | |
675 | unread = true | |
676 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
677 | } else { | |
678 | db_query($link, "UPDATE ttrss_user_entries SET | |
679 | unread = NOT unread,last_read = NOW() | |
680 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
681 | } | |
682 | } | |
683 | print "<rpc-reply>"; | |
684 | getAllCounters($link); | |
685 | print "</rpc-reply>"; | |
686 | } | |
687 | ||
688 | if ($subop == "markSelected") { | |
689 | ||
690 | $ids = split(",", db_escape_string($_GET["ids"])); | |
691 | ||
692 | $cmode = sprintf("%d", $_GET["cmode"]); | |
693 | ||
694 | foreach ($ids as $id) { | |
695 | ||
696 | if ($cmode == 0) { | |
697 | db_query($link, "UPDATE ttrss_user_entries SET | |
698 | marked = false | |
699 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
700 | } else if ($cmode == 1) { | |
701 | db_query($link, "UPDATE ttrss_user_entries SET | |
702 | marked = true | |
703 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
704 | } else { | |
705 | db_query($link, "UPDATE ttrss_user_entries SET | |
706 | marked = NOT marked | |
707 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
708 | } | |
709 | } | |
710 | print "<rpc-reply>"; | |
711 | getAllCounters($link); | |
712 | print "</rpc-reply>"; | |
713 | } | |
714 | ||
715 | if ($subop == "sanityCheck") { | |
716 | ||
717 | $error_code = 0; | |
718 | ||
719 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
720 | ||
721 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
722 | ||
723 | if ($schema_version != SCHEMA_VERSION) { | |
724 | $error_code = 5; | |
725 | } | |
726 | ||
727 | print "<error error-code='$error_code'/>"; | |
728 | } | |
729 | ||
730 | if ($subop == "globalPurge") { | |
731 | ||
732 | print "<rpc-reply>"; | |
733 | global_purge_old_posts($link, true); | |
734 | print "</rpc-reply>"; | |
735 | ||
736 | } | |
737 | ||
738 | } | |
739 | ||
740 | if ($op == "feeds") { | |
741 | ||
742 | $tags = $_GET["tags"]; | |
743 | ||
744 | $subop = $_GET["subop"]; | |
745 | ||
746 | if ($subop == "catchupAll") { | |
747 | db_query($link, "UPDATE ttrss_user_entries SET | |
748 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); | |
749 | } | |
750 | ||
751 | if ($subop == "collapse") { | |
752 | $cat_id = db_escape_string($_GET["cid"]); | |
753 | ||
754 | db_query($link, "UPDATE ttrss_feed_categories SET | |
755 | collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " . | |
756 | $_SESSION["uid"]); | |
757 | return; | |
758 | } | |
759 | ||
760 | outputFeedList($link, $tags); | |
761 | ||
762 | } | |
763 | ||
764 | if ($op == "view") { | |
765 | ||
766 | $id = $_GET["id"]; | |
767 | $feed_id = $_GET["feed"]; | |
768 | ||
769 | $result = db_query($link, "UPDATE ttrss_user_entries | |
770 | SET unread = false,last_read = NOW() | |
771 | WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
772 | ||
773 | $addheader = $_GET["addheader"]; | |
774 | ||
775 | $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id, | |
776 | SUBSTRING(updated,1,16) as updated, | |
777 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url, | |
778 | num_comments | |
779 | FROM ttrss_entries,ttrss_user_entries | |
780 | WHERE id = '$id' AND ref_id = id"); | |
781 | ||
782 | if ($addheader) { | |
783 | print "<html><head> | |
784 | <title>Tiny Tiny RSS : Article $id</title> | |
785 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; | |
786 | ||
787 | $user_theme = $_SESSION["theme"]; | |
788 | if ($user_theme) { | |
789 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
790 | href=\"themes/$user_theme/theme.css\">"; | |
791 | } | |
792 | ||
793 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { | |
794 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
795 | href=\"tt-rss_compact.css\"/>"; | |
796 | } else { | |
797 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
798 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
799 | } | |
800 | ||
801 | print "<script type=\"text/javascript\" src=\"functions.js\"></script> | |
802 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
803 | </head><body>"; | |
804 | } | |
805 | ||
806 | if ($result) { | |
807 | ||
808 | $line = db_fetch_assoc($result); | |
809 | ||
810 | if ($line["icon_url"]) { | |
811 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
812 | } else { | |
813 | $feed_icon = " "; | |
814 | } | |
815 | ||
816 | /* if ($line["comments"] && $line["link"] != $line["comments"]) { | |
817 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
818 | } else { | |
819 | $entry_comments = ""; | |
820 | } */ | |
821 | ||
822 | $num_comments = $line["num_comments"]; | |
823 | $entry_comments = ""; | |
824 | ||
825 | if ($num_comments > 0) { | |
826 | if ($line["comments"]) { | |
827 | $comments_url = $line["comments"]; | |
828 | } else { | |
829 | $comments_url = $line["link"]; | |
830 | } | |
831 | $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>"; | |
832 | } else { | |
833 | if ($line["comments"] && $line["link"] != $line["comments"]) { | |
834 | $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>"; | |
835 | } | |
836 | } | |
837 | ||
838 | print "<div class=\"postReply\">"; | |
839 | ||
840 | print "<div class=\"postHeader\"><table width=\"100%\">"; | |
841 | ||
842 | print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] . "</a></td>"; | |
843 | ||
844 | $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
845 | strtotime($line["updated"])); | |
846 | ||
847 | print "<td class=\"postDate\">$parsed_updated</td>"; | |
848 | ||
849 | print "</tr>"; | |
850 | ||
851 | $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM | |
852 | ttrss_tags WHERE post_int_id = " . $line["int_id"] . " | |
853 | ORDER BY tag_name"); | |
854 | ||
855 | $tags_str = ""; | |
856 | $f_tags_str = ""; | |
857 | ||
858 | $num_tags = 0; | |
859 | ||
860 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
861 | $num_tags++; | |
862 | $tag = $tmp_line["tag_name"]; | |
863 | $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, "; | |
864 | ||
865 | if ($num_tags == 5) { | |
866 | $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>"; | |
867 | } else if ($num_tags < 5) { | |
868 | $tags_str .= $tag_str; | |
869 | } | |
870 | $f_tags_str .= $tag_str; | |
871 | } | |
872 | ||
873 | $tags_str = preg_replace("/, $/", "", $tags_str); | |
874 | $f_tags_str = preg_replace("/, $/", "", $f_tags_str); | |
875 | ||
876 | // $truncated_link = truncate_string($line["link"], 60); | |
877 | ||
878 | if ($tags_str || $entry_comments) { | |
879 | print "<tr><td width='50%'> | |
880 | $entry_comments</td> | |
881 | <td align=\"right\">$tags_str</td></tr>"; | |
882 | } | |
883 | ||
884 | print "</table></div>"; | |
885 | ||
886 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
887 | print "<div class=\"postContent\">"; | |
888 | ||
889 | if (db_num_rows($tmp_result) > 5) { | |
890 | print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>"; | |
891 | } | |
892 | ||
893 | print $line["content"] . "</div>"; | |
894 | ||
895 | print "</div>"; | |
896 | ||
897 | print "<script type=\"text/javascript\"> | |
898 | update_all_counters('$feed_id'); | |
899 | </script>"; | |
900 | } | |
901 | ||
902 | if ($addheader) { | |
903 | print "</body></html>"; | |
904 | } | |
905 | } | |
906 | ||
907 | if ($op == "viewfeed") { | |
908 | ||
909 | $feed = $_GET["feed"]; | |
910 | $skip = $_GET["skip"]; | |
911 | $subop = $_GET["subop"]; | |
912 | $view_mode = $_GET["view"]; | |
913 | $addheader = $_GET["addheader"]; | |
914 | $limit = $_GET["limit"]; | |
915 | ||
916 | if (!$feed) { | |
917 | return; | |
918 | } | |
919 | ||
920 | if (!$skip) $skip = 0; | |
921 | ||
922 | if ($subop == "undefined") $subop = ""; | |
923 | ||
924 | if ($addheader) { | |
925 | print "<html><head> | |
926 | <title>Tiny Tiny RSS : Feed $feed</title> | |
927 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; | |
928 | ||
929 | $user_theme = $_SESSION["theme"]; | |
930 | if ($user_theme) { | |
931 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
932 | href=\"themes/$user_theme/theme.css\">"; | |
933 | } | |
934 | ||
935 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { | |
936 | print "<link rel=\"stylesheet\" | |
937 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
938 | ||
939 | } else { | |
940 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
941 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
942 | } | |
943 | ||
944 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
945 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
946 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
947 | </head><body onload='init()'>"; | |
948 | } | |
949 | ||
950 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { | |
951 | ||
952 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
953 | WHERE id = '$feed'"); | |
954 | ||
955 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
956 | ||
957 | update_rss_feed($link, $feed_url, $feed); | |
958 | ||
959 | } | |
960 | ||
961 | if ($subop == "MarkAllRead") { | |
962 | ||
963 | if (sprintf("%d", $feed) != 0) { | |
964 | ||
965 | if ($feed > 0) { | |
966 | db_query($link, "UPDATE ttrss_user_entries | |
967 | SET unread = false,last_read = NOW() | |
968 | WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
969 | ||
970 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
971 | ||
972 | if ($feed == -1) { | |
973 | db_query($link, "UPDATE ttrss_user_entries | |
974 | SET unread = false,last_read = NOW() | |
975 | WHERE marked = true AND owner_uid = ".$_SESSION["uid"]); | |
976 | } | |
977 | ||
978 | } else if ($feed < -10) { // label | |
979 | ||
980 | // TODO make this more efficient | |
981 | ||
982 | $label_id = -$feed - 11; | |
983 | ||
984 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
985 | WHERE id = '$label_id'"); | |
986 | ||
987 | if ($tmp_result) { | |
988 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
989 | ||
990 | db_query($link, "BEGIN"); | |
991 | ||
992 | $tmp2_result = db_query($link, | |
993 | "SELECT | |
994 | int_id | |
995 | FROM | |
996 | ttrss_user_entries,ttrss_entries | |
997 | WHERE | |
998 | ref_id = id AND | |
999 | $sql_exp AND | |
1000 | owner_uid = " . $_SESSION["uid"]); | |
1001 | ||
1002 | while ($tmp_line = db_fetch_assoc($tmp2_result)) { | |
1003 | db_query($link, "UPDATE | |
1004 | ttrss_user_entries | |
1005 | SET | |
1006 | unread = false, last_read = NOW() | |
1007 | WHERE | |
1008 | int_id = " . $tmp_line["int_id"]); | |
1009 | } | |
1010 | ||
1011 | db_query($link, "COMMIT"); | |
1012 | ||
1013 | /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries | |
1014 | SET unread = false,last_read = NOW() | |
1015 | WHERE $sql_exp | |
1016 | AND ref_id = id | |
1017 | AND owner_uid = ".$_SESSION["uid"]); */ | |
1018 | } | |
1019 | } | |
1020 | } else { // tag | |
1021 | db_query($link, "BEGIN"); | |
1022 | ||
1023 | $tag_name = db_escape_string($feed); | |
1024 | ||
1025 | $result = db_query($link, "SELECT post_int_id FROM ttrss_tags | |
1026 | WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]); | |
1027 | ||
1028 | while ($line = db_fetch_assoc($result)) { | |
1029 | db_query($link, "UPDATE ttrss_user_entries SET | |
1030 | unread = false, last_read = NOW() | |
1031 | WHERE int_id = " . $line["post_int_id"]); | |
1032 | } | |
1033 | db_query($link, "COMMIT"); | |
1034 | } | |
1035 | ||
1036 | } | |
1037 | ||
1038 | $search = db_escape_string($_GET["search"]); | |
1039 | $search_mode = db_escape_string($_GET["smode"]); | |
1040 | ||
1041 | if ($search) { | |
1042 | $search_query_part = "(upper(title) LIKE upper('%$search%') | |
1043 | OR content LIKE '%$search%') AND"; | |
1044 | } else { | |
1045 | $search_query_part = ""; | |
1046 | } | |
1047 | ||
1048 | $view_query_part = ""; | |
1049 | ||
1050 | if ($view_mode == "Adaptive") { | |
1051 | if ($feed != -1) { | |
1052 | $unread = getFeedUnread($link, $feed); | |
1053 | if ($unread > 0) { | |
1054 | $view_query_part = " unread = true AND "; | |
1055 | } | |
1056 | } | |
1057 | } | |
1058 | ||
1059 | if ($view_mode == "Starred") { | |
1060 | $view_query_part = " marked = true AND "; | |
1061 | } | |
1062 | ||
1063 | if ($view_mode == "Unread") { | |
1064 | $view_query_part = " unread = true AND "; | |
1065 | } | |
1066 | ||
1067 | /* if ($view_mode == "Unread or Starred") { | |
1068 | $view_query_part = " (unread = true OR marked = true) AND "; | |
1069 | } | |
1070 | ||
1071 | if ($view_mode == "Unread or Updated") { | |
1072 | $view_query_part = " (unread = true OR last_read is NULL) AND "; | |
1073 | } */ | |
1074 | ||
1075 | /* $result = db_query($link, "SELECT count(id) AS total_entries | |
1076 | FROM ttrss_entries WHERE | |
1077 | $search_query_part | |
1078 | feed_id = '$feed'"); | |
1079 | ||
1080 | $total_entries = db_fetch_result($result, 0, "total_entries"); */ | |
1081 | ||
1082 | /* $result = db_query("SELECT count(id) AS unread_entries | |
1083 | FROM ttrss_entries WHERE | |
1084 | $search_query_part | |
1085 | unread = true AND | |
1086 | feed_id = '$feed'"); | |
1087 | ||
1088 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ | |
1089 | ||
1090 | if ($limit && $limit != "All") { | |
1091 | $limit_query_part = "LIMIT " . $limit; | |
1092 | } | |
1093 | ||
1094 | $vfeed_query_part = ""; | |
1095 | ||
1096 | // override query strategy and enable feed display when searching globally | |
1097 | if ($search && $search_mode == "All feeds") { | |
1098 | $query_strategy_part = "id > 0"; | |
1099 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
1100 | id = feed_id) as feed_title,"; | |
1101 | } else if (sprintf("%d", $feed) == 0) { | |
1102 | $query_strategy_part = "ttrss_entries.id > 0"; | |
1103 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
1104 | id = feed_id) as feed_title,"; | |
1105 | } else if ($feed >= 0) { | |
1106 | $query_strategy_part = "feed_id = '$feed'"; | |
1107 | } else if ($feed == -1) { // starred virtual feed | |
1108 | $query_strategy_part = "marked = true"; | |
1109 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
1110 | id = feed_id) as feed_title,"; | |
1111 | } else if ($feed <= -10) { // labels | |
1112 | $label_id = -$feed - 11; | |
1113 | ||
1114 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
1115 | WHERE id = '$label_id'"); | |
1116 | ||
1117 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
1118 | ||
1119 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
1120 | id = feed_id) as feed_title,"; | |
1121 | } else { | |
1122 | $query_strategy_part = "id > 0"; // dumb | |
1123 | } | |
1124 | ||
1125 | $order_by = "updated DESC"; | |
1126 | ||
1127 | // if ($feed < -10) { | |
1128 | // $order_by = "feed_id,updated DESC"; | |
1129 | // } | |
1130 | ||
1131 | $feed_title = ""; | |
1132 | ||
1133 | if ($search && $search_mode == "All feeds") { | |
1134 | $feed_title = "Search results"; | |
1135 | } else if (sprintf("%d", $feed) == 0) { | |
1136 | $feed_title = $feed; | |
1137 | } else if ($feed > 0) { | |
1138 | $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds | |
1139 | WHERE id = '$feed'"); | |
1140 | ||
1141 | $feed_title = db_fetch_result($result, 0, "title"); | |
1142 | $feed_site_url = db_fetch_result($result, 0, "site_url"); | |
1143 | $last_error = db_fetch_result($result, 0, "last_error"); | |
1144 | ||
1145 | } else if ($feed == -1) { | |
1146 | $feed_title = "Starred articles"; | |
1147 | } else if ($feed < -10) { | |
1148 | $label_id = -$feed - 11; | |
1149 | $result = db_query($link, "SELECT description FROM ttrss_labels | |
1150 | WHERE id = '$label_id'"); | |
1151 | $feed_title = db_fetch_result($result, 0, "description"); | |
1152 | } else { | |
1153 | $feed_title = "?"; | |
1154 | } | |
1155 | ||
1156 | if ($feed < -10) error_reporting (0); | |
1157 | ||
1158 | print "<div id=\"headlinesContainer\">"; | |
1159 | ||
1160 | if (sprintf("%d", $feed) != 0) { | |
1161 | ||
1162 | if ($feed > 0) { | |
1163 | $feed_kind = "Feeds"; | |
1164 | } else { | |
1165 | $feed_kind = "Labels"; | |
1166 | } | |
1167 | ||
1168 | // if (!$vfeed_query_part) { | |
1169 | $content_query_part = "content as content_preview,"; | |
1170 | // } else { | |
1171 | // $content_query_part = ""; | |
1172 | // } | |
1173 | ||
1174 | $result = db_query($link, "SELECT | |
1175 | id,title, | |
1176 | SUBSTRING(updated,1,16) as updated, | |
1177 | unread,feed_id,marked,link,last_read, | |
1178 | SUBSTRING(last_read,1,19) as last_read_noms, | |
1179 | $vfeed_query_part | |
1180 | $content_query_part | |
1181 | SUBSTRING(updated,1,19) as updated_noms | |
1182 | FROM | |
1183 | ttrss_entries,ttrss_user_entries | |
1184 | WHERE | |
1185 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
1186 | owner_uid = '".$_SESSION["uid"]."' AND | |
1187 | $search_query_part | |
1188 | $view_query_part | |
1189 | $query_strategy_part ORDER BY $order_by | |
1190 | $limit_query_part"); | |
1191 | ||
1192 | } else { | |
1193 | // browsing by tag | |
1194 | ||
1195 | $feed_kind = "Tags"; | |
1196 | ||
1197 | $result = db_query($link, "SELECT | |
1198 | ttrss_entries.id as id,title, | |
1199 | SUBSTRING(updated,1,16) as updated, | |
1200 | unread,feed_id, | |
1201 | marked,link,last_read, | |
1202 | SUBSTRING(last_read,1,19) as last_read_noms, | |
1203 | $vfeed_query_part | |
1204 | $content_query_part | |
1205 | SUBSTRING(updated,1,19) as updated_noms | |
1206 | FROM | |
1207 | ttrss_entries,ttrss_user_entries,ttrss_tags | |
1208 | WHERE | |
1209 | ref_id = ttrss_entries.id AND | |
1210 | ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND | |
1211 | post_int_id = int_id AND tag_name = '$feed' AND | |
1212 | $view_query_part | |
1213 | $search_query_part | |
1214 | $query_strategy_part ORDER BY $order_by | |
1215 | $limit_query_part"); | |
1216 | } | |
1217 | ||
1218 | if (!$result) { | |
1219 | print "<div align='center'> | |
1220 | Could not display feed (query failed). Please check label match syntax or local configuration.</div>"; | |
1221 | return; | |
1222 | } | |
1223 | ||
1224 | if (db_num_rows($result) > 0) { | |
1225 | ||
1226 | print "<table class=\"headlinesSubToolbar\" | |
1227 | width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>"; | |
1228 | ||
1229 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
1230 | ||
1231 | print "<td class=\"headlineActions\"> | |
1232 | Select: | |
1233 | <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList', | |
1234 | 'RROW-', 'RCHK-', true)\">All</a>, | |
1235 | <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList', | |
1236 | 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>, | |
1237 | <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList', | |
1238 | 'RROW-', 'RCHK-', false)\">None</a> | |
1239 | | |
1240 | Toggle: <a href=\"javascript:selectionToggleUnread()\">Unread</a>, | |
1241 | <a href=\"javascript:selectionToggleMarked()\">Starred</a>"; | |
1242 | if ($last_error) { | |
1243 | print " | |
1244 | <a class=\"warning\" href=\"javascript:alert('Could not update | |
1245 | feed: $last_error')\">Could not update this feed...</a>"; | |
1246 | } | |
1247 | print "</td>"; | |
1248 | ||
1249 | } else { | |
1250 | ||
1251 | print "<td class=\"headlineActions\"> | |
1252 | Select: | |
1253 | <a href=\"javascript:cdmSelectArticles('all')\">All</a>, | |
1254 | <a href=\"javascript:cdmSelectArticles('unread')\">Unread</a>, | |
1255 | <a href=\"javascript:cdmSelectArticles('none')\">None</a> | |
1256 | | |
1257 | Toggle: <a href=\"javascript:selectionToggleUnread(true)\">Unread</a>, | |
1258 | <a href=\"javascript:selectionToggleMarked(true)\">Starred</a>"; | |
1259 | ||
1260 | print "</td>"; | |
1261 | ||
1262 | ||
1263 | } | |
1264 | ||
1265 | print "<td class=\"headlineTitle\">"; | |
1266 | ||
1267 | if ($feed_site_url) { | |
1268 | print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>"; | |
1269 | } else { | |
1270 | print $feed_title; | |
1271 | } | |
1272 | ||
1273 | print "</td>"; | |
1274 | print "</tr></table>"; | |
1275 | ||
1276 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
1277 | print "<table class=\"headlinesList\" id=\"headlinesList\" | |
1278 | cellspacing=\"0\" width=\"100%\">"; | |
1279 | } | |
1280 | ||
1281 | $lnum = 0; | |
1282 | ||
1283 | error_reporting (DEFAULT_ERROR_LEVEL); | |
1284 | ||
1285 | $num_unread = 0; | |
1286 | ||
1287 | while ($line = db_fetch_assoc($result)) { | |
1288 | ||
1289 | $class = ($lnum % 2) ? "even" : "odd"; | |
1290 | ||
1291 | $id = $line["id"]; | |
1292 | $feed_id = $line["feed_id"]; | |
1293 | ||
1294 | if ($line["last_read"] == "" && | |
1295 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
1296 | ||
1297 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
1298 | alt=\"Updated\">"; | |
1299 | } else { | |
1300 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
1301 | alt=\"Updated\">"; | |
1302 | } | |
1303 | ||
1304 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
1305 | $class .= "Unread"; | |
1306 | ++$num_unread; | |
1307 | $is_unread = true; | |
1308 | } else { | |
1309 | $is_unread = false; | |
1310 | } | |
1311 | ||
1312 | if ($line["marked"] == "t" || $line["marked"] == "1") { | |
1313 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" | |
1314 | alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>"; | |
1315 | } else { | |
1316 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
1317 | alt=\"Set mark\" onclick='javascript:toggleMark($id)'>"; | |
1318 | } | |
1319 | ||
1320 | $content_link = "<a href=\"javascript:view($id,$feed_id);\">" . | |
1321 | $line["title"] . "</a>"; | |
1322 | ||
1323 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
1324 | $updated_fmt = smart_date_time(strtotime($line["updated"])); | |
1325 | } else { | |
1326 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
1327 | $updated_fmt = date($short_date, strtotime($line["updated"])); | |
1328 | } | |
1329 | ||
1330 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
1331 | $content_preview = truncate_string(strip_tags($line["content_preview"]), | |
1332 | 200); | |
1333 | } | |
1334 | ||
1335 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
1336 | ||
1337 | print "<tr class='$class' id='RROW-$id'>"; | |
1338 | ||
1339 | print "<td class='hlUpdatePic'>$update_pic</td>"; | |
1340 | ||
1341 | print "<td class='hlSelectRow'> | |
1342 | <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\" | |
1343 | class=\"feedCheckBox\" id=\"RCHK-$id\"> | |
1344 | </td>"; | |
1345 | ||
1346 | print "<td class='hlMarkedPic'>$marked_pic</td>"; | |
1347 | ||
1348 | if ($line["feed_title"]) { | |
1349 | print "<td class='hlContent'>$content_link</td>"; | |
1350 | print "<td class='hlFeed'> | |
1351 | <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a> </td>"; | |
1352 | } else { | |
1353 | print "<td class='hlContent' valign='middle'>"; | |
1354 | ||
1355 | print "<a href=\"javascript:view($id,$feed_id);\">" . | |
1356 | $line["title"]; | |
1357 | ||
1358 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
1359 | ||
1360 | if ($content_preview) { | |
1361 | print "<span class=\"contentPreview\"> - $content_preview</span>"; | |
1362 | } | |
1363 | } | |
1364 | ||
1365 | print "</a>"; | |
1366 | print "</td>"; | |
1367 | } | |
1368 | ||
1369 | print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>"; | |
1370 | ||
1371 | print "</tr>"; | |
1372 | ||
1373 | } else { | |
1374 | ||
1375 | if ($is_unread) { | |
1376 | $add_class = "Unread"; | |
1377 | } else { | |
1378 | $add_class = ""; | |
1379 | } | |
1380 | ||
1381 | print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">"; | |
1382 | ||
1383 | print "<div class=\"cdmHeader\">"; | |
1384 | ||
1385 | print "<div style=\"float : right\">$updated_fmt</div>"; | |
1386 | ||
1387 | print "<a href=\"".$line["link"]."\">".$line["title"]."</a>"; | |
1388 | ||
1389 | if ($line["feed_title"]) { | |
1390 | print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)"; | |
1391 | } | |
1392 | ||
1393 | print "</div>"; | |
1394 | ||
1395 | print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>"; | |
1396 | ||
1397 | print "<div style=\"float : right\">$marked_pic</div> | |
1398 | <div class=\"cdmFooter\"> | |
1399 | <input type=\"checkbox\" onclick=\"toggleSelectRowById(this, | |
1400 | 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>"; | |
1401 | ||
1402 | print "</div>"; | |
1403 | ||
1404 | } | |
1405 | ||
1406 | ++$lnum; | |
1407 | } | |
1408 | ||
1409 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
1410 | print "</table>"; | |
1411 | } | |
1412 | ||
1413 | } else { | |
1414 | print "<div width='100%' align='center'>No articles found.</div>"; | |
1415 | } | |
1416 | ||
1417 | print "</div>"; | |
1418 | ||
1419 | print "<script type=\"text/javascript\"> | |
1420 | document.onkeydown = hotkey_handler; | |
1421 | update_all_counters('$feed'); | |
1422 | </script>"; | |
1423 | ||
1424 | if ($addheader) { | |
1425 | print "</body></html>"; | |
1426 | } | |
1427 | } | |
1428 | ||
1429 | if ($op == "pref-rpc") { | |
1430 | ||
1431 | $subop = $_GET["subop"]; | |
1432 | ||
1433 | if ($subop == "unread") { | |
1434 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1435 | foreach ($ids as $id) { | |
1436 | db_query($link, "UPDATE ttrss_user_entries SET unread = true | |
1437 | WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
1438 | } | |
1439 | ||
1440 | print "Marked selected feeds as unread."; | |
1441 | } | |
1442 | ||
1443 | if ($subop == "read") { | |
1444 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1445 | foreach ($ids as $id) { | |
1446 | db_query($link, "UPDATE ttrss_user_entries | |
1447 | SET unread = false,last_read = NOW() WHERE | |
1448 | feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
1449 | } | |
1450 | ||
1451 | print "Marked selected feeds as read."; | |
1452 | ||
1453 | } | |
1454 | ||
1455 | } | |
1456 | ||
1457 | if ($op == "pref-feeds") { | |
1458 | ||
1459 | $subop = $_REQUEST["subop"]; | |
1460 | $quiet = $_REQUEST["quiet"]; | |
1461 | ||
1462 | if ($subop == "editfeed") { | |
1463 | $feed_id = db_escape_string($_GET["id"]); | |
1464 | ||
1465 | $result = db_query($link, | |
1466 | "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND | |
1467 | owner_uid = " . $_SESSION["uid"]); | |
1468 | ||
1469 | $title = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
1470 | 0, "title"))); | |
1471 | ||
1472 | print "<div class=\"infoBoxContents\">"; | |
1473 | ||
1474 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
1475 | ||
1476 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1477 | $feed_icon = "<img width=\"16\" height=\"16\" | |
1478 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
1479 | } else { | |
1480 | $feed_icon = ""; | |
1481 | } | |
1482 | ||
1483 | print "<h1>$feed_icon $title</h1>"; | |
1484 | ||
1485 | print "<table width='100%'>"; | |
1486 | ||
1487 | $row_class = "odd"; | |
1488 | ||
1489 | print "<tr class='$row_class'><td>Title:</td>"; | |
1490 | print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>"; | |
1491 | ||
1492 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
1493 | $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
1494 | 0, "feed_url"))); | |
1495 | $row_class = toggleEvenOdd($row_class); | |
1496 | ||
1497 | print "<tr class='$row_class'><td>Feed URL:</td>"; | |
1498 | print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>"; | |
1499 | ||
1500 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1501 | ||
1502 | $cat_id = db_fetch_result($result, 0, "cat_id"); | |
1503 | ||
1504 | $row_class = toggleEvenOdd($row_class); | |
1505 | ||
1506 | print "<tr class='$row_class'><td>Category:</td>"; | |
1507 | print "<td>"; | |
1508 | print "<select id=\"iedit_fcat\">"; | |
1509 | print "<option id=\"0\">Uncategorized</option>"; | |
1510 | ||
1511 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
1512 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1513 | ||
1514 | if (db_num_rows($tmp_result) > 0) { | |
1515 | print "<option disabled>--------</option>"; | |
1516 | } | |
1517 | ||
1518 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1519 | if ($tmp_line["id"] == $cat_id) { | |
1520 | $is_selected = "selected"; | |
1521 | } else { | |
1522 | $is_selected = ""; | |
1523 | } | |
1524 | printf("<option $is_selected id='%d'>%s</option>", | |
1525 | $tmp_line["id"], $tmp_line["title"]); | |
1526 | } | |
1527 | ||
1528 | print "</select></td>"; | |
1529 | print "</td></tr>"; | |
1530 | ||
1531 | } | |
1532 | ||
1533 | $update_interval = db_fetch_result($result, 0, "update_interval"); | |
1534 | $row_class = toggleEvenOdd($row_class); | |
1535 | ||
1536 | print "<tr class='$row_class'><td>Update Interval:</td>"; | |
1537 | print "<td><input id=\"iedit_updintl\" | |
1538 | value=\"$update_interval\"></td></tr>"; | |
1539 | ||
1540 | $purge_interval = db_fetch_result($result, 0, "purge_interval"); | |
1541 | $row_class = toggleEvenOdd($row_class); | |
1542 | ||
1543 | print "<tr class='$row_class'><td>Purge Days:</td>"; | |
1544 | print "<td><input id=\"iedit_purgintl\" | |
1545 | value=\"$purge_interval\"></td></tr>"; | |
1546 | ||
1547 | // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>"; | |
1548 | ||
1549 | $row_class = toggleEvenOdd($row_class); | |
1550 | $auth_login = db_fetch_result($result, 0, "auth_login"); | |
1551 | ||
1552 | print "<tr class='$row_class'><td>Login:</td>"; | |
1553 | print "<td><input id=\"iedit_login\" | |
1554 | value=\"$auth_login\"></td></tr>"; | |
1555 | ||
1556 | $row_class = toggleEvenOdd($row_class); | |
1557 | $auth_pass = db_fetch_result($result, 0, "auth_pass"); | |
1558 | ||
1559 | print "<tr class='$row_class'><td>Password:</td>"; | |
1560 | print "<td><input type=\"password\" id=\"iedit_pass\" | |
1561 | value=\"$auth_pass\"></td></tr>"; | |
1562 | ||
1563 | print "</table>"; | |
1564 | print "</div>"; | |
1565 | ||
1566 | print "<div align='center'> | |
1567 | <input type='submit' class='button' | |
1568 | onclick=\"feedEditCancel()\" value=\"Cancel\"> | |
1569 | <input type=\"submit\" class=\"button\" | |
1570 | onclick=\"feedEditSave()\" value=\"Save\"></div>"; | |
1571 | return; | |
1572 | } | |
1573 | ||
1574 | if ($subop == "editSave") { | |
1575 | $feed_title = db_escape_string($_POST["t"]); | |
1576 | $feed_link = db_escape_string($_POST["l"]); | |
1577 | $upd_intl = db_escape_string($_POST["ui"]); | |
1578 | $purge_intl = db_escape_string($_POST["pi"]); | |
1579 | $feed_id = db_escape_string($_POST["id"]); | |
1580 | $cat_id = db_escape_string($_POST["catid"]); | |
1581 | $auth_login = db_escape_string($_POST["login"]); | |
1582 | $auth_pass = db_escape_string($_POST["pass"]); | |
1583 | ||
1584 | if (strtoupper($upd_intl) == "DEFAULT") | |
1585 | $upd_intl = 0; | |
1586 | ||
1587 | if (strtoupper($upd_intl) == "DISABLED") | |
1588 | $upd_intl = -1; | |
1589 | ||
1590 | if (strtoupper($purge_intl) == "DEFAULT") | |
1591 | $purge_intl = 0; | |
1592 | ||
1593 | if (strtoupper($purge_intl) == "DISABLED") | |
1594 | $purge_intl = -1; | |
1595 | ||
1596 | if ($cat_id != 0) { | |
1597 | $category_qpart = "cat_id = '$cat_id'"; | |
1598 | } else { | |
1599 | $category_qpart = 'cat_id = NULL'; | |
1600 | } | |
1601 | ||
1602 | $result = db_query($link, "UPDATE ttrss_feeds SET | |
1603 | $category_qpart, | |
1604 | title = '$feed_title', feed_url = '$feed_link', | |
1605 | update_interval = '$upd_intl', | |
1606 | purge_interval = '$purge_intl', | |
1607 | auth_login = '$auth_login', | |
1608 | auth_pass = '$auth_pass' | |
1609 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
1610 | } | |
1611 | ||
1612 | if ($subop == "saveCat") { | |
1613 | $cat_title = db_escape_string($_GET["title"]); | |
1614 | $cat_id = db_escape_string($_GET["id"]); | |
1615 | ||
1616 | $result = db_query($link, "UPDATE ttrss_feed_categories SET | |
1617 | title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); | |
1618 | ||
1619 | } | |
1620 | ||
1621 | if ($subop == "remove") { | |
1622 | ||
1623 | if (!WEB_DEMO_MODE) { | |
1624 | ||
1625 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1626 | ||
1627 | foreach ($ids as $id) { | |
1628 | db_query($link, "DELETE FROM ttrss_feeds | |
1629 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1630 | ||
1631 | $icons_dir = ICONS_DIR; | |
1632 | ||
1633 | if (file_exists($icons_dir . "/$id.ico")) { | |
1634 | unlink($icons_dir . "/$id.ico"); | |
1635 | } | |
1636 | } | |
1637 | } | |
1638 | } | |
1639 | ||
1640 | if ($subop == "add") { | |
1641 | ||
1642 | if (!WEB_DEMO_MODE) { | |
1643 | ||
1644 | $feed_link = db_escape_string(trim($_GET["link"])); | |
1645 | ||
1646 | $result = db_query($link, | |
1647 | "SELECT id FROM ttrss_feeds | |
1648 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
1649 | ||
1650 | if (db_num_rows($result) == 0) { | |
1651 | ||
1652 | $result = db_query($link, | |
1653 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) | |
1654 | VALUES ('".$_SESSION["uid"]."', '$feed_link', '')"); | |
1655 | ||
1656 | $result = db_query($link, | |
1657 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' | |
1658 | AND owner_uid = " . $_SESSION["uid"]); | |
1659 | ||
1660 | $feed_id = db_fetch_result($result, 0, "id"); | |
1661 | ||
1662 | if ($feed_id) { | |
1663 | update_rss_feed($link, $feed_link, $feed_id, true); | |
1664 | } | |
1665 | } else { | |
1666 | ||
1667 | print "<div class=\"warning\"> | |
1668 | Feed <b>$feed_link</b> already exists in the database. | |
1669 | </div>"; | |
1670 | } | |
1671 | } | |
1672 | } | |
1673 | ||
1674 | if ($subop == "addCat") { | |
1675 | ||
1676 | if (!WEB_DEMO_MODE) { | |
1677 | ||
1678 | $feed_cat = db_escape_string(trim($_GET["cat"])); | |
1679 | ||
1680 | $result = db_query($link, | |
1681 | "SELECT id FROM ttrss_feed_categories | |
1682 | WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); | |
1683 | ||
1684 | if (db_num_rows($result) == 0) { | |
1685 | ||
1686 | $result = db_query($link, | |
1687 | "INSERT INTO ttrss_feed_categories (owner_uid,title) | |
1688 | VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); | |
1689 | ||
1690 | } else { | |
1691 | ||
1692 | print "<div class=\"warning\"> | |
1693 | Category <b>$feed_cat</b> already exists in the database. | |
1694 | </div>"; | |
1695 | } | |
1696 | ||
1697 | ||
1698 | } | |
1699 | } | |
1700 | ||
1701 | if ($subop == "removeCats") { | |
1702 | ||
1703 | if (!WEB_DEMO_MODE) { | |
1704 | ||
1705 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1706 | ||
1707 | foreach ($ids as $id) { | |
1708 | ||
1709 | db_query($link, "BEGIN"); | |
1710 | ||
1711 | $result = db_query($link, | |
1712 | "SELECT count(id) as num_feeds FROM ttrss_feeds | |
1713 | WHERE cat_id = '$id'"); | |
1714 | ||
1715 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
1716 | ||
1717 | if ($num_feeds == 0) { | |
1718 | db_query($link, "DELETE FROM ttrss_feed_categories | |
1719 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1720 | } else { | |
1721 | ||
1722 | print "<div class=\"warning\"> | |
1723 | Unable to delete non empty feed categories.</div>"; | |
1724 | ||
1725 | } | |
1726 | ||
1727 | db_query($link, "COMMIT"); | |
1728 | } | |
1729 | } | |
1730 | } | |
1731 | ||
1732 | if ($subop == "categorize") { | |
1733 | ||
1734 | if (!WEB_DEMO_MODE) { | |
1735 | ||
1736 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1737 | ||
1738 | $cat_id = db_escape_string($_GET["cat_id"]); | |
1739 | ||
1740 | if ($cat_id == 0) { | |
1741 | $cat_id_qpart = 'NULL'; | |
1742 | } else { | |
1743 | $cat_id_qpart = "'$cat_id'"; | |
1744 | } | |
1745 | ||
1746 | db_query($link, "BEGIN"); | |
1747 | ||
1748 | foreach ($ids as $id) { | |
1749 | ||
1750 | db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart | |
1751 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1752 | } | |
1753 | ||
1754 | db_query($link, "COMMIT"); | |
1755 | } | |
1756 | ||
1757 | } | |
1758 | ||
1759 | if ($quiet) return; | |
1760 | ||
1761 | // print "<h3>Edit Feeds</h3>"; | |
1762 | ||
1763 | $result = db_query($link, "SELECT id,title,feed_url,last_error | |
1764 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); | |
1765 | ||
1766 | if (db_num_rows($result) > 0) { | |
1767 | ||
1768 | print "<div class=\"warning\">"; | |
1769 | ||
1770 | print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\"> | |
1771 | <b>Feeds with update errors</b> (click to expand)</a>"; | |
1772 | ||
1773 | print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">"; | |
1774 | ||
1775 | while ($line = db_fetch_assoc($result)) { | |
1776 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
1777 | $line["last_error"]; | |
1778 | } | |
1779 | ||
1780 | print "</ul>"; | |
1781 | print "</div>"; | |
1782 | ||
1783 | } | |
1784 | ||
1785 | $feed_search = db_escape_string($_GET["search"]); | |
1786 | ||
1787 | if (array_key_exists("search", $_GET)) { | |
1788 | $_SESSION["prefs_feed_search"] = $feed_search; | |
1789 | } else { | |
1790 | $feed_search = $_SESSION["prefs_feed_search"]; | |
1791 | } | |
1792 | ||
1793 | print "<table width='100%' class=\"prefGenericAddBox\" | |
1794 | cellspacing='0' cellpadding='0'><tr> | |
1795 | <td> | |
1796 | <input id=\"fadd_link\" | |
1797 | onchange=\"javascript:addFeed()\" | |
1798 | size=\"40\"> | |
1799 | <input type=\"submit\" class=\"button\" | |
1800 | onclick=\"javascript:addFeed()\" value=\"Add feed\"> | |
1801 | </td><td align='right'> | |
1802 | <input id=\"feed_search\" size=\"20\" | |
1803 | onchange=\"javascript:updateFeedList()\" | |
1804 | value=\"$feed_search\"> | |
1805 | <input type=\"submit\" class=\"button\" | |
1806 | onclick=\"javascript:updateFeedList()\" value=\"Search\"> | |
1807 | </td> | |
1808 | </tr></table>"; | |
1809 | ||
1810 | $feeds_sort = db_escape_string($_GET["sort"]); | |
1811 | ||
1812 | if (!$feeds_sort || $feeds_sort == "undefined") { | |
1813 | $feeds_sort = $_SESSION["pref_sort_feeds"]; | |
1814 | if (!$feeds_sort) $feeds_sort = "title"; | |
1815 | } | |
1816 | ||
1817 | $_SESSION["pref_sort_feeds"] = $feeds_sort; | |
1818 | ||
1819 | if ($feed_search) { | |
1820 | $search_qpart = "(UPPER(title) LIKE UPPER('%$feed_search%') OR | |
1821 | UPPER(feed_url) LIKE UPPER('%$feed_search%')) AND"; | |
1822 | } else { | |
1823 | $search_qpart = ""; | |
1824 | } | |
1825 | ||
1826 | $result = db_query($link, "SELECT | |
1827 | id,title,feed_url,substring(last_updated,1,16) as last_updated, | |
1828 | update_interval,purge_interval,cat_id, | |
1829 | (SELECT title FROM ttrss_feed_categories | |
1830 | WHERE id = cat_id) AS category | |
1831 | FROM | |
1832 | ttrss_feeds | |
1833 | WHERE | |
1834 | $search_qpart owner_uid = '".$_SESSION["uid"]."' | |
1835 | ORDER by category,$feeds_sort,title"); | |
1836 | ||
1837 | if (db_num_rows($result) != 0) { | |
1838 | ||
1839 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
1840 | ||
1841 | print "<p><table width=\"100%\" cellspacing=\"0\" | |
1842 | class=\"prefFeedList\" id=\"prefFeedList\">"; | |
1843 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
1844 | Select: | |
1845 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', | |
1846 | 'FEEDR-', 'FRCHK-', true)\">All</a>, | |
1847 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', | |
1848 | 'FEEDR-', 'FRCHK-', false)\">None</a> | |
1849 | </td</tr>"; | |
1850 | ||
1851 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
1852 | print "<tr class=\"title\"> | |
1853 | <td width='5%' align='center'> </td> | |
1854 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> | |
1855 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> | |
1856 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> | |
1857 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>"; | |
1858 | } | |
1859 | ||
1860 | $lnum = 0; | |
1861 | ||
1862 | $cur_cat_id = -1; | |
1863 | ||
1864 | while ($line = db_fetch_assoc($result)) { | |
1865 | ||
1866 | $feed_id = $line["id"]; | |
1867 | $cat_id = $line["cat_id"]; | |
1868 | ||
1869 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
1870 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
1871 | $edit_cat = htmlspecialchars(db_unescape_string($line["category"])); | |
1872 | ||
1873 | if ($line["update_interval"] == "0") $line["update_interval"] = "Default"; | |
1874 | if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled"; | |
1875 | if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default"; | |
1876 | if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled"; | |
1877 | ||
1878 | if (!$edit_cat) $edit_cat = "Uncategorized"; | |
1879 | ||
1880 | ||
1881 | if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) { | |
1882 | $lnum = 0; | |
1883 | ||
1884 | print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>"; | |
1885 | ||
1886 | print "<tr class=\"title\"> | |
1887 | <td width='5%' align='center'> </td> | |
1888 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> | |
1889 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> | |
1890 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> | |
1891 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>"; | |
1892 | ||
1893 | $cur_cat_id = $cat_id; | |
1894 | } | |
1895 | ||
1896 | $class = ($lnum % 2) ? "even" : "odd"; | |
1897 | $this_row_id = "id=\"FEEDR-$feed_id\""; | |
1898 | ||
1899 | print "<tr class=\"$class\" $this_row_id>"; | |
1900 | ||
1901 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
1902 | ||
1903 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1904 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
1905 | } else { | |
1906 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
1907 | } | |
1908 | // print "<td class='feedIcon'>$feed_icon</td>"; | |
1909 | ||
1910 | print "<td class='feedSelect'><input onclick='toggleSelectRow(this);' | |
1911 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; | |
1912 | ||
1913 | $edit_title = truncate_string($edit_title, 40); | |
1914 | $edit_link = truncate_string($edit_link, 60); | |
1915 | ||
1916 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1917 | "$feed_icon $edit_title" . "</a></td>"; | |
1918 | ||
1919 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1920 | $edit_link . "</a></td>"; | |
1921 | ||
1922 | /* if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1923 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1924 | $edit_cat . "</a></td>"; | |
1925 | } */ | |
1926 | ||
1927 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1928 | $line["update_interval"] . "</a></td>"; | |
1929 | ||
1930 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1931 | $line["purge_interval"] . "</a></td>"; | |
1932 | ||
1933 | print "</tr>"; | |
1934 | ||
1935 | ++$lnum; | |
1936 | } | |
1937 | ||
1938 | print "</table>"; | |
1939 | ||
1940 | print "<p>"; | |
1941 | ||
1942 | if ($subop == "edit") { | |
1943 | print "Edit feed: | |
1944 | <input type=\"submit\" class=\"button\" | |
1945 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
1946 | <input type=\"submit\" class=\"button\" | |
1947 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; | |
1948 | } else { | |
1949 | ||
1950 | print " | |
1951 | Selection: | |
1952 | <input type=\"submit\" class=\"button\" | |
1953 | onclick=\"javascript:selectedFeedDetails()\" value=\"Details\"> | |
1954 | <input type=\"submit\" class=\"button\" | |
1955 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
1956 | <input type=\"submit\" class=\"button\" | |
1957 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
1958 | ||
1959 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1960 | ||
1961 | print " "; | |
1962 | ||
1963 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
1964 | WHERE owner_uid = ".$_SESSION["uid"]." | |
1965 | ORDER BY title"); | |
1966 | ||
1967 | print "<select id=\"sfeed_set_fcat\">"; | |
1968 | print "<option id=\"0\">Uncategorized</option>"; | |
1969 | ||
1970 | if (db_num_rows($result) != 0) { | |
1971 | ||
1972 | print "<option disabled>--------</option>"; | |
1973 | ||
1974 | while ($line = db_fetch_assoc($result)) { | |
1975 | printf("<option id='%d'>%s</option>", | |
1976 | $line["id"], $line["title"]); | |
1977 | } | |
1978 | } | |
1979 | ||
1980 | print "</select>"; | |
1981 | ||
1982 | print " <input type=\"submit\" class=\"button\" | |
1983 | onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">"; | |
1984 | ||
1985 | } | |
1986 | ||
1987 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { | |
1988 | print " | |
1989 | <input type=\"submit\" class=\"button\" | |
1990 | onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\"> | |
1991 | <input type=\"submit\" class=\"button\" | |
1992 | onclick=\"javascript:readSelectedFeeds(false)\" | |
1993 | value=\"Mark as unread\"> "; | |
1994 | } | |
1995 | ||
1996 | print " | |
1997 | All feeds: <input type=\"submit\" | |
1998 | class=\"button\" onclick=\"gotoExportOpml()\" | |
1999 | value=\"Export OPML\">"; | |
2000 | } | |
2001 | } else { | |
2002 | ||
2003 | print "<p>No feeds defined.</p>"; | |
2004 | ||
2005 | } | |
2006 | ||
2007 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2008 | ||
2009 | print "<h3>Edit Categories</h3>"; | |
2010 | ||
2011 | // print "<h3>Categories</h3>"; | |
2012 | ||
2013 | print "<div class=\"prefGenericAddBox\"> | |
2014 | <input id=\"fadd_cat\" | |
2015 | onchange=\"javascript:addFeedCat()\" | |
2016 | size=\"40\"> | |
2017 | <input | |
2018 | type=\"submit\" class=\"button\" | |
2019 | onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>"; | |
2020 | ||
2021 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2022 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2023 | ORDER BY title"); | |
2024 | ||
2025 | if (db_num_rows($result) != 0) { | |
2026 | ||
2027 | print "<p><table width=\"100%\" class=\"prefFeedCatList\" | |
2028 | cellspacing=\"0\" id=\"prefFeedCatList\">"; | |
2029 | ||
2030 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2031 | Select: | |
2032 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', | |
2033 | 'FCATR-', 'FCCHK-', true)\">All</a>, | |
2034 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', | |
2035 | 'FCATR-', 'FCCHK-', false)\">None</a> | |
2036 | </td</tr>"; | |
2037 | ||
2038 | print "<tr class=\"title\"> | |
2039 | <td width=\"5%\"></td><td width=\"80%\">Title</td> | |
2040 | </tr>"; | |
2041 | ||
2042 | $lnum = 0; | |
2043 | ||
2044 | while ($line = db_fetch_assoc($result)) { | |
2045 | ||
2046 | $class = ($lnum % 2) ? "even" : "odd"; | |
2047 | ||
2048 | $cat_id = $line["id"]; | |
2049 | ||
2050 | $edit_cat_id = $_GET["id"]; | |
2051 | ||
2052 | if ($subop == "editCat" && $cat_id != $edit_cat_id) { | |
2053 | $class .= "Grayed"; | |
2054 | $this_row_id = ""; | |
2055 | } else { | |
2056 | $this_row_id = "id=\"FCATR-$cat_id\""; | |
2057 | } | |
2058 | ||
2059 | print "<tr class=\"$class\" $this_row_id>"; | |
2060 | ||
2061 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
2062 | ||
2063 | if (!$edit_cat_id || $subop != "editCat") { | |
2064 | ||
2065 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
2066 | type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>"; | |
2067 | ||
2068 | print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . | |
2069 | $edit_title . "</a></td>"; | |
2070 | ||
2071 | } else if ($cat_id != $edit_cat_id) { | |
2072 | ||
2073 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2074 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
2075 | ||
2076 | print "<td>$edit_title</td>"; | |
2077 | ||
2078 | } else { | |
2079 | ||
2080 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2081 | ||
2082 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; | |
2083 | ||
2084 | } | |
2085 | ||
2086 | print "</tr>"; | |
2087 | ||
2088 | ++$lnum; | |
2089 | } | |
2090 | ||
2091 | print "</table>"; | |
2092 | ||
2093 | print "<p>"; | |
2094 | ||
2095 | if ($subop == "editCat") { | |
2096 | print "Edit category: | |
2097 | <input type=\"submit\" class=\"button\" | |
2098 | onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\"> | |
2099 | <input type=\"submit\" class=\"button\" | |
2100 | onclick=\"javascript:feedCatEditSave()\" value=\"Save\">"; | |
2101 | } else { | |
2102 | ||
2103 | print " | |
2104 | Selection: | |
2105 | <input type=\"submit\" class=\"button\" | |
2106 | onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\"> | |
2107 | <input type=\"submit\" class=\"button\" | |
2108 | onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">"; | |
2109 | ||
2110 | } | |
2111 | ||
2112 | } else { | |
2113 | print "<p>No feed categories defined.</p>"; | |
2114 | } | |
2115 | } | |
2116 | ||
2117 | print "<h3>Import OPML</h3> | |
2118 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> | |
2119 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
2120 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
2121 | type=\"submit\" value=\"Import\"> | |
2122 | </form>"; | |
2123 | ||
2124 | } | |
2125 | ||
2126 | if ($op == "pref-filters") { | |
2127 | ||
2128 | $subop = $_GET["subop"]; | |
2129 | $quiet = $_GET["quiet"]; | |
2130 | ||
2131 | if ($subop == "editSave") { | |
2132 | ||
2133 | $regexp = db_escape_string($_GET["r"]); | |
2134 | $descr = db_escape_string($_GET["d"]); | |
2135 | $match = db_escape_string($_GET["m"]); | |
2136 | $filter_id = db_escape_string($_GET["id"]); | |
2137 | $feed_id = db_escape_string($_GET["fid"]); | |
2138 | $action_id = db_escape_string($_GET["aid"]); | |
2139 | ||
2140 | if (!$feed_id) { | |
2141 | $feed_id = 'NULL'; | |
2142 | } else { | |
2143 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2144 | } | |
2145 | ||
2146 | $result = db_query($link, "UPDATE ttrss_filters SET | |
2147 | reg_exp = '$regexp', | |
2148 | description = '$descr', | |
2149 | feed_id = $feed_id, | |
2150 | action_id = '$action_id', | |
2151 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
2152 | description = '$match') | |
2153 | WHERE id = '$filter_id'"); | |
2154 | } | |
2155 | ||
2156 | if ($subop == "remove") { | |
2157 | ||
2158 | if (!WEB_DEMO_MODE) { | |
2159 | ||
2160 | $ids = split(",", db_escape_string($_GET["ids"])); | |
2161 | ||
2162 | foreach ($ids as $id) { | |
2163 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); | |
2164 | ||
2165 | } | |
2166 | } | |
2167 | } | |
2168 | ||
2169 | if ($subop == "add") { | |
2170 | ||
2171 | if (!WEB_DEMO_MODE) { | |
2172 | ||
2173 | $regexp = db_escape_string(trim($_GET["regexp"])); | |
2174 | $match = db_escape_string(trim($_GET["match"])); | |
2175 | $feed_id = db_escape_string($_GET["fid"]); | |
2176 | $action_id = db_escape_string($_GET["aid"]); | |
2177 | ||
2178 | if (!$feed_id) { | |
2179 | $feed_id = 'NULL'; | |
2180 | } else { | |
2181 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2182 | } | |
2183 | ||
2184 | $result = db_query($link, | |
2185 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, | |
2186 | action_id) | |
2187 | VALUES | |
2188 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE | |
2189 | description = '$match'),'".$_SESSION["uid"]."', | |
2190 | $feed_id, '$action_id')"); | |
2191 | } | |
2192 | } | |
2193 | ||
2194 | if ($quiet) return; | |
2195 | ||
2196 | $result = db_query($link, "SELECT description | |
2197 | FROM ttrss_filter_types ORDER BY description"); | |
2198 | ||
2199 | $filter_types = array(); | |
2200 | ||
2201 | while ($line = db_fetch_assoc($result)) { | |
2202 | array_push($filter_types, $line["description"]); | |
2203 | } | |
2204 | ||
2205 | print "<div class=\"prefGenericAddBox\"> | |
2206 | <input id=\"fadd_regexp\" size=\"40\"> "; | |
2207 | ||
2208 | print_select("fadd_match", "Title", $filter_types); | |
2209 | ||
2210 | print " <select id=\"fadd_feed\">"; | |
2211 | ||
2212 | print "<option selected id=\"0\">All feeds</option>"; | |
2213 | ||
2214 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2215 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2216 | ||
2217 | if (db_num_rows($result) > 0) { | |
2218 | print "<option disabled>--------</option>"; | |
2219 | } | |
2220 | ||
2221 | while ($line = db_fetch_assoc($result)) { | |
2222 | printf("<option id='%d'>%s</option>", $line["id"], $line["title"]); | |
2223 | } | |
2224 | ||
2225 | print "</select> "; | |
2226 | ||
2227 | print " Action: "; | |
2228 | ||
2229 | print "<select id=\"fadd_action\">"; | |
2230 | ||
2231 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2232 | ORDER BY name"); | |
2233 | ||
2234 | while ($line = db_fetch_assoc($result)) { | |
2235 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
2236 | } | |
2237 | ||
2238 | print "</select> "; | |
2239 | ||
2240 | print "<input type=\"submit\" | |
2241 | class=\"button\" onclick=\"javascript:addFilter()\" | |
2242 | value=\"Add filter\">"; | |
2243 | ||
2244 | print "</div>"; | |
2245 | ||
2246 | $result = db_query($link, "SELECT | |
2247 | ttrss_filters.id AS id,reg_exp, | |
2248 | ttrss_filters.description AS description, | |
2249 | ttrss_filter_types.name AS filter_type_name, | |
2250 | ttrss_filter_types.description AS filter_type_descr, | |
2251 | feed_id, | |
2252 | ttrss_filter_actions.description AS action_description, | |
2253 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
2254 | FROM | |
2255 | ttrss_filters,ttrss_filter_types,ttrss_filter_actions | |
2256 | WHERE | |
2257 | filter_type = ttrss_filter_types.id AND | |
2258 | ttrss_filter_actions.id = action_id AND | |
2259 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." | |
2260 | ORDER by reg_exp"); | |
2261 | ||
2262 | if (db_num_rows($result) != 0) { | |
2263 | ||
2264 | print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" | |
2265 | id=\"prefFilterList\">"; | |
2266 | ||
2267 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2268 | Select: | |
2269 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', | |
2270 | 'FILRR-', 'FICHK-', true)\">All</a>, | |
2271 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', | |
2272 | 'FILRR-', 'FICHK-', false)\">None</a> | |
2273 | </td</tr>"; | |
2274 | ||
2275 | print "<tr class=\"title\"> | |
2276 | <td align='center' width=\"5%\"> </td> | |
2277 | <td width=\"20%\">Filter expression</td> | |
2278 | <td width=\"20%\">Feed</td> | |
2279 | <td width=\"15%\">Match</td> | |
2280 | <td width=\"15%\">Action</td> | |
2281 | <td width=\"30%\">Description</td></tr>"; | |
2282 | ||
2283 | $lnum = 0; | |
2284 | ||
2285 | while ($line = db_fetch_assoc($result)) { | |
2286 | ||
2287 | $class = ($lnum % 2) ? "even" : "odd"; | |
2288 | ||
2289 | $filter_id = $line["id"]; | |
2290 | $edit_filter_id = $_GET["id"]; | |
2291 | ||
2292 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
2293 | $class .= "Grayed"; | |
2294 | $this_row_id = ""; | |
2295 | } else { | |
2296 | $this_row_id = "id=\"FILRR-$filter_id\""; | |
2297 | } | |
2298 | ||
2299 | print "<tr class=\"$class\" $this_row_id>"; | |
2300 | ||
2301 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); | |
2302 | $line["description"] = htmlspecialchars($line["description"]); | |
2303 | ||
2304 | if (!$line["feed_title"]) $line["feed_title"] = "All feeds"; | |
2305 | ||
2306 | if (!$edit_filter_id || $subop != "edit") { | |
2307 | ||
2308 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2309 | ||
2310 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
2311 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
2312 | ||
2313 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2314 | $line["reg_exp"] . "</td>"; | |
2315 | ||
2316 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2317 | $line["feed_title"] . "</td>"; | |
2318 | ||
2319 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2320 | $line["filter_type_descr"] . "</td>"; | |
2321 | ||
2322 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2323 | $line["action_description"] . "</td>"; | |
2324 | ||
2325 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2326 | $line["description"] . "</td>"; | |
2327 | ||
2328 | } else if ($filter_id != $edit_filter_id) { | |
2329 | ||
2330 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2331 | ||
2332 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2333 | id=\"FICHK-".$line["id"]."\"></td>"; | |
2334 | ||
2335 | print "<td>".$line["reg_exp"]."</td>"; | |
2336 | print "<td>".$line["feed_title"]."</td>"; | |
2337 | print "<td>".$line["filter_type_descr"]."</td>"; | |
2338 | print "<td>".$line["action_description"]."</td>"; | |
2339 | print "<td>".$line["description"]."</td>"; | |
2340 | ||
2341 | } else { | |
2342 | ||
2343 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2344 | ||
2345 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. | |
2346 | "\"></td>"; | |
2347 | ||
2348 | print "<td>"; | |
2349 | print "<select id=\"iedit_feed\">"; | |
2350 | print "<option id=\"0\">All feeds</option>"; | |
2351 | ||
2352 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2353 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2354 | ||
2355 | if (db_num_rows($tmp_result) > 0) { | |
2356 | print "<option disabled>--------</option>"; | |
2357 | } | |
2358 | ||
2359 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2360 | if ($tmp_line["id"] == $line["feed_id"]) { | |
2361 | $is_selected = "selected"; | |
2362 | } else { | |
2363 | $is_selected = ""; | |
2364 | } | |
2365 | printf("<option $is_selected id='%d'>%s</option>", | |
2366 | $tmp_line["id"], $tmp_line["title"]); | |
2367 | } | |
2368 | ||
2369 | print "</select></td>"; | |
2370 | ||
2371 | print "<td>"; | |
2372 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
2373 | print "</td>"; | |
2374 | ||
2375 | print "<td>"; | |
2376 | print "<select id=\"iedit_filter_action\">"; | |
2377 | ||
2378 | $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2379 | ORDER BY description"); | |
2380 | ||
2381 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2382 | if ($tmp_line["description"] == $line["action_description"]) { | |
2383 | $is_selected = "selected"; | |
2384 | } else { | |
2385 | $is_selected = ""; | |
2386 | } | |
2387 | printf("<option $is_selected id='%d'>%s</option>", | |
2388 | $tmp_line["id"], $tmp_line["description"]); | |
2389 | } | |
2390 | ||
2391 | print "</select></td>"; | |
2392 | ||
2393 | ||
2394 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
2395 | "\"></td>"; | |
2396 | ||
2397 | print "</td>"; | |
2398 | } | |
2399 | ||
2400 | print "</tr>"; | |
2401 | ||
2402 | ++$lnum; | |
2403 | } | |
2404 | ||
2405 | if ($lnum == 0) { | |
2406 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
2407 | } | |
2408 | ||
2409 | print "</table>"; | |
2410 | ||
2411 | print "<p>"; | |
2412 | ||
2413 | if ($subop == "edit") { | |
2414 | print "Edit feed: | |
2415 | <input type=\"submit\" class=\"button\" | |
2416 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
2417 | <input type=\"submit\" class=\"button\" | |
2418 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
2419 | ||
2420 | } else { | |
2421 | ||
2422 | print " | |
2423 | Selection: | |
2424 | <input type=\"submit\" class=\"button\" | |
2425 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
2426 | <input type=\"submit\" class=\"button\" | |
2427 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
2428 | } | |
2429 | ||
2430 | } else { | |
2431 | ||
2432 | print "<p>No filters defined.</p>"; | |
2433 | ||
2434 | } | |
2435 | } | |
2436 | ||
2437 | // We need to accept raw SQL data in label queries, so not everything is escaped | |
2438 | // here, this is by design. If you don't like the whole idea, disable labels | |
2439 | // altogether with GLOBAL_ENABLE_LABELS = false | |
2440 | ||
2441 | if ($op == "pref-labels") { | |
2442 | ||
2443 | if (!GLOBAL_ENABLE_LABELS) { | |
2444 | return; | |
2445 | } | |
2446 | ||
2447 | $subop = $_GET["subop"]; | |
2448 | ||
2449 | if ($subop == "test") { | |
2450 | ||
2451 | $expr = $_GET["expr"]; | |
2452 | $descr = $_GET["descr"]; | |
2453 | ||
2454 | print "<div class='infoBoxContents'>"; | |
2455 | ||
2456 | print "<h1>Label «$descr»</h1>"; | |
2457 | ||
2458 | // print "<p><b>Expression</b>: $expr</p>"; | |
2459 | ||
2460 | $result = db_query($link, | |
2461 | "SELECT count(id) AS num_matches | |
2462 | FROM ttrss_entries,ttrss_user_entries | |
2463 | WHERE ($expr) AND | |
2464 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2465 | owner_uid = " . $_SESSION["uid"]); | |
2466 | ||
2467 | $num_matches = db_fetch_result($result, 0, "num_matches");; | |
2468 | ||
2469 | if ($num_matches > 0) { | |
2470 | ||
2471 | print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>"; | |
2472 | ||
2473 | $result = db_query($link, | |
2474 | "SELECT title, | |
2475 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
2476 | FROM ttrss_entries,ttrss_user_entries | |
2477 | WHERE ($expr) AND | |
2478 | ttrss_user_entries.ref_id = ttrss_entries.id | |
2479 | AND owner_uid = " . $_SESSION["uid"] . " | |
2480 | ORDER BY date_entered DESC LIMIT 5"); | |
2481 | ||
2482 | print "<ul class=\"nomarks\">"; | |
2483 | while ($line = db_fetch_assoc($result)) { | |
2484 | print "<li>".$line["title"]. | |
2485 | " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>"; | |
2486 | } | |
2487 | print "</ul>"; | |
2488 | ||
2489 | } else { | |
2490 | print "<p>Query didn't return any matches.</p>"; | |
2491 | } | |
2492 | ||
2493 | print "</div>"; | |
2494 | ||
2495 | print "<div align='center'> | |
2496 | <input type='submit' class='button' | |
2497 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
2498 | return; | |
2499 | } | |
2500 | ||
2501 | if ($subop == "editSave") { | |
2502 | ||
2503 | $sql_exp = $_GET["s"]; | |
2504 | $descr = $_GET["d"]; | |
2505 | $label_id = db_escape_string($_GET["id"]); | |
2506 | ||
2507 | // print "$sql_exp : $descr : $label_id"; | |
2508 | ||
2509 | $result = db_query($link, "UPDATE ttrss_labels SET | |
2510 | sql_exp = '$sql_exp', | |
2511 | description = '$descr' | |
2512 | WHERE id = '$label_id'"); | |
2513 | } | |
2514 | ||
2515 | if ($subop == "remove") { | |
2516 | ||
2517 | if (!WEB_DEMO_MODE) { | |
2518 | ||
2519 | $ids = split(",", db_escape_string($_GET["ids"])); | |
2520 | ||
2521 | foreach ($ids as $id) { | |
2522 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
2523 | ||
2524 | } | |
2525 | } | |
2526 | } | |
2527 | ||
2528 | if ($subop == "add") { | |
2529 | ||
2530 | if (!WEB_DEMO_MODE) { | |
2531 | ||
2532 | // no escaping is done here on purpose | |
2533 | $exp = trim($_GET["exp"]); | |
2534 | ||
2535 | $result = db_query($link, | |
2536 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) | |
2537 | VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')"); | |
2538 | } | |
2539 | } | |
2540 | ||
2541 | print "<div class=\"prefGenericAddBox\"> | |
2542 | <input size=\"40\" id=\"ladd_expr\"> "; | |
2543 | ||
2544 | print"<input type=\"submit\" class=\"button\" | |
2545 | onclick=\"javascript:addLabel()\" value=\"Add label\"></div>"; | |
2546 | ||
2547 | $result = db_query($link, "SELECT | |
2548 | id,sql_exp,description | |
2549 | FROM | |
2550 | ttrss_labels | |
2551 | WHERE | |
2552 | owner_uid = ".$_SESSION["uid"]." | |
2553 | ORDER by description"); | |
2554 | ||
2555 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
2556 | ||
2557 | if (db_num_rows($result) != 0) { | |
2558 | ||
2559 | print "<p><table width=\"100%\" cellspacing=\"0\" | |
2560 | class=\"prefLabelList\" id=\"prefLabelList\">"; | |
2561 | ||
2562 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2563 | Select: | |
2564 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', | |
2565 | 'LILRR-', 'LICHK-', true)\">All</a>, | |
2566 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', | |
2567 | 'LILRR-', 'LICHK-', false)\">None</a> | |
2568 | </td</tr>"; | |
2569 | ||
2570 | print "<tr class=\"title\"> | |
2571 | <td align='center' width=\"5%\"> </td> | |
2572 | <td width=\"40%\">SQL expression | |
2573 | <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a> | |
2574 | </td> | |
2575 | <td width=\"40%\">Caption</td></tr>"; | |
2576 | ||
2577 | $lnum = 0; | |
2578 | ||
2579 | while ($line = db_fetch_assoc($result)) { | |
2580 | ||
2581 | $class = ($lnum % 2) ? "even" : "odd"; | |
2582 | ||
2583 | $label_id = $line["id"]; | |
2584 | $edit_label_id = $_GET["id"]; | |
2585 | ||
2586 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
2587 | $class .= "Grayed"; | |
2588 | $this_row_id = ""; | |
2589 | } else { | |
2590 | $this_row_id = "id=\"LILRR-$label_id\""; | |
2591 | } | |
2592 | ||
2593 | print "<tr class=\"$class\" $this_row_id>"; | |
2594 | ||
2595 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
2596 | $line["description"] = htmlspecialchars($line["description"]); | |
2597 | ||
2598 | if (!$edit_label_id || $subop != "edit") { | |
2599 | ||
2600 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
2601 | ||
2602 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
2603 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
2604 | ||
2605 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
2606 | $line["sql_exp"] . "</td>"; | |
2607 | ||
2608 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
2609 | $line["description"] . "</td>"; | |
2610 | ||
2611 | } else if ($label_id != $edit_label_id) { | |
2612 | ||
2613 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2614 | ||
2615 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2616 | id=\"LICHK-".$line["id"]."\"></td>"; | |
2617 | ||
2618 | print "<td>".$line["sql_exp"]."</td>"; | |
2619 | print "<td>".$line["description"]."</td>"; | |
2620 | ||
2621 | } else { | |
2622 | ||
2623 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2624 | ||
2625 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
2626 | "\"></td>"; | |
2627 | ||
2628 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
2629 | "\"></td>"; | |
2630 | ||
2631 | } | |
2632 | ||
2633 | ||
2634 | print "</tr>"; | |
2635 | ||
2636 | ++$lnum; | |
2637 | } | |
2638 | ||
2639 | if ($lnum == 0) { | |
2640 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
2641 | } | |
2642 | ||
2643 | print "</table>"; | |
2644 | ||
2645 | print "<p>"; | |
2646 | ||
2647 | if ($subop == "edit") { | |
2648 | print "Edit label: | |
2649 | <input type=\"submit\" class=\"button\" | |
2650 | onclick=\"javascript:labelTest()\" value=\"Test\"> | |
2651 | <input type=\"submit\" class=\"button\" | |
2652 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
2653 | <input type=\"submit\" class=\"button\" | |
2654 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
2655 | ||
2656 | } else { | |
2657 | ||
2658 | print " | |
2659 | Selection: | |
2660 | <input type=\"submit\" class=\"button\" | |
2661 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> | |
2662 | <input type=\"submit\" class=\"button\" | |
2663 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; | |
2664 | } | |
2665 | } else { | |
2666 | print "<p>No labels defined.</p>"; | |
2667 | } | |
2668 | } | |
2669 | ||
2670 | if ($op == "error") { | |
2671 | print "<div width=\"100%\" align='center'>"; | |
2672 | $msg = $_GET["msg"]; | |
2673 | print $msg; | |
2674 | print "</div>"; | |
2675 | } | |
2676 | ||
2677 | if ($op == "help") { | |
2678 | if (!$_GET["noheaders"]) { | |
2679 | print "<html><head> | |
2680 | <title>Tiny Tiny RSS : Help</title> | |
2681 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
2682 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
2683 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
2684 | </head><body>"; | |
2685 | } | |
2686 | ||
2687 | $tid = sprintf("%d", $_GET["tid"]); | |
2688 | ||
2689 | print "<div class='infoBoxContents'>"; | |
2690 | ||
2691 | if (file_exists("help/$tid.php")) { | |
2692 | include("help/$tid.php"); | |
2693 | } else { | |
2694 | print "<p>Help topic not found.</p>"; | |
2695 | } | |
2696 | ||
2697 | print "</div>"; | |
2698 | ||
2699 | print "<div align='center'> | |
2700 | <input type='submit' class='button' | |
2701 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
2702 | ||
2703 | if (!$_GET["noheaders"]) { | |
2704 | print "</body></html>"; | |
2705 | } | |
2706 | ||
2707 | } | |
2708 | ||
2709 | if ($op == "dlg") { | |
2710 | $id = $_GET["id"]; | |
2711 | $param = $_GET["param"]; | |
2712 | ||
2713 | if ($id == "quickAddFeed") { | |
2714 | print " | |
2715 | Feed URL: <input | |
2716 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
2717 | id=\"qafInput\"> | |
2718 | <input class=\"button\" | |
2719 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> | |
2720 | <input class=\"button\" | |
2721 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2722 | value=\"Cancel\">"; | |
2723 | } | |
2724 | ||
2725 | if ($id == "quickDelFeed") { | |
2726 | ||
2727 | $param = db_escape_string($param); | |
2728 | ||
2729 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
2730 | ||
2731 | if ($result) { | |
2732 | ||
2733 | $f_title = db_fetch_result($result, 0, "title"); | |
2734 | ||
2735 | print "Remove current feed (<b>$f_title</b>)? | |
2736 | <input class=\"button\" | |
2737 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
2738 | <input class=\"button\" | |
2739 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2740 | value=\"Cancel\">"; | |
2741 | } else { | |
2742 | print "Error: Feed $param not found. | |
2743 | <input class=\"button\" | |
2744 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2745 | value=\"Cancel\">"; | |
2746 | } | |
2747 | } | |
2748 | ||
2749 | if ($id == "search") { | |
2750 | ||
2751 | print "<input id=\"searchbox\" class=\"extSearch\" | |
2752 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
2753 | onchange=\"javascript:search()\"> | |
2754 | <select id=\"searchmodebox\"> | |
2755 | <option selected>All feeds</option> | |
2756 | <option>This feed</option> | |
2757 | </select> | |
2758 | <input type=\"submit\" | |
2759 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
2760 | <input class=\"button\" | |
2761 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2762 | value=\"Close\">"; | |
2763 | ||
2764 | } | |
2765 | ||
2766 | if ($id == "quickAddFilter") { | |
2767 | ||
2768 | $result = db_query($link, "SELECT description | |
2769 | FROM ttrss_filter_types ORDER BY description"); | |
2770 | ||
2771 | $filter_types = array(); | |
2772 | ||
2773 | while ($line = db_fetch_assoc($result)) { | |
2774 | array_push($filter_types, $line["description"]); | |
2775 | } | |
2776 | ||
2777 | print "<table>"; | |
2778 | ||
2779 | print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> "; | |
2780 | ||
2781 | print_select("fadd_match", "Title", $filter_types); | |
2782 | ||
2783 | print "</td></tr>"; | |
2784 | print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">"; | |
2785 | ||
2786 | print "<option selected id=\"0\">All feeds</option>"; | |
2787 | ||
2788 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2789 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2790 | ||
2791 | if (db_num_rows($result) > 0) { | |
2792 | print "<option disabled>--------</option>"; | |
2793 | } | |
2794 | ||
2795 | while ($line = db_fetch_assoc($result)) { | |
2796 | if ($param == $line["id"]) { | |
2797 | $selected = "selected"; | |
2798 | } else { | |
2799 | $selected = ""; | |
2800 | } | |
2801 | printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]); | |
2802 | } | |
2803 | ||
2804 | print "</select></td></tr>"; | |
2805 | ||
2806 | print "<tr><td>Action:</td>"; | |
2807 | ||
2808 | print "<td><select id=\"fadd_action\">"; | |
2809 | ||
2810 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2811 | ORDER BY name"); | |
2812 | ||
2813 | while ($line = db_fetch_assoc($result)) { | |
2814 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
2815 | } | |
2816 | ||
2817 | print "</select>"; | |
2818 | ||
2819 | print "</td></tr><tr><td colspan=\"2\" align=\"right\">"; | |
2820 | ||
2821 | print "<input type=\"submit\" | |
2822 | class=\"button\" onclick=\"javascript:qaddFilter()\" | |
2823 | value=\"Add filter\"> "; | |
2824 | ||
2825 | print "<input class=\"button\" | |
2826 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2827 | value=\"Close\">"; | |
2828 | ||
2829 | print "</td></tr></table>"; | |
2830 | } | |
2831 | } | |
2832 | ||
2833 | // update feeds of all users, may be used anonymously | |
2834 | if ($op == "globalUpdateFeeds") { | |
2835 | ||
2836 | $result = db_query($link, "SELECT id FROM ttrss_users"); | |
2837 | ||
2838 | while ($line = db_fetch_assoc($result)) { | |
2839 | $user_id = $line["id"]; | |
2840 | // print "<!-- updating feeds of uid $user_id -->"; | |
2841 | update_all_feeds($link, false, $user_id); | |
2842 | } | |
2843 | ||
2844 | print "<rpc-reply> | |
2845 | <message msg=\"All feeds updated\"/> | |
2846 | </rpc-reply>"; | |
2847 | ||
2848 | } | |
2849 | ||
2850 | if ($op == "pref-prefs") { | |
2851 | ||
2852 | $subop = $_REQUEST["subop"]; | |
2853 | ||
2854 | if ($subop == "Save configuration") { | |
2855 | ||
2856 | if (WEB_DEMO_MODE) { | |
2857 | header("Location: prefs.php"); | |
2858 | return; | |
2859 | } | |
2860 | ||
2861 | $_SESSION["prefs_op_result"] = "save-config"; | |
2862 | ||
2863 | foreach (array_keys($_POST) as $pref_name) { | |
2864 | ||
2865 | $pref_name = db_escape_string($pref_name); | |
2866 | $value = db_escape_string($_POST[$pref_name]); | |
2867 | ||
2868 | $result = db_query($link, "SELECT type_name | |
2869 | FROM ttrss_prefs,ttrss_prefs_types | |
2870 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
2871 | ||
2872 | if (db_num_rows($result) > 0) { | |
2873 | ||
2874 | $type_name = db_fetch_result($result, 0, "type_name"); | |
2875 | ||
2876 | // print "$pref_name : $type_name : $value<br>"; | |
2877 | ||
2878 | if ($type_name == "bool") { | |
2879 | if ($value == "1") { | |
2880 | $value = "true"; | |
2881 | } else { | |
2882 | $value = "false"; | |
2883 | } | |
2884 | } else if ($type_name == "integer") { | |
2885 | $value = sprintf("%d", $value); | |
2886 | } | |
2887 | ||
2888 | // print "$pref_name : $type_name : $value<br>"; | |
2889 | ||
2890 | db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' | |
2891 | WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); | |
2892 | ||
2893 | } | |
2894 | ||
2895 | header("Location: prefs.php"); | |
2896 | ||
2897 | } | |
2898 | ||
2899 | } else if ($subop == "getHelp") { | |
2900 | ||
2901 | $pref_name = db_escape_string($_GET["pn"]); | |
2902 | ||
2903 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
2904 | WHERE pref_name = '$pref_name'"); | |
2905 | ||
2906 | if (db_num_rows($result) > 0) { | |
2907 | $help_text = db_fetch_result($result, 0, "help_text"); | |
2908 | print $help_text; | |
2909 | } else { | |
2910 | print "Unknown option: $pref_name"; | |
2911 | } | |
2912 | ||
2913 | } else if ($subop == "Change password") { | |
2914 | ||
2915 | if (WEB_DEMO_MODE) { | |
2916 | header("Location: prefs.php"); | |
2917 | return; | |
2918 | } | |
2919 | ||
2920 | $old_pw = $_POST["OLD_PASSWORD"]; | |
2921 | $new_pw = $_POST["OLD_PASSWORD"]; | |
2922 | ||
2923 | $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]); | |
2924 | $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]); | |
2925 | ||
2926 | $active_uid = $_SESSION["uid"]; | |
2927 | ||
2928 | if ($old_pw && $new_pw) { | |
2929 | ||
2930 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
2931 | ||
2932 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
2933 | id = '$active_uid' AND (pwd_hash = '$old_pw' OR | |
2934 | pwd_hash = '$old_pw_hash')"); | |
2935 | ||
2936 | if (db_num_rows($result) == 1) { | |
2937 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
2938 | WHERE id = '$active_uid'"); | |
2939 | ||
2940 | $_SESSION["pwd_change_result"] = "ok"; | |
2941 | } else { | |
2942 | $_SESSION["pwd_change_result"] = "failed"; | |
2943 | } | |
2944 | } | |
2945 | ||
2946 | header("Location: prefs.php"); | |
2947 | ||
2948 | } else if ($subop == "Reset to defaults") { | |
2949 | ||
2950 | if (WEB_DEMO_MODE) { | |
2951 | header("Location: prefs.php"); | |
2952 | return; | |
2953 | } | |
2954 | ||
2955 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; | |
2956 | ||
2957 | if (DB_TYPE == "pgsql") { | |
2958 | db_query($link,"UPDATE ttrss_user_prefs | |
2959 | SET value = ttrss_prefs.def_value | |
2960 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
2961 | ttrss_prefs.pref_name = ttrss_user_prefs.pref_name"); | |
2962 | } else { | |
2963 | db_query($link, "DELETE FROM ttrss_user_prefs | |
2964 | WHERE owner_uid = ".$_SESSION["uid"]); | |
2965 | initialize_user_prefs($link, $_SESSION["uid"]); | |
2966 | } | |
2967 | ||
2968 | header("Location: prefs.php"); | |
2969 | ||
2970 | } else if ($subop == "Change theme") { | |
2971 | ||
2972 | $theme = db_escape_string($_POST["theme"]); | |
2973 | ||
2974 | if ($theme == "Default") { | |
2975 | $theme_qpart = 'NULL'; | |
2976 | } else { | |
2977 | $theme_qpart = "'$theme'"; | |
2978 | } | |
2979 | ||
2980 | $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes | |
2981 | WHERE theme_name = '$theme'"); | |
2982 | ||
2983 | if (db_num_rows($result) == 1) { | |
2984 | $theme_id = db_fetch_result($result, 0, "id"); | |
2985 | $theme_path = db_fetch_result($result, 0, "theme_path"); | |
2986 | } else { | |
2987 | $theme_id = "NULL"; | |
2988 | $theme_path = ""; | |
2989 | } | |
2990 | ||
2991 | db_query($link, "UPDATE ttrss_users SET | |
2992 | theme_id = $theme_id WHERE id = " . $_SESSION["uid"]); | |
2993 | ||
2994 | $_SESSION["theme"] = $theme_path; | |
2995 | ||
2996 | header("Location: prefs.php"); | |
2997 | ||
2998 | } else { | |
2999 | ||
3000 | if (!SINGLE_USER_MODE) { | |
3001 | ||
3002 | $result = db_query($link, "SELECT id FROM ttrss_users | |
3003 | WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR | |
3004 | pwd_hash = 'SHA1:".sha1("password")."')"); | |
3005 | ||
3006 | if (db_num_rows($result) != 0) { | |
3007 | print "<div class=\"warning\"> | |
3008 | Your password is at default value, please change it. | |
3009 | </div>"; | |
3010 | } | |
3011 | ||
3012 | if ($_SESSION["pwd_change_result"] == "failed") { | |
3013 | print "<div class=\"warning\"> | |
3014 | There was an error while changing your password. | |
3015 | </div>"; | |
3016 | } | |
3017 | ||
3018 | if ($_SESSION["pwd_change_result"] == "ok") { | |
3019 | print "<div class=\"notice\"> | |
3020 | Password changed successfully. | |
3021 | </div>"; | |
3022 | } | |
3023 | ||
3024 | $_SESSION["pwd_change_result"] = ""; | |
3025 | ||
3026 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { | |
3027 | print "<div class=\"notice\"> | |
3028 | Your configuration was reset to defaults. | |
3029 | </div>"; | |
3030 | } | |
3031 | ||
3032 | if ($_SESSION["prefs_op_result"] == "save-config") { | |
3033 | print "<div class=\"notice\"> | |
3034 | Your configuration was saved successfully. | |
3035 | </div>"; | |
3036 | } | |
3037 | ||
3038 | $_SESSION["prefs_op_result"] = ""; | |
3039 | ||
3040 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3041 | ||
3042 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3043 | print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>"; | |
3044 | ||
3045 | print "<tr><td width=\"40%\">Old password</td>"; | |
3046 | print "<td><input class=\"editbox\" type=\"password\" | |
3047 | name=\"OLD_PASSWORD\"></td></tr>"; | |
3048 | ||
3049 | print "<tr><td width=\"40%\">New password</td>"; | |
3050 | ||
3051 | print "<td><input class=\"editbox\" type=\"password\" | |
3052 | name=\"NEW_PASSWORD\"></td></tr>"; | |
3053 | ||
3054 | print "</table>"; | |
3055 | ||
3056 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3057 | ||
3058 | print "<p><input class=\"button\" type=\"submit\" | |
3059 | value=\"Change password\" name=\"subop\">"; | |
3060 | ||
3061 | print "</form>"; | |
3062 | ||
3063 | } | |
3064 | ||
3065 | $result = db_query($link, "SELECT | |
3066 | theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]); | |
3067 | ||
3068 | $user_theme_id = db_fetch_result($result, 0, "theme_id"); | |
3069 | ||
3070 | $result = db_query($link, "SELECT | |
3071 | id,theme_name FROM ttrss_themes ORDER BY theme_name"); | |
3072 | ||
3073 | if (db_num_rows($result) > 0) { | |
3074 | ||
3075 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3076 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3077 | print "<tr><td colspan='3'><h3>Themes</h3></tr></td>"; | |
3078 | print "<tr><td width=\"40%\">Select theme</td>"; | |
3079 | print "<td><select name=\"theme\">"; | |
3080 | print "<option>Default</option>"; | |
3081 | print "<option disabled>--------</option>"; | |
3082 | ||
3083 | while ($line = db_fetch_assoc($result)) { | |
3084 | if ($line["id"] == $user_theme_id) { | |
3085 | $selected = "selected"; | |
3086 | } else { | |
3087 | $selected = ""; | |
3088 | } | |
3089 | print "<option $selected>" . $line["theme_name"] . "</option>"; | |
3090 | } | |
3091 | print "</select></td></tr>"; | |
3092 | print "</table>"; | |
3093 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3094 | print "<p><input class=\"button\" type=\"submit\" | |
3095 | value=\"Change theme\" name=\"subop\">"; | |
3096 | print "</form>"; | |
3097 | } | |
3098 | ||
3099 | $result = db_query($link, "SELECT | |
3100 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, | |
3101 | section_name,def_value | |
3102 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs | |
3103 | WHERE type_id = ttrss_prefs_types.id AND | |
3104 | section_id = ttrss_prefs_sections.id AND | |
3105 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND | |
3106 | owner_uid = ".$_SESSION["uid"]." | |
3107 | ORDER BY section_id,short_desc"); | |
3108 | ||
3109 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3110 | ||
3111 | $lnum = 0; | |
3112 | ||
3113 | $active_section = ""; | |
3114 | ||
3115 | while ($line = db_fetch_assoc($result)) { | |
3116 | ||
3117 | if ($active_section != $line["section_name"]) { | |
3118 | ||
3119 | if ($active_section != "") { | |
3120 | print "</table>"; | |
3121 | } | |
3122 | ||
3123 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
3124 | ||
3125 | $active_section = $line["section_name"]; | |
3126 | ||
3127 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; | |
3128 | // print "<tr class=\"title\"> | |
3129 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
3130 | ||
3131 | $lnum = 0; | |
3132 | } | |
3133 | ||
3134 | // $class = ($lnum % 2) ? "even" : "odd"; | |
3135 | ||
3136 | print "<tr>"; | |
3137 | ||
3138 | $type_name = $line["type_name"]; | |
3139 | $pref_name = $line["pref_name"]; | |
3140 | $value = $line["value"]; | |
3141 | $def_value = $line["def_value"]; | |
3142 | $help_text = $line["help_text"]; | |
3143 | ||
3144 | print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"]; | |
3145 | ||
3146 | if ($help_text) print "<div class=\"prefHelp\">$help_text</div>"; | |
3147 | ||
3148 | print "</td>"; | |
3149 | ||
3150 | print "<td>"; | |
3151 | ||
3152 | if ($type_name == "bool") { | |
3153 | // print_select($pref_name, $value, array("true", "false")); | |
3154 | ||
3155 | if ($value == "true") { | |
3156 | $value = "Yes"; | |
3157 | } else { | |
3158 | $value = "No"; | |
3159 | } | |
3160 | ||
3161 | print_radio($pref_name, $value, array("Yes", "No")); | |
3162 | ||
3163 | } else { | |
3164 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
3165 | } | |
3166 | ||
3167 | print "</td>"; | |
3168 | ||
3169 | print "</tr>"; | |
3170 | ||
3171 | $lnum++; | |
3172 | } | |
3173 | ||
3174 | print "</table>"; | |
3175 | ||
3176 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3177 | ||
3178 | print "<p><input class=\"button\" type=\"submit\" | |
3179 | name=\"subop\" value=\"Save configuration\">"; | |
3180 | ||
3181 | print " <input class=\"button\" type=\"submit\" | |
3182 | name=\"subop\" onclick=\"return validatePrefsReset()\" | |
3183 | value=\"Reset to defaults\"></p>"; | |
3184 | ||
3185 | print "</form>"; | |
3186 | ||
3187 | } | |
3188 | ||
3189 | } | |
3190 | ||
3191 | if ($op == "pref-users") { | |
3192 | ||
3193 | $subop = $_GET["subop"]; | |
3194 | ||
3195 | if ($subop == "editSave") { | |
3196 | ||
3197 | if (!WEB_DEMO_MODE) { | |
3198 | ||
3199 | $login = db_escape_string($_GET["l"]); | |
3200 | $uid = db_escape_string($_GET["id"]); | |
3201 | $access_level = sprintf("%d", $_GET["al"]); | |
3202 | ||
3203 | db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'"); | |
3204 | ||
3205 | } | |
3206 | } else if ($subop == "remove") { | |
3207 | ||
3208 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3209 | ||
3210 | $ids = split(",", db_escape_string($_GET["ids"])); | |
3211 | ||
3212 | foreach ($ids as $id) { | |
3213 | db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]); | |
3214 | ||
3215 | } | |
3216 | } | |
3217 | } else if ($subop == "add") { | |
3218 | ||
3219 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3220 | ||
3221 | $login = db_escape_string(trim($_GET["login"])); | |
3222 | $tmp_user_pwd = make_password(8); | |
3223 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3224 | ||
3225 | db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level) | |
3226 | VALUES ('$login', '$pwd_hash', 0)"); | |
3227 | ||
3228 | ||
3229 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
3230 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
3231 | ||
3232 | if (db_num_rows($result) == 1) { | |
3233 | ||
3234 | $new_uid = db_fetch_result($result, 0, "id"); | |
3235 | ||
3236 | print "<div class=\"notice\">Added user <b>".$_GET["login"]. | |
3237 | "</b> with password <b>$tmp_user_pwd</b>.</div>"; | |
3238 | ||
3239 | initialize_user($link, $new_uid); | |
3240 | ||
3241 | } else { | |
3242 | ||
3243 | print "<div class=\"warning\">Error while adding user <b>". | |
3244 | $_GET["login"].".</b></div>"; | |
3245 | ||
3246 | } | |
3247 | } | |
3248 | } else if ($subop == "resetPass") { | |
3249 | ||
3250 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3251 | ||
3252 | $uid = db_escape_string($_GET["id"]); | |
3253 | ||
3254 | $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'"); | |
3255 | ||
3256 | $login = db_fetch_result($result, 0, "login"); | |
3257 | $tmp_user_pwd = make_password(8); | |
3258 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3259 | ||
3260 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
3261 | WHERE id = '$uid'"); | |
3262 | ||
3263 | print "<div class=\"notice\">Changed password of | |
3264 | user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>"; | |
3265 | ||
3266 | } | |
3267 | } | |
3268 | ||
3269 | print "<div class=\"prefGenericAddBox\"> | |
3270 | <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> "; | |
3271 | ||
3272 | print"<input type=\"submit\" class=\"button\" | |
3273 | onclick=\"javascript:addUser()\" value=\"Add user\"></div>"; | |
3274 | ||
3275 | $result = db_query($link, "SELECT | |
3276 | id,login,access_level, | |
3277 | SUBSTRING(last_login,1,16) as last_login | |
3278 | FROM | |
3279 | ttrss_users | |
3280 | ORDER by login"); | |
3281 | ||
3282 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
3283 | ||
3284 | print "<p><table width=\"100%\" cellspacing=\"0\" | |
3285 | class=\"prefUserList\" id=\"prefUserList\">"; | |
3286 | ||
3287 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
3288 | Select: | |
3289 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', | |
3290 | 'UMRR-', 'UMCHK-', true)\">All</a>, | |
3291 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', | |
3292 | 'UMRR-', 'UMCHK-', false)\">None</a> | |
3293 | </td</tr>"; | |
3294 | ||
3295 | print "<tr class=\"title\"> | |
3296 | <td align='center' width=\"5%\"> </td> | |
3297 | <td width='30%'>Username</td> | |
3298 | <td width='30%'>Access Level</td> | |
3299 | <td width='30%'>Last login</td></tr>"; | |
3300 | ||
3301 | $lnum = 0; | |
3302 | ||
3303 | while ($line = db_fetch_assoc($result)) { | |
3304 | ||
3305 | $class = ($lnum % 2) ? "even" : "odd"; | |
3306 | ||
3307 | $uid = $line["id"]; | |
3308 | $edit_uid = $_GET["id"]; | |
3309 | ||
3310 | if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) { | |
3311 | $class .= "Grayed"; | |
3312 | $this_row_id = ""; | |
3313 | } else { | |
3314 | $this_row_id = "id=\"UMRR-$uid\""; | |
3315 | } | |
3316 | ||
3317 | print "<tr class=\"$class\" $this_row_id>"; | |
3318 | ||
3319 | $line["login"] = htmlspecialchars($line["login"]); | |
3320 | ||
3321 | $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'), | |
3322 | strtotime($line["last_login"])); | |
3323 | ||
3324 | if ($uid == $_SESSION["uid"]) { | |
3325 | ||
3326 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" | |
3327 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
3328 | ||
3329 | print "<td>".$line["login"]."</td>"; | |
3330 | print "<td>".$line["access_level"]."</td>"; | |
3331 | ||
3332 | } else if (!$edit_uid || $subop != "edit") { | |
3333 | ||
3334 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
3335 | type=\"checkbox\" id=\"UMCHK-$uid\"></td>"; | |
3336 | ||
3337 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
3338 | $line["login"] . "</td>"; | |
3339 | ||
3340 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
3341 | $line["access_level"] . "</td>"; | |
3342 | ||
3343 | } else if ($uid != $edit_uid) { | |
3344 | ||
3345 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
3346 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
3347 | ||
3348 | print "<td>".$line["login"]."</td>"; | |
3349 | print "<td>".$line["access_level"]."</td>"; | |
3350 | ||
3351 | } else { | |
3352 | ||
3353 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
3354 | ||
3355 | print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"]. | |
3356 | "\"></td>"; | |
3357 | ||
3358 | print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"]. | |
3359 | "\"></td>"; | |
3360 | ||
3361 | } | |
3362 | ||
3363 | print "<td>".$line["last_login"]."</td>"; | |
3364 | ||
3365 | print "</tr>"; | |
3366 | ||
3367 | ++$lnum; | |
3368 | } | |
3369 | ||
3370 | print "</table>"; | |
3371 | ||
3372 | print "<p>"; | |
3373 | ||
3374 | if ($subop == "edit") { | |
3375 | print "Edit label: | |
3376 | <input type=\"submit\" class=\"button\" | |
3377 | onclick=\"javascript:userEditCancel()\" value=\"Cancel\"> | |
3378 | <input type=\"submit\" class=\"button\" | |
3379 | onclick=\"javascript:userEditSave()\" value=\"Save\">"; | |
3380 | ||
3381 | } else { | |
3382 | ||
3383 | print " | |
3384 | Selection: | |
3385 | <input type=\"submit\" class=\"button\" | |
3386 | onclick=\"javascript:selectedUserDetails()\" value=\"User details\"> | |
3387 | <input type=\"submit\" class=\"button\" | |
3388 | onclick=\"javascript:editSelectedUser()\" value=\"Edit\"> | |
3389 | <input type=\"submit\" class=\"button\" | |
3390 | onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\"> | |
3391 | <input type=\"submit\" class=\"button\" | |
3392 | onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">"; | |
3393 | ||
3394 | } | |
3395 | } | |
3396 | ||
3397 | if ($op == "user-details") { | |
3398 | ||
3399 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { | |
3400 | return; | |
3401 | } | |
3402 | ||
3403 | /* print "<html><head> | |
3404 | <title>Tiny Tiny RSS : User Details</title> | |
3405 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
3406 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
3407 | </head><body>"; */ | |
3408 | ||
3409 | $uid = sprintf("%d", $_GET["id"]); | |
3410 | ||
3411 | print "<div class='infoBoxContents'>"; | |
3412 | ||
3413 | $result = db_query($link, "SELECT login, | |
3414 | SUBSTRING(last_login,1,16) AS last_login, | |
3415 | access_level, | |
3416 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3417 | WHERE owner_uid = id) AS stored_articles | |
3418 | FROM ttrss_users | |
3419 | WHERE id = '$uid'"); | |
3420 | ||
3421 | if (db_num_rows($result) == 0) { | |
3422 | print "<h1>User not found</h1>"; | |
3423 | return; | |
3424 | } | |
3425 | ||
3426 | print "<h1>User Details</h1>"; | |
3427 | ||
3428 | print "<table width='100%'>"; | |
3429 | ||
3430 | $login = db_fetch_result($result, 0, "login"); | |
3431 | $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
3432 | strtotime(db_fetch_result($result, 0, "last_login"))); | |
3433 | $access_level = db_fetch_result($result, 0, "access_level"); | |
3434 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); | |
3435 | ||
3436 | print "<tr><td>Username</td><td>$login</td></tr>"; | |
3437 | print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
3438 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
3439 | print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>"; | |
3440 | ||
3441 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
3442 | WHERE owner_uid = '$uid'"); | |
3443 | ||
3444 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
3445 | ||
3446 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; | |
3447 | ||
3448 | /* $result = db_query($link, "SELECT | |
3449 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size | |
3450 | FROM ttrss_user_entries,ttrss_entries | |
3451 | WHERE owner_uid = '$uid' AND ref_id = id"); | |
3452 | ||
3453 | $db_size = round(db_fetch_result($result, 0, "db_size") / 1024); | |
3454 | ||
3455 | print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */ | |
3456 | ||
3457 | print "</table>"; | |
3458 | ||
3459 | print "<h1>Subscribed feeds</h1>"; | |
3460 | ||
3461 | $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds | |
3462 | WHERE owner_uid = '$uid' ORDER BY title LIMIT 20"); | |
3463 | ||
3464 | print "<ul class=\"nomarks\">"; | |
3465 | ||
3466 | while ($line = db_fetch_assoc($result)) { | |
3467 | ||
3468 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
3469 | ||
3470 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
3471 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; | |
3472 | } else { | |
3473 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
3474 | } | |
3475 | ||
3476 | print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; | |
3477 | } | |
3478 | ||
3479 | if (db_num_rows($result) < $num_feeds) { | |
3480 | // FIXME - add link to show ALL subscribed feeds here somewhere | |
3481 | print "<li><img | |
3482 | class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>"; | |
3483 | } | |
3484 | ||
3485 | print "</ul>"; | |
3486 | ||
3487 | print "</div>"; | |
3488 | ||
3489 | print "<div align='center'> | |
3490 | <input type='submit' class='button' | |
3491 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
3492 | ||
3493 | // print "</body></html>"; | |
3494 | ||
3495 | } | |
3496 | ||
3497 | if ($op == "feed-details") { | |
3498 | ||
3499 | // $feed_id = $_GET["id"]; | |
3500 | ||
3501 | $feed_ids = split(",", db_escape_string($_GET["id"])); | |
3502 | ||
3503 | print "<div class=\"infoBoxContents\">"; | |
3504 | ||
3505 | foreach ($feed_ids as $feed_id) { | |
3506 | ||
3507 | $result = db_query($link, | |
3508 | "SELECT | |
3509 | title,feed_url, | |
3510 | SUBSTRING(last_updated,1,16) as last_updated, | |
3511 | icon_url,site_url, | |
3512 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3513 | WHERE feed_id = id) AS total, | |
3514 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3515 | WHERE feed_id = id AND unread = true) AS unread, | |
3516 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3517 | WHERE feed_id = id AND marked = true) AS marked | |
3518 | FROM ttrss_feeds | |
3519 | WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]); | |
3520 | ||
3521 | if (db_num_rows($result) == 0) return; | |
3522 | ||
3523 | $title = db_unescape_string(db_fetch_result($result, 0, "title")); | |
3524 | $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
3525 | strtotime(db_fetch_result($result, 0, "last_updated"))); | |
3526 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
3527 | $icon_url = db_fetch_result($result, 0, "icon_url"); | |
3528 | $total = db_fetch_result($result, 0, "total"); | |
3529 | $unread = db_fetch_result($result, 0, "unread"); | |
3530 | $marked = db_fetch_result($result, 0, "marked"); | |
3531 | $site_url = db_fetch_result($result, 0, "site_url"); | |
3532 | ||
3533 | $result = db_query($link, "SELECT COUNT(id) AS subscribed | |
3534 | FROM ttrss_feeds WHERE feed_url = '$feed_url'"); | |
3535 | ||
3536 | $subscribed = db_fetch_result($result, 0, "subscribed"); | |
3537 | ||
3538 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
3539 | ||
3540 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
3541 | $feed_icon = "<img width=\"16\" height=\"16\" | |
3542 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
3543 | } else { | |
3544 | $feed_icon = ""; | |
3545 | } | |
3546 | ||
3547 | print "<h1>$feed_icon $title</h1>"; | |
3548 | ||
3549 | print "<table width='100%'>"; | |
3550 | ||
3551 | if ($site_url) { | |
3552 | print "<tr><td width='30%'>Link</td> | |
3553 | <td><a href=\"$site_url\">$site_url</a> | |
3554 | <a href=\"$feed_url\">(feed)</a></td> | |
3555 | </td></tr>"; | |
3556 | } else { | |
3557 | print "<tr><td width='30%'>Feed URL</td> | |
3558 | <td><a href=\"$feed_url\">$feed_url</a></td></tr>"; | |
3559 | } | |
3560 | print "<tr><td>Last updated</td><td>$last_updated</td></tr>"; | |
3561 | print "<tr><td>Total articles</td><td>$total</td></tr>"; | |
3562 | print "<tr><td>Unread articles</td><td>$unread</td></tr>"; | |
3563 | print "<tr><td>Starred articles</td><td>$marked</td></tr>"; | |
3564 | print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>"; | |
3565 | ||
3566 | print "</table>"; | |
3567 | ||
3568 | /* $result = db_query($link, "SELECT title, | |
3569 | SUBSTRING(updated,1,16) AS updated,unread | |
3570 | FROM ttrss_entries,ttrss_user_entries | |
3571 | WHERE ref_id = id AND feed_id = '$feed_id' | |
3572 | ORDER BY date_entered DESC LIMIT 5"); | |
3573 | ||
3574 | if (db_num_rows($result) > 0) { | |
3575 | ||
3576 | print "<h1>Latest headlines</h1>"; | |
3577 | ||
3578 | print "<ul class=\"nomarks\">"; | |
3579 | ||
3580 | while ($line = db_fetch_assoc($result)) { | |
3581 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
3582 | $line["title"] = "<b>" . $line["title"] . "</b>"; | |
3583 | } | |
3584 | print "<li>" . $line["title"]. | |
3585 | " <span class=\"insensitive\">(" . | |
3586 | date(get_pref($link, 'SHORT_DATE_FORMAT'), | |
3587 | strtotime($line["updated"])). | |
3588 | ")</span></li>"; | |
3589 | } | |
3590 | ||
3591 | print "</ul>"; | |
3592 | ||
3593 | } */ | |
3594 | } | |
3595 | ||
3596 | print "</div>"; | |
3597 | ||
3598 | print "<div align='center'> | |
3599 | <input type='submit' class='button' | |
3600 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
3601 | } | |
3602 | ||
3603 | db_close($link); | |
3604 | ?> | |
3605 | ||
3606 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
3607 |