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