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