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