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