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