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