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