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