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