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