2014-10-15 23:59:16 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2016-10-27 18:41:15 +03:00
|
|
|
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 18:07:57 +03:00
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-10-15 23:59:16 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-10-15 23:59:16 +04:00
|
|
|
namespace OC\Settings\Controller;
|
|
|
|
|
2016-10-27 18:41:15 +03:00
|
|
|
use OC\App\AppStore\Fetcher\AppFetcher;
|
|
|
|
use OC\App\AppStore\Fetcher\CategoryFetcher;
|
|
|
|
use OC\App\AppStore\Version\VersionParser;
|
2014-12-01 23:47:22 +03:00
|
|
|
use OC\App\DependencyAnalyzer;
|
|
|
|
use OC\App\Platform;
|
2015-03-30 16:58:20 +03:00
|
|
|
use OCP\App\IAppManager;
|
2014-10-15 23:59:16 +04:00
|
|
|
use \OCP\AppFramework\Controller;
|
2015-03-30 16:58:20 +03:00
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
2016-10-27 18:41:15 +03:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2015-03-30 16:58:20 +03:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\INavigationManager;
|
2014-10-15 23:59:16 +04:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IConfig;
|
2016-10-27 18:41:15 +03:00
|
|
|
use OCP\L10N\IFactory;
|
2014-10-15 23:59:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package OC\Settings\Controller
|
|
|
|
*/
|
|
|
|
class AppSettingsController extends Controller {
|
2015-10-20 13:02:08 +03:00
|
|
|
const CAT_ENABLED = 0;
|
|
|
|
const CAT_DISABLED = 1;
|
2014-10-15 23:59:16 +04:00
|
|
|
|
|
|
|
/** @var \OCP\IL10N */
|
|
|
|
private $l10n;
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
2015-03-30 16:58:20 +03:00
|
|
|
/** @var INavigationManager */
|
|
|
|
private $navigationManager;
|
|
|
|
/** @var IAppManager */
|
|
|
|
private $appManager;
|
2016-10-27 18:41:15 +03:00
|
|
|
/** @var CategoryFetcher */
|
|
|
|
private $categoryFetcher;
|
|
|
|
/** @var AppFetcher */
|
|
|
|
private $appFetcher;
|
|
|
|
/** @var IFactory */
|
|
|
|
private $l10nFactory;
|
2014-10-15 23:59:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param IConfig $config
|
2015-03-30 16:58:20 +03:00
|
|
|
* @param INavigationManager $navigationManager
|
|
|
|
* @param IAppManager $appManager
|
2016-10-27 18:41:15 +03:00
|
|
|
* @param CategoryFetcher $categoryFetcher
|
|
|
|
* @param AppFetcher $appFetcher
|
|
|
|
* @param IFactory $l10nFactory
|
2014-10-15 23:59:16 +04:00
|
|
|
*/
|
|
|
|
public function __construct($appName,
|
|
|
|
IRequest $request,
|
|
|
|
IL10N $l10n,
|
2015-01-09 20:31:39 +03:00
|
|
|
IConfig $config,
|
2015-03-30 16:58:20 +03:00
|
|
|
INavigationManager $navigationManager,
|
|
|
|
IAppManager $appManager,
|
2016-10-27 18:41:15 +03:00
|
|
|
CategoryFetcher $categoryFetcher,
|
|
|
|
AppFetcher $appFetcher,
|
|
|
|
IFactory $l10nFactory) {
|
2014-10-15 23:59:16 +04:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
$this->config = $config;
|
2015-03-30 16:58:20 +03:00
|
|
|
$this->navigationManager = $navigationManager;
|
|
|
|
$this->appManager = $appManager;
|
2016-10-27 18:41:15 +03:00
|
|
|
$this->categoryFetcher = $categoryFetcher;
|
|
|
|
$this->appFetcher = $appFetcher;
|
|
|
|
$this->l10nFactory = $l10nFactory;
|
2015-10-20 13:02:08 +03:00
|
|
|
}
|
|
|
|
|
2015-03-30 16:58:20 +03:00
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
2016-10-27 18:41:15 +03:00
|
|
|
*
|
2015-10-20 13:02:08 +03:00
|
|
|
* @param string $category
|
2015-03-30 16:58:20 +03:00
|
|
|
* @return TemplateResponse
|
|
|
|
*/
|
2015-10-20 13:02:08 +03:00
|
|
|
public function viewApps($category = '') {
|
2016-10-27 18:41:15 +03:00
|
|
|
if ($category === '') {
|
2015-10-20 13:02:08 +03:00
|
|
|
$category = 'enabled';
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:58:20 +03:00
|
|
|
$params = [];
|
2015-10-15 17:15:42 +03:00
|
|
|
$params['category'] = $category;
|
2015-12-02 16:35:38 +03:00
|
|
|
$params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true;
|
2015-03-30 16:58:20 +03:00
|
|
|
$this->navigationManager->setActiveEntry('core_apps');
|
|
|
|
|
|
|
|
$templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user');
|
|
|
|
$policy = new ContentSecurityPolicy();
|
2016-10-31 19:08:11 +03:00
|
|
|
$policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
|
2015-03-30 16:58:20 +03:00
|
|
|
$templateResponse->setContentSecurityPolicy($policy);
|
|
|
|
|
|
|
|
return $templateResponse;
|
2014-10-15 23:59:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all available categories
|
2016-10-27 18:41:15 +03:00
|
|
|
*
|
|
|
|
* @return JSONResponse
|
2014-10-15 23:59:16 +04:00
|
|
|
*/
|
|
|
|
public function listCategories() {
|
2016-10-27 18:41:15 +03:00
|
|
|
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
|
2014-10-15 23:59:16 +04:00
|
|
|
|
2016-10-27 18:41:15 +03:00
|
|
|
$formattedCategories = [
|
2015-10-20 13:02:08 +03:00
|
|
|
['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled')],
|
|
|
|
['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Not enabled')],
|
2015-01-09 20:31:39 +03:00
|
|
|
];
|
2016-10-27 18:41:15 +03:00
|
|
|
$categories = $this->categoryFetcher->get();
|
|
|
|
foreach($categories as $category) {
|
|
|
|
$formattedCategories[] = [
|
|
|
|
'id' => $category['id'],
|
|
|
|
'ident' => $category['id'],
|
|
|
|
'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'],
|
|
|
|
];
|
|
|
|
}
|
2014-10-15 23:59:16 +04:00
|
|
|
|
2016-10-27 18:41:15 +03:00
|
|
|
return new JSONResponse($formattedCategories);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all apps for a category
|
|
|
|
*
|
|
|
|
* @param string $requestedCategory
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getAppsForCategory($requestedCategory) {
|
|
|
|
$versionParser = new VersionParser();
|
|
|
|
$formattedApps = [];
|
|
|
|
$apps = $this->appFetcher->get();
|
|
|
|
foreach($apps as $app) {
|
2016-11-21 23:34:37 +03:00
|
|
|
if (isset($app['isFeatured'])) {
|
|
|
|
$app['featured'] = $app['isFeatured'];
|
|
|
|
}
|
2016-10-27 18:41:15 +03:00
|
|
|
|
|
|
|
// Skip all apps not in the requested category
|
|
|
|
$isInCategory = false;
|
|
|
|
foreach($app['categories'] as $category) {
|
|
|
|
if($category === $requestedCategory) {
|
|
|
|
$isInCategory = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$isInCategory) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']);
|
|
|
|
$nextCloudVersionDependencies = [];
|
|
|
|
if($nextCloudVersion->getMinimumVersion() !== '') {
|
2016-11-15 17:07:58 +03:00
|
|
|
$nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion();
|
2016-10-27 18:41:15 +03:00
|
|
|
}
|
|
|
|
if($nextCloudVersion->getMaximumVersion() !== '') {
|
2016-11-15 17:07:58 +03:00
|
|
|
$nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion();
|
2016-10-27 18:41:15 +03:00
|
|
|
}
|
|
|
|
$phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']);
|
|
|
|
$existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false;
|
|
|
|
$phpDependencies = [];
|
|
|
|
if($phpVersion->getMinimumVersion() !== '') {
|
|
|
|
$phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion();
|
|
|
|
}
|
|
|
|
if($phpVersion->getMaximumVersion() !== '') {
|
|
|
|
$phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion();
|
|
|
|
}
|
|
|
|
if(isset($app['releases'][0]['minIntSize'])) {
|
|
|
|
$phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize'];
|
|
|
|
}
|
|
|
|
$authors = '';
|
|
|
|
foreach($app['authors'] as $key => $author) {
|
|
|
|
$authors .= $author['name'];
|
|
|
|
if($key !== count($app['authors']) - 1) {
|
|
|
|
$authors .= ', ';
|
2015-01-30 18:39:57 +03:00
|
|
|
}
|
2014-10-15 23:59:16 +04:00
|
|
|
}
|
|
|
|
|
2016-10-27 18:41:15 +03:00
|
|
|
$currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2);
|
2016-10-31 13:07:54 +03:00
|
|
|
$enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no');
|
|
|
|
$groups = null;
|
|
|
|
if($enabledValue !== 'no' && $enabledValue !== 'yes') {
|
|
|
|
$groups = $enabledValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$currentVersion = '';
|
|
|
|
if($this->appManager->isInstalled($app['id'])) {
|
|
|
|
$currentVersion = \OC_App::getAppVersion($app['id']);
|
|
|
|
} else {
|
|
|
|
$currentLanguage = $app['releases'][0]['version'];
|
|
|
|
}
|
2016-10-27 18:41:15 +03:00
|
|
|
|
|
|
|
$formattedApps[] = [
|
|
|
|
'id' => $app['id'],
|
|
|
|
'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'],
|
|
|
|
'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'],
|
|
|
|
'license' => $app['releases'][0]['licenses'],
|
|
|
|
'author' => $authors,
|
|
|
|
'shipped' => false,
|
2016-10-31 13:07:54 +03:00
|
|
|
'version' => $currentVersion,
|
2016-10-27 18:41:15 +03:00
|
|
|
'default_enable' => '',
|
|
|
|
'types' => [],
|
|
|
|
'documentation' => [
|
|
|
|
'admin' => $app['adminDocs'],
|
|
|
|
'user' => $app['userDocs'],
|
|
|
|
'developer' => $app['developerDocs']
|
|
|
|
],
|
|
|
|
'website' => $app['website'],
|
|
|
|
'bugs' => $app['issueTracker'],
|
|
|
|
'detailpage' => $app['website'],
|
|
|
|
'dependencies' => array_merge(
|
|
|
|
$nextCloudVersionDependencies,
|
|
|
|
$phpDependencies
|
|
|
|
),
|
|
|
|
'level' => ($app['featured'] === true) ? 200 : 100,
|
|
|
|
'missingMaxOwnCloudVersion' => false,
|
|
|
|
'missingMinOwnCloudVersion' => false,
|
|
|
|
'canInstall' => true,
|
2016-10-31 19:08:11 +03:00
|
|
|
'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '',
|
2016-10-27 18:41:15 +03:00
|
|
|
'score' => $app['ratingOverall'],
|
2016-11-30 17:59:02 +03:00
|
|
|
'ratingNumOverall' => $app['ratingNumOverall'],
|
|
|
|
'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5 ? true : false,
|
2016-10-27 18:41:15 +03:00
|
|
|
'removable' => $existsLocally,
|
|
|
|
'active' => $this->appManager->isEnabledForUser($app['id']),
|
|
|
|
'needsDownload' => !$existsLocally,
|
2016-10-31 13:07:54 +03:00
|
|
|
'groups' => $groups,
|
2016-10-31 19:08:11 +03:00
|
|
|
'fromAppStore' => true,
|
2016-10-27 18:41:15 +03:00
|
|
|
];
|
2016-10-31 13:07:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
$appFetcher = \OC::$server->getAppFetcher();
|
|
|
|
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher);
|
2016-10-31 19:08:11 +03:00
|
|
|
if($newVersion && $this->appManager->isInstalled($app['id'])) {
|
2016-10-31 13:07:54 +03:00
|
|
|
$formattedApps[count($formattedApps)-1]['update'] = $newVersion;
|
|
|
|
}
|
2016-10-27 18:41:15 +03:00
|
|
|
}
|
2014-10-15 23:59:16 +04:00
|
|
|
|
2016-10-27 18:41:15 +03:00
|
|
|
return $formattedApps;
|
2014-10-15 23:59:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-30 16:58:20 +03:00
|
|
|
* Get all available apps in a category
|
|
|
|
*
|
2015-10-20 13:02:08 +03:00
|
|
|
* @param string $category
|
2016-10-27 18:41:15 +03:00
|
|
|
* @return JSONResponse
|
2014-10-15 23:59:16 +04:00
|
|
|
*/
|
2016-10-27 18:41:15 +03:00
|
|
|
public function listApps($category = '') {
|
|
|
|
$appClass = new \OC_App();
|
|
|
|
|
|
|
|
switch ($category) {
|
|
|
|
// installed apps
|
|
|
|
case 'enabled':
|
|
|
|
$apps = $appClass->listAllApps();
|
|
|
|
$apps = array_filter($apps, function ($app) {
|
|
|
|
return $app['active'];
|
|
|
|
});
|
2016-11-24 17:04:23 +03:00
|
|
|
|
|
|
|
foreach($apps as $key => $app) {
|
|
|
|
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
|
|
|
|
$apps[$key]['update'] = $newVersion;
|
|
|
|
}
|
|
|
|
|
2016-10-27 18:41:15 +03:00
|
|
|
usort($apps, function ($a, $b) {
|
|
|
|
$a = (string)$a['name'];
|
|
|
|
$b = (string)$b['name'];
|
|
|
|
if ($a === $b) {
|
|
|
|
return 0;
|
2015-06-29 12:38:28 +03:00
|
|
|
}
|
2016-10-27 18:41:15 +03:00
|
|
|
return ($a < $b) ? -1 : 1;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
// disabled apps
|
|
|
|
case 'disabled':
|
|
|
|
$apps = $appClass->listAllApps();
|
|
|
|
$apps = array_filter($apps, function ($app) {
|
|
|
|
return !$app['active'];
|
|
|
|
});
|
|
|
|
usort($apps, function ($a, $b) {
|
|
|
|
$a = (string)$a['name'];
|
|
|
|
$b = (string)$b['name'];
|
|
|
|
if ($a === $b) {
|
|
|
|
return 0;
|
2015-06-19 20:01:58 +03:00
|
|
|
}
|
2016-10-27 18:41:15 +03:00
|
|
|
return ($a < $b) ? -1 : 1;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$apps = $this->getAppsForCategory($category);
|
|
|
|
|
|
|
|
// sort by score
|
|
|
|
usort($apps, function ($a, $b) {
|
|
|
|
$a = (int)$a['score'];
|
|
|
|
$b = (int)$b['score'];
|
|
|
|
if ($a === $b) {
|
|
|
|
return 0;
|
2014-10-15 23:59:16 +04:00
|
|
|
}
|
2016-10-27 18:41:15 +03:00
|
|
|
return ($a > $b) ? -1 : 1;
|
|
|
|
});
|
|
|
|
break;
|
2014-10-15 23:59:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// fix groups to be an array
|
2014-12-12 14:34:53 +03:00
|
|
|
$dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
|
|
|
|
$apps = array_map(function($app) use ($dependencyAnalyzer) {
|
2015-01-06 15:07:17 +03:00
|
|
|
|
|
|
|
// fix groups
|
2014-10-15 23:59:16 +04:00
|
|
|
$groups = array();
|
|
|
|
if (is_string($app['groups'])) {
|
|
|
|
$groups = json_decode($app['groups']);
|
|
|
|
}
|
|
|
|
$app['groups'] = $groups;
|
|
|
|
$app['canUnInstall'] = !$app['active'] && $app['removable'];
|
2014-12-01 23:47:22 +03:00
|
|
|
|
2015-01-06 15:07:17 +03:00
|
|
|
// fix licence vs license
|
|
|
|
if (isset($app['license']) && !isset($app['licence'])) {
|
|
|
|
$app['licence'] = $app['license'];
|
|
|
|
}
|
|
|
|
|
2014-12-01 23:47:22 +03:00
|
|
|
// analyse dependencies
|
2014-12-12 14:34:53 +03:00
|
|
|
$missing = $dependencyAnalyzer->analyze($app);
|
2014-12-01 23:47:22 +03:00
|
|
|
$app['canInstall'] = empty($missing);
|
|
|
|
$app['missingDependencies'] = $missing;
|
2015-01-06 15:07:17 +03:00
|
|
|
|
2016-11-15 17:07:58 +03:00
|
|
|
$app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['min-version']);
|
|
|
|
$app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['max-version']);
|
2016-01-07 16:55:23 +03:00
|
|
|
|
2014-10-15 23:59:16 +04:00
|
|
|
return $app;
|
|
|
|
}, $apps);
|
|
|
|
|
2016-10-27 18:41:15 +03:00
|
|
|
return new JSONResponse(['apps' => $apps, 'status' => 'success']);
|
2016-04-11 17:48:07 +03:00
|
|
|
}
|
2014-10-15 23:59:16 +04:00
|
|
|
}
|