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