]>
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 AD |
1460 | if ($feed_site_url) { |
1461 | print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>"; | |
1462 | } else { | |
1463 | print $feed_title; | |
1464 | } | |
1465 | ||
1466 | print "</td>"; | |
1467 | print "</tr></table>"; | |
1468 | ||
98bea1b1 AD |
1469 | } |
1470 | ||
1471 | if (db_num_rows($result) > 0) { | |
1472 | ||
1473 | print_headline_subtoolbar($link, $feed_site_url, $feed_title); | |
1474 | ||
386cbf27 | 1475 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
adccd201 AD |
1476 | print "<table class=\"headlinesList\" id=\"headlinesList\" |
1477 | cellspacing=\"0\" width=\"100%\">"; | |
f4c10d44 | 1478 | } |
386cbf27 | 1479 | |
e5a99b88 AD |
1480 | $lnum = 0; |
1481 | ||
1482 | error_reporting (DEFAULT_ERROR_LEVEL); | |
1483 | ||
1484 | $num_unread = 0; | |
1485 | ||
1486 | while ($line = db_fetch_assoc($result)) { | |
adccd201 | 1487 | |
e5a99b88 AD |
1488 | $class = ($lnum % 2) ? "even" : "odd"; |
1489 | ||
1490 | $id = $line["id"]; | |
1491 | $feed_id = $line["feed_id"]; | |
1492 | ||
1493 | if ($line["last_read"] == "" && | |
1494 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
1495 | ||
1496 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
1497 | alt=\"Updated\">"; | |
1498 | } else { | |
1499 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
1500 | alt=\"Updated\">"; | |
1501 | } | |
1502 | ||
1503 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
1504 | $class .= "Unread"; | |
1505 | ++$num_unread; | |
386cbf27 | 1506 | $is_unread = true; |
adccd201 | 1507 | } else { |
386cbf27 | 1508 | $is_unread = false; |
e5a99b88 AD |
1509 | } |
1510 | ||
1511 | if ($line["marked"] == "t" || $line["marked"] == "1") { | |
1512 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" | |
9932fb06 | 1513 | alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>"; |
e5a99b88 AD |
1514 | } else { |
1515 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
9932fb06 | 1516 | alt=\"Set mark\" onclick='javascript:toggleMark($id)'>"; |
e5a99b88 AD |
1517 | } |
1518 | ||
e454a889 | 1519 | $content_link = "<a href=\"javascript:view($id,$feed_id);\">" . |
e5a99b88 | 1520 | $line["title"] . "</a>"; |
adccd201 | 1521 | |
e5a99b88 AD |
1522 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { |
1523 | $updated_fmt = smart_date_time(strtotime($line["updated"])); | |
1524 | } else { | |
1525 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
1526 | $updated_fmt = date($short_date, strtotime($line["updated"])); | |
1527 | } | |
adccd201 AD |
1528 | |
1529 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
8fd0c717 | 1530 | $content_preview = truncate_string(strip_tags($line["content_preview"]), |
070d0d2a | 1531 | 100); |
adccd201 AD |
1532 | } |
1533 | ||
386cbf27 | 1534 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
adccd201 AD |
1535 | |
1536 | print "<tr class='$class' id='RROW-$id'>"; | |
adccd201 AD |
1537 | |
1538 | print "<td class='hlUpdatePic'>$update_pic</td>"; | |
1539 | ||
1540 | print "<td class='hlSelectRow'> | |
1541 | <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\" | |
1542 | class=\"feedCheckBox\" id=\"RCHK-$id\"> | |
1543 | </td>"; | |
1544 | ||
1545 | print "<td class='hlMarkedPic'>$marked_pic</td>"; | |
1546 | ||
1547 | if ($line["feed_title"]) { | |
1548 | print "<td class='hlContent'>$content_link</td>"; | |
1549 | print "<td class='hlFeed'> | |
9b1424fe AD |
1550 | <a href='javascript:viewfeed($feed_id)'>". |
1551 | $line["feed_title"]."</a> </td>"; | |
adccd201 | 1552 | } else { |
de244d27 | 1553 | print "<td class='hlContent' valign='middle'>"; |
adccd201 | 1554 | |
e454a889 | 1555 | print "<a href=\"javascript:view($id,$feed_id);\">" . |
adccd201 AD |
1556 | $line["title"]; |
1557 | ||
1558 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
1559 | ||
1560 | if ($content_preview) { | |
1561 | print "<span class=\"contentPreview\"> - $content_preview</span>"; | |
1562 | } | |
1563 | } | |
1564 | ||
1565 | print "</a>"; | |
1566 | print "</td>"; | |
1567 | } | |
1568 | ||
1569 | print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>"; | |
1570 | ||
1571 | print "</tr>"; | |
1572 | ||
1573 | } else { | |
386cbf27 AD |
1574 | |
1575 | if ($is_unread) { | |
1576 | $add_class = "Unread"; | |
1577 | } else { | |
1578 | $add_class = ""; | |
1579 | } | |
1580 | ||
1581 | print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">"; | |
1582 | ||
1583 | print "<div class=\"cdmHeader\">"; | |
adccd201 | 1584 | |
386cbf27 AD |
1585 | print "<div style=\"float : right\">$updated_fmt</div>"; |
1586 | ||
86383df6 | 1587 | print "<a target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>"; |
adccd201 | 1588 | |
386cbf27 AD |
1589 | if ($line["feed_title"]) { |
1590 | print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)"; | |
adccd201 | 1591 | } |
adccd201 | 1592 | |
386cbf27 AD |
1593 | print "</div>"; |
1594 | ||
1595 | print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>"; | |
1596 | ||
1597 | print "<div style=\"float : right\">$marked_pic</div> | |
1598 | <div class=\"cdmFooter\"> | |
1599 | <input type=\"checkbox\" onclick=\"toggleSelectRowById(this, | |
1600 | 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>"; | |
1601 | ||
1602 | print "</div>"; | |
1603 | ||
1604 | } | |
e5a99b88 AD |
1605 | |
1606 | ++$lnum; | |
254e0e4b | 1607 | } |
adccd201 | 1608 | |
386cbf27 | 1609 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
adccd201 | 1610 | print "</table>"; |
adccd201 | 1611 | } |
d76a3b03 | 1612 | |
e0a7121b AD |
1613 | print_headline_subtoolbar($link, |
1614 | "javascript:catchupPage()", "Mark page as read", true); | |
98bea1b1 AD |
1615 | |
1616 | ||
e5a99b88 AD |
1617 | } else { |
1618 | print "<div width='100%' align='center'>No articles found.</div>"; | |
a1a8a2be | 1619 | } |
d76a3b03 | 1620 | |
386cbf27 | 1621 | print "</div>"; |
d76a3b03 | 1622 | |
386cbf27 AD |
1623 | print "<script type=\"text/javascript\"> |
1624 | document.onkeydown = hotkey_handler; | |
5a494a0b | 1625 | // if (parent.daemon_enabled) parent.updateTitle('$feed_title'); |
386cbf27 AD |
1626 | update_all_counters('$feed'); |
1627 | </script>"; | |
adccd201 | 1628 | |
97dcd654 AD |
1629 | print ' |
1630 | <script type="text/javascript"> | |
1631 | /* for IE */ | |
1632 | function statechange() { | |
1633 | if (document.readyState == "interactive") init(); | |
1634 | } | |
1635 | ||
1636 | if (document.readyState) { | |
1637 | if (document.readyState == "interactive" || document.readyState == "complete") { | |
1638 | init(); | |
1639 | } else { | |
1640 | document.onreadystatechange = statechange; | |
1641 | } | |
1642 | } | |
1643 | </script>'; | |
1644 | ||
59b8192f | 1645 | print "</body></html>"; |
1cd17194 AD |
1646 | } |
1647 | ||
0e091d38 | 1648 | if ($op == "pref-rpc") { |
331900c6 | 1649 | |
0e091d38 | 1650 | $subop = $_GET["subop"]; |
331900c6 | 1651 | |
83fe4d6d | 1652 | if ($subop == "unread") { |
f932bc9f | 1653 | $ids = split(",", db_escape_string($_GET["ids"])); |
83fe4d6d | 1654 | foreach ($ids as $id) { |
a5873b2e AD |
1655 | db_query($link, "UPDATE ttrss_user_entries SET unread = true |
1656 | WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
83fe4d6d | 1657 | } |
0e091d38 | 1658 | |
a5873b2e | 1659 | print "Marked selected feeds as unread."; |
83fe4d6d AD |
1660 | } |
1661 | ||
1662 | if ($subop == "read") { | |
f932bc9f | 1663 | $ids = split(",", db_escape_string($_GET["ids"])); |
83fe4d6d | 1664 | foreach ($ids as $id) { |
a5873b2e AD |
1665 | db_query($link, "UPDATE ttrss_user_entries |
1666 | SET unread = false,last_read = NOW() WHERE | |
1667 | feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
83fe4d6d | 1668 | } |
0e091d38 | 1669 | |
a5873b2e | 1670 | print "Marked selected feeds as read."; |
0e091d38 AD |
1671 | |
1672 | } | |
1673 | ||
1674 | } | |
1675 | ||
1676 | if ($op == "pref-feeds") { | |
1677 | ||
47c6c988 AD |
1678 | $subop = $_REQUEST["subop"]; |
1679 | $quiet = $_REQUEST["quiet"]; | |
0e091d38 | 1680 | |
a0476535 AD |
1681 | if ($subop == "massSubscribe") { |
1682 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1683 | ||
a7f22b70 AD |
1684 | $subscribed = array(); |
1685 | ||
a0476535 AD |
1686 | foreach ($ids as $id) { |
1687 | $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds | |
1688 | WHERE id = '$id'"); | |
1689 | ||
1690 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
1691 | $title = db_fetch_result($result, 0, "title"); | |
1692 | ||
1693 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
1694 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
1695 | ||
1696 | if (db_num_rows($result) == 0) { | |
1697 | $result = db_query($link, | |
1698 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) | |
1699 | VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); | |
a7f22b70 AD |
1700 | |
1701 | array_push($subscribed, $title); | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | if (count($subscribed) > 0) { | |
1706 | print "<div class=\"notice\">"; | |
1707 | print "<b>Subscribed to feeds:</b>"; | |
1708 | print "<ul class=\"nomarks\">"; | |
1709 | foreach ($subscribed as $title) { | |
1710 | print "<li>$title</li>"; | |
a0476535 | 1711 | } |
a7f22b70 AD |
1712 | print "</ul>"; |
1713 | print "</div>"; | |
a0476535 AD |
1714 | } |
1715 | } | |
1716 | ||
f9cb39ac | 1717 | if ($subop == "browse") { |
e2f728be AD |
1718 | |
1719 | if (!ENABLE_FEED_BROWSER) { | |
1720 | print "Feed browser is administratively disabled."; | |
1721 | return; | |
1722 | } | |
f9cb39ac AD |
1723 | |
1724 | print "<div class=\"infoBoxContents\">"; | |
1725 | ||
1726 | print "<h1>Feed browser</h1>"; | |
1727 | ||
1728 | print "<p>Showing top 50 registered feeds, sorted by popularity:</p>"; | |
1729 | ||
1730 | $result = db_query($link, "SELECT feed_url,count(id) AS subscribers | |
e3c99f3b AD |
1731 | FROM ttrss_feeds |
1732 | WHERE auth_login = '' AND auth_pass = '' AND private = false | |
24b18114 | 1733 | GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50"); |
f9cb39ac AD |
1734 | |
1735 | print "<ul class='browseFeedList' id='browseFeedList'>"; | |
dc932d0a AD |
1736 | |
1737 | $feedctr = 0; | |
f9cb39ac AD |
1738 | |
1739 | while ($line = db_fetch_assoc($result)) { | |
1740 | $feed_url = $line["feed_url"]; | |
1741 | $subscribers = $line["subscribers"]; | |
dc932d0a AD |
1742 | |
1743 | $sub_result = db_query($link, "SELECT id | |
1744 | FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" . | |
1745 | $_SESSION["uid"]); | |
1746 | ||
1747 | if (db_num_rows($sub_result) > 0) { | |
1748 | continue; // already subscribed | |
1749 | } | |
f9cb39ac AD |
1750 | |
1751 | $det_result = db_query($link, "SELECT site_url,title,id | |
1752 | FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1"); | |
1753 | ||
1754 | $details = db_fetch_assoc($det_result); | |
1755 | ||
1756 | $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico"; | |
1757 | ||
1758 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1759 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . | |
1760 | "/".$details["id"].".ico\">"; | |
1761 | } else { | |
1762 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
1763 | } | |
1764 | ||
b92e6209 AD |
1765 | $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' |
1766 | type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">"; | |
f9cb39ac | 1767 | |
b92e6209 AD |
1768 | $class = ($feedctr % 2) ? "even" : "odd"; |
1769 | ||
1770 | print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box". | |
1771 | "$feed_icon " . db_unescape_string($details["title"]) . | |
f9cb39ac | 1772 | " <span class='subscribers'>($subscribers)</span></li>"; |
dc932d0a AD |
1773 | |
1774 | ++$feedctr; | |
1775 | } | |
1776 | ||
1777 | if ($feedctr == 0) { | |
1778 | print "<li>No feeds found to subscribe.</li>"; | |
1779 | } | |
f9cb39ac AD |
1780 | |
1781 | print "</ul>"; | |
1782 | ||
1783 | print "<div align='center'> | |
f9cb39ac | 1784 | <input type=\"submit\" class=\"button\" |
d10fabe4 AD |
1785 | onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\"> |
1786 | <input type='submit' class='button' | |
1787 | onclick=\"closeInfoBox()\" value=\"Cancel\"></div>"; | |
f9cb39ac AD |
1788 | |
1789 | print "</div>"; | |
1790 | return; | |
1791 | } | |
1792 | ||
0ea4fb50 AD |
1793 | if ($subop == "editfeed") { |
1794 | $feed_id = db_escape_string($_GET["id"]); | |
1795 | ||
1796 | $result = db_query($link, | |
1797 | "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND | |
1798 | owner_uid = " . $_SESSION["uid"]); | |
1799 | ||
1800 | $title = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
1801 | 0, "title"))); | |
1802 | ||
1803 | print "<div class=\"infoBoxContents\">"; | |
1804 | ||
1805 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
1806 | ||
1807 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1808 | $feed_icon = "<img width=\"16\" height=\"16\" | |
1809 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
1810 | } else { | |
1811 | $feed_icon = ""; | |
1812 | } | |
1813 | ||
1814 | print "<h1>$feed_icon $title</h1>"; | |
1815 | ||
1816 | print "<table width='100%'>"; | |
1817 | ||
1818 | $row_class = "odd"; | |
1819 | ||
1820 | print "<tr class='$row_class'><td>Title:</td>"; | |
1821 | print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>"; | |
1822 | ||
1823 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
1824 | $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
1825 | 0, "feed_url"))); | |
1826 | $row_class = toggleEvenOdd($row_class); | |
1827 | ||
1828 | print "<tr class='$row_class'><td>Feed URL:</td>"; | |
1829 | print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>"; | |
1830 | ||
1831 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1832 | ||
1833 | $cat_id = db_fetch_result($result, 0, "cat_id"); | |
1834 | ||
1835 | $row_class = toggleEvenOdd($row_class); | |
1836 | ||
1837 | print "<tr class='$row_class'><td>Category:</td>"; | |
1838 | print "<td>"; | |
1839 | print "<select id=\"iedit_fcat\">"; | |
1840 | print "<option id=\"0\">Uncategorized</option>"; | |
1841 | ||
1842 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
1843 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1844 | ||
1845 | if (db_num_rows($tmp_result) > 0) { | |
1846 | print "<option disabled>--------</option>"; | |
1847 | } | |
1848 | ||
1849 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1850 | if ($tmp_line["id"] == $cat_id) { | |
1851 | $is_selected = "selected"; | |
1852 | } else { | |
1853 | $is_selected = ""; | |
1854 | } | |
1855 | printf("<option $is_selected id='%d'>%s</option>", | |
1856 | $tmp_line["id"], $tmp_line["title"]); | |
1857 | } | |
1858 | ||
1859 | print "</select></td>"; | |
1860 | print "</td></tr>"; | |
1861 | ||
1862 | } | |
1863 | ||
1864 | $update_interval = db_fetch_result($result, 0, "update_interval"); | |
1865 | $row_class = toggleEvenOdd($row_class); | |
1866 | ||
1867 | print "<tr class='$row_class'><td>Update Interval:</td>"; | |
1868 | print "<td><input id=\"iedit_updintl\" | |
1869 | value=\"$update_interval\"></td></tr>"; | |
1870 | ||
1da7e457 AD |
1871 | $row_class = toggleEvenOdd($row_class); |
1872 | print "<tr class='$row_class'><td>Link to:</td>"; | |
1873 | ||
3b0027a4 AD |
1874 | $tmp_result = db_query($link, "SELECT COUNT(id) AS count |
1875 | FROM ttrss_feeds WHERE parent_feed = '$feed_id'"); | |
1876 | ||
1877 | $linked_count = db_fetch_result($tmp_result, 0, "count"); | |
1878 | ||
1da7e457 | 1879 | $parent_feed = db_fetch_result($result, 0, "parent_feed"); |
3b0027a4 AD |
1880 | |
1881 | if ($linked_count > 0) { | |
1882 | $disabled = "disabled"; | |
1883 | } | |
1884 | ||
1885 | print "<select $disabled id=\"iedit_parent_feed\">"; | |
1886 | ||
eac46afb | 1887 | print "<option id=\"0\">Not linked</option>"; |
1da7e457 | 1888 | |
8a53e029 AD |
1889 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
1890 | if ($cat_id) { | |
1891 | $cat_qpart = "AND cat_id = '$cat_id'"; | |
1892 | } else { | |
1893 | $cat_qpart = "AND cat_id IS NULL"; | |
1894 | } | |
1895 | } | |
1896 | ||
1da7e457 | 1897 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds |
262c2426 AD |
1898 | WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." |
1899 | $cat_qpart ORDER BY title"); | |
1da7e457 AD |
1900 | |
1901 | if (db_num_rows($tmp_result) > 0) { | |
1902 | print "<option disabled>--------</option>"; | |
1903 | } | |
1904 | ||
1905 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1906 | if ($tmp_line["id"] == $parent_feed) { | |
1907 | $is_selected = "selected"; | |
1908 | } else { | |
1909 | $is_selected = ""; | |
1910 | } | |
1911 | printf("<option $is_selected id='%d'>%s</option>", | |
1912 | $tmp_line["id"], $tmp_line["title"]); | |
1913 | } | |
1914 | ||
1915 | print "</select></td>"; | |
1916 | print "</td></tr>"; | |
1917 | ||
0ea4fb50 AD |
1918 | $purge_interval = db_fetch_result($result, 0, "purge_interval"); |
1919 | $row_class = toggleEvenOdd($row_class); | |
1920 | ||
1921 | print "<tr class='$row_class'><td>Purge Days:</td>"; | |
1922 | print "<td><input id=\"iedit_purgintl\" | |
1923 | value=\"$purge_interval\"></td></tr>"; | |
1924 | ||
47c6c988 AD |
1925 | // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>"; |
1926 | ||
1927 | $row_class = toggleEvenOdd($row_class); | |
1928 | $auth_login = db_fetch_result($result, 0, "auth_login"); | |
1929 | ||
1930 | print "<tr class='$row_class'><td>Login:</td>"; | |
1931 | print "<td><input id=\"iedit_login\" | |
1932 | value=\"$auth_login\"></td></tr>"; | |
1933 | ||
1934 | $row_class = toggleEvenOdd($row_class); | |
1935 | $auth_pass = db_fetch_result($result, 0, "auth_pass"); | |
1936 | ||
1937 | print "<tr class='$row_class'><td>Password:</td>"; | |
1938 | print "<td><input type=\"password\" id=\"iedit_pass\" | |
1939 | value=\"$auth_pass\"></td></tr>"; | |
1940 | ||
e3c99f3b AD |
1941 | $row_class = toggleEvenOdd($row_class); |
1942 | $private = sql_bool_to_bool(db_fetch_result($result, 0, "private")); | |
1943 | ||
1944 | if ($private) { | |
1945 | $checked = "checked"; | |
1946 | } else { | |
1947 | $checked = ""; | |
1948 | } | |
1949 | ||
1950 | print "<tr class='$row_class'><td>Options:</td>"; | |
1951 | print "<td><input type=\"checkbox\" id=\"iedit_private\" | |
88d9259a AD |
1952 | $checked><label for=\"iedit_private\">Hide from feed browser</label> |
1953 | </td></tr>"; | |
e3c99f3b | 1954 | |
0ea4fb50 AD |
1955 | print "</table>"; |
1956 | print "</div>"; | |
1957 | ||
1958 | print "<div align='center'> | |
0ea4fb50 | 1959 | <input type=\"submit\" class=\"button\" |
d10fabe4 AD |
1960 | onclick=\"feedEditSave()\" value=\"Save\"> |
1961 | <input type='submit' class='button' | |
1962 | onclick=\"feedEditCancel()\" value=\"Cancel\"></div>"; | |
0ea4fb50 AD |
1963 | return; |
1964 | } | |
1965 | ||
508a81e1 | 1966 | if ($subop == "editSave") { |
47c6c988 AD |
1967 | $feed_title = db_escape_string($_POST["t"]); |
1968 | $feed_link = db_escape_string($_POST["l"]); | |
1969 | $upd_intl = db_escape_string($_POST["ui"]); | |
1970 | $purge_intl = db_escape_string($_POST["pi"]); | |
1971 | $feed_id = db_escape_string($_POST["id"]); | |
1972 | $cat_id = db_escape_string($_POST["catid"]); | |
1973 | $auth_login = db_escape_string($_POST["login"]); | |
1974 | $auth_pass = db_escape_string($_POST["pass"]); | |
1da7e457 | 1975 | $parent_feed = db_escape_string($_POST["pfeed"]); |
19ded366 | 1976 | $private = db_escape_string($_POST["is_pvt"]); |
508a81e1 | 1977 | |
d148926e AD |
1978 | if (strtoupper($upd_intl) == "DEFAULT") |
1979 | $upd_intl = 0; | |
1980 | ||
a88c1f36 AD |
1981 | if (strtoupper($upd_intl) == "DISABLED") |
1982 | $upd_intl = -1; | |
1983 | ||
5d73494a AD |
1984 | if (strtoupper($purge_intl) == "DEFAULT") |
1985 | $purge_intl = 0; | |
1986 | ||
140aae81 AD |
1987 | if (strtoupper($purge_intl) == "DISABLED") |
1988 | $purge_intl = -1; | |
1989 | ||
91ff844a AD |
1990 | if ($cat_id != 0) { |
1991 | $category_qpart = "cat_id = '$cat_id'"; | |
1992 | } else { | |
1993 | $category_qpart = 'cat_id = NULL'; | |
1994 | } | |
1995 | ||
1da7e457 AD |
1996 | if ($parent_feed != 0) { |
1997 | $parent_qpart = "parent_feed = '$parent_feed'"; | |
1998 | } else { | |
1999 | $parent_qpart = 'parent_feed = NULL'; | |
2000 | } | |
2001 | ||
648472a7 | 2002 | $result = db_query($link, "UPDATE ttrss_feeds SET |
91ff844a | 2003 | $category_qpart, |
1da7e457 | 2004 | $parent_qpart, |
d148926e | 2005 | title = '$feed_title', feed_url = '$feed_link', |
5d73494a | 2006 | update_interval = '$upd_intl', |
47c6c988 AD |
2007 | purge_interval = '$purge_intl', |
2008 | auth_login = '$auth_login', | |
e3c99f3b AD |
2009 | auth_pass = '$auth_pass', |
2010 | private = '$private' | |
f72dbbde | 2011 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); |
5ddadb4c AD |
2012 | } |
2013 | ||
2014 | if ($subop == "saveCat") { | |
2015 | $cat_title = db_escape_string($_GET["title"]); | |
2016 | $cat_id = db_escape_string($_GET["id"]); | |
2017 | ||
2018 | $result = db_query($link, "UPDATE ttrss_feed_categories SET | |
2019 | title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); | |
508a81e1 | 2020 | |
83fe4d6d AD |
2021 | } |
2022 | ||
331900c6 | 2023 | if ($subop == "remove") { |
331900c6 | 2024 | |
b0b4abcf | 2025 | if (!WEB_DEMO_MODE) { |
331900c6 | 2026 | |
f932bc9f | 2027 | $ids = split(",", db_escape_string($_GET["ids"])); |
b0b4abcf AD |
2028 | |
2029 | foreach ($ids as $id) { | |
f72dbbde AD |
2030 | db_query($link, "DELETE FROM ttrss_feeds |
2031 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
4769ddaf | 2032 | |
273a2f6b | 2033 | $icons_dir = ICONS_DIR; |
d5caaae5 | 2034 | |
4769ddaf AD |
2035 | if (file_exists($icons_dir . "/$id.ico")) { |
2036 | unlink($icons_dir . "/$id.ico"); | |
d5caaae5 | 2037 | } |
b0b4abcf | 2038 | } |
331900c6 AD |
2039 | } |
2040 | } | |
2041 | ||
2042 | if ($subop == "add") { | |
b0b4abcf AD |
2043 | |
2044 | if (!WEB_DEMO_MODE) { | |
331900c6 | 2045 | |
b6b535ca | 2046 | $feed_link = db_escape_string(trim($_GET["link"])); |
15da5cc1 AD |
2047 | $cat_id = db_escape_string($_GET["cid"]); |
2048 | ||
5edfe303 | 2049 | if ($cat_id == "0" || !$cat_id) { |
15da5cc1 AD |
2050 | $cat_qpart = "NULL"; |
2051 | } else { | |
2052 | $cat_qpart = "'$cat_id'"; | |
2053 | } | |
331900c6 | 2054 | |
648472a7 | 2055 | $result = db_query($link, |
7e9a3986 AD |
2056 | "SELECT id FROM ttrss_feeds |
2057 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
2058 | ||
2059 | if (db_num_rows($result) == 0) { | |
2060 | ||
2061 | $result = db_query($link, | |
15da5cc1 | 2062 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) |
746b249f AD |
2063 | VALUES ('".$_SESSION["uid"]."', '$feed_link', |
2064 | '[Unknown]', $cat_qpart)"); | |
331900c6 | 2065 | |
7e9a3986 | 2066 | $result = db_query($link, |
746b249f | 2067 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' |
7e9a3986 AD |
2068 | AND owner_uid = " . $_SESSION["uid"]); |
2069 | ||
2070 | $feed_id = db_fetch_result($result, 0, "id"); | |
2071 | ||
2072 | if ($feed_id) { | |
ddb68b81 | 2073 | update_rss_feed($link, $feed_link, $feed_id, true); |
7e9a3986 AD |
2074 | } |
2075 | } else { | |
331900c6 | 2076 | |
7e9a3986 AD |
2077 | print "<div class=\"warning\"> |
2078 | Feed <b>$feed_link</b> already exists in the database. | |
2079 | </div>"; | |
b0b4abcf AD |
2080 | } |
2081 | } | |
331900c6 | 2082 | } |
a0d53889 | 2083 | |
91ff844a AD |
2084 | if ($subop == "addCat") { |
2085 | ||
2086 | if (!WEB_DEMO_MODE) { | |
2087 | ||
2088 | $feed_cat = db_escape_string(trim($_GET["cat"])); | |
2089 | ||
2090 | $result = db_query($link, | |
2091 | "SELECT id FROM ttrss_feed_categories | |
2092 | WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); | |
2093 | ||
2094 | if (db_num_rows($result) == 0) { | |
2095 | ||
2096 | $result = db_query($link, | |
2097 | "INSERT INTO ttrss_feed_categories (owner_uid,title) | |
2098 | VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); | |
2099 | ||
2100 | } else { | |
2101 | ||
2102 | print "<div class=\"warning\"> | |
2103 | Category <b>$feed_cat</b> already exists in the database. | |
2104 | </div>"; | |
2105 | } | |
2106 | ||
2107 | ||
2108 | } | |
2109 | } | |
2110 | ||
2111 | if ($subop == "removeCats") { | |
2112 | ||
2113 | if (!WEB_DEMO_MODE) { | |
2114 | ||
f932bc9f | 2115 | $ids = split(",", db_escape_string($_GET["ids"])); |
91ff844a AD |
2116 | |
2117 | foreach ($ids as $id) { | |
2118 | ||
2119 | db_query($link, "BEGIN"); | |
2120 | ||
2121 | $result = db_query($link, | |
2122 | "SELECT count(id) as num_feeds FROM ttrss_feeds | |
2123 | WHERE cat_id = '$id'"); | |
2124 | ||
2125 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
2126 | ||
2127 | if ($num_feeds == 0) { | |
2128 | db_query($link, "DELETE FROM ttrss_feed_categories | |
2129 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
2130 | } else { | |
2131 | ||
2132 | print "<div class=\"warning\"> | |
2133 | Unable to delete non empty feed categories.</div>"; | |
2134 | ||
2135 | } | |
2136 | ||
2137 | db_query($link, "COMMIT"); | |
2138 | } | |
2139 | } | |
2140 | } | |
2141 | ||
f932bc9f AD |
2142 | if ($subop == "categorize") { |
2143 | ||
2144 | if (!WEB_DEMO_MODE) { | |
2145 | ||
2146 | $ids = split(",", db_escape_string($_GET["ids"])); | |
2147 | ||
2148 | $cat_id = db_escape_string($_GET["cat_id"]); | |
2149 | ||
2150 | if ($cat_id == 0) { | |
2151 | $cat_id_qpart = 'NULL'; | |
2152 | } else { | |
2153 | $cat_id_qpart = "'$cat_id'"; | |
2154 | } | |
2155 | ||
2156 | db_query($link, "BEGIN"); | |
2157 | ||
2158 | foreach ($ids as $id) { | |
2159 | ||
2160 | db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart | |
2161 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
2162 | } | |
2163 | ||
2164 | db_query($link, "COMMIT"); | |
2165 | } | |
2166 | ||
2167 | } | |
2168 | ||
a24f525c AD |
2169 | if ($quiet) return; |
2170 | ||
c64d5b03 | 2171 | // print "<h3>Edit Feeds</h3>"; |
91ff844a | 2172 | |
4904f845 AD |
2173 | $result = db_query($link, "SELECT id,title,feed_url,last_error |
2174 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); | |
2175 | ||
2176 | if (db_num_rows($result) > 0) { | |
2177 | ||
2178 | print "<div class=\"warning\">"; | |
a9b0bfd5 AD |
2179 | |
2180 | // print"<img class=\"closeButton\" | |
2181 | // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">"; | |
2182 | ||
36aab70f AD |
2183 | print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\"> |
2184 | <b>Feeds with update errors</b> (click to expand)</a>"; | |
4904f845 | 2185 | |
36aab70f | 2186 | print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">"; |
4904f845 AD |
2187 | |
2188 | while ($line = db_fetch_assoc($result)) { | |
2189 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
2190 | $line["last_error"]; | |
2191 | } | |
2192 | ||
2193 | print "</ul>"; | |
2194 | print "</div>"; | |
2195 | ||
2196 | } | |
2197 | ||
f932bc9f AD |
2198 | $feed_search = db_escape_string($_GET["search"]); |
2199 | ||
2200 | if (array_key_exists("search", $_GET)) { | |
2201 | $_SESSION["prefs_feed_search"] = $feed_search; | |
2202 | } else { | |
2203 | $feed_search = $_SESSION["prefs_feed_search"]; | |
2204 | } | |
2205 | ||
2206 | print "<table width='100%' class=\"prefGenericAddBox\" | |
2207 | cellspacing='0' cellpadding='0'><tr> | |
2208 | <td> | |
2209 | <input id=\"fadd_link\" | |
2210 | onchange=\"javascript:addFeed()\" | |
2211 | size=\"40\"> | |
2212 | <input type=\"submit\" class=\"button\" | |
e2f728be AD |
2213 | onclick=\"javascript:addFeed()\" value=\"Add feed\">"; |
2214 | ||
2215 | if (ENABLE_FEED_BROWSER) { | |
2216 | print " (<a href='javascript:browseFeeds()'>Top 50</a>)"; | |
2217 | } | |
2218 | ||
2219 | print "</td><td align='right'> | |
f932bc9f AD |
2220 | <input id=\"feed_search\" size=\"20\" |
2221 | onchange=\"javascript:updateFeedList()\" | |
2222 | value=\"$feed_search\"> | |
2223 | <input type=\"submit\" class=\"button\" | |
2224 | onclick=\"javascript:updateFeedList()\" value=\"Search\"> | |
2225 | </td> | |
2226 | </tr></table>"; | |
a0d53889 | 2227 | |
b83c7545 AD |
2228 | $feeds_sort = db_escape_string($_GET["sort"]); |
2229 | ||
2230 | if (!$feeds_sort || $feeds_sort == "undefined") { | |
2231 | $feeds_sort = $_SESSION["pref_sort_feeds"]; | |
2232 | if (!$feeds_sort) $feeds_sort = "title"; | |
2233 | } | |
2234 | ||
2235 | $_SESSION["pref_sort_feeds"] = $feeds_sort; | |
2236 | ||
f932bc9f | 2237 | if ($feed_search) { |
11de82c3 AD |
2238 | $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR |
2239 | UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND"; | |
f932bc9f AD |
2240 | } else { |
2241 | $search_qpart = ""; | |
2242 | } | |
2243 | ||
648472a7 | 2244 | $result = db_query($link, "SELECT |
db42b934 AD |
2245 | F1.id, |
2246 | F1.title, | |
2247 | F1.feed_url, | |
2248 | substring(F1.last_updated,1,16) AS last_updated, | |
2249 | F1.parent_feed, | |
2250 | F1.update_interval, | |
2251 | F1.purge_interval, | |
2252 | F1.cat_id, | |
2253 | F2.title AS parent_title, | |
2254 | C1.title AS category | |
c0e5a40e | 2255 | FROM |
db42b934 AD |
2256 | ttrss_feeds AS F1 |
2257 | LEFT JOIN ttrss_feeds AS F2 | |
2258 | ON (F1.parent_feed = F2.id) | |
2259 | LEFT JOIN ttrss_feed_categories AS C1 | |
2260 | ON (F1.cat_id = C1.id) | |
f932bc9f | 2261 | WHERE |
db42b934 | 2262 | $search_qpart F1.owner_uid = '".$_SESSION["uid"]."' |
0ea4fb50 | 2263 | ORDER by category,$feeds_sort,title"); |
1cd17194 | 2264 | |
3b0feb9b | 2265 | if (db_num_rows($result) != 0) { |
91ff844a | 2266 | |
3b0feb9b | 2267 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
35f3c923 | 2268 | |
f4fe2cde AD |
2269 | print "<p><table width=\"100%\" cellspacing=\"0\" |
2270 | class=\"prefFeedList\" id=\"prefFeedList\">"; | |
35f3c923 AD |
2271 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> |
2272 | Select: | |
2273 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', | |
3055bc41 | 2274 | 'FEEDR-', 'FRCHK-', true)\">All</a>, |
35f3c923 | 2275 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', |
3055bc41 | 2276 | 'FEEDR-', 'FRCHK-', false)\">None</a> |
35f3c923 AD |
2277 | </td</tr>"; |
2278 | ||
0ea4fb50 AD |
2279 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { |
2280 | print "<tr class=\"title\"> | |
e325c6e7 | 2281 | <td width='5%' align='center'> </td> |
62ac0cc8 | 2282 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> |
f42e9435 | 2283 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> |
62ac0cc8 AD |
2284 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> |
2285 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>"; | |
603c27f8 | 2286 | } |
603c27f8 | 2287 | |
c64d5b03 | 2288 | $lnum = 0; |
0ea4fb50 AD |
2289 | |
2290 | $cur_cat_id = -1; | |
c64d5b03 AD |
2291 | |
2292 | while ($line = db_fetch_assoc($result)) { | |
2293 | ||
3b0feb9b | 2294 | $feed_id = $line["id"]; |
0ea4fb50 AD |
2295 | $cat_id = $line["cat_id"]; |
2296 | ||
2297 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
2298 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
2299 | $edit_cat = htmlspecialchars(db_unescape_string($line["category"])); | |
c64d5b03 | 2300 | |
0ea4fb50 AD |
2301 | if ($line["update_interval"] == "0") $line["update_interval"] = "Default"; |
2302 | if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled"; | |
2303 | if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default"; | |
2304 | if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled"; | |
2305 | ||
2306 | if (!$edit_cat) $edit_cat = "Uncategorized"; | |
2307 | ||
2308 | ||
2309 | if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) { | |
cb58d0df AD |
2310 | $lnum = 0; |
2311 | ||
0ea4fb50 AD |
2312 | print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>"; |
2313 | ||
2314 | print "<tr class=\"title\"> | |
e325c6e7 | 2315 | <td width='5%' align='center'> </td> |
62ac0cc8 | 2316 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> |
f42e9435 | 2317 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> |
62ac0cc8 AD |
2318 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> |
2319 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>"; | |
0ea4fb50 AD |
2320 | |
2321 | $cur_cat_id = $cat_id; | |
c64d5b03 | 2322 | } |
0ea4fb50 | 2323 | |
cb58d0df | 2324 | $class = ($lnum % 2) ? "even" : "odd"; |
0ea4fb50 AD |
2325 | $this_row_id = "id=\"FEEDR-$feed_id\""; |
2326 | ||
53226edc | 2327 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2328 | |
2329 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
2330 | ||
2331 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
327a3bbe | 2332 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">"; |
3b0feb9b | 2333 | } else { |
327a3bbe | 2334 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; |
3b0feb9b | 2335 | } |
327a3bbe | 2336 | // print "<td class='feedIcon'>$feed_icon</td>"; |
c64d5b03 | 2337 | |
62ac0cc8 | 2338 | print "<td class='feedSelect'><input onclick='toggleSelectRow(this);' |
0ea4fb50 | 2339 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
3547842a | 2340 | |
0ea4fb50 AD |
2341 | $edit_title = truncate_string($edit_title, 40); |
2342 | $edit_link = truncate_string($edit_link, 60); | |
a88c1f36 | 2343 | |
1da7e457 AD |
2344 | $parent_title = $line["parent_title"]; |
2345 | if ($parent_title) { | |
2346 | $parent_title = "<span class='groupPrompt'>(linked to | |
2347 | $parent_title)</span>"; | |
2348 | } | |
2349 | ||
0ea4fb50 | 2350 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
1da7e457 | 2351 | "$feed_icon $edit_title $parent_title" . "</a></td>"; |
0ea4fb50 AD |
2352 | |
2353 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2354 | $edit_link . "</a></td>"; | |
3547842a | 2355 | |
0ea4fb50 AD |
2356 | /* if (get_pref($link, 'ENABLE_FEED_CATS')) { |
2357 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2358 | $edit_cat . "</a></td>"; | |
2359 | } */ | |
3547842a | 2360 | |
0ea4fb50 AD |
2361 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
2362 | $line["update_interval"] . "</a></td>"; | |
3b0feb9b | 2363 | |
0ea4fb50 AD |
2364 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
2365 | $line["purge_interval"] . "</a></td>"; | |
3b0feb9b | 2366 | |
c64d5b03 AD |
2367 | print "</tr>"; |
2368 | ||
2369 | ++$lnum; | |
2370 | } | |
2371 | ||
c64d5b03 | 2372 | print "</table>"; |
3b0feb9b | 2373 | |
c64d5b03 AD |
2374 | print "<p>"; |
2375 | ||
3b0feb9b AD |
2376 | if ($subop == "edit") { |
2377 | print "Edit feed: | |
c64d5b03 | 2378 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 2379 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> |
c64d5b03 | 2380 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2381 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
2382 | } else { | |
c64d5b03 AD |
2383 | |
2384 | print " | |
2385 | Selection: | |
2386 | <input type=\"submit\" class=\"button\" | |
3b0feb9b | 2387 | onclick=\"javascript:selectedFeedDetails()\" value=\"Details\"> |
c64d5b03 | 2388 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2389 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> |
2390 | <input type=\"submit\" class=\"button\" | |
2391 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
f932bc9f AD |
2392 | |
2393 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2394 | ||
2395 | print " "; | |
2396 | ||
2397 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2398 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2399 | ORDER BY title"); | |
2400 | ||
2401 | print "<select id=\"sfeed_set_fcat\">"; | |
2402 | print "<option id=\"0\">Uncategorized</option>"; | |
2403 | ||
2404 | if (db_num_rows($result) != 0) { | |
2405 | ||
2406 | print "<option disabled>--------</option>"; | |
2407 | ||
2408 | while ($line = db_fetch_assoc($result)) { | |
2409 | printf("<option id='%d'>%s</option>", | |
2410 | $line["id"], $line["title"]); | |
2411 | } | |
2412 | } | |
2413 | ||
2414 | print "</select>"; | |
2415 | ||
2416 | print " <input type=\"submit\" class=\"button\" | |
2417 | onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">"; | |
2418 | ||
2419 | } | |
2420 | ||
3b0feb9b AD |
2421 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { |
2422 | print " | |
2423 | <input type=\"submit\" class=\"button\" | |
4f3a84f4 | 2424 | onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\"> |
3b0feb9b | 2425 | <input type=\"submit\" class=\"button\" |
4f3a84f4 | 2426 | onclick=\"javascript:readSelectedFeeds(false)\" |
3b0feb9b AD |
2427 | value=\"Mark as unread\"> "; |
2428 | } | |
2429 | ||
2430 | print " | |
f932bc9f | 2431 | All feeds: <input type=\"submit\" |
3b0feb9b AD |
2432 | class=\"button\" onclick=\"gotoExportOpml()\" |
2433 | value=\"Export OPML\">"; | |
2434 | } | |
2435 | } else { | |
2436 | ||
2437 | print "<p>No feeds defined.</p>"; | |
2438 | ||
2439 | } | |
2440 | ||
2441 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2442 | ||
2443 | print "<h3>Edit Categories</h3>"; | |
2444 | ||
2445 | // print "<h3>Categories</h3>"; | |
2446 | ||
2447 | print "<div class=\"prefGenericAddBox\"> | |
f932bc9f AD |
2448 | <input id=\"fadd_cat\" |
2449 | onchange=\"javascript:addFeedCat()\" | |
2450 | size=\"40\"> | |
2451 | <input | |
3b0feb9b AD |
2452 | type=\"submit\" class=\"button\" |
2453 | onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>"; | |
2454 | ||
2455 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2456 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2457 | ORDER BY title"); | |
2458 | ||
2459 | if (db_num_rows($result) != 0) { | |
2460 | ||
35f3c923 | 2461 | print "<p><table width=\"100%\" class=\"prefFeedCatList\" |
f4fe2cde | 2462 | cellspacing=\"0\" id=\"prefFeedCatList\">"; |
35f3c923 AD |
2463 | |
2464 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2465 | Select: | |
2466 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', | |
3055bc41 | 2467 | 'FCATR-', 'FCCHK-', true)\">All</a>, |
35f3c923 | 2468 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', |
3055bc41 | 2469 | 'FCATR-', 'FCCHK-', false)\">None</a> |
35f3c923 AD |
2470 | </td</tr>"; |
2471 | ||
3b0feb9b | 2472 | print "<tr class=\"title\"> |
a426e532 | 2473 | <td width=\"5%\"></td><td width=\"80%\">Title</td> |
3b0feb9b AD |
2474 | </tr>"; |
2475 | ||
2476 | $lnum = 0; | |
2477 | ||
2478 | while ($line = db_fetch_assoc($result)) { | |
2479 | ||
2480 | $class = ($lnum % 2) ? "even" : "odd"; | |
2481 | ||
2482 | $cat_id = $line["id"]; | |
2483 | ||
2484 | $edit_cat_id = $_GET["id"]; | |
2485 | ||
2486 | if ($subop == "editCat" && $cat_id != $edit_cat_id) { | |
2487 | $class .= "Grayed"; | |
53226edc AD |
2488 | $this_row_id = ""; |
2489 | } else { | |
2490 | $this_row_id = "id=\"FCATR-$cat_id\""; | |
3b0feb9b AD |
2491 | } |
2492 | ||
53226edc | 2493 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2494 | |
2495 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
2496 | ||
2497 | if (!$edit_cat_id || $subop != "editCat") { | |
2498 | ||
a426e532 | 2499 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
2500 | type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>"; |
2501 | ||
2502 | print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . | |
2503 | $edit_title . "</a></td>"; | |
2504 | ||
2505 | } else if ($cat_id != $edit_cat_id) { | |
2506 | ||
2507 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2508 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
2509 | ||
2510 | print "<td>$edit_title</td>"; | |
2511 | ||
2512 | } else { | |
2513 | ||
2514 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2515 | ||
2516 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; | |
2517 | ||
2518 | } | |
2519 | ||
2520 | print "</tr>"; | |
2521 | ||
2522 | ++$lnum; | |
2523 | } | |
2524 | ||
2525 | print "</table>"; | |
2526 | ||
2527 | print "<p>"; | |
2528 | ||
2529 | if ($subop == "editCat") { | |
2530 | print "Edit category: | |
2531 | <input type=\"submit\" class=\"button\" | |
2532 | onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\"> | |
2533 | <input type=\"submit\" class=\"button\" | |
2534 | onclick=\"javascript:feedCatEditSave()\" value=\"Save\">"; | |
2535 | } else { | |
2536 | ||
2537 | print " | |
2538 | Selection: | |
2539 | <input type=\"submit\" class=\"button\" | |
2540 | onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\"> | |
2541 | <input type=\"submit\" class=\"button\" | |
2542 | onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">"; | |
2543 | ||
2544 | } | |
2545 | ||
2546 | } else { | |
2547 | print "<p>No feed categories defined.</p>"; | |
2548 | } | |
c64d5b03 AD |
2549 | } |
2550 | ||
2551 | print "<h3>Import OPML</h3> | |
f5a50b25 AD |
2552 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> |
2553 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
2554 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
2555 | type=\"submit\" value=\"Import\"> | |
2556 | </form>"; | |
2557 | ||
007bda35 AD |
2558 | } |
2559 | ||
a0d53889 AD |
2560 | if ($op == "pref-filters") { |
2561 | ||
2562 | $subop = $_GET["subop"]; | |
a24f525c | 2563 | $quiet = $_GET["quiet"]; |
a0d53889 AD |
2564 | |
2565 | if ($subop == "editSave") { | |
a0d53889 | 2566 | |
648472a7 AD |
2567 | $regexp = db_escape_string($_GET["r"]); |
2568 | $descr = db_escape_string($_GET["d"]); | |
2569 | $match = db_escape_string($_GET["m"]); | |
2570 | $filter_id = db_escape_string($_GET["id"]); | |
ead60402 | 2571 | $feed_id = db_escape_string($_GET["fid"]); |
19c9cb11 | 2572 | $action_id = db_escape_string($_GET["aid"]); |
ead60402 AD |
2573 | |
2574 | if (!$feed_id) { | |
2575 | $feed_id = 'NULL'; | |
2576 | } else { | |
2577 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2578 | } | |
0afbd851 | 2579 | |
648472a7 | 2580 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 2581 | reg_exp = '$regexp', |
0afbd851 | 2582 | description = '$descr', |
ead60402 | 2583 | feed_id = $feed_id, |
19c9cb11 | 2584 | action_id = '$action_id', |
0afbd851 AD |
2585 | filter_type = (SELECT id FROM ttrss_filter_types WHERE |
2586 | description = '$match') | |
2587 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
2588 | } |
2589 | ||
2590 | if ($subop == "remove") { | |
2591 | ||
2592 | if (!WEB_DEMO_MODE) { | |
2593 | ||
f932bc9f | 2594 | $ids = split(",", db_escape_string($_GET["ids"])); |
a0d53889 AD |
2595 | |
2596 | foreach ($ids as $id) { | |
648472a7 | 2597 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
2598 | |
2599 | } | |
2600 | } | |
2601 | } | |
2602 | ||
2603 | if ($subop == "add") { | |
2604 | ||
de435974 | 2605 | if (!WEB_DEMO_MODE) { |
a0d53889 | 2606 | |
b6b535ca AD |
2607 | $regexp = db_escape_string(trim($_GET["regexp"])); |
2608 | $match = db_escape_string(trim($_GET["match"])); | |
ead60402 | 2609 | $feed_id = db_escape_string($_GET["fid"]); |
19c9cb11 | 2610 | $action_id = db_escape_string($_GET["aid"]); |
ead60402 AD |
2611 | |
2612 | if (!$feed_id) { | |
2613 | $feed_id = 'NULL'; | |
2614 | } else { | |
2615 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2616 | } | |
4401bf04 | 2617 | |
648472a7 | 2618 | $result = db_query($link, |
19c9cb11 AD |
2619 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, |
2620 | action_id) | |
2621 | VALUES | |
de435974 | 2622 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
19c9cb11 AD |
2623 | description = '$match'),'".$_SESSION["uid"]."', |
2624 | $feed_id, '$action_id')"); | |
de435974 | 2625 | } |
a0d53889 AD |
2626 | } |
2627 | ||
a24f525c AD |
2628 | if ($quiet) return; |
2629 | ||
648472a7 | 2630 | $result = db_query($link, "SELECT description |
a0d53889 AD |
2631 | FROM ttrss_filter_types ORDER BY description"); |
2632 | ||
2633 | $filter_types = array(); | |
2634 | ||
648472a7 | 2635 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
2636 | array_push($filter_types, $line["description"]); |
2637 | } | |
2638 | ||
2c7070b5 | 2639 | print "<div class=\"prefGenericAddBox\"> |
7cc1e5d6 | 2640 | <input id=\"fadd_regexp\" size=\"40\"> "; |
2c7070b5 | 2641 | |
ead60402 AD |
2642 | print_select("fadd_match", "Title", $filter_types); |
2643 | ||
2644 | print " <select id=\"fadd_feed\">"; | |
2645 | ||
2646 | print "<option selected id=\"0\">All feeds</option>"; | |
2647 | ||
2648 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2649 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2650 | ||
2651 | if (db_num_rows($result) > 0) { | |
2652 | print "<option disabled>--------</option>"; | |
2653 | } | |
2654 | ||
2655 | while ($line = db_fetch_assoc($result)) { | |
2656 | printf("<option id='%d'>%s</option>", $line["id"], $line["title"]); | |
2657 | } | |
2658 | ||
2c7070b5 | 2659 | print "</select> "; |
19c9cb11 AD |
2660 | |
2661 | print " Action: "; | |
2662 | ||
2663 | print "<select id=\"fadd_action\">"; | |
2664 | ||
2665 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2666 | ORDER BY name"); | |
2667 | ||
2668 | while ($line = db_fetch_assoc($result)) { | |
2669 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
2670 | } | |
2671 | ||
2672 | print "</select> "; | |
2673 | ||
2c7070b5 AD |
2674 | print "<input type=\"submit\" |
2675 | class=\"button\" onclick=\"javascript:addFilter()\" | |
2676 | value=\"Add filter\">"; | |
a0d53889 | 2677 | |
19c9cb11 AD |
2678 | print "</div>"; |
2679 | ||
648472a7 | 2680 | $result = db_query($link, "SELECT |
ead60402 AD |
2681 | ttrss_filters.id AS id,reg_exp, |
2682 | ttrss_filters.description AS description, | |
2683 | ttrss_filter_types.name AS filter_type_name, | |
2684 | ttrss_filter_types.description AS filter_type_descr, | |
2685 | feed_id, | |
19c9cb11 | 2686 | ttrss_filter_actions.description AS action_description, |
11de82c3 | 2687 | ttrss_feeds.title AS feed_title |
a0d53889 | 2688 | FROM |
5890c3f4 AD |
2689 | ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN |
2690 | ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) | |
4356293a | 2691 | WHERE |
ead60402 | 2692 | filter_type = ttrss_filter_types.id AND |
19c9cb11 | 2693 | ttrss_filter_actions.id = action_id AND |
ead60402 | 2694 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." |
4356293a | 2695 | ORDER by reg_exp"); |
a0d53889 | 2696 | |
3b0feb9b | 2697 | if (db_num_rows($result) != 0) { |
a0d53889 | 2698 | |
f4fe2cde AD |
2699 | print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" |
2700 | id=\"prefFilterList\">"; | |
35f3c923 AD |
2701 | |
2702 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2703 | Select: | |
2704 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', | |
3055bc41 | 2705 | 'FILRR-', 'FICHK-', true)\">All</a>, |
35f3c923 | 2706 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', |
3055bc41 | 2707 | 'FILRR-', 'FICHK-', false)\">None</a> |
35f3c923 AD |
2708 | </td</tr>"; |
2709 | ||
3b0feb9b | 2710 | print "<tr class=\"title\"> |
e325c6e7 | 2711 | <td align='center' width=\"5%\"> </td> |
19c9cb11 AD |
2712 | <td width=\"20%\">Filter expression</td> |
2713 | <td width=\"20%\">Feed</td> | |
2714 | <td width=\"15%\">Match</td> | |
2715 | <td width=\"15%\">Action</td> | |
3b0feb9b | 2716 | <td width=\"30%\">Description</td></tr>"; |
a0d53889 | 2717 | |
3b0feb9b AD |
2718 | $lnum = 0; |
2719 | ||
2720 | while ($line = db_fetch_assoc($result)) { | |
2721 | ||
2722 | $class = ($lnum % 2) ? "even" : "odd"; | |
2723 | ||
2724 | $filter_id = $line["id"]; | |
2725 | $edit_filter_id = $_GET["id"]; | |
2726 | ||
2727 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
2728 | $class .= "Grayed"; | |
53226edc AD |
2729 | $this_row_id = ""; |
2730 | } else { | |
2731 | $this_row_id = "id=\"FILRR-$filter_id\""; | |
ead60402 | 2732 | } |
3b0feb9b | 2733 | |
53226edc | 2734 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2735 | |
2736 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); | |
2737 | $line["description"] = htmlspecialchars($line["description"]); | |
2738 | ||
2739 | if (!$line["feed_title"]) $line["feed_title"] = "All feeds"; | |
2740 | ||
2741 | if (!$edit_filter_id || $subop != "edit") { | |
2742 | ||
2743 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2744 | ||
a426e532 | 2745 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
2746 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; |
2747 | ||
2748 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2749 | $line["reg_exp"] . "</td>"; | |
2750 | ||
2751 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2752 | $line["feed_title"] . "</td>"; | |
2753 | ||
2754 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2755 | $line["filter_type_descr"] . "</td>"; | |
19c9cb11 AD |
2756 | |
2757 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2758 | $line["action_description"] . "</td>"; | |
2759 | ||
3b0feb9b AD |
2760 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . |
2761 | $line["description"] . "</td>"; | |
2762 | ||
2763 | } else if ($filter_id != $edit_filter_id) { | |
2764 | ||
2765 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2766 | ||
2767 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2768 | id=\"FICHK-".$line["id"]."\"></td>"; | |
2769 | ||
2770 | print "<td>".$line["reg_exp"]."</td>"; | |
2771 | print "<td>".$line["feed_title"]."</td>"; | |
2772 | print "<td>".$line["filter_type_descr"]."</td>"; | |
19c9cb11 | 2773 | print "<td>".$line["action_description"]."</td>"; |
3b0feb9b | 2774 | print "<td>".$line["description"]."</td>"; |
19c9cb11 | 2775 | |
3b0feb9b AD |
2776 | } else { |
2777 | ||
2778 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2779 | ||
2780 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. | |
2781 | "\"></td>"; | |
2782 | ||
2783 | print "<td>"; | |
3b0feb9b | 2784 | print "<select id=\"iedit_feed\">"; |
3b0feb9b AD |
2785 | print "<option id=\"0\">All feeds</option>"; |
2786 | ||
3b0feb9b AD |
2787 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds |
2788 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
19c9cb11 AD |
2789 | |
2790 | if (db_num_rows($tmp_result) > 0) { | |
2791 | print "<option disabled>--------</option>"; | |
2792 | } | |
2793 | ||
3b0feb9b AD |
2794 | while ($tmp_line = db_fetch_assoc($tmp_result)) { |
2795 | if ($tmp_line["id"] == $line["feed_id"]) { | |
2796 | $is_selected = "selected"; | |
2797 | } else { | |
2798 | $is_selected = ""; | |
2799 | } | |
2800 | printf("<option $is_selected id='%d'>%s</option>", | |
2801 | $tmp_line["id"], $tmp_line["title"]); | |
ead60402 | 2802 | } |
3b0feb9b AD |
2803 | |
2804 | print "</select></td>"; | |
2805 | ||
2806 | print "<td>"; | |
2807 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
2808 | print "</td>"; | |
19c9cb11 AD |
2809 | |
2810 | print "<td>"; | |
2811 | print "<select id=\"iedit_filter_action\">"; | |
2812 | ||
2813 | $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2814 | ORDER BY description"); | |
2815 | ||
2816 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2817 | if ($tmp_line["description"] == $line["action_description"]) { | |
2818 | $is_selected = "selected"; | |
2819 | } else { | |
2820 | $is_selected = ""; | |
2821 | } | |
2822 | printf("<option $is_selected id='%d'>%s</option>", | |
2823 | $tmp_line["id"], $tmp_line["description"]); | |
2824 | } | |
3b0feb9b | 2825 | |
19c9cb11 AD |
2826 | print "</select></td>"; |
2827 | ||
2828 | ||
3b0feb9b AD |
2829 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. |
2830 | "\"></td>"; | |
2831 | ||
2832 | print "</td>"; | |
ead60402 | 2833 | } |
3b0feb9b AD |
2834 | |
2835 | print "</tr>"; | |
2836 | ||
2837 | ++$lnum; | |
a0d53889 | 2838 | } |
3b0feb9b AD |
2839 | |
2840 | if ($lnum == 0) { | |
2841 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
2842 | } | |
2843 | ||
2844 | print "</table>"; | |
2845 | ||
2846 | print "<p>"; | |
2847 | ||
2848 | if ($subop == "edit") { | |
d10fabe4 | 2849 | print "Edit filter: |
3b0feb9b | 2850 | <input type=\"submit\" class=\"button\" |
d10fabe4 | 2851 | onclick=\"javascript:filterEditSave()\" value=\"Save\"> |
3b0feb9b | 2852 | <input type=\"submit\" class=\"button\" |
d10fabe4 | 2853 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">"; |
3b0feb9b AD |
2854 | |
2855 | } else { | |
2856 | ||
2857 | print " | |
2858 | Selection: | |
e828e31e | 2859 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 2860 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> |
e828e31e | 2861 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2862 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; |
2863 | } | |
2864 | ||
a0d53889 AD |
2865 | } else { |
2866 | ||
3b0feb9b AD |
2867 | print "<p>No filters defined.</p>"; |
2868 | ||
a0d53889 AD |
2869 | } |
2870 | } | |
2871 | ||
80dce858 AD |
2872 | // We need to accept raw SQL data in label queries, so not everything is escaped |
2873 | // here, this is by design. If you don't like the whole idea, disable labels | |
2874 | // altogether with GLOBAL_ENABLE_LABELS = false | |
2875 | ||
48f0adb0 AD |
2876 | if ($op == "pref-labels") { |
2877 | ||
cfaba6df AD |
2878 | if (!GLOBAL_ENABLE_LABELS) { |
2879 | return; | |
2880 | } | |
2881 | ||
48f0adb0 AD |
2882 | $subop = $_GET["subop"]; |
2883 | ||
d9dde1d6 AD |
2884 | if ($subop == "test") { |
2885 | ||
2886 | $expr = $_GET["expr"]; | |
2887 | $descr = $_GET["descr"]; | |
2888 | ||
2889 | print "<div class='infoBoxContents'>"; | |
2890 | ||
2891 | print "<h1>Label «$descr»</h1>"; | |
2892 | ||
2893 | // print "<p><b>Expression</b>: $expr</p>"; | |
2894 | ||
2895 | $result = db_query($link, | |
2896 | "SELECT count(id) AS num_matches | |
2897 | FROM ttrss_entries,ttrss_user_entries | |
2898 | WHERE ($expr) AND | |
2899 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2900 | owner_uid = " . $_SESSION["uid"]); | |
2901 | ||
2902 | $num_matches = db_fetch_result($result, 0, "num_matches");; | |
2903 | ||
2904 | if ($num_matches > 0) { | |
2905 | ||
a31a7b39 | 2906 | print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>"; |
d9dde1d6 AD |
2907 | |
2908 | $result = db_query($link, | |
2909 | "SELECT title, | |
2910 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
2911 | FROM ttrss_entries,ttrss_user_entries | |
2912 | WHERE ($expr) AND | |
2913 | ttrss_user_entries.ref_id = ttrss_entries.id | |
2914 | AND owner_uid = " . $_SESSION["uid"] . " | |
2915 | ORDER BY date_entered DESC LIMIT 5"); | |
2916 | ||
2917 | print "<ul class=\"nomarks\">"; | |
2918 | while ($line = db_fetch_assoc($result)) { | |
2919 | print "<li>".$line["title"]. | |
2920 | " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>"; | |
2921 | } | |
2922 | print "</ul>"; | |
2923 | ||
2924 | } else { | |
2925 | print "<p>Query didn't return any matches.</p>"; | |
2926 | } | |
2927 | ||
2928 | print "</div>"; | |
2929 | ||
2930 | print "<div align='center'> | |
2931 | <input type='submit' class='button' | |
2932 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
2933 | return; | |
2934 | } | |
2935 | ||
48f0adb0 AD |
2936 | if ($subop == "editSave") { |
2937 | ||
2938 | $sql_exp = $_GET["s"]; | |
2939 | $descr = $_GET["d"]; | |
2940 | $label_id = db_escape_string($_GET["id"]); | |
2941 | ||
2942 | // print "$sql_exp : $descr : $label_id"; | |
2943 | ||
2944 | $result = db_query($link, "UPDATE ttrss_labels SET | |
2945 | sql_exp = '$sql_exp', | |
2946 | description = '$descr' | |
2947 | WHERE id = '$label_id'"); | |
2948 | } | |
2949 | ||
2950 | if ($subop == "remove") { | |
2951 | ||
2952 | if (!WEB_DEMO_MODE) { | |
2953 | ||
f932bc9f | 2954 | $ids = split(",", db_escape_string($_GET["ids"])); |
48f0adb0 AD |
2955 | |
2956 | foreach ($ids as $id) { | |
2957 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
2958 | ||
2959 | } | |
2960 | } | |
2961 | } | |
2962 | ||
2963 | if ($subop == "add") { | |
2964 | ||
2965 | if (!WEB_DEMO_MODE) { | |
2966 | ||
4401bf04 AD |
2967 | // no escaping is done here on purpose |
2968 | $exp = trim($_GET["exp"]); | |
48f0adb0 AD |
2969 | |
2970 | $result = db_query($link, | |
4356293a AD |
2971 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) |
2972 | VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')"); | |
48f0adb0 AD |
2973 | } |
2974 | } | |
2975 | ||
2c7070b5 AD |
2976 | print "<div class=\"prefGenericAddBox\"> |
2977 | <input size=\"40\" id=\"ladd_expr\"> "; | |
48f0adb0 | 2978 | |
2c7070b5 AD |
2979 | print"<input type=\"submit\" class=\"button\" |
2980 | onclick=\"javascript:addLabel()\" value=\"Add label\"></div>"; | |
48f0adb0 AD |
2981 | |
2982 | $result = db_query($link, "SELECT | |
2983 | id,sql_exp,description | |
2984 | FROM | |
4356293a AD |
2985 | ttrss_labels |
2986 | WHERE | |
2987 | owner_uid = ".$_SESSION["uid"]." | |
2988 | ORDER by description"); | |
48f0adb0 | 2989 | |
d9dde1d6 AD |
2990 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
2991 | ||
3b0feb9b | 2992 | if (db_num_rows($result) != 0) { |
48f0adb0 | 2993 | |
f4fe2cde AD |
2994 | print "<p><table width=\"100%\" cellspacing=\"0\" |
2995 | class=\"prefLabelList\" id=\"prefLabelList\">"; | |
35f3c923 AD |
2996 | |
2997 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2998 | Select: | |
2999 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', | |
3055bc41 | 3000 | 'LILRR-', 'LICHK-', true)\">All</a>, |
35f3c923 | 3001 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', |
3055bc41 | 3002 | 'LILRR-', 'LICHK-', false)\">None</a> |
35f3c923 AD |
3003 | </td</tr>"; |
3004 | ||
3b0feb9b | 3005 | print "<tr class=\"title\"> |
e325c6e7 AD |
3006 | <td align='center' width=\"5%\"> </td> |
3007 | <td width=\"40%\">SQL expression | |
01c9c74a | 3008 | <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a> |
3b0feb9b AD |
3009 | </td> |
3010 | <td width=\"40%\">Caption</td></tr>"; | |
3011 | ||
3012 | $lnum = 0; | |
3013 | ||
3014 | while ($line = db_fetch_assoc($result)) { | |
3015 | ||
3016 | $class = ($lnum % 2) ? "even" : "odd"; | |
3017 | ||
3018 | $label_id = $line["id"]; | |
3019 | $edit_label_id = $_GET["id"]; | |
3020 | ||
3021 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
3022 | $class .= "Grayed"; | |
53226edc AD |
3023 | $this_row_id = ""; |
3024 | } else { | |
3025 | $this_row_id = "id=\"LILRR-$label_id\""; | |
3b0feb9b AD |
3026 | } |
3027 | ||
53226edc | 3028 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
3029 | |
3030 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
3031 | $line["description"] = htmlspecialchars($line["description"]); | |
3032 | ||
3033 | if (!$edit_label_id || $subop != "edit") { | |
3034 | ||
3035 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
3036 | ||
a426e532 | 3037 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
3038 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; |
3039 | ||
3040 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
3041 | $line["sql_exp"] . "</td>"; | |
48f0adb0 | 3042 | |
3b0feb9b AD |
3043 | print "<td><a href=\"javascript:editLabel($label_id);\">" . |
3044 | $line["description"] . "</td>"; | |
3045 | ||
3046 | } else if ($label_id != $edit_label_id) { | |
3047 | ||
3048 | if (!$line["description"]) $line["description"] = "[No description]"; | |
3049 | ||
3050 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
3051 | id=\"LICHK-".$line["id"]."\"></td>"; | |
3052 | ||
3053 | print "<td>".$line["sql_exp"]."</td>"; | |
3054 | print "<td>".$line["description"]."</td>"; | |
3055 | ||
3056 | } else { | |
3057 | ||
3058 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
3059 | ||
3060 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
3061 | "\"></td>"; | |
3062 | ||
3063 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
3064 | "\"></td>"; | |
3065 | ||
3066 | } | |
3067 | ||
48f0adb0 | 3068 | |
3b0feb9b AD |
3069 | print "</tr>"; |
3070 | ||
3071 | ++$lnum; | |
3072 | } | |
3073 | ||
3074 | if ($lnum == 0) { | |
3075 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
3076 | } | |
3077 | ||
3078 | print "</table>"; | |
3079 | ||
3080 | print "<p>"; | |
3081 | ||
3082 | if ($subop == "edit") { | |
3083 | print "Edit label: | |
d9dde1d6 AD |
3084 | <input type=\"submit\" class=\"button\" |
3085 | onclick=\"javascript:labelTest()\" value=\"Test\"> | |
3b0feb9b | 3086 | <input type=\"submit\" class=\"button\" |
d10fabe4 | 3087 | onclick=\"javascript:labelEditSave()\" value=\"Save\"> |
3b0feb9b | 3088 | <input type=\"submit\" class=\"button\" |
d10fabe4 | 3089 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">"; |
3b0feb9b AD |
3090 | |
3091 | } else { | |
3092 | ||
3093 | print " | |
3094 | Selection: | |
48f0adb0 | 3095 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 3096 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> |
48f0adb0 | 3097 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
3098 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; |
3099 | } | |
48f0adb0 | 3100 | } else { |
3b0feb9b | 3101 | print "<p>No labels defined.</p>"; |
48f0adb0 AD |
3102 | } |
3103 | } | |
3104 | ||
e828e31e AD |
3105 | if ($op == "error") { |
3106 | print "<div width=\"100%\" align='center'>"; | |
3107 | $msg = $_GET["msg"]; | |
3108 | print $msg; | |
3109 | print "</div>"; | |
3110 | } | |
3111 | ||
7dc66a61 | 3112 | if ($op == "help") { |
01c9c74a AD |
3113 | if (!$_GET["noheaders"]) { |
3114 | print "<html><head> | |
3115 | <title>Tiny Tiny RSS : Help</title> | |
3116 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
3117 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
3118 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
3119 | </head><body>"; | |
3120 | } | |
7dc66a61 AD |
3121 | |
3122 | $tid = sprintf("%d", $_GET["tid"]); | |
3123 | ||
01c9c74a | 3124 | print "<div class='infoBoxContents'>"; |
7dc66a61 | 3125 | |
01c9c74a AD |
3126 | if (file_exists("help/$tid.php")) { |
3127 | include("help/$tid.php"); | |
3128 | } else { | |
3129 | print "<p>Help topic not found.</p>"; | |
3130 | } | |
7dc66a61 | 3131 | |
01c9c74a | 3132 | print "</div>"; |
7dc66a61 AD |
3133 | |
3134 | print "<div align='center'> | |
01c9c74a AD |
3135 | <input type='submit' class='button' |
3136 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
7dc66a61 | 3137 | |
01c9c74a AD |
3138 | if (!$_GET["noheaders"]) { |
3139 | print "</body></html>"; | |
3140 | } | |
7dc66a61 AD |
3141 | |
3142 | } | |
3143 | ||
f84a97a3 AD |
3144 | if ($op == "dlg") { |
3145 | $id = $_GET["id"]; | |
6de5d056 | 3146 | $param = $_GET["param"]; |
f84a97a3 AD |
3147 | |
3148 | if ($id == "quickAddFeed") { | |
76332f3c AD |
3149 | print " |
3150 | Feed URL: <input | |
033e47e0 | 3151 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" |
15da5cc1 AD |
3152 | id=\"qafInput\">"; |
3153 | ||
3154 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3155 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
3156 | WHERE owner_uid = ".$_SESSION["uid"]." | |
3157 | ORDER BY title"); | |
3158 | ||
3159 | print " <select id=\"qafCat\">"; | |
3160 | print "<option id=\"0\">Uncategorized</option>"; | |
3161 | ||
3162 | if (db_num_rows($result) != 0) { | |
3163 | ||
3164 | print "<option disabled>--------</option>"; | |
3165 | ||
3166 | while ($line = db_fetch_assoc($result)) { | |
3167 | printf("<option id='%d'>%s</option>", | |
3168 | $line["id"], $line["title"]); | |
3169 | } | |
3170 | } | |
3171 | ||
3172 | print "</select>"; | |
3173 | } | |
3174 | ||
3175 | print " <input class=\"button\" | |
f84a97a3 AD |
3176 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> |
3177 | <input class=\"button\" | |
3178 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3179 | value=\"Cancel\">"; | |
3180 | } | |
6de5d056 AD |
3181 | |
3182 | if ($id == "quickDelFeed") { | |
3183 | ||
3184 | $param = db_escape_string($param); | |
3185 | ||
3186 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
3187 | ||
3188 | if ($result) { | |
3189 | ||
3190 | $f_title = db_fetch_result($result, 0, "title"); | |
3191 | ||
76332f3c | 3192 | print "Remove current feed (<b>$f_title</b>)? |
6de5d056 AD |
3193 | <input class=\"button\" |
3194 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
3195 | <input class=\"button\" | |
3196 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3197 | value=\"Cancel\">"; | |
3198 | } else { | |
3199 | print "Error: Feed $param not found. | |
3200 | <input class=\"button\" | |
3201 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3202 | value=\"Cancel\">"; | |
3203 | } | |
3204 | } | |
3205 | ||
033e47e0 AD |
3206 | if ($id == "search") { |
3207 | ||
49b7cbd3 AD |
3208 | $active_feed_id = db_escape_string($_GET["param"]); |
3209 | ||
033e47e0 AD |
3210 | print "<input id=\"searchbox\" class=\"extSearch\" |
3211 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
3212 | onchange=\"javascript:search()\"> | |
3213 | <select id=\"searchmodebox\"> | |
49b7cbd3 AD |
3214 | <option selected>All feeds</option>"; |
3215 | ||
3216 | if ($active_feed_id) { | |
3217 | print "<option>This feed</option>"; | |
3218 | } else { | |
3219 | print "<option disabled>This feed</option>"; | |
3220 | } | |
b0005823 AD |
3221 | |
3222 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3223 | print "<option>This category</option>"; | |
3224 | } | |
3225 | ||
49b7cbd3 | 3226 | print "</select> |
033e47e0 AD |
3227 | <input type=\"submit\" |
3228 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
3229 | <input class=\"button\" | |
3230 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3231 | value=\"Close\">"; | |
3232 | ||
3233 | } | |
3234 | ||
a24f525c AD |
3235 | if ($id == "quickAddFilter") { |
3236 | ||
3237 | $result = db_query($link, "SELECT description | |
3238 | FROM ttrss_filter_types ORDER BY description"); | |
3239 | ||
3240 | $filter_types = array(); | |
3241 | ||
3242 | while ($line = db_fetch_assoc($result)) { | |
3243 | array_push($filter_types, $line["description"]); | |
3244 | } | |
3245 | ||
3246 | print "<table>"; | |
3247 | ||
3248 | print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> "; | |
3249 | ||
3250 | print_select("fadd_match", "Title", $filter_types); | |
3251 | ||
3252 | print "</td></tr>"; | |
3253 | print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">"; | |
3254 | ||
3255 | print "<option selected id=\"0\">All feeds</option>"; | |
3256 | ||
3257 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
3258 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
3259 | ||
3260 | if (db_num_rows($result) > 0) { | |
3261 | print "<option disabled>--------</option>"; | |
3262 | } | |
3263 | ||
3264 | while ($line = db_fetch_assoc($result)) { | |
3265 | if ($param == $line["id"]) { | |
3266 | $selected = "selected"; | |
3267 | } else { | |
3268 | $selected = ""; | |
3269 | } | |
3270 | printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]); | |
3271 | } | |
3272 | ||
3273 | print "</select></td></tr>"; | |
3274 | ||
3275 | print "<tr><td>Action:</td>"; | |
3276 | ||
3277 | print "<td><select id=\"fadd_action\">"; | |
3278 | ||
3279 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
3280 | ORDER BY name"); | |
3281 | ||
3282 | while ($line = db_fetch_assoc($result)) { | |
3283 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
3284 | } | |
3285 | ||
3286 | print "</select>"; | |
3287 | ||
3288 | print "</td></tr><tr><td colspan=\"2\" align=\"right\">"; | |
3289 | ||
3290 | print "<input type=\"submit\" | |
3291 | class=\"button\" onclick=\"javascript:qaddFilter()\" | |
3292 | value=\"Add filter\"> "; | |
3293 | ||
3294 | print "<input class=\"button\" | |
3295 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3296 | value=\"Close\">"; | |
3297 | ||
3298 | print "</td></tr></table>"; | |
3299 | } | |
f84a97a3 AD |
3300 | } |
3301 | ||
a2770077 AD |
3302 | // update feeds of all users, may be used anonymously |
3303 | if ($op == "globalUpdateFeeds") { | |
3304 | ||
3305 | $result = db_query($link, "SELECT id FROM ttrss_users"); | |
3306 | ||
3307 | while ($line = db_fetch_assoc($result)) { | |
3308 | $user_id = $line["id"]; | |
3309 | // print "<!-- updating feeds of uid $user_id -->"; | |
3310 | update_all_feeds($link, false, $user_id); | |
3311 | } | |
e65af9c1 | 3312 | |
a2770077 AD |
3313 | print "<rpc-reply> |
3314 | <message msg=\"All feeds updated\"/> | |
3315 | </rpc-reply>"; | |
e65af9c1 AD |
3316 | |
3317 | } | |
3318 | ||
77e96719 AD |
3319 | if ($op == "pref-prefs") { |
3320 | ||
b1895692 | 3321 | $subop = $_REQUEST["subop"]; |
77e96719 AD |
3322 | |
3323 | if ($subop == "Save configuration") { | |
3324 | ||
d2892032 AD |
3325 | if (WEB_DEMO_MODE) { |
3326 | header("Location: prefs.php"); | |
3327 | return; | |
3328 | } | |
01d68cf9 | 3329 | |
93cb4442 AD |
3330 | $_SESSION["prefs_op_result"] = "save-config"; |
3331 | ||
11de82c3 AD |
3332 | $_SESSION["prefs_cache"] = false; |
3333 | ||
77e96719 AD |
3334 | foreach (array_keys($_POST) as $pref_name) { |
3335 | ||
3336 | $pref_name = db_escape_string($pref_name); | |
3337 | $value = db_escape_string($_POST[$pref_name]); | |
3338 | ||
3339 | $result = db_query($link, "SELECT type_name | |
3340 | FROM ttrss_prefs,ttrss_prefs_types | |
3341 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
3342 | ||
3343 | if (db_num_rows($result) > 0) { | |
3344 | ||
3345 | $type_name = db_fetch_result($result, 0, "type_name"); | |
3346 | ||
5da169d9 AD |
3347 | // print "$pref_name : $type_name : $value<br>"; |
3348 | ||
77e96719 | 3349 | if ($type_name == "bool") { |
5da169d9 | 3350 | if ($value == "1") { |
77e96719 AD |
3351 | $value = "true"; |
3352 | } else { | |
3353 | $value = "false"; | |
3354 | } | |
3355 | } else if ($type_name == "integer") { | |
3356 | $value = sprintf("%d", $value); | |
3357 | } | |
3358 | ||
3359 | // print "$pref_name : $type_name : $value<br>"; | |
3360 | ||
ff485f1d AD |
3361 | db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' |
3362 | WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); | |
77e96719 AD |
3363 | |
3364 | } | |
3365 | ||
3366 | header("Location: prefs.php"); | |
3367 | ||
3368 | } | |
3369 | ||
b1895692 AD |
3370 | } else if ($subop == "getHelp") { |
3371 | ||
3372 | $pref_name = db_escape_string($_GET["pn"]); | |
3373 | ||
3374 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
3375 | WHERE pref_name = '$pref_name'"); | |
3376 | ||
3377 | if (db_num_rows($result) > 0) { | |
3378 | $help_text = db_fetch_result($result, 0, "help_text"); | |
3379 | print $help_text; | |
3380 | } else { | |
3381 | print "Unknown option: $pref_name"; | |
3382 | } | |
3383 | ||
cbb01696 AD |
3384 | } else if ($subop == "Change e-mail") { |
3385 | ||
3386 | if (WEB_DEMO_MODE) { | |
3387 | header("Location: prefs.php"); | |
3388 | return; | |
3389 | } | |
3390 | ||
3391 | $email = db_escape_string($_GET["email"]); | |
3392 | $active_uid = $_SESSION["uid"]; | |
3393 | ||
3394 | if ($email) { | |
3395 | db_query($link, "UPDATE ttrss_users SET email = '$email' | |
3396 | WHERE id = '$active_uid'"); | |
3397 | } | |
3398 | ||
3399 | header("Location: prefs.php"); | |
3400 | ||
1c7f75ed AD |
3401 | } else if ($subop == "Change password") { |
3402 | ||
d2892032 AD |
3403 | if (WEB_DEMO_MODE) { |
3404 | header("Location: prefs.php"); | |
3405 | return; | |
3406 | } | |
1c7f75ed AD |
3407 | |
3408 | $old_pw = $_POST["OLD_PASSWORD"]; | |
3409 | $new_pw = $_POST["OLD_PASSWORD"]; | |
3410 | ||
3411 | $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]); | |
3412 | $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]); | |
3413 | ||
3414 | $active_uid = $_SESSION["uid"]; | |
3415 | ||
3416 | if ($old_pw && $new_pw) { | |
3417 | ||
3418 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
3419 | ||
3420 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
3421 | id = '$active_uid' AND (pwd_hash = '$old_pw' OR | |
3422 | pwd_hash = '$old_pw_hash')"); | |
3423 | ||
3424 | if (db_num_rows($result) == 1) { | |
3425 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
3426 | WHERE id = '$active_uid'"); | |
b791095d AD |
3427 | |
3428 | $_SESSION["pwd_change_result"] = "ok"; | |
3429 | } else { | |
3430 | $_SESSION["pwd_change_result"] = "failed"; | |
1c7f75ed AD |
3431 | } |
3432 | } | |
3433 | ||
3434 | header("Location: prefs.php"); | |
b791095d | 3435 | |
77e96719 AD |
3436 | } else if ($subop == "Reset to defaults") { |
3437 | ||
d2892032 AD |
3438 | if (WEB_DEMO_MODE) { |
3439 | header("Location: prefs.php"); | |
3440 | return; | |
3441 | } | |
01d68cf9 | 3442 | |
93cb4442 AD |
3443 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
3444 | ||
e1aa0559 AD |
3445 | if (DB_TYPE == "pgsql") { |
3446 | db_query($link,"UPDATE ttrss_user_prefs | |
3447 | SET value = ttrss_prefs.def_value | |
3448 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
3449 | ttrss_prefs.pref_name = ttrss_user_prefs.pref_name"); | |
3450 | } else { | |
3451 | db_query($link, "DELETE FROM ttrss_user_prefs | |
3452 | WHERE owner_uid = ".$_SESSION["uid"]); | |
3453 | initialize_user_prefs($link, $_SESSION["uid"]); | |
3454 | } | |
5da169d9 | 3455 | |
77e96719 AD |
3456 | header("Location: prefs.php"); |
3457 | ||
58f8ad54 AD |
3458 | } else if ($subop == "Change theme") { |
3459 | ||
3460 | $theme = db_escape_string($_POST["theme"]); | |
3461 | ||
3462 | if ($theme == "Default") { | |
3463 | $theme_qpart = 'NULL'; | |
3464 | } else { | |
3465 | $theme_qpart = "'$theme'"; | |
3466 | } | |
3467 | ||
6752e330 AD |
3468 | $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes |
3469 | WHERE theme_name = '$theme'"); | |
3470 | ||
3471 | if (db_num_rows($result) == 1) { | |
3472 | $theme_id = db_fetch_result($result, 0, "id"); | |
3473 | $theme_path = db_fetch_result($result, 0, "theme_path"); | |
3474 | } else { | |
3475 | $theme_id = "NULL"; | |
3476 | $theme_path = ""; | |
3477 | } | |
3478 | ||
58f8ad54 | 3479 | db_query($link, "UPDATE ttrss_users SET |
6752e330 | 3480 | theme_id = $theme_id WHERE id = " . $_SESSION["uid"]); |
58f8ad54 | 3481 | |
6752e330 | 3482 | $_SESSION["theme"] = $theme_path; |
503eb349 | 3483 | |
58f8ad54 AD |
3484 | header("Location: prefs.php"); |
3485 | ||
77e96719 AD |
3486 | } else { |
3487 | ||
7d4c898a | 3488 | if (!SINGLE_USER_MODE) { |
1c7f75ed | 3489 | |
cbb01696 | 3490 | $result = db_query($link, "SELECT id,email FROM ttrss_users |
a029d530 AD |
3491 | WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR |
3492 | pwd_hash = 'SHA1:".sha1("password")."')"); | |
3493 | ||
3494 | if (db_num_rows($result) != 0) { | |
b791095d | 3495 | print "<div class=\"warning\"> |
a029d530 AD |
3496 | Your password is at default value, please change it. |
3497 | </div>"; | |
3498 | } | |
3499 | ||
b791095d AD |
3500 | if ($_SESSION["pwd_change_result"] == "failed") { |
3501 | print "<div class=\"warning\"> | |
3502 | There was an error while changing your password. | |
3503 | </div>"; | |
3504 | } | |
3505 | ||
3506 | if ($_SESSION["pwd_change_result"] == "ok") { | |
3507 | print "<div class=\"notice\"> | |
3508 | Password changed successfully. | |
3509 | </div>"; | |
3510 | } | |
3511 | ||
3512 | $_SESSION["pwd_change_result"] = ""; | |
3513 | ||
93cb4442 AD |
3514 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { |
3515 | print "<div class=\"notice\"> | |
3516 | Your configuration was reset to defaults. | |
3517 | </div>"; | |
3518 | } | |
3519 | ||
3520 | if ($_SESSION["prefs_op_result"] == "save-config") { | |
3521 | print "<div class=\"notice\"> | |
3522 | Your configuration was saved successfully. | |
3523 | </div>"; | |
3524 | } | |
3525 | ||
3526 | $_SESSION["prefs_op_result"] = ""; | |
3527 | ||
cbb01696 AD |
3528 | print "<form action=\"backend.php\" method=\"GET\">"; |
3529 | ||
3530 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3531 | print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>"; | |
3532 | ||
3533 | $result = db_query($link, "SELECT email FROM ttrss_users | |
3534 | WHERE id = ".$_SESSION["uid"]); | |
3535 | ||
3536 | $email = db_fetch_result($result, 0, "email"); | |
3537 | ||
3538 | print "<tr><td width=\"40%\">E-mail</td>"; | |
3539 | print "<td><input class=\"editbox\" name=\"email\" | |
3540 | value=\"$email\"></td></tr>"; | |
3541 | ||
3542 | print "</table>"; | |
3543 | ||
3544 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3545 | ||
3546 | print "<p><input class=\"button\" type=\"submit\" | |
3547 | value=\"Change e-mail\" name=\"subop\">"; | |
3548 | ||
a132b8b1 AD |
3549 | print "</form>"; |
3550 | ||
7d4c898a AD |
3551 | print "<form action=\"backend.php\" method=\"POST\">"; |
3552 | ||
3553 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3554 | print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>"; | |
3555 | ||
3556 | print "<tr><td width=\"40%\">Old password</td>"; | |
3557 | print "<td><input class=\"editbox\" type=\"password\" | |
3558 | name=\"OLD_PASSWORD\"></td></tr>"; | |
3559 | ||
3560 | print "<tr><td width=\"40%\">New password</td>"; | |
3561 | ||
3562 | print "<td><input class=\"editbox\" type=\"password\" | |
3563 | name=\"NEW_PASSWORD\"></td></tr>"; | |
3564 | ||
3565 | print "</table>"; | |
3566 | ||
3567 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3568 | ||
3569 | print "<p><input class=\"button\" type=\"submit\" | |
3570 | value=\"Change password\" name=\"subop\">"; | |
3571 | ||
3572 | print "</form>"; | |
1c7f75ed | 3573 | |
7d4c898a | 3574 | } |
1c7f75ed | 3575 | |
58f8ad54 AD |
3576 | $result = db_query($link, "SELECT |
3577 | theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]); | |
3578 | ||
3579 | $user_theme_id = db_fetch_result($result, 0, "theme_id"); | |
3580 | ||
3581 | $result = db_query($link, "SELECT | |
3582 | id,theme_name FROM ttrss_themes ORDER BY theme_name"); | |
3583 | ||
3584 | if (db_num_rows($result) > 0) { | |
6752e330 AD |
3585 | |
3586 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3587 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3588 | print "<tr><td colspan='3'><h3>Themes</h3></tr></td>"; | |
3589 | print "<tr><td width=\"40%\">Select theme</td>"; | |
3590 | print "<td><select name=\"theme\">"; | |
3591 | print "<option>Default</option>"; | |
58f8ad54 | 3592 | print "<option disabled>--------</option>"; |
6752e330 | 3593 | |
58f8ad54 AD |
3594 | while ($line = db_fetch_assoc($result)) { |
3595 | if ($line["id"] == $user_theme_id) { | |
3596 | $selected = "selected"; | |
3597 | } else { | |
3598 | $selected = ""; | |
3599 | } | |
3600 | print "<option $selected>" . $line["theme_name"] . "</option>"; | |
3601 | } | |
6752e330 AD |
3602 | print "</select></td></tr>"; |
3603 | print "</table>"; | |
3604 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3605 | print "<p><input class=\"button\" type=\"submit\" | |
3606 | value=\"Change theme\" name=\"subop\">"; | |
3607 | print "</form>"; | |
58f8ad54 AD |
3608 | } |
3609 | ||
77e96719 | 3610 | $result = db_query($link, "SELECT |
ff485f1d | 3611 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, |
77e96719 | 3612 | section_name,def_value |
ff485f1d | 3613 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
77e96719 | 3614 | WHERE type_id = ttrss_prefs_types.id AND |
ff485f1d | 3615 | section_id = ttrss_prefs_sections.id AND |
a2411bd9 AD |
3616 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
3617 | owner_uid = ".$_SESSION["uid"]." | |
650bc435 | 3618 | ORDER BY section_id,short_desc"); |
77e96719 AD |
3619 | |
3620 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3621 | ||
77e96719 AD |
3622 | $lnum = 0; |
3623 | ||
3624 | $active_section = ""; | |
3625 | ||
3626 | while ($line = db_fetch_assoc($result)) { | |
3627 | ||
3628 | if ($active_section != $line["section_name"]) { | |
59a654ba AD |
3629 | |
3630 | if ($active_section != "") { | |
1c7f75ed | 3631 | print "</table>"; |
59a654ba | 3632 | } |
1c7f75ed AD |
3633 | |
3634 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
59a654ba AD |
3635 | |
3636 | $active_section = $line["section_name"]; | |
3637 | ||
77e96719 | 3638 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; |
59a654ba AD |
3639 | // print "<tr class=\"title\"> |
3640 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
7268adf7 AD |
3641 | |
3642 | $lnum = 0; | |
77e96719 AD |
3643 | } |
3644 | ||
650bc435 | 3645 | // $class = ($lnum % 2) ? "even" : "odd"; |
77e96719 | 3646 | |
650bc435 | 3647 | print "<tr>"; |
77e96719 | 3648 | |
77e96719 AD |
3649 | $type_name = $line["type_name"]; |
3650 | $pref_name = $line["pref_name"]; | |
3651 | $value = $line["value"]; | |
3652 | $def_value = $line["def_value"]; | |
b1895692 AD |
3653 | $help_text = $line["help_text"]; |
3654 | ||
3655 | print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"]; | |
3656 | ||
3657 | if ($help_text) print "<div class=\"prefHelp\">$help_text</div>"; | |
3658 | ||
3659 | print "</td>"; | |
77e96719 AD |
3660 | |
3661 | print "<td>"; | |
3662 | ||
3663 | if ($type_name == "bool") { | |
3664 | // print_select($pref_name, $value, array("true", "false")); | |
3665 | ||
3666 | if ($value == "true") { | |
3667 | $value = "Yes"; | |
3668 | } else { | |
3669 | $value = "No"; | |
3670 | } | |
3671 | ||
3672 | print_radio($pref_name, $value, array("Yes", "No")); | |
3673 | ||
3674 | } else { | |
3675 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
3676 | } | |
3677 | ||
3678 | print "</td>"; | |
3679 | ||
3680 | print "</tr>"; | |
3681 | ||
3682 | $lnum++; | |
3683 | } | |
3684 | ||
3685 | print "</table>"; | |
3686 | ||
3687 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3688 | ||
3689 | print "<p><input class=\"button\" type=\"submit\" | |
3690 | name=\"subop\" value=\"Save configuration\">"; | |
3691 | ||
3692 | print " <input class=\"button\" type=\"submit\" | |
69668465 AD |
3693 | name=\"subop\" onclick=\"return validatePrefsReset()\" |
3694 | value=\"Reset to defaults\"></p>"; | |
77e96719 AD |
3695 | |
3696 | print "</form>"; | |
3697 | ||
3698 | } | |
3699 | ||
3700 | } | |
3701 | ||
e6cb77a0 AD |
3702 | if ($op == "pref-users") { |
3703 | ||
3704 | $subop = $_GET["subop"]; | |
3705 | ||
3706 | if ($subop == "editSave") { | |
3707 | ||
3708 | if (!WEB_DEMO_MODE) { | |
3709 | ||
3710 | $login = db_escape_string($_GET["l"]); | |
3711 | $uid = db_escape_string($_GET["id"]); | |
3712 | $access_level = sprintf("%d", $_GET["al"]); | |
72932a75 | 3713 | $email = db_escape_string($_GET["e"]); |
e6cb77a0 | 3714 | |
72932a75 AD |
3715 | db_query($link, "UPDATE ttrss_users SET login = '$login', |
3716 | access_level = '$access_level', email = '$email' WHERE id = '$uid'"); | |
e6cb77a0 AD |
3717 | |
3718 | } | |
3719 | } else if ($subop == "remove") { | |
3720 | ||
3721 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3722 | ||
f932bc9f | 3723 | $ids = split(",", db_escape_string($_GET["ids"])); |
e6cb77a0 AD |
3724 | |
3725 | foreach ($ids as $id) { | |
3726 | db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]); | |
3727 | ||
3728 | } | |
3729 | } | |
3730 | } else if ($subop == "add") { | |
3731 | ||
3732 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3733 | ||
b6b535ca | 3734 | $login = db_escape_string(trim($_GET["login"])); |
e6cb77a0 AD |
3735 | $tmp_user_pwd = make_password(8); |
3736 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3737 | ||
69c0d759 AD |
3738 | db_query($link, "INSERT INTO ttrss_users |
3739 | (login,pwd_hash,access_level,last_login) | |
3740 | VALUES ('$login', '$pwd_hash', 0, NOW())"); | |
e6cb77a0 AD |
3741 | |
3742 | ||
3743 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
3744 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
3745 | ||
3746 | if (db_num_rows($result) == 1) { | |
3747 | ||
3748 | $new_uid = db_fetch_result($result, 0, "id"); | |
3749 | ||
3750 | print "<div class=\"notice\">Added user <b>".$_GET["login"]. | |
3751 | "</b> with password <b>$tmp_user_pwd</b>.</div>"; | |
3752 | ||
3753 | initialize_user($link, $new_uid); | |
3754 | ||
3755 | } else { | |
3756 | ||
3757 | print "<div class=\"warning\">Error while adding user <b>". | |
3758 | $_GET["login"].".</b></div>"; | |
3759 | ||
3760 | } | |
3761 | } | |
3762 | } else if ($subop == "resetPass") { | |
3763 | ||
3764 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3765 | ||
3766 | $uid = db_escape_string($_GET["id"]); | |
3767 | ||
72932a75 AD |
3768 | $result = db_query($link, "SELECT login,email |
3769 | FROM ttrss_users WHERE id = '$uid'"); | |
e6cb77a0 AD |
3770 | |
3771 | $login = db_fetch_result($result, 0, "login"); | |
72932a75 | 3772 | $email = db_fetch_result($result, 0, "email"); |
e6cb77a0 AD |
3773 | $tmp_user_pwd = make_password(8); |
3774 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3775 | ||
3776 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
3777 | WHERE id = '$uid'"); | |
3778 | ||
3779 | print "<div class=\"notice\">Changed password of | |
72932a75 AD |
3780 | user <b>$login</b> to <b>$tmp_user_pwd</b>."; |
3781 | ||
3782 | if (MAIL_RESET_PASS && $email) { | |
3783 | print " Notifying <b>$email</b>."; | |
3784 | ||
3785 | mail("$login <$email>", "Password reset notification", | |
3786 | "Hi, $login.\n". | |
3787 | "\n". | |
3788 | "Your password for this TT-RSS installation was reset by". | |
3789 | " an administrator.\n". | |
3790 | "\n". | |
3791 | "Your new password is $tmp_user_pwd, please remember". | |
3792 | " it for later reference.\n". | |
3793 | "\n". | |
3794 | "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM); | |
3795 | } | |
3796 | ||
3797 | print "</div>"; | |
e6cb77a0 AD |
3798 | |
3799 | } | |
3800 | } | |
3801 | ||
2c7070b5 | 3802 | print "<div class=\"prefGenericAddBox\"> |
f932bc9f | 3803 | <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> "; |
e6cb77a0 | 3804 | |
2c7070b5 AD |
3805 | print"<input type=\"submit\" class=\"button\" |
3806 | onclick=\"javascript:addUser()\" value=\"Add user\"></div>"; | |
e6cb77a0 AD |
3807 | |
3808 | $result = db_query($link, "SELECT | |
72932a75 | 3809 | id,login,access_level,email, |
fe99ab12 | 3810 | SUBSTRING(last_login,1,16) as last_login |
e6cb77a0 AD |
3811 | FROM |
3812 | ttrss_users | |
3813 | ORDER by login"); | |
3814 | ||
2317ffaa | 3815 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
1a7572cb | 3816 | |
f4fe2cde AD |
3817 | print "<p><table width=\"100%\" cellspacing=\"0\" |
3818 | class=\"prefUserList\" id=\"prefUserList\">"; | |
e6cb77a0 | 3819 | |
35f3c923 AD |
3820 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> |
3821 | Select: | |
3822 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', | |
3055bc41 | 3823 | 'UMRR-', 'UMCHK-', true)\">All</a>, |
35f3c923 | 3824 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', |
3055bc41 | 3825 | 'UMRR-', 'UMCHK-', false)\">None</a> |
35f3c923 AD |
3826 | </td</tr>"; |
3827 | ||
e6cb77a0 | 3828 | print "<tr class=\"title\"> |
e325c6e7 | 3829 | <td align='center' width=\"5%\"> </td> |
72932a75 AD |
3830 | <td width='20%'>Username</td> |
3831 | <td width='20%'>E-mail</td> | |
3832 | <td width='20%'>Access Level</td> | |
3833 | <td width='20%'>Last login</td></tr>"; | |
e6cb77a0 AD |
3834 | |
3835 | $lnum = 0; | |
3836 | ||
3837 | while ($line = db_fetch_assoc($result)) { | |
3838 | ||
3839 | $class = ($lnum % 2) ? "even" : "odd"; | |
3840 | ||
3841 | $uid = $line["id"]; | |
3842 | $edit_uid = $_GET["id"]; | |
3843 | ||
4154a415 | 3844 | if ($subop == "edit" && $uid != $edit_uid) { |
e6cb77a0 | 3845 | $class .= "Grayed"; |
53226edc AD |
3846 | $this_row_id = ""; |
3847 | } else { | |
3848 | $this_row_id = "id=\"UMRR-$uid\""; | |
3849 | } | |
3850 | ||
3851 | print "<tr class=\"$class\" $this_row_id>"; | |
e6cb77a0 AD |
3852 | |
3853 | $line["login"] = htmlspecialchars($line["login"]); | |
3854 | ||
6be6bc03 AD |
3855 | $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'), |
3856 | strtotime($line["last_login"])); | |
3857 | ||
72932a75 | 3858 | /* if ($uid == $_SESSION["uid"]) { |
e6cb77a0 | 3859 | |
a426e532 | 3860 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" |
e6cb77a0 AD |
3861 | id=\"UMCHK-".$line["id"]."\"></td>"; |
3862 | ||
72932a75 AD |
3863 | print "<td>".$line["login"]."</td>"; |
3864 | print "<td>".$line["email"]."</td>"; | |
3865 | print "<td>".$line["access_level"]."</td>"; | |
e6cb77a0 | 3866 | |
72932a75 | 3867 | } else */ if (!$edit_uid || $subop != "edit") { |
e6cb77a0 | 3868 | |
a426e532 | 3869 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
1a7572cb | 3870 | type=\"checkbox\" id=\"UMCHK-$uid\"></td>"; |
e6cb77a0 AD |
3871 | |
3872 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
3873 | $line["login"] . "</td>"; | |
72932a75 AD |
3874 | |
3875 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
3876 | $line["email"] . "</td>"; | |
3877 | ||
e6cb77a0 AD |
3878 | print "<td><a href=\"javascript:editUser($uid);\">" . |
3879 | $line["access_level"] . "</td>"; | |
3880 | ||
3881 | } else if ($uid != $edit_uid) { | |
3882 | ||
72932a75 | 3883 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" |
e6cb77a0 AD |
3884 | id=\"UMCHK-".$line["id"]."\"></td>"; |
3885 | ||
3886 | print "<td>".$line["login"]."</td>"; | |
72932a75 | 3887 | print "<td>".$line["email"]."</td>"; |
e6cb77a0 AD |
3888 | print "<td>".$line["access_level"]."</td>"; |
3889 | ||
3890 | } else { | |
3891 | ||
72932a75 AD |
3892 | print "<td align='center'> |
3893 | <input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
e6cb77a0 AD |
3894 | |
3895 | print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"]. | |
3896 | "\"></td>"; | |
3897 | ||
72932a75 AD |
3898 | print "<td><input id=\"iedit_email\" value=\"".$line["email"]. |
3899 | "\"></td>"; | |
3900 | ||
e6cb77a0 AD |
3901 | print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"]. |
3902 | "\"></td>"; | |
3903 | ||
3904 | } | |
3905 | ||
f6f32198 AD |
3906 | print "<td>".$line["last_login"]."</td>"; |
3907 | ||
e6cb77a0 AD |
3908 | print "</tr>"; |
3909 | ||
3910 | ++$lnum; | |
3911 | } | |
3912 | ||
3913 | print "</table>"; | |
3914 | ||
3915 | print "<p>"; | |
3916 | ||
3917 | if ($subop == "edit") { | |
d10fabe4 | 3918 | print "Edit user: |
e6cb77a0 | 3919 | <input type=\"submit\" class=\"button\" |
d10fabe4 | 3920 | onclick=\"javascript:userEditSave()\" value=\"Save\"> |
e6cb77a0 | 3921 | <input type=\"submit\" class=\"button\" |
d10fabe4 | 3922 | onclick=\"javascript:userEditCancel()\" value=\"Cancel\">"; |
e6cb77a0 AD |
3923 | |
3924 | } else { | |
3925 | ||
3926 | print " | |
3927 | Selection: | |
3928 | <input type=\"submit\" class=\"button\" | |
717f5e64 | 3929 | onclick=\"javascript:selectedUserDetails()\" value=\"User details\"> |
e6cb77a0 AD |
3930 | <input type=\"submit\" class=\"button\" |
3931 | onclick=\"javascript:editSelectedUser()\" value=\"Edit\"> | |
3932 | <input type=\"submit\" class=\"button\" | |
717f5e64 AD |
3933 | onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\"> |
3934 | <input type=\"submit\" class=\"button\" | |
3935 | onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">"; | |
3936 | ||
3937 | } | |
3938 | } | |
3939 | ||
3940 | if ($op == "user-details") { | |
3941 | ||
3942 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { | |
3943 | return; | |
3944 | } | |
3945 | ||
1a7572cb | 3946 | /* print "<html><head> |
717f5e64 AD |
3947 | <title>Tiny Tiny RSS : User Details</title> |
3948 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
3949 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
1a7572cb | 3950 | </head><body>"; */ |
717f5e64 AD |
3951 | |
3952 | $uid = sprintf("%d", $_GET["id"]); | |
3953 | ||
c6c3a07f | 3954 | print "<div class='infoBoxContents'>"; |
717f5e64 | 3955 | |
fe99ab12 AD |
3956 | $result = db_query($link, "SELECT login, |
3957 | SUBSTRING(last_login,1,16) AS last_login, | |
3958 | access_level, | |
c6c3a07f AD |
3959 | (SELECT COUNT(int_id) FROM ttrss_user_entries |
3960 | WHERE owner_uid = id) AS stored_articles | |
717f5e64 AD |
3961 | FROM ttrss_users |
3962 | WHERE id = '$uid'"); | |
3963 | ||
3964 | if (db_num_rows($result) == 0) { | |
3965 | print "<h1>User not found</h1>"; | |
3966 | return; | |
3967 | } | |
3968 | ||
3969 | print "<h1>User Details</h1>"; | |
3970 | ||
3971 | print "<table width='100%'>"; | |
3972 | ||
3973 | $login = db_fetch_result($result, 0, "login"); | |
6be6bc03 AD |
3974 | $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'), |
3975 | strtotime(db_fetch_result($result, 0, "last_login"))); | |
717f5e64 | 3976 | $access_level = db_fetch_result($result, 0, "access_level"); |
c6c3a07f | 3977 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); |
717f5e64 AD |
3978 | |
3979 | print "<tr><td>Username</td><td>$login</td></tr>"; | |
3980 | print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
3981 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
c6c3a07f | 3982 | print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>"; |
717f5e64 AD |
3983 | |
3984 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
3985 | WHERE owner_uid = '$uid'"); | |
3986 | ||
3987 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
3988 | ||
3989 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; | |
3990 | ||
5d15d3ea | 3991 | /* $result = db_query($link, "SELECT |
717f5e64 | 3992 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size |
c6c3a07f AD |
3993 | FROM ttrss_user_entries,ttrss_entries |
3994 | WHERE owner_uid = '$uid' AND ref_id = id"); | |
717f5e64 | 3995 | |
d9f115c3 | 3996 | $db_size = round(db_fetch_result($result, 0, "db_size") / 1024); |
717f5e64 | 3997 | |
c6c3a07f | 3998 | print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */ |
717f5e64 AD |
3999 | |
4000 | print "</table>"; | |
4001 | ||
4002 | print "<h1>Subscribed feeds</h1>"; | |
4003 | ||
e94645ca | 4004 | $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds |
9b3e2cc7 | 4005 | WHERE owner_uid = '$uid' ORDER BY title"); |
717f5e64 | 4006 | |
9b3e2cc7 | 4007 | print "<ul class=\"userFeedList\">"; |
717f5e64 AD |
4008 | |
4009 | while ($line = db_fetch_assoc($result)) { | |
4010 | ||
4011 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
4012 | ||
4013 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
6c56687e | 4014 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; |
717f5e64 | 4015 | } else { |
5951ded1 | 4016 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; |
717f5e64 AD |
4017 | } |
4018 | ||
e94645ca | 4019 | print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; |
e6cb77a0 | 4020 | } |
717f5e64 | 4021 | |
a88c1f36 AD |
4022 | if (db_num_rows($result) < $num_feeds) { |
4023 | // FIXME - add link to show ALL subscribed feeds here somewhere | |
4024 | print "<li><img | |
4025 | class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>"; | |
4026 | } | |
4027 | ||
717f5e64 AD |
4028 | print "</ul>"; |
4029 | ||
717f5e64 AD |
4030 | print "</div>"; |
4031 | ||
1a7572cb AD |
4032 | print "<div align='center'> |
4033 | <input type='submit' class='button' | |
c6c3a07f | 4034 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; |
1a7572cb AD |
4035 | |
4036 | // print "</body></html>"; | |
717f5e64 | 4037 | |
e6cb77a0 AD |
4038 | } |
4039 | ||
c6c3a07f AD |
4040 | if ($op == "feed-details") { |
4041 | ||
df268d47 | 4042 | // $feed_id = $_GET["id"]; |
4fec9fd7 | 4043 | |
df268d47 | 4044 | $feed_ids = split(",", db_escape_string($_GET["id"])); |
c6c3a07f | 4045 | |
df268d47 | 4046 | print "<div class=\"infoBoxContents\">"; |
bca02305 | 4047 | |
df268d47 | 4048 | foreach ($feed_ids as $feed_id) { |
c6c3a07f | 4049 | |
df268d47 AD |
4050 | $result = db_query($link, |
4051 | "SELECT | |
4052 | title,feed_url, | |
4053 | SUBSTRING(last_updated,1,16) as last_updated, | |
4054 | icon_url,site_url, | |
4055 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
4056 | WHERE feed_id = id) AS total, | |
4057 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
4058 | WHERE feed_id = id AND unread = true) AS unread, | |
4059 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
4060 | WHERE feed_id = id AND marked = true) AS marked | |
4061 | FROM ttrss_feeds | |
4062 | WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]); | |
4063 | ||
4064 | if (db_num_rows($result) == 0) return; | |
4065 | ||
4066 | $title = db_unescape_string(db_fetch_result($result, 0, "title")); | |
4067 | $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
4068 | strtotime(db_fetch_result($result, 0, "last_updated"))); | |
4069 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
4070 | $icon_url = db_fetch_result($result, 0, "icon_url"); | |
4071 | $total = db_fetch_result($result, 0, "total"); | |
4072 | $unread = db_fetch_result($result, 0, "unread"); | |
4073 | $marked = db_fetch_result($result, 0, "marked"); | |
4074 | $site_url = db_fetch_result($result, 0, "site_url"); | |
bca02305 | 4075 | |
df268d47 | 4076 | $result = db_query($link, "SELECT COUNT(id) AS subscribed |
3803fa6a | 4077 | FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false"); |
df268d47 AD |
4078 | |
4079 | $subscribed = db_fetch_result($result, 0, "subscribed"); | |
4080 | ||
4081 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
4082 | ||
4083 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
4084 | $feed_icon = "<img width=\"16\" height=\"16\" | |
4085 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
4086 | } else { | |
4087 | $feed_icon = ""; | |
bca02305 AD |
4088 | } |
4089 | ||
df268d47 | 4090 | print "<h1>$feed_icon $title</h1>"; |
bca02305 | 4091 | |
df268d47 | 4092 | print "<table width='100%'>"; |
bca02305 | 4093 | |
df268d47 AD |
4094 | if ($site_url) { |
4095 | print "<tr><td width='30%'>Link</td> | |
4096 | <td><a href=\"$site_url\">$site_url</a> | |
4097 | <a href=\"$feed_url\">(feed)</a></td> | |
4098 | </td></tr>"; | |
4099 | } else { | |
4100 | print "<tr><td width='30%'>Feed URL</td> | |
4101 | <td><a href=\"$feed_url\">$feed_url</a></td></tr>"; | |
4102 | } | |
4103 | print "<tr><td>Last updated</td><td>$last_updated</td></tr>"; | |
4104 | print "<tr><td>Total articles</td><td>$total</td></tr>"; | |
4105 | print "<tr><td>Unread articles</td><td>$unread</td></tr>"; | |
4106 | print "<tr><td>Starred articles</td><td>$marked</td></tr>"; | |
4107 | print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>"; | |
4108 | ||
4109 | print "</table>"; | |
4110 | ||
4111 | /* $result = db_query($link, "SELECT title, | |
4112 | SUBSTRING(updated,1,16) AS updated,unread | |
4113 | FROM ttrss_entries,ttrss_user_entries | |
4114 | WHERE ref_id = id AND feed_id = '$feed_id' | |
4115 | ORDER BY date_entered DESC LIMIT 5"); | |
4116 | ||
4117 | if (db_num_rows($result) > 0) { | |
4118 | ||
4119 | print "<h1>Latest headlines</h1>"; | |
4120 | ||
4121 | print "<ul class=\"nomarks\">"; | |
4122 | ||
4123 | while ($line = db_fetch_assoc($result)) { | |
4124 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
4125 | $line["title"] = "<b>" . $line["title"] . "</b>"; | |
4126 | } | |
4127 | print "<li>" . $line["title"]. | |
4128 | " <span class=\"insensitive\">(" . | |
4129 | date(get_pref($link, 'SHORT_DATE_FORMAT'), | |
4130 | strtotime($line["updated"])). | |
4131 | ")</span></li>"; | |
4132 | } | |
4133 | ||
4134 | print "</ul>"; | |
4135 | ||
4136 | } */ | |
bca02305 | 4137 | } |
df268d47 AD |
4138 | |
4139 | print "</div>"; | |
4140 | ||
4141 | print "<div align='center'> | |
4142 | <input type='submit' class='button' | |
4143 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
4144 | } | |
c6c3a07f | 4145 | |
c6232e43 AD |
4146 | if ($op == "pref-feed-browser") { |
4147 | ||
e2f728be AD |
4148 | if (!ENABLE_FEED_BROWSER) { |
4149 | print "Feed browser is administratively disabled."; | |
4150 | return; | |
4151 | } | |
4152 | ||
c6232e43 AD |
4153 | $subop = $_REQUEST["subop"]; |
4154 | ||
4155 | if ($subop == "details") { | |
4156 | $id = db_escape_string($_GET["id"]); | |
c2b2aee0 | 4157 | |
072f1ee2 AD |
4158 | print "<div class=\"browserFeedInfo\">"; |
4159 | print "<b>Feed information:</b>"; | |
4160 | print "<div class=\"detailsPart\">"; | |
4161 | ||
4162 | $result = db_query($link, "SELECT | |
4163 | feed_url,site_url, | |
4164 | SUBSTRING(last_updated,1,19) AS last_updated | |
4165 | FROM ttrss_feeds WHERE id = '$id'"); | |
4166 | ||
4167 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
4168 | $site_url = db_fetch_result($result, 0, "site_url"); | |
4169 | $last_updated = db_fetch_result($result, 0, "last_updated"); | |
4170 | ||
4171 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
4172 | $last_updated = smart_date_time(strtotime($last_updated)); | |
4173 | } else { | |
4174 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
4175 | $last_updated = date($short_date, strtotime($last_updated)); | |
4176 | } | |
4177 | ||
4178 | print "Site: <a href='$site_url'>$site_url</a> ". | |
4179 | "(<a href='$feed_url'>feed</a>), ". | |
4180 | "Last updated: $last_updated"; | |
4181 | ||
4182 | print "</div>"; | |
4183 | ||
4184 | $result = db_query($link, "SELECT | |
4185 | ttrss_entries.title, | |
4186 | content, | |
c2b2aee0 AD |
4187 | substring(date_entered,1,19) as date_entered, |
4188 | substring(updated,1,19) as updated | |
072f1ee2 AD |
4189 | FROM ttrss_entries,ttrss_user_entries |
4190 | WHERE ttrss_entries.id = ref_id AND feed_id = '$id' | |
c2b2aee0 AD |
4191 | ORDER BY updated DESC LIMIT 5"); |
4192 | ||
4193 | if (db_num_rows($result) > 0) { | |
c2b2aee0 AD |
4194 | |
4195 | print "<b>Last headlines:</b><br>"; | |
4196 | ||
4197 | print "<div class=\"detailsPart\">"; | |
4198 | print "<ul class=\"compact\">"; | |
4199 | while ($line = db_fetch_assoc($result)) { | |
4200 | ||
4201 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
4202 | $entry_dt = smart_date_time(strtotime($line["updated"])); | |
4203 | } else { | |
4204 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
4205 | $entry_dt = date($short_date, strtotime($line["updated"])); | |
4206 | } | |
4207 | ||
4208 | print "<li>" . $line["title"] . | |
4209 | " <span class=\"insensitive\">($entry_dt)</span></li>"; | |
4210 | } | |
4211 | print "</ul></div>"; | |
4212 | } | |
072f1ee2 AD |
4213 | |
4214 | print "</div>"; | |
c2b2aee0 | 4215 | |
c6232e43 AD |
4216 | return; |
4217 | } | |
65f28a40 | 4218 | |
c6232e43 AD |
4219 | $result = db_query($link, "SELECT feed_url,count(id) AS subscribers |
4220 | FROM ttrss_feeds | |
4221 | WHERE auth_login = '' AND auth_pass = '' AND private = false | |
65f28a40 | 4222 | GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100"); |
c6232e43 | 4223 | |
0fefdacc | 4224 | print "<ul class='nomarks' id='browseBigFeedList'>"; |
c6232e43 AD |
4225 | |
4226 | $feedctr = 0; | |
4227 | ||
4228 | while ($line = db_fetch_assoc($result)) { | |
4229 | $feed_url = $line["feed_url"]; | |
4230 | $subscribers = $line["subscribers"]; | |
4231 | ||
4232 | $sub_result = db_query($link, "SELECT id | |
4233 | FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" . | |
4234 | $_SESSION["uid"]); | |
4235 | ||
4236 | if (db_num_rows($sub_result) > 0) { | |
4237 | continue; // already subscribed | |
4238 | } | |
4239 | ||
4240 | $det_result = db_query($link, "SELECT site_url,title,id | |
4241 | FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1"); | |
4242 | ||
4243 | $details = db_fetch_assoc($det_result); | |
4244 | ||
4245 | $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico"; | |
4246 | ||
4247 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
4248 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . | |
4249 | "/".$details["id"].".ico\">"; | |
4250 | } else { | |
4251 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
4252 | } | |
4253 | ||
4254 | $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' | |
4255 | type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">"; | |
4256 | ||
4257 | $class = ($feedctr % 2) ? "even" : "odd"; | |
4258 | ||
4259 | print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box". | |
4260 | "$feed_icon "; | |
4261 | ||
c2b2aee0 | 4262 | print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" . |
c6232e43 AD |
4263 | $details["title"] ."</a> " . |
4264 | "<span class='subscribers'>($subscribers)</span>"; | |
4265 | ||
4266 | print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">"; | |
4267 | print "</div>"; | |
4268 | ||
4269 | print "</li>"; | |
4270 | ||
4271 | ++$feedctr; | |
4272 | } | |
4273 | ||
4274 | if ($feedctr == 0) { | |
4275 | print "<li>No feeds found to subscribe.</li>"; | |
4276 | } | |
4277 | ||
4278 | print "</ul>"; | |
4279 | ||
0010d872 AD |
4280 | print "<p>Selection: |
4281 | <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\" | |
4282 | value=\"Subscribe\"></p>"; | |
c6232e43 AD |
4283 | |
4284 | print "</div>"; | |
4285 | ||
4286 | } | |
4287 | ||
4b3dff6e | 4288 | db_close($link); |
1cd17194 | 4289 | ?> |
406d9489 AD |
4290 | |
4291 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
4292 |