]>
git.wh0rd.org - tt-rss.git/blob - backend.php
9dd4c6f55d33e59e4981abf72fe8f72ef6cf43ad
2 set_include_path(get_include_path() . PATH_SEPARATOR
. "include");
4 /* remove ill effects of magic quotes */
6 if (get_magic_quotes_gpc()) {
7 function stripslashes_deep($value) {
8 $value = is_array($value) ?
9 array_map('stripslashes_deep', $value) : stripslashes($value);
13 $_POST = array_map('stripslashes_deep', $_POST);
14 $_GET = array_map('stripslashes_deep', $_GET);
15 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
16 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
19 function __autoload($class) {
20 $file = "classes/".strtolower(basename($class)).".php";
21 if (file_exists($file)) {
26 $op = $_REQUEST["op"];
28 require_once "functions.php";
29 if ($op != "share") require_once "sessions.php";
30 require_once "sanity_check.php";
31 require_once "config.php";
32 require_once "db.php";
33 require_once "db-prefs.php";
35 no_cache_incantation();
39 $script_started = getmicrotime();
41 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
44 if (DB_TYPE
== "mysql") {
47 // PG seems to display its own errors just fine by default.
51 init_connection($link);
53 $method = $_REQUEST['subop'] ?
$_REQUEST['subop'] : $_REQUEST["method"];
55 header("Content-Type: text/plain; charset=utf-8");
57 if (ENABLE_GZIP_OUTPUT
) {
58 ob_start("ob_gzhandler");
61 if (SINGLE_USER_MODE
) {
62 authenticate_user($link, "admin", null);
65 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
66 "fbexport", "logout", "pubsub");
68 if (array_search($op, $public_calls) !== false) {
70 handle_public_request($link, $op);
73 } else if (!($_SESSION["uid"] && validate_session($link))) {
74 if ($op == 'pref-feeds' && $method == 'add') {
75 header("Content-Type: text/html");
76 login_sequence($link);
77 render_login_form($link);
79 header("Content-Type: text/plain");
80 print json_encode(array("error" => array("code" => 6)));
85 $purge_intervals = array(
86 0 => __("Use default"),
87 -1 => __("Never purge"),
88 5 => __("1 week old"),
89 14 => __("2 weeks old"),
90 31 => __("1 month old"),
91 60 => __("2 months old"),
92 90 => __("3 months old"));
94 $update_intervals = array(
95 0 => __("Default interval"),
96 -1 => __("Disable updates"),
97 15 => __("Each 15 minutes"),
98 30 => __("Each 30 minutes"),
100 240 => __("Each 4 hours"),
101 720 => __("Each 12 hours"),
103 10080 => __("Weekly"));
105 $update_intervals_nodefault = array(
106 -1 => __("Disable updates"),
107 15 => __("Each 15 minutes"),
108 30 => __("Each 30 minutes"),
110 240 => __("Each 4 hours"),
111 720 => __("Each 12 hours"),
113 10080 => __("Weekly"));
115 $update_methods = array(
118 2 => __("SimplePie"),
119 3 => __("Twitter OAuth"));
121 if (DEFAULT_UPDATE_METHOD
== "1") {
122 $update_methods[0] .= ' (SimplePie)';
124 $update_methods[0] .= ' (Magpie)';
127 $access_level_names = array(
129 5 => __("Power User"),
130 10 => __("Administrator"));
132 $error = sanity_check($link);
134 if ($error['code'] != 0 && $op != "logout") {
135 print json_encode(array("error" => $error));
139 $op = str_replace("-", "_", $op);
141 if (class_exists($op)) {
142 $handler = new $op($link, $_REQUEST);
145 if ($handler->before()) {
146 if ($method && method_exists($handler, $method)) {
148 } else if (method_exists($handler, 'index')) {
157 switch($op) { // Select action according to $op value.
160 require_once "modules/pref-filters.php";
161 module_pref_filters($link);
162 break; // pref-filters
164 case "pref_instances":
165 require_once "modules/pref-instances.php";
166 module_pref_instances($link);
167 break; // pref-instances
170 header("Content-Type: text/plain");
171 print json_encode(array("error" => array("code" => 7)));
173 } // Select action according to $op value.
175 // We close the connection to database.