Passed
Push — master ( 5a5c41...fade3b )
by Cody
04:50 queued 10s
created

backend.php (2 issues)

1
<?php
2
	set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
3
		get_include_path());
4
5
	$op = $_REQUEST["op"];
6
	@$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
7
8
	if (!$method)
9
		$method = 'index';
10
	else
11
		$method = strtolower($method);
12
13
	/* Public calls compatibility shim */
14
15
	$public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
16
		"fbexport", "logout", "pubsub");
17
18
	if (array_search($op, $public_calls) !== false) {
19
		header("Location: public.php?" . $_SERVER['QUERY_STRING']);
20
		return;
21
	}
22
23
	@$csrf_token = $_REQUEST['csrf_token'];
24
25
	require_once "autoload.php";
26
	require_once "sessions.php";
27
	require_once "functions.php";
28
	require_once "config.php";
29
	require_once "db.php";
30
	require_once "db-prefs.php";
31
32
	startup_gettext();
33
34
	$script_started = microtime(true);
35
36
	if (!init_plugins()) return;
37
38
	header("Content-Type: text/json; charset=utf-8");
39
40
	if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
0 ignored issues
show
The constant ENABLE_GZIP_OUTPUT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
		ob_start("ob_gzhandler");
42
	}
43
44
	if (SINGLE_USER_MODE) {
0 ignored issues
show
The constant SINGLE_USER_MODE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
45
		authenticate_user( "admin", null);
46
	}
47
48
	if ($_SESSION["uid"]) {
49
		if (!validate_session()) {
50
			header("Content-Type: text/json");
51
			print error_json(6);
52
			return;
53
		}
54
		load_user_plugins( $_SESSION["uid"]);
55
	}
56
57
	$purge_intervals = array(
58
		0  => __("Use default"),
59
		-1 => __("Never purge"),
60
		5  => __("1 week old"),
61
		14 => __("2 weeks old"),
62
		31 => __("1 month old"),
63
		60 => __("2 months old"),
64
		90 => __("3 months old"));
65
66
	$update_intervals = array(
67
		0   => __("Default interval"),
68
		-1  => __("Disable updates"),
69
		15  => __("15 minutes"),
70
		30  => __("30 minutes"),
71
		60  => __("Hourly"),
72
		240 => __("4 hours"),
73
		720 => __("12 hours"),
74
		1440 => __("Daily"),
75
		10080 => __("Weekly"));
76
77
	$update_intervals_nodefault = array(
78
		-1  => __("Disable updates"),
79
		15  => __("15 minutes"),
80
		30  => __("30 minutes"),
81
		60  => __("Hourly"),
82
		240 => __("4 hours"),
83
		720 => __("12 hours"),
84
		1440 => __("Daily"),
85
		10080 => __("Weekly"));
86
87
	$access_level_names = array(
88
		0 => __("User"),
89
		5 => __("Power User"),
90
		10 => __("Administrator"));
91
92
	$op = str_replace("-", "_", $op);
93
94
	$override = PluginHost::getInstance()->lookup_handler($op, $method);
95
96
	if (class_exists($op) || $override) {
97
98
		if ($override) {
99
			$handler = $override;
100
		} else {
101
			$handler = new $op($_REQUEST);
102
		}
103
104
		if ($handler && implements_interface($handler, 'IHandler')) {
105
			if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
106
				if ($handler->before($method)) {
107
					if ($method && method_exists($handler, $method)) {
108
						$handler->$method();
109
					} else {
110
						if (method_exists($handler, "catchall")) {
111
							$handler->catchall($method);
112
						}
113
					}
114
					$handler->after();
115
					return;
116
				} else {
117
					header("Content-Type: text/json");
118
					print error_json(6);
119
					return;
120
				}
121
			} else {
122
				header("Content-Type: text/json");
123
				print error_json(6);
124
				return;
125
			}
126
		}
127
	}
128
129
	header("Content-Type: text/json");
130
	print error_json(13);
131