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