1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Audio Player |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the LICENSE.md file. |
7
|
|
|
* |
8
|
|
|
* @author Marcel Scherello <[email protected]> |
9
|
|
|
* @author Sebastian Doell <[email protected]> |
10
|
|
|
* @copyright 2016-2021 Marcel Scherello |
11
|
|
|
* @copyright 2015 Sebastian Doell |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OCA\audioplayer\Controller; |
15
|
|
|
|
16
|
|
|
use OCA\audioplayer\Event\LoadAdditionalScriptsEvent; |
17
|
|
|
use OCP\AppFramework\Controller; |
18
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
19
|
|
|
use OCP\IRequest; |
20
|
|
|
use OCP\IConfig; |
21
|
|
|
use OCP\IL10N; |
22
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy; |
23
|
|
|
use OCP\EventDispatcher\IEventDispatcher; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Controller class for main page. |
27
|
|
|
*/ |
28
|
|
|
class PageController extends Controller |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
private $userId; |
32
|
|
|
private $l10n; |
33
|
|
|
private $configManager; |
34
|
|
|
/** @var IEventDispatcher */ |
35
|
|
|
protected $eventDispatcher; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function __construct( |
39
|
|
|
$appName, |
40
|
|
|
IRequest $request, |
41
|
|
|
$userId, |
42
|
|
|
IConfig $configManager, |
43
|
|
|
IEventDispatcher $eventDispatcher, |
44
|
|
|
IL10N $l10n |
45
|
|
|
) |
46
|
|
|
{ |
47
|
|
|
parent::__construct($appName, $request); |
48
|
|
|
$this->appName = $appName; |
49
|
|
|
$this->userId = $userId; |
50
|
|
|
$this->configManager = $configManager; |
51
|
|
|
$this->l10n = $l10n; |
52
|
|
|
$this->eventDispatcher = $eventDispatcher; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @NoAdminRequired |
57
|
|
|
* @NoCSRFRequired |
58
|
|
|
* @throws \OCP\PreConditionNotMetException |
59
|
|
|
*/ |
60
|
|
|
public function index() |
61
|
|
|
{ |
62
|
|
|
|
63
|
|
|
if ($this->configManager->getAppValue('audioplayer_sonos', 'enabled') === "yes" AND $this->configManager->getAppValue('audioplayer_sonos', 'sonos') === "checked") { |
64
|
|
|
$audioplayer_sonos = $this->configManager->getUserValue($this->userId, 'audioplayer_sonos', 'sonos') ?: false; |
65
|
|
|
} else { |
66
|
|
|
$audioplayer_sonos = false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$event = new LoadAdditionalScriptsEvent(); |
70
|
|
|
$this->eventDispatcher->dispatchTyped($event); |
71
|
|
|
|
72
|
|
|
$response = new TemplateResponse('audioplayer', 'index'); |
73
|
|
|
$csp = new ContentSecurityPolicy(); |
74
|
|
|
$csp->addAllowedMediaDomain('*'); //required for external m3u playlists |
75
|
|
|
$response->setContentSecurityPolicy($csp); |
76
|
|
|
$response->setParams([ |
77
|
|
|
'audioplayer_navigationShown' => $this->configManager->getUserValue($this->userId, $this->appName, 'navigation'), |
78
|
|
|
'audioplayer_view' => $this->configManager->getUserValue($this->userId, $this->appName, 'view') ?: 'pictures', |
79
|
|
|
'audioplayer_volume' => $this->configManager->getUserValue($this->userId, $this->appName, 'volume') ?: '1', |
80
|
|
|
'audioplayer_repeat' => $this->configManager->getUserValue($this->userId, $this->appName, 'repeat') ?: 'none', |
81
|
|
|
'audioplayer_sonos' => $audioplayer_sonos, |
82
|
|
|
]); |
83
|
|
|
return $response; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|