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