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 $op = $_REQUEST["op"];
20 @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
22 /* Public calls compatibility shim */
24 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
25 "fbexport", "logout", "pubsub");
27 if (array_search($op, $public_calls) !== false) {
28 header("Location: public.php?" . $_SERVER['QUERY_STRING']);
32 require_once "functions.php";
33 require_once "sessions.php";
34 require_once "sanity_check.php";
35 require_once "config.php";
36 require_once "db.php";
37 require_once "db-prefs.php";
39 no_cache_incantation();
43 $script_started = getmicrotime();
45 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
47 if (!init_connection($link)) return;
49 header("Content-Type: text/plain; charset=utf-8");
51 if (ENABLE_GZIP_OUTPUT) {
52 ob_start("ob_gzhandler");
55 if (SINGLE_USER_MODE) {
56 authenticate_user($link, "admin", null);
59 // TODO remove and handle within Handlers
61 if (!($_SESSION["uid"] && validate_session($link))) {
62 if ($op == 'pref-feeds' && $method == 'add') {
63 header("Content-Type: text/html");
64 login_sequence($link);
65 render_login_form($link);
67 header("Content-Type: text/plain");
68 print json_encode(array("error" => array("code" => 6)));
73 $purge_intervals = array(
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"));
82 $update_intervals = array(
83 0 => __("Default interval"),
84 -1 => __("Disable updates"),
85 15 => __("Each 15 minutes"),
86 30 => __("Each 30 minutes"),
88 240 => __("Each 4 hours"),
89 720 => __("Each 12 hours"),
91 10080 => __("Weekly"));
93 $update_intervals_nodefault = array(
94 -1 => __("Disable updates"),
95 15 => __("Each 15 minutes"),
96 30 => __("Each 30 minutes"),
98 240 => __("Each 4 hours"),
99 720 => __("Each 12 hours"),
101 10080 => __("Weekly"));
103 $update_methods = array(
106 2 => __("SimplePie"),
107 3 => __("Twitter OAuth"));
109 if (DEFAULT_UPDATE_METHOD == "1") {
110 $update_methods[0] .= ' (SimplePie)';
112 $update_methods[0] .= ' (Magpie)';
115 $access_level_names = array(
117 5 => __("Power User"),
118 10 => __("Administrator"));
120 $error = sanity_check($link);
122 if ($error['code'] != 0 && $op != "logout") {
123 print json_encode(array("error" => $error));
127 function __autoload($class) {
128 $file = "classes/".strtolower(basename($class)).".php";
129 if (file_exists($file)) {
134 $op = str_replace("-", "_", $op);
136 if (class_exists($op)) {
137 $handler = new $op($link, $_REQUEST);
140 if ($handler->before()) {
141 if ($method && method_exists($handler, $method)) {
143 } else if (method_exists($handler, 'index')) {
152 header("Content-Type: text/plain");
153 print json_encode(array("error" => array("code" => 7)));
155 // We close the connection to database.