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