|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bart Visscher <[email protected]> |
|
6
|
|
|
* @author Frank Karlitschek <[email protected]> |
|
7
|
|
|
* @author Lukas Reschke <[email protected]> |
|
8
|
|
|
* @author Morris Jobke <[email protected]> |
|
9
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
10
|
|
|
* @author Thomas Müller <[email protected]> |
|
11
|
|
|
* @author Thomas Tanghus <[email protected]> |
|
12
|
|
|
* @author Vincent Petry <[email protected]> |
|
13
|
|
|
* |
|
14
|
|
|
* @license AGPL-3.0 |
|
15
|
|
|
* |
|
16
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
17
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* as published by the Free Software Foundation. |
|
19
|
|
|
* |
|
20
|
|
|
* This program is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU Affero General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Public interface of ownCloud for apps to use. |
|
32
|
|
|
* JSON Class |
|
33
|
|
|
*/ |
|
34
|
|
|
|
|
35
|
|
|
// use OCP namespace for all classes that are considered public. |
|
36
|
|
|
// This means that they should be used by apps instead of the internal ownCloud classes |
|
37
|
|
|
namespace OCP; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* This class provides convenient functions to generate and send JSON data. Useful for Ajax calls |
|
41
|
|
|
* @deprecated 8.1.0 Use a AppFramework JSONResponse instead |
|
42
|
|
|
*/ |
|
43
|
|
|
class JSON { |
|
44
|
|
|
/** |
|
45
|
|
|
* Check if the user is logged in, send json error msg if not. |
|
46
|
|
|
* |
|
47
|
|
|
* This method checks if a user is logged in. If not, a json error |
|
48
|
|
|
* response will be return and the method will exit from execution |
|
49
|
|
|
* of the script. |
|
50
|
|
|
* The returned json will be in the format: |
|
51
|
|
|
* |
|
52
|
|
|
* {"status":"error","data":{"message":"Authentication error."}} |
|
53
|
|
|
* |
|
54
|
|
|
* Add this call to the start of all ajax method files that requires |
|
55
|
|
|
* an authenticated user. |
|
56
|
|
|
* @deprecated 8.1.0 Use annotation based ACLs from the AppFramework instead |
|
57
|
|
|
* |
|
58
|
|
|
* @suppress PhanDeprecatedFunction |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function checkLoggedIn() { |
|
61
|
|
|
\OC_JSON::checkLoggedIn(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Check an ajax get/post call if the request token is valid. |
|
66
|
|
|
* |
|
67
|
|
|
* This method checks for a valid variable 'requesttoken' in $_GET, |
|
68
|
|
|
* $_POST and $_SERVER. If a valid token is not found, a json error |
|
69
|
|
|
* response will be return and the method will exit from execution |
|
70
|
|
|
* of the script. |
|
71
|
|
|
* The returned json will be in the format: |
|
72
|
|
|
* |
|
73
|
|
|
* {"status":"error","data":{"message":"Token expired. Please reload page."}} |
|
74
|
|
|
* |
|
75
|
|
|
* Add this call to the start of all ajax method files that creates, |
|
76
|
|
|
* updates or deletes anything. |
|
77
|
|
|
* In cases where you e.g. use an ajax call to load a dialog containing |
|
78
|
|
|
* a submittable form, you will need to add the requesttoken first as a |
|
79
|
|
|
* parameter to the ajax call, then assign it to the template and finally |
|
80
|
|
|
* add a hidden input field also named 'requesttoken' containing the value. |
|
81
|
|
|
* @deprecated 8.1.0 Use annotation based CSRF checks from the AppFramework instead |
|
82
|
|
|
* |
|
83
|
|
|
* @suppress PhanDeprecatedFunction |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function callCheck() { |
|
86
|
|
|
\OC_JSON::callCheck(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Send json success msg |
|
91
|
|
|
* |
|
92
|
|
|
* Return a json success message with optional extra data. |
|
93
|
|
|
* @see \OCP\JSON::error() for the format to use. |
|
94
|
|
|
* |
|
95
|
|
|
* @param array $data The data to use |
|
96
|
|
|
* @deprecated 8.1.0 Use a AppFramework JSONResponse instead |
|
97
|
|
|
* @suppress PhanDeprecatedFunction |
|
98
|
|
|
*/ |
|
99
|
|
|
public static function success( $data = array() ) { |
|
100
|
|
|
\OC_JSON::success($data); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Send json error msg |
|
105
|
|
|
* |
|
106
|
|
|
* Return a json error message with optional extra data for |
|
107
|
|
|
* error message or app specific data. |
|
108
|
|
|
* |
|
109
|
|
|
* Example use: |
|
110
|
|
|
* |
|
111
|
|
|
* $id = [some value] |
|
112
|
|
|
* OCP\JSON::error(array('data':array('message':'An error happened', 'id': $id))); |
|
113
|
|
|
* |
|
114
|
|
|
* Will return the json formatted string: |
|
115
|
|
|
* |
|
116
|
|
|
* {"status":"error","data":{"message":"An error happened", "id":[some value]}} |
|
117
|
|
|
* |
|
118
|
|
|
* @param array $data The data to use |
|
119
|
|
|
* @deprecated 8.1.0 Use a AppFramework JSONResponse instead |
|
120
|
|
|
* @suppress PhanDeprecatedFunction |
|
121
|
|
|
*/ |
|
122
|
|
|
public static function error( $data = array() ) { |
|
123
|
|
|
\OC_JSON::error($data); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Check if the App is enabled and send JSON error message instead |
|
128
|
|
|
* |
|
129
|
|
|
* This method checks if a specific app is enabled. If not, a json error |
|
130
|
|
|
* response will be return and the method will exit from execution |
|
131
|
|
|
* of the script. |
|
132
|
|
|
* The returned json will be in the format: |
|
133
|
|
|
* |
|
134
|
|
|
* {"status":"error","data":{"message":"Application is not enabled."}} |
|
135
|
|
|
* |
|
136
|
|
|
* Add this call to the start of all ajax method files that requires |
|
137
|
|
|
* a specific app to be enabled. |
|
138
|
|
|
* |
|
139
|
|
|
* @param string $app The app to check |
|
140
|
|
|
* @deprecated 8.1.0 Use the AppFramework instead. It will automatically check if the app is enabled. |
|
141
|
|
|
* @suppress PhanDeprecatedFunction |
|
142
|
|
|
*/ |
|
143
|
|
|
public static function checkAppEnabled( $app ) { |
|
144
|
|
|
\OC_JSON::checkAppEnabled($app); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Check if the user is a admin, send json error msg if not |
|
149
|
|
|
* |
|
150
|
|
|
* This method checks if the current user has admin rights. If not, a json error |
|
151
|
|
|
* response will be return and the method will exit from execution |
|
152
|
|
|
* of the script. |
|
153
|
|
|
* The returned json will be in the format: |
|
154
|
|
|
* |
|
155
|
|
|
* {"status":"error","data":{"message":"Authentication error."}} |
|
156
|
|
|
* |
|
157
|
|
|
* Add this call to the start of all ajax method files that requires |
|
158
|
|
|
* administrative rights. |
|
159
|
|
|
* |
|
160
|
|
|
* @deprecated 8.1.0 Use annotation based ACLs from the AppFramework instead |
|
161
|
|
|
* @suppress PhanDeprecatedFunction |
|
162
|
|
|
*/ |
|
163
|
|
|
public static function checkAdminUser() { |
|
164
|
|
|
\OC_JSON::checkAdminUser(); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|