]>
git.wh0rd.org - tt-rss.git/blob - backend.php
2 /* remove ill effects of magic quotes */
4 if (get_magic_quotes_gpc()) {
5 function stripslashes_deep($value) {
6 $value = is_array($value) ?
7 array_map('stripslashes_deep', $value) : stripslashes($value);
11 $_POST = array_map('stripslashes_deep', $_POST);
12 $_GET = array_map('stripslashes_deep', $_GET);
13 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
14 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
17 require_once "functions.php";
18 require_once "sessions.php";
19 require_once "modules/backend-rpc.php";
20 require_once "sanity_check.php";
21 require_once "config.php";
22 require_once "db.php";
23 require_once "db-prefs.php";
25 no_cache_incantation();
27 if (ENABLE_TRANSLATIONS
== true) {
31 $script_started = getmicrotime();
33 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
36 if (DB_TYPE
== "mysql") {
39 // PG seems to display its own errors just fine by default.
43 init_connection($link);
45 $op = $_REQUEST["op"];
46 $subop = $_REQUEST["subop"];
47 $mode = $_REQUEST["mode"];
49 $print_exec_time = false;
51 if ((!$op ||
$op == "rpc" ||
$op == "rss" ||
52 ($op == "view" && $mode != "zoom") ||
53 $op == "digestSend" ||
$op == "viewfeed" ||
$op == "publish" ||
54 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
55 header("Content-Type: application/xml; charset=utf-8");
57 if (ENABLE_GZIP_OUTPUT
) {
58 ob_start("ob_gzhandler");
62 if (!$_REQUEST["noxml"]) {
63 header("Content-Type: text/html; charset=utf-8");
65 header("Content-Type: text/plain; charset=utf-8");
70 header("Content-Type: application/xml");
71 print_error_xml(7); exit;
74 if (SINGLE_USER_MODE
) {
75 authenticate_user($link, "admin", null);
78 if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
79 && $op != "rss" && $op != "getUnread" && $op != "publish" && $op != "getProfiles") {
81 if ($op == "rpc" ||
$op == "viewfeed" ||
$op == "view") {
82 print_error_xml(6); die;
86 <p>Error: Not logged in.</p>
87 <script type=\"text/javascript\">
88 if (parent.window != 'undefined') {
89 parent.window.location = \"tt-rss.php\";
91 window.location = \"tt-rss.php\";
100 $purge_intervals = array(
101 0 => __("Use default"),
102 -1 => __("Never purge"),
103 5 => __("1 week old"),
104 14 => __("2 weeks old"),
105 31 => __("1 month old"),
106 60 => __("2 months old"),
107 90 => __("3 months old"));
109 $update_intervals = array(
110 0 => __("Default interval"),
111 -1 => __("Disable updates"),
112 15 => __("Each 15 minutes"),
113 30 => __("Each 30 minutes"),
115 240 => __("Each 4 hours"),
116 720 => __("Each 12 hours"),
118 10080 => __("Weekly"));
120 $update_intervals_nodefault = array(
121 -1 => __("Disable updates"),
122 15 => __("Each 15 minutes"),
123 30 => __("Each 30 minutes"),
125 240 => __("Each 4 hours"),
126 720 => __("Each 12 hours"),
128 10080 => __("Weekly"));
130 $update_methods = array(
133 2 => __("SimplePie"));
135 if (DEFAULT_UPDATE_METHOD
== "1") {
136 $update_methods[0] .= ' (SimplePie)';
138 $update_methods[0] .= ' (Magpie)';
141 $access_level_names = array(
143 5 => __("Power User"),
144 10 => __("Administrator"));
146 require_once "modules/pref-prefs.php";
147 require_once "modules/popup-dialog.php";
148 require_once "modules/help.php";
149 require_once "modules/pref-feeds.php";
150 require_once "modules/pref-filters.php";
151 require_once "modules/pref-labels.php";
152 require_once "modules/pref-users.php";
154 if (!sanity_check($link)) { return; }
156 switch($op) { // Select action according to $op value.
158 // Handle remote procedure calls.
159 handle_rpc_request($link);
163 if (ENABLE_GZIP_OUTPUT
) {
164 ob_start("ob_gzhandler");
167 $tags = $_REQUEST["tags"];
169 $subop = $_REQUEST["subop"];
173 db_query($link, "UPDATE ttrss_user_entries SET
174 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
175 ccache_zero_all($link, $_SESSION["uid"]);
180 $cat_id = db_escape_string($_REQUEST["cid"]);
181 toggle_collapse_cat($link, $cat_id);
186 db_query($link, "UPDATE ttrss_feed_categories
187 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
192 $corder = db_escape_string($_REQUEST["corder"]);
194 $cats = split(",", $corder);
196 for ($i = 0; $i < count($cats); $i++
) {
200 db_query($link, "UPDATE ttrss_feed_categories
201 SET order_id = '$i' WHERE id = '$cat_id' AND
202 owner_uid = " . $_SESSION["uid"]);
211 $_SESSION["viewfeed:counters_stamp"] = time();
213 outputFeedList($link, $tags);
218 $id = db_escape_string($_REQUEST["id"]);
219 $cids = split(",", db_escape_string($_REQUEST["cids"]));
220 $mode = db_escape_string($_REQUEST["mode"]);
221 $omode = db_escape_string($_REQUEST["omode"]);
223 $csync = $_REQUEST["csync"];
227 // in prefetch mode we only output requested cids, main article
228 // just gets marked as read (it already exists in client cache)
231 outputArticleXML($link, $id, false);
232 } else if ($mode == "zoom") {
233 outputArticleXML($link, $id, false, true, true);
235 catchupArticleById($link, $id, 0);
238 if (!$_SESSION["bw_limit"]) {
239 foreach ($cids as $cid) {
241 outputArticleXML($link, $cid, false, false);
246 // if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
248 if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
249 print "<counters><![CDATA[";
250 print json_encode(getAllCounters($link, $omode));
251 print "]]></counters>";
252 $_SESSION["view:counters_stamp"] = time();
260 $print_exec_time = true;
261 $timing_info = getmicrotime();
265 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
267 $omode = db_escape_string($_REQUEST["omode"]);
269 $feed = db_escape_string($_REQUEST["feed"]);
270 $subop = db_escape_string($_REQUEST["subop"]);
271 $view_mode = db_escape_string($_REQUEST["view_mode"]);
272 $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT");
273 @$cat_view = db_escape_string($_REQUEST["cat"]);
274 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
275 @$offset = db_escape_string($_REQUEST["skip"]);
276 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
277 $csync = $_REQUEST["csync"];
278 $order_by = db_escape_string($_REQUEST["order_by"]);
280 /* Feed -5 is a special case: it is used to display auxiliary information
281 * when there's nothing to load - e.g. no stuff in fresh feed */
284 generate_dashboard_feed($link);
289 /* Updating a label ccache means recalculating all of the caches
290 * so for performance reasons we don't do that here */
292 // if (time() - $_SESSION["viewfeed:ccache_update_stamp"] > 120) {
294 ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
296 $_SESSION["viewfeed:ccache_update_stamp"] = time();
299 set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
300 set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
301 set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
303 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
304 db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
305 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
308 if (!$next_unread_feed) {
309 print "<headlines id=\"$feed\" is_cat=\"$cat_view\"><![CDATA[";
311 print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\"><![CDATA[";
314 $override_order = false;
318 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
319 $override_order = "date_entered";
321 $override_order = "date_entered DESC";
326 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
327 $override_order = "title DESC, date_entered";
329 $override_order = "title, date_entered DESC";
334 if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
335 $override_order = "score, date_entered";
337 $override_order = "score DESC, date_entered DESC";
342 $ret = outputHeadlinesList($link, $feed, $subop,
343 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
344 $vgroup_last_feed, $override_order);
346 $topmost_article_ids = $ret[0];
347 $headlines_count = $ret[1];
348 $returned_feed = $ret[2];
349 $disable_cache = $ret[3];
350 $vgroup_last_feed = $ret[4];
352 print "]]></headlines>";
354 //print "<headlines-count value=\"$headlines_count\"/>";
355 //print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
357 $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
360 if ($headlines_unread == -1) {
361 $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
365 //print "<headlines-unread value=\"$headlines_unread\"/>";
366 //printf("<disable-cache value=\"%d\"/>", $disable_cache);
368 print "<headlines-info><![CDATA[";
370 $info = array("count" => (int) $headlines_count,
371 "vgroup_last_feed" => $vgroup_last_feed,
372 "unread" => (int) $headlines_unread,
373 "disable_cache" => (bool) $disable_cache);
375 print json_encode($info);
377 print "]]></headlines-info>";
379 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("10", $timing_info);
381 if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
383 foreach ($topmost_article_ids as $id) {
384 outputArticleXML($link, $id, $feed, false);
389 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
391 if (get_pref($link, 'COMBINED_DISPLAY_MODE') ||
$subop ||
392 time() - $_SESSION["viewfeed:counters_stamp"] > 5) {
394 print "<counters><![CDATA[";
395 print json_encode(getAllCounters($link, $omode, $feed));
396 print "]]></counters>";
397 $_SESSION["viewfeed:counters_stamp"] = time();
401 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
403 print_runtime_info($link);
409 module_pref_feeds($link);
413 module_pref_filters($link);
414 break; // pref-filters
417 module_pref_labels($link);
418 break; // pref-labels
421 module_pref_prefs($link);
425 module_pref_users($link);
426 break; // prefs-users
433 module_popup_dialog($link);
436 case "pref-pub-items":
437 module_pref_pub_items($link);
438 break; // pref-pub-items
440 case "globalUpdateFeeds":
441 // update feeds of all users, may be used anonymously
444 // Update all feeds needing a update.
445 update_daemon_common($link, 0, true, true);
449 <message msg=\"All feeds updated\"/>
451 break; // globalUpdateFeeds
453 case "pref-feed-browser":
454 module_pref_feed_browser($link);
455 break; // pref-feed-browser
458 $feed = db_escape_string($_REQUEST["id"]);
459 $key = db_escape_string($_REQUEST["key"]);
460 $is_cat = $_REQUEST["is_cat"] != false;
461 $limit = (int)db_escape_string($_REQUEST["limit"]);
463 $search = db_escape_string($_REQUEST["q"]);
464 $match_on = db_escape_string($_REQUEST["m"]);
465 $search_mode = db_escape_string($_REQUEST["smode"]);
466 $view_mode = db_escape_string($_REQUEST["view-mode"]);
468 if (SINGLE_USER_MODE
) {
469 authenticate_user($link, "admin", null);
472 if ($key && !$_SESSION["uid"]) {
473 $result = db_query($link, "SELECT owner_uid FROM
474 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
476 if (db_num_rows($result) == 1)
477 $_SESSION["uid"] = db_fetch_result($result, 0, "owner_uid");
481 if ($_SESSION["uid"]) {
482 generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
483 $search, $search_mode, $match_on, $view_mode);
488 $login = db_escape_string($_REQUEST["login"]);
489 $fresh = $_REQUEST["fresh"] == "1";
491 header("Content-Type: text/plain; charset=utf-8");
493 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
495 if (db_num_rows($result) == 1) {
496 $uid = db_fetch_result($result, 0, "id");
498 print getGlobalUnread($link, $uid);
502 print getFeedArticles($link, -3, false, true, $uid);
506 print "-1;User not found";
509 $print_exec_time = false;
513 header("Content-Type: text/plain");
514 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
515 $print_exec_time = false;
519 header("Content-Type: text/plain");
520 send_headlines_digests($link);
521 $print_exec_time = false;
525 $login = db_escape_string($_REQUEST["login"]);
526 $password = db_escape_string($_REQUEST["password"]);
528 if (authenticate_user($link, $login, $password)) {
529 $result = db_query($link, "SELECT * FROM ttrss_settings_profiles
530 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
532 print "<select style='width: 100%' name='profile'>";
534 print "<option value='0'>" . __("Default profile") . "</option>";
536 while ($line = db_fetch_assoc($result)) {
538 $title = $line["title"];
540 print "<option value='$id'>$title</option>";
549 } // Select action according to $op value.
551 // We close the connection to database.
555 <?php
if ($print_exec_time) { ?
>
556 <!-- <?php
echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->