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