diff --git a/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php b/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php index 258138caa42be..a222fd1684dc5 100644 --- a/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php +++ b/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php @@ -11,6 +11,7 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\Theming\IDefaults; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; use Sabre\HTTP\RequestInterface; @@ -22,23 +23,17 @@ class AppleProvisioningPlugin extends ServerPlugin { */ protected $server; - /** - * @var \OC_Defaults - */ - protected $themingDefaults; - /** * AppleProvisioningPlugin constructor. */ public function __construct( protected IUserSession $userSession, protected IURLGenerator $urlGenerator, - \OC_Defaults $themingDefaults, + protected IDefaults $themingDefaults, protected IRequest $request, protected IL10N $l10n, protected \Closure $uuidClosure, ) { - $this->themingDefaults = $themingDefaults; } /** diff --git a/apps/files_sharing/tests/CapabilitiesTest.php b/apps/files_sharing/tests/CapabilitiesTest.php index 644cde444bd32..cfad6d8ad503d 100644 --- a/apps/files_sharing/tests/CapabilitiesTest.php +++ b/apps/files_sharing/tests/CapabilitiesTest.php @@ -27,6 +27,7 @@ use OCP\Security\IHasher; use OCP\Security\ISecureRandom; use OCP\Share\IProviderFactory; +use OCP\Theming\IDefaults; use Psr\Log\LoggerInterface; /** @@ -93,7 +94,7 @@ private function getResults(array $map, array $typedMap = [], bool $federationEn $this->createMock(IRootFolder::class), $this->createMock(IMailer::class), $this->createMock(IURLGenerator::class), - $this->createMock(\OC_Defaults::class), + $this->createMock(IDefaults::class), $this->createMock(IEventDispatcher::class), $this->createMock(IUserSession::class), $this->createMock(KnownUserService::class), diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 71afae14a8ea7..aa74258a13c13 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -1,40 +1,39 @@ name = parent::getName(); - $this->title = parent::getTitle(); - $this->entity = parent::getEntity(); - $this->productName = parent::getProductName(); - $this->url = parent::getBaseUrl(); - $this->primaryColor = parent::getColorPrimary(); - $this->backgroundColor = parent::getColorBackground(); - $this->iTunesAppId = parent::getiTunesAppId(); - $this->iOSClientUrl = parent::getiOSClientUrl(); - $this->AndroidClientUrl = parent::getAndroidClientUrl(); - $this->FDroidClientUrl = parent::getFDroidClientUrl(); - $this->docBaseUrl = parent::getDocBaseUrl(); - } + $themeName = $config->getSystemValueString('theme', ''); + if ($themeName === '') { + if (is_dir(\OC::$SERVERROOT . '/themes/default')) { + $themeName = 'default'; + } + } + $themePath = \OC::$SERVERROOT . '/themes/' . $themeName . '/defaults.php'; + if (file_exists($themePath)) { + // prevent defaults.php from printing output + ob_start(); + require_once $themePath; + ob_end_clean(); + if (class_exists(\OC_Theme::class)) { + $this->theme = new \OC_Theme(); + } + } - public function getName() { - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); + $this->iTunesAppId = $this->getFromLegacyTheme( + 'getiTunesAppId', + $config->getSystemValueString('customclient_ios_appid', '1125420102') + ); + $this->iOSClientUrl = $this->getFromLegacyTheme( + 'getiOSClientUrl', + $config->getSystemValueString('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8') + ); + $this->AndroidClientUrl = $this->getFromLegacyTheme( + 'getAndroidClientUrl', + $config->getSystemValueString('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client') + ); + $this->FDroidClientUrl = $this->getFromLegacyTheme( + 'getFDroidClientUrl', + $config->getSystemValueString('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/') + ); + $this->defaultDocVersion = (string)$serverVersion->getMajorVersion(); // used to generate doc links + } + + private function getFromLegacyTheme(string $method, string $default): string { + if (isset($this->theme) && method_exists($this->theme, $method)) { + return $this->theme->$method(); + } + return $default; } - public function getHTMLName() { - return $this->config->getAppValue('theming', 'name', $this->name); + public function getName(): string { + return strip_tags($this->appConfig->getAppValueString('name', $this->getFromLegacyTheme('getName', 'Nextcloud'))); } - public function getTitle() { - return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); + public function getTitle(): string { + return strip_tags($this->appConfig->getAppValueString('name', $this->getFromLegacyTheme('getTitle', 'Nextcloud'))); } - public function getEntity() { - return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); + public function getEntity(): string { + return strip_tags($this->appConfig->getAppValueString('name', $this->getFromLegacyTheme('getEntity', 'Nextcloud'))); } - public function getProductName() { - return strip_tags($this->config->getAppValue('theming', 'productName', $this->productName)); + public function getProductName(): string { + return strip_tags($this->appConfig->getAppValueString('productName', $this->getFromLegacyTheme('getProductName', 'Nextcloud'))); } - public function getBaseUrl() { - return $this->config->getAppValue('theming', 'url', $this->url); + public function getBaseUrl(): string { + return $this->appConfig->getAppValueString('url', $this->getFromLegacyTheme('getBaseUrl', 'https://nextcloud.com')); } /** @@ -97,23 +120,33 @@ public function getBaseUrl() { * @psalm-suppress InvalidReturnStatement * @psalm-suppress InvalidReturnType */ - public function getSlogan(?string $lang = null) { - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); + public function getSlogan(?string $lang = null): string { + if ($this->appConfig->hasAppKey('slogan')) { + return \OCP\Util::sanitizeHTML($this->appConfig->getAppValueString('slogan')); + } + if (isset($this->theme) && method_exists($this->theme, 'getSlogan')) { + return $this->theme->getSlogan($lang); + } + if ($this->defaultSlogan === null) { + $l10n = \OCP\Util::getL10N('lib', $lang); + $this->defaultSlogan = $l10n->t('a safe home for all your data'); + } + return $this->defaultSlogan; } - public function getImprintUrl() { - return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); + public function getImprintUrl(): string { + return $this->appConfig->getAppValueString('imprintUrl', ''); } - public function getPrivacyUrl() { - return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); + public function getPrivacyUrl(): string { + return $this->appConfig->getAppValueString('privacyUrl', ''); } - public function getDocBaseUrl() { - return (string)$this->config->getAppValue('theming', 'docBaseUrl', $this->docBaseUrl); + public function getDocBaseUrl(): string { + return $this->appConfig->getAppValueString('docBaseUrl', $this->getFromLegacyTheme('getDocBaseUrl', 'https://docs.nextcloud.com')); } - public function getShortFooter() { + public function getShortFooter(): string { $slogan = $this->getSlogan(); $baseUrl = $this->getBaseUrl(); $entity = $this->getEntity(); @@ -132,11 +165,11 @@ public function getShortFooter() { $links = [ [ 'text' => $this->l->t('Legal notice'), - 'url' => (string)$this->getImprintUrl() + 'url' => $this->getImprintUrl() ], [ 'text' => $this->l->t('Privacy policy'), - 'url' => (string)$this->getPrivacyUrl() + 'url' => $this->getPrivacyUrl() ], ]; @@ -167,6 +200,13 @@ public function getShortFooter() { return $footer; } + /** + * Returns long version of the footer + */ + public function getLongFooter(): string { + return $this->getFromLegacyTheme('getLongFooter', $this->getShortFooter()); + } + /** * Color that is used for highlighting elements like important buttons * If user theming is enabled then the user defined value is returned @@ -224,42 +264,40 @@ public function getColorBackground(): string { */ public function getDefaultColorPrimary(): string { // try admin color - $defaultColor = $this->appConfig->getValueString(Application::APP_ID, 'primary_color', ''); + $defaultColor = $this->appConfig->getAppValueString('primary_color', ''); if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) { return $defaultColor; } - // fall back to default primary color - return $this->primaryColor; + return $this->getFromLegacyTheme('getColorPrimary', $this->getFromLegacyTheme('getMailHeaderColor', '#00679e')); } /** * Default background color only taking admin setting into account */ public function getDefaultColorBackground(): string { - $defaultColor = $this->appConfig->getValueString(Application::APP_ID, 'background_color'); + $defaultColor = $this->appConfig->getAppValueString('background_color'); if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) { return $defaultColor; } - return $this->backgroundColor; + return $this->getFromLegacyTheme('getColorBackground', '#00679e'); } /** * Themed logo url * * @param bool $useSvg Whether to point to the SVG image or a fallback - * @return string */ - public function getLogo($useSvg = true): string { - $logo = $this->config->getAppValue('theming', 'logoMime', ''); + public function getLogo(bool $useSvg = true): string { + $logo = $this->appConfig->getAppValueString('logoMime', ''); // short cut to avoid setting up the filesystem just to check if the logo is there // // explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there. // otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which // needs to be called then) - if ($useSvg === true && $logo !== false) { + if ($useSvg === true && $logo !== '') { $logoExists = true; } else { try { @@ -270,9 +308,9 @@ public function getLogo($useSvg = true): string { } } - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); + $cacheBusterCounter = $this->appConfig->getAppValueString('cachebuster', '0'); - if (!$logo || !$logoExists) { + if ($logo !== '' || !$logoExists) { if ($useSvg) { $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); } else { @@ -288,82 +326,32 @@ public function getLogo($useSvg = true): string { * Themed background image url * * @param bool $darkVariant if the dark variant (if available) of the background should be used - * @return string */ public function getBackground(bool $darkVariant = false): string { return $this->imageManager->getImageUrl('background' . ($darkVariant ? 'Dark' : '')); } - /** - * @return string - */ - public function getiTunesAppId() { - return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); + public function getiTunesAppId(): string { + return $this->appConfig->getAppValueString('iTunesAppId', $this->iTunesAppId); } - /** - * @return string - */ - public function getiOSClientUrl() { - return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); + public function getiOSClientUrl(): string { + return $this->appConfig->getAppValueString('iOSClientUrl', $this->iOSClientUrl); } - /** - * @return string - */ - public function getAndroidClientUrl() { - return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); + public function getAndroidClientUrl(): string { + return $this->appConfig->getAppValueString('AndroidClientUrl', $this->AndroidClientUrl); } - /** - * @return string - */ - public function getFDroidClientUrl() { - return $this->config->getAppValue('theming', 'FDroidClientUrl', $this->FDroidClientUrl); + public function getFDroidClientUrl(): string { + return $this->appConfig->getAppValueString('FDroidClientUrl', $this->FDroidClientUrl); } /** - * @return array scss variables to overwrite - * @deprecated since Nextcloud 22 - https://github.com/nextcloud/server/issues/9940 + * Returns the URL where the sync clients are listed */ - public function getScssVariables() { - $cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0'); - $cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl()); - if ($value = $cache->get('getScssVariables')) { - return $value; - } - - $variables = [ - 'theming-cachebuster' => "'" . $cacheBuster . "'", - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" - ]; - - $variables['image-logo'] = "url('" . $this->imageManager->getImageUrl('logo') . "')"; - $variables['image-logoheader'] = "url('" . $this->imageManager->getImageUrl('logoheader') . "')"; - $variables['image-favicon'] = "url('" . $this->imageManager->getImageUrl('favicon') . "')"; - $variables['image-login-background'] = "url('" . $this->imageManager->getImageUrl('background') . "')"; - $variables['image-login-plain'] = 'false'; - - if ($this->appConfig->getValueString(Application::APP_ID, 'primary_color', '') !== '') { - $variables['color-primary'] = $this->getColorPrimary(); - $variables['color-primary-text'] = $this->getTextColorPrimary(); - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); - } - - if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') { - $variables['image-login-plain'] = 'true'; - } - - $variables['has-legal-links'] = 'false'; - if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { - $variables['has-legal-links'] = 'true'; - } - - $cache->set('getScssVariables', $variables); - return $variables; + public function getSyncClientUrl(): string { + return $this->getFromLegacyTheme('getSyncClientUrl', $this->config->getSystemValueString('customclient_desktop', 'https://nextcloud.com/install/#install-clients')); } /** @@ -372,15 +360,15 @@ public function getScssVariables() { * * @param string $app name of the app * @param string $image filename of the image - * @return bool|string false if image should not replaced, otherwise the location of the image + * @return string|false false if image should not replaced, otherwise the location of the image */ - public function replaceImagePath($app, $image) { + public function replaceImagePath(string $app, string $image): string|false { if ($app === '' || $app === 'files_sharing') { $app = 'core'; } - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); + $cacheBusterValue = $this->appConfig->getAppValueString('cachebuster', '0'); - $route = false; + $route = ''; if ($image === 'favicon.ico' && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) { $route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]); } @@ -401,7 +389,7 @@ public function replaceImagePath($app, $image) { $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); } - if ($route) { + if ($route !== '') { return $route . '?v=' . $this->util->getCacheBuster(); } @@ -420,20 +408,17 @@ protected function getCustomFavicon(): ?ISimpleFile { * Increases the cache buster key */ public function increaseCacheBuster(): void { - $cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0'); - $this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1)); + $cacheBusterKey = (int)$this->appConfig->getAppValueString('cachebuster', '0'); + $this->appConfig->setAppValueString('cachebuster', (string)($cacheBusterKey + 1)); $this->cacheFactory->createDistributed('theming-')->clear(); $this->cacheFactory->createDistributed('imagePath')->clear(); } /** * Update setting in the database - * - * @param string $setting - * @param string $value */ - public function set($setting, $value): void { - $this->appConfig->setValueString('theming', $setting, $value); + public function set(string $setting, string $value): void { + $this->appConfig->setAppValueString($setting, $value); $this->increaseCacheBuster(); } @@ -443,9 +428,9 @@ public function set($setting, $value): void { public function undoAll(): void { // Remember the current cachebuster value, as we do not want to reset this value // Otherwise this can lead to caching issues as the value might be known to a browser already - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); - $this->config->deleteAppValues('theming'); - $this->config->setAppValue('theming', 'cachebuster', $cacheBusterKey); + $cacheBusterKey = $this->appConfig->getAppValueString('cachebuster', '0'); + $this->appConfig->deleteAppValues(); + $this->appConfig->setAppValueString('cachebuster', $cacheBusterKey); $this->increaseCacheBuster(); } @@ -455,8 +440,8 @@ public function undoAll(): void { * @param string $setting setting which should be reverted * @return string default value */ - public function undo($setting): string { - $this->config->deleteAppValue('theming', $setting); + public function undo(string $setting): string { + $this->appConfig->deleteAppValue($setting); $this->increaseCacheBuster(); $returnValue = ''; @@ -485,7 +470,7 @@ public function undo($setting): string { case 'background': case 'favicon': $this->imageManager->delete($setting); - $this->config->deleteAppValue('theming', $setting . 'Mime'); + $this->appConfig->deleteAppValue($setting . 'Mime'); break; } @@ -494,28 +479,22 @@ public function undo($setting): string { /** * Color of text in the header menu - * - * @return string */ - public function getTextColorBackground() { + public function getTextColorBackground(): string { return $this->util->invertTextColor($this->getColorBackground()) ? '#000000' : '#ffffff'; } /** * Color of text on primary buttons and other elements - * - * @return string */ - public function getTextColorPrimary() { + public function getTextColorPrimary(): string { return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; } /** * Color of text in the header and primary buttons - * - * @return string */ - public function getDefaultTextColorPrimary() { + public function getDefaultTextColorPrimary(): string { return $this->util->invertTextColor($this->getDefaultColorPrimary()) ? '#000000' : '#ffffff'; } @@ -523,6 +502,16 @@ public function getDefaultTextColorPrimary() { * Has the admin disabled user customization */ public function isUserThemingDisabled(): bool { - return $this->appConfig->getValueBool(Application::APP_ID, 'disable-user-theming'); + return $this->appConfig->getAppValueBool('disable-user-theming'); + } + + /** + * @return string URL to doc with key + */ + public function buildDocLinkToKey(string $key): string { + if (isset($this->theme) && method_exists($this->theme, 'buildDocLinkToKey')) { + return $this->theme->buildDocLinkToKey($key); + } + return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key; } } diff --git a/apps/theming/tests/ServicesTest.php b/apps/theming/tests/ServicesTest.php index 3971c9b66986a..c7952be5894f2 100644 --- a/apps/theming/tests/ServicesTest.php +++ b/apps/theming/tests/ServicesTest.php @@ -46,7 +46,6 @@ public static function queryData(): array { [Capabilities::class], [Capabilities::class, ICapability::class], [ThemingDefaults::class], - [ThemingDefaults::class, \OC_Defaults::class], [Util::class], // Controller diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 917ab960318a0..7f53ece431f04 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -650,71 +650,6 @@ public function testGetLogoCustom(): void { $this->assertEquals('custom-logo' . '?v=0', $this->template->getLogo()); } - public function testGetScssVariablesCached(): void { - $this->config->expects($this->any())->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('1'); - $this->cacheFactory->expects($this->once()) - ->method('createDistributed') - ->with('theming-1-') - ->willReturn($this->cache); - $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(['foo' => 'bar']); - $this->assertEquals(['foo' => 'bar'], $this->template->getScssVariables()); - } - - public function testGetScssVariables(): void { - $this->config - ->expects($this->any()) - ->method('getAppValue') - ->willReturnMap([ - ['theming', 'cachebuster', '0', '0'], - ['theming', 'logoMime', '', 'jpeg'], - ['theming', 'backgroundMime', '', 'jpeg'], - ['theming', 'logoheaderMime', '', 'jpeg'], - ['theming', 'faviconMime', '', 'jpeg'], - ]); - - $this->appConfig - ->expects(self::atLeastOnce()) - ->method('getValueString') - ->willReturnMap([ - ['theming', 'primary_color', '', false, $this->defaults->getColorPrimary()], - ['theming', 'primary_color', $this->defaults->getColorPrimary(), false, $this->defaults->getColorPrimary()], - ]); - - $this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false); - $this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa'); - $this->cacheFactory->expects($this->once()) - ->method('createDistributed') - ->with('theming-0-') - ->willReturn($this->cache); - $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null); - $this->imageManager->expects($this->exactly(4)) - ->method('getImageUrl') - ->willReturnMap([ - ['logo', 'custom-logo?v=0'], - ['logoheader', 'custom-logoheader?v=0'], - ['favicon', 'custom-favicon?v=0'], - ['background', 'custom-background?v=0'], - ]); - - $expected = [ - 'theming-cachebuster' => '\'0\'', - 'theming-logo-mime' => '\'jpeg\'', - 'theming-background-mime' => '\'jpeg\'', - 'image-logo' => "url('custom-logo?v=0')", - 'image-login-background' => "url('custom-background?v=0')", - 'color-primary' => $this->defaults->getColorPrimary(), - 'color-primary-text' => '#ffffff', - 'image-login-plain' => 'false', - 'color-primary-element' => '#aaaaaa', - 'theming-logoheader-mime' => '\'jpeg\'', - 'theming-favicon-mime' => '\'jpeg\'', - 'image-logoheader' => "url('custom-logoheader?v=0')", - 'image-favicon' => "url('custom-favicon?v=0')", - 'has-legal-links' => 'false' - ]; - $this->assertEquals($expected, $this->template->getScssVariables()); - } - public function testGetDefaultAndroidURL(): void { $this->config ->expects($this->once()) diff --git a/core/Command/Base.php b/core/Command/Base.php index 138f3ca613bf7..7ea1ab04197fb 100644 --- a/core/Command/Base.php +++ b/core/Command/Base.php @@ -8,8 +8,8 @@ namespace OC\Core\Command; use OC\Core\Command\User\ListCommand; -use OCP\Defaults; use OCP\Server; +use OCP\Theming\IDefaults; use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Command\Command; @@ -29,7 +29,7 @@ class Base extends Command implements CompletionAwareInterface { protected function configure() { // Some of our commands do not extend this class; and some of those that do do not call parent::configure() - $defaultHelp = 'More extensive and thorough documentation may be found at ' . Server::get(Defaults::class)->getDocBaseUrl() . PHP_EOL; + $defaultHelp = '';//'More extensive and thorough documentation may be found at ' . Server::get(IDefaults::class)->getDocBaseUrl() . PHP_EOL; $this ->setHelp($defaultHelp) ->addOption( diff --git a/core/Command/Status.php b/core/Command/Status.php index a00d4a94658fd..099b8c8fb90be 100644 --- a/core/Command/Status.php +++ b/core/Command/Status.php @@ -7,7 +7,6 @@ */ namespace OC\Core\Command; -use OCP\Defaults; use OCP\IConfig; use OCP\ServerVersion; use OCP\Util; @@ -18,7 +17,7 @@ class Status extends Base { public function __construct( private IConfig $config, - private Defaults $themingDefaults, + private string $productName, private ServerVersion $serverVersion, ) { parent::__construct('status'); @@ -47,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'edition' => '', 'maintenance' => $maintenanceMode, 'needsDbUpgrade' => $needUpgrade, - 'productname' => $this->themingDefaults->getProductName(), + 'productname' => $this->productName, 'extendedSupport' => Util::hasExtendedSupport() ]; diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index 47cced308bcbf..0ef6f27876a9c 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -6,7 +6,7 @@ */ /** - * @var \OC_Defaults $theme + * @var \OCP\Theming\IDefaults $theme * @var array $_ */ diff --git a/lib/base.php b/lib/base.php index fb3794aa8ec17..f72ca26cd3a78 100644 --- a/lib/base.php +++ b/lib/base.php @@ -354,7 +354,7 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); $tmpl->assign('incompatibleAppsList', $incompatibleDisabledApps); try { - $defaults = new \OC_Defaults(); + $defaults = Server::get(\OCP\Theming\IDefaults::class); $tmpl->assign('productName', $defaults->getName()); } catch (Throwable $error) { $tmpl->assign('productName', 'Nextcloud'); diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 4cbade8e68e3b..88e69ca230465 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -932,6 +932,7 @@ 'OCP\\TextToImage\\IProvider' => $baseDir . '/lib/public/TextToImage/IProvider.php', 'OCP\\TextToImage\\IProviderWithUserId' => $baseDir . '/lib/public/TextToImage/IProviderWithUserId.php', 'OCP\\TextToImage\\Task' => $baseDir . '/lib/public/TextToImage/Task.php', + 'OCP\\Theming\\IDefaults' => $baseDir . '/lib/public/Theming/IDefaults.php', 'OCP\\Translation\\CouldNotTranslateException' => $baseDir . '/lib/public/Translation/CouldNotTranslateException.php', 'OCP\\Translation\\IDetectLanguageProvider' => $baseDir . '/lib/public/Translation/IDetectLanguageProvider.php', 'OCP\\Translation\\ITranslationManager' => $baseDir . '/lib/public/Translation/ITranslationManager.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 79f4c88358f00..5788526fe54f9 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -973,6 +973,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\TextToImage\\IProvider' => __DIR__ . '/../../..' . '/lib/public/TextToImage/IProvider.php', 'OCP\\TextToImage\\IProviderWithUserId' => __DIR__ . '/../../..' . '/lib/public/TextToImage/IProviderWithUserId.php', 'OCP\\TextToImage\\Task' => __DIR__ . '/../../..' . '/lib/public/TextToImage/Task.php', + 'OCP\\Theming\\IDefaults' => __DIR__ . '/../../..' . '/lib/public/Theming/IDefaults.php', 'OCP\\Translation\\CouldNotTranslateException' => __DIR__ . '/../../..' . '/lib/public/Translation/CouldNotTranslateException.php', 'OCP\\Translation\\IDetectLanguageProvider' => __DIR__ . '/../../..' . '/lib/public/Translation/IDetectLanguageProvider.php', 'OCP\\Translation\\ITranslationManager' => __DIR__ . '/../../..' . '/lib/public/Translation/ITranslationManager.php', diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 76261fe6b92c5..95406789d1c42 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -138,9 +138,7 @@ public function __construct(string $appName, array $urlParams = [], ?ServerConta return $c->get(IServerContainer::class)->getWebRoot(); }); - $this->registerService('OC_Defaults', function (ContainerInterface $c): object { - return $c->get(IServerContainer::class)->get('ThemingDefaults'); - }); + $this->registerDeprecatedAlias('OC_Defaults', \OCP\Theming\IDefaults::class); /** @deprecated 32.0.0 */ $this->registerDeprecatedAlias('Protocol', Http::class); diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 4cf1e0da8ca13..fa08872fb6440 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -14,7 +14,6 @@ use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use OCP\Console\ConsoleEvent; -use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IRequest; @@ -39,9 +38,9 @@ public function __construct( private LoggerInterface $logger, private MemoryInfo $memoryInfo, private IAppManager $appManager, - private Defaults $defaults, + string $instanceName, ) { - $this->application = new SymfonyApplication($defaults->getName(), $serverVersion->getVersionString()); + $this->application = new SymfonyApplication($instanceName, $serverVersion->getVersionString()); } /** diff --git a/lib/private/Server.php b/lib/private/Server.php index 2804acbbb7964..1de2a60ec7682 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1001,8 +1001,24 @@ public function __construct($webRoot, \OC\Config $config) { return $manager; }); - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); - $this->registerService('ThemingDefaults', function (Server $c) { + $this->registerService('instanceName', function (ContainerInterface $c) { + try { + return $c->get(\OCP\Theming\IDefaults::class)->getName(); + } catch (\Throwable $e) { + return 'Nextcloud'; + } + }); + $this->registerService('productName', function (ContainerInterface $c) { + try { + return $c->get(\OCP\Theming\IDefaults::class)->getProductName(); + } catch (\Throwable $e) { + return 'Nextcloud'; + } + }); + $this->registerDeprecatedAlias(\OC_Defaults::class, \OCP\Theming\IDefaults::class); + $this->registerDeprecatedAlias('ThemingDefaults', \OCP\Theming\IDefaults::class); + $this->registerAlias(ThemingDefaults::class, \OCP\Theming\IDefaults::class); + $this->registerService(\OCP\Theming\IDefaults::class, function (Server $c) { try { $classExists = class_exists('OCA\Theming\ThemingDefaults'); } catch (\OCP\AutoloadNotAllowedException $e) { @@ -1010,7 +1026,7 @@ public function __construct($webRoot, \OC\Config $config) { $classExists = false; } - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { $backgroundService = new BackgroundService( $c->get(IRootFolder::class), $c->getAppDataDir('theming'), @@ -1029,7 +1045,7 @@ public function __construct($webRoot, \OC\Config $config) { ); return new ThemingDefaults( $c->get(\OCP\IConfig::class), - $c->get(\OCP\IAppConfig::class), + $c->getAppContainerForService(\OCA\Theming\ThemingDefaults::class)->get(\OCP\AppFramework\Services\IAppConfig::class), $c->getL10N('theming'), $c->get(IUserSession::class), $c->get(IURLGenerator::class), @@ -1039,8 +1055,14 @@ public function __construct($webRoot, \OC\Config $config) { $c->get(IAppManager::class), $c->get(INavigationManager::class), $backgroundService, + $c->get(ServerVersion::class), ); } + var_dump( + $classExists, + $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false), + $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())); + throw new \Exception('Does it break?'); return new \OC_Defaults(); }); $this->registerService(JSCombiner::class, function (Server $c) { diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 15f0a4eb61700..f0a8beaa43f97 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -21,7 +21,6 @@ use OC\User\BackgroundJobs\CleanupDeletedUsers; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; -use OCP\Defaults; use OCP\Http\Client\IClientService; use OCP\IAppConfig; use OCP\IConfig; @@ -46,7 +45,7 @@ public function __construct( protected SystemConfig $config, protected IniGetWrapper $iniWrapper, IL10NFactory $l10nFactory, - protected Defaults $defaults, + protected string $productName, protected LoggerInterface $logger, protected ISecureRandom $random, protected Installer $installer, @@ -189,7 +188,7 @@ public function getSystemInfo(bool $allowAllDatabases = false): array { 'error' => $this->l10n->t( 'Mac OS X is not supported and %s will not work properly on this platform. ' . 'Use it at your own risk!', - [$this->defaults->getProductName()] + [$this->productName] ), 'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.'), ]; @@ -200,7 +199,7 @@ public function getSystemInfo(bool $allowAllDatabases = false): array { 'error' => $this->l10n->t( 'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' . 'This will lead to problems with files over 4 GB and is highly discouraged.', - [$this->defaults->getProductName()] + [$this->productName] ), 'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.'), ]; diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 4abc3a3f54cad..20c80a45bd9ee 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -56,6 +56,7 @@ use OCP\Share\IShareProviderSupportsAccept; use OCP\Share\IShareProviderSupportsAllSharesInFolder; use OCP\Share\IShareProviderWithNotification; +use OCP\Theming\IDefaults; use Psr\Log\LoggerInterface; /** @@ -79,7 +80,7 @@ public function __construct( private IRootFolder $rootFolder, private IMailer $mailer, private IURLGenerator $urlGenerator, - private \OC_Defaults $defaults, + private IDefaults $defaults, private IEventDispatcher $dispatcher, private IUserSession $userSession, private KnownUserService $knownUserService, diff --git a/lib/private/legacy/OC_Defaults.php b/lib/private/legacy/OC_Defaults.php index 0d460ff966d9c..dc4cc3718a0c5 100644 --- a/lib/private/legacy/OC_Defaults.php +++ b/lib/private/legacy/OC_Defaults.php @@ -84,18 +84,6 @@ public function getBaseUrl() { } } - /** - * Returns the URL where the sync clients are listed - * @return string URL - */ - public function getSyncClientUrl() { - if ($this->themeExist('getSyncClientUrl')) { - return $this->theme->getSyncClientUrl(); - } else { - return $this->defaultSyncClientUrl; - } - } - /** * Returns the URL to the App Store for the iOS Client * @return string URL diff --git a/lib/public/Theming/IDefaults.php b/lib/public/Theming/IDefaults.php new file mode 100644 index 0000000000000..49a8b8ab1aa59 --- /dev/null +++ b/lib/public/Theming/IDefaults.php @@ -0,0 +1,141 @@ +rootFolder = $this->createMock(IRootFolder::class); $this->mailer = $this->createMock(IMailer::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->defaults = $this->createMock(\OC_Defaults::class); + $this->defaults = $this->createMock(IDefaults::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->userSession = $this->createMock(IUserSession::class); $this->knownUserService = $this->createMock(KnownUserService::class); diff --git a/themes/example/defaults.php b/themes/example/defaults.php index 6bf93e62681f8..a7fb6d3e0c5cd 100644 --- a/themes/example/defaults.php +++ b/themes/example/defaults.php @@ -118,14 +118,4 @@ public function getColorPrimary(): string { public function getColorBackground(): string { return '#3d85c6'; } - - /** - * Returns variables to overload defaults from core/css/variables.scss - * @return array - */ - public function getScssVariables(): array { - return [ - 'color-primary' => '#745bca' - ]; - } }