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