+function invidious_settings(array &$data)
+{
+ if (!DI::userSession()->getLocalUserId()) {
+ return;
+ }
+
+ $enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'invidious', 'enabled');
+ $server = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'invidious', 'server', DI::config()->get('invidious', 'server', INVIDIOUS_DEFAULT));
+
+ $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/invidious/');
+ $html = Renderer::replaceMacros($t, [
+ '$enabled' => ['enabled', DI::l10n()->t('Replace Youtube links with links to an Invidious server'), $enabled, DI::l10n()->t('If enabled, Youtube links are replaced with the links to the specified Invidious server.')],
+ '$server' => ['server', DI::l10n()->t('Invidious server'), $server, DI::l10n()->t('See %s for a list of available Invidious servers.', '<a href="https://api.invidious.io/">https://api.invidious.io/</a>')],
+ ]);
+
+ $data = [
+ 'addon' => 'invidious',
+ 'title' => DI::l10n()->t('Invidious Settings'),
+ 'html' => $html,
+ ];
+}
+
+function invidious_settings_post(array &$b)
+{
+ if (!DI::userSession()->getLocalUserId() || empty($_POST['invidious-submit'])) {
+ return;
+ }
+
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'invidious', 'enabled', (bool)$_POST['enabled']);
+
+ $server = trim($_POST['server'], " \n\r\t\v\x00/");
+ if ($server != DI::config()->get('invidious', 'server', INVIDIOUS_DEFAULT) && !empty($server)) {
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'invidious', 'server', $server);
+ } else {
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'invidious', 'server');
+ }
+}
+