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