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