]>
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 | ||
49756fc3 | 31 | define('SCHEMA_VERSION', 3); |
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 | |
f9cb39ac AD |
1504 | if ($subop == "browse") { |
1505 | ||
1506 | print "<div class=\"infoBoxContents\">"; | |
1507 | ||
1508 | print "<h1>Feed browser</h1>"; | |
1509 | ||
1510 | print "<p>Showing top 50 registered feeds, sorted by popularity:</p>"; | |
1511 | ||
1512 | $result = db_query($link, "SELECT feed_url,count(id) AS subscribers | |
1513 | FROM ttrss_feeds WHERE auth_login = '' AND auth_pass = '' | |
1514 | GROUP BY feed_url ORDER BY subscribers LIMIT 50"); | |
1515 | ||
1516 | print "<ul class='browseFeedList' id='browseFeedList'>"; | |
1517 | ||
1518 | while ($line = db_fetch_assoc($result)) { | |
1519 | $feed_url = $line["feed_url"]; | |
1520 | $subscribers = $line["subscribers"]; | |
1521 | ||
1522 | $det_result = db_query($link, "SELECT site_url,title,id | |
1523 | FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1"); | |
1524 | ||
1525 | $details = db_fetch_assoc($det_result); | |
1526 | ||
1527 | $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico"; | |
1528 | ||
1529 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1530 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . | |
1531 | "/".$details["id"].".ico\">"; | |
1532 | } else { | |
1533 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
1534 | } | |
1535 | ||
1536 | $check_box = "<input class='feedBrowseCB' type=\"checkbox\" id=\"BFCHK-" . $details["id"] . "\">"; | |
1537 | ||
1538 | print "<li>$check_box $feed_icon" . $details["title"] . | |
1539 | " <span class='subscribers'>($subscribers)</span></li>"; | |
1540 | } | |
1541 | ||
1542 | print "</ul>"; | |
1543 | ||
1544 | print "<div align='center'> | |
1545 | <input type='submit' class='button' | |
1546 | onclick=\"closeInfoBox()\" value=\"Cancel\"> | |
1547 | <input type=\"submit\" class=\"button\" | |
1548 | onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\"></div>"; | |
1549 | ||
1550 | print "</div>"; | |
1551 | return; | |
1552 | } | |
1553 | ||
0ea4fb50 AD |
1554 | if ($subop == "editfeed") { |
1555 | $feed_id = db_escape_string($_GET["id"]); | |
1556 | ||
1557 | $result = db_query($link, | |
1558 | "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND | |
1559 | owner_uid = " . $_SESSION["uid"]); | |
1560 | ||
1561 | $title = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
1562 | 0, "title"))); | |
1563 | ||
1564 | print "<div class=\"infoBoxContents\">"; | |
1565 | ||
1566 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
1567 | ||
1568 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1569 | $feed_icon = "<img width=\"16\" height=\"16\" | |
1570 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
1571 | } else { | |
1572 | $feed_icon = ""; | |
1573 | } | |
1574 | ||
1575 | print "<h1>$feed_icon $title</h1>"; | |
1576 | ||
1577 | print "<table width='100%'>"; | |
1578 | ||
1579 | $row_class = "odd"; | |
1580 | ||
1581 | print "<tr class='$row_class'><td>Title:</td>"; | |
1582 | print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>"; | |
1583 | ||
1584 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
1585 | $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
1586 | 0, "feed_url"))); | |
1587 | $row_class = toggleEvenOdd($row_class); | |
1588 | ||
1589 | print "<tr class='$row_class'><td>Feed URL:</td>"; | |
1590 | print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>"; | |
1591 | ||
1592 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1593 | ||
1594 | $cat_id = db_fetch_result($result, 0, "cat_id"); | |
1595 | ||
1596 | $row_class = toggleEvenOdd($row_class); | |
1597 | ||
1598 | print "<tr class='$row_class'><td>Category:</td>"; | |
1599 | print "<td>"; | |
1600 | print "<select id=\"iedit_fcat\">"; | |
1601 | print "<option id=\"0\">Uncategorized</option>"; | |
1602 | ||
1603 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
1604 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1605 | ||
1606 | if (db_num_rows($tmp_result) > 0) { | |
1607 | print "<option disabled>--------</option>"; | |
1608 | } | |
1609 | ||
1610 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1611 | if ($tmp_line["id"] == $cat_id) { | |
1612 | $is_selected = "selected"; | |
1613 | } else { | |
1614 | $is_selected = ""; | |
1615 | } | |
1616 | printf("<option $is_selected id='%d'>%s</option>", | |
1617 | $tmp_line["id"], $tmp_line["title"]); | |
1618 | } | |
1619 | ||
1620 | print "</select></td>"; | |
1621 | print "</td></tr>"; | |
1622 | ||
1623 | } | |
1624 | ||
1625 | $update_interval = db_fetch_result($result, 0, "update_interval"); | |
1626 | $row_class = toggleEvenOdd($row_class); | |
1627 | ||
1628 | print "<tr class='$row_class'><td>Update Interval:</td>"; | |
1629 | print "<td><input id=\"iedit_updintl\" | |
1630 | value=\"$update_interval\"></td></tr>"; | |
1631 | ||
1da7e457 AD |
1632 | $row_class = toggleEvenOdd($row_class); |
1633 | print "<tr class='$row_class'><td>Link to:</td>"; | |
1634 | ||
1635 | $parent_feed = db_fetch_result($result, 0, "parent_feed"); | |
1636 | ||
1637 | print "<select id=\"iedit_parent_feed\">"; | |
eac46afb | 1638 | print "<option id=\"0\">Not linked</option>"; |
1da7e457 | 1639 | |
8a53e029 AD |
1640 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
1641 | if ($cat_id) { | |
1642 | $cat_qpart = "AND cat_id = '$cat_id'"; | |
1643 | } else { | |
1644 | $cat_qpart = "AND cat_id IS NULL"; | |
1645 | } | |
1646 | } | |
1647 | ||
1da7e457 | 1648 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds |
8a53e029 | 1649 | WHERE owner_uid = ".$_SESSION["uid"]." $cat_qpart ORDER BY title"); |
1da7e457 AD |
1650 | |
1651 | if (db_num_rows($tmp_result) > 0) { | |
1652 | print "<option disabled>--------</option>"; | |
1653 | } | |
1654 | ||
1655 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1656 | if ($tmp_line["id"] == $parent_feed) { | |
1657 | $is_selected = "selected"; | |
1658 | } else { | |
1659 | $is_selected = ""; | |
1660 | } | |
1661 | printf("<option $is_selected id='%d'>%s</option>", | |
1662 | $tmp_line["id"], $tmp_line["title"]); | |
1663 | } | |
1664 | ||
1665 | print "</select></td>"; | |
1666 | print "</td></tr>"; | |
1667 | ||
0ea4fb50 AD |
1668 | $purge_interval = db_fetch_result($result, 0, "purge_interval"); |
1669 | $row_class = toggleEvenOdd($row_class); | |
1670 | ||
1671 | print "<tr class='$row_class'><td>Purge Days:</td>"; | |
1672 | print "<td><input id=\"iedit_purgintl\" | |
1673 | value=\"$purge_interval\"></td></tr>"; | |
1674 | ||
47c6c988 AD |
1675 | // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>"; |
1676 | ||
1677 | $row_class = toggleEvenOdd($row_class); | |
1678 | $auth_login = db_fetch_result($result, 0, "auth_login"); | |
1679 | ||
1680 | print "<tr class='$row_class'><td>Login:</td>"; | |
1681 | print "<td><input id=\"iedit_login\" | |
1682 | value=\"$auth_login\"></td></tr>"; | |
1683 | ||
1684 | $row_class = toggleEvenOdd($row_class); | |
1685 | $auth_pass = db_fetch_result($result, 0, "auth_pass"); | |
1686 | ||
1687 | print "<tr class='$row_class'><td>Password:</td>"; | |
1688 | print "<td><input type=\"password\" id=\"iedit_pass\" | |
1689 | value=\"$auth_pass\"></td></tr>"; | |
1690 | ||
0ea4fb50 AD |
1691 | print "</table>"; |
1692 | print "</div>"; | |
1693 | ||
1694 | print "<div align='center'> | |
1695 | <input type='submit' class='button' | |
327a3bbe | 1696 | onclick=\"feedEditCancel()\" value=\"Cancel\"> |
0ea4fb50 | 1697 | <input type=\"submit\" class=\"button\" |
327a3bbe | 1698 | onclick=\"feedEditSave()\" value=\"Save\"></div>"; |
0ea4fb50 AD |
1699 | return; |
1700 | } | |
1701 | ||
508a81e1 | 1702 | if ($subop == "editSave") { |
47c6c988 AD |
1703 | $feed_title = db_escape_string($_POST["t"]); |
1704 | $feed_link = db_escape_string($_POST["l"]); | |
1705 | $upd_intl = db_escape_string($_POST["ui"]); | |
1706 | $purge_intl = db_escape_string($_POST["pi"]); | |
1707 | $feed_id = db_escape_string($_POST["id"]); | |
1708 | $cat_id = db_escape_string($_POST["catid"]); | |
1709 | $auth_login = db_escape_string($_POST["login"]); | |
1710 | $auth_pass = db_escape_string($_POST["pass"]); | |
1da7e457 | 1711 | $parent_feed = db_escape_string($_POST["pfeed"]); |
508a81e1 | 1712 | |
d148926e AD |
1713 | if (strtoupper($upd_intl) == "DEFAULT") |
1714 | $upd_intl = 0; | |
1715 | ||
a88c1f36 AD |
1716 | if (strtoupper($upd_intl) == "DISABLED") |
1717 | $upd_intl = -1; | |
1718 | ||
5d73494a AD |
1719 | if (strtoupper($purge_intl) == "DEFAULT") |
1720 | $purge_intl = 0; | |
1721 | ||
140aae81 AD |
1722 | if (strtoupper($purge_intl) == "DISABLED") |
1723 | $purge_intl = -1; | |
1724 | ||
91ff844a AD |
1725 | if ($cat_id != 0) { |
1726 | $category_qpart = "cat_id = '$cat_id'"; | |
1727 | } else { | |
1728 | $category_qpart = 'cat_id = NULL'; | |
1729 | } | |
1730 | ||
1da7e457 AD |
1731 | if ($parent_feed != 0) { |
1732 | $parent_qpart = "parent_feed = '$parent_feed'"; | |
1733 | } else { | |
1734 | $parent_qpart = 'parent_feed = NULL'; | |
1735 | } | |
1736 | ||
648472a7 | 1737 | $result = db_query($link, "UPDATE ttrss_feeds SET |
91ff844a | 1738 | $category_qpart, |
1da7e457 | 1739 | $parent_qpart, |
d148926e | 1740 | title = '$feed_title', feed_url = '$feed_link', |
5d73494a | 1741 | update_interval = '$upd_intl', |
47c6c988 AD |
1742 | purge_interval = '$purge_intl', |
1743 | auth_login = '$auth_login', | |
1744 | auth_pass = '$auth_pass' | |
f72dbbde | 1745 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); |
5ddadb4c AD |
1746 | } |
1747 | ||
1748 | if ($subop == "saveCat") { | |
1749 | $cat_title = db_escape_string($_GET["title"]); | |
1750 | $cat_id = db_escape_string($_GET["id"]); | |
1751 | ||
1752 | $result = db_query($link, "UPDATE ttrss_feed_categories SET | |
1753 | title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); | |
508a81e1 | 1754 | |
83fe4d6d AD |
1755 | } |
1756 | ||
331900c6 | 1757 | if ($subop == "remove") { |
331900c6 | 1758 | |
b0b4abcf | 1759 | if (!WEB_DEMO_MODE) { |
331900c6 | 1760 | |
f932bc9f | 1761 | $ids = split(",", db_escape_string($_GET["ids"])); |
b0b4abcf AD |
1762 | |
1763 | foreach ($ids as $id) { | |
f72dbbde AD |
1764 | db_query($link, "DELETE FROM ttrss_feeds |
1765 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
4769ddaf | 1766 | |
273a2f6b | 1767 | $icons_dir = ICONS_DIR; |
d5caaae5 | 1768 | |
4769ddaf AD |
1769 | if (file_exists($icons_dir . "/$id.ico")) { |
1770 | unlink($icons_dir . "/$id.ico"); | |
d5caaae5 | 1771 | } |
b0b4abcf | 1772 | } |
331900c6 AD |
1773 | } |
1774 | } | |
1775 | ||
1776 | if ($subop == "add") { | |
b0b4abcf AD |
1777 | |
1778 | if (!WEB_DEMO_MODE) { | |
331900c6 | 1779 | |
b6b535ca | 1780 | $feed_link = db_escape_string(trim($_GET["link"])); |
15da5cc1 AD |
1781 | $cat_id = db_escape_string($_GET["cid"]); |
1782 | ||
5edfe303 | 1783 | if ($cat_id == "0" || !$cat_id) { |
15da5cc1 AD |
1784 | $cat_qpart = "NULL"; |
1785 | } else { | |
1786 | $cat_qpart = "'$cat_id'"; | |
1787 | } | |
331900c6 | 1788 | |
648472a7 | 1789 | $result = db_query($link, |
7e9a3986 AD |
1790 | "SELECT id FROM ttrss_feeds |
1791 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
1792 | ||
1793 | if (db_num_rows($result) == 0) { | |
1794 | ||
1795 | $result = db_query($link, | |
15da5cc1 | 1796 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) |
746b249f AD |
1797 | VALUES ('".$_SESSION["uid"]."', '$feed_link', |
1798 | '[Unknown]', $cat_qpart)"); | |
331900c6 | 1799 | |
7e9a3986 | 1800 | $result = db_query($link, |
746b249f | 1801 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' |
7e9a3986 AD |
1802 | AND owner_uid = " . $_SESSION["uid"]); |
1803 | ||
1804 | $feed_id = db_fetch_result($result, 0, "id"); | |
1805 | ||
1806 | if ($feed_id) { | |
ddb68b81 | 1807 | update_rss_feed($link, $feed_link, $feed_id, true); |
7e9a3986 AD |
1808 | } |
1809 | } else { | |
331900c6 | 1810 | |
7e9a3986 AD |
1811 | print "<div class=\"warning\"> |
1812 | Feed <b>$feed_link</b> already exists in the database. | |
1813 | </div>"; | |
b0b4abcf AD |
1814 | } |
1815 | } | |
331900c6 | 1816 | } |
a0d53889 | 1817 | |
91ff844a AD |
1818 | if ($subop == "addCat") { |
1819 | ||
1820 | if (!WEB_DEMO_MODE) { | |
1821 | ||
1822 | $feed_cat = db_escape_string(trim($_GET["cat"])); | |
1823 | ||
1824 | $result = db_query($link, | |
1825 | "SELECT id FROM ttrss_feed_categories | |
1826 | WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); | |
1827 | ||
1828 | if (db_num_rows($result) == 0) { | |
1829 | ||
1830 | $result = db_query($link, | |
1831 | "INSERT INTO ttrss_feed_categories (owner_uid,title) | |
1832 | VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); | |
1833 | ||
1834 | } else { | |
1835 | ||
1836 | print "<div class=\"warning\"> | |
1837 | Category <b>$feed_cat</b> already exists in the database. | |
1838 | </div>"; | |
1839 | } | |
1840 | ||
1841 | ||
1842 | } | |
1843 | } | |
1844 | ||
1845 | if ($subop == "removeCats") { | |
1846 | ||
1847 | if (!WEB_DEMO_MODE) { | |
1848 | ||
f932bc9f | 1849 | $ids = split(",", db_escape_string($_GET["ids"])); |
91ff844a AD |
1850 | |
1851 | foreach ($ids as $id) { | |
1852 | ||
1853 | db_query($link, "BEGIN"); | |
1854 | ||
1855 | $result = db_query($link, | |
1856 | "SELECT count(id) as num_feeds FROM ttrss_feeds | |
1857 | WHERE cat_id = '$id'"); | |
1858 | ||
1859 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
1860 | ||
1861 | if ($num_feeds == 0) { | |
1862 | db_query($link, "DELETE FROM ttrss_feed_categories | |
1863 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1864 | } else { | |
1865 | ||
1866 | print "<div class=\"warning\"> | |
1867 | Unable to delete non empty feed categories.</div>"; | |
1868 | ||
1869 | } | |
1870 | ||
1871 | db_query($link, "COMMIT"); | |
1872 | } | |
1873 | } | |
1874 | } | |
1875 | ||
f932bc9f AD |
1876 | if ($subop == "categorize") { |
1877 | ||
1878 | if (!WEB_DEMO_MODE) { | |
1879 | ||
1880 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1881 | ||
1882 | $cat_id = db_escape_string($_GET["cat_id"]); | |
1883 | ||
1884 | if ($cat_id == 0) { | |
1885 | $cat_id_qpart = 'NULL'; | |
1886 | } else { | |
1887 | $cat_id_qpart = "'$cat_id'"; | |
1888 | } | |
1889 | ||
1890 | db_query($link, "BEGIN"); | |
1891 | ||
1892 | foreach ($ids as $id) { | |
1893 | ||
1894 | db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart | |
1895 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1896 | } | |
1897 | ||
1898 | db_query($link, "COMMIT"); | |
1899 | } | |
1900 | ||
1901 | } | |
1902 | ||
a24f525c AD |
1903 | if ($quiet) return; |
1904 | ||
c64d5b03 | 1905 | // print "<h3>Edit Feeds</h3>"; |
91ff844a | 1906 | |
4904f845 AD |
1907 | $result = db_query($link, "SELECT id,title,feed_url,last_error |
1908 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); | |
1909 | ||
1910 | if (db_num_rows($result) > 0) { | |
1911 | ||
1912 | print "<div class=\"warning\">"; | |
a9b0bfd5 AD |
1913 | |
1914 | // print"<img class=\"closeButton\" | |
1915 | // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">"; | |
1916 | ||
36aab70f AD |
1917 | print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\"> |
1918 | <b>Feeds with update errors</b> (click to expand)</a>"; | |
4904f845 | 1919 | |
36aab70f | 1920 | print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">"; |
4904f845 AD |
1921 | |
1922 | while ($line = db_fetch_assoc($result)) { | |
1923 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
1924 | $line["last_error"]; | |
1925 | } | |
1926 | ||
1927 | print "</ul>"; | |
1928 | print "</div>"; | |
1929 | ||
1930 | } | |
1931 | ||
f932bc9f AD |
1932 | $feed_search = db_escape_string($_GET["search"]); |
1933 | ||
1934 | if (array_key_exists("search", $_GET)) { | |
1935 | $_SESSION["prefs_feed_search"] = $feed_search; | |
1936 | } else { | |
1937 | $feed_search = $_SESSION["prefs_feed_search"]; | |
1938 | } | |
1939 | ||
1940 | print "<table width='100%' class=\"prefGenericAddBox\" | |
1941 | cellspacing='0' cellpadding='0'><tr> | |
1942 | <td> | |
1943 | <input id=\"fadd_link\" | |
1944 | onchange=\"javascript:addFeed()\" | |
1945 | size=\"40\"> | |
1946 | <input type=\"submit\" class=\"button\" | |
1947 | onclick=\"javascript:addFeed()\" value=\"Add feed\"> | |
f9cb39ac AD |
1948 | |
1949 | (<a href='javascript:browseFeeds()'>Browse feeds</a>) | |
f932bc9f AD |
1950 | </td><td align='right'> |
1951 | <input id=\"feed_search\" size=\"20\" | |
1952 | onchange=\"javascript:updateFeedList()\" | |
1953 | value=\"$feed_search\"> | |
1954 | <input type=\"submit\" class=\"button\" | |
1955 | onclick=\"javascript:updateFeedList()\" value=\"Search\"> | |
1956 | </td> | |
1957 | </tr></table>"; | |
a0d53889 | 1958 | |
b83c7545 AD |
1959 | $feeds_sort = db_escape_string($_GET["sort"]); |
1960 | ||
1961 | if (!$feeds_sort || $feeds_sort == "undefined") { | |
1962 | $feeds_sort = $_SESSION["pref_sort_feeds"]; | |
1963 | if (!$feeds_sort) $feeds_sort = "title"; | |
1964 | } | |
1965 | ||
1966 | $_SESSION["pref_sort_feeds"] = $feeds_sort; | |
1967 | ||
f932bc9f | 1968 | if ($feed_search) { |
11de82c3 AD |
1969 | $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR |
1970 | UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND"; | |
f932bc9f AD |
1971 | } else { |
1972 | $search_qpart = ""; | |
1973 | } | |
1974 | ||
648472a7 | 1975 | $result = db_query($link, "SELECT |
db42b934 AD |
1976 | F1.id, |
1977 | F1.title, | |
1978 | F1.feed_url, | |
1979 | substring(F1.last_updated,1,16) AS last_updated, | |
1980 | F1.parent_feed, | |
1981 | F1.update_interval, | |
1982 | F1.purge_interval, | |
1983 | F1.cat_id, | |
1984 | F2.title AS parent_title, | |
1985 | C1.title AS category | |
c0e5a40e | 1986 | FROM |
db42b934 AD |
1987 | ttrss_feeds AS F1 |
1988 | LEFT JOIN ttrss_feeds AS F2 | |
1989 | ON (F1.parent_feed = F2.id) | |
1990 | LEFT JOIN ttrss_feed_categories AS C1 | |
1991 | ON (F1.cat_id = C1.id) | |
f932bc9f | 1992 | WHERE |
db42b934 | 1993 | $search_qpart F1.owner_uid = '".$_SESSION["uid"]."' |
0ea4fb50 | 1994 | ORDER by category,$feeds_sort,title"); |
1cd17194 | 1995 | |
3b0feb9b | 1996 | if (db_num_rows($result) != 0) { |
91ff844a | 1997 | |
3b0feb9b | 1998 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
35f3c923 | 1999 | |
f4fe2cde AD |
2000 | print "<p><table width=\"100%\" cellspacing=\"0\" |
2001 | class=\"prefFeedList\" id=\"prefFeedList\">"; | |
35f3c923 AD |
2002 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> |
2003 | Select: | |
2004 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', | |
3055bc41 | 2005 | 'FEEDR-', 'FRCHK-', true)\">All</a>, |
35f3c923 | 2006 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', |
3055bc41 | 2007 | 'FEEDR-', 'FRCHK-', false)\">None</a> |
35f3c923 AD |
2008 | </td</tr>"; |
2009 | ||
0ea4fb50 AD |
2010 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { |
2011 | print "<tr class=\"title\"> | |
e325c6e7 | 2012 | <td width='5%' align='center'> </td> |
62ac0cc8 | 2013 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> |
f42e9435 | 2014 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> |
62ac0cc8 AD |
2015 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> |
2016 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>"; | |
603c27f8 | 2017 | } |
603c27f8 | 2018 | |
c64d5b03 | 2019 | $lnum = 0; |
0ea4fb50 AD |
2020 | |
2021 | $cur_cat_id = -1; | |
c64d5b03 AD |
2022 | |
2023 | while ($line = db_fetch_assoc($result)) { | |
2024 | ||
3b0feb9b | 2025 | $feed_id = $line["id"]; |
0ea4fb50 AD |
2026 | $cat_id = $line["cat_id"]; |
2027 | ||
2028 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
2029 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
2030 | $edit_cat = htmlspecialchars(db_unescape_string($line["category"])); | |
c64d5b03 | 2031 | |
0ea4fb50 AD |
2032 | if ($line["update_interval"] == "0") $line["update_interval"] = "Default"; |
2033 | if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled"; | |
2034 | if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default"; | |
2035 | if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled"; | |
2036 | ||
2037 | if (!$edit_cat) $edit_cat = "Uncategorized"; | |
2038 | ||
2039 | ||
2040 | if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) { | |
cb58d0df AD |
2041 | $lnum = 0; |
2042 | ||
0ea4fb50 AD |
2043 | print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>"; |
2044 | ||
2045 | print "<tr class=\"title\"> | |
e325c6e7 | 2046 | <td width='5%' align='center'> </td> |
62ac0cc8 | 2047 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> |
f42e9435 | 2048 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> |
62ac0cc8 AD |
2049 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> |
2050 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>"; | |
0ea4fb50 AD |
2051 | |
2052 | $cur_cat_id = $cat_id; | |
c64d5b03 | 2053 | } |
0ea4fb50 | 2054 | |
cb58d0df | 2055 | $class = ($lnum % 2) ? "even" : "odd"; |
0ea4fb50 AD |
2056 | $this_row_id = "id=\"FEEDR-$feed_id\""; |
2057 | ||
53226edc | 2058 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2059 | |
2060 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
2061 | ||
2062 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
327a3bbe | 2063 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">"; |
3b0feb9b | 2064 | } else { |
327a3bbe | 2065 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; |
3b0feb9b | 2066 | } |
327a3bbe | 2067 | // print "<td class='feedIcon'>$feed_icon</td>"; |
c64d5b03 | 2068 | |
62ac0cc8 | 2069 | print "<td class='feedSelect'><input onclick='toggleSelectRow(this);' |
0ea4fb50 | 2070 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
3547842a | 2071 | |
0ea4fb50 AD |
2072 | $edit_title = truncate_string($edit_title, 40); |
2073 | $edit_link = truncate_string($edit_link, 60); | |
a88c1f36 | 2074 | |
1da7e457 AD |
2075 | $parent_title = $line["parent_title"]; |
2076 | if ($parent_title) { | |
2077 | $parent_title = "<span class='groupPrompt'>(linked to | |
2078 | $parent_title)</span>"; | |
2079 | } | |
2080 | ||
0ea4fb50 | 2081 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
1da7e457 | 2082 | "$feed_icon $edit_title $parent_title" . "</a></td>"; |
0ea4fb50 AD |
2083 | |
2084 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2085 | $edit_link . "</a></td>"; | |
3547842a | 2086 | |
0ea4fb50 AD |
2087 | /* if (get_pref($link, 'ENABLE_FEED_CATS')) { |
2088 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2089 | $edit_cat . "</a></td>"; | |
2090 | } */ | |
3547842a | 2091 | |
0ea4fb50 AD |
2092 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
2093 | $line["update_interval"] . "</a></td>"; | |
3b0feb9b | 2094 | |
0ea4fb50 AD |
2095 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
2096 | $line["purge_interval"] . "</a></td>"; | |
3b0feb9b | 2097 | |
c64d5b03 AD |
2098 | print "</tr>"; |
2099 | ||
2100 | ++$lnum; | |
2101 | } | |
2102 | ||
c64d5b03 | 2103 | print "</table>"; |
3b0feb9b | 2104 | |
c64d5b03 AD |
2105 | print "<p>"; |
2106 | ||
3b0feb9b AD |
2107 | if ($subop == "edit") { |
2108 | print "Edit feed: | |
c64d5b03 | 2109 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 2110 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> |
c64d5b03 | 2111 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2112 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
2113 | } else { | |
c64d5b03 AD |
2114 | |
2115 | print " | |
2116 | Selection: | |
2117 | <input type=\"submit\" class=\"button\" | |
3b0feb9b | 2118 | onclick=\"javascript:selectedFeedDetails()\" value=\"Details\"> |
c64d5b03 | 2119 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2120 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> |
2121 | <input type=\"submit\" class=\"button\" | |
2122 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
f932bc9f AD |
2123 | |
2124 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2125 | ||
2126 | print " "; | |
2127 | ||
2128 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2129 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2130 | ORDER BY title"); | |
2131 | ||
2132 | print "<select id=\"sfeed_set_fcat\">"; | |
2133 | print "<option id=\"0\">Uncategorized</option>"; | |
2134 | ||
2135 | if (db_num_rows($result) != 0) { | |
2136 | ||
2137 | print "<option disabled>--------</option>"; | |
2138 | ||
2139 | while ($line = db_fetch_assoc($result)) { | |
2140 | printf("<option id='%d'>%s</option>", | |
2141 | $line["id"], $line["title"]); | |
2142 | } | |
2143 | } | |
2144 | ||
2145 | print "</select>"; | |
2146 | ||
2147 | print " <input type=\"submit\" class=\"button\" | |
2148 | onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">"; | |
2149 | ||
2150 | } | |
2151 | ||
3b0feb9b AD |
2152 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { |
2153 | print " | |
2154 | <input type=\"submit\" class=\"button\" | |
4f3a84f4 | 2155 | onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\"> |
3b0feb9b | 2156 | <input type=\"submit\" class=\"button\" |
4f3a84f4 | 2157 | onclick=\"javascript:readSelectedFeeds(false)\" |
3b0feb9b AD |
2158 | value=\"Mark as unread\"> "; |
2159 | } | |
2160 | ||
2161 | print " | |
f932bc9f | 2162 | All feeds: <input type=\"submit\" |
3b0feb9b AD |
2163 | class=\"button\" onclick=\"gotoExportOpml()\" |
2164 | value=\"Export OPML\">"; | |
2165 | } | |
2166 | } else { | |
2167 | ||
2168 | print "<p>No feeds defined.</p>"; | |
2169 | ||
2170 | } | |
2171 | ||
2172 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2173 | ||
2174 | print "<h3>Edit Categories</h3>"; | |
2175 | ||
2176 | // print "<h3>Categories</h3>"; | |
2177 | ||
2178 | print "<div class=\"prefGenericAddBox\"> | |
f932bc9f AD |
2179 | <input id=\"fadd_cat\" |
2180 | onchange=\"javascript:addFeedCat()\" | |
2181 | size=\"40\"> | |
2182 | <input | |
3b0feb9b AD |
2183 | type=\"submit\" class=\"button\" |
2184 | onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>"; | |
2185 | ||
2186 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2187 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2188 | ORDER BY title"); | |
2189 | ||
2190 | if (db_num_rows($result) != 0) { | |
2191 | ||
35f3c923 | 2192 | print "<p><table width=\"100%\" class=\"prefFeedCatList\" |
f4fe2cde | 2193 | cellspacing=\"0\" id=\"prefFeedCatList\">"; |
35f3c923 AD |
2194 | |
2195 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2196 | Select: | |
2197 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', | |
3055bc41 | 2198 | 'FCATR-', 'FCCHK-', true)\">All</a>, |
35f3c923 | 2199 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', |
3055bc41 | 2200 | 'FCATR-', 'FCCHK-', false)\">None</a> |
35f3c923 AD |
2201 | </td</tr>"; |
2202 | ||
3b0feb9b | 2203 | print "<tr class=\"title\"> |
a426e532 | 2204 | <td width=\"5%\"></td><td width=\"80%\">Title</td> |
3b0feb9b AD |
2205 | </tr>"; |
2206 | ||
2207 | $lnum = 0; | |
2208 | ||
2209 | while ($line = db_fetch_assoc($result)) { | |
2210 | ||
2211 | $class = ($lnum % 2) ? "even" : "odd"; | |
2212 | ||
2213 | $cat_id = $line["id"]; | |
2214 | ||
2215 | $edit_cat_id = $_GET["id"]; | |
2216 | ||
2217 | if ($subop == "editCat" && $cat_id != $edit_cat_id) { | |
2218 | $class .= "Grayed"; | |
53226edc AD |
2219 | $this_row_id = ""; |
2220 | } else { | |
2221 | $this_row_id = "id=\"FCATR-$cat_id\""; | |
3b0feb9b AD |
2222 | } |
2223 | ||
53226edc | 2224 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2225 | |
2226 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
2227 | ||
2228 | if (!$edit_cat_id || $subop != "editCat") { | |
2229 | ||
a426e532 | 2230 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
2231 | type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>"; |
2232 | ||
2233 | print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . | |
2234 | $edit_title . "</a></td>"; | |
2235 | ||
2236 | } else if ($cat_id != $edit_cat_id) { | |
2237 | ||
2238 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2239 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
2240 | ||
2241 | print "<td>$edit_title</td>"; | |
2242 | ||
2243 | } else { | |
2244 | ||
2245 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2246 | ||
2247 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; | |
2248 | ||
2249 | } | |
2250 | ||
2251 | print "</tr>"; | |
2252 | ||
2253 | ++$lnum; | |
2254 | } | |
2255 | ||
2256 | print "</table>"; | |
2257 | ||
2258 | print "<p>"; | |
2259 | ||
2260 | if ($subop == "editCat") { | |
2261 | print "Edit category: | |
2262 | <input type=\"submit\" class=\"button\" | |
2263 | onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\"> | |
2264 | <input type=\"submit\" class=\"button\" | |
2265 | onclick=\"javascript:feedCatEditSave()\" value=\"Save\">"; | |
2266 | } else { | |
2267 | ||
2268 | print " | |
2269 | Selection: | |
2270 | <input type=\"submit\" class=\"button\" | |
2271 | onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\"> | |
2272 | <input type=\"submit\" class=\"button\" | |
2273 | onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">"; | |
2274 | ||
2275 | } | |
2276 | ||
2277 | } else { | |
2278 | print "<p>No feed categories defined.</p>"; | |
2279 | } | |
c64d5b03 AD |
2280 | } |
2281 | ||
2282 | print "<h3>Import OPML</h3> | |
f5a50b25 AD |
2283 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> |
2284 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
2285 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
2286 | type=\"submit\" value=\"Import\"> | |
2287 | </form>"; | |
2288 | ||
007bda35 AD |
2289 | } |
2290 | ||
a0d53889 AD |
2291 | if ($op == "pref-filters") { |
2292 | ||
2293 | $subop = $_GET["subop"]; | |
a24f525c | 2294 | $quiet = $_GET["quiet"]; |
a0d53889 AD |
2295 | |
2296 | if ($subop == "editSave") { | |
a0d53889 | 2297 | |
648472a7 AD |
2298 | $regexp = db_escape_string($_GET["r"]); |
2299 | $descr = db_escape_string($_GET["d"]); | |
2300 | $match = db_escape_string($_GET["m"]); | |
2301 | $filter_id = db_escape_string($_GET["id"]); | |
ead60402 | 2302 | $feed_id = db_escape_string($_GET["fid"]); |
19c9cb11 | 2303 | $action_id = db_escape_string($_GET["aid"]); |
ead60402 AD |
2304 | |
2305 | if (!$feed_id) { | |
2306 | $feed_id = 'NULL'; | |
2307 | } else { | |
2308 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2309 | } | |
0afbd851 | 2310 | |
648472a7 | 2311 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 2312 | reg_exp = '$regexp', |
0afbd851 | 2313 | description = '$descr', |
ead60402 | 2314 | feed_id = $feed_id, |
19c9cb11 | 2315 | action_id = '$action_id', |
0afbd851 AD |
2316 | filter_type = (SELECT id FROM ttrss_filter_types WHERE |
2317 | description = '$match') | |
2318 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
2319 | } |
2320 | ||
2321 | if ($subop == "remove") { | |
2322 | ||
2323 | if (!WEB_DEMO_MODE) { | |
2324 | ||
f932bc9f | 2325 | $ids = split(",", db_escape_string($_GET["ids"])); |
a0d53889 AD |
2326 | |
2327 | foreach ($ids as $id) { | |
648472a7 | 2328 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
2329 | |
2330 | } | |
2331 | } | |
2332 | } | |
2333 | ||
2334 | if ($subop == "add") { | |
2335 | ||
de435974 | 2336 | if (!WEB_DEMO_MODE) { |
a0d53889 | 2337 | |
b6b535ca AD |
2338 | $regexp = db_escape_string(trim($_GET["regexp"])); |
2339 | $match = db_escape_string(trim($_GET["match"])); | |
ead60402 | 2340 | $feed_id = db_escape_string($_GET["fid"]); |
19c9cb11 | 2341 | $action_id = db_escape_string($_GET["aid"]); |
ead60402 AD |
2342 | |
2343 | if (!$feed_id) { | |
2344 | $feed_id = 'NULL'; | |
2345 | } else { | |
2346 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2347 | } | |
4401bf04 | 2348 | |
648472a7 | 2349 | $result = db_query($link, |
19c9cb11 AD |
2350 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, |
2351 | action_id) | |
2352 | VALUES | |
de435974 | 2353 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
19c9cb11 AD |
2354 | description = '$match'),'".$_SESSION["uid"]."', |
2355 | $feed_id, '$action_id')"); | |
de435974 | 2356 | } |
a0d53889 AD |
2357 | } |
2358 | ||
a24f525c AD |
2359 | if ($quiet) return; |
2360 | ||
648472a7 | 2361 | $result = db_query($link, "SELECT description |
a0d53889 AD |
2362 | FROM ttrss_filter_types ORDER BY description"); |
2363 | ||
2364 | $filter_types = array(); | |
2365 | ||
648472a7 | 2366 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
2367 | array_push($filter_types, $line["description"]); |
2368 | } | |
2369 | ||
2c7070b5 | 2370 | print "<div class=\"prefGenericAddBox\"> |
7cc1e5d6 | 2371 | <input id=\"fadd_regexp\" size=\"40\"> "; |
2c7070b5 | 2372 | |
ead60402 AD |
2373 | print_select("fadd_match", "Title", $filter_types); |
2374 | ||
2375 | print " <select id=\"fadd_feed\">"; | |
2376 | ||
2377 | print "<option selected id=\"0\">All feeds</option>"; | |
2378 | ||
2379 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2380 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2381 | ||
2382 | if (db_num_rows($result) > 0) { | |
2383 | print "<option disabled>--------</option>"; | |
2384 | } | |
2385 | ||
2386 | while ($line = db_fetch_assoc($result)) { | |
2387 | printf("<option id='%d'>%s</option>", $line["id"], $line["title"]); | |
2388 | } | |
2389 | ||
2c7070b5 | 2390 | print "</select> "; |
19c9cb11 AD |
2391 | |
2392 | print " Action: "; | |
2393 | ||
2394 | print "<select id=\"fadd_action\">"; | |
2395 | ||
2396 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2397 | ORDER BY name"); | |
2398 | ||
2399 | while ($line = db_fetch_assoc($result)) { | |
2400 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
2401 | } | |
2402 | ||
2403 | print "</select> "; | |
2404 | ||
2c7070b5 AD |
2405 | print "<input type=\"submit\" |
2406 | class=\"button\" onclick=\"javascript:addFilter()\" | |
2407 | value=\"Add filter\">"; | |
a0d53889 | 2408 | |
19c9cb11 AD |
2409 | print "</div>"; |
2410 | ||
648472a7 | 2411 | $result = db_query($link, "SELECT |
ead60402 AD |
2412 | ttrss_filters.id AS id,reg_exp, |
2413 | ttrss_filters.description AS description, | |
2414 | ttrss_filter_types.name AS filter_type_name, | |
2415 | ttrss_filter_types.description AS filter_type_descr, | |
2416 | feed_id, | |
19c9cb11 | 2417 | ttrss_filter_actions.description AS action_description, |
11de82c3 | 2418 | ttrss_feeds.title AS feed_title |
a0d53889 | 2419 | FROM |
11de82c3 AD |
2420 | ttrss_filters,ttrss_filter_types,ttrss_filter_actions LEFT JOIN |
2421 | ttrss_feeds ON (feed_id = ttrss_feeds.id) | |
4356293a | 2422 | WHERE |
ead60402 | 2423 | filter_type = ttrss_filter_types.id AND |
19c9cb11 | 2424 | ttrss_filter_actions.id = action_id AND |
ead60402 | 2425 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." |
4356293a | 2426 | ORDER by reg_exp"); |
a0d53889 | 2427 | |
3b0feb9b | 2428 | if (db_num_rows($result) != 0) { |
a0d53889 | 2429 | |
f4fe2cde AD |
2430 | print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" |
2431 | id=\"prefFilterList\">"; | |
35f3c923 AD |
2432 | |
2433 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2434 | Select: | |
2435 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', | |
3055bc41 | 2436 | 'FILRR-', 'FICHK-', true)\">All</a>, |
35f3c923 | 2437 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', |
3055bc41 | 2438 | 'FILRR-', 'FICHK-', false)\">None</a> |
35f3c923 AD |
2439 | </td</tr>"; |
2440 | ||
3b0feb9b | 2441 | print "<tr class=\"title\"> |
e325c6e7 | 2442 | <td align='center' width=\"5%\"> </td> |
19c9cb11 AD |
2443 | <td width=\"20%\">Filter expression</td> |
2444 | <td width=\"20%\">Feed</td> | |
2445 | <td width=\"15%\">Match</td> | |
2446 | <td width=\"15%\">Action</td> | |
3b0feb9b | 2447 | <td width=\"30%\">Description</td></tr>"; |
a0d53889 | 2448 | |
3b0feb9b AD |
2449 | $lnum = 0; |
2450 | ||
2451 | while ($line = db_fetch_assoc($result)) { | |
2452 | ||
2453 | $class = ($lnum % 2) ? "even" : "odd"; | |
2454 | ||
2455 | $filter_id = $line["id"]; | |
2456 | $edit_filter_id = $_GET["id"]; | |
2457 | ||
2458 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
2459 | $class .= "Grayed"; | |
53226edc AD |
2460 | $this_row_id = ""; |
2461 | } else { | |
2462 | $this_row_id = "id=\"FILRR-$filter_id\""; | |
ead60402 | 2463 | } |
3b0feb9b | 2464 | |
53226edc | 2465 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2466 | |
2467 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); | |
2468 | $line["description"] = htmlspecialchars($line["description"]); | |
2469 | ||
2470 | if (!$line["feed_title"]) $line["feed_title"] = "All feeds"; | |
2471 | ||
2472 | if (!$edit_filter_id || $subop != "edit") { | |
2473 | ||
2474 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2475 | ||
a426e532 | 2476 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
2477 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; |
2478 | ||
2479 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2480 | $line["reg_exp"] . "</td>"; | |
2481 | ||
2482 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2483 | $line["feed_title"] . "</td>"; | |
2484 | ||
2485 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2486 | $line["filter_type_descr"] . "</td>"; | |
19c9cb11 AD |
2487 | |
2488 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2489 | $line["action_description"] . "</td>"; | |
2490 | ||
3b0feb9b AD |
2491 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . |
2492 | $line["description"] . "</td>"; | |
2493 | ||
2494 | } else if ($filter_id != $edit_filter_id) { | |
2495 | ||
2496 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2497 | ||
2498 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2499 | id=\"FICHK-".$line["id"]."\"></td>"; | |
2500 | ||
2501 | print "<td>".$line["reg_exp"]."</td>"; | |
2502 | print "<td>".$line["feed_title"]."</td>"; | |
2503 | print "<td>".$line["filter_type_descr"]."</td>"; | |
19c9cb11 | 2504 | print "<td>".$line["action_description"]."</td>"; |
3b0feb9b | 2505 | print "<td>".$line["description"]."</td>"; |
19c9cb11 | 2506 | |
3b0feb9b AD |
2507 | } else { |
2508 | ||
2509 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2510 | ||
2511 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. | |
2512 | "\"></td>"; | |
2513 | ||
2514 | print "<td>"; | |
3b0feb9b | 2515 | print "<select id=\"iedit_feed\">"; |
3b0feb9b AD |
2516 | print "<option id=\"0\">All feeds</option>"; |
2517 | ||
3b0feb9b AD |
2518 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds |
2519 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
19c9cb11 AD |
2520 | |
2521 | if (db_num_rows($tmp_result) > 0) { | |
2522 | print "<option disabled>--------</option>"; | |
2523 | } | |
2524 | ||
3b0feb9b AD |
2525 | while ($tmp_line = db_fetch_assoc($tmp_result)) { |
2526 | if ($tmp_line["id"] == $line["feed_id"]) { | |
2527 | $is_selected = "selected"; | |
2528 | } else { | |
2529 | $is_selected = ""; | |
2530 | } | |
2531 | printf("<option $is_selected id='%d'>%s</option>", | |
2532 | $tmp_line["id"], $tmp_line["title"]); | |
ead60402 | 2533 | } |
3b0feb9b AD |
2534 | |
2535 | print "</select></td>"; | |
2536 | ||
2537 | print "<td>"; | |
2538 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
2539 | print "</td>"; | |
19c9cb11 AD |
2540 | |
2541 | print "<td>"; | |
2542 | print "<select id=\"iedit_filter_action\">"; | |
2543 | ||
2544 | $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2545 | ORDER BY description"); | |
2546 | ||
2547 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2548 | if ($tmp_line["description"] == $line["action_description"]) { | |
2549 | $is_selected = "selected"; | |
2550 | } else { | |
2551 | $is_selected = ""; | |
2552 | } | |
2553 | printf("<option $is_selected id='%d'>%s</option>", | |
2554 | $tmp_line["id"], $tmp_line["description"]); | |
2555 | } | |
3b0feb9b | 2556 | |
19c9cb11 AD |
2557 | print "</select></td>"; |
2558 | ||
2559 | ||
3b0feb9b AD |
2560 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. |
2561 | "\"></td>"; | |
2562 | ||
2563 | print "</td>"; | |
ead60402 | 2564 | } |
3b0feb9b AD |
2565 | |
2566 | print "</tr>"; | |
2567 | ||
2568 | ++$lnum; | |
a0d53889 | 2569 | } |
3b0feb9b AD |
2570 | |
2571 | if ($lnum == 0) { | |
2572 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
2573 | } | |
2574 | ||
2575 | print "</table>"; | |
2576 | ||
2577 | print "<p>"; | |
2578 | ||
2579 | if ($subop == "edit") { | |
2580 | print "Edit feed: | |
2581 | <input type=\"submit\" class=\"button\" | |
2582 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
2583 | <input type=\"submit\" class=\"button\" | |
2584 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
2585 | ||
2586 | } else { | |
2587 | ||
2588 | print " | |
2589 | Selection: | |
e828e31e | 2590 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 2591 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> |
e828e31e | 2592 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2593 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; |
2594 | } | |
2595 | ||
a0d53889 AD |
2596 | } else { |
2597 | ||
3b0feb9b AD |
2598 | print "<p>No filters defined.</p>"; |
2599 | ||
a0d53889 AD |
2600 | } |
2601 | } | |
2602 | ||
80dce858 AD |
2603 | // We need to accept raw SQL data in label queries, so not everything is escaped |
2604 | // here, this is by design. If you don't like the whole idea, disable labels | |
2605 | // altogether with GLOBAL_ENABLE_LABELS = false | |
2606 | ||
48f0adb0 AD |
2607 | if ($op == "pref-labels") { |
2608 | ||
cfaba6df AD |
2609 | if (!GLOBAL_ENABLE_LABELS) { |
2610 | return; | |
2611 | } | |
2612 | ||
48f0adb0 AD |
2613 | $subop = $_GET["subop"]; |
2614 | ||
d9dde1d6 AD |
2615 | if ($subop == "test") { |
2616 | ||
2617 | $expr = $_GET["expr"]; | |
2618 | $descr = $_GET["descr"]; | |
2619 | ||
2620 | print "<div class='infoBoxContents'>"; | |
2621 | ||
2622 | print "<h1>Label «$descr»</h1>"; | |
2623 | ||
2624 | // print "<p><b>Expression</b>: $expr</p>"; | |
2625 | ||
2626 | $result = db_query($link, | |
2627 | "SELECT count(id) AS num_matches | |
2628 | FROM ttrss_entries,ttrss_user_entries | |
2629 | WHERE ($expr) AND | |
2630 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2631 | owner_uid = " . $_SESSION["uid"]); | |
2632 | ||
2633 | $num_matches = db_fetch_result($result, 0, "num_matches");; | |
2634 | ||
2635 | if ($num_matches > 0) { | |
2636 | ||
a31a7b39 | 2637 | print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>"; |
d9dde1d6 AD |
2638 | |
2639 | $result = db_query($link, | |
2640 | "SELECT title, | |
2641 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
2642 | FROM ttrss_entries,ttrss_user_entries | |
2643 | WHERE ($expr) AND | |
2644 | ttrss_user_entries.ref_id = ttrss_entries.id | |
2645 | AND owner_uid = " . $_SESSION["uid"] . " | |
2646 | ORDER BY date_entered DESC LIMIT 5"); | |
2647 | ||
2648 | print "<ul class=\"nomarks\">"; | |
2649 | while ($line = db_fetch_assoc($result)) { | |
2650 | print "<li>".$line["title"]. | |
2651 | " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>"; | |
2652 | } | |
2653 | print "</ul>"; | |
2654 | ||
2655 | } else { | |
2656 | print "<p>Query didn't return any matches.</p>"; | |
2657 | } | |
2658 | ||
2659 | print "</div>"; | |
2660 | ||
2661 | print "<div align='center'> | |
2662 | <input type='submit' class='button' | |
2663 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
2664 | return; | |
2665 | } | |
2666 | ||
48f0adb0 AD |
2667 | if ($subop == "editSave") { |
2668 | ||
2669 | $sql_exp = $_GET["s"]; | |
2670 | $descr = $_GET["d"]; | |
2671 | $label_id = db_escape_string($_GET["id"]); | |
2672 | ||
2673 | // print "$sql_exp : $descr : $label_id"; | |
2674 | ||
2675 | $result = db_query($link, "UPDATE ttrss_labels SET | |
2676 | sql_exp = '$sql_exp', | |
2677 | description = '$descr' | |
2678 | WHERE id = '$label_id'"); | |
2679 | } | |
2680 | ||
2681 | if ($subop == "remove") { | |
2682 | ||
2683 | if (!WEB_DEMO_MODE) { | |
2684 | ||
f932bc9f | 2685 | $ids = split(",", db_escape_string($_GET["ids"])); |
48f0adb0 AD |
2686 | |
2687 | foreach ($ids as $id) { | |
2688 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
2689 | ||
2690 | } | |
2691 | } | |
2692 | } | |
2693 | ||
2694 | if ($subop == "add") { | |
2695 | ||
2696 | if (!WEB_DEMO_MODE) { | |
2697 | ||
4401bf04 AD |
2698 | // no escaping is done here on purpose |
2699 | $exp = trim($_GET["exp"]); | |
48f0adb0 AD |
2700 | |
2701 | $result = db_query($link, | |
4356293a AD |
2702 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) |
2703 | VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')"); | |
48f0adb0 AD |
2704 | } |
2705 | } | |
2706 | ||
2c7070b5 AD |
2707 | print "<div class=\"prefGenericAddBox\"> |
2708 | <input size=\"40\" id=\"ladd_expr\"> "; | |
48f0adb0 | 2709 | |
2c7070b5 AD |
2710 | print"<input type=\"submit\" class=\"button\" |
2711 | onclick=\"javascript:addLabel()\" value=\"Add label\"></div>"; | |
48f0adb0 AD |
2712 | |
2713 | $result = db_query($link, "SELECT | |
2714 | id,sql_exp,description | |
2715 | FROM | |
4356293a AD |
2716 | ttrss_labels |
2717 | WHERE | |
2718 | owner_uid = ".$_SESSION["uid"]." | |
2719 | ORDER by description"); | |
48f0adb0 | 2720 | |
d9dde1d6 AD |
2721 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
2722 | ||
3b0feb9b | 2723 | if (db_num_rows($result) != 0) { |
48f0adb0 | 2724 | |
f4fe2cde AD |
2725 | print "<p><table width=\"100%\" cellspacing=\"0\" |
2726 | class=\"prefLabelList\" id=\"prefLabelList\">"; | |
35f3c923 AD |
2727 | |
2728 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2729 | Select: | |
2730 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', | |
3055bc41 | 2731 | 'LILRR-', 'LICHK-', true)\">All</a>, |
35f3c923 | 2732 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', |
3055bc41 | 2733 | 'LILRR-', 'LICHK-', false)\">None</a> |
35f3c923 AD |
2734 | </td</tr>"; |
2735 | ||
3b0feb9b | 2736 | print "<tr class=\"title\"> |
e325c6e7 AD |
2737 | <td align='center' width=\"5%\"> </td> |
2738 | <td width=\"40%\">SQL expression | |
01c9c74a | 2739 | <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a> |
3b0feb9b AD |
2740 | </td> |
2741 | <td width=\"40%\">Caption</td></tr>"; | |
2742 | ||
2743 | $lnum = 0; | |
2744 | ||
2745 | while ($line = db_fetch_assoc($result)) { | |
2746 | ||
2747 | $class = ($lnum % 2) ? "even" : "odd"; | |
2748 | ||
2749 | $label_id = $line["id"]; | |
2750 | $edit_label_id = $_GET["id"]; | |
2751 | ||
2752 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
2753 | $class .= "Grayed"; | |
53226edc AD |
2754 | $this_row_id = ""; |
2755 | } else { | |
2756 | $this_row_id = "id=\"LILRR-$label_id\""; | |
3b0feb9b AD |
2757 | } |
2758 | ||
53226edc | 2759 | print "<tr class=\"$class\" $this_row_id>"; |
3b0feb9b AD |
2760 | |
2761 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
2762 | $line["description"] = htmlspecialchars($line["description"]); | |
2763 | ||
2764 | if (!$edit_label_id || $subop != "edit") { | |
2765 | ||
2766 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
2767 | ||
a426e532 | 2768 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
3b0feb9b AD |
2769 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; |
2770 | ||
2771 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
2772 | $line["sql_exp"] . "</td>"; | |
48f0adb0 | 2773 | |
3b0feb9b AD |
2774 | print "<td><a href=\"javascript:editLabel($label_id);\">" . |
2775 | $line["description"] . "</td>"; | |
2776 | ||
2777 | } else if ($label_id != $edit_label_id) { | |
2778 | ||
2779 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2780 | ||
2781 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2782 | id=\"LICHK-".$line["id"]."\"></td>"; | |
2783 | ||
2784 | print "<td>".$line["sql_exp"]."</td>"; | |
2785 | print "<td>".$line["description"]."</td>"; | |
2786 | ||
2787 | } else { | |
2788 | ||
2789 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2790 | ||
2791 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
2792 | "\"></td>"; | |
2793 | ||
2794 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
2795 | "\"></td>"; | |
2796 | ||
2797 | } | |
2798 | ||
48f0adb0 | 2799 | |
3b0feb9b AD |
2800 | print "</tr>"; |
2801 | ||
2802 | ++$lnum; | |
2803 | } | |
2804 | ||
2805 | if ($lnum == 0) { | |
2806 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
2807 | } | |
2808 | ||
2809 | print "</table>"; | |
2810 | ||
2811 | print "<p>"; | |
2812 | ||
2813 | if ($subop == "edit") { | |
2814 | print "Edit label: | |
d9dde1d6 AD |
2815 | <input type=\"submit\" class=\"button\" |
2816 | onclick=\"javascript:labelTest()\" value=\"Test\"> | |
3b0feb9b AD |
2817 | <input type=\"submit\" class=\"button\" |
2818 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
2819 | <input type=\"submit\" class=\"button\" | |
2820 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
2821 | ||
2822 | } else { | |
2823 | ||
2824 | print " | |
2825 | Selection: | |
48f0adb0 | 2826 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 2827 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> |
48f0adb0 | 2828 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
2829 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; |
2830 | } | |
48f0adb0 | 2831 | } else { |
3b0feb9b | 2832 | print "<p>No labels defined.</p>"; |
48f0adb0 AD |
2833 | } |
2834 | } | |
2835 | ||
e828e31e AD |
2836 | if ($op == "error") { |
2837 | print "<div width=\"100%\" align='center'>"; | |
2838 | $msg = $_GET["msg"]; | |
2839 | print $msg; | |
2840 | print "</div>"; | |
2841 | } | |
2842 | ||
7dc66a61 | 2843 | if ($op == "help") { |
01c9c74a AD |
2844 | if (!$_GET["noheaders"]) { |
2845 | print "<html><head> | |
2846 | <title>Tiny Tiny RSS : Help</title> | |
2847 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
2848 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
2849 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
2850 | </head><body>"; | |
2851 | } | |
7dc66a61 AD |
2852 | |
2853 | $tid = sprintf("%d", $_GET["tid"]); | |
2854 | ||
01c9c74a | 2855 | print "<div class='infoBoxContents'>"; |
7dc66a61 | 2856 | |
01c9c74a AD |
2857 | if (file_exists("help/$tid.php")) { |
2858 | include("help/$tid.php"); | |
2859 | } else { | |
2860 | print "<p>Help topic not found.</p>"; | |
2861 | } | |
7dc66a61 | 2862 | |
01c9c74a | 2863 | print "</div>"; |
7dc66a61 AD |
2864 | |
2865 | print "<div align='center'> | |
01c9c74a AD |
2866 | <input type='submit' class='button' |
2867 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
7dc66a61 | 2868 | |
01c9c74a AD |
2869 | if (!$_GET["noheaders"]) { |
2870 | print "</body></html>"; | |
2871 | } | |
7dc66a61 AD |
2872 | |
2873 | } | |
2874 | ||
f84a97a3 AD |
2875 | if ($op == "dlg") { |
2876 | $id = $_GET["id"]; | |
6de5d056 | 2877 | $param = $_GET["param"]; |
f84a97a3 AD |
2878 | |
2879 | if ($id == "quickAddFeed") { | |
76332f3c AD |
2880 | print " |
2881 | Feed URL: <input | |
033e47e0 | 2882 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" |
15da5cc1 AD |
2883 | id=\"qafInput\">"; |
2884 | ||
2885 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2886 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2887 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2888 | ORDER BY title"); | |
2889 | ||
2890 | print " <select id=\"qafCat\">"; | |
2891 | print "<option id=\"0\">Uncategorized</option>"; | |
2892 | ||
2893 | if (db_num_rows($result) != 0) { | |
2894 | ||
2895 | print "<option disabled>--------</option>"; | |
2896 | ||
2897 | while ($line = db_fetch_assoc($result)) { | |
2898 | printf("<option id='%d'>%s</option>", | |
2899 | $line["id"], $line["title"]); | |
2900 | } | |
2901 | } | |
2902 | ||
2903 | print "</select>"; | |
2904 | } | |
2905 | ||
2906 | print " <input class=\"button\" | |
f84a97a3 AD |
2907 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> |
2908 | <input class=\"button\" | |
2909 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2910 | value=\"Cancel\">"; | |
2911 | } | |
6de5d056 AD |
2912 | |
2913 | if ($id == "quickDelFeed") { | |
2914 | ||
2915 | $param = db_escape_string($param); | |
2916 | ||
2917 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
2918 | ||
2919 | if ($result) { | |
2920 | ||
2921 | $f_title = db_fetch_result($result, 0, "title"); | |
2922 | ||
76332f3c | 2923 | print "Remove current feed (<b>$f_title</b>)? |
6de5d056 AD |
2924 | <input class=\"button\" |
2925 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
2926 | <input class=\"button\" | |
2927 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2928 | value=\"Cancel\">"; | |
2929 | } else { | |
2930 | print "Error: Feed $param not found. | |
2931 | <input class=\"button\" | |
2932 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2933 | value=\"Cancel\">"; | |
2934 | } | |
2935 | } | |
2936 | ||
033e47e0 AD |
2937 | if ($id == "search") { |
2938 | ||
2939 | print "<input id=\"searchbox\" class=\"extSearch\" | |
2940 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
2941 | onchange=\"javascript:search()\"> | |
2942 | <select id=\"searchmodebox\"> | |
2943 | <option selected>All feeds</option> | |
2944 | <option>This feed</option> | |
2945 | </select> | |
2946 | <input type=\"submit\" | |
2947 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
2948 | <input class=\"button\" | |
2949 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2950 | value=\"Close\">"; | |
2951 | ||
2952 | } | |
2953 | ||
a24f525c AD |
2954 | if ($id == "quickAddFilter") { |
2955 | ||
2956 | $result = db_query($link, "SELECT description | |
2957 | FROM ttrss_filter_types ORDER BY description"); | |
2958 | ||
2959 | $filter_types = array(); | |
2960 | ||
2961 | while ($line = db_fetch_assoc($result)) { | |
2962 | array_push($filter_types, $line["description"]); | |
2963 | } | |
2964 | ||
2965 | print "<table>"; | |
2966 | ||
2967 | print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> "; | |
2968 | ||
2969 | print_select("fadd_match", "Title", $filter_types); | |
2970 | ||
2971 | print "</td></tr>"; | |
2972 | print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">"; | |
2973 | ||
2974 | print "<option selected id=\"0\">All feeds</option>"; | |
2975 | ||
2976 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2977 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2978 | ||
2979 | if (db_num_rows($result) > 0) { | |
2980 | print "<option disabled>--------</option>"; | |
2981 | } | |
2982 | ||
2983 | while ($line = db_fetch_assoc($result)) { | |
2984 | if ($param == $line["id"]) { | |
2985 | $selected = "selected"; | |
2986 | } else { | |
2987 | $selected = ""; | |
2988 | } | |
2989 | printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]); | |
2990 | } | |
2991 | ||
2992 | print "</select></td></tr>"; | |
2993 | ||
2994 | print "<tr><td>Action:</td>"; | |
2995 | ||
2996 | print "<td><select id=\"fadd_action\">"; | |
2997 | ||
2998 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2999 | ORDER BY name"); | |
3000 | ||
3001 | while ($line = db_fetch_assoc($result)) { | |
3002 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
3003 | } | |
3004 | ||
3005 | print "</select>"; | |
3006 | ||
3007 | print "</td></tr><tr><td colspan=\"2\" align=\"right\">"; | |
3008 | ||
3009 | print "<input type=\"submit\" | |
3010 | class=\"button\" onclick=\"javascript:qaddFilter()\" | |
3011 | value=\"Add filter\"> "; | |
3012 | ||
3013 | print "<input class=\"button\" | |
3014 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3015 | value=\"Close\">"; | |
3016 | ||
3017 | print "</td></tr></table>"; | |
3018 | } | |
f84a97a3 AD |
3019 | } |
3020 | ||
a2770077 AD |
3021 | // update feeds of all users, may be used anonymously |
3022 | if ($op == "globalUpdateFeeds") { | |
3023 | ||
3024 | $result = db_query($link, "SELECT id FROM ttrss_users"); | |
3025 | ||
3026 | while ($line = db_fetch_assoc($result)) { | |
3027 | $user_id = $line["id"]; | |
3028 | // print "<!-- updating feeds of uid $user_id -->"; | |
3029 | update_all_feeds($link, false, $user_id); | |
3030 | } | |
e65af9c1 | 3031 | |
a2770077 AD |
3032 | print "<rpc-reply> |
3033 | <message msg=\"All feeds updated\"/> | |
3034 | </rpc-reply>"; | |
e65af9c1 AD |
3035 | |
3036 | } | |
3037 | ||
77e96719 AD |
3038 | if ($op == "pref-prefs") { |
3039 | ||
b1895692 | 3040 | $subop = $_REQUEST["subop"]; |
77e96719 AD |
3041 | |
3042 | if ($subop == "Save configuration") { | |
3043 | ||
d2892032 AD |
3044 | if (WEB_DEMO_MODE) { |
3045 | header("Location: prefs.php"); | |
3046 | return; | |
3047 | } | |
01d68cf9 | 3048 | |
93cb4442 AD |
3049 | $_SESSION["prefs_op_result"] = "save-config"; |
3050 | ||
11de82c3 AD |
3051 | $_SESSION["prefs_cache"] = false; |
3052 | ||
77e96719 AD |
3053 | foreach (array_keys($_POST) as $pref_name) { |
3054 | ||
3055 | $pref_name = db_escape_string($pref_name); | |
3056 | $value = db_escape_string($_POST[$pref_name]); | |
3057 | ||
3058 | $result = db_query($link, "SELECT type_name | |
3059 | FROM ttrss_prefs,ttrss_prefs_types | |
3060 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
3061 | ||
3062 | if (db_num_rows($result) > 0) { | |
3063 | ||
3064 | $type_name = db_fetch_result($result, 0, "type_name"); | |
3065 | ||
5da169d9 AD |
3066 | // print "$pref_name : $type_name : $value<br>"; |
3067 | ||
77e96719 | 3068 | if ($type_name == "bool") { |
5da169d9 | 3069 | if ($value == "1") { |
77e96719 AD |
3070 | $value = "true"; |
3071 | } else { | |
3072 | $value = "false"; | |
3073 | } | |
3074 | } else if ($type_name == "integer") { | |
3075 | $value = sprintf("%d", $value); | |
3076 | } | |
3077 | ||
3078 | // print "$pref_name : $type_name : $value<br>"; | |
3079 | ||
ff485f1d AD |
3080 | db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' |
3081 | WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); | |
77e96719 AD |
3082 | |
3083 | } | |
3084 | ||
3085 | header("Location: prefs.php"); | |
3086 | ||
3087 | } | |
3088 | ||
b1895692 AD |
3089 | } else if ($subop == "getHelp") { |
3090 | ||
3091 | $pref_name = db_escape_string($_GET["pn"]); | |
3092 | ||
3093 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
3094 | WHERE pref_name = '$pref_name'"); | |
3095 | ||
3096 | if (db_num_rows($result) > 0) { | |
3097 | $help_text = db_fetch_result($result, 0, "help_text"); | |
3098 | print $help_text; | |
3099 | } else { | |
3100 | print "Unknown option: $pref_name"; | |
3101 | } | |
3102 | ||
cbb01696 AD |
3103 | } else if ($subop == "Change e-mail") { |
3104 | ||
3105 | if (WEB_DEMO_MODE) { | |
3106 | header("Location: prefs.php"); | |
3107 | return; | |
3108 | } | |
3109 | ||
3110 | $email = db_escape_string($_GET["email"]); | |
3111 | $active_uid = $_SESSION["uid"]; | |
3112 | ||
3113 | if ($email) { | |
3114 | db_query($link, "UPDATE ttrss_users SET email = '$email' | |
3115 | WHERE id = '$active_uid'"); | |
3116 | } | |
3117 | ||
3118 | header("Location: prefs.php"); | |
3119 | ||
1c7f75ed AD |
3120 | } else if ($subop == "Change password") { |
3121 | ||
d2892032 AD |
3122 | if (WEB_DEMO_MODE) { |
3123 | header("Location: prefs.php"); | |
3124 | return; | |
3125 | } | |
1c7f75ed AD |
3126 | |
3127 | $old_pw = $_POST["OLD_PASSWORD"]; | |
3128 | $new_pw = $_POST["OLD_PASSWORD"]; | |
3129 | ||
3130 | $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]); | |
3131 | $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]); | |
3132 | ||
3133 | $active_uid = $_SESSION["uid"]; | |
3134 | ||
3135 | if ($old_pw && $new_pw) { | |
3136 | ||
3137 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
3138 | ||
3139 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
3140 | id = '$active_uid' AND (pwd_hash = '$old_pw' OR | |
3141 | pwd_hash = '$old_pw_hash')"); | |
3142 | ||
3143 | if (db_num_rows($result) == 1) { | |
3144 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
3145 | WHERE id = '$active_uid'"); | |
b791095d AD |
3146 | |
3147 | $_SESSION["pwd_change_result"] = "ok"; | |
3148 | } else { | |
3149 | $_SESSION["pwd_change_result"] = "failed"; | |
1c7f75ed AD |
3150 | } |
3151 | } | |
3152 | ||
3153 | header("Location: prefs.php"); | |
b791095d | 3154 | |
77e96719 AD |
3155 | } else if ($subop == "Reset to defaults") { |
3156 | ||
d2892032 AD |
3157 | if (WEB_DEMO_MODE) { |
3158 | header("Location: prefs.php"); | |
3159 | return; | |
3160 | } | |
01d68cf9 | 3161 | |
93cb4442 AD |
3162 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
3163 | ||
e1aa0559 AD |
3164 | if (DB_TYPE == "pgsql") { |
3165 | db_query($link,"UPDATE ttrss_user_prefs | |
3166 | SET value = ttrss_prefs.def_value | |
3167 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
3168 | ttrss_prefs.pref_name = ttrss_user_prefs.pref_name"); | |
3169 | } else { | |
3170 | db_query($link, "DELETE FROM ttrss_user_prefs | |
3171 | WHERE owner_uid = ".$_SESSION["uid"]); | |
3172 | initialize_user_prefs($link, $_SESSION["uid"]); | |
3173 | } | |
5da169d9 | 3174 | |
77e96719 AD |
3175 | header("Location: prefs.php"); |
3176 | ||
58f8ad54 AD |
3177 | } else if ($subop == "Change theme") { |
3178 | ||
3179 | $theme = db_escape_string($_POST["theme"]); | |
3180 | ||
3181 | if ($theme == "Default") { | |
3182 | $theme_qpart = 'NULL'; | |
3183 | } else { | |
3184 | $theme_qpart = "'$theme'"; | |
3185 | } | |
3186 | ||
6752e330 AD |
3187 | $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes |
3188 | WHERE theme_name = '$theme'"); | |
3189 | ||
3190 | if (db_num_rows($result) == 1) { | |
3191 | $theme_id = db_fetch_result($result, 0, "id"); | |
3192 | $theme_path = db_fetch_result($result, 0, "theme_path"); | |
3193 | } else { | |
3194 | $theme_id = "NULL"; | |
3195 | $theme_path = ""; | |
3196 | } | |
3197 | ||
58f8ad54 | 3198 | db_query($link, "UPDATE ttrss_users SET |
6752e330 | 3199 | theme_id = $theme_id WHERE id = " . $_SESSION["uid"]); |
58f8ad54 | 3200 | |
6752e330 | 3201 | $_SESSION["theme"] = $theme_path; |
503eb349 | 3202 | |
58f8ad54 AD |
3203 | header("Location: prefs.php"); |
3204 | ||
77e96719 AD |
3205 | } else { |
3206 | ||
7d4c898a | 3207 | if (!SINGLE_USER_MODE) { |
1c7f75ed | 3208 | |
cbb01696 | 3209 | $result = db_query($link, "SELECT id,email FROM ttrss_users |
a029d530 AD |
3210 | WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR |
3211 | pwd_hash = 'SHA1:".sha1("password")."')"); | |
3212 | ||
3213 | if (db_num_rows($result) != 0) { | |
b791095d | 3214 | print "<div class=\"warning\"> |
a029d530 AD |
3215 | Your password is at default value, please change it. |
3216 | </div>"; | |
3217 | } | |
3218 | ||
b791095d AD |
3219 | if ($_SESSION["pwd_change_result"] == "failed") { |
3220 | print "<div class=\"warning\"> | |
3221 | There was an error while changing your password. | |
3222 | </div>"; | |
3223 | } | |
3224 | ||
3225 | if ($_SESSION["pwd_change_result"] == "ok") { | |
3226 | print "<div class=\"notice\"> | |
3227 | Password changed successfully. | |
3228 | </div>"; | |
3229 | } | |
3230 | ||
3231 | $_SESSION["pwd_change_result"] = ""; | |
3232 | ||
93cb4442 AD |
3233 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { |
3234 | print "<div class=\"notice\"> | |
3235 | Your configuration was reset to defaults. | |
3236 | </div>"; | |
3237 | } | |
3238 | ||
3239 | if ($_SESSION["prefs_op_result"] == "save-config") { | |
3240 | print "<div class=\"notice\"> | |
3241 | Your configuration was saved successfully. | |
3242 | </div>"; | |
3243 | } | |
3244 | ||
3245 | $_SESSION["prefs_op_result"] = ""; | |
3246 | ||
cbb01696 AD |
3247 | print "<form action=\"backend.php\" method=\"GET\">"; |
3248 | ||
3249 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3250 | print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>"; | |
3251 | ||
3252 | $result = db_query($link, "SELECT email FROM ttrss_users | |
3253 | WHERE id = ".$_SESSION["uid"]); | |
3254 | ||
3255 | $email = db_fetch_result($result, 0, "email"); | |
3256 | ||
3257 | print "<tr><td width=\"40%\">E-mail</td>"; | |
3258 | print "<td><input class=\"editbox\" name=\"email\" | |
3259 | value=\"$email\"></td></tr>"; | |
3260 | ||
3261 | print "</table>"; | |
3262 | ||
3263 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3264 | ||
3265 | print "<p><input class=\"button\" type=\"submit\" | |
3266 | value=\"Change e-mail\" name=\"subop\">"; | |
3267 | ||
7d4c898a AD |
3268 | print "<form action=\"backend.php\" method=\"POST\">"; |
3269 | ||
3270 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3271 | print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>"; | |
3272 | ||
3273 | print "<tr><td width=\"40%\">Old password</td>"; | |
3274 | print "<td><input class=\"editbox\" type=\"password\" | |
3275 | name=\"OLD_PASSWORD\"></td></tr>"; | |
3276 | ||
3277 | print "<tr><td width=\"40%\">New password</td>"; | |
3278 | ||
3279 | print "<td><input class=\"editbox\" type=\"password\" | |
3280 | name=\"NEW_PASSWORD\"></td></tr>"; | |
3281 | ||
3282 | print "</table>"; | |
3283 | ||
3284 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3285 | ||
3286 | print "<p><input class=\"button\" type=\"submit\" | |
3287 | value=\"Change password\" name=\"subop\">"; | |
3288 | ||
3289 | print "</form>"; | |
1c7f75ed | 3290 | |
7d4c898a | 3291 | } |
1c7f75ed | 3292 | |
58f8ad54 AD |
3293 | $result = db_query($link, "SELECT |
3294 | theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]); | |
3295 | ||
3296 | $user_theme_id = db_fetch_result($result, 0, "theme_id"); | |
3297 | ||
3298 | $result = db_query($link, "SELECT | |
3299 | id,theme_name FROM ttrss_themes ORDER BY theme_name"); | |
3300 | ||
3301 | if (db_num_rows($result) > 0) { | |
6752e330 AD |
3302 | |
3303 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3304 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3305 | print "<tr><td colspan='3'><h3>Themes</h3></tr></td>"; | |
3306 | print "<tr><td width=\"40%\">Select theme</td>"; | |
3307 | print "<td><select name=\"theme\">"; | |
3308 | print "<option>Default</option>"; | |
58f8ad54 | 3309 | print "<option disabled>--------</option>"; |
6752e330 | 3310 | |
58f8ad54 AD |
3311 | while ($line = db_fetch_assoc($result)) { |
3312 | if ($line["id"] == $user_theme_id) { | |
3313 | $selected = "selected"; | |
3314 | } else { | |
3315 | $selected = ""; | |
3316 | } | |
3317 | print "<option $selected>" . $line["theme_name"] . "</option>"; | |
3318 | } | |
6752e330 AD |
3319 | print "</select></td></tr>"; |
3320 | print "</table>"; | |
3321 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3322 | print "<p><input class=\"button\" type=\"submit\" | |
3323 | value=\"Change theme\" name=\"subop\">"; | |
3324 | print "</form>"; | |
58f8ad54 AD |
3325 | } |
3326 | ||
77e96719 | 3327 | $result = db_query($link, "SELECT |
ff485f1d | 3328 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, |
77e96719 | 3329 | section_name,def_value |
ff485f1d | 3330 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
77e96719 | 3331 | WHERE type_id = ttrss_prefs_types.id AND |
ff485f1d | 3332 | section_id = ttrss_prefs_sections.id AND |
a2411bd9 AD |
3333 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
3334 | owner_uid = ".$_SESSION["uid"]." | |
650bc435 | 3335 | ORDER BY section_id,short_desc"); |
77e96719 AD |
3336 | |
3337 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3338 | ||
77e96719 AD |
3339 | $lnum = 0; |
3340 | ||
3341 | $active_section = ""; | |
3342 | ||
3343 | while ($line = db_fetch_assoc($result)) { | |
3344 | ||
3345 | if ($active_section != $line["section_name"]) { | |
59a654ba AD |
3346 | |
3347 | if ($active_section != "") { | |
1c7f75ed | 3348 | print "</table>"; |
59a654ba | 3349 | } |
1c7f75ed AD |
3350 | |
3351 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
59a654ba AD |
3352 | |
3353 | $active_section = $line["section_name"]; | |
3354 | ||
77e96719 | 3355 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; |
59a654ba AD |
3356 | // print "<tr class=\"title\"> |
3357 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
7268adf7 AD |
3358 | |
3359 | $lnum = 0; | |
77e96719 AD |
3360 | } |
3361 | ||
650bc435 | 3362 | // $class = ($lnum % 2) ? "even" : "odd"; |
77e96719 | 3363 | |
650bc435 | 3364 | print "<tr>"; |
77e96719 | 3365 | |
77e96719 AD |
3366 | $type_name = $line["type_name"]; |
3367 | $pref_name = $line["pref_name"]; | |
3368 | $value = $line["value"]; | |
3369 | $def_value = $line["def_value"]; | |
b1895692 AD |
3370 | $help_text = $line["help_text"]; |
3371 | ||
3372 | print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"]; | |
3373 | ||
3374 | if ($help_text) print "<div class=\"prefHelp\">$help_text</div>"; | |
3375 | ||
3376 | print "</td>"; | |
77e96719 AD |
3377 | |
3378 | print "<td>"; | |
3379 | ||
3380 | if ($type_name == "bool") { | |
3381 | // print_select($pref_name, $value, array("true", "false")); | |
3382 | ||
3383 | if ($value == "true") { | |
3384 | $value = "Yes"; | |
3385 | } else { | |
3386 | $value = "No"; | |
3387 | } | |
3388 | ||
3389 | print_radio($pref_name, $value, array("Yes", "No")); | |
3390 | ||
3391 | } else { | |
3392 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
3393 | } | |
3394 | ||
3395 | print "</td>"; | |
3396 | ||
3397 | print "</tr>"; | |
3398 | ||
3399 | $lnum++; | |
3400 | } | |
3401 | ||
3402 | print "</table>"; | |
3403 | ||
3404 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3405 | ||
3406 | print "<p><input class=\"button\" type=\"submit\" | |
3407 | name=\"subop\" value=\"Save configuration\">"; | |
3408 | ||
3409 | print " <input class=\"button\" type=\"submit\" | |
69668465 AD |
3410 | name=\"subop\" onclick=\"return validatePrefsReset()\" |
3411 | value=\"Reset to defaults\"></p>"; | |
77e96719 AD |
3412 | |
3413 | print "</form>"; | |
3414 | ||
3415 | } | |
3416 | ||
3417 | } | |
3418 | ||
e6cb77a0 AD |
3419 | if ($op == "pref-users") { |
3420 | ||
3421 | $subop = $_GET["subop"]; | |
3422 | ||
3423 | if ($subop == "editSave") { | |
3424 | ||
3425 | if (!WEB_DEMO_MODE) { | |
3426 | ||
3427 | $login = db_escape_string($_GET["l"]); | |
3428 | $uid = db_escape_string($_GET["id"]); | |
3429 | $access_level = sprintf("%d", $_GET["al"]); | |
72932a75 | 3430 | $email = db_escape_string($_GET["e"]); |
e6cb77a0 | 3431 | |
72932a75 AD |
3432 | db_query($link, "UPDATE ttrss_users SET login = '$login', |
3433 | access_level = '$access_level', email = '$email' WHERE id = '$uid'"); | |
e6cb77a0 AD |
3434 | |
3435 | } | |
3436 | } else if ($subop == "remove") { | |
3437 | ||
3438 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3439 | ||
f932bc9f | 3440 | $ids = split(",", db_escape_string($_GET["ids"])); |
e6cb77a0 AD |
3441 | |
3442 | foreach ($ids as $id) { | |
3443 | db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]); | |
3444 | ||
3445 | } | |
3446 | } | |
3447 | } else if ($subop == "add") { | |
3448 | ||
3449 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3450 | ||
b6b535ca | 3451 | $login = db_escape_string(trim($_GET["login"])); |
e6cb77a0 AD |
3452 | $tmp_user_pwd = make_password(8); |
3453 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3454 | ||
3455 | db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level) | |
3456 | VALUES ('$login', '$pwd_hash', 0)"); | |
3457 | ||
3458 | ||
3459 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
3460 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
3461 | ||
3462 | if (db_num_rows($result) == 1) { | |
3463 | ||
3464 | $new_uid = db_fetch_result($result, 0, "id"); | |
3465 | ||
3466 | print "<div class=\"notice\">Added user <b>".$_GET["login"]. | |
3467 | "</b> with password <b>$tmp_user_pwd</b>.</div>"; | |
3468 | ||
3469 | initialize_user($link, $new_uid); | |
3470 | ||
3471 | } else { | |
3472 | ||
3473 | print "<div class=\"warning\">Error while adding user <b>". | |
3474 | $_GET["login"].".</b></div>"; | |
3475 | ||
3476 | } | |
3477 | } | |
3478 | } else if ($subop == "resetPass") { | |
3479 | ||
3480 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3481 | ||
3482 | $uid = db_escape_string($_GET["id"]); | |
3483 | ||
72932a75 AD |
3484 | $result = db_query($link, "SELECT login,email |
3485 | FROM ttrss_users WHERE id = '$uid'"); | |
e6cb77a0 AD |
3486 | |
3487 | $login = db_fetch_result($result, 0, "login"); | |
72932a75 | 3488 | $email = db_fetch_result($result, 0, "email"); |
e6cb77a0 AD |
3489 | $tmp_user_pwd = make_password(8); |
3490 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3491 | ||
3492 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
3493 | WHERE id = '$uid'"); | |
3494 | ||
3495 | print "<div class=\"notice\">Changed password of | |
72932a75 AD |
3496 | user <b>$login</b> to <b>$tmp_user_pwd</b>."; |
3497 | ||
3498 | if (MAIL_RESET_PASS && $email) { | |
3499 | print " Notifying <b>$email</b>."; | |
3500 | ||
3501 | mail("$login <$email>", "Password reset notification", | |
3502 | "Hi, $login.\n". | |
3503 | "\n". | |
3504 | "Your password for this TT-RSS installation was reset by". | |
3505 | " an administrator.\n". | |
3506 | "\n". | |
3507 | "Your new password is $tmp_user_pwd, please remember". | |
3508 | " it for later reference.\n". | |
3509 | "\n". | |
3510 | "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM); | |
3511 | } | |
3512 | ||
3513 | print "</div>"; | |
e6cb77a0 AD |
3514 | |
3515 | } | |
3516 | } | |
3517 | ||
2c7070b5 | 3518 | print "<div class=\"prefGenericAddBox\"> |
f932bc9f | 3519 | <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> "; |
e6cb77a0 | 3520 | |
2c7070b5 AD |
3521 | print"<input type=\"submit\" class=\"button\" |
3522 | onclick=\"javascript:addUser()\" value=\"Add user\"></div>"; | |
e6cb77a0 AD |
3523 | |
3524 | $result = db_query($link, "SELECT | |
72932a75 | 3525 | id,login,access_level,email, |
fe99ab12 | 3526 | SUBSTRING(last_login,1,16) as last_login |
e6cb77a0 AD |
3527 | FROM |
3528 | ttrss_users | |
3529 | ORDER by login"); | |
3530 | ||
2317ffaa | 3531 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
1a7572cb | 3532 | |
f4fe2cde AD |
3533 | print "<p><table width=\"100%\" cellspacing=\"0\" |
3534 | class=\"prefUserList\" id=\"prefUserList\">"; | |
e6cb77a0 | 3535 | |
35f3c923 AD |
3536 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> |
3537 | Select: | |
3538 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', | |
3055bc41 | 3539 | 'UMRR-', 'UMCHK-', true)\">All</a>, |
35f3c923 | 3540 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', |
3055bc41 | 3541 | 'UMRR-', 'UMCHK-', false)\">None</a> |
35f3c923 AD |
3542 | </td</tr>"; |
3543 | ||
e6cb77a0 | 3544 | print "<tr class=\"title\"> |
e325c6e7 | 3545 | <td align='center' width=\"5%\"> </td> |
72932a75 AD |
3546 | <td width='20%'>Username</td> |
3547 | <td width='20%'>E-mail</td> | |
3548 | <td width='20%'>Access Level</td> | |
3549 | <td width='20%'>Last login</td></tr>"; | |
e6cb77a0 AD |
3550 | |
3551 | $lnum = 0; | |
3552 | ||
3553 | while ($line = db_fetch_assoc($result)) { | |
3554 | ||
3555 | $class = ($lnum % 2) ? "even" : "odd"; | |
3556 | ||
3557 | $uid = $line["id"]; | |
3558 | $edit_uid = $_GET["id"]; | |
3559 | ||
4154a415 | 3560 | if ($subop == "edit" && $uid != $edit_uid) { |
e6cb77a0 | 3561 | $class .= "Grayed"; |
53226edc AD |
3562 | $this_row_id = ""; |
3563 | } else { | |
3564 | $this_row_id = "id=\"UMRR-$uid\""; | |
3565 | } | |
3566 | ||
3567 | print "<tr class=\"$class\" $this_row_id>"; | |
e6cb77a0 AD |
3568 | |
3569 | $line["login"] = htmlspecialchars($line["login"]); | |
3570 | ||
6be6bc03 AD |
3571 | $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'), |
3572 | strtotime($line["last_login"])); | |
3573 | ||
72932a75 | 3574 | /* if ($uid == $_SESSION["uid"]) { |
e6cb77a0 | 3575 | |
a426e532 | 3576 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" |
e6cb77a0 AD |
3577 | id=\"UMCHK-".$line["id"]."\"></td>"; |
3578 | ||
72932a75 AD |
3579 | print "<td>".$line["login"]."</td>"; |
3580 | print "<td>".$line["email"]."</td>"; | |
3581 | print "<td>".$line["access_level"]."</td>"; | |
e6cb77a0 | 3582 | |
72932a75 | 3583 | } else */ if (!$edit_uid || $subop != "edit") { |
e6cb77a0 | 3584 | |
a426e532 | 3585 | print "<td align='center'><input onclick='toggleSelectRow(this);' |
1a7572cb | 3586 | type=\"checkbox\" id=\"UMCHK-$uid\"></td>"; |
e6cb77a0 AD |
3587 | |
3588 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
3589 | $line["login"] . "</td>"; | |
72932a75 AD |
3590 | |
3591 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
3592 | $line["email"] . "</td>"; | |
3593 | ||
e6cb77a0 AD |
3594 | print "<td><a href=\"javascript:editUser($uid);\">" . |
3595 | $line["access_level"] . "</td>"; | |
3596 | ||
3597 | } else if ($uid != $edit_uid) { | |
3598 | ||
72932a75 | 3599 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" |
e6cb77a0 AD |
3600 | id=\"UMCHK-".$line["id"]."\"></td>"; |
3601 | ||
3602 | print "<td>".$line["login"]."</td>"; | |
72932a75 | 3603 | print "<td>".$line["email"]."</td>"; |
e6cb77a0 AD |
3604 | print "<td>".$line["access_level"]."</td>"; |
3605 | ||
3606 | } else { | |
3607 | ||
72932a75 AD |
3608 | print "<td align='center'> |
3609 | <input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
e6cb77a0 AD |
3610 | |
3611 | print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"]. | |
3612 | "\"></td>"; | |
3613 | ||
72932a75 AD |
3614 | print "<td><input id=\"iedit_email\" value=\"".$line["email"]. |
3615 | "\"></td>"; | |
3616 | ||
e6cb77a0 AD |
3617 | print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"]. |
3618 | "\"></td>"; | |
3619 | ||
3620 | } | |
3621 | ||
f6f32198 AD |
3622 | print "<td>".$line["last_login"]."</td>"; |
3623 | ||
e6cb77a0 AD |
3624 | print "</tr>"; |
3625 | ||
3626 | ++$lnum; | |
3627 | } | |
3628 | ||
3629 | print "</table>"; | |
3630 | ||
3631 | print "<p>"; | |
3632 | ||
3633 | if ($subop == "edit") { | |
3634 | print "Edit label: | |
3635 | <input type=\"submit\" class=\"button\" | |
3636 | onclick=\"javascript:userEditCancel()\" value=\"Cancel\"> | |
3637 | <input type=\"submit\" class=\"button\" | |
3638 | onclick=\"javascript:userEditSave()\" value=\"Save\">"; | |
3639 | ||
3640 | } else { | |
3641 | ||
3642 | print " | |
3643 | Selection: | |
3644 | <input type=\"submit\" class=\"button\" | |
717f5e64 | 3645 | onclick=\"javascript:selectedUserDetails()\" value=\"User details\"> |
e6cb77a0 AD |
3646 | <input type=\"submit\" class=\"button\" |
3647 | onclick=\"javascript:editSelectedUser()\" value=\"Edit\"> | |
3648 | <input type=\"submit\" class=\"button\" | |
717f5e64 AD |
3649 | onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\"> |
3650 | <input type=\"submit\" class=\"button\" | |
3651 | onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">"; | |
3652 | ||
3653 | } | |
3654 | } | |
3655 | ||
3656 | if ($op == "user-details") { | |
3657 | ||
3658 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { | |
3659 | return; | |
3660 | } | |
3661 | ||
1a7572cb | 3662 | /* print "<html><head> |
717f5e64 AD |
3663 | <title>Tiny Tiny RSS : User Details</title> |
3664 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
3665 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
1a7572cb | 3666 | </head><body>"; */ |
717f5e64 AD |
3667 | |
3668 | $uid = sprintf("%d", $_GET["id"]); | |
3669 | ||
c6c3a07f | 3670 | print "<div class='infoBoxContents'>"; |
717f5e64 | 3671 | |
fe99ab12 AD |
3672 | $result = db_query($link, "SELECT login, |
3673 | SUBSTRING(last_login,1,16) AS last_login, | |
3674 | access_level, | |
c6c3a07f AD |
3675 | (SELECT COUNT(int_id) FROM ttrss_user_entries |
3676 | WHERE owner_uid = id) AS stored_articles | |
717f5e64 AD |
3677 | FROM ttrss_users |
3678 | WHERE id = '$uid'"); | |
3679 | ||
3680 | if (db_num_rows($result) == 0) { | |
3681 | print "<h1>User not found</h1>"; | |
3682 | return; | |
3683 | } | |
3684 | ||
3685 | print "<h1>User Details</h1>"; | |
3686 | ||
3687 | print "<table width='100%'>"; | |
3688 | ||
3689 | $login = db_fetch_result($result, 0, "login"); | |
6be6bc03 AD |
3690 | $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'), |
3691 | strtotime(db_fetch_result($result, 0, "last_login"))); | |
717f5e64 | 3692 | $access_level = db_fetch_result($result, 0, "access_level"); |
c6c3a07f | 3693 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); |
717f5e64 AD |
3694 | |
3695 | print "<tr><td>Username</td><td>$login</td></tr>"; | |
3696 | print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
3697 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
c6c3a07f | 3698 | print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>"; |
717f5e64 AD |
3699 | |
3700 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
3701 | WHERE owner_uid = '$uid'"); | |
3702 | ||
3703 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
3704 | ||
3705 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; | |
3706 | ||
5d15d3ea | 3707 | /* $result = db_query($link, "SELECT |
717f5e64 | 3708 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size |
c6c3a07f AD |
3709 | FROM ttrss_user_entries,ttrss_entries |
3710 | WHERE owner_uid = '$uid' AND ref_id = id"); | |
717f5e64 | 3711 | |
d9f115c3 | 3712 | $db_size = round(db_fetch_result($result, 0, "db_size") / 1024); |
717f5e64 | 3713 | |
c6c3a07f | 3714 | print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */ |
717f5e64 AD |
3715 | |
3716 | print "</table>"; | |
3717 | ||
3718 | print "<h1>Subscribed feeds</h1>"; | |
3719 | ||
e94645ca | 3720 | $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds |
9b3e2cc7 | 3721 | WHERE owner_uid = '$uid' ORDER BY title"); |
717f5e64 | 3722 | |
9b3e2cc7 | 3723 | print "<ul class=\"userFeedList\">"; |
717f5e64 AD |
3724 | |
3725 | while ($line = db_fetch_assoc($result)) { | |
3726 | ||
3727 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
3728 | ||
3729 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
6c56687e | 3730 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; |
717f5e64 | 3731 | } else { |
5951ded1 | 3732 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; |
717f5e64 AD |
3733 | } |
3734 | ||
e94645ca | 3735 | print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; |
e6cb77a0 | 3736 | } |
717f5e64 | 3737 | |
a88c1f36 AD |
3738 | if (db_num_rows($result) < $num_feeds) { |
3739 | // FIXME - add link to show ALL subscribed feeds here somewhere | |
3740 | print "<li><img | |
3741 | class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>"; | |
3742 | } | |
3743 | ||
717f5e64 AD |
3744 | print "</ul>"; |
3745 | ||
717f5e64 AD |
3746 | print "</div>"; |
3747 | ||
1a7572cb AD |
3748 | print "<div align='center'> |
3749 | <input type='submit' class='button' | |
c6c3a07f | 3750 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; |
1a7572cb AD |
3751 | |
3752 | // print "</body></html>"; | |
717f5e64 | 3753 | |
e6cb77a0 AD |
3754 | } |
3755 | ||
c6c3a07f AD |
3756 | if ($op == "feed-details") { |
3757 | ||
df268d47 | 3758 | // $feed_id = $_GET["id"]; |
4fec9fd7 | 3759 | |
df268d47 | 3760 | $feed_ids = split(",", db_escape_string($_GET["id"])); |
c6c3a07f | 3761 | |
df268d47 | 3762 | print "<div class=\"infoBoxContents\">"; |
bca02305 | 3763 | |
df268d47 | 3764 | foreach ($feed_ids as $feed_id) { |
c6c3a07f | 3765 | |
df268d47 AD |
3766 | $result = db_query($link, |
3767 | "SELECT | |
3768 | title,feed_url, | |
3769 | SUBSTRING(last_updated,1,16) as last_updated, | |
3770 | icon_url,site_url, | |
3771 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3772 | WHERE feed_id = id) AS total, | |
3773 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3774 | WHERE feed_id = id AND unread = true) AS unread, | |
3775 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
3776 | WHERE feed_id = id AND marked = true) AS marked | |
3777 | FROM ttrss_feeds | |
3778 | WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]); | |
3779 | ||
3780 | if (db_num_rows($result) == 0) return; | |
3781 | ||
3782 | $title = db_unescape_string(db_fetch_result($result, 0, "title")); | |
3783 | $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
3784 | strtotime(db_fetch_result($result, 0, "last_updated"))); | |
3785 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
3786 | $icon_url = db_fetch_result($result, 0, "icon_url"); | |
3787 | $total = db_fetch_result($result, 0, "total"); | |
3788 | $unread = db_fetch_result($result, 0, "unread"); | |
3789 | $marked = db_fetch_result($result, 0, "marked"); | |
3790 | $site_url = db_fetch_result($result, 0, "site_url"); | |
bca02305 | 3791 | |
df268d47 AD |
3792 | $result = db_query($link, "SELECT COUNT(id) AS subscribed |
3793 | FROM ttrss_feeds WHERE feed_url = '$feed_url'"); | |
3794 | ||
3795 | $subscribed = db_fetch_result($result, 0, "subscribed"); | |
3796 | ||
3797 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
3798 | ||
3799 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
3800 | $feed_icon = "<img width=\"16\" height=\"16\" | |
3801 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
3802 | } else { | |
3803 | $feed_icon = ""; | |
bca02305 AD |
3804 | } |
3805 | ||
df268d47 | 3806 | print "<h1>$feed_icon $title</h1>"; |
bca02305 | 3807 | |
df268d47 | 3808 | print "<table width='100%'>"; |
bca02305 | 3809 | |
df268d47 AD |
3810 | if ($site_url) { |
3811 | print "<tr><td width='30%'>Link</td> | |
3812 | <td><a href=\"$site_url\">$site_url</a> | |
3813 | <a href=\"$feed_url\">(feed)</a></td> | |
3814 | </td></tr>"; | |
3815 | } else { | |
3816 | print "<tr><td width='30%'>Feed URL</td> | |
3817 | <td><a href=\"$feed_url\">$feed_url</a></td></tr>"; | |
3818 | } | |
3819 | print "<tr><td>Last updated</td><td>$last_updated</td></tr>"; | |
3820 | print "<tr><td>Total articles</td><td>$total</td></tr>"; | |
3821 | print "<tr><td>Unread articles</td><td>$unread</td></tr>"; | |
3822 | print "<tr><td>Starred articles</td><td>$marked</td></tr>"; | |
3823 | print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>"; | |
3824 | ||
3825 | print "</table>"; | |
3826 | ||
3827 | /* $result = db_query($link, "SELECT title, | |
3828 | SUBSTRING(updated,1,16) AS updated,unread | |
3829 | FROM ttrss_entries,ttrss_user_entries | |
3830 | WHERE ref_id = id AND feed_id = '$feed_id' | |
3831 | ORDER BY date_entered DESC LIMIT 5"); | |
3832 | ||
3833 | if (db_num_rows($result) > 0) { | |
3834 | ||
3835 | print "<h1>Latest headlines</h1>"; | |
3836 | ||
3837 | print "<ul class=\"nomarks\">"; | |
3838 | ||
3839 | while ($line = db_fetch_assoc($result)) { | |
3840 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
3841 | $line["title"] = "<b>" . $line["title"] . "</b>"; | |
3842 | } | |
3843 | print "<li>" . $line["title"]. | |
3844 | " <span class=\"insensitive\">(" . | |
3845 | date(get_pref($link, 'SHORT_DATE_FORMAT'), | |
3846 | strtotime($line["updated"])). | |
3847 | ")</span></li>"; | |
3848 | } | |
3849 | ||
3850 | print "</ul>"; | |
3851 | ||
3852 | } */ | |
bca02305 | 3853 | } |
df268d47 AD |
3854 | |
3855 | print "</div>"; | |
3856 | ||
3857 | print "<div align='center'> | |
3858 | <input type='submit' class='button' | |
3859 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
3860 | } | |
c6c3a07f | 3861 | |
4b3dff6e | 3862 | db_close($link); |
1cd17194 | 3863 | ?> |
406d9489 AD |
3864 | |
3865 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
3866 |