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