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