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