]>
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 | 1660 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) |
746b249f AD |
1661 | VALUES ('".$_SESSION["uid"]."', '$feed_link', |
1662 | '[Unknown]', $cat_qpart)"); | |
331900c6 | 1663 | |
7e9a3986 | 1664 | $result = db_query($link, |
746b249f | 1665 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' |
7e9a3986 AD |
1666 | AND owner_uid = " . $_SESSION["uid"]); |
1667 | ||
1668 | $feed_id = db_fetch_result($result, 0, "id"); | |
1669 | ||
1670 | if ($feed_id) { | |
ddb68b81 | 1671 | update_rss_feed($link, $feed_link, $feed_id, true); |
7e9a3986 AD |
1672 | } |
1673 | } else { | |
331900c6 | 1674 | |
7e9a3986 AD |
1675 | print "<div class=\"warning\"> |
1676 | Feed <b>$feed_link</b> already exists in the database. | |
1677 | </div>"; | |
b0b4abcf AD |
1678 | } |
1679 | } | |
331900c6 | 1680 | } |
a0d53889 | 1681 | |
91ff844a AD |
1682 | if ($subop == "addCat") { |
1683 | ||
1684 | if (!WEB_DEMO_MODE) { | |
1685 | ||
1686 | $feed_cat = db_escape_string(trim($_GET["cat"])); | |
1687 | ||
1688 | $result = db_query($link, | |
1689 | "SELECT id FROM ttrss_feed_categories | |
1690 | WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); | |
1691 | ||
1692 | if (db_num_rows($result) == 0) { | |
1693 | ||
1694 | $result = db_query($link, | |
1695 | "INSERT INTO ttrss_feed_categories (owner_uid,title) | |
1696 | VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); | |
1697 | ||
1698 | } else { | |
1699 | ||
1700 | print "<div class=\"warning\"> | |
1701 | Category <b>$feed_cat</b> already exists in the database. | |
1702 | </div>"; | |
1703 | } | |
1704 | ||
1705 | ||
1706 | } | |
1707 | } | |
1708 | ||
1709 | if ($subop == "removeCats") { | |
1710 | ||
1711 | if (!WEB_DEMO_MODE) { | |
1712 | ||
f932bc9f | 1713 | $ids = split(",", db_escape_string($_GET["ids"])); |
91ff844a AD |
1714 | |
1715 | foreach ($ids as $id) { | |
1716 | ||
1717 | db_query($link, "BEGIN"); | |
1718 | ||
1719 | $result = db_query($link, | |
1720 | "SELECT count(id) as num_feeds FROM ttrss_feeds | |
1721 | WHERE cat_id = '$id'"); | |
1722 | ||
1723 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
1724 | ||
1725 | if ($num_feeds == 0) { | |
1726 | db_query($link, "DELETE FROM ttrss_feed_categories | |
1727 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1728 | } else { | |
1729 | ||
1730 | print "<div class=\"warning\"> | |
1731 | Unable to delete non empty feed categories.</div>"; | |
1732 | ||
1733 | } | |
1734 | ||
1735 | db_query($link, "COMMIT"); | |
1736 | } | |
1737 | } | |
1738 | } | |
1739 | ||
f932bc9f AD |
1740 | if ($subop == "categorize") { |
1741 | ||
1742 | if (!WEB_DEMO_MODE) { | |
1743 | ||
1744 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1745 | ||
1746 | $cat_id = db_escape_string($_GET["cat_id"]); | |
1747 | ||
1748 | if ($cat_id == 0) { | |
1749 | $cat_id_qpart = 'NULL'; | |
1750 | } else { | |
1751 | $cat_id_qpart = "'$cat_id'"; | |
1752 | } | |
1753 | ||
1754 | db_query($link, "BEGIN"); | |
1755 | ||
1756 | foreach ($ids as $id) { | |
1757 | ||
1758 | db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart | |
1759 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1760 | } | |
1761 | ||
1762 | db_query($link, "COMMIT"); | |
1763 | } | |
1764 | ||
1765 | } | |
1766 | ||
a24f525c AD |
1767 | if ($quiet) return; |
1768 | ||
c64d5b03 | 1769 | // print "<h3>Edit Feeds</h3>"; |
91ff844a | 1770 | |
4904f845 AD |
1771 | $result = db_query($link, "SELECT id,title,feed_url,last_error |
1772 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); | |
1773 | ||
1774 | if (db_num_rows($result) > 0) { | |
1775 | ||
1776 | print "<div class=\"warning\">"; | |
1777 | ||
36aab70f AD |
1778 | print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\"> |
1779 | <b>Feeds with update errors</b> (click to expand)</a>"; | |
4904f845 | 1780 | |
36aab70f | 1781 | print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">"; |
4904f845 AD |
1782 | |
1783 | while ($line = db_fetch_assoc($result)) { | |
1784 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
1785 | $line["last_error"]; | |
1786 | } | |
1787 | ||
1788 | print "</ul>"; | |
1789 | print "</div>"; | |
1790 | ||
1791 | } | |
1792 | ||
f932bc9f AD |
1793 | $feed_search = db_escape_string($_GET["search"]); |
1794 | ||
1795 | if (array_key_exists("search", $_GET)) { | |
1796 | $_SESSION["prefs_feed_search"] = $feed_search; | |
1797 | } else { | |
1798 | $feed_search = $_SESSION["prefs_feed_search"]; | |
1799 | } | |
1800 | ||
1801 | print "<table width='100%' class=\"prefGenericAddBox\" | |
1802 | cellspacing='0' cellpadding='0'><tr> | |
1803 | <td> | |
1804 | <input id=\"fadd_link\" | |
1805 | onchange=\"javascript:addFeed()\" | |
1806 | size=\"40\"> | |
1807 | <input type=\"submit\" class=\"button\" | |
1808 | onclick=\"javascript:addFeed()\" value=\"Add feed\"> | |
1809 | </td><td align='right'> | |
1810 | <input id=\"feed_search\" size=\"20\" | |
1811 | onchange=\"javascript:updateFeedList()\" | |
1812 | value=\"$feed_search\"> | |
1813 | <input type=\"submit\" class=\"button\" | |
1814 | onclick=\"javascript:updateFeedList()\" value=\"Search\"> | |
1815 | </td> | |
1816 | </tr></table>"; | |
a0d53889 | 1817 | |
b83c7545 AD |
1818 | $feeds_sort = db_escape_string($_GET["sort"]); |
1819 | ||
1820 | if (!$feeds_sort || $feeds_sort == "undefined") { | |
1821 | $feeds_sort = $_SESSION["pref_sort_feeds"]; | |
1822 | if (!$feeds_sort) $feeds_sort = "title"; | |
1823 | } | |
1824 | ||
1825 | $_SESSION["pref_sort_feeds"] = $feeds_sort; | |
1826 | ||
f932bc9f | 1827 | if ($feed_search) { |
85af98a6 AD |
1828 | $search_qpart = "(UPPER(title) LIKE UPPER('%$feed_search%') OR |
1829 | UPPER(feed_url) LIKE UPPER('%$feed_search%')) AND"; | |
f932bc9f AD |
1830 | } else { |
1831 | $search_qpart = ""; | |
1832 | } | |
1833 | ||
648472a7 | 1834 | $result = db_query($link, "SELECT |
d148926e | 1835 | id,title,feed_url,substring(last_updated,1,16) as last_updated, |
76684fc7 | 1836 | update_interval,purge_interval,cat_id, |
91ff844a AD |
1837 | (SELECT title FROM ttrss_feed_categories |
1838 | WHERE id = cat_id) AS category | |
c0e5a40e | 1839 | FROM |
f932bc9f AD |
1840 | ttrss_feeds |
1841 | WHERE | |
1842 | $search_qpart owner_uid = '".$_SESSION["uid"]."' | |
0ea4fb50 | 1843 | ORDER by category,$feeds_sort,title"); |
1cd17194 | 1844 | |
3b0feb9b | 1845 | if (db_num_rows($result) != 0) { |
91ff844a | 1846 | |
3b0feb9b | 1847 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
35f3c923 | 1848 | |
f4fe2cde AD |
1849 | print "<p><table width=\"100%\" cellspacing=\"0\" |
1850 | class=\"prefFeedList\" id=\"prefFeedList\">"; | |
35f3c923 AD |
1851 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> |
1852 | Select: | |
1853 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', | |
3055bc41 | 1854 | 'FEEDR-', 'FRCHK-', true)\">All</a>, |
35f3c923 | 1855 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', |
3055bc41 | 1856 | 'FEEDR-', 'FRCHK-', false)\">None</a> |
35f3c923 AD |
1857 | </td</tr>"; |
1858 | ||
0ea4fb50 AD |
1859 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { |
1860 | print "<tr class=\"title\"> | |
e325c6e7 | 1861 | <td width='5%' align='center'> </td> |
62ac0cc8 | 1862 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> |
f42e9435 | 1863 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> |
62ac0cc8 AD |
1864 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> |
1865 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>"; | |
603c27f8 | 1866 | } |
603c27f8 | 1867 | |
c64d5b03 | 1868 | $lnum = 0; |
0ea4fb50 AD |
1869 | |
1870 | $cur_cat_id = -1; | |
c64d5b03 AD |
1871 | |
1872 | while ($line = db_fetch_assoc($result)) { | |
1873 | ||
3b0feb9b | 1874 | $feed_id = $line["id"]; |
0ea4fb50 AD |
1875 | $cat_id = $line["cat_id"]; |
1876 | ||
1877 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
1878 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
1879 | $edit_cat = htmlspecialchars(db_unescape_string($line["category"])); | |
c64d5b03 | 1880 | |
0ea4fb50 AD |
1881 | if ($line["update_interval"] == "0") $line["update_interval"] = "Default"; |
1882 | if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled"; | |
1883 | if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default"; | |
1884 | if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled"; | |
1885 | ||
1886 | if (!$edit_cat) $edit_cat = "Uncategorized"; | |
1887 | ||
1888 | ||
1889 | if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) { | |
cb58d0df AD |
1890 | $lnum = 0; |
1891 | ||
0ea4fb50 AD |
1892 | print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>"; |
1893 | ||
1894 | print "<tr class=\"title\"> | |
e325c6e7 | 1895 | <td width='5%' align='center'> </td> |
62ac0cc8 | 1896 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> |
f42e9435 | 1897 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> |
62ac0cc8 AD |
1898 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> |
1899 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>"; | |
0ea4fb50 AD |
1900 | |
1901 | $cur_cat_id = $cat_id; | |
c64d5b03 | 1902 | } |
0ea4fb50 | 1903 | |
cb58d0df | 1904 | $class = ($lnum % 2) ? "even" : "odd"; |
0ea4fb50 AD |
1905 | $this_row_id = "id=\"FEEDR-$feed_id\""; |
1906 | ||
53226edc | 1907 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
1908 | |
1909 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
1910 | ||
1911 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
327a3bbe | 1912 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">"; |
3b0feb9b | 1913 | } else { |
327a3bbe | 1914 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; |
3b0feb9b | 1915 | } |
327a3bbe | 1916 | // print "<td class='feedIcon'>$feed_icon</td>"; |
c64d5b03 | 1917 | |
62ac0cc8 | 1918 | print "<td class='feedSelect'><input onclick='toggleSelectRow(this);' |
0ea4fb50 | 1919 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
3547842a | 1920 | |
0ea4fb50 AD |
1921 | $edit_title = truncate_string($edit_title, 40); |
1922 | $edit_link = truncate_string($edit_link, 60); | |
a88c1f36 | 1923 | |
0ea4fb50 | 1924 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
327a3bbe | 1925 | "$feed_icon $edit_title" . "</a></td>"; |
0ea4fb50 AD |
1926 | |
1927 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1928 | $edit_link . "</a></td>"; | |
3547842a | 1929 | |
0ea4fb50 AD |
1930 | /* if (get_pref($link, 'ENABLE_FEED_CATS')) { |
1931 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1932 | $edit_cat . "</a></td>"; | |
1933 | } */ | |
3547842a | 1934 | |
0ea4fb50 AD |
1935 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
1936 | $line["update_interval"] . "</a></td>"; | |
3b0feb9b | 1937 | |
0ea4fb50 AD |
1938 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
1939 | $line["purge_interval"] . "</a></td>"; | |
3b0feb9b | 1940 | |
c64d5b03 AD |
1941 | print "</tr>"; |
1942 | ||
1943 | ++$lnum; | |
1944 | } | |
1945 | ||
c64d5b03 | 1946 | print "</table>"; |
3b0feb9b | 1947 | |
c64d5b03 AD |
1948 | print "<p>"; |
1949 | ||
3b0feb9b AD |
1950 | if ($subop == "edit") { |
1951 | print "Edit feed: | |
c64d5b03 | 1952 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 1953 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> |
c64d5b03 | 1954 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
1955 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
1956 | } else { | |
c64d5b03 AD |
1957 | |
1958 | print " | |
1959 | Selection: | |
1960 | <input type=\"submit\" class=\"button\" | |
3b0feb9b | 1961 | onclick=\"javascript:selectedFeedDetails()\" value=\"Details\"> |
c64d5b03 | 1962 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
1963 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> |
1964 | <input type=\"submit\" class=\"button\" | |
1965 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
f932bc9f AD |
1966 | |
1967 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1968 | ||
1969 | print " "; | |
1970 | ||
1971 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
1972 | WHERE owner_uid = ".$_SESSION["uid"]." | |
1973 | ORDER BY title"); | |
1974 | ||
1975 | print "<select id=\"sfeed_set_fcat\">"; | |
1976 | print "<option id=\"0\">Uncategorized</option>"; | |
1977 | ||
1978 | if (db_num_rows($result) != 0) { | |
1979 | ||
1980 | print "<option disabled>--------</option>"; | |
1981 | ||
1982 | while ($line = db_fetch_assoc($result)) { | |
1983 | printf("<option id='%d'>%s</option>", | |
1984 | $line["id"], $line["title"]); | |
1985 | } | |
1986 | } | |
1987 | ||
1988 | print "</select>"; | |
1989 | ||
1990 | print " <input type=\"submit\" class=\"button\" | |
1991 | onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">"; | |
1992 | ||
1993 | } | |
1994 | ||
3b0feb9b AD |
1995 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { |
1996 | print " | |
1997 | <input type=\"submit\" class=\"button\" | |
4f3a84f4 | 1998 | onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\"> |
3b0feb9b | 1999 | <input type=\"submit\" class=\"button\" |
4f3a84f4 | 2000 | onclick=\"javascript:readSelectedFeeds(false)\" |
3b0feb9b AD |
2001 | value=\"Mark as unread\"> "; |
2002 | } | |
2003 | ||
2004 | print " | |
f932bc9f | 2005 | All feeds: <input type=\"submit\" |
3b0feb9b AD |
2006 | class=\"button\" onclick=\"gotoExportOpml()\" |
2007 | value=\"Export OPML\">"; | |
2008 | } | |
2009 | } else { | |
2010 | ||
2011 | print "<p>No feeds defined.</p>"; | |
2012 | ||
2013 | } | |
2014 | ||
2015 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2016 | ||
2017 | print "<h3>Edit Categories</h3>"; | |
2018 | ||
2019 | // print "<h3>Categories</h3>"; | |
2020 | ||
2021 | print "<div class=\"prefGenericAddBox\"> | |
f932bc9f AD |
2022 | <input id=\"fadd_cat\" |
2023 | onchange=\"javascript:addFeedCat()\" | |
2024 | size=\"40\"> | |
2025 | <input | |
3b0feb9b AD |
2026 | type=\"submit\" class=\"button\" |
2027 | onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>"; | |
2028 | ||
2029 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2030 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2031 | ORDER BY title"); | |
2032 | ||
2033 | if (db_num_rows($result) != 0) { | |
2034 | ||
35f3c923 | 2035 | print "<p><table width=\"100%\" class=\"prefFeedCatList\" |
f4fe2cde | 2036 | cellspacing=\"0\" id=\"prefFeedCatList\">"; |
35f3c923 AD |
2037 | |
2038 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2039 | Select: | |
2040 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', | |
3055bc41 | 2041 | 'FCATR-', 'FCCHK-', true)\">All</a>, |
35f3c923 | 2042 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', |
3055bc41 | 2043 | 'FCATR-', 'FCCHK-', false)\">None</a> |
35f3c923 AD |
2044 | </td</tr>"; |
2045 | ||
3b0feb9b | 2046 | print "<tr class=\"title\"> |
a426e532 | 2047 | <td width=\"5%\"></td><td width=\"80%\">Title</td> |
3b0feb9b AD |
2048 | </tr>"; |
2049 | ||
2050 | $lnum = 0; | |
2051 | ||
2052 | while ($line = db_fetch_assoc($result)) { | |
2053 | ||
2054 | $class = ($lnum % 2) ? "even" : "odd"; | |
2055 | ||
2056 | $cat_id = $line["id"]; | |
2057 | ||
2058 | $edit_cat_id = $_GET["id"]; | |
2059 | ||
2060 | if ($subop == "editCat" && $cat_id != $edit_cat_id) { | |
2061 | $class .= "Grayed"; | |
53226edc AD |
2062 | $this_row_id = ""; |
2063 | } else { | |
2064 | $this_row_id = "id=\"FCATR-$cat_id\""; | |
3b0feb9b AD |
2065 | } |
2066 | ||
53226edc | 2067 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2068 | |
2069 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
2070 | ||
2071 | if (!$edit_cat_id || $subop != "editCat") { | |
2072 | ||
a426e532 | 2073 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
2074 | type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>"; |
2075 | ||
2076 | print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . | |
2077 | $edit_title . "</a></td>"; | |
2078 | ||
2079 | } else if ($cat_id != $edit_cat_id) { | |
2080 | ||
2081 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2082 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
2083 | ||
2084 | print "<td>$edit_title</td>"; | |
2085 | ||
2086 | } else { | |
2087 | ||
2088 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2089 | ||
2090 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; | |
2091 | ||
2092 | } | |
2093 | ||
2094 | print "</tr>"; | |
2095 | ||
2096 | ++$lnum; | |
2097 | } | |
2098 | ||
2099 | print "</table>"; | |
2100 | ||
2101 | print "<p>"; | |
2102 | ||
2103 | if ($subop == "editCat") { | |
2104 | print "Edit category: | |
2105 | <input type=\"submit\" class=\"button\" | |
2106 | onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\"> | |
2107 | <input type=\"submit\" class=\"button\" | |
2108 | onclick=\"javascript:feedCatEditSave()\" value=\"Save\">"; | |
2109 | } else { | |
2110 | ||
2111 | print " | |
2112 | Selection: | |
2113 | <input type=\"submit\" class=\"button\" | |
2114 | onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\"> | |
2115 | <input type=\"submit\" class=\"button\" | |
2116 | onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">"; | |
2117 | ||
2118 | } | |
2119 | ||
2120 | } else { | |
2121 | print "<p>No feed categories defined.</p>"; | |
2122 | } | |
c64d5b03 AD |
2123 | } |
2124 | ||
2125 | print "<h3>Import OPML</h3> | |
f5a50b25 AD |
2126 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> |
2127 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
2128 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
2129 | type=\"submit\" value=\"Import\"> | |
2130 | </form>"; | |
2131 | ||
007bda35 AD |
2132 | } |
2133 | ||
a0d53889 AD |
2134 | if ($op == "pref-filters") { |
2135 | ||
2136 | $subop = $_GET["subop"]; | |
a24f525c | 2137 | $quiet = $_GET["quiet"]; |
a0d53889 AD |
2138 | |
2139 | if ($subop == "editSave") { | |
a0d53889 | 2140 | |
648472a7 AD |
2141 | $regexp = db_escape_string($_GET["r"]); |
2142 | $descr = db_escape_string($_GET["d"]); | |
2143 | $match = db_escape_string($_GET["m"]); | |
2144 | $filter_id = db_escape_string($_GET["id"]); | |
ead60402 | 2145 | $feed_id = db_escape_string($_GET["fid"]); |
19c9cb11 | 2146 | $action_id = db_escape_string($_GET["aid"]); |
ead60402 AD |
2147 | |
2148 | if (!$feed_id) { | |
2149 | $feed_id = 'NULL'; | |
2150 | } else { | |
2151 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2152 | } | |
0afbd851 | 2153 | |
648472a7 | 2154 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 2155 | reg_exp = '$regexp', |
0afbd851 | 2156 | description = '$descr', |
ead60402 | 2157 | feed_id = $feed_id, |
19c9cb11 | 2158 | action_id = '$action_id', |
0afbd851 AD |
2159 | filter_type = (SELECT id FROM ttrss_filter_types WHERE |
2160 | description = '$match') | |
2161 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
2162 | } |
2163 | ||
2164 | if ($subop == "remove") { | |
2165 | ||
2166 | if (!WEB_DEMO_MODE) { | |
2167 | ||
f932bc9f | 2168 | $ids = split(",", db_escape_string($_GET["ids"])); |
a0d53889 AD |
2169 | |
2170 | foreach ($ids as $id) { | |
648472a7 | 2171 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
2172 | |
2173 | } | |
2174 | } | |
2175 | } | |
2176 | ||
2177 | if ($subop == "add") { | |
2178 | ||
de435974 | 2179 | if (!WEB_DEMO_MODE) { |
a0d53889 | 2180 | |
b6b535ca AD |
2181 | $regexp = db_escape_string(trim($_GET["regexp"])); |
2182 | $match = db_escape_string(trim($_GET["match"])); | |
ead60402 | 2183 | $feed_id = db_escape_string($_GET["fid"]); |
19c9cb11 | 2184 | $action_id = db_escape_string($_GET["aid"]); |
ead60402 AD |
2185 | |
2186 | if (!$feed_id) { | |
2187 | $feed_id = 'NULL'; | |
2188 | } else { | |
2189 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2190 | } | |
4401bf04 | 2191 | |
648472a7 | 2192 | $result = db_query($link, |
19c9cb11 AD |
2193 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, |
2194 | action_id) | |
2195 | VALUES | |
de435974 | 2196 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
19c9cb11 AD |
2197 | description = '$match'),'".$_SESSION["uid"]."', |
2198 | $feed_id, '$action_id')"); | |
de435974 | 2199 | } |
a0d53889 AD |
2200 | } |
2201 | ||
a24f525c AD |
2202 | if ($quiet) return; |
2203 | ||
648472a7 | 2204 | $result = db_query($link, "SELECT description |
a0d53889 AD |
2205 | FROM ttrss_filter_types ORDER BY description"); |
2206 | ||
2207 | $filter_types = array(); | |
2208 | ||
648472a7 | 2209 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
2210 | array_push($filter_types, $line["description"]); |
2211 | } | |
2212 | ||
2c7070b5 | 2213 | print "<div class=\"prefGenericAddBox\"> |
7cc1e5d6 | 2214 | <input id=\"fadd_regexp\" size=\"40\"> "; |
2c7070b5 | 2215 | |
ead60402 AD |
2216 | print_select("fadd_match", "Title", $filter_types); |
2217 | ||
2218 | print " <select id=\"fadd_feed\">"; | |
2219 | ||
2220 | print "<option selected id=\"0\">All feeds</option>"; | |
2221 | ||
2222 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2223 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2224 | ||
2225 | if (db_num_rows($result) > 0) { | |
2226 | print "<option disabled>--------</option>"; | |
2227 | } | |
2228 | ||
2229 | while ($line = db_fetch_assoc($result)) { | |
2230 | printf("<option id='%d'>%s</option>", $line["id"], $line["title"]); | |
2231 | } | |
2232 | ||
2c7070b5 | 2233 | print "</select> "; |
19c9cb11 AD |
2234 | |
2235 | print " Action: "; | |
2236 | ||
2237 | print "<select id=\"fadd_action\">"; | |
2238 | ||
2239 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2240 | ORDER BY name"); | |
2241 | ||
2242 | while ($line = db_fetch_assoc($result)) { | |
2243 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
2244 | } | |
2245 | ||
2246 | print "</select> "; | |
2247 | ||
2c7070b5 AD |
2248 | print "<input type=\"submit\" |
2249 | class=\"button\" onclick=\"javascript:addFilter()\" | |
2250 | value=\"Add filter\">"; | |
a0d53889 | 2251 | |
19c9cb11 AD |
2252 | print "</div>"; |
2253 | ||
648472a7 | 2254 | $result = db_query($link, "SELECT |
ead60402 AD |
2255 | ttrss_filters.id AS id,reg_exp, |
2256 | ttrss_filters.description AS description, | |
2257 | ttrss_filter_types.name AS filter_type_name, | |
2258 | ttrss_filter_types.description AS filter_type_descr, | |
2259 | feed_id, | |
19c9cb11 | 2260 | ttrss_filter_actions.description AS action_description, |
ead60402 | 2261 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title |
a0d53889 | 2262 | FROM |
19c9cb11 | 2263 | ttrss_filters,ttrss_filter_types,ttrss_filter_actions |
4356293a | 2264 | WHERE |
ead60402 | 2265 | filter_type = ttrss_filter_types.id AND |
19c9cb11 | 2266 | ttrss_filter_actions.id = action_id AND |
ead60402 | 2267 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." |
4356293a | 2268 | ORDER by reg_exp"); |
a0d53889 | 2269 | |
3b0feb9b | 2270 | if (db_num_rows($result) != 0) { |
a0d53889 | 2271 | |
f4fe2cde AD |
2272 | print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" |
2273 | id=\"prefFilterList\">"; | |
35f3c923 AD |
2274 | |
2275 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2276 | Select: | |
2277 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', | |
3055bc41 | 2278 | 'FILRR-', 'FICHK-', true)\">All</a>, |
35f3c923 | 2279 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', |
3055bc41 | 2280 | 'FILRR-', 'FICHK-', false)\">None</a> |
35f3c923 AD |
2281 | </td</tr>"; |
2282 | ||
3b0feb9b | 2283 | print "<tr class=\"title\"> |
e325c6e7 | 2284 | <td align='center' width=\"5%\"> </td> |
19c9cb11 AD |
2285 | <td width=\"20%\">Filter expression</td> |
2286 | <td width=\"20%\">Feed</td> | |
2287 | <td width=\"15%\">Match</td> | |
2288 | <td width=\"15%\">Action</td> | |
3b0feb9b | 2289 | <td width=\"30%\">Description</td></tr>"; |
a0d53889 | 2290 | |
3b0feb9b AD |
2291 | $lnum = 0; |
2292 | ||
2293 | while ($line = db_fetch_assoc($result)) { | |
2294 | ||
2295 | $class = ($lnum % 2) ? "even" : "odd"; | |
2296 | ||
2297 | $filter_id = $line["id"]; | |
2298 | $edit_filter_id = $_GET["id"]; | |
2299 | ||
2300 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
2301 | $class .= "Grayed"; | |
53226edc AD |
2302 | $this_row_id = ""; |
2303 | } else { | |
2304 | $this_row_id = "id=\"FILRR-$filter_id\""; | |
ead60402 | 2305 | } |
3b0feb9b | 2306 | |
53226edc | 2307 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2308 | |
2309 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); | |
2310 | $line["description"] = htmlspecialchars($line["description"]); | |
2311 | ||
2312 | if (!$line["feed_title"]) $line["feed_title"] = "All feeds"; | |
2313 | ||
2314 | if (!$edit_filter_id || $subop != "edit") { | |
2315 | ||
2316 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2317 | ||
a426e532 | 2318 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
2319 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; |
2320 | ||
2321 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2322 | $line["reg_exp"] . "</td>"; | |
2323 | ||
2324 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2325 | $line["feed_title"] . "</td>"; | |
2326 | ||
2327 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2328 | $line["filter_type_descr"] . "</td>"; | |
19c9cb11 AD |
2329 | |
2330 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2331 | $line["action_description"] . "</td>"; | |
2332 | ||
3b0feb9b AD |
2333 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . |
2334 | $line["description"] . "</td>"; | |
2335 | ||
2336 | } else if ($filter_id != $edit_filter_id) { | |
2337 | ||
2338 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2339 | ||
2340 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2341 | id=\"FICHK-".$line["id"]."\"></td>"; | |
2342 | ||
2343 | print "<td>".$line["reg_exp"]."</td>"; | |
2344 | print "<td>".$line["feed_title"]."</td>"; | |
2345 | print "<td>".$line["filter_type_descr"]."</td>"; | |
19c9cb11 | 2346 | print "<td>".$line["action_description"]."</td>"; |
3b0feb9b | 2347 | print "<td>".$line["description"]."</td>"; |
19c9cb11 | 2348 | |
3b0feb9b AD |
2349 | } else { |
2350 | ||
2351 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2352 | ||
2353 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. | |
2354 | "\"></td>"; | |
2355 | ||
2356 | print "<td>"; | |
3b0feb9b | 2357 | print "<select id=\"iedit_feed\">"; |
3b0feb9b AD |
2358 | print "<option id=\"0\">All feeds</option>"; |
2359 | ||
3b0feb9b AD |
2360 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds |
2361 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
19c9cb11 AD |
2362 | |
2363 | if (db_num_rows($tmp_result) > 0) { | |
2364 | print "<option disabled>--------</option>"; | |
2365 | } | |
2366 | ||
3b0feb9b AD |
2367 | while ($tmp_line = db_fetch_assoc($tmp_result)) { |
2368 | if ($tmp_line["id"] == $line["feed_id"]) { | |
2369 | $is_selected = "selected"; | |
2370 | } else { | |
2371 | $is_selected = ""; | |
2372 | } | |
2373 | printf("<option $is_selected id='%d'>%s</option>", | |
2374 | $tmp_line["id"], $tmp_line["title"]); | |
ead60402 | 2375 | } |
3b0feb9b AD |
2376 | |
2377 | print "</select></td>"; | |
2378 | ||
2379 | print "<td>"; | |
2380 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
2381 | print "</td>"; | |
19c9cb11 AD |
2382 | |
2383 | print "<td>"; | |
2384 | print "<select id=\"iedit_filter_action\">"; | |
2385 | ||
2386 | $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2387 | ORDER BY description"); | |
2388 | ||
2389 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2390 | if ($tmp_line["description"] == $line["action_description"]) { | |
2391 | $is_selected = "selected"; | |
2392 | } else { | |
2393 | $is_selected = ""; | |
2394 | } | |
2395 | printf("<option $is_selected id='%d'>%s</option>", | |
2396 | $tmp_line["id"], $tmp_line["description"]); | |
2397 | } | |
3b0feb9b | 2398 | |
19c9cb11 AD |
2399 | print "</select></td>"; |
2400 | ||
2401 | ||
3b0feb9b AD |
2402 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. |
2403 | "\"></td>"; | |
2404 | ||
2405 | print "</td>"; | |
ead60402 | 2406 | } |
3b0feb9b AD |
2407 | |
2408 | print "</tr>"; | |
2409 | ||
2410 | ++$lnum; | |
a0d53889 | 2411 | } |
3b0feb9b AD |
2412 | |
2413 | if ($lnum == 0) { | |
2414 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
2415 | } | |
2416 | ||
2417 | print "</table>"; | |
2418 | ||
2419 | print "<p>"; | |
2420 | ||
2421 | if ($subop == "edit") { | |
2422 | print "Edit feed: | |
2423 | <input type=\"submit\" class=\"button\" | |
2424 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
2425 | <input type=\"submit\" class=\"button\" | |
2426 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
2427 | ||
2428 | } else { | |
2429 | ||
2430 | print " | |
2431 | Selection: | |
e828e31e | 2432 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 2433 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> |
e828e31e | 2434 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2435 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; |
2436 | } | |
2437 | ||
a0d53889 AD |
2438 | } else { |
2439 | ||
3b0feb9b AD |
2440 | print "<p>No filters defined.</p>"; |
2441 | ||
a0d53889 AD |
2442 | } |
2443 | } | |
2444 | ||
80dce858 AD |
2445 | // We need to accept raw SQL data in label queries, so not everything is escaped |
2446 | // here, this is by design. If you don't like the whole idea, disable labels | |
2447 | // altogether with GLOBAL_ENABLE_LABELS = false | |
2448 | ||
48f0adb0 AD |
2449 | if ($op == "pref-labels") { |
2450 | ||
cfaba6df AD |
2451 | if (!GLOBAL_ENABLE_LABELS) { |
2452 | return; | |
2453 | } | |
2454 | ||
48f0adb0 AD |
2455 | $subop = $_GET["subop"]; |
2456 | ||
d9dde1d6 AD |
2457 | if ($subop == "test") { |
2458 | ||
2459 | $expr = $_GET["expr"]; | |
2460 | $descr = $_GET["descr"]; | |
2461 | ||
2462 | print "<div class='infoBoxContents'>"; | |
2463 | ||
2464 | print "<h1>Label «$descr»</h1>"; | |
2465 | ||
2466 | // print "<p><b>Expression</b>: $expr</p>"; | |
2467 | ||
2468 | $result = db_query($link, | |
2469 | "SELECT count(id) AS num_matches | |
2470 | FROM ttrss_entries,ttrss_user_entries | |
2471 | WHERE ($expr) AND | |
2472 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2473 | owner_uid = " . $_SESSION["uid"]); | |
2474 | ||
2475 | $num_matches = db_fetch_result($result, 0, "num_matches");; | |
2476 | ||
2477 | if ($num_matches > 0) { | |
2478 | ||
a31a7b39 | 2479 | print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>"; |
d9dde1d6 AD |
2480 | |
2481 | $result = db_query($link, | |
2482 | "SELECT title, | |
2483 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
2484 | FROM ttrss_entries,ttrss_user_entries | |
2485 | WHERE ($expr) AND | |
2486 | ttrss_user_entries.ref_id = ttrss_entries.id | |
2487 | AND owner_uid = " . $_SESSION["uid"] . " | |
2488 | ORDER BY date_entered DESC LIMIT 5"); | |
2489 | ||
2490 | print "<ul class=\"nomarks\">"; | |
2491 | while ($line = db_fetch_assoc($result)) { | |
2492 | print "<li>".$line["title"]. | |
2493 | " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>"; | |
2494 | } | |
2495 | print "</ul>"; | |
2496 | ||
2497 | } else { | |
2498 | print "<p>Query didn't return any matches.</p>"; | |
2499 | } | |
2500 | ||
2501 | print "</div>"; | |
2502 | ||
2503 | print "<div align='center'> | |
2504 | <input type='submit' class='button' | |
2505 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
2506 | return; | |
2507 | } | |
2508 | ||
48f0adb0 AD |
2509 | if ($subop == "editSave") { |
2510 | ||
2511 | $sql_exp = $_GET["s"]; | |
2512 | $descr = $_GET["d"]; | |
2513 | $label_id = db_escape_string($_GET["id"]); | |
2514 | ||
2515 | // print "$sql_exp : $descr : $label_id"; | |
2516 | ||
2517 | $result = db_query($link, "UPDATE ttrss_labels SET | |
2518 | sql_exp = '$sql_exp', | |
2519 | description = '$descr' | |
2520 | WHERE id = '$label_id'"); | |
2521 | } | |
2522 | ||
2523 | if ($subop == "remove") { | |
2524 | ||
2525 | if (!WEB_DEMO_MODE) { | |
2526 | ||
f932bc9f | 2527 | $ids = split(",", db_escape_string($_GET["ids"])); |
48f0adb0 AD |
2528 | |
2529 | foreach ($ids as $id) { | |
2530 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
2531 | ||
2532 | } | |
2533 | } | |
2534 | } | |
2535 | ||
2536 | if ($subop == "add") { | |
2537 | ||
2538 | if (!WEB_DEMO_MODE) { | |
2539 | ||
4401bf04 AD |
2540 | // no escaping is done here on purpose |
2541 | $exp = trim($_GET["exp"]); | |
48f0adb0 AD |
2542 | |
2543 | $result = db_query($link, | |
4356293a AD |
2544 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) |
2545 | VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')"); | |
48f0adb0 AD |
2546 | } |
2547 | } | |
2548 | ||
2c7070b5 AD |
2549 | print "<div class=\"prefGenericAddBox\"> |
2550 | <input size=\"40\" id=\"ladd_expr\"> "; | |
48f0adb0 | 2551 | |
2c7070b5 AD |
2552 | print"<input type=\"submit\" class=\"button\" |
2553 | onclick=\"javascript:addLabel()\" value=\"Add label\"></div>"; | |
48f0adb0 AD |
2554 | |
2555 | $result = db_query($link, "SELECT | |
2556 | id,sql_exp,description | |
2557 | FROM | |
4356293a AD |
2558 | ttrss_labels |
2559 | WHERE | |
2560 | owner_uid = ".$_SESSION["uid"]." | |
2561 | ORDER by description"); | |
48f0adb0 | 2562 | |
d9dde1d6 AD |
2563 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
2564 | ||
3b0feb9b | 2565 | if (db_num_rows($result) != 0) { |
48f0adb0 | 2566 | |
f4fe2cde AD |
2567 | print "<p><table width=\"100%\" cellspacing=\"0\" |
2568 | class=\"prefLabelList\" id=\"prefLabelList\">"; | |
35f3c923 AD |
2569 | |
2570 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2571 | Select: | |
2572 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', | |
3055bc41 | 2573 | 'LILRR-', 'LICHK-', true)\">All</a>, |
35f3c923 | 2574 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', |
3055bc41 | 2575 | 'LILRR-', 'LICHK-', false)\">None</a> |
35f3c923 AD |
2576 | </td</tr>"; |
2577 | ||
3b0feb9b | 2578 | print "<tr class=\"title\"> |
e325c6e7 AD |
2579 | <td align='center' width=\"5%\"> </td> |
2580 | <td width=\"40%\">SQL expression | |
01c9c74a | 2581 | <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a> |
3b0feb9b AD |
2582 | </td> |
2583 | <td width=\"40%\">Caption</td></tr>"; | |
2584 | ||
2585 | $lnum = 0; | |
2586 | ||
2587 | while ($line = db_fetch_assoc($result)) { | |
2588 | ||
2589 | $class = ($lnum % 2) ? "even" : "odd"; | |
2590 | ||
2591 | $label_id = $line["id"]; | |
2592 | $edit_label_id = $_GET["id"]; | |
2593 | ||
2594 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
2595 | $class .= "Grayed"; | |
53226edc AD |
2596 | $this_row_id = ""; |
2597 | } else { | |
2598 | $this_row_id = "id=\"LILRR-$label_id\""; | |
3b0feb9b AD |
2599 | } |
2600 | ||
53226edc | 2601 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2602 | |
2603 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
2604 | $line["description"] = htmlspecialchars($line["description"]); | |
2605 | ||
2606 | if (!$edit_label_id || $subop != "edit") { | |
2607 | ||
2608 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
2609 | ||
a426e532 | 2610 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
2611 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; |
2612 | ||
2613 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
2614 | $line["sql_exp"] . "</td>"; | |
48f0adb0 | 2615 | |
3b0feb9b AD |
2616 | print "<td><a href=\"javascript:editLabel($label_id);\">" . |
2617 | $line["description"] . "</td>"; | |
2618 | ||
2619 | } else if ($label_id != $edit_label_id) { | |
2620 | ||
2621 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2622 | ||
2623 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2624 | id=\"LICHK-".$line["id"]."\"></td>"; | |
2625 | ||
2626 | print "<td>".$line["sql_exp"]."</td>"; | |
2627 | print "<td>".$line["description"]."</td>"; | |
2628 | ||
2629 | } else { | |
2630 | ||
2631 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2632 | ||
2633 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
2634 | "\"></td>"; | |
2635 | ||
2636 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
2637 | "\"></td>"; | |
2638 | ||
2639 | } | |
2640 | ||
48f0adb0 | 2641 | |
3b0feb9b AD |
2642 | print "</tr>"; |
2643 | ||
2644 | ++$lnum; | |
2645 | } | |
2646 | ||
2647 | if ($lnum == 0) { | |
2648 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
2649 | } | |
2650 | ||
2651 | print "</table>"; | |
2652 | ||
2653 | print "<p>"; | |
2654 | ||
2655 | if ($subop == "edit") { | |
2656 | print "Edit label: | |
d9dde1d6 AD |
2657 | <input type=\"submit\" class=\"button\" |
2658 | onclick=\"javascript:labelTest()\" value=\"Test\"> | |
3b0feb9b AD |
2659 | <input type=\"submit\" class=\"button\" |
2660 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
2661 | <input type=\"submit\" class=\"button\" | |
2662 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
2663 | ||
2664 | } else { | |
2665 | ||
2666 | print " | |
2667 | Selection: | |
48f0adb0 | 2668 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 2669 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> |
48f0adb0 | 2670 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2671 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; |
2672 | } | |
48f0adb0 | 2673 | } else { |
3b0feb9b | 2674 | print "<p>No labels defined.</p>"; |
48f0adb0 AD |
2675 | } |
2676 | } | |
2677 | ||
e828e31e AD |
2678 | if ($op == "error") { |
2679 | print "<div width=\"100%\" align='center'>"; | |
2680 | $msg = $_GET["msg"]; | |
2681 | print $msg; | |
2682 | print "</div>"; | |
2683 | } | |
2684 | ||
7dc66a61 | 2685 | if ($op == "help") { |
01c9c74a AD |
2686 | if (!$_GET["noheaders"]) { |
2687 | print "<html><head> | |
2688 | <title>Tiny Tiny RSS : Help</title> | |
2689 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
2690 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
2691 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
2692 | </head><body>"; | |
2693 | } | |
7dc66a61 AD |
2694 | |
2695 | $tid = sprintf("%d", $_GET["tid"]); | |
2696 | ||
01c9c74a | 2697 | print "<div class='infoBoxContents'>"; |
7dc66a61 | 2698 | |
01c9c74a AD |
2699 | if (file_exists("help/$tid.php")) { |
2700 | include("help/$tid.php"); | |
2701 | } else { | |
2702 | print "<p>Help topic not found.</p>"; | |
2703 | } | |
7dc66a61 | 2704 | |
01c9c74a | 2705 | print "</div>"; |
7dc66a61 AD |
2706 | |
2707 | print "<div align='center'> | |
01c9c74a AD |
2708 | <input type='submit' class='button' |
2709 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
7dc66a61 | 2710 | |
01c9c74a AD |
2711 | if (!$_GET["noheaders"]) { |
2712 | print "</body></html>"; | |
2713 | } | |
7dc66a61 AD |
2714 | |
2715 | } | |
2716 | ||
f84a97a3 AD |
2717 | if ($op == "dlg") { |
2718 | $id = $_GET["id"]; | |
6de5d056 | 2719 | $param = $_GET["param"]; |
f84a97a3 AD |
2720 | |
2721 | if ($id == "quickAddFeed") { | |
76332f3c AD |
2722 | print " |
2723 | Feed URL: <input | |
033e47e0 | 2724 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" |
15da5cc1 AD |
2725 | id=\"qafInput\">"; |
2726 | ||
2727 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2728 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2729 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2730 | ORDER BY title"); | |
2731 | ||
2732 | print " <select id=\"qafCat\">"; | |
2733 | print "<option id=\"0\">Uncategorized</option>"; | |
2734 | ||
2735 | if (db_num_rows($result) != 0) { | |
2736 | ||
2737 | print "<option disabled>--------</option>"; | |
2738 | ||
2739 | while ($line = db_fetch_assoc($result)) { | |
2740 | printf("<option id='%d'>%s</option>", | |
2741 | $line["id"], $line["title"]); | |
2742 | } | |
2743 | } | |
2744 | ||
2745 | print "</select>"; | |
2746 | } | |
2747 | ||
2748 | print " <input class=\"button\" | |
f84a97a3 AD |
2749 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> |
2750 | <input class=\"button\" | |
2751 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2752 | value=\"Cancel\">"; | |
2753 | } | |
6de5d056 AD |
2754 | |
2755 | if ($id == "quickDelFeed") { | |
2756 | ||
2757 | $param = db_escape_string($param); | |
2758 | ||
2759 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
2760 | ||
2761 | if ($result) { | |
2762 | ||
2763 | $f_title = db_fetch_result($result, 0, "title"); | |
2764 | ||
76332f3c | 2765 | print "Remove current feed (<b>$f_title</b>)? |
6de5d056 AD |
2766 | <input class=\"button\" |
2767 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
2768 | <input class=\"button\" | |
2769 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2770 | value=\"Cancel\">"; | |
2771 | } else { | |
2772 | print "Error: Feed $param not found. | |
2773 | <input class=\"button\" | |
2774 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2775 | value=\"Cancel\">"; | |
2776 | } | |
2777 | } | |
2778 | ||
033e47e0 AD |
2779 | if ($id == "search") { |
2780 | ||
2781 | print "<input id=\"searchbox\" class=\"extSearch\" | |
2782 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
2783 | onchange=\"javascript:search()\"> | |
2784 | <select id=\"searchmodebox\"> | |
2785 | <option selected>All feeds</option> | |
2786 | <option>This feed</option> | |
2787 | </select> | |
2788 | <input type=\"submit\" | |
2789 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
2790 | <input class=\"button\" | |
2791 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2792 | value=\"Close\">"; | |
2793 | ||
2794 | } | |
2795 | ||
a24f525c AD |
2796 | if ($id == "quickAddFilter") { |
2797 | ||
2798 | $result = db_query($link, "SELECT description | |
2799 | FROM ttrss_filter_types ORDER BY description"); | |
2800 | ||
2801 | $filter_types = array(); | |
2802 | ||
2803 | while ($line = db_fetch_assoc($result)) { | |
2804 | array_push($filter_types, $line["description"]); | |
2805 | } | |
2806 | ||
2807 | print "<table>"; | |
2808 | ||
2809 | print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> "; | |
2810 | ||
2811 | print_select("fadd_match", "Title", $filter_types); | |
2812 | ||
2813 | print "</td></tr>"; | |
2814 | print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">"; | |
2815 | ||
2816 | print "<option selected id=\"0\">All feeds</option>"; | |
2817 | ||
2818 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2819 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2820 | ||
2821 | if (db_num_rows($result) > 0) { | |
2822 | print "<option disabled>--------</option>"; | |
2823 | } | |
2824 | ||
2825 | while ($line = db_fetch_assoc($result)) { | |
2826 | if ($param == $line["id"]) { | |
2827 | $selected = "selected"; | |
2828 | } else { | |
2829 | $selected = ""; | |
2830 | } | |
2831 | printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]); | |
2832 | } | |
2833 | ||
2834 | print "</select></td></tr>"; | |
2835 | ||
2836 | print "<tr><td>Action:</td>"; | |
2837 | ||
2838 | print "<td><select id=\"fadd_action\">"; | |
2839 | ||
2840 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2841 | ORDER BY name"); | |
2842 | ||
2843 | while ($line = db_fetch_assoc($result)) { | |
2844 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
2845 | } | |
2846 | ||
2847 | print "</select>"; | |
2848 | ||
2849 | print "</td></tr><tr><td colspan=\"2\" align=\"right\">"; | |
2850 | ||
2851 | print "<input type=\"submit\" | |
2852 | class=\"button\" onclick=\"javascript:qaddFilter()\" | |
2853 | value=\"Add filter\"> "; | |
2854 | ||
2855 | print "<input class=\"button\" | |
2856 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2857 | value=\"Close\">"; | |
2858 | ||
2859 | print "</td></tr></table>"; | |
2860 | } | |
f84a97a3 AD |
2861 | } |
2862 | ||
a2770077 AD |
2863 | // update feeds of all users, may be used anonymously |
2864 | if ($op == "globalUpdateFeeds") { | |
2865 | ||
2866 | $result = db_query($link, "SELECT id FROM ttrss_users"); | |
2867 | ||
2868 | while ($line = db_fetch_assoc($result)) { | |
2869 | $user_id = $line["id"]; | |
2870 | // print "<!-- updating feeds of uid $user_id -->"; | |
2871 | update_all_feeds($link, false, $user_id); | |
2872 | } | |
e65af9c1 | 2873 | |
a2770077 AD |
2874 | print "<rpc-reply> |
2875 | <message msg=\"All feeds updated\"/> | |
2876 | </rpc-reply>"; | |
e65af9c1 AD |
2877 | |
2878 | } | |
2879 | ||
77e96719 AD |
2880 | if ($op == "pref-prefs") { |
2881 | ||
b1895692 | 2882 | $subop = $_REQUEST["subop"]; |
77e96719 AD |
2883 | |
2884 | if ($subop == "Save configuration") { | |
2885 | ||
d2892032 AD |
2886 | if (WEB_DEMO_MODE) { |
2887 | header("Location: prefs.php"); | |
2888 | return; | |
2889 | } | |
01d68cf9 | 2890 | |
93cb4442 AD |
2891 | $_SESSION["prefs_op_result"] = "save-config"; |
2892 | ||
77e96719 AD |
2893 | foreach (array_keys($_POST) as $pref_name) { |
2894 | ||
2895 | $pref_name = db_escape_string($pref_name); | |
2896 | $value = db_escape_string($_POST[$pref_name]); | |
2897 | ||
2898 | $result = db_query($link, "SELECT type_name | |
2899 | FROM ttrss_prefs,ttrss_prefs_types | |
2900 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
2901 | ||
2902 | if (db_num_rows($result) > 0) { | |
2903 | ||
2904 | $type_name = db_fetch_result($result, 0, "type_name"); | |
2905 | ||
5da169d9 AD |
2906 | // print "$pref_name : $type_name : $value<br>"; |
2907 | ||
77e96719 | 2908 | if ($type_name == "bool") { |
5da169d9 | 2909 | if ($value == "1") { |
77e96719 AD |
2910 | $value = "true"; |
2911 | } else { | |
2912 | $value = "false"; | |
2913 | } | |
2914 | } else if ($type_name == "integer") { | |
2915 | $value = sprintf("%d", $value); | |
2916 | } | |
2917 | ||
2918 | // print "$pref_name : $type_name : $value<br>"; | |
2919 | ||
ff485f1d AD |
2920 | db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' |
2921 | WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); | |
77e96719 AD |
2922 | |
2923 | } | |
2924 | ||
2925 | header("Location: prefs.php"); | |
2926 | ||
2927 | } | |
2928 | ||
b1895692 AD |
2929 | } else if ($subop == "getHelp") { |
2930 | ||
2931 | $pref_name = db_escape_string($_GET["pn"]); | |
2932 | ||
2933 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
2934 | WHERE pref_name = '$pref_name'"); | |
2935 | ||
2936 | if (db_num_rows($result) > 0) { | |
2937 | $help_text = db_fetch_result($result, 0, "help_text"); | |
2938 | print $help_text; | |
2939 | } else { | |
2940 | print "Unknown option: $pref_name"; | |
2941 | } | |
2942 | ||
1c7f75ed AD |
2943 | } else if ($subop == "Change password") { |
2944 | ||
d2892032 AD |
2945 | if (WEB_DEMO_MODE) { |
2946 | header("Location: prefs.php"); | |
2947 | return; | |
2948 | } | |
1c7f75ed AD |
2949 | |
2950 | $old_pw = $_POST["OLD_PASSWORD"]; | |
2951 | $new_pw = $_POST["OLD_PASSWORD"]; | |
2952 | ||
2953 | $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]); | |
2954 | $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]); | |
2955 | ||
2956 | $active_uid = $_SESSION["uid"]; | |
2957 | ||
2958 | if ($old_pw && $new_pw) { | |
2959 | ||
2960 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
2961 | ||
2962 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
2963 | id = '$active_uid' AND (pwd_hash = '$old_pw' OR | |
2964 | pwd_hash = '$old_pw_hash')"); | |
2965 | ||
2966 | if (db_num_rows($result) == 1) { | |
2967 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
2968 | WHERE id = '$active_uid'"); | |
b791095d AD |
2969 | |
2970 | $_SESSION["pwd_change_result"] = "ok"; | |
2971 | } else { | |
2972 | $_SESSION["pwd_change_result"] = "failed"; | |
1c7f75ed AD |
2973 | } |
2974 | } | |
2975 | ||
2976 | header("Location: prefs.php"); | |
b791095d | 2977 | |
77e96719 AD |
2978 | } else if ($subop == "Reset to defaults") { |
2979 | ||
d2892032 AD |
2980 | if (WEB_DEMO_MODE) { |
2981 | header("Location: prefs.php"); | |
2982 | return; | |
2983 | } | |
01d68cf9 | 2984 | |
93cb4442 AD |
2985 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
2986 | ||
e1aa0559 AD |
2987 | if (DB_TYPE == "pgsql") { |
2988 | db_query($link,"UPDATE ttrss_user_prefs | |
2989 | SET value = ttrss_prefs.def_value | |
2990 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
2991 | ttrss_prefs.pref_name = ttrss_user_prefs.pref_name"); | |
2992 | } else { | |
2993 | db_query($link, "DELETE FROM ttrss_user_prefs | |
2994 | WHERE owner_uid = ".$_SESSION["uid"]); | |
2995 | initialize_user_prefs($link, $_SESSION["uid"]); | |
2996 | } | |
5da169d9 | 2997 | |
77e96719 AD |
2998 | header("Location: prefs.php"); |
2999 | ||
58f8ad54 AD |
3000 | } else if ($subop == "Change theme") { |
3001 | ||
3002 | $theme = db_escape_string($_POST["theme"]); | |
3003 | ||
3004 | if ($theme == "Default") { | |
3005 | $theme_qpart = 'NULL'; | |
3006 | } else { | |
3007 | $theme_qpart = "'$theme'"; | |
3008 | } | |
3009 | ||
6752e330 AD |
3010 | $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes |
3011 | WHERE theme_name = '$theme'"); | |
3012 | ||
3013 | if (db_num_rows($result) == 1) { | |
3014 | $theme_id = db_fetch_result($result, 0, "id"); | |
3015 | $theme_path = db_fetch_result($result, 0, "theme_path"); | |
3016 | } else { | |
3017 | $theme_id = "NULL"; | |
3018 | $theme_path = ""; | |
3019 | } | |
3020 | ||
58f8ad54 | 3021 | db_query($link, "UPDATE ttrss_users SET |
6752e330 | 3022 | theme_id = $theme_id WHERE id = " . $_SESSION["uid"]); |
58f8ad54 | 3023 | |
6752e330 | 3024 | $_SESSION["theme"] = $theme_path; |
503eb349 | 3025 | |
58f8ad54 AD |
3026 | header("Location: prefs.php"); |
3027 | ||
77e96719 AD |
3028 | } else { |
3029 | ||
7d4c898a | 3030 | if (!SINGLE_USER_MODE) { |
1c7f75ed | 3031 | |
a029d530 AD |
3032 | $result = db_query($link, "SELECT id FROM ttrss_users |
3033 | WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR | |
3034 | pwd_hash = 'SHA1:".sha1("password")."')"); | |
3035 | ||
3036 | if (db_num_rows($result) != 0) { | |
b791095d | 3037 | print "<div class=\"warning\"> |
a029d530 AD |
3038 | Your password is at default value, please change it. |
3039 | </div>"; | |
3040 | } | |
3041 | ||
b791095d AD |
3042 | if ($_SESSION["pwd_change_result"] == "failed") { |
3043 | print "<div class=\"warning\"> | |
3044 | There was an error while changing your password. | |
3045 | </div>"; | |
3046 | } | |
3047 | ||
3048 | if ($_SESSION["pwd_change_result"] == "ok") { | |
3049 | print "<div class=\"notice\"> | |
3050 | Password changed successfully. | |
3051 | </div>"; | |
3052 | } | |
3053 | ||
3054 | $_SESSION["pwd_change_result"] = ""; | |
3055 | ||
93cb4442 AD |
3056 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { |
3057 | print "<div class=\"notice\"> | |
3058 | Your configuration was reset to defaults. | |
3059 | </div>"; | |
3060 | } | |
3061 | ||
3062 | if ($_SESSION["prefs_op_result"] == "save-config") { | |
3063 | print "<div class=\"notice\"> | |
3064 | Your configuration was saved successfully. | |
3065 | </div>"; | |
3066 | } | |
3067 | ||
3068 | $_SESSION["prefs_op_result"] = ""; | |
3069 | ||
7d4c898a AD |
3070 | print "<form action=\"backend.php\" method=\"POST\">"; |
3071 | ||
3072 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3073 | print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>"; | |
3074 | ||
3075 | print "<tr><td width=\"40%\">Old password</td>"; | |
3076 | print "<td><input class=\"editbox\" type=\"password\" | |
3077 | name=\"OLD_PASSWORD\"></td></tr>"; | |
3078 | ||
3079 | print "<tr><td width=\"40%\">New password</td>"; | |
3080 | ||
3081 | print "<td><input class=\"editbox\" type=\"password\" | |
3082 | name=\"NEW_PASSWORD\"></td></tr>"; | |
3083 | ||
3084 | print "</table>"; | |
3085 | ||
3086 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3087 | ||
3088 | print "<p><input class=\"button\" type=\"submit\" | |
3089 | value=\"Change password\" name=\"subop\">"; | |
3090 | ||
3091 | print "</form>"; | |
1c7f75ed | 3092 | |
7d4c898a | 3093 | } |
1c7f75ed | 3094 | |
58f8ad54 AD |
3095 | $result = db_query($link, "SELECT |
3096 | theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]); | |
3097 | ||
3098 | $user_theme_id = db_fetch_result($result, 0, "theme_id"); | |
3099 | ||
3100 | $result = db_query($link, "SELECT | |
3101 | id,theme_name FROM ttrss_themes ORDER BY theme_name"); | |
3102 | ||
3103 | if (db_num_rows($result) > 0) { | |
6752e330 AD |
3104 | |
3105 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3106 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3107 | print "<tr><td colspan='3'><h3>Themes</h3></tr></td>"; | |
3108 | print "<tr><td width=\"40%\">Select theme</td>"; | |
3109 | print "<td><select name=\"theme\">"; | |
3110 | print "<option>Default</option>"; | |
58f8ad54 | 3111 | print "<option disabled>--------</option>"; |
6752e330 | 3112 | |
58f8ad54 AD |
3113 | while ($line = db_fetch_assoc($result)) { |
3114 | if ($line["id"] == $user_theme_id) { | |
3115 | $selected = "selected"; | |
3116 | } else { | |
3117 | $selected = ""; | |
3118 | } | |
3119 | print "<option $selected>" . $line["theme_name"] . "</option>"; | |
3120 | } | |
6752e330 AD |
3121 | print "</select></td></tr>"; |
3122 | print "</table>"; | |
3123 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3124 | print "<p><input class=\"button\" type=\"submit\" | |
3125 | value=\"Change theme\" name=\"subop\">"; | |
3126 | print "</form>"; | |
58f8ad54 AD |
3127 | } |
3128 | ||
77e96719 | 3129 | $result = db_query($link, "SELECT |
ff485f1d | 3130 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, |
77e96719 | 3131 | section_name,def_value |
ff485f1d | 3132 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
77e96719 | 3133 | WHERE type_id = ttrss_prefs_types.id AND |
ff485f1d | 3134 | section_id = ttrss_prefs_sections.id AND |
a2411bd9 AD |
3135 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
3136 | owner_uid = ".$_SESSION["uid"]." | |
650bc435 | 3137 | ORDER BY section_id,short_desc"); |
77e96719 AD |
3138 | |
3139 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3140 | ||
77e96719 AD |
3141 | $lnum = 0; |
3142 | ||
3143 | $active_section = ""; | |
3144 | ||
3145 | while ($line = db_fetch_assoc($result)) { | |
3146 | ||
3147 | if ($active_section != $line["section_name"]) { | |
59a654ba AD |
3148 | |
3149 | if ($active_section != "") { | |
1c7f75ed | 3150 | print "</table>"; |
59a654ba | 3151 | } |
1c7f75ed AD |
3152 | |
3153 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
59a654ba AD |
3154 | |
3155 | $active_section = $line["section_name"]; | |
3156 | ||
77e96719 | 3157 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; |
59a654ba AD |
3158 | // print "<tr class=\"title\"> |
3159 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
7268adf7 AD |
3160 | |
3161 | $lnum = 0; | |
77e96719 AD |
3162 | } |
3163 | ||
650bc435 | 3164 | // $class = ($lnum % 2) ? "even" : "odd"; |
77e96719 | 3165 | |
650bc435 | 3166 | print "<tr>"; |
77e96719 | 3167 | |
77e96719 AD |
3168 | $type_name = $line["type_name"]; |
3169 | $pref_name = $line["pref_name"]; | |
3170 | $value = $line["value"]; | |
3171 | $def_value = $line["def_value"]; | |
b1895692 AD |
3172 | $help_text = $line["help_text"]; |
3173 | ||
3174 | print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"]; | |
3175 | ||
3176 | if ($help_text) print "<div class=\"prefHelp\">$help_text</div>"; | |
3177 | ||
3178 | print "</td>"; | |
77e96719 AD |
3179 | |
3180 | print "<td>"; | |
3181 | ||
3182 | if ($type_name == "bool") { | |
3183 | // print_select($pref_name, $value, array("true", "false")); | |
3184 | ||
3185 | if ($value == "true") { | |
3186 | $value = "Yes"; | |
3187 | } else { | |
3188 | $value = "No"; | |
3189 | } | |
3190 | ||
3191 | print_radio($pref_name, $value, array("Yes", "No")); | |
3192 | ||
3193 | } else { | |
3194 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
3195 | } | |
3196 | ||
3197 | print "</td>"; | |
3198 | ||
3199 | print "</tr>"; | |
3200 | ||
3201 | $lnum++; | |
3202 | } | |
3203 | ||
3204 | print "</table>"; | |
3205 | ||
3206 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3207 | ||
3208 | print "<p><input class=\"button\" type=\"submit\" | |
3209 | name=\"subop\" value=\"Save configuration\">"; | |
3210 | ||
3211 | print " <input class=\"button\" type=\"submit\" | |
69668465 AD |
3212 | name=\"subop\" onclick=\"return validatePrefsReset()\" |
3213 | value=\"Reset to defaults\"></p>"; | |
77e96719 AD |
3214 | |
3215 | print "</form>"; | |
3216 | ||
3217 | } | |
3218 | ||
3219 | } | |
3220 | ||
e6cb77a0 AD |
3221 | if ($op == "pref-users") { |
3222 | ||
3223 | $subop = $_GET["subop"]; | |
3224 | ||
3225 | if ($subop == "editSave") { | |
3226 | ||
3227 | if (!WEB_DEMO_MODE) { | |
3228 | ||
3229 | $login = db_escape_string($_GET["l"]); | |
3230 | $uid = db_escape_string($_GET["id"]); | |
3231 | $access_level = sprintf("%d", $_GET["al"]); | |
72932a75 | 3232 | $email = db_escape_string($_GET["e"]); |
e6cb77a0 | 3233 | |
72932a75 AD |
3234 | db_query($link, "UPDATE ttrss_users SET login = '$login', |
3235 | access_level = '$access_level', email = '$email' WHERE id = '$uid'"); | |
e6cb77a0 AD |
3236 | |
3237 | } | |
3238 | } else if ($subop == "remove") { | |
3239 | ||
3240 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3241 | ||
f932bc9f | 3242 | $ids = split(",", db_escape_string($_GET["ids"])); |
e6cb77a0 AD |
3243 | |
3244 | foreach ($ids as $id) { | |
3245 | db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]); | |
3246 | ||
3247 | } | |
3248 | } | |
3249 | } else if ($subop == "add") { | |
3250 | ||
3251 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3252 | ||
b6b535ca | 3253 | $login = db_escape_string(trim($_GET["login"])); |
e6cb77a0 AD |
3254 | $tmp_user_pwd = make_password(8); |
3255 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3256 | ||
3257 | db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level) | |
3258 | VALUES ('$login', '$pwd_hash', 0)"); | |
3259 | ||
3260 | ||
3261 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
3262 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
3263 | ||
3264 | if (db_num_rows($result) == 1) { | |
3265 | ||
3266 | $new_uid = db_fetch_result($result, 0, "id"); | |
3267 | ||
3268 | print "<div class=\"notice\">Added user <b>".$_GET["login"]. | |
3269 | "</b> with password <b>$tmp_user_pwd</b>.</div>"; | |
3270 | ||
3271 | initialize_user($link, $new_uid); | |
3272 | ||
3273 | } else { | |
3274 | ||
3275 | print "<div class=\"warning\">Error while adding user <b>". | |
3276 | $_GET["login"].".</b></div>"; | |
3277 | ||
3278 | } | |
3279 | } | |
3280 | } else if ($subop == "resetPass") { | |
3281 | ||
3282 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3283 | ||
3284 | $uid = db_escape_string($_GET["id"]); | |
3285 | ||
72932a75 AD |
3286 | $result = db_query($link, "SELECT login,email |
3287 | FROM ttrss_users WHERE id = '$uid'"); | |
e6cb77a0 AD |
3288 | |
3289 | $login = db_fetch_result($result, 0, "login"); | |
72932a75 | 3290 | $email = db_fetch_result($result, 0, "email"); |
e6cb77a0 AD |
3291 | $tmp_user_pwd = make_password(8); |
3292 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3293 | ||
3294 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
3295 | WHERE id = '$uid'"); | |
3296 | ||
3297 | print "<div class=\"notice\">Changed password of | |
72932a75 AD |
3298 | user <b>$login</b> to <b>$tmp_user_pwd</b>."; |
3299 | ||
3300 | if (MAIL_RESET_PASS && $email) { | |
3301 | print " Notifying <b>$email</b>."; | |
3302 | ||
3303 | mail("$login <$email>", "Password reset notification", | |
3304 | "Hi, $login.\n". | |
3305 | "\n". | |
3306 | "Your password for this TT-RSS installation was reset by". | |
3307 | " an administrator.\n". | |
3308 | "\n". | |
3309 | "Your new password is $tmp_user_pwd, please remember". | |
3310 | " it for later reference.\n". | |
3311 | "\n". | |
3312 | "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM); | |
3313 | } | |
3314 | ||
3315 | print "</div>"; | |
e6cb77a0 AD |
3316 | |
3317 | } | |
3318 | } | |
3319 | ||
2c7070b5 | 3320 | print "<div class=\"prefGenericAddBox\"> |
f932bc9f | 3321 | <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> "; |
e6cb77a0 | 3322 | |
2c7070b5 AD |
3323 | print"<input type=\"submit\" class=\"button\" |
3324 | onclick=\"javascript:addUser()\" value=\"Add user\"></div>"; | |
e6cb77a0 AD |
3325 | |
3326 | $result = db_query($link, "SELECT | |
72932a75 | 3327 | id,login,access_level,email, |
fe99ab12 | 3328 | SUBSTRING(last_login,1,16) as last_login |
e6cb77a0 AD |
3329 | FROM |
3330 | ttrss_users | |
3331 | ORDER by login"); | |
3332 | ||
2317ffaa | 3333 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
1a7572cb | 3334 | |
f4fe2cde AD |
3335 | print "<p><table width=\"100%\" cellspacing=\"0\" |
3336 | class=\"prefUserList\" id=\"prefUserList\">"; | |
e6cb77a0 | 3337 | |
35f3c923 AD |
3338 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> |
3339 | Select: | |
3340 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', | |
3055bc41 | 3341 | 'UMRR-', 'UMCHK-', true)\">All</a>, |
35f3c923 | 3342 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', |
3055bc41 | 3343 | 'UMRR-', 'UMCHK-', false)\">None</a> |
35f3c923 AD |
3344 | </td</tr>"; |
3345 | ||
e6cb77a0 | 3346 | print "<tr class=\"title\"> |
e325c6e7 | 3347 | <td align='center' width=\"5%\"> </td> |
72932a75 AD |
3348 | <td width='20%'>Username</td> |
3349 | <td width='20%'>E-mail</td> | |
3350 | <td width='20%'>Access Level</td> | |
3351 | <td width='20%'>Last login</td></tr>"; | |
e6cb77a0 AD |
3352 | |
3353 | $lnum = 0; | |
3354 | ||
3355 | while ($line = db_fetch_assoc($result)) { | |
3356 | ||
3357 | $class = ($lnum % 2) ? "even" : "odd"; | |
3358 | ||
3359 | $uid = $line["id"]; | |
3360 | $edit_uid = $_GET["id"]; | |
3361 | ||
3362 | if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) { | |
3363 | $class .= "Grayed"; | |
53226edc AD |
3364 | $this_row_id = ""; |
3365 | } else { | |
3366 | $this_row_id = "id=\"UMRR-$uid\""; | |
3367 | } | |
3368 | ||
3369 | print "<tr class=\"$class\" $this_row_id>"; | |
e6cb77a0 AD |
3370 | |
3371 | $line["login"] = htmlspecialchars($line["login"]); | |
3372 | ||
6be6bc03 AD |
3373 | $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'), |
3374 | strtotime($line["last_login"])); | |
3375 | ||
72932a75 | 3376 | /* if ($uid == $_SESSION["uid"]) { |
e6cb77a0 | 3377 | |
a426e532 | 3378 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" |
e6cb77a0 AD |
3379 | id=\"UMCHK-".$line["id"]."\"></td>"; |
3380 | ||
72932a75 AD |
3381 | print "<td>".$line["login"]."</td>"; |
3382 | print "<td>".$line["email"]."</td>"; | |
3383 | print "<td>".$line["access_level"]."</td>"; | |
e6cb77a0 | 3384 | |
72932a75 | 3385 | } else */ if (!$edit_uid || $subop != "edit") { |
e6cb77a0 | 3386 | |
a426e532 | 3387 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
1a7572cb | 3388 | type=\"checkbox\" id=\"UMCHK-$uid\"></td>"; |
e6cb77a0 AD |
3389 | |
3390 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
3391 | $line["login"] . "</td>"; | |
72932a75 AD |
3392 | |
3393 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
3394 | $line["email"] . "</td>"; | |
3395 | ||
e6cb77a0 AD |
3396 | print "<td><a href=\"javascript:editUser($uid);\">" . |
3397 | $line["access_level"] . "</td>"; | |
3398 | ||
3399 | } else if ($uid != $edit_uid) { | |
3400 | ||
72932a75 | 3401 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" |
e6cb77a0 AD |
3402 | id=\"UMCHK-".$line["id"]."\"></td>"; |
3403 | ||
3404 | print "<td>".$line["login"]."</td>"; | |
72932a75 | 3405 | print "<td>".$line["email"]."</td>"; |
e6cb77a0 AD |
3406 | print "<td>".$line["access_level"]."</td>"; |
3407 | ||
3408 | } else { | |
3409 | ||
72932a75 AD |
3410 | print "<td align='center'> |
3411 | <input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
e6cb77a0 AD |
3412 | |
3413 | print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"]. | |
3414 | "\"></td>"; | |
3415 | ||
72932a75 AD |
3416 | print "<td><input id=\"iedit_email\" value=\"".$line["email"]. |
3417 | "\"></td>"; | |
3418 | ||
e6cb77a0 AD |
3419 | print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"]. |
3420 | "\"></td>"; | |
3421 | ||
3422 | } | |
3423 | ||
f6f32198 AD |
3424 | print "<td>".$line["last_login"]."</td>"; |
3425 | ||
e6cb77a0 AD |
3426 | print "</tr>"; |
3427 | ||
3428 | ++$lnum; | |
3429 | } | |
3430 | ||
3431 | print "</table>"; | |
3432 | ||
3433 | print "<p>"; | |
3434 | ||
3435 | if ($subop == "edit") { | |
3436 | print "Edit label: | |
3437 | <input type=\"submit\" class=\"button\" | |
3438 | onclick=\"javascript:userEditCancel()\" value=\"Cancel\"> | |
3439 | <input type=\"submit\" class=\"button\" | |
3440 | onclick=\"javascript:userEditSave()\" value=\"Save\">"; | |
3441 | ||
3442 | } else { | |
3443 | ||
3444 | print " | |
3445 | Selection: | |
3446 | <input type=\"submit\" class=\"button\" | |
717f5e64 | 3447 | onclick=\"javascript:selectedUserDetails()\" value=\"User details\"> |
e6cb77a0 AD |
3448 | <input type=\"submit\" class=\"button\" |
3449 | onclick=\"javascript:editSelectedUser()\" value=\"Edit\"> | |
3450 | <input type=\"submit\" class=\"button\" | |
717f5e64 AD |
3451 | onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\"> |
3452 | <input type=\"submit\" class=\"button\" | |
3453 | onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">"; | |
3454 | ||
3455 | } | |
3456 | } | |
3457 | ||
3458 | if ($op == "user-details") { | |
3459 | ||
3460 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { | |
3461 | return; | |
3462 | } | |
3463 | ||
1a7572cb | 3464 | /* print "<html><head> |
717f5e64 AD |
3465 | <title>Tiny Tiny RSS : User Details</title> |
3466 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
3467 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
1a7572cb | 3468 | </head><body>"; */ |
717f5e64 AD |
3469 | |
3470 | $uid = sprintf("%d", $_GET["id"]); | |
3471 | ||
c6c3a07f | 3472 | print "<div class='infoBoxContents'>"; |
717f5e64 | 3473 | |
fe99ab12 AD |
3474 | $result = db_query($link, "SELECT login, |
3475 | SUBSTRING(last_login,1,16) AS last_login, | |
3476 | access_level, | |
c6c3a07f AD |
3477 | (SELECT COUNT(int_id) FROM ttrss_user_entries |
3478 | WHERE owner_uid = id) AS stored_articles | |
717f5e64 AD |
3479 | FROM ttrss_users |
3480 | WHERE id = '$uid'"); | |
3481 | ||
3482 | if (db_num_rows($result) == 0) { | |
3483 | print "<h1>User not found</h1>"; | |
3484 | return; | |
3485 | } | |
3486 | ||
3487 | print "<h1>User Details</h1>"; | |
3488 | ||
3489 | print "<table width='100%'>"; | |
3490 | ||
3491 | $login = db_fetch_result($result, 0, "login"); | |
6be6bc03 AD |
3492 | $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'), |
3493 | strtotime(db_fetch_result($result, 0, "last_login"))); | |
717f5e64 | 3494 | $access_level = db_fetch_result($result, 0, "access_level"); |
c6c3a07f | 3495 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); |
717f5e64 AD |
3496 | |
3497 | print "<tr><td>Username</td><td>$login</td></tr>"; | |
3498 | print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
3499 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
c6c3a07f | 3500 | print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>"; |
717f5e64 AD |
3501 | |
3502 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
3503 | WHERE owner_uid = '$uid'"); | |
3504 | ||
3505 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
3506 | ||
3507 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; | |
3508 | ||
5d15d3ea | 3509 | /* $result = db_query($link, "SELECT |
717f5e64 | 3510 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size |
c6c3a07f AD |
3511 | FROM ttrss_user_entries,ttrss_entries |
3512 | WHERE owner_uid = '$uid' AND ref_id = id"); | |
717f5e64 | 3513 | |
d9f115c3 | 3514 | $db_size = round(db_fetch_result($result, 0, "db_size") / 1024); |
717f5e64 | 3515 | |
c6c3a07f | 3516 | print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */ |
717f5e64 AD |
3517 | |
3518 | print "</table>"; | |
3519 | ||
3520 | print "<h1>Subscribed feeds</h1>"; | |
3521 | ||
e94645ca | 3522 | $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds |
a88c1f36 | 3523 | WHERE owner_uid = '$uid' ORDER BY title LIMIT 20"); |
717f5e64 AD |
3524 | |
3525 | print "<ul class=\"nomarks\">"; | |
3526 | ||
3527 | while ($line = db_fetch_assoc($result)) { | |
3528 | ||
3529 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
3530 | ||
3531 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
6c56687e | 3532 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; |
717f5e64 | 3533 | } else { |
5951ded1 | 3534 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; |
717f5e64 AD |
3535 | } |
3536 | ||
e94645ca | 3537 | print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; |
e6cb77a0 | 3538 | } |
717f5e64 | 3539 | |
a88c1f36 AD |
3540 | if (db_num_rows($result) < $num_feeds) { |
3541 | // FIXME - add link to show ALL subscribed feeds here somewhere | |
3542 | print "<li><img | |
3543 | class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>"; | |
3544 | } | |
3545 | ||
717f5e64 AD |
3546 | print "</ul>"; |
3547 | ||
717f5e64 AD |
3548 | print "</div>"; |
3549 | ||
1a7572cb AD |
3550 | print "<div align='center'> |
3551 | <input type='submit' class='button' | |
c6c3a07f | 3552 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; |
1a7572cb AD |
3553 | |
3554 | // print "</body></html>"; | |
717f5e64 | 3555 | |
e6cb77a0 AD |
3556 | } |
3557 | ||
c6c3a07f AD |
3558 | if ($op == "feed-details") { |
3559 | ||
df268d47 | 3560 | // $feed_id = $_GET["id"]; |
4fec9fd7 | 3561 | |
df268d47 | 3562 | $feed_ids = split(",", db_escape_string($_GET["id"])); |
c6c3a07f | 3563 | |
df268d47 | 3564 | print "<div class=\"infoBoxContents\">"; |
bca02305 | 3565 | |
df268d47 | 3566 | foreach ($feed_ids as $feed_id) { |
c6c3a07f | 3567 | |
df268d47 AD |
3568 | $result = db_query($link, |
3569 | "SELECT | |
3570 | title,feed_url, | |
3571 | SUBSTRING(last_updated,1,16) as last_updated, | |
3572 | icon_url,site_url, | |
3573 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3574 | WHERE feed_id = id) AS total, | |
3575 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3576 | WHERE feed_id = id AND unread = true) AS unread, | |
3577 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3578 | WHERE feed_id = id AND marked = true) AS marked | |
3579 | FROM ttrss_feeds | |
3580 | WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]); | |
3581 | ||
3582 | if (db_num_rows($result) == 0) return; | |
3583 | ||
3584 | $title = db_unescape_string(db_fetch_result($result, 0, "title")); | |
3585 | $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
3586 | strtotime(db_fetch_result($result, 0, "last_updated"))); | |
3587 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
3588 | $icon_url = db_fetch_result($result, 0, "icon_url"); | |
3589 | $total = db_fetch_result($result, 0, "total"); | |
3590 | $unread = db_fetch_result($result, 0, "unread"); | |
3591 | $marked = db_fetch_result($result, 0, "marked"); | |
3592 | $site_url = db_fetch_result($result, 0, "site_url"); | |
bca02305 | 3593 | |
df268d47 AD |
3594 | $result = db_query($link, "SELECT COUNT(id) AS subscribed |
3595 | FROM ttrss_feeds WHERE feed_url = '$feed_url'"); | |
3596 | ||
3597 | $subscribed = db_fetch_result($result, 0, "subscribed"); | |
3598 | ||
3599 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
3600 | ||
3601 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
3602 | $feed_icon = "<img width=\"16\" height=\"16\" | |
3603 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
3604 | } else { | |
3605 | $feed_icon = ""; | |
bca02305 AD |
3606 | } |
3607 | ||
df268d47 | 3608 | print "<h1>$feed_icon $title</h1>"; |
bca02305 | 3609 | |
df268d47 | 3610 | print "<table width='100%'>"; |
bca02305 | 3611 | |
df268d47 AD |
3612 | if ($site_url) { |
3613 | print "<tr><td width='30%'>Link</td> | |
3614 | <td><a href=\"$site_url\">$site_url</a> | |
3615 | <a href=\"$feed_url\">(feed)</a></td> | |
3616 | </td></tr>"; | |
3617 | } else { | |
3618 | print "<tr><td width='30%'>Feed URL</td> | |
3619 | <td><a href=\"$feed_url\">$feed_url</a></td></tr>"; | |
3620 | } | |
3621 | print "<tr><td>Last updated</td><td>$last_updated</td></tr>"; | |
3622 | print "<tr><td>Total articles</td><td>$total</td></tr>"; | |
3623 | print "<tr><td>Unread articles</td><td>$unread</td></tr>"; | |
3624 | print "<tr><td>Starred articles</td><td>$marked</td></tr>"; | |
3625 | print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>"; | |
3626 | ||
3627 | print "</table>"; | |
3628 | ||
3629 | /* $result = db_query($link, "SELECT title, | |
3630 | SUBSTRING(updated,1,16) AS updated,unread | |
3631 | FROM ttrss_entries,ttrss_user_entries | |
3632 | WHERE ref_id = id AND feed_id = '$feed_id' | |
3633 | ORDER BY date_entered DESC LIMIT 5"); | |
3634 | ||
3635 | if (db_num_rows($result) > 0) { | |
3636 | ||
3637 | print "<h1>Latest headlines</h1>"; | |
3638 | ||
3639 | print "<ul class=\"nomarks\">"; | |
3640 | ||
3641 | while ($line = db_fetch_assoc($result)) { | |
3642 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
3643 | $line["title"] = "<b>" . $line["title"] . "</b>"; | |
3644 | } | |
3645 | print "<li>" . $line["title"]. | |
3646 | " <span class=\"insensitive\">(" . | |
3647 | date(get_pref($link, 'SHORT_DATE_FORMAT'), | |
3648 | strtotime($line["updated"])). | |
3649 | ")</span></li>"; | |
3650 | } | |
3651 | ||
3652 | print "</ul>"; | |
3653 | ||
3654 | } */ | |
bca02305 | 3655 | } |
df268d47 AD |
3656 | |
3657 | print "</div>"; | |
3658 | ||
3659 | print "<div align='center'> | |
3660 | <input type='submit' class='button' | |
3661 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
3662 | } | |
c6c3a07f | 3663 | |
4b3dff6e | 3664 | db_close($link); |
1cd17194 | 3665 | ?> |
406d9489 AD |
3666 | |
3667 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
3668 |