cloud.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. * @author Tom Needham <tom@owncloud.com>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. class OC_OCS_Cloud {
  26. public static function getCapabilities() {
  27. $result = array();
  28. list($major, $minor, $micro) = OC_Util::getVersion();
  29. $result['version'] = array(
  30. 'major' => $major,
  31. 'minor' => $minor,
  32. 'micro' => $micro,
  33. 'string' => OC_Util::getVersionString(),
  34. 'edition' => OC_Util::getEditionString(),
  35. );
  36. $result['capabilities'] = array(
  37. 'core' => array(
  38. 'pollinterval' => OC_Config::getValue('pollinterval', 60),
  39. ),
  40. );
  41. return new OC_OCS_Result($result);
  42. }
  43. /**
  44. * gets user info
  45. *
  46. * exposes the quota of an user:
  47. * <data>
  48. * <quota>
  49. * <free>1234</free>
  50. * <used>4321</used>
  51. * <total>5555</total>
  52. * <ralative>0.78</ralative>
  53. * </quota>
  54. * </data>
  55. *
  56. * @param array $parameters should contain parameter 'userid' which identifies
  57. * the user from whom the information will be returned
  58. */
  59. public static function getUser($parameters) {
  60. $return = array();
  61. // Check if they are viewing information on themselves
  62. if($parameters['userid'] === OC_User::getUser()) {
  63. // Self lookup
  64. $storage = OC_Helper::getStorageInfo('/');
  65. $return['quota'] = array(
  66. 'free' => $storage['free'],
  67. 'used' => $storage['used'],
  68. 'total' => $storage['total'],
  69. 'relative' => $storage['relative'],
  70. );
  71. }
  72. if(OC_User::isAdminUser(OC_User::getUser())
  73. || OC_Subadmin::isUserAccessible(OC_User::getUser(), $parameters['userid'])) {
  74. if(OC_User::userExists($parameters['userid'])) {
  75. // Is an admin/subadmin so can see display name
  76. $return['displayname'] = OC_User::getDisplayName($parameters['userid']);
  77. } else {
  78. return new OC_OCS_Result(null, 101);
  79. }
  80. }
  81. if(count($return)) {
  82. return new OC_OCS_Result($return);
  83. } else {
  84. // No permission to view this user data
  85. return new OC_OCS_Result(null, 997);
  86. }
  87. }
  88. public static function getCurrentUser() {
  89. $email=\OC::$server->getConfig()->getUserValue(OC_User::getUser(), 'settings', 'email', '');
  90. $data = array(
  91. 'id' => OC_User::getUser(),
  92. 'display-name' => OC_User::getDisplayName(),
  93. 'email' => $email,
  94. );
  95. return new OC_OCS_Result($data);
  96. }
  97. }