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