index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. OC_JSON::checkAdminUser();
  9. $l = OC_L10N::get('settings');
  10. $category = intval($_GET['category']);
  11. $apps = array();
  12. switch($category) {
  13. // installed apps
  14. case 0:
  15. $apps = \OC_App::listAllApps(true);
  16. $apps = array_filter($apps, function($app) {
  17. return $app['active'];
  18. });
  19. break;
  20. // not-installed apps
  21. case 1:
  22. $apps = \OC_App::listAllApps(true);
  23. $apps = array_filter($apps, function($app) {
  24. return !$app['active'];
  25. });
  26. break;
  27. default:
  28. if ($category === 2) {
  29. $apps = \OC_App::getAppstoreApps('approved');
  30. $apps = array_filter($apps, function($app) {
  31. return isset($app['internalclass']) && $app['internalclass'] === 'recommendedapp';
  32. });
  33. } else {
  34. $apps = \OC_App::getAppstoreApps('approved', $category);
  35. }
  36. if (!$apps) {
  37. $apps = array();
  38. }
  39. usort($apps, function ($a, $b) {
  40. $a = (int)$a['score'];
  41. $b = (int)$b['score'];
  42. if ($a === $b) {
  43. return 0;
  44. }
  45. return ($a > $b) ? -1 : 1;
  46. });
  47. break;
  48. }
  49. // fix groups to be an array
  50. $apps = array_map(function($app){
  51. $groups = array();
  52. if (is_string($app['groups'])) {
  53. $groups = json_decode($app['groups']);
  54. }
  55. $app['groups'] = $groups;
  56. $app['canUnInstall'] = !$app['active'] && $app['removable'];
  57. return $app;
  58. }, $apps);
  59. OCP\JSON::success(array("apps" => $apps));