]>
git.wh0rd.org - tt-rss.git/blob - backend.php
2 set_include_path(get_include_path() . PATH_SEPARATOR
.
3 dirname(__FILE__
) . "/include");
5 /* remove ill effects of magic quotes */
7 if (get_magic_quotes_gpc()) {
8 function stripslashes_deep($value) {
9 $value = is_array($value) ?
10 array_map('stripslashes_deep', $value) : stripslashes($value);
14 $_POST = array_map('stripslashes_deep', $_POST);
15 $_GET = array_map('stripslashes_deep', $_GET);
16 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
17 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
20 $op = $_REQUEST["op"];
21 @$method = $_REQUEST['subop'] ?
$_REQUEST['subop'] : $_REQUEST["method"];
26 $method = strtolower($method);
28 /* Public calls compatibility shim */
30 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
31 "fbexport", "logout", "pubsub");
33 if (array_search($op, $public_calls) !== false) {
34 header("Location: public.php?" . $_SERVER['QUERY_STRING']);
38 @$csrf_token = $_REQUEST['csrf_token'];
40 require_once "functions.php";
41 require_once "sessions.php";
42 require_once "sanity_check.php";
43 require_once "config.php";
44 require_once "db.php";
45 require_once "db-prefs.php";
47 no_cache_incantation();
51 $script_started = getmicrotime();
53 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
55 if (!init_connection($link)) return;
57 header("Content-Type: text/plain; charset=utf-8");
59 if (ENABLE_GZIP_OUTPUT
) {
60 ob_start("ob_gzhandler");
63 if (SINGLE_USER_MODE
) {
64 authenticate_user($link, "admin", null);
67 // TODO remove and handle within Handlers
69 if (!($_SESSION["uid"] && validate_session($link))) {
70 if ($op == 'pref-feeds' && $method == 'add') {
71 header("Content-Type: text/html");
72 login_sequence($link);
73 render_login_form($link);
75 header("Content-Type: text/plain");
76 print json_encode(array("error" => array("code" => 6)));
81 $purge_intervals = array(
82 0 => __("Use default"),
83 -1 => __("Never purge"),
84 5 => __("1 week old"),
85 14 => __("2 weeks old"),
86 31 => __("1 month old"),
87 60 => __("2 months old"),
88 90 => __("3 months old"));
90 $update_intervals = array(
91 0 => __("Default interval"),
92 -1 => __("Disable updates"),
93 15 => __("Each 15 minutes"),
94 30 => __("Each 30 minutes"),
96 240 => __("Each 4 hours"),
97 720 => __("Each 12 hours"),
99 10080 => __("Weekly"));
101 $update_intervals_nodefault = array(
102 -1 => __("Disable updates"),
103 15 => __("Each 15 minutes"),
104 30 => __("Each 30 minutes"),
106 240 => __("Each 4 hours"),
107 720 => __("Each 12 hours"),
109 10080 => __("Weekly"));
111 $update_methods = array(
114 2 => __("SimplePie"),
115 3 => __("Twitter OAuth"));
117 if (DEFAULT_UPDATE_METHOD
== "1") {
118 $update_methods[0] .= ' (SimplePie)';
120 $update_methods[0] .= ' (Magpie)';
123 $access_level_names = array(
125 5 => __("Power User"),
126 10 => __("Administrator"));
128 $error = sanity_check($link);
130 if ($error['code'] != 0 && $op != "logout") {
131 print json_encode(array("error" => $error));
135 function __autoload($class) {
136 $file = "classes/".strtolower(basename($class)).".php";
137 if (file_exists($file)) {
142 $op = str_replace("-", "_", $op);
144 if (class_exists($op)) {
145 $handler = new $op($link, $_REQUEST);
148 if (validate_csrf($csrf_token) ||
$handler->csrf_ignore($method)) {
149 if ($handler->before($method)) {
150 if ($method && method_exists($handler, $method)) {
157 header("Content-Type: text/plain");
158 print json_encode(array("error" => array("code" => 6)));
164 header("Content-Type: text/plain");
165 print json_encode(array("error" => array("code" => 7)));
167 // We close the connection to database.