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