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