You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.5 KiB

14 years ago
9 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Frank Karlitschek <frank@karlitschek.de>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Thomas Tanghus <thomas@tanghus.net>
  12. * @author Vincent Petry <pvince81@owncloud.com>
  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. * Public interface of ownCloud for apps to use.
  31. * JSON Class
  32. */
  33. // use OCP namespace for all classes that are considered public.
  34. // This means that they should be used by apps instead of the internal ownCloud classes
  35. namespace OCP;
  36. /**
  37. * This class provides convenient functions to generate and send JSON data. Useful for Ajax calls
  38. * @deprecated 8.1.0 Use a AppFramework JSONResponse instead
  39. */
  40. class JSON {
  41. /**
  42. * Check if the user is logged in, send json error msg if not.
  43. *
  44. * This method checks if a user is logged in. If not, a json error
  45. * response will be return and the method will exit from execution
  46. * of the script.
  47. * The returned json will be in the format:
  48. *
  49. * {"status":"error","data":{"message":"Authentication error."}}
  50. *
  51. * Add this call to the start of all ajax method files that requires
  52. * an authenticated user.
  53. * @deprecated 8.1.0 Use annotation based ACLs from the AppFramework instead
  54. *
  55. * @suppress PhanDeprecatedFunction
  56. */
  57. public static function checkLoggedIn() {
  58. \OC_JSON::checkLoggedIn();
  59. }
  60. /**
  61. * Check an ajax get/post call if the request token is valid.
  62. *
  63. * This method checks for a valid variable 'requesttoken' in $_GET,
  64. * $_POST and $_SERVER. If a valid token is not found, a json error
  65. * response will be return and the method will exit from execution
  66. * of the script.
  67. * The returned json will be in the format:
  68. *
  69. * {"status":"error","data":{"message":"Token expired. Please reload page."}}
  70. *
  71. * Add this call to the start of all ajax method files that creates,
  72. * updates or deletes anything.
  73. * In cases where you e.g. use an ajax call to load a dialog containing
  74. * a submittable form, you will need to add the requesttoken first as a
  75. * parameter to the ajax call, then assign it to the template and finally
  76. * add a hidden input field also named 'requesttoken' containing the value.
  77. * @deprecated 8.1.0 Use annotation based CSRF checks from the AppFramework instead
  78. *
  79. * @suppress PhanDeprecatedFunction
  80. */
  81. public static function callCheck() {
  82. \OC_JSON::callCheck();
  83. }
  84. /**
  85. * Send json success msg
  86. *
  87. * Return a json success message with optional extra data.
  88. * @see \OCP\JSON::error() for the format to use.
  89. *
  90. * @param array $data The data to use
  91. * @deprecated 8.1.0 Use a AppFramework JSONResponse instead
  92. * @suppress PhanDeprecatedFunction
  93. */
  94. public static function success( $data = array() ) {
  95. \OC_JSON::success($data);
  96. }
  97. /**
  98. * Send json error msg
  99. *
  100. * Return a json error message with optional extra data for
  101. * error message or app specific data.
  102. *
  103. * Example use:
  104. *
  105. * $id = [some value]
  106. * OCP\JSON::error(array('data':array('message':'An error happened', 'id': $id)));
  107. *
  108. * Will return the json formatted string:
  109. *
  110. * {"status":"error","data":{"message":"An error happened", "id":[some value]}}
  111. *
  112. * @param array $data The data to use
  113. * @deprecated 8.1.0 Use a AppFramework JSONResponse instead
  114. * @suppress PhanDeprecatedFunction
  115. */
  116. public static function error( $data = array() ) {
  117. \OC_JSON::error($data);
  118. }
  119. /**
  120. * Check if the App is enabled and send JSON error message instead
  121. *
  122. * This method checks if a specific app is enabled. If not, a json error
  123. * response will be return and the method will exit from execution
  124. * of the script.
  125. * The returned json will be in the format:
  126. *
  127. * {"status":"error","data":{"message":"Application is not enabled."}}
  128. *
  129. * Add this call to the start of all ajax method files that requires
  130. * a specific app to be enabled.
  131. *
  132. * @param string $app The app to check
  133. * @deprecated 8.1.0 Use the AppFramework instead. It will automatically check if the app is enabled.
  134. * @suppress PhanDeprecatedFunction
  135. */
  136. public static function checkAppEnabled( $app ) {
  137. \OC_JSON::checkAppEnabled($app);
  138. }
  139. /**
  140. * Check if the user is a admin, send json error msg if not
  141. *
  142. * This method checks if the current user has admin rights. If not, a json error
  143. * response will be return and the method will exit from execution
  144. * of the script.
  145. * The returned json will be in the format:
  146. *
  147. * {"status":"error","data":{"message":"Authentication error."}}
  148. *
  149. * Add this call to the start of all ajax method files that requires
  150. * administrative rights.
  151. *
  152. * @deprecated 8.1.0 Use annotation based ACLs from the AppFramework instead
  153. * @suppress PhanDeprecatedFunction
  154. */
  155. public static function checkAdminUser() {
  156. \OC_JSON::checkAdminUser();
  157. }
  158. }