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