2020-04-17 13:57:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\SideMenu\Controller;
|
|
|
|
|
2020-08-13 11:21:59 +02:00
|
|
|
use OC;
|
2020-09-20 20:53:03 +02:00
|
|
|
use OC\User\User;
|
2020-09-22 14:35:09 +02:00
|
|
|
use OCA\SideMenu\AppInfo\Application;
|
|
|
|
use OCA\SideMenu\Service\ConfigProxy;
|
2020-09-20 20:53:03 +02:00
|
|
|
use OCA\Theming\ThemingDefaults;
|
2020-04-17 13:57:23 +02:00
|
|
|
use OCP\AppFramework\Controller;
|
2020-09-20 20:53:03 +02:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2020-08-13 11:21:59 +02:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2020-04-17 13:57:23 +02:00
|
|
|
use OCP\IRequest;
|
2020-08-12 15:59:51 +02:00
|
|
|
use OCP\IUserSession;
|
2020-04-17 13:57:23 +02:00
|
|
|
|
|
|
|
class JsController extends Controller
|
|
|
|
{
|
2020-05-11 22:51:27 +02:00
|
|
|
/**
|
2020-09-22 14:24:53 +02:00
|
|
|
* @var ConfigProxy
|
2020-05-11 22:51:27 +02:00
|
|
|
*/
|
2020-04-17 13:57:23 +02:00
|
|
|
protected $config;
|
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ThemingDefaults
|
|
|
|
*/
|
|
|
|
protected $themingDefaults;
|
|
|
|
|
2020-09-22 14:35:09 +02:00
|
|
|
public function __construct(string $appName, IRequest $request, ConfigProxy $config, ThemingDefaults $themingDefaults)
|
2020-04-17 13:57:23 +02:00
|
|
|
{
|
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
$this->themingDefaults = $themingDefaults;
|
|
|
|
|
|
|
|
$this->user = OC::$server[IUserSession::class]->getUser();
|
2020-04-17 13:57:23 +02:00
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @PublicPage
|
|
|
|
*/
|
2020-09-20 20:53:03 +02:00
|
|
|
public function script(): TemplateResponse
|
|
|
|
{
|
2020-09-21 11:28:55 +02:00
|
|
|
$response = new TemplateResponse(Application::APP_ID, 'js/script', $this->getConfig(), 'blank');
|
2020-09-20 20:53:03 +02:00
|
|
|
$response->addHeader('Content-Type', 'text/javascript');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @PublicPage
|
|
|
|
*/
|
|
|
|
public function config(): JSONResponse
|
|
|
|
{
|
|
|
|
return new JSONResponse($this->getConfig());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getConfig(): array
|
2020-04-17 13:57:23 +02:00
|
|
|
{
|
2020-09-22 14:24:53 +02:00
|
|
|
$topMenuApps = $this->config->getAppValueArray('top-menu-apps', '[]');
|
|
|
|
$targetBlankApps = $this->config->getAppValueArray('target-blank-apps', '[]');
|
|
|
|
$useAvatar = $this->config->getAppValueBool('use-avatar', '0');
|
2020-09-18 11:09:01 +02:00
|
|
|
$avatar = null;
|
2020-08-12 15:59:51 +02:00
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
if ($this->user) {
|
2020-09-22 14:24:53 +02:00
|
|
|
$userTopMenuApps = $this->config->getUserValueArray($this->user, 'top-menu-apps', '[]');
|
2020-08-12 15:59:51 +02:00
|
|
|
|
|
|
|
if (!empty($userTopMenuApps)) {
|
|
|
|
$topMenuApps = $userTopMenuApps;
|
|
|
|
}
|
2020-09-11 13:23:40 +02:00
|
|
|
|
2020-09-22 14:24:53 +02:00
|
|
|
$userTargetBlankMode = $this->config->getUserValueInt($this->user, 'target-blank-mode', '1');
|
|
|
|
$userTargetBlankApps = $this->config->getUserValueArray($this->user, 'target-blank-apps', '[]');
|
2020-09-11 13:23:40 +02:00
|
|
|
|
2020-09-18 11:09:14 +02:00
|
|
|
if (2 === $userTargetBlankMode) {
|
2020-09-12 16:32:10 +02:00
|
|
|
$targetBlankApps = $userTargetBlankApps;
|
2020-09-11 13:23:40 +02:00
|
|
|
}
|
2020-09-18 11:09:01 +02:00
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
$isAvatarSet = OC::$server->getAvatarManager()->getAvatar($this->user->getUid())->exists();
|
2020-09-18 11:09:01 +02:00
|
|
|
|
|
|
|
if ($useAvatar && $isAvatarSet) {
|
|
|
|
$avatar = OC::$server->getURLGenerator()->linkToRoute(
|
|
|
|
'core.avatar.getAvatar', [
|
2020-09-20 20:53:03 +02:00
|
|
|
'userId' => $this->user->getUid(),
|
2020-09-18 11:09:01 +02:00
|
|
|
'size' => 128,
|
2020-09-22 14:24:53 +02:00
|
|
|
'v' => $this->config->getUserValueInt($this->user, 'avatar', 'version', 0),
|
2020-09-18 11:09:01 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2020-08-12 15:59:51 +02:00
|
|
|
}
|
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
return [
|
2020-09-22 14:24:53 +02:00
|
|
|
'opener-position' => $this->config->getAppValue('opener-position', 'before'),
|
|
|
|
'opener-hover' => $this->config->getAppValueBool('opener-hover', '0'),
|
|
|
|
'external-sites-in-top-menu' => $this->config->getAppValueBool('external-sites-in-top-menu', 0),
|
|
|
|
'force-light-icon' => $this->config->getAppValueBool('force-light-icon', '0'),
|
|
|
|
'hide-when-no-apps' => $this->config->getAppValueBool('hide-when-no-apps', '0'),
|
|
|
|
'loader-enabled' => $this->config->getAppValueBool('loader-enabled', '1'),
|
|
|
|
'always-displayed' => $this->config->getAppValueBool('always-displayed', '0'),
|
|
|
|
'big-menu' => $this->config->getAppValueBool('big-menu', '0'),
|
2020-09-18 11:09:01 +02:00
|
|
|
'avatar' => $avatar,
|
2020-08-12 15:59:51 +02:00
|
|
|
'top-menu-apps' => $topMenuApps,
|
2020-09-12 16:32:10 +02:00
|
|
|
'target-blank-apps' => $targetBlankApps,
|
2020-09-20 20:53:03 +02:00
|
|
|
'logo' => $this->themingDefaults->getLogo(),
|
2020-04-17 13:57:23 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|