]> git.wh0rd.org - tt-rss.git/blame - backend.php
move API to classes/
[tt-rss.git] / backend.php
CommitLineData
1d3a17c7 1<?php
107d0cf3
AD
2 set_include_path(get_include_path() . PATH_SEPARATOR . "include");
3
ce885e21
AD
4 /* remove ill effects of magic quotes */
5
5fa17372 6 if (get_magic_quotes_gpc()) {
c0793f64 7 function stripslashes_deep($value) {
009646d2 8 $value = is_array($value) ?
c0793f64
AD
9 array_map('stripslashes_deep', $value) : stripslashes($value);
10 return $value;
11 }
12
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);
ce885e21
AD
17 }
18
f9da2388 19 $op = $_REQUEST["op"];
5f0a3741
AD
20 @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
21
22 /* Public calls compatibility shim */
23
24 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
25 "fbexport", "logout", "pubsub");
26
27 if (array_search($op, $public_calls) !== false) {
28 header("Location: public.php?" . $_SERVER['QUERY_STRING']);
29 return;
30 }
f9da2388 31
fb074239 32 require_once "functions.php";
5f0a3741 33 require_once "sessions.php";
657770a0
AD
34 require_once "sanity_check.php";
35 require_once "config.php";
af106b0e
AD
36 require_once "db.php";
37 require_once "db-prefs.php";
657770a0 38
dc56b3b7 39 no_cache_incantation();
8d039718 40
7b26a148 41 startup_gettext();
dc56b3b7 42
7f0acba7
AD
43 $script_started = getmicrotime();
44
009646d2 45 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
7f0acba7 46
5f0a3741 47 if (!init_connection($link)) return;
3f363052
AD
48
49 header("Content-Type: text/plain; charset=utf-8");
262bd8ea 50
bd202c3f
AD
51 if (ENABLE_GZIP_OUTPUT) {
52 ob_start("ob_gzhandler");
53 }
54
9c883208
AD
55 if (SINGLE_USER_MODE) {
56 authenticate_user($link, "admin", null);
57 }
58
5f0a3741 59 // TODO remove and handle within Handlers
009646d2 60
5f0a3741 61 if (!($_SESSION["uid"] && validate_session($link))) {
1395083e 62 if ($op == 'pref-feeds' && $method == 'add') {
d0f73380
AD
63 header("Content-Type: text/html");
64 login_sequence($link);
65 render_login_form($link);
66 } else {
67 header("Content-Type: text/plain");
68 print json_encode(array("error" => array("code" => 6)));
69 }
009646d2 70 return;
262bd8ea 71 }
1c7f75ed 72
ad815c71 73 $purge_intervals = array(
d1db26aa
AD
74 0 => __("Use default"),
75 -1 => __("Never purge"),
76 5 => __("1 week old"),
77 14 => __("2 weeks old"),
78 31 => __("1 month old"),
79 60 => __("2 months old"),
80 90 => __("3 months old"));
ad815c71
AD
81
82 $update_intervals = array(
ecace165 83 0 => __("Default interval"),
d1db26aa 84 -1 => __("Disable updates"),
1e7cbe16 85 15 => __("Each 15 minutes"),
d1db26aa 86 30 => __("Each 30 minutes"),
505f2f0e
AD
87 60 => __("Hourly"),
88 240 => __("Each 4 hours"),
89 720 => __("Each 12 hours"),
90 1440 => __("Daily"),
91 10080 => __("Weekly"));
92
93 $update_intervals_nodefault = array(
94 -1 => __("Disable updates"),
95 15 => __("Each 15 minutes"),
96 30 => __("Each 30 minutes"),
d1db26aa
AD
97 60 => __("Hourly"),
98 240 => __("Each 4 hours"),
99 720 => __("Each 12 hours"),
100 1440 => __("Daily"),
101 10080 => __("Weekly"));
ad815c71 102
16211ddb 103 $update_methods = array(
ecace165 104 0 => __("Default"),
0dd9c0cf 105 1 => __("Magpie"),
009646d2 106 2 => __("SimplePie"),
b3009bcd 107 3 => __("Twitter OAuth"));
16211ddb 108
78a5c296 109 if (DEFAULT_UPDATE_METHOD == "1") {
16211ddb
AD
110 $update_methods[0] .= ' (SimplePie)';
111 } else {
112 $update_methods[0] .= ' (Magpie)';
113 }
114
3c5783b7 115 $access_level_names = array(
009646d2 116 0 => __("User"),
a88d37e5 117 5 => __("Power User"),
d1db26aa 118 10 => __("Administrator"));
3c5783b7 119
ebb948c2
AD
120 $error = sanity_check($link);
121
2376ad49 122 if ($error['code'] != 0 && $op != "logout") {
ebb948c2
AD
123 print json_encode(array("error" => $error));
124 return;
125 }
023fe037 126
5f0a3741
AD
127 function __autoload($class) {
128 $file = "classes/".strtolower(basename($class)).".php";
129 if (file_exists($file)) {
130 require $file;
131 }
132 }
133
afcfe6ca
AD
134 $op = str_replace("-", "_", $op);
135
d5112468
AD
136 if (class_exists($op)) {
137 $handler = new $op($link, $_REQUEST);
45004d43 138
d5112468 139 if ($handler) {
de8260cb 140 if ($handler->before($method)) {
3f363052
AD
141 if ($method && method_exists($handler, $method)) {
142 $handler->$method();
143 } else if (method_exists($handler, 'index')) {
144 $handler->index();
d5112468 145 }
3f363052
AD
146 $handler->after();
147 return;
d5112468
AD
148 }
149 }
150 }
151
5f0a3741
AD
152 header("Content-Type: text/plain");
153 print json_encode(array("error" => array("code" => 7)));
ba7e88e5 154
45004d43 155 // We close the connection to database.
4b3dff6e 156 db_close($link);
1cd17194 157?>