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