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