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