2020-08-06 15:00:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\SideMenu\AppInfo;
|
|
|
|
|
|
|
|
use OC;
|
|
|
|
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
|
|
|
|
use OC\User\User;
|
|
|
|
use OCA\SideMenu\Service\AppRepository;
|
2021-02-03 10:14:03 +01:00
|
|
|
use OCA\SideMenu\Service\CategoryRepository;
|
2020-09-22 14:24:53 +02:00
|
|
|
use OCA\SideMenu\Service\ConfigProxy;
|
2020-08-06 15:00:24 +02:00
|
|
|
use OCP\AppFramework\App;
|
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\Util;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class Application.
|
|
|
|
*
|
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
|
|
*/
|
|
|
|
class Application extends App
|
|
|
|
{
|
2020-09-22 14:35:09 +02:00
|
|
|
public const APP_ID = 'side_menu';
|
|
|
|
|
2020-09-23 13:17:13 +02:00
|
|
|
public const APP_NAME = 'Custom menu';
|
2020-08-06 15:00:24 +02:00
|
|
|
/**
|
|
|
|
* @var OC\AllConfig
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ContentSecurityPolicyNonceManager
|
|
|
|
*/
|
|
|
|
protected $cspnm;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function __construct(array $urlParams = [])
|
|
|
|
{
|
2020-09-21 11:28:55 +02:00
|
|
|
parent::__construct(self::APP_ID, $urlParams);
|
2020-08-06 15:00:24 +02:00
|
|
|
|
|
|
|
$this->config = OC::$server->getConfig();
|
|
|
|
$this->cspnm = OC::$server->getContentSecurityPolicyNonceManager();
|
|
|
|
$this->user = OC::$server[IUserSession::class]->getUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if this app is enabled.
|
|
|
|
*/
|
|
|
|
public function isEnabled(): bool
|
|
|
|
{
|
|
|
|
$enabled = true;
|
2020-09-24 14:26:25 +02:00
|
|
|
$isForced = (bool) $this->config->getAppValue(self::APP_ID, 'force', '0');
|
2020-08-06 15:00:24 +02:00
|
|
|
|
2020-09-24 14:26:25 +02:00
|
|
|
if (null !== $this->user && !$isForced) {
|
2020-10-19 13:44:07 +02:00
|
|
|
$enabled = (bool) $this->config->getUserValue(
|
|
|
|
$this->user->getUid(),
|
|
|
|
self::APP_ID,
|
|
|
|
'enabled',
|
|
|
|
$this->config->getAppValue(
|
|
|
|
self::APP_ID,
|
|
|
|
'default-enabled',
|
|
|
|
'1'
|
|
|
|
)
|
|
|
|
);
|
2020-08-06 15:00:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registes services.
|
|
|
|
*/
|
|
|
|
public function registerServices()
|
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
|
|
|
|
$container->registerService('AppRepository', function (ContainerInterface $c) {
|
2020-10-14 09:57:42 +02:00
|
|
|
return new AppRepository();
|
2020-08-06 15:00:24 +02:00
|
|
|
});
|
2020-09-22 14:24:53 +02:00
|
|
|
|
2021-02-03 10:14:03 +01:00
|
|
|
$container->registerService('CategoryRepository', function (ContainerInterface $c) {
|
|
|
|
return new CategoryRepository();
|
|
|
|
});
|
|
|
|
|
2020-09-22 14:24:53 +02:00
|
|
|
$container->registerService('ConfigProxy', function (ContainerInterface $c) {
|
2021-02-03 10:14:03 +01:00
|
|
|
return new ConfigProxy();
|
2020-09-22 14:24:53 +02:00
|
|
|
});
|
2020-08-06 15:00:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers assets.
|
|
|
|
*/
|
|
|
|
public function registerAssets()
|
|
|
|
{
|
2020-09-21 11:28:55 +02:00
|
|
|
Util::addScript(self::APP_ID, 'sideMenu');
|
|
|
|
Util::addStyle(self::APP_ID, 'sideMenu');
|
2020-08-06 15:00:24 +02:00
|
|
|
|
|
|
|
$stylesheet = OC::$server->getURLGenerator()->linkToRoute(
|
|
|
|
'side_menu.Css.stylesheet',
|
|
|
|
[
|
2020-09-21 11:28:55 +02:00
|
|
|
'v' => $this->config->getAppValue(self::APP_ID, 'cache', '0'),
|
2020-08-06 15:00:24 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$script = OC::$server->getURLGenerator()->linkToRoute(
|
|
|
|
'side_menu.Js.script',
|
|
|
|
[
|
2020-09-21 11:28:55 +02:00
|
|
|
'v' => $this->config->getAppValue(self::APP_ID, 'cache', '0'),
|
2020-08-06 15:00:24 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
Util::addHeader(
|
|
|
|
'link',
|
|
|
|
[
|
|
|
|
'href' => $stylesheet,
|
|
|
|
'rel' => 'stylesheet',
|
|
|
|
],
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
|
|
|
Util::addHeader(
|
|
|
|
'script',
|
|
|
|
[
|
|
|
|
'src' => $script,
|
|
|
|
'nonce' => $this->cspnm->getNonce(),
|
|
|
|
],
|
|
|
|
''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|