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