2022-08-13 01:58:37 +00:00
|
|
|
<?php
|
2022-10-19 17:10:36 +00:00
|
|
|
|
2022-08-18 18:27:25 +00:00
|
|
|
namespace OCA\Memories\Controller;
|
2022-08-13 01:58:37 +00:00
|
|
|
|
2022-08-20 00:18:04 +00:00
|
|
|
use OCA\Files\Event\LoadSidebar;
|
2022-10-19 17:10:36 +00:00
|
|
|
use OCA\Memories\AppInfo\Application;
|
2022-10-07 17:46:09 +00:00
|
|
|
use OCP\App\IAppManager;
|
2022-10-19 17:10:36 +00:00
|
|
|
use OCP\AppFramework\Controller;
|
2022-10-17 02:52:44 +00:00
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
2022-10-19 17:10:36 +00:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2022-08-20 00:18:04 +00:00
|
|
|
use OCP\IConfig;
|
2022-10-19 17:10:36 +00:00
|
|
|
use OCP\IRequest;
|
2022-08-20 00:18:04 +00:00
|
|
|
use OCP\IUserSession;
|
2022-08-14 20:54:18 +00:00
|
|
|
use OCP\Util;
|
2022-08-13 01:58:37 +00:00
|
|
|
|
2022-10-19 17:10:36 +00:00
|
|
|
class PageController extends Controller
|
|
|
|
{
|
2022-09-14 18:19:51 +00:00
|
|
|
protected $userId;
|
2022-09-09 07:31:42 +00:00
|
|
|
protected $appName;
|
|
|
|
protected IEventDispatcher $eventDispatcher;
|
2022-10-19 17:10:36 +00:00
|
|
|
private IAppManager $appManager;
|
2022-09-09 07:31:42 +00:00
|
|
|
private IInitialState $initialState;
|
|
|
|
private IUserSession $userSession;
|
|
|
|
private IConfig $config;
|
2022-08-13 01:58:37 +00:00
|
|
|
|
2022-09-09 07:31:42 +00:00
|
|
|
public function __construct(
|
|
|
|
string $AppName,
|
|
|
|
IRequest $request,
|
2022-09-14 18:19:51 +00:00
|
|
|
$UserId,
|
2022-10-07 17:46:09 +00:00
|
|
|
IAppManager $appManager,
|
2022-09-09 07:31:42 +00:00
|
|
|
IEventDispatcher $eventDispatcher,
|
|
|
|
IInitialState $initialState,
|
|
|
|
IUserSession $userSession,
|
2022-10-19 17:10:36 +00:00
|
|
|
IConfig $config
|
2022-10-19 17:15:14 +00:00
|
|
|
) {
|
2022-09-09 07:31:42 +00:00
|
|
|
parent::__construct($AppName, $request);
|
|
|
|
$this->userId = $UserId;
|
|
|
|
$this->appName = $AppName;
|
2022-10-07 17:46:09 +00:00
|
|
|
$this->appManager = $appManager;
|
2022-09-09 07:31:42 +00:00
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
|
|
|
$this->initialState = $initialState;
|
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
2022-08-13 01:58:37 +00:00
|
|
|
|
2022-09-09 07:31:42 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-09 07:31:42 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function main()
|
|
|
|
{
|
2022-09-09 07:31:42 +00:00
|
|
|
$user = $this->userSession->getUser();
|
2022-10-19 17:10:36 +00:00
|
|
|
if (null === $user) {
|
2022-09-09 07:31:42 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-08-20 00:18:04 +00:00
|
|
|
|
2022-10-07 17:46:09 +00:00
|
|
|
// Scripts
|
2022-09-09 07:31:42 +00:00
|
|
|
Util::addScript($this->appName, 'memories-main');
|
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
|
2022-08-15 21:41:05 +00:00
|
|
|
|
2022-10-07 17:46:09 +00:00
|
|
|
// Configuration
|
2022-09-16 22:42:29 +00:00
|
|
|
$uid = $user->getUid();
|
2022-10-25 04:30:43 +00:00
|
|
|
$this->initialState->provideInitialState('timelinePath', $this->config->getUserValue(
|
|
|
|
$uid,
|
|
|
|
Application::APPNAME,
|
|
|
|
'timelinePath',
|
|
|
|
'EMPTY'
|
|
|
|
));
|
2022-10-19 19:26:32 +00:00
|
|
|
$this->initialState->provideInitialState('foldersPath', $this->config->getUserValue(
|
|
|
|
$uid,
|
|
|
|
Application::APPNAME,
|
|
|
|
'foldersPath',
|
|
|
|
'/'
|
|
|
|
));
|
2022-10-19 17:10:36 +00:00
|
|
|
$this->initialState->provideInitialState('showHidden', $this->config->getUserValue(
|
|
|
|
$uid,
|
|
|
|
Application::APPNAME,
|
|
|
|
'showHidden',
|
|
|
|
false
|
|
|
|
));
|
2022-08-20 00:18:04 +00:00
|
|
|
|
2022-10-07 17:46:09 +00:00
|
|
|
// Apps enabled
|
2022-10-19 17:10:36 +00:00
|
|
|
$this->initialState->provideInitialState('systemtags', true === $this->appManager->isEnabledForUser('systemtags'));
|
2022-10-26 18:58:06 +00:00
|
|
|
$this->initialState->provideInitialState('maps', true === $this->appManager->isEnabledForUser('maps'));
|
2022-10-27 20:45:03 +00:00
|
|
|
$this->initialState->provideInitialState('recognize', \OCA\Memories\Util::recognizeIsEnabled($this->appManager));
|
|
|
|
$this->initialState->provideInitialState('albums', \OCA\Memories\Util::albumsIsEnabled($this->appManager));
|
|
|
|
|
|
|
|
// App version
|
2022-10-19 17:10:36 +00:00
|
|
|
$this->initialState->provideInitialState('version', $this->appManager->getAppInfo('memories')['version']);
|
2022-10-07 17:46:09 +00:00
|
|
|
|
2022-10-17 02:52:44 +00:00
|
|
|
$policy = new ContentSecurityPolicy();
|
2022-10-19 17:10:36 +00:00
|
|
|
$policy->addAllowedWorkerSrcDomain("'self'");
|
|
|
|
$policy->addAllowedScriptDomain("'self'");
|
2022-10-17 02:52:44 +00:00
|
|
|
|
2022-11-07 23:49:50 +00:00
|
|
|
// Allow nominatim for metadata
|
|
|
|
$policy->addAllowedConnectDomain('nominatim.openstreetmap.org');
|
|
|
|
|
2022-09-09 07:31:42 +00:00
|
|
|
$response = new TemplateResponse($this->appName, 'main');
|
2022-10-17 02:52:44 +00:00
|
|
|
$response->setContentSecurityPolicy($policy);
|
2022-10-19 17:10:36 +00:00
|
|
|
|
2022-09-09 07:31:42 +00:00
|
|
|
return $response;
|
|
|
|
}
|
2022-08-13 01:58:37 +00:00
|
|
|
|
2022-09-09 07:31:42 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-09 07:31:42 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function folder()
|
|
|
|
{
|
2022-09-09 07:31:42 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-09-12 03:06:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-12 03:06:28 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function favorites()
|
|
|
|
{
|
2022-09-12 03:06:28 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-09-13 07:55:32 +00:00
|
|
|
|
2022-10-26 22:12:46 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function albums()
|
|
|
|
{
|
|
|
|
return $this->main();
|
|
|
|
}
|
|
|
|
|
2022-09-13 07:55:32 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-13 07:55:32 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function videos()
|
|
|
|
{
|
2022-09-13 07:55:32 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-09-25 23:02:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-25 23:02:26 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function archive()
|
|
|
|
{
|
2022-09-25 23:02:26 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-10-06 20:20:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-10-06 20:20:29 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function thisday()
|
|
|
|
{
|
2022-10-06 20:20:29 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-10-06 23:28:35 +00:00
|
|
|
|
2022-10-07 19:28:39 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-10-07 19:28:39 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function people()
|
|
|
|
{
|
2022-10-07 19:28:39 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
|
|
|
|
2022-10-06 23:28:35 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-10-06 23:28:35 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function tags()
|
|
|
|
{
|
2022-10-06 23:28:35 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-08-13 01:58:37 +00:00
|
|
|
}
|