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