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