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