2 set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
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 "sessions.php";
41 require_once "functions.php";
42 require_once "config.php";
43 require_once "db.php";
44 require_once "db-prefs.php";
46 no_cache_incantation();
50 $script_started = getmicrotime();
52 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
54 if (!init_connection($link)) return;
56 header("Content-Type: text/json; charset=utf-8");
58 if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
59 ob_start("ob_gzhandler");
62 if (SINGLE_USER_MODE) {
63 authenticate_user($link, "admin", null);
66 if ($_SESSION["uid"]) {
67 load_user_plugins($link, $_SESSION["uid"]);
70 $purge_intervals = array(
71 0 => __("Use default"),
72 -1 => __("Never purge"),
73 5 => __("1 week old"),
74 14 => __("2 weeks old"),
75 31 => __("1 month old"),
76 60 => __("2 months old"),
77 90 => __("3 months old"));
79 $update_intervals = array(
80 0 => __("Default interval"),
81 -1 => __("Disable updates"),
82 15 => __("Each 15 minutes"),
83 30 => __("Each 30 minutes"),
85 240 => __("Each 4 hours"),
86 720 => __("Each 12 hours"),
88 10080 => __("Weekly"));
90 $update_intervals_nodefault = array(
91 -1 => __("Disable updates"),
92 15 => __("Each 15 minutes"),
93 30 => __("Each 30 minutes"),
95 240 => __("Each 4 hours"),
96 720 => __("Each 12 hours"),
98 10080 => __("Weekly"));
100 $access_level_names = array(
102 5 => __("Power User"),
103 10 => __("Administrator"));
105 #$error = sanity_check($link);
107 #if ($error['code'] != 0 && $op != "logout") {
108 # print json_encode(array("error" => $error));
112 $op = str_replace("-", "_", $op);
115 $override = $pluginhost->lookup_handler($op, $method);
117 if (class_exists($op) || $override) {
120 $handler = $override;
122 $handler = new $op($link, $_REQUEST);
125 if ($handler && implements_interface($handler, 'IHandler')) {
126 if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
127 if ($handler->before($method)) {
128 if ($method && method_exists($handler, $method)) {
131 if (method_exists($handler, "catchall")) {
132 $handler->catchall($method);
138 header("Content-Type: text/json");
139 print json_encode(array("error" => array("code" => 6)));
143 header("Content-Type: text/json");
144 print json_encode(array("error" => array("code" => 6)));
150 header("Content-Type: text/json");
151 print json_encode(array("error" => array("code" => 7)));
153 // We close the connection to database.