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