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