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