]>
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 | |
8143ae1f AD |
58 | /* FIXME this needs reworking */ |
59 | ||
fc69e641 | 60 | function getGlobalCounters($link) { |
4c193675 AD |
61 | $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries |
62 | WHERE unread = true AND | |
63 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
64 | owner_uid = " . $_SESSION["uid"]); | |
fc69e641 AD |
65 | $c_id = db_fetch_result($result, 0, "c_id"); |
66 | print "<counter id='global-unread' counter='$c_id'/>"; | |
67 | } | |
68 | ||
8143ae1f | 69 | function getTagCounters($link) { |
05732aa0 | 70 | |
8143ae1f | 71 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count |
4c193675 AD |
72 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE |
73 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
4356293a | 74 | ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND |
05732aa0 | 75 | post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name |
8143ae1f | 76 | UNION |
4356293a AD |
77 | select tag_name,0 as count FROM ttrss_tags |
78 | WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); | |
8143ae1f AD |
79 | |
80 | $tags = array(); | |
81 | ||
82 | while ($line = db_fetch_assoc($result)) { | |
83 | $tags[$line["tag_name"]] += $line["count"]; | |
84 | } | |
85 | ||
86 | foreach (array_keys($tags) as $tag) { | |
87 | $unread = $tags[$tag]; | |
88 | ||
89 | $tag = htmlspecialchars($tag); | |
90 | print "<tag id=\"$tag\" counter=\"$unread\"/>"; | |
91 | } | |
92 | } | |
93 | ||
090e250b AD |
94 | function getLabelCounters($link) { |
95 | ||
4c193675 AD |
96 | $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries |
97 | WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND | |
98 | unread = true AND owner_uid = ".$_SESSION["uid"]); | |
090e250b | 99 | |
d61fd764 | 100 | $count = db_fetch_result($result, 0, "count"); |
090e250b AD |
101 | |
102 | print "<label id=\"-1\" counter=\"$count\"/>"; | |
103 | ||
4356293a AD |
104 | $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM |
105 | ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); | |
090e250b AD |
106 | |
107 | while ($line = db_fetch_assoc($result)) { | |
108 | ||
109 | $id = -$line["id"] - 11; | |
110 | ||
111 | error_reporting (0); | |
d61fd764 | 112 | |
4c193675 | 113 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries |
655be073 | 114 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND |
4c193675 | 115 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
655be073 | 116 | owner_uid = ".$_SESSION["uid"]); |
090e250b | 117 | |
d61fd764 | 118 | $count = db_fetch_result($tmp_result, 0, "count"); |
090e250b | 119 | |
ab3f3f72 | 120 | print "<label id=\"$id\" counter=\"$count\"/>"; |
090e250b | 121 | |
cce28758 | 122 | error_reporting (DEFAULT_ERROR_LEVEL); |
090e250b AD |
123 | |
124 | } | |
125 | } | |
126 | ||
8073cce7 AD |
127 | function getFeedCounter($link, $id) { |
128 | ||
129 | $result = db_query($link, "SELECT | |
4c193675 AD |
130 | count(id) as count FROM ttrss_entries,ttrss_user_entries |
131 | WHERE feed_id = '$id' AND unread = true | |
132 | AND ttrss_user_entries.ref_id = ttrss_entries.id"); | |
8073cce7 AD |
133 | |
134 | $count = db_fetch_result($result, 0, "count"); | |
135 | ||
136 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
137 | } | |
090e250b | 138 | |
8073cce7 AD |
139 | function getFeedCounters($link) { |
140 | ||
090e250b | 141 | $result = db_query($link, "SELECT id, |
4c193675 AD |
142 | (SELECT count(id) |
143 | FROM ttrss_entries,ttrss_user_entries | |
144 | WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id | |
b88917af | 145 | AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count |
4356293a | 146 | FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); |
090e250b AD |
147 | |
148 | while ($line = db_fetch_assoc($result)) { | |
149 | ||
150 | $id = $line["id"]; | |
151 | $count = $line["count"]; | |
152 | ||
153 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
154 | } | |
155 | } | |
156 | ||
8143ae1f | 157 | function outputFeedList($link, $tags = false) { |
175847de | 158 | |
1a66d16e AD |
159 | print "<html><head> |
160 | <title>Tiny Tiny RSS : Feedlist</title> | |
430bf183 AD |
161 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; |
162 | ||
4769ddaf | 163 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { |
430bf183 AD |
164 | print "<link rel=\"stylesheet\" type=\"text/css\" |
165 | href=\"tt-rss_compact.css\"/>"; | |
166 | } else { | |
167 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
168 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
169 | } | |
170 | ||
171 | print "<script type=\"text/javascript\" src=\"functions.js\"></script> | |
1a66d16e AD |
172 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> |
173 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
3745788e | 174 | </head><body onload=\"init()\">"; |
254e0e4b AD |
175 | |
176 | print "<ul class=\"feedList\" id=\"feedList\">"; | |
177 | ||
4356293a AD |
178 | $owner_uid = $_SESSION["uid"]; |
179 | ||
8143ae1f | 180 | if (!$tags) { |
254e0e4b | 181 | |
8143ae1f | 182 | /* virtual feeds */ |
254e0e4b | 183 | |
91ff844a AD |
184 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
185 | print "<li class=\"feedCat\">Special</li>"; | |
703b632e | 186 | print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; |
91ff844a AD |
187 | } |
188 | ||
8143ae1f | 189 | $result = db_query($link, "SELECT count(id) as num_starred |
4c193675 AD |
190 | FROM ttrss_entries,ttrss_user_entries |
191 | WHERE marked = true AND | |
192 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
193 | unread = true AND owner_uid = '$owner_uid'"); | |
8143ae1f | 194 | $num_starred = db_fetch_result($result, 0, "num_starred"); |
254e0e4b | 195 | |
3745788e | 196 | $class = "virt"; |
8add756a AD |
197 | |
198 | if ($num_starred > 0) $class .= "Unread"; | |
199 | ||
200 | printFeedEntry(-1, $class, "Starred articles", $num_starred, | |
4668523d | 201 | "images/mark_set.png", $link); |
48f0adb0 | 202 | |
91ff844a | 203 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
703b632e | 204 | print "</li></ul>"; |
91ff844a AD |
205 | } |
206 | ||
4769ddaf | 207 | if (get_pref($link, 'ENABLE_LABELS')) { |
8143ae1f AD |
208 | |
209 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
4356293a | 210 | ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); |
8143ae1f AD |
211 | |
212 | if (db_num_rows($result) > 0) { | |
91ff844a AD |
213 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
214 | print "<li class=\"feedCat\">Labels</li>"; | |
703b632e | 215 | print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; |
91ff844a AD |
216 | } else { |
217 | print "<li><hr></li>"; | |
218 | } | |
8143ae1f AD |
219 | } |
220 | ||
221 | while ($line = db_fetch_assoc($result)) { | |
48f0adb0 | 222 | |
8143ae1f AD |
223 | error_reporting (0); |
224 | ||
4c193675 AD |
225 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries |
226 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND | |
227 | ttrss_user_entries.ref_id = ttrss_entries.id | |
655be073 | 228 | AND owner_uid = '$owner_uid'"); |
8143ae1f AD |
229 | |
230 | $count = db_fetch_result($tmp_result, 0, "count"); | |
231 | ||
3745788e | 232 | $class = "label"; |
8143ae1f AD |
233 | |
234 | if ($count > 0) { | |
235 | $class .= "Unread"; | |
236 | } | |
237 | ||
cce28758 | 238 | error_reporting (DEFAULT_ERROR_LEVEL); |
8143ae1f AD |
239 | |
240 | printFeedEntry(-$line["id"]-11, | |
4668523d | 241 | $class, $line["description"], $count, "images/label.png", $link); |
8143ae1f AD |
242 | |
243 | } | |
91ff844a AD |
244 | |
245 | if (db_num_rows($result) > 0) { | |
246 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
703b632e | 247 | print "</li></ul>"; |
91ff844a AD |
248 | } |
249 | } | |
250 | ||
251 | } | |
252 | ||
253 | // if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
254 | print "<li><hr></li>"; | |
255 | // } | |
256 | ||
257 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
258 | $order_by_qpart = "category,title"; | |
259 | } else { | |
260 | $order_by_qpart = "title"; | |
48f0adb0 | 261 | } |
8143ae1f AD |
262 | |
263 | $result = db_query($link, "SELECT *, | |
4c193675 AD |
264 | (SELECT count(id) FROM ttrss_entries,ttrss_user_entries |
265 | WHERE feed_id = ttrss_feeds.id AND | |
266 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
267 | owner_uid = '$owner_uid') AS total, | |
268 | (SELECT count(id) FROM ttrss_entries,ttrss_user_entries | |
b88917af | 269 | WHERE feed_id = ttrss_feeds.id AND unread = true |
4c193675 | 270 | AND ttrss_user_entries.ref_id = ttrss_entries.id |
91ff844a AD |
271 | AND owner_uid = '$owner_uid') as unread, |
272 | (SELECT title FROM ttrss_feed_categories | |
273 | WHERE id = cat_id) AS category | |
274 | FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart"); | |
8143ae1f AD |
275 | |
276 | $actid = $_GET["actid"]; | |
277 | ||
278 | /* real feeds */ | |
279 | ||
280 | $lnum = 0; | |
281 | ||
282 | $total_unread = 0; | |
91ff844a AD |
283 | |
284 | $category = ""; | |
8143ae1f | 285 | |
48f0adb0 | 286 | while ($line = db_fetch_assoc($result)) { |
8143ae1f AD |
287 | |
288 | $feed = $line["title"]; | |
289 | $feed_id = $line["id"]; | |
290 | ||
291 | $subop = $_GET["subop"]; | |
292 | ||
293 | $total = $line["total"]; | |
294 | $unread = $line["unread"]; | |
91ff844a AD |
295 | |
296 | $tmp_category = $line["category"]; | |
297 | ||
298 | if (!$tmp_category) { | |
299 | $tmp_category = "Uncategorized"; | |
300 | } | |
8143ae1f AD |
301 | |
302 | // $class = ($lnum % 2) ? "even" : "odd"; | |
48f0adb0 | 303 | |
3745788e | 304 | $class = "feed"; |
8143ae1f AD |
305 | |
306 | if ($unread > 0) $class .= "Unread"; | |
307 | ||
308 | if ($actid == $feed_id) { | |
309 | $class .= "Selected"; | |
392d4563 | 310 | } |
48f0adb0 | 311 | |
8143ae1f | 312 | $total_unread += $unread; |
91ff844a AD |
313 | |
314 | if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) { | |
315 | ||
316 | if ($category) { | |
317 | print "</li></ul></li>"; | |
318 | } | |
319 | ||
320 | $category = $tmp_category; | |
321 | ||
322 | print "<li class=\"feedCat\">$category</li>"; | |
703b632e | 323 | print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; |
91ff844a | 324 | } |
8143ae1f | 325 | |
91ff844a AD |
326 | printFeedEntry($feed_id, $class, $feed, $unread, |
327 | "icons/$feed_id.ico", $link); | |
8143ae1f AD |
328 | |
329 | ++$lnum; | |
48f0adb0 | 330 | } |
91ff844a | 331 | |
8143ae1f | 332 | } else { |
a1a8a2be | 333 | |
8143ae1f | 334 | // tags |
a1a8a2be | 335 | |
8143ae1f | 336 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count |
05732aa0 AD |
337 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE |
338 | post_int_id = ttrss_user_entries.int_id AND | |
339 | unread = true AND ref_id = ttrss_entries.id | |
3b0948c4 | 340 | AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name |
8143ae1f | 341 | UNION |
3b0948c4 AD |
342 | select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid' |
343 | ORDER BY tag_name"); | |
8143ae1f AD |
344 | |
345 | $tags = array(); | |
346 | ||
347 | while ($line = db_fetch_assoc($result)) { | |
348 | $tags[$line["tag_name"]] += $line["count"]; | |
1a66d16e | 349 | } |
8143ae1f AD |
350 | |
351 | foreach (array_keys($tags) as $tag) { | |
352 | ||
353 | $unread = $tags[$tag]; | |
354 | ||
355 | $class = "odd"; | |
356 | ||
357 | if ($unread > 0) { | |
358 | $class .= "Unread"; | |
359 | } | |
360 | ||
4668523d | 361 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); |
8143ae1f AD |
362 | |
363 | } | |
1a66d16e | 364 | |
e828e31e | 365 | } |
82baad4a | 366 | |
dc33ec95 | 367 | if (db_num_rows($result) == 0) { |
8037c618 AD |
368 | if ($tags) { |
369 | $what = "tags"; | |
370 | } else { | |
371 | $what = "feeds"; | |
372 | } | |
373 | print "<li>No $what to display.</li>"; | |
dc33ec95 AD |
374 | } |
375 | ||
8143ae1f | 376 | print "</ul>"; |
1cd17194 | 377 | |
caa4e57f AD |
378 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; |
379 | ||
c3b81db0 AD |
380 | } |
381 | ||
382 | ||
383 | if ($op == "rpc") { | |
384 | ||
385 | $subop = $_GET["subop"]; | |
386 | ||
090e250b | 387 | if ($subop == "getLabelCounters") { |
8073cce7 | 388 | $aid = $_GET["aid"]; |
090e250b AD |
389 | print "<rpc-reply>"; |
390 | getLabelCounters($link); | |
8073cce7 AD |
391 | if ($aid) { |
392 | getFeedCounter($link, $aid); | |
393 | } | |
090e250b AD |
394 | print "</rpc-reply>"; |
395 | } | |
396 | ||
397 | if ($subop == "getFeedCounters") { | |
398 | print "<rpc-reply>"; | |
399 | getFeedCounters($link); | |
400 | print "</rpc-reply>"; | |
401 | } | |
402 | ||
403 | if ($subop == "getAllCounters") { | |
404 | print "<rpc-reply>"; | |
405 | getLabelCounters($link); | |
406 | getFeedCounters($link); | |
8143ae1f | 407 | getTagCounters($link); |
fc69e641 | 408 | getGlobalCounters($link); |
090e250b | 409 | print "</rpc-reply>"; |
090e250b AD |
410 | } |
411 | ||
f4c10d44 AD |
412 | if ($subop == "mark") { |
413 | $mark = $_GET["mark"]; | |
648472a7 | 414 | $id = db_escape_string($_GET["id"]); |
f4c10d44 AD |
415 | |
416 | if ($mark == "1") { | |
417 | $mark = "true"; | |
418 | } else { | |
419 | $mark = "false"; | |
420 | } | |
421 | ||
b5137506 AD |
422 | // FIXME this needs collision testing |
423 | ||
424 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
425 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
f4c10d44 AD |
426 | } |
427 | ||
caa4e57f | 428 | if ($subop == "updateFeed") { |
648472a7 | 429 | $feed_id = db_escape_string($_GET["feed"]); |
9cfc649a | 430 | |
648472a7 | 431 | $result = db_query($link, |
a5873b2e AD |
432 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id' |
433 | AND owner_uid = " . $_SESSION["uid"]); | |
9cfc649a | 434 | |
648472a7 AD |
435 | if (db_num_rows($result) > 0) { |
436 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
a5873b2e | 437 | update_rss_feed($link, $feed_url, $feed_id); |
caa4e57f | 438 | } |
9cfc649a | 439 | |
a5873b2e AD |
440 | print "<rpc-reply>"; |
441 | getFeedCounter($link, $feed_id); | |
442 | print "</rpc-reply>"; | |
443 | ||
caa4e57f | 444 | return; |
9cfc649a AD |
445 | } |
446 | ||
090e250b | 447 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { |
c5142cca | 448 | |
05732aa0 | 449 | update_all_feeds($link, $subop == "forceUpdateAllFeeds"); |
c3b81db0 | 450 | |
ab3f3f72 AD |
451 | $omode = $_GET["omode"]; |
452 | ||
453 | if (!$omode) $omode = "tfl"; | |
454 | ||
090e250b | 455 | print "<rpc-reply>"; |
ab3f3f72 AD |
456 | if (strchr($omode, "l")) getLabelCounters($link); |
457 | if (strchr($omode, "f")) getFeedCounters($link); | |
458 | if (strchr($omode, "t")) getTagCounters($link); | |
fc69e641 | 459 | getGlobalCounters($link); |
090e250b | 460 | print "</rpc-reply>"; |
c3b81db0 AD |
461 | } |
462 | ||
b018b49b | 463 | if ($subop == "catchupSelected") { |
c3b81db0 AD |
464 | |
465 | $ids = split(",", $_GET["ids"]); | |
466 | ||
467 | foreach ($ids as $id) { | |
468 | ||
b018b49b AD |
469 | db_query($link, "UPDATE ttrss_user_entries SET unread=false,last_read = NOW() |
470 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
c3b81db0 AD |
471 | |
472 | } | |
473 | ||
474 | print "Marked active page as read."; | |
475 | } | |
295f9b42 AD |
476 | |
477 | if ($subop == "sanityCheck") { | |
478 | ||
479 | $error_code = 0; | |
480 | ||
481 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
482 | ||
483 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
484 | ||
485 | if ($schema_version != SCHEMA_VERSION) { | |
486 | $error_code = 5; | |
487 | } | |
488 | ||
262bd8ea | 489 | print "<error error-code='$error_code'/>"; |
295f9b42 | 490 | } |
fefa6ca3 AD |
491 | |
492 | if ($subop == "globalPurge") { | |
493 | ||
494 | print "<rpc-reply>"; | |
495 | global_purge_old_posts($link, true); | |
496 | print "</rpc-reply>"; | |
497 | ||
498 | } | |
499 | ||
c3b81db0 AD |
500 | } |
501 | ||
502 | if ($op == "feeds") { | |
503 | ||
8143ae1f AD |
504 | $tags = $_GET["tags"]; |
505 | ||
c3b81db0 AD |
506 | $subop = $_GET["subop"]; |
507 | ||
508 | if ($subop == "catchupAll") { | |
b018b49b | 509 | db_query($link, "UPDATE ttrss_user_entries SET |
6d15e1ef | 510 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); |
c3b81db0 AD |
511 | } |
512 | ||
8143ae1f | 513 | outputFeedList($link, $tags); |
c3b81db0 | 514 | |
1cd17194 AD |
515 | } |
516 | ||
517 | if ($op == "view") { | |
518 | ||
d76a3b03 | 519 | $id = $_GET["id"]; |
8073cce7 | 520 | $feed_id = $_GET["feed"]; |
d76a3b03 | 521 | |
4c193675 AD |
522 | $result = db_query($link, "UPDATE ttrss_user_entries |
523 | SET unread = false,last_read = NOW() | |
524 | WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
a1a8a2be | 525 | |
70830c87 AD |
526 | $addheader = $_GET["addheader"]; |
527 | ||
21703604 AD |
528 | $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id, |
529 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url | |
4c193675 AD |
530 | FROM ttrss_entries,ttrss_user_entries |
531 | WHERE id = '$id' AND ref_id = id"); | |
1cd17194 | 532 | |
70830c87 | 533 | if ($addheader) { |
f0601b87 | 534 | print "<html><head> |
70830c87 AD |
535 | <title>Tiny Tiny RSS : Article $id</title> |
536 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
c05608c2 | 537 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
70830c87 | 538 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
f0601b87 | 539 | </head><body>"; |
70830c87 AD |
540 | } |
541 | ||
d76a3b03 | 542 | if ($result) { |
1cd17194 | 543 | |
648472a7 | 544 | $line = db_fetch_assoc($result); |
1cd17194 | 545 | |
b7f4bda2 AD |
546 | if ($line["icon_url"]) { |
547 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
548 | } else { | |
549 | $feed_icon = " "; | |
550 | } | |
d76a3b03 | 551 | |
f7181e9b AD |
552 | if ($line["comments"] && $line["link"] != $line["comments"]) { |
553 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
554 | } else { | |
555 | $entry_comments = ""; | |
556 | } | |
557 | ||
e828e31e AD |
558 | print "<div class=\"postReply\">"; |
559 | ||
21703604 AD |
560 | print "<div class=\"postHeader\"><table width=\"100%\">"; |
561 | ||
562 | print "<tr><td width='5%'><b>Title:</b></td> | |
563 | <td colspan='2'>" . $line["title"] . "</td></tr>"; | |
564 | ||
565 | $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM | |
566 | ttrss_tags WHERE post_int_id = " . $line["int_id"] . " | |
567 | ORDER BY tag_name"); | |
568 | ||
569 | $tags_str = ""; | |
570 | ||
571 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
572 | $tag = $tmp_line["tag_name"]; | |
573 | $tags_str .= "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a> / "; | |
574 | } | |
575 | ||
576 | $tags_str = preg_replace("/ \/ $/", "", $tags_str); | |
e828e31e | 577 | |
e828e31e | 578 | print "<tr><td><b>Link:</b></td> |
21703604 | 579 | <td width='50%'> |
f7181e9b | 580 | <a href=\"" . $line["link"] . "\">".$line["link"]."</a> |
21703604 AD |
581 | $entry_comments</td> |
582 | <td align=\"right\">$tags_str</td></tr>"; | |
583 | ||
584 | /* if ($tags_str) { | |
585 | print "<tr><td><b>Tags:</b></td> | |
586 | <td width='100%'>$tags_str</td></tr>"; | |
587 | } */ | |
588 | ||
e828e31e AD |
589 | print "</table></div>"; |
590 | ||
591 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
592 | print "<div class=\"postContent\">" . $line["content"] . "</div>"; | |
593 | ||
594 | print "</div>"; | |
595 | ||
090e250b | 596 | print "<script type=\"text/javascript\"> |
8143ae1f | 597 | update_label_counters('$feed_id'); |
090e250b | 598 | </script>"; |
d76a3b03 | 599 | } |
70830c87 AD |
600 | |
601 | if ($addheader) { | |
602 | print "</body></html>"; | |
603 | } | |
1cd17194 AD |
604 | } |
605 | ||
606 | if ($op == "viewfeed") { | |
607 | ||
608 | $feed = $_GET["feed"]; | |
d76a3b03 | 609 | $skip = $_GET["skip"]; |
476cac42 | 610 | $subop = $_GET["subop"]; |
f175937c | 611 | $view_mode = $_GET["view"]; |
f0601b87 | 612 | $addheader = $_GET["addheader"]; |
cb1083a1 | 613 | $limit = $_GET["limit"]; |
a1a8a2be | 614 | |
8d7008c7 | 615 | if (!$feed) { |
8d7008c7 AD |
616 | return; |
617 | } | |
618 | ||
ac53063a AD |
619 | if (!$skip) $skip = 0; |
620 | ||
476cac42 | 621 | if ($subop == "undefined") $subop = ""; |
1cd17194 | 622 | |
f0601b87 AD |
623 | if ($addheader) { |
624 | print "<html><head> | |
ac43eba1 | 625 | <title>Tiny Tiny RSS : Feed $feed</title> |
430bf183 AD |
626 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; |
627 | ||
4769ddaf | 628 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { |
430bf183 AD |
629 | print "<link rel=\"stylesheet\" |
630 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
631 | ||
632 | } else { | |
633 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
634 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
635 | } | |
636 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
f0601b87 AD |
637 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
638 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
b623b3ed | 639 | </head><body onload='init()'>"; |
f0601b87 AD |
640 | } |
641 | ||
dcee8f61 AD |
642 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { |
643 | ||
644 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
645 | WHERE id = '$feed'"); | |
646 | ||
647 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
648 | ||
649 | update_rss_feed($link, $feed_url, $feed); | |
650 | ||
651 | } | |
652 | ||
0e32076b | 653 | if ($subop == "MarkAllRead") { |
d76a3b03 | 654 | |
0e32076b AD |
655 | if (sprintf("%d", $feed) != 0) { |
656 | ||
657 | if ($feed > 0) { | |
f23a2177 | 658 | db_query($link, "UPDATE ttrss_user_entries |
0e32076b | 659 | SET unread = false,last_read = NOW() |
f23a2177 | 660 | WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]); |
0e32076b AD |
661 | |
662 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
663 | ||
664 | if ($feed == -1) { | |
f23a2177 | 665 | db_query($link, "UPDATE ttrss_user_entries |
0e32076b | 666 | SET unread = false,last_read = NOW() |
5859be02 | 667 | WHERE marked = true AND owner_uid = ".$_SESSION["uid"]); |
0e32076b AD |
668 | } |
669 | ||
670 | } else if ($feed < -10) { // label | |
671 | ||
f23a2177 AD |
672 | // TODO make this more efficient |
673 | ||
7db95187 | 674 | $label_id = -$feed - 11; |
0e32076b | 675 | |
7db95187 | 676 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels |
f23a2177 | 677 | WHERE id = '$label_id'"); |
7db95187 AD |
678 | |
679 | if ($tmp_result) { | |
680 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
681 | ||
f23a2177 AD |
682 | db_query($link, "BEGIN"); |
683 | ||
684 | $tmp2_result = db_query($link, | |
685 | "SELECT | |
686 | int_id | |
687 | FROM | |
688 | ttrss_user_entries,ttrss_entries | |
689 | WHERE | |
690 | ref_id = id AND | |
691 | $sql_exp AND | |
692 | owner_uid = " . $_SESSION["uid"]); | |
693 | ||
694 | while ($tmp_line = db_fetch_assoc($tmp2_result)) { | |
695 | db_query($link, "UPDATE | |
696 | ttrss_user_entries | |
697 | SET | |
698 | unread = false, last_read = NOW() | |
699 | WHERE | |
700 | int_id = " . $tmp_line["int_id"]); | |
701 | } | |
702 | ||
703 | db_query($link, "COMMIT"); | |
704 | ||
705 | /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries | |
7db95187 | 706 | SET unread = false,last_read = NOW() |
f23a2177 AD |
707 | WHERE $sql_exp |
708 | AND ref_id = id | |
709 | AND owner_uid = ".$_SESSION["uid"]); */ | |
7db95187 | 710 | } |
254e0e4b | 711 | } |
0e32076b | 712 | } else { // tag |
7eec90cf AD |
713 | db_query($link, "BEGIN"); |
714 | ||
715 | $tag_name = db_escape_string($feed); | |
716 | ||
717 | $result = db_query($link, "SELECT post_int_id FROM ttrss_tags | |
718 | WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]); | |
719 | ||
720 | while ($line = db_fetch_assoc($result)) { | |
721 | db_query($link, "UPDATE ttrss_user_entries SET | |
722 | unread = false, last_read = NOW() | |
723 | WHERE int_id = " . $line["post_int_id"]); | |
724 | } | |
725 | db_query($link, "COMMIT"); | |
a1a8a2be | 726 | } |
0e32076b | 727 | |
a1a8a2be | 728 | } |
d76a3b03 | 729 | |
175847de | 730 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 731 | |
c374a3fe AD |
732 | $search = $_GET["search"]; |
733 | ||
52b51244 AD |
734 | $search_mode = $_GET["smode"]; |
735 | ||
f175937c | 736 | if ($search) { |
ac53063a AD |
737 | $search_query_part = "(upper(title) LIKE upper('%$search%') |
738 | OR content LIKE '%$search%') AND"; | |
f175937c AD |
739 | } else { |
740 | $search_query_part = ""; | |
741 | } | |
742 | ||
743 | $view_query_part = ""; | |
744 | ||
745 | if ($view_mode == "Starred") { | |
746 | $view_query_part = " marked = true AND "; | |
ac53063a AD |
747 | } |
748 | ||
ac43eba1 AD |
749 | if ($view_mode == "Unread") { |
750 | $view_query_part = " unread = true AND "; | |
751 | } | |
752 | ||
b5aa95e7 AD |
753 | if ($view_mode == "Unread or Starred") { |
754 | $view_query_part = " (unread = true OR marked = true) AND "; | |
755 | } | |
756 | ||
bdd01d3f AD |
757 | if ($view_mode == "Unread or Updated") { |
758 | $view_query_part = " (unread = true OR last_read is NULL) AND "; | |
759 | } | |
760 | ||
254e0e4b | 761 | /* $result = db_query($link, "SELECT count(id) AS total_entries |
36bf7496 AD |
762 | FROM ttrss_entries WHERE |
763 | $search_query_part | |
764 | feed_id = '$feed'"); | |
e6d1c0a0 | 765 | |
254e0e4b | 766 | $total_entries = db_fetch_result($result, 0, "total_entries"); */ |
e6d1c0a0 | 767 | |
648472a7 | 768 | /* $result = db_query("SELECT count(id) AS unread_entries |
ac43eba1 AD |
769 | FROM ttrss_entries WHERE |
770 | $search_query_part | |
771 | unread = true AND | |
772 | feed_id = '$feed'"); | |
773 | ||
648472a7 | 774 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ |
ac43eba1 | 775 | |
8d7008c7 | 776 | if ($limit && $limit != "All") { |
82c9223c | 777 | $limit_query_part = "LIMIT " . $limit; |
ad3cb710 | 778 | } |
f0601b87 | 779 | |
254e0e4b AD |
780 | $vfeed_query_part = ""; |
781 | ||
52b51244 | 782 | // override query strategy and enable feed display when searching globally |
d3416913 | 783 | if ($search && $search_mode == "All feeds") { |
52b51244 AD |
784 | $query_strategy_part = "id > 0"; |
785 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
786 | id = feed_id) as feed_title,"; | |
787 | } else if (sprintf("%d", $feed) == 0) { | |
8143ae1f AD |
788 | $query_strategy_part = "ttrss_entries.id > 0"; |
789 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
790 | id = feed_id) as feed_title,"; | |
791 | } else if ($feed >= 0) { | |
254e0e4b | 792 | $query_strategy_part = "feed_id = '$feed'"; |
48f0adb0 | 793 | } else if ($feed == -1) { // starred virtual feed |
254e0e4b | 794 | $query_strategy_part = "marked = true"; |
48f0adb0 AD |
795 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
796 | id = feed_id) as feed_title,"; | |
797 | } else if ($feed <= -10) { // labels | |
798 | $label_id = -$feed - 11; | |
799 | ||
800 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
801 | WHERE id = '$label_id'"); | |
802 | ||
803 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
804 | ||
254e0e4b AD |
805 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
806 | id = feed_id) as feed_title,"; | |
807 | } else { | |
48f0adb0 | 808 | $query_strategy_part = "id > 0"; // dumb |
254e0e4b AD |
809 | } |
810 | ||
52b51244 | 811 | |
f99321a3 AD |
812 | $order_by = "updated DESC"; |
813 | ||
814 | // if ($feed < -10) { | |
815 | // $order_by = "feed_id,updated DESC"; | |
816 | // } | |
817 | ||
48f0adb0 AD |
818 | if ($feed < -10) error_reporting (0); |
819 | ||
8143ae1f AD |
820 | if (sprintf("%d", $feed) != 0) { |
821 | ||
21703604 AD |
822 | if ($feed > 0) { |
823 | $feed_kind = "Feeds"; | |
824 | } else { | |
825 | $feed_kind = "Labels"; | |
826 | } | |
827 | ||
8143ae1f AD |
828 | $result = db_query($link, "SELECT |
829 | id,title,updated,unread,feed_id,marked,link,last_read, | |
830 | SUBSTRING(last_read,1,19) as last_read_noms, | |
831 | $vfeed_query_part | |
832 | SUBSTRING(updated,1,19) as updated_noms | |
833 | FROM | |
4c193675 | 834 | ttrss_entries,ttrss_user_entries |
8143ae1f | 835 | WHERE |
4c193675 | 836 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
aee86c2e | 837 | owner_uid = '".$_SESSION["uid"]."' AND |
8143ae1f AD |
838 | $search_query_part |
839 | $view_query_part | |
840 | $query_strategy_part ORDER BY $order_by | |
841 | $limit_query_part"); | |
842 | ||
843 | } else { | |
844 | // browsing by tag | |
845 | ||
21703604 AD |
846 | $feed_kind = "Tags"; |
847 | ||
8143ae1f AD |
848 | $result = db_query($link, "SELECT |
849 | ttrss_entries.id as id,title,updated,unread,feed_id, | |
850 | marked,link,last_read, | |
c05a19f3 | 851 | SUBSTRING(last_read,1,19) as last_read_noms, |
254e0e4b | 852 | $vfeed_query_part |
c05a19f3 | 853 | SUBSTRING(updated,1,19) as updated_noms |
8143ae1f | 854 | FROM |
05732aa0 | 855 | ttrss_entries,ttrss_user_entries,ttrss_tags |
8143ae1f | 856 | WHERE |
05732aa0 AD |
857 | ref_id = ttrss_entries.id AND |
858 | ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND | |
859 | post_int_id = int_id AND tag_name = '$feed' AND | |
8143ae1f AD |
860 | $view_query_part |
861 | $search_query_part | |
862 | $query_strategy_part ORDER BY $order_by | |
863 | $limit_query_part"); | |
864 | } | |
d76a3b03 | 865 | |
48f0adb0 AD |
866 | if (!$result) { |
867 | print "<tr><td colspan='4' align='center'> | |
868 | Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>"; | |
869 | return; | |
870 | } | |
871 | ||
a1a8a2be | 872 | $lnum = 0; |
48f0adb0 | 873 | |
cce28758 | 874 | error_reporting (DEFAULT_ERROR_LEVEL); |
48f0adb0 | 875 | |
e1123aee | 876 | $num_unread = 0; |
d76a3b03 | 877 | |
648472a7 | 878 | while ($line = db_fetch_assoc($result)) { |
d76a3b03 | 879 | |
a1a8a2be | 880 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 881 | |
ad99045e AD |
882 | $id = $line["id"]; |
883 | $feed_id = $line["feed_id"]; | |
884 | ||
c43f77f5 | 885 | // printf("L %d (%s) > U %d (%s) = %d<br>", |
c05a19f3 | 886 | // strtotime($line["last_read_noms"]), $line["last_read_noms"], |
c43f77f5 AD |
887 | // strtotime($line["updated"]), $line["updated"], |
888 | // strtotime($line["last_read"]) >= strtotime($line["updated"])); | |
889 | ||
ecb14114 | 890 | /* if ($line["last_read"] != "" && $line["updated"] != "" && |
c05a19f3 | 891 | strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) { |
c43f77f5 AD |
892 | |
893 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
894 | alt=\"Updated\">"; | |
895 | ||
896 | } else { | |
897 | ||
5bfef089 | 898 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" |
c43f77f5 AD |
899 | alt=\"Updated\">"; |
900 | ||
ecb14114 AD |
901 | } */ |
902 | ||
4cc6ea5e AD |
903 | if ($line["last_read"] == "" && |
904 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
905 | ||
ecb14114 AD |
906 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" |
907 | alt=\"Updated\">"; | |
908 | } else { | |
909 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
910 | alt=\"Updated\">"; | |
c43f77f5 | 911 | } |
b197f117 | 912 | |
8158c57a | 913 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
a1a8a2be | 914 | $class .= "Unread"; |
e1123aee AD |
915 | ++$num_unread; |
916 | } | |
d76a3b03 | 917 | |
8158c57a | 918 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
f4c10d44 AD |
919 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" |
920 | alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>"; | |
921 | } else { | |
922 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
923 | alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>"; | |
924 | } | |
925 | ||
ac43eba1 | 926 | $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" . |
b197f117 AD |
927 | $line["title"] . "</a>"; |
928 | ||
d5224f0d | 929 | print "<tr class='$class' id='RROW-$id'>"; |
5f89f780 | 930 | // onclick=\"javascript:view($id,$feed_id)\"> |
b197f117 | 931 | |
8d7008c7 AD |
932 | print "<td valign='center' align='center'>$update_pic</td>"; |
933 | print "<td valign='center' align='center'>$marked_pic</td>"; | |
b197f117 | 934 | |
8d7008c7 | 935 | print "<td width='25%'> |
a3ee2a38 | 936 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; |
254e0e4b AD |
937 | |
938 | if ($line["feed_title"]) { | |
939 | print "<td width='50%'>$content_link</td>"; | |
2db4190c AD |
940 | print "<td width='20%'> |
941 | <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>"; | |
254e0e4b AD |
942 | } else { |
943 | print "<td width='70%'>$content_link</td>"; | |
944 | } | |
d76a3b03 | 945 | |
a1a8a2be | 946 | print "</tr>"; |
d76a3b03 | 947 | |
a1a8a2be AD |
948 | ++$lnum; |
949 | } | |
d76a3b03 | 950 | |
ac53063a | 951 | if ($lnum == 0) { |
a82065a1 | 952 | print "<tr><td align='center'>No articles found.</td></tr>"; |
047bae73 | 953 | } |
a2015351 | 954 | |
a1a8a2be | 955 | print "</table>"; |
6113ef7d AD |
956 | |
957 | print "<script type=\"text/javascript\"> | |
bb7cface | 958 | document.onkeydown = hotkey_handler; |
8143ae1f | 959 | update_label_counters('$feed'); |
6113ef7d | 960 | </script>"; |
d76a3b03 | 961 | |
f0601b87 AD |
962 | if ($addheader) { |
963 | print "</body></html>"; | |
964 | } | |
965 | ||
1cd17194 AD |
966 | } |
967 | ||
0e091d38 | 968 | if ($op == "pref-rpc") { |
331900c6 | 969 | |
0e091d38 | 970 | $subop = $_GET["subop"]; |
331900c6 | 971 | |
83fe4d6d AD |
972 | if ($subop == "unread") { |
973 | $ids = split(",", $_GET["ids"]); | |
974 | foreach ($ids as $id) { | |
a5873b2e AD |
975 | db_query($link, "UPDATE ttrss_user_entries SET unread = true |
976 | WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
83fe4d6d | 977 | } |
0e091d38 | 978 | |
a5873b2e | 979 | print "Marked selected feeds as unread."; |
83fe4d6d AD |
980 | } |
981 | ||
982 | if ($subop == "read") { | |
983 | $ids = split(",", $_GET["ids"]); | |
984 | foreach ($ids as $id) { | |
a5873b2e AD |
985 | db_query($link, "UPDATE ttrss_user_entries |
986 | SET unread = false,last_read = NOW() WHERE | |
987 | feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
83fe4d6d | 988 | } |
0e091d38 | 989 | |
a5873b2e | 990 | print "Marked selected feeds as read."; |
0e091d38 AD |
991 | |
992 | } | |
993 | ||
994 | } | |
995 | ||
996 | if ($op == "pref-feeds") { | |
997 | ||
998 | $subop = $_GET["subop"]; | |
999 | ||
508a81e1 | 1000 | if ($subop == "editSave") { |
648472a7 AD |
1001 | $feed_title = db_escape_string($_GET["t"]); |
1002 | $feed_link = db_escape_string($_GET["l"]); | |
d148926e | 1003 | $upd_intl = db_escape_string($_GET["ui"]); |
5d73494a | 1004 | $purge_intl = db_escape_string($_GET["pi"]); |
91ff844a AD |
1005 | $feed_id = db_escape_string($_GET["id"]); |
1006 | $cat_id = db_escape_string($_GET["catid"]); | |
508a81e1 | 1007 | |
d148926e AD |
1008 | if (strtoupper($upd_intl) == "DEFAULT") |
1009 | $upd_intl = 0; | |
1010 | ||
5d73494a AD |
1011 | if (strtoupper($purge_intl) == "DEFAULT") |
1012 | $purge_intl = 0; | |
1013 | ||
140aae81 AD |
1014 | if (strtoupper($purge_intl) == "DISABLED") |
1015 | $purge_intl = -1; | |
1016 | ||
91ff844a AD |
1017 | if ($cat_id != 0) { |
1018 | $category_qpart = "cat_id = '$cat_id'"; | |
1019 | } else { | |
1020 | $category_qpart = 'cat_id = NULL'; | |
1021 | } | |
1022 | ||
648472a7 | 1023 | $result = db_query($link, "UPDATE ttrss_feeds SET |
91ff844a | 1024 | $category_qpart, |
d148926e | 1025 | title = '$feed_title', feed_url = '$feed_link', |
5d73494a | 1026 | update_interval = '$upd_intl', |
91ff844a | 1027 | purge_interval = '$purge_intl' |
f72dbbde | 1028 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); |
508a81e1 | 1029 | |
83fe4d6d AD |
1030 | } |
1031 | ||
331900c6 | 1032 | if ($subop == "remove") { |
331900c6 | 1033 | |
b0b4abcf | 1034 | if (!WEB_DEMO_MODE) { |
331900c6 | 1035 | |
b0b4abcf AD |
1036 | $ids = split(",", $_GET["ids"]); |
1037 | ||
1038 | foreach ($ids as $id) { | |
f72dbbde AD |
1039 | db_query($link, "DELETE FROM ttrss_feeds |
1040 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
4769ddaf | 1041 | |
273a2f6b | 1042 | $icons_dir = ICONS_DIR; |
d5caaae5 | 1043 | |
4769ddaf AD |
1044 | if (file_exists($icons_dir . "/$id.ico")) { |
1045 | unlink($icons_dir . "/$id.ico"); | |
d5caaae5 | 1046 | } |
b0b4abcf | 1047 | } |
331900c6 AD |
1048 | } |
1049 | } | |
1050 | ||
1051 | if ($subop == "add") { | |
b0b4abcf AD |
1052 | |
1053 | if (!WEB_DEMO_MODE) { | |
331900c6 | 1054 | |
b6b535ca | 1055 | $feed_link = db_escape_string(trim($_GET["link"])); |
331900c6 | 1056 | |
648472a7 | 1057 | $result = db_query($link, |
7e9a3986 AD |
1058 | "SELECT id FROM ttrss_feeds |
1059 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
1060 | ||
1061 | if (db_num_rows($result) == 0) { | |
1062 | ||
1063 | $result = db_query($link, | |
1064 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) | |
1065 | VALUES ('".$_SESSION["uid"]."', '$feed_link', '')"); | |
331900c6 | 1066 | |
7e9a3986 AD |
1067 | $result = db_query($link, |
1068 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' | |
1069 | AND owner_uid = " . $_SESSION["uid"]); | |
1070 | ||
1071 | $feed_id = db_fetch_result($result, 0, "id"); | |
1072 | ||
1073 | if ($feed_id) { | |
1074 | update_rss_feed($link, $feed_link, $feed_id); | |
1075 | } | |
1076 | } else { | |
331900c6 | 1077 | |
7e9a3986 AD |
1078 | print "<div class=\"warning\"> |
1079 | Feed <b>$feed_link</b> already exists in the database. | |
1080 | </div>"; | |
b0b4abcf AD |
1081 | } |
1082 | } | |
331900c6 | 1083 | } |
a0d53889 | 1084 | |
91ff844a AD |
1085 | if ($subop == "addCat") { |
1086 | ||
1087 | if (!WEB_DEMO_MODE) { | |
1088 | ||
1089 | $feed_cat = db_escape_string(trim($_GET["cat"])); | |
1090 | ||
1091 | $result = db_query($link, | |
1092 | "SELECT id FROM ttrss_feed_categories | |
1093 | WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); | |
1094 | ||
1095 | if (db_num_rows($result) == 0) { | |
1096 | ||
1097 | $result = db_query($link, | |
1098 | "INSERT INTO ttrss_feed_categories (owner_uid,title) | |
1099 | VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); | |
1100 | ||
1101 | } else { | |
1102 | ||
1103 | print "<div class=\"warning\"> | |
1104 | Category <b>$feed_cat</b> already exists in the database. | |
1105 | </div>"; | |
1106 | } | |
1107 | ||
1108 | ||
1109 | } | |
1110 | } | |
1111 | ||
1112 | if ($subop == "removeCats") { | |
1113 | ||
1114 | if (!WEB_DEMO_MODE) { | |
1115 | ||
1116 | $ids = split(",", $_GET["ids"]); | |
1117 | ||
1118 | foreach ($ids as $id) { | |
1119 | ||
1120 | db_query($link, "BEGIN"); | |
1121 | ||
1122 | $result = db_query($link, | |
1123 | "SELECT count(id) as num_feeds FROM ttrss_feeds | |
1124 | WHERE cat_id = '$id'"); | |
1125 | ||
1126 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
1127 | ||
1128 | if ($num_feeds == 0) { | |
1129 | db_query($link, "DELETE FROM ttrss_feed_categories | |
1130 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
1131 | } else { | |
1132 | ||
1133 | print "<div class=\"warning\"> | |
1134 | Unable to delete non empty feed categories.</div>"; | |
1135 | ||
1136 | } | |
1137 | ||
1138 | db_query($link, "COMMIT"); | |
1139 | } | |
1140 | } | |
1141 | } | |
1142 | ||
c64d5b03 | 1143 | // print "<h3>Edit Feeds</h3>"; |
91ff844a | 1144 | |
4904f845 AD |
1145 | $result = db_query($link, "SELECT id,title,feed_url,last_error |
1146 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); | |
1147 | ||
1148 | if (db_num_rows($result) > 0) { | |
1149 | ||
1150 | print "<div class=\"warning\">"; | |
1151 | ||
1152 | print "<b>Feeds with update errors:</b>"; | |
1153 | ||
1154 | print "<ul class=\"nomarks\">"; | |
1155 | ||
1156 | while ($line = db_fetch_assoc($result)) { | |
1157 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
1158 | $line["last_error"]; | |
1159 | } | |
1160 | ||
1161 | print "</ul>"; | |
1162 | print "</div>"; | |
1163 | ||
1164 | } | |
1165 | ||
c64d5b03 | 1166 | print "<p><div class=\"prefGenericAddBox\"> |
2c7070b5 AD |
1167 | <input id=\"fadd_link\" size=\"40\"> <input |
1168 | type=\"submit\" class=\"button\" | |
1169 | onclick=\"javascript:addFeed()\" value=\"Add feed\"></div>"; | |
a0d53889 | 1170 | |
b83c7545 AD |
1171 | $feeds_sort = db_escape_string($_GET["sort"]); |
1172 | ||
1173 | if (!$feeds_sort || $feeds_sort == "undefined") { | |
1174 | $feeds_sort = $_SESSION["pref_sort_feeds"]; | |
1175 | if (!$feeds_sort) $feeds_sort = "title"; | |
1176 | } | |
1177 | ||
1178 | $_SESSION["pref_sort_feeds"] = $feeds_sort; | |
1179 | ||
648472a7 | 1180 | $result = db_query($link, "SELECT |
d148926e | 1181 | id,title,feed_url,substring(last_updated,1,16) as last_updated, |
91ff844a AD |
1182 | update_interval,purge_interval, |
1183 | (SELECT title FROM ttrss_feed_categories | |
1184 | WHERE id = cat_id) AS category | |
c0e5a40e | 1185 | FROM |
b83c7545 AD |
1186 | ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' |
1187 | ORDER by $feeds_sort,title"); | |
1cd17194 | 1188 | |
3b0feb9b | 1189 | if (db_num_rows($result) != 0) { |
91ff844a | 1190 | |
3b0feb9b | 1191 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
54d3ba50 | 1192 | |
3b0feb9b AD |
1193 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
1194 | print "<tr class=\"title\"> | |
3547842a AD |
1195 | <td width=\"3%\"> </td> |
1196 | <td width=\"3%\">Select</td> | |
3b0feb9b AD |
1197 | <td width=\"20%\"> |
1198 | <a href=\"javascript:updateFeedList('title')\">Title</a></td> | |
1199 | <td width=\"20%\"> | |
1200 | <a href=\"javascript:updateFeedList('feed_url')\">Link</a> | |
1201 | </td>"; | |
54d3ba50 | 1202 | |
3b0feb9b AD |
1203 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
1204 | print "<td width=\"10%\"> | |
1205 | <a href=\"javascript:updateFeedList('category')\">Category</a></td>"; | |
603c27f8 | 1206 | } |
603c27f8 | 1207 | |
f92db4f5 | 1208 | print " |
3b0feb9b AD |
1209 | <td width=\"10%\"> |
1210 | <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a> | |
1211 | </td> | |
1212 | <td width=\"10%\"> | |
1213 | <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a> | |
1214 | </td> | |
3b0feb9b AD |
1215 | </tr>"; |
1216 | ||
c64d5b03 AD |
1217 | $lnum = 0; |
1218 | ||
1219 | while ($line = db_fetch_assoc($result)) { | |
1220 | ||
1221 | $class = ($lnum % 2) ? "even" : "odd"; | |
1222 | ||
3b0feb9b | 1223 | $feed_id = $line["id"]; |
c64d5b03 | 1224 | |
3b0feb9b | 1225 | $edit_feed_id = $_GET["id"]; |
c64d5b03 | 1226 | |
3b0feb9b | 1227 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
c64d5b03 AD |
1228 | $class .= "Grayed"; |
1229 | } | |
1230 | ||
3b0feb9b AD |
1231 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
1232 | ||
1233 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
1234 | ||
1235 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1236 | $feed_icon = "<img width=\"16\" height=\"16\" | |
1237 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
1238 | } else { | |
1239 | $feed_icon = " "; | |
1240 | } | |
1241 | print "<td align='center'>$feed_icon</td>"; | |
c64d5b03 AD |
1242 | |
1243 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
3b0feb9b AD |
1244 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); |
1245 | $edit_cat = htmlspecialchars(db_unescape_string($line["category"])); | |
1246 | ||
1247 | if (!$edit_cat) $edit_cat = "Uncategorized"; | |
c64d5b03 | 1248 | |
3b0feb9b | 1249 | if (!$edit_feed_id || $subop != "edit") { |
c64d5b03 AD |
1250 | |
1251 | print "<td><input onclick='toggleSelectRow(this);' | |
3b0feb9b | 1252 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
3547842a AD |
1253 | |
1254 | $edit_title = truncate_string($edit_title, 40); | |
1255 | $edit_link = truncate_string($edit_link, 60); | |
c64d5b03 | 1256 | |
3b0feb9b | 1257 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
c64d5b03 | 1258 | $edit_title . "</a></td>"; |
3b0feb9b AD |
1259 | |
1260 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1261 | $edit_link . "</a></td>"; | |
1262 | ||
1263 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1264 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1265 | $edit_cat . "</a></td>"; | |
1266 | } | |
1267 | ||
1268 | if ($line["update_interval"] == "0") | |
1269 | $line["update_interval"] = "Default"; | |
c64d5b03 | 1270 | |
3b0feb9b AD |
1271 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
1272 | $line["update_interval"] . "</a></td>"; | |
1273 | ||
1274 | if ($line["purge_interval"] == "0") | |
1275 | $line["purge_interval"] = "Default"; | |
1276 | ||
1277 | if ($line["purge_interval"] < 0) | |
1278 | $line["purge_interval"] = "Disabled"; | |
1279 | ||
1280 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
1281 | $line["purge_interval"] . "</a></td>"; | |
1282 | ||
1283 | } else if ($feed_id != $edit_feed_id) { | |
c64d5b03 AD |
1284 | |
1285 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1286 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
3547842a AD |
1287 | |
1288 | $edit_title = truncate_string($edit_title, 40); | |
1289 | $edit_link = truncate_string($edit_link, 60); | |
1290 | ||
c64d5b03 | 1291 | print "<td>$edit_title</td>"; |
3b0feb9b AD |
1292 | print "<td>$edit_link</td>"; |
1293 | ||
1294 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1295 | print "<td>$edit_cat</td>"; | |
1296 | } | |
1297 | ||
1298 | if ($line["update_interval"] == "0") | |
1299 | $line["update_interval"] = "Default"; | |
1300 | ||
1301 | print "<td>" . $line["update_interval"] . "</td>"; | |
1302 | ||
1303 | if ($line["purge_interval"] == "0") | |
1304 | $line["purge_interval"] = "Default"; | |
1305 | ||
1306 | if ($line["purge_interval"] < 0) | |
1307 | $line["purge_interval"] = "Disabled"; | |
1308 | ||
1309 | print "<td>" . $line["purge_interval"] . "</td>"; | |
c64d5b03 AD |
1310 | |
1311 | } else { | |
1312 | ||
1313 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
1314 | ||
1315 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; | |
3b0feb9b AD |
1316 | print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>"; |
1317 | ||
1318 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1319 | ||
1320 | print "<td>"; | |
1321 | print "<select id=\"iedit_fcat\">"; | |
1322 | print "<option id=\"0\">Uncategorized</option>"; | |
1323 | ||
1324 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
1325 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1326 | ||
1327 | if (db_num_rows($tmp_result) > 0) { | |
1328 | print "<option disabled>--------</option>"; | |
1329 | } | |
1330 | ||
1331 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1332 | if ($tmp_line["id"] == $line["cat_id"]) { | |
1333 | $is_selected = "selected"; | |
1334 | } else { | |
1335 | $is_selected = ""; | |
1336 | } | |
1337 | printf("<option $is_selected id='%d'>%s</option>", | |
1338 | $tmp_line["id"], $tmp_line["title"]); | |
1339 | } | |
1340 | ||
1341 | print "</select></td>"; | |
1342 | print "</td>"; | |
1343 | ||
1344 | } | |
c64d5b03 | 1345 | |
3b0feb9b AD |
1346 | print "<td><input id=\"iedit_updintl\" |
1347 | value=\"".$line["update_interval"]."\"></td>"; | |
1348 | print "<td><input id=\"iedit_purgintl\" | |
1349 | value=\"".$line["purge_interval"]."\"></td>"; | |
1350 | ||
c64d5b03 | 1351 | } |
3b0feb9b | 1352 | |
3547842a | 1353 | /* if (!$line["last_updated"]) $line["last_updated"] = "Never"; |
3b0feb9b | 1354 | |
3547842a | 1355 | print "<td>" . $line["last_updated"] . "</td>"; */ |
c64d5b03 AD |
1356 | |
1357 | print "</tr>"; | |
1358 | ||
1359 | ++$lnum; | |
1360 | } | |
1361 | ||
c64d5b03 | 1362 | print "</table>"; |
3b0feb9b | 1363 | |
c64d5b03 AD |
1364 | print "<p>"; |
1365 | ||
3b0feb9b AD |
1366 | if ($subop == "edit") { |
1367 | print "Edit feed: | |
c64d5b03 | 1368 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 1369 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> |
c64d5b03 | 1370 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
1371 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
1372 | } else { | |
c64d5b03 AD |
1373 | |
1374 | print " | |
1375 | Selection: | |
1376 | <input type=\"submit\" class=\"button\" | |
3b0feb9b | 1377 | onclick=\"javascript:selectedFeedDetails()\" value=\"Details\"> |
c64d5b03 | 1378 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
1379 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> |
1380 | <input type=\"submit\" class=\"button\" | |
1381 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
1382 | ||
1383 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { | |
1384 | print " | |
1385 | <input type=\"submit\" class=\"button\" | |
1386 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
1387 | <input type=\"submit\" class=\"button\" | |
1388 | onclick=\"javascript:unreadSelectedFeeds()\" | |
1389 | value=\"Mark as unread\"> "; | |
1390 | } | |
1391 | ||
1392 | print " | |
1393 | All feeds: <input type=\"submit\" | |
1394 | class=\"button\" onclick=\"gotoExportOpml()\" | |
1395 | value=\"Export OPML\">"; | |
1396 | } | |
1397 | } else { | |
1398 | ||
1399 | print "<p>No feeds defined.</p>"; | |
1400 | ||
1401 | } | |
1402 | ||
1403 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1404 | ||
1405 | print "<h3>Edit Categories</h3>"; | |
1406 | ||
1407 | // print "<h3>Categories</h3>"; | |
1408 | ||
1409 | print "<div class=\"prefGenericAddBox\"> | |
1410 | <input id=\"fadd_cat\" size=\"40\"> <input | |
1411 | type=\"submit\" class=\"button\" | |
1412 | onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>"; | |
1413 | ||
1414 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
1415 | WHERE owner_uid = ".$_SESSION["uid"]." | |
1416 | ORDER BY title"); | |
1417 | ||
1418 | if (db_num_rows($result) != 0) { | |
1419 | ||
1420 | print "<p><table width=\"100%\" class=\"prefFeedCatList\" id=\"prefFeedCatList\">"; | |
1421 | print "<tr class=\"title\"> | |
1422 | <td width=\"10%\">Select</td><td width=\"80%\">Title</td> | |
1423 | </tr>"; | |
1424 | ||
1425 | $lnum = 0; | |
1426 | ||
1427 | while ($line = db_fetch_assoc($result)) { | |
1428 | ||
1429 | $class = ($lnum % 2) ? "even" : "odd"; | |
1430 | ||
1431 | $cat_id = $line["id"]; | |
1432 | ||
1433 | $edit_cat_id = $_GET["id"]; | |
1434 | ||
1435 | if ($subop == "editCat" && $cat_id != $edit_cat_id) { | |
1436 | $class .= "Grayed"; | |
1437 | } | |
1438 | ||
1439 | print "<tr class=\"$class\" id=\"FCATR-$cat_id\">"; | |
1440 | ||
1441 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
1442 | ||
1443 | if (!$edit_cat_id || $subop != "editCat") { | |
1444 | ||
1445 | print "<td><input onclick='toggleSelectRow(this);' | |
1446 | type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>"; | |
1447 | ||
1448 | print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . | |
1449 | $edit_title . "</a></td>"; | |
1450 | ||
1451 | } else if ($cat_id != $edit_cat_id) { | |
1452 | ||
1453 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1454 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
1455 | ||
1456 | print "<td>$edit_title</td>"; | |
1457 | ||
1458 | } else { | |
1459 | ||
1460 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
1461 | ||
1462 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; | |
1463 | ||
1464 | } | |
1465 | ||
1466 | print "</tr>"; | |
1467 | ||
1468 | ++$lnum; | |
1469 | } | |
1470 | ||
1471 | print "</table>"; | |
1472 | ||
1473 | print "<p>"; | |
1474 | ||
1475 | if ($subop == "editCat") { | |
1476 | print "Edit category: | |
1477 | <input type=\"submit\" class=\"button\" | |
1478 | onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\"> | |
1479 | <input type=\"submit\" class=\"button\" | |
1480 | onclick=\"javascript:feedCatEditSave()\" value=\"Save\">"; | |
1481 | } else { | |
1482 | ||
1483 | print " | |
1484 | Selection: | |
1485 | <input type=\"submit\" class=\"button\" | |
1486 | onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\"> | |
1487 | <input type=\"submit\" class=\"button\" | |
1488 | onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">"; | |
1489 | ||
1490 | } | |
1491 | ||
1492 | } else { | |
1493 | print "<p>No feed categories defined.</p>"; | |
1494 | } | |
c64d5b03 AD |
1495 | } |
1496 | ||
1497 | print "<h3>Import OPML</h3> | |
f5a50b25 AD |
1498 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> |
1499 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
1500 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
1501 | type=\"submit\" value=\"Import\"> | |
1502 | </form>"; | |
1503 | ||
007bda35 AD |
1504 | } |
1505 | ||
a0d53889 AD |
1506 | if ($op == "pref-filters") { |
1507 | ||
1508 | $subop = $_GET["subop"]; | |
1509 | ||
1510 | if ($subop == "editSave") { | |
a0d53889 | 1511 | |
648472a7 AD |
1512 | $regexp = db_escape_string($_GET["r"]); |
1513 | $descr = db_escape_string($_GET["d"]); | |
1514 | $match = db_escape_string($_GET["m"]); | |
1515 | $filter_id = db_escape_string($_GET["id"]); | |
ead60402 AD |
1516 | $feed_id = db_escape_string($_GET["fid"]); |
1517 | ||
1518 | if (!$feed_id) { | |
1519 | $feed_id = 'NULL'; | |
1520 | } else { | |
1521 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
1522 | } | |
0afbd851 | 1523 | |
648472a7 | 1524 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 1525 | reg_exp = '$regexp', |
0afbd851 | 1526 | description = '$descr', |
ead60402 | 1527 | feed_id = $feed_id, |
0afbd851 AD |
1528 | filter_type = (SELECT id FROM ttrss_filter_types WHERE |
1529 | description = '$match') | |
1530 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
1531 | } |
1532 | ||
1533 | if ($subop == "remove") { | |
1534 | ||
1535 | if (!WEB_DEMO_MODE) { | |
1536 | ||
1537 | $ids = split(",", $_GET["ids"]); | |
1538 | ||
1539 | foreach ($ids as $id) { | |
648472a7 | 1540 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
1541 | |
1542 | } | |
1543 | } | |
1544 | } | |
1545 | ||
1546 | if ($subop == "add") { | |
1547 | ||
de435974 | 1548 | if (!WEB_DEMO_MODE) { |
a0d53889 | 1549 | |
b6b535ca AD |
1550 | $regexp = db_escape_string(trim($_GET["regexp"])); |
1551 | $match = db_escape_string(trim($_GET["match"])); | |
ead60402 AD |
1552 | $feed_id = db_escape_string($_GET["fid"]); |
1553 | ||
1554 | if (!$feed_id) { | |
1555 | $feed_id = 'NULL'; | |
1556 | } else { | |
1557 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
1558 | } | |
4401bf04 | 1559 | |
648472a7 | 1560 | $result = db_query($link, |
ead60402 | 1561 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES |
de435974 | 1562 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
ead60402 | 1563 | description = '$match'),'".$_SESSION["uid"]."', $feed_id)"); |
de435974 | 1564 | } |
a0d53889 AD |
1565 | } |
1566 | ||
648472a7 | 1567 | $result = db_query($link, "SELECT description |
a0d53889 AD |
1568 | FROM ttrss_filter_types ORDER BY description"); |
1569 | ||
1570 | $filter_types = array(); | |
1571 | ||
648472a7 | 1572 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1573 | array_push($filter_types, $line["description"]); |
1574 | } | |
1575 | ||
2c7070b5 AD |
1576 | print "<div class=\"prefGenericAddBox\"> |
1577 | <input id=\"fadd_regexp\" size=\"40\"> "; | |
1578 | ||
ead60402 AD |
1579 | print_select("fadd_match", "Title", $filter_types); |
1580 | ||
1581 | print " <select id=\"fadd_feed\">"; | |
1582 | ||
1583 | print "<option selected id=\"0\">All feeds</option>"; | |
1584 | ||
1585 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
1586 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1587 | ||
1588 | if (db_num_rows($result) > 0) { | |
1589 | print "<option disabled>--------</option>"; | |
1590 | } | |
1591 | ||
1592 | while ($line = db_fetch_assoc($result)) { | |
1593 | printf("<option id='%d'>%s</option>", $line["id"], $line["title"]); | |
1594 | } | |
1595 | ||
2c7070b5 | 1596 | print "</select> "; |
a0d53889 | 1597 | |
2c7070b5 AD |
1598 | print "<input type=\"submit\" |
1599 | class=\"button\" onclick=\"javascript:addFilter()\" | |
1600 | value=\"Add filter\">"; | |
a0d53889 | 1601 | |
648472a7 | 1602 | $result = db_query($link, "SELECT |
ead60402 AD |
1603 | ttrss_filters.id AS id,reg_exp, |
1604 | ttrss_filters.description AS description, | |
1605 | ttrss_filter_types.name AS filter_type_name, | |
1606 | ttrss_filter_types.description AS filter_type_descr, | |
1607 | feed_id, | |
1608 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
a0d53889 | 1609 | FROM |
ead60402 | 1610 | ttrss_filters,ttrss_filter_types |
4356293a | 1611 | WHERE |
ead60402 AD |
1612 | filter_type = ttrss_filter_types.id AND |
1613 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." | |
4356293a | 1614 | ORDER by reg_exp"); |
a0d53889 | 1615 | |
3b0feb9b | 1616 | if (db_num_rows($result) != 0) { |
a0d53889 | 1617 | |
3b0feb9b AD |
1618 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; |
1619 | ||
1620 | print "<tr class=\"title\"> | |
1621 | <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td> | |
1622 | <td width=\"30%\">Feed</td><td width=\"10%\">Match</td> | |
1623 | <td width=\"30%\">Description</td></tr>"; | |
a0d53889 | 1624 | |
3b0feb9b AD |
1625 | $lnum = 0; |
1626 | ||
1627 | while ($line = db_fetch_assoc($result)) { | |
1628 | ||
1629 | $class = ($lnum % 2) ? "even" : "odd"; | |
1630 | ||
1631 | $filter_id = $line["id"]; | |
1632 | $edit_filter_id = $_GET["id"]; | |
1633 | ||
1634 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
1635 | $class .= "Grayed"; | |
ead60402 | 1636 | } |
3b0feb9b AD |
1637 | |
1638 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
1639 | ||
1640 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); | |
1641 | $line["description"] = htmlspecialchars($line["description"]); | |
1642 | ||
1643 | if (!$line["feed_title"]) $line["feed_title"] = "All feeds"; | |
1644 | ||
1645 | if (!$edit_filter_id || $subop != "edit") { | |
1646 | ||
1647 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1648 | ||
1649 | print "<td><input onclick='toggleSelectRow(this);' | |
1650 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
1651 | ||
1652 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
1653 | $line["reg_exp"] . "</td>"; | |
1654 | ||
1655 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
1656 | $line["feed_title"] . "</td>"; | |
1657 | ||
1658 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
1659 | $line["filter_type_descr"] . "</td>"; | |
1660 | ||
1661 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
1662 | $line["description"] . "</td>"; | |
1663 | ||
1664 | } else if ($filter_id != $edit_filter_id) { | |
1665 | ||
1666 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1667 | ||
1668 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1669 | id=\"FICHK-".$line["id"]."\"></td>"; | |
1670 | ||
1671 | print "<td>".$line["reg_exp"]."</td>"; | |
1672 | print "<td>".$line["feed_title"]."</td>"; | |
1673 | print "<td>".$line["filter_type_descr"]."</td>"; | |
1674 | print "<td>".$line["description"]."</td>"; | |
1675 | ||
1676 | } else { | |
1677 | ||
1678 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
1679 | ||
1680 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. | |
1681 | "\"></td>"; | |
1682 | ||
1683 | print "<td>"; | |
1684 | ||
1685 | print "<select id=\"iedit_feed\">"; | |
1686 | ||
1687 | print "<option id=\"0\">All feeds</option>"; | |
1688 | ||
1689 | if (db_num_rows($result) > 0) { | |
1690 | print "<option disabled>--------</option>"; | |
1691 | } | |
1692 | ||
1693 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
1694 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1695 | ||
1696 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1697 | if ($tmp_line["id"] == $line["feed_id"]) { | |
1698 | $is_selected = "selected"; | |
1699 | } else { | |
1700 | $is_selected = ""; | |
1701 | } | |
1702 | printf("<option $is_selected id='%d'>%s</option>", | |
1703 | $tmp_line["id"], $tmp_line["title"]); | |
ead60402 | 1704 | } |
3b0feb9b AD |
1705 | |
1706 | print "</select></td>"; | |
1707 | ||
1708 | print "<td>"; | |
1709 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
1710 | print "</td>"; | |
1711 | ||
1712 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1713 | "\"></td>"; | |
1714 | ||
1715 | print "</td>"; | |
ead60402 | 1716 | } |
3b0feb9b AD |
1717 | |
1718 | print "</tr>"; | |
1719 | ||
1720 | ++$lnum; | |
a0d53889 | 1721 | } |
3b0feb9b AD |
1722 | |
1723 | if ($lnum == 0) { | |
1724 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
1725 | } | |
1726 | ||
1727 | print "</table>"; | |
1728 | ||
1729 | print "<p>"; | |
1730 | ||
1731 | if ($subop == "edit") { | |
1732 | print "Edit feed: | |
1733 | <input type=\"submit\" class=\"button\" | |
1734 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
1735 | <input type=\"submit\" class=\"button\" | |
1736 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
1737 | ||
1738 | } else { | |
1739 | ||
1740 | print " | |
1741 | Selection: | |
e828e31e | 1742 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 1743 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> |
e828e31e | 1744 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
1745 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; |
1746 | } | |
1747 | ||
a0d53889 AD |
1748 | } else { |
1749 | ||
3b0feb9b AD |
1750 | print "<p>No filters defined.</p>"; |
1751 | ||
a0d53889 AD |
1752 | } |
1753 | } | |
1754 | ||
48f0adb0 AD |
1755 | if ($op == "pref-labels") { |
1756 | ||
1757 | $subop = $_GET["subop"]; | |
1758 | ||
d9dde1d6 AD |
1759 | if ($subop == "test") { |
1760 | ||
1761 | $expr = $_GET["expr"]; | |
1762 | $descr = $_GET["descr"]; | |
1763 | ||
1764 | print "<div class='infoBoxContents'>"; | |
1765 | ||
1766 | print "<h1>Label «$descr»</h1>"; | |
1767 | ||
1768 | // print "<p><b>Expression</b>: $expr</p>"; | |
1769 | ||
1770 | $result = db_query($link, | |
1771 | "SELECT count(id) AS num_matches | |
1772 | FROM ttrss_entries,ttrss_user_entries | |
1773 | WHERE ($expr) AND | |
1774 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
1775 | owner_uid = " . $_SESSION["uid"]); | |
1776 | ||
1777 | $num_matches = db_fetch_result($result, 0, "num_matches");; | |
1778 | ||
1779 | if ($num_matches > 0) { | |
1780 | ||
1781 | print "<p>Query returned <b>$num_matches</b> matches, first 5:</p>"; | |
1782 | ||
1783 | $result = db_query($link, | |
1784 | "SELECT title, | |
1785 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
1786 | FROM ttrss_entries,ttrss_user_entries | |
1787 | WHERE ($expr) AND | |
1788 | ttrss_user_entries.ref_id = ttrss_entries.id | |
1789 | AND owner_uid = " . $_SESSION["uid"] . " | |
1790 | ORDER BY date_entered DESC LIMIT 5"); | |
1791 | ||
1792 | print "<ul class=\"nomarks\">"; | |
1793 | while ($line = db_fetch_assoc($result)) { | |
1794 | print "<li>".$line["title"]. | |
1795 | " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>"; | |
1796 | } | |
1797 | print "</ul>"; | |
1798 | ||
1799 | } else { | |
1800 | print "<p>Query didn't return any matches.</p>"; | |
1801 | } | |
1802 | ||
1803 | print "</div>"; | |
1804 | ||
1805 | print "<div align='center'> | |
1806 | <input type='submit' class='button' | |
1807 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
1808 | return; | |
1809 | } | |
1810 | ||
48f0adb0 AD |
1811 | if ($subop == "editSave") { |
1812 | ||
1813 | $sql_exp = $_GET["s"]; | |
1814 | $descr = $_GET["d"]; | |
1815 | $label_id = db_escape_string($_GET["id"]); | |
1816 | ||
1817 | // print "$sql_exp : $descr : $label_id"; | |
1818 | ||
1819 | $result = db_query($link, "UPDATE ttrss_labels SET | |
1820 | sql_exp = '$sql_exp', | |
1821 | description = '$descr' | |
1822 | WHERE id = '$label_id'"); | |
1823 | } | |
1824 | ||
1825 | if ($subop == "remove") { | |
1826 | ||
1827 | if (!WEB_DEMO_MODE) { | |
1828 | ||
1829 | $ids = split(",", $_GET["ids"]); | |
1830 | ||
1831 | foreach ($ids as $id) { | |
1832 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
1833 | ||
1834 | } | |
1835 | } | |
1836 | } | |
1837 | ||
1838 | if ($subop == "add") { | |
1839 | ||
1840 | if (!WEB_DEMO_MODE) { | |
1841 | ||
4401bf04 AD |
1842 | // no escaping is done here on purpose |
1843 | $exp = trim($_GET["exp"]); | |
48f0adb0 AD |
1844 | |
1845 | $result = db_query($link, | |
4356293a AD |
1846 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) |
1847 | VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')"); | |
48f0adb0 AD |
1848 | } |
1849 | } | |
1850 | ||
2c7070b5 AD |
1851 | print "<div class=\"prefGenericAddBox\"> |
1852 | <input size=\"40\" id=\"ladd_expr\"> "; | |
48f0adb0 | 1853 | |
2c7070b5 AD |
1854 | print"<input type=\"submit\" class=\"button\" |
1855 | onclick=\"javascript:addLabel()\" value=\"Add label\"></div>"; | |
48f0adb0 AD |
1856 | |
1857 | $result = db_query($link, "SELECT | |
1858 | id,sql_exp,description | |
1859 | FROM | |
4356293a AD |
1860 | ttrss_labels |
1861 | WHERE | |
1862 | owner_uid = ".$_SESSION["uid"]." | |
1863 | ORDER by description"); | |
48f0adb0 | 1864 | |
d9dde1d6 AD |
1865 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
1866 | ||
3b0feb9b | 1867 | if (db_num_rows($result) != 0) { |
48f0adb0 | 1868 | |
3b0feb9b AD |
1869 | print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">"; |
1870 | ||
1871 | print "<tr class=\"title\"> | |
1872 | <td width=\"5%\">Select</td><td width=\"40%\">SQL expression | |
1873 | <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a> | |
1874 | </td> | |
1875 | <td width=\"40%\">Caption</td></tr>"; | |
1876 | ||
1877 | $lnum = 0; | |
1878 | ||
1879 | while ($line = db_fetch_assoc($result)) { | |
1880 | ||
1881 | $class = ($lnum % 2) ? "even" : "odd"; | |
1882 | ||
1883 | $label_id = $line["id"]; | |
1884 | $edit_label_id = $_GET["id"]; | |
1885 | ||
1886 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
1887 | $class .= "Grayed"; | |
1888 | } | |
1889 | ||
1890 | print "<tr class=\"$class\" id=\"LILRR-$label_id\">"; | |
1891 | ||
1892 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
1893 | $line["description"] = htmlspecialchars($line["description"]); | |
1894 | ||
1895 | if (!$edit_label_id || $subop != "edit") { | |
1896 | ||
1897 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
1898 | ||
1899 | print "<td><input onclick='toggleSelectRow(this);' | |
1900 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
1901 | ||
1902 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1903 | $line["sql_exp"] . "</td>"; | |
48f0adb0 | 1904 | |
3b0feb9b AD |
1905 | print "<td><a href=\"javascript:editLabel($label_id);\">" . |
1906 | $line["description"] . "</td>"; | |
1907 | ||
1908 | } else if ($label_id != $edit_label_id) { | |
1909 | ||
1910 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1911 | ||
1912 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1913 | id=\"LICHK-".$line["id"]."\"></td>"; | |
1914 | ||
1915 | print "<td>".$line["sql_exp"]."</td>"; | |
1916 | print "<td>".$line["description"]."</td>"; | |
1917 | ||
1918 | } else { | |
1919 | ||
1920 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
1921 | ||
1922 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
1923 | "\"></td>"; | |
1924 | ||
1925 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1926 | "\"></td>"; | |
1927 | ||
1928 | } | |
1929 | ||
48f0adb0 | 1930 | |
3b0feb9b AD |
1931 | print "</tr>"; |
1932 | ||
1933 | ++$lnum; | |
1934 | } | |
1935 | ||
1936 | if ($lnum == 0) { | |
1937 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
1938 | } | |
1939 | ||
1940 | print "</table>"; | |
1941 | ||
1942 | print "<p>"; | |
1943 | ||
1944 | if ($subop == "edit") { | |
1945 | print "Edit label: | |
d9dde1d6 AD |
1946 | <input type=\"submit\" class=\"button\" |
1947 | onclick=\"javascript:labelTest()\" value=\"Test\"> | |
3b0feb9b AD |
1948 | <input type=\"submit\" class=\"button\" |
1949 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
1950 | <input type=\"submit\" class=\"button\" | |
1951 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
1952 | ||
1953 | } else { | |
1954 | ||
1955 | print " | |
1956 | Selection: | |
48f0adb0 | 1957 | <input type=\"submit\" class=\"button\" |
3b0feb9b | 1958 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> |
48f0adb0 | 1959 | <input type=\"submit\" class=\"button\" |
3b0feb9b AD |
1960 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; |
1961 | } | |
48f0adb0 | 1962 | } else { |
3b0feb9b | 1963 | print "<p>No labels defined.</p>"; |
48f0adb0 AD |
1964 | } |
1965 | } | |
1966 | ||
e828e31e AD |
1967 | if ($op == "error") { |
1968 | print "<div width=\"100%\" align='center'>"; | |
1969 | $msg = $_GET["msg"]; | |
1970 | print $msg; | |
1971 | print "</div>"; | |
1972 | } | |
1973 | ||
7dc66a61 AD |
1974 | if ($op == "help") { |
1975 | print "<html><head> | |
1976 | <title>Tiny Tiny RSS : Help</title> | |
1977 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
1978 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
7dc66a61 AD |
1979 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
1980 | </head><body>"; | |
1981 | ||
1982 | $tid = sprintf("%d", $_GET["tid"]); | |
1983 | ||
1984 | /* FIXME this badly needs real implementation */ | |
1985 | ||
1986 | print "<div class='helpResponse'>"; | |
1987 | ||
1988 | ?> | |
1989 | ||
1990 | <h1>Help for SQL expressions</h1> | |
1991 | ||
1992 | <h2>Description</h2> | |
1993 | ||
1994 | <p>The «SQL expression» is added to WHERE clause of | |
d1f948d1 | 1995 | view feed query. You can match on ttrss_entries table fields |
7dc66a61 AD |
1996 | and even use subselect to query additional information. This |
1997 | functionality is considered to be advanced and requires basic | |
1998 | understanding of SQL.</p> | |
1999 | ||
2000 | <h2>Examples</h2> | |
2001 | ||
2002 | <pre>unread = true</pre> | |
2003 | ||
2004 | Matches all unread articles | |
2005 | ||
2006 | <pre>title like '%Linux%'</pre> | |
2007 | ||
2008 | Matches all articles which mention Linux in the title. You get the idea. | |
2009 | ||
2010 | <p>See the database schema included in the distribution package for gruesome | |
2011 | details.</p> | |
2012 | ||
2013 | <? | |
2014 | ||
2015 | print "<div align='center'> | |
2016 | <a class=\"helpLink\" | |
2017 | href=\"javascript:window.close()\">(Close this window)</a></div>"; | |
2018 | ||
2019 | print "</div>"; | |
2020 | ||
2021 | print "</body></html>"; | |
2022 | ||
2023 | } | |
2024 | ||
f84a97a3 AD |
2025 | if ($op == "dlg") { |
2026 | $id = $_GET["id"]; | |
6de5d056 | 2027 | $param = $_GET["param"]; |
f84a97a3 AD |
2028 | |
2029 | if ($id == "quickAddFeed") { | |
033e47e0 AD |
2030 | print "Feed URL: <input |
2031 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
2032 | id=\"qafInput\"> | |
f84a97a3 AD |
2033 | <input class=\"button\" |
2034 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> | |
2035 | <input class=\"button\" | |
2036 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2037 | value=\"Cancel\">"; | |
2038 | } | |
6de5d056 AD |
2039 | |
2040 | if ($id == "quickDelFeed") { | |
2041 | ||
2042 | $param = db_escape_string($param); | |
2043 | ||
2044 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
2045 | ||
2046 | if ($result) { | |
2047 | ||
2048 | $f_title = db_fetch_result($result, 0, "title"); | |
2049 | ||
2050 | print "Remove current feed ($f_title)? | |
2051 | <input class=\"button\" | |
2052 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
2053 | <input class=\"button\" | |
2054 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2055 | value=\"Cancel\">"; | |
2056 | } else { | |
2057 | print "Error: Feed $param not found. | |
2058 | <input class=\"button\" | |
2059 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2060 | value=\"Cancel\">"; | |
2061 | } | |
2062 | } | |
2063 | ||
033e47e0 AD |
2064 | if ($id == "search") { |
2065 | ||
2066 | print "<input id=\"searchbox\" class=\"extSearch\" | |
2067 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
2068 | onchange=\"javascript:search()\"> | |
2069 | <select id=\"searchmodebox\"> | |
2070 | <option selected>All feeds</option> | |
2071 | <option>This feed</option> | |
2072 | </select> | |
2073 | <input type=\"submit\" | |
2074 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
2075 | <input class=\"button\" | |
2076 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
2077 | value=\"Close\">"; | |
2078 | ||
2079 | } | |
2080 | ||
f84a97a3 AD |
2081 | } |
2082 | ||
a2770077 AD |
2083 | // update feeds of all users, may be used anonymously |
2084 | if ($op == "globalUpdateFeeds") { | |
2085 | ||
2086 | $result = db_query($link, "SELECT id FROM ttrss_users"); | |
2087 | ||
2088 | while ($line = db_fetch_assoc($result)) { | |
2089 | $user_id = $line["id"]; | |
2090 | // print "<!-- updating feeds of uid $user_id -->"; | |
2091 | update_all_feeds($link, false, $user_id); | |
2092 | } | |
e65af9c1 | 2093 | |
a2770077 AD |
2094 | print "<rpc-reply> |
2095 | <message msg=\"All feeds updated\"/> | |
2096 | </rpc-reply>"; | |
e65af9c1 AD |
2097 | |
2098 | } | |
2099 | ||
77e96719 AD |
2100 | if ($op == "pref-prefs") { |
2101 | ||
b1895692 | 2102 | $subop = $_REQUEST["subop"]; |
77e96719 AD |
2103 | |
2104 | if ($subop == "Save configuration") { | |
2105 | ||
d2892032 AD |
2106 | if (WEB_DEMO_MODE) { |
2107 | header("Location: prefs.php"); | |
2108 | return; | |
2109 | } | |
01d68cf9 | 2110 | |
93cb4442 AD |
2111 | $_SESSION["prefs_op_result"] = "save-config"; |
2112 | ||
77e96719 AD |
2113 | foreach (array_keys($_POST) as $pref_name) { |
2114 | ||
2115 | $pref_name = db_escape_string($pref_name); | |
2116 | $value = db_escape_string($_POST[$pref_name]); | |
2117 | ||
2118 | $result = db_query($link, "SELECT type_name | |
2119 | FROM ttrss_prefs,ttrss_prefs_types | |
2120 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
2121 | ||
2122 | if (db_num_rows($result) > 0) { | |
2123 | ||
2124 | $type_name = db_fetch_result($result, 0, "type_name"); | |
2125 | ||
5da169d9 AD |
2126 | // print "$pref_name : $type_name : $value<br>"; |
2127 | ||
77e96719 | 2128 | if ($type_name == "bool") { |
5da169d9 | 2129 | if ($value == "1") { |
77e96719 AD |
2130 | $value = "true"; |
2131 | } else { | |
2132 | $value = "false"; | |
2133 | } | |
2134 | } else if ($type_name == "integer") { | |
2135 | $value = sprintf("%d", $value); | |
2136 | } | |
2137 | ||
2138 | // print "$pref_name : $type_name : $value<br>"; | |
2139 | ||
ff485f1d AD |
2140 | db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' |
2141 | WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); | |
77e96719 AD |
2142 | |
2143 | } | |
2144 | ||
2145 | header("Location: prefs.php"); | |
2146 | ||
2147 | } | |
2148 | ||
b1895692 AD |
2149 | } else if ($subop == "getHelp") { |
2150 | ||
2151 | $pref_name = db_escape_string($_GET["pn"]); | |
2152 | ||
2153 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
2154 | WHERE pref_name = '$pref_name'"); | |
2155 | ||
2156 | if (db_num_rows($result) > 0) { | |
2157 | $help_text = db_fetch_result($result, 0, "help_text"); | |
2158 | print $help_text; | |
2159 | } else { | |
2160 | print "Unknown option: $pref_name"; | |
2161 | } | |
2162 | ||
1c7f75ed AD |
2163 | } else if ($subop == "Change password") { |
2164 | ||
d2892032 AD |
2165 | if (WEB_DEMO_MODE) { |
2166 | header("Location: prefs.php"); | |
2167 | return; | |
2168 | } | |
1c7f75ed AD |
2169 | |
2170 | $old_pw = $_POST["OLD_PASSWORD"]; | |
2171 | $new_pw = $_POST["OLD_PASSWORD"]; | |
2172 | ||
2173 | $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]); | |
2174 | $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]); | |
2175 | ||
2176 | $active_uid = $_SESSION["uid"]; | |
2177 | ||
2178 | if ($old_pw && $new_pw) { | |
2179 | ||
2180 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
2181 | ||
2182 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
2183 | id = '$active_uid' AND (pwd_hash = '$old_pw' OR | |
2184 | pwd_hash = '$old_pw_hash')"); | |
2185 | ||
2186 | if (db_num_rows($result) == 1) { | |
2187 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
2188 | WHERE id = '$active_uid'"); | |
b791095d AD |
2189 | |
2190 | $_SESSION["pwd_change_result"] = "ok"; | |
2191 | } else { | |
2192 | $_SESSION["pwd_change_result"] = "failed"; | |
1c7f75ed AD |
2193 | } |
2194 | } | |
2195 | ||
2196 | header("Location: prefs.php"); | |
b791095d | 2197 | |
77e96719 AD |
2198 | } else if ($subop == "Reset to defaults") { |
2199 | ||
d2892032 AD |
2200 | if (WEB_DEMO_MODE) { |
2201 | header("Location: prefs.php"); | |
2202 | return; | |
2203 | } | |
01d68cf9 | 2204 | |
93cb4442 AD |
2205 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
2206 | ||
e1aa0559 AD |
2207 | if (DB_TYPE == "pgsql") { |
2208 | db_query($link,"UPDATE ttrss_user_prefs | |
2209 | SET value = ttrss_prefs.def_value | |
2210 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
2211 | ttrss_prefs.pref_name = ttrss_user_prefs.pref_name"); | |
2212 | } else { | |
2213 | db_query($link, "DELETE FROM ttrss_user_prefs | |
2214 | WHERE owner_uid = ".$_SESSION["uid"]); | |
2215 | initialize_user_prefs($link, $_SESSION["uid"]); | |
2216 | } | |
5da169d9 | 2217 | |
77e96719 AD |
2218 | header("Location: prefs.php"); |
2219 | ||
2220 | } else { | |
2221 | ||
7d4c898a | 2222 | if (!SINGLE_USER_MODE) { |
1c7f75ed | 2223 | |
a029d530 AD |
2224 | $result = db_query($link, "SELECT id FROM ttrss_users |
2225 | WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR | |
2226 | pwd_hash = 'SHA1:".sha1("password")."')"); | |
2227 | ||
2228 | if (db_num_rows($result) != 0) { | |
b791095d | 2229 | print "<div class=\"warning\"> |
a029d530 AD |
2230 | Your password is at default value, please change it. |
2231 | </div>"; | |
2232 | } | |
2233 | ||
b791095d AD |
2234 | if ($_SESSION["pwd_change_result"] == "failed") { |
2235 | print "<div class=\"warning\"> | |
2236 | There was an error while changing your password. | |
2237 | </div>"; | |
2238 | } | |
2239 | ||
2240 | if ($_SESSION["pwd_change_result"] == "ok") { | |
2241 | print "<div class=\"notice\"> | |
2242 | Password changed successfully. | |
2243 | </div>"; | |
2244 | } | |
2245 | ||
2246 | $_SESSION["pwd_change_result"] = ""; | |
2247 | ||
93cb4442 AD |
2248 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { |
2249 | print "<div class=\"notice\"> | |
2250 | Your configuration was reset to defaults. | |
2251 | </div>"; | |
2252 | } | |
2253 | ||
2254 | if ($_SESSION["prefs_op_result"] == "save-config") { | |
2255 | print "<div class=\"notice\"> | |
2256 | Your configuration was saved successfully. | |
2257 | </div>"; | |
2258 | } | |
2259 | ||
2260 | $_SESSION["prefs_op_result"] = ""; | |
2261 | ||
7d4c898a AD |
2262 | print "<form action=\"backend.php\" method=\"POST\">"; |
2263 | ||
2264 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
2265 | print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>"; | |
2266 | ||
2267 | print "<tr><td width=\"40%\">Old password</td>"; | |
2268 | print "<td><input class=\"editbox\" type=\"password\" | |
2269 | name=\"OLD_PASSWORD\"></td></tr>"; | |
2270 | ||
2271 | print "<tr><td width=\"40%\">New password</td>"; | |
2272 | ||
2273 | print "<td><input class=\"editbox\" type=\"password\" | |
2274 | name=\"NEW_PASSWORD\"></td></tr>"; | |
2275 | ||
2276 | print "</table>"; | |
2277 | ||
2278 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
2279 | ||
2280 | print "<p><input class=\"button\" type=\"submit\" | |
2281 | value=\"Change password\" name=\"subop\">"; | |
2282 | ||
2283 | print "</form>"; | |
1c7f75ed | 2284 | |
7d4c898a | 2285 | } |
1c7f75ed | 2286 | |
77e96719 | 2287 | $result = db_query($link, "SELECT |
ff485f1d | 2288 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, |
77e96719 | 2289 | section_name,def_value |
ff485f1d | 2290 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
77e96719 | 2291 | WHERE type_id = ttrss_prefs_types.id AND |
ff485f1d | 2292 | section_id = ttrss_prefs_sections.id AND |
a2411bd9 AD |
2293 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
2294 | owner_uid = ".$_SESSION["uid"]." | |
650bc435 | 2295 | ORDER BY section_id,short_desc"); |
77e96719 AD |
2296 | |
2297 | print "<form action=\"backend.php\" method=\"POST\">"; | |
2298 | ||
77e96719 AD |
2299 | $lnum = 0; |
2300 | ||
2301 | $active_section = ""; | |
2302 | ||
2303 | while ($line = db_fetch_assoc($result)) { | |
2304 | ||
2305 | if ($active_section != $line["section_name"]) { | |
59a654ba AD |
2306 | |
2307 | if ($active_section != "") { | |
1c7f75ed | 2308 | print "</table>"; |
59a654ba | 2309 | } |
1c7f75ed AD |
2310 | |
2311 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
59a654ba AD |
2312 | |
2313 | $active_section = $line["section_name"]; | |
2314 | ||
77e96719 | 2315 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; |
59a654ba AD |
2316 | // print "<tr class=\"title\"> |
2317 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
7268adf7 AD |
2318 | |
2319 | $lnum = 0; | |
77e96719 AD |
2320 | } |
2321 | ||
650bc435 | 2322 | // $class = ($lnum % 2) ? "even" : "odd"; |
77e96719 | 2323 | |
650bc435 | 2324 | print "<tr>"; |
77e96719 | 2325 | |
77e96719 AD |
2326 | $type_name = $line["type_name"]; |
2327 | $pref_name = $line["pref_name"]; | |
2328 | $value = $line["value"]; | |
2329 | $def_value = $line["def_value"]; | |
b1895692 AD |
2330 | $help_text = $line["help_text"]; |
2331 | ||
2332 | print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"]; | |
2333 | ||
2334 | if ($help_text) print "<div class=\"prefHelp\">$help_text</div>"; | |
2335 | ||
2336 | print "</td>"; | |
77e96719 AD |
2337 | |
2338 | print "<td>"; | |
2339 | ||
2340 | if ($type_name == "bool") { | |
2341 | // print_select($pref_name, $value, array("true", "false")); | |
2342 | ||
2343 | if ($value == "true") { | |
2344 | $value = "Yes"; | |
2345 | } else { | |
2346 | $value = "No"; | |
2347 | } | |
2348 | ||
2349 | print_radio($pref_name, $value, array("Yes", "No")); | |
2350 | ||
2351 | } else { | |
2352 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
2353 | } | |
2354 | ||
2355 | print "</td>"; | |
2356 | ||
2357 | print "</tr>"; | |
2358 | ||
2359 | $lnum++; | |
2360 | } | |
2361 | ||
2362 | print "</table>"; | |
2363 | ||
2364 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
2365 | ||
2366 | print "<p><input class=\"button\" type=\"submit\" | |
2367 | name=\"subop\" value=\"Save configuration\">"; | |
2368 | ||
2369 | print " <input class=\"button\" type=\"submit\" | |
2370 | name=\"subop\" value=\"Reset to defaults\"></p>"; | |
2371 | ||
2372 | print "</form>"; | |
2373 | ||
2374 | } | |
2375 | ||
2376 | } | |
2377 | ||
e6cb77a0 AD |
2378 | if ($op == "pref-users") { |
2379 | ||
2380 | $subop = $_GET["subop"]; | |
2381 | ||
2382 | if ($subop == "editSave") { | |
2383 | ||
2384 | if (!WEB_DEMO_MODE) { | |
2385 | ||
2386 | $login = db_escape_string($_GET["l"]); | |
2387 | $uid = db_escape_string($_GET["id"]); | |
2388 | $access_level = sprintf("%d", $_GET["al"]); | |
2389 | ||
2390 | db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'"); | |
2391 | ||
2392 | } | |
2393 | } else if ($subop == "remove") { | |
2394 | ||
2395 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
2396 | ||
2397 | $ids = split(",", $_GET["ids"]); | |
2398 | ||
2399 | foreach ($ids as $id) { | |
2400 | db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]); | |
2401 | ||
2402 | } | |
2403 | } | |
2404 | } else if ($subop == "add") { | |
2405 | ||
2406 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
2407 | ||
b6b535ca | 2408 | $login = db_escape_string(trim($_GET["login"])); |
e6cb77a0 AD |
2409 | $tmp_user_pwd = make_password(8); |
2410 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
2411 | ||
2412 | db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level) | |
2413 | VALUES ('$login', '$pwd_hash', 0)"); | |
2414 | ||
2415 | ||
2416 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
2417 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
2418 | ||
2419 | if (db_num_rows($result) == 1) { | |
2420 | ||
2421 | $new_uid = db_fetch_result($result, 0, "id"); | |
2422 | ||
2423 | print "<div class=\"notice\">Added user <b>".$_GET["login"]. | |
2424 | "</b> with password <b>$tmp_user_pwd</b>.</div>"; | |
2425 | ||
2426 | initialize_user($link, $new_uid); | |
2427 | ||
2428 | } else { | |
2429 | ||
2430 | print "<div class=\"warning\">Error while adding user <b>". | |
2431 | $_GET["login"].".</b></div>"; | |
2432 | ||
2433 | } | |
2434 | } | |
2435 | } else if ($subop == "resetPass") { | |
2436 | ||
2437 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
2438 | ||
2439 | $uid = db_escape_string($_GET["id"]); | |
2440 | ||
2441 | $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'"); | |
2442 | ||
2443 | $login = db_fetch_result($result, 0, "login"); | |
2444 | $tmp_user_pwd = make_password(8); | |
2445 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
2446 | ||
2447 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
2448 | WHERE id = '$uid'"); | |
2449 | ||
2450 | print "<div class=\"notice\">Changed password of | |
2451 | user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>"; | |
2452 | ||
2453 | } | |
2454 | } | |
2455 | ||
2c7070b5 AD |
2456 | print "<div class=\"prefGenericAddBox\"> |
2457 | <input id=\"uadd_box\" size=\"40\"> "; | |
e6cb77a0 | 2458 | |
2c7070b5 AD |
2459 | print"<input type=\"submit\" class=\"button\" |
2460 | onclick=\"javascript:addUser()\" value=\"Add user\"></div>"; | |
e6cb77a0 AD |
2461 | |
2462 | $result = db_query($link, "SELECT | |
fe99ab12 AD |
2463 | id,login,access_level, |
2464 | SUBSTRING(last_login,1,16) as last_login | |
e6cb77a0 AD |
2465 | FROM |
2466 | ttrss_users | |
2467 | ORDER by login"); | |
2468 | ||
2317ffaa | 2469 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; |
1a7572cb | 2470 | |
e6cb77a0 AD |
2471 | print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">"; |
2472 | ||
2473 | print "<tr class=\"title\"> | |
f6f32198 AD |
2474 | <td width=\"5%\">Select</td> |
2475 | <td width='30%'>Username</td> | |
2476 | <td width='30%'>Access Level</td> | |
2477 | <td width='30%'>Last login</td></tr>"; | |
e6cb77a0 AD |
2478 | |
2479 | $lnum = 0; | |
2480 | ||
2481 | while ($line = db_fetch_assoc($result)) { | |
2482 | ||
2483 | $class = ($lnum % 2) ? "even" : "odd"; | |
2484 | ||
2485 | $uid = $line["id"]; | |
2486 | $edit_uid = $_GET["id"]; | |
2487 | ||
2488 | if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) { | |
2489 | $class .= "Grayed"; | |
2490 | } | |
2491 | ||
2492 | print "<tr class=\"$class\" id=\"UMRR-$uid\">"; | |
2493 | ||
2494 | $line["login"] = htmlspecialchars($line["login"]); | |
2495 | ||
2496 | if ($uid == $_SESSION["uid"]) { | |
2497 | ||
2498 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2499 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
2500 | ||
2501 | print "<td>".$line["login"]."</td>"; | |
2502 | print "<td>".$line["access_level"]."</td>"; | |
e6cb77a0 AD |
2503 | |
2504 | } else if (!$edit_uid || $subop != "edit") { | |
2505 | ||
2506 | print "<td><input onclick='toggleSelectRow(this);' | |
1a7572cb | 2507 | type=\"checkbox\" id=\"UMCHK-$uid\"></td>"; |
e6cb77a0 AD |
2508 | |
2509 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
2510 | $line["login"] . "</td>"; | |
2511 | ||
2512 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
2513 | $line["access_level"] . "</td>"; | |
2514 | ||
2515 | } else if ($uid != $edit_uid) { | |
2516 | ||
2517 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2518 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
2519 | ||
2520 | print "<td>".$line["login"]."</td>"; | |
2521 | print "<td>".$line["access_level"]."</td>"; | |
2522 | ||
2523 | } else { | |
2524 | ||
2525 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2526 | ||
2527 | print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"]. | |
2528 | "\"></td>"; | |
2529 | ||
2530 | print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"]. | |
2531 | "\"></td>"; | |
2532 | ||
2533 | } | |
2534 | ||
f6f32198 AD |
2535 | print "<td>".$line["last_login"]."</td>"; |
2536 | ||
e6cb77a0 AD |
2537 | print "</tr>"; |
2538 | ||
2539 | ++$lnum; | |
2540 | } | |
2541 | ||
2542 | print "</table>"; | |
2543 | ||
2544 | print "<p>"; | |
2545 | ||
2546 | if ($subop == "edit") { | |
2547 | print "Edit label: | |
2548 | <input type=\"submit\" class=\"button\" | |
2549 | onclick=\"javascript:userEditCancel()\" value=\"Cancel\"> | |
2550 | <input type=\"submit\" class=\"button\" | |
2551 | onclick=\"javascript:userEditSave()\" value=\"Save\">"; | |
2552 | ||
2553 | } else { | |
2554 | ||
2555 | print " | |
2556 | Selection: | |
2557 | <input type=\"submit\" class=\"button\" | |
717f5e64 | 2558 | onclick=\"javascript:selectedUserDetails()\" value=\"User details\"> |
e6cb77a0 AD |
2559 | <input type=\"submit\" class=\"button\" |
2560 | onclick=\"javascript:editSelectedUser()\" value=\"Edit\"> | |
2561 | <input type=\"submit\" class=\"button\" | |
717f5e64 AD |
2562 | onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\"> |
2563 | <input type=\"submit\" class=\"button\" | |
2564 | onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">"; | |
2565 | ||
2566 | } | |
2567 | } | |
2568 | ||
2569 | if ($op == "user-details") { | |
2570 | ||
2571 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { | |
2572 | return; | |
2573 | } | |
2574 | ||
1a7572cb | 2575 | /* print "<html><head> |
717f5e64 AD |
2576 | <title>Tiny Tiny RSS : User Details</title> |
2577 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
2578 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
1a7572cb | 2579 | </head><body>"; */ |
717f5e64 AD |
2580 | |
2581 | $uid = sprintf("%d", $_GET["id"]); | |
2582 | ||
c6c3a07f | 2583 | print "<div class='infoBoxContents'>"; |
717f5e64 | 2584 | |
fe99ab12 AD |
2585 | $result = db_query($link, "SELECT login, |
2586 | SUBSTRING(last_login,1,16) AS last_login, | |
2587 | access_level, | |
c6c3a07f AD |
2588 | (SELECT COUNT(int_id) FROM ttrss_user_entries |
2589 | WHERE owner_uid = id) AS stored_articles | |
717f5e64 AD |
2590 | FROM ttrss_users |
2591 | WHERE id = '$uid'"); | |
2592 | ||
2593 | if (db_num_rows($result) == 0) { | |
2594 | print "<h1>User not found</h1>"; | |
2595 | return; | |
2596 | } | |
2597 | ||
2598 | print "<h1>User Details</h1>"; | |
2599 | ||
2600 | print "<table width='100%'>"; | |
2601 | ||
2602 | $login = db_fetch_result($result, 0, "login"); | |
2603 | $last_login = db_fetch_result($result, 0, "last_login"); | |
2604 | $access_level = db_fetch_result($result, 0, "access_level"); | |
c6c3a07f | 2605 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); |
717f5e64 AD |
2606 | |
2607 | print "<tr><td>Username</td><td>$login</td></tr>"; | |
2608 | print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
2609 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
c6c3a07f | 2610 | print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>"; |
717f5e64 AD |
2611 | |
2612 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
2613 | WHERE owner_uid = '$uid'"); | |
2614 | ||
2615 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
2616 | ||
2617 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; | |
2618 | ||
5d15d3ea | 2619 | /* $result = db_query($link, "SELECT |
717f5e64 | 2620 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size |
c6c3a07f AD |
2621 | FROM ttrss_user_entries,ttrss_entries |
2622 | WHERE owner_uid = '$uid' AND ref_id = id"); | |
717f5e64 | 2623 | |
d9f115c3 | 2624 | $db_size = round(db_fetch_result($result, 0, "db_size") / 1024); |
717f5e64 | 2625 | |
c6c3a07f | 2626 | print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */ |
717f5e64 AD |
2627 | |
2628 | print "</table>"; | |
2629 | ||
2630 | print "<h1>Subscribed feeds</h1>"; | |
2631 | ||
2632 | $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds | |
d9f115c3 | 2633 | WHERE owner_uid = '$uid' ORDER BY title"); |
717f5e64 AD |
2634 | |
2635 | print "<ul class=\"nomarks\">"; | |
2636 | ||
2637 | while ($line = db_fetch_assoc($result)) { | |
2638 | ||
2639 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
2640 | ||
2641 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
6c56687e | 2642 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; |
717f5e64 | 2643 | } else { |
5951ded1 | 2644 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; |
717f5e64 AD |
2645 | } |
2646 | ||
2647 | print "<li>$feed_icon <a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>"; | |
e6cb77a0 | 2648 | } |
717f5e64 AD |
2649 | |
2650 | print "</ul>"; | |
2651 | ||
717f5e64 AD |
2652 | print "</div>"; |
2653 | ||
1a7572cb AD |
2654 | print "<div align='center'> |
2655 | <input type='submit' class='button' | |
c6c3a07f | 2656 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; |
1a7572cb AD |
2657 | |
2658 | // print "</body></html>"; | |
717f5e64 | 2659 | |
e6cb77a0 AD |
2660 | } |
2661 | ||
c6c3a07f AD |
2662 | if ($op == "feed-details") { |
2663 | ||
2664 | $feed_id = $_GET["id"]; | |
2665 | ||
2666 | $result = db_query($link, | |
2667 | "SELECT | |
f324892e | 2668 | title,feed_url,last_updated,icon_url,site_url, |
c6c3a07f AD |
2669 | (SELECT COUNT(int_id) FROM ttrss_user_entries |
2670 | WHERE feed_id = id) AS total, | |
2671 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
2672 | WHERE feed_id = id AND unread = true) AS unread, | |
2673 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
2674 | WHERE feed_id = id AND marked = true) AS marked | |
2675 | FROM ttrss_feeds | |
2676 | WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]); | |
2677 | ||
2678 | if (db_num_rows($result) == 0) return; | |
2679 | ||
2680 | $title = db_fetch_result($result, 0, "title"); | |
2681 | $last_updated = db_fetch_result($result, 0, "last_updated"); | |
2682 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
4fec9fd7 | 2683 | $icon_url = db_fetch_result($result, 0, "icon_url"); |
c6c3a07f AD |
2684 | $total = db_fetch_result($result, 0, "total"); |
2685 | $unread = db_fetch_result($result, 0, "unread"); | |
2686 | $marked = db_fetch_result($result, 0, "marked"); | |
f324892e | 2687 | $site_url = db_fetch_result($result, 0, "site_url"); |
4fec9fd7 AD |
2688 | |
2689 | $result = db_query($link, "SELECT COUNT(id) AS subscribed | |
2690 | FROM ttrss_feeds WHERE feed_url = '$feed_url'"); | |
2691 | ||
2692 | $subscribed = db_fetch_result($result, 0, "subscribed"); | |
2693 | ||
2694 | print "<div class=\"infoBoxContents\">"; | |
2695 | ||
2696 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
2697 | ||
2698 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
2699 | $feed_icon = "<img width=\"16\" height=\"16\" | |
2700 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
2701 | } else { | |
2702 | $feed_icon = ""; | |
2703 | } | |
2704 | ||
2705 | print "<h1>$feed_icon $title</h1>"; | |
c6c3a07f AD |
2706 | |
2707 | print "<table width='100%'>"; | |
2708 | ||
f324892e AD |
2709 | if ($site_url) { |
2710 | print "<tr><td width='30%'>Link</td> | |
2711 | <td><a href=\"$site_url\">$site_url</a> | |
2712 | <a href=\"$feed_url\">(feed)</a></td> | |
2713 | </td></tr>"; | |
2714 | } else { | |
2715 | print "<tr><td width='30%'>Feed URL</td> | |
2716 | <td><a href=\"$feed_url\">$feed_url</a></td></tr>"; | |
2717 | } | |
c6c3a07f AD |
2718 | print "<tr><td>Last updated</td><td>$last_updated</td></tr>"; |
2719 | print "<tr><td>Total articles</td><td>$total</td></tr>"; | |
2720 | print "<tr><td>Unread articles</td><td>$unread</td></tr>"; | |
2721 | print "<tr><td>Starred articles</td><td>$marked</td></tr>"; | |
4fec9fd7 | 2722 | print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>"; |
c6c3a07f AD |
2723 | |
2724 | print "</table>"; | |
2725 | ||
bffdddd0 AD |
2726 | $result = db_query($link, "SELECT title, |
2727 | SUBSTRING(updated,1,16) AS updated,unread | |
bca02305 AD |
2728 | FROM ttrss_entries,ttrss_user_entries |
2729 | WHERE ref_id = id AND feed_id = '$feed_id' | |
c565e1ef | 2730 | ORDER BY date_entered DESC LIMIT 5"); |
c6c3a07f | 2731 | |
bca02305 AD |
2732 | if (db_num_rows($result) > 0) { |
2733 | ||
2734 | print "<h1>Latest headlines</h1>"; | |
c6c3a07f | 2735 | |
bca02305 AD |
2736 | print "<ul class=\"nomarks\">"; |
2737 | ||
2738 | while ($line = db_fetch_assoc($result)) { | |
c565e1ef AD |
2739 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
2740 | $line["title"] = "<b>" . $line["title"] . "</b>"; | |
2741 | } | |
bca02305 AD |
2742 | print "<li>" . $line["title"]. |
2743 | " <span class=\"insensitive\">(" .$line["updated"].")</span></li>"; | |
2744 | } | |
2745 | ||
2746 | print "</ul>"; | |
2747 | ||
2748 | print "</div>"; | |
2749 | ||
2750 | print "<div align='center'> | |
2751 | <input type='submit' class='button' | |
2752 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
2753 | } | |
c6c3a07f AD |
2754 | } |
2755 | ||
4b3dff6e | 2756 | db_close($link); |
1cd17194 | 2757 | ?> |
406d9489 AD |
2758 | |
2759 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
2760 |