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