Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4037,27 +4037,6 @@
<code><![CDATA[$tag]]></code>
</MoreSpecificImplementedParamType>
</file>
<file src="lib/private/Template/CSSResourceLocator.php">
<ParamNameMismatch>
<code><![CDATA[$style]]></code>
<code><![CDATA[$style]]></code>
</ParamNameMismatch>
</file>
<file src="lib/private/Template/JSConfigHelper.php">
<NullArgument>
<code><![CDATA[null]]></code>
<code><![CDATA[null]]></code>
</NullArgument>
</file>
<file src="lib/private/Template/JSResourceLocator.php">
<InvalidArgument>
<code><![CDATA[false]]></code>
</InvalidArgument>
<ParamNameMismatch>
<code><![CDATA[$script]]></code>
<code><![CDATA[$script]]></code>
</ParamNameMismatch>
</file>
<file src="lib/private/URLGenerator.php">
<InvalidReturnStatement>
<code><![CDATA[$path]]></code>
Expand Down
1 change: 1 addition & 0 deletions build/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
$nextcloudDir . '/status.php',
$nextcloudDir . '/version.php',
$nextcloudDir . '/lib/private/Share20/ProviderFactory.php',
$nextcloudDir . '/lib/private/Template',
$nextcloudDir . '/tests',
// $nextcloudDir . '/config',
// $nextcloudDir . '/lib',
Expand Down
2 changes: 1 addition & 1 deletion lib/private/L10N/L10N.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function n(string $text_singular, string $text_plural, int $count, array
/**
* Localization
* @param string $type Type of localization
* @param \DateTime|int|string $data parameters for this localization
* @param \DateTime|int|string|null $data parameters for this localization
* @param array $options
* @return string|int|false
*
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getAppDataDir('js'),
$c->get(IURLGenerator::class),
$this->get(ICacheFactory::class),
$c->get(SystemConfig::class),
$c->get(\OCP\IConfig::class),
$c->get(LoggerInterface::class)
);
});
Expand Down
29 changes: 11 additions & 18 deletions lib/private/Template/Base.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OC\Template;

use OCP\Defaults;
use OCP\IL10N;

class Base {
private $template; // The template
private array $vars = [];

/** @var \OCP\IL10N */
private $l10n;

/** @var Defaults */
private $theme;

/**
* @param string $template
* @param string $requestToken
* @param \OCP\IL10N $l10n
* @param string $cspNonce
* @param Defaults $theme
*/
public function __construct($template, $requestToken, $l10n, $theme, $cspNonce) {
public function __construct(
private string $template,
string $requestToken,
private IL10N $l10n,
private Defaults $theme,
string $cspNonce,
) {
$this->vars = [
'cspNonce' => $cspNonce,
'requesttoken' => $requestToken,
];
$this->l10n = $l10n;
$this->template = $template;
$this->theme = $theme;
}

/**
Expand Down
60 changes: 34 additions & 26 deletions lib/private/Template/CSSResourceLocator.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016-2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OC\Template;

use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\IConfig;
use Psr\Log\LoggerInterface;

class CSSResourceLocator extends ResourceLocator {
public function __construct(LoggerInterface $logger) {
parent::__construct($logger);
public function __construct(
LoggerInterface $logger,
IConfig $config,
protected IAppManager $appManager,
) {
parent::__construct($logger, $config);
}

/**
* @param string $style
*/
public function doFind($style) {
$app = substr($style, 0, strpos($style, '/'));
if ($this->appendIfExist($this->serverroot, $style . '.css')
|| $this->appendIfExist($this->serverroot, 'core/' . $style . '.css')
public function doFind(string $resource): void {
$parts = explode('/', $resource, 2);
if (count($parts) < 2) {
return;
}
[$app,$subpath] = $parts;
if ($this->appendIfExist($this->serverroot, $resource . '.css')
|| $this->appendIfExist($this->serverroot, 'core/' . $resource . '.css')
) {
return;
}
$style = substr($style, strpos($style, '/') + 1);
$app_path = \OC_App::getAppPath($app);
$app_url = \OC_App::getAppWebPath($app);

if ($app_path === false && $app_url === false) {
try {
$app_path = $this->appManager->getAppPath($app);
$app_url = $this->appManager->getAppWebPath($app);
} catch (AppPathNotFoundException $e) {
$this->logger->error('Could not find resource {resource} to load', [
'resource' => $app . '/' . $style . '.css',
'resource' => $app . '/' . $subpath . '.css',
'app' => 'cssresourceloader',
'exception' => $e,
]);
return;
}
Expand All @@ -41,24 +52,21 @@ public function doFind($style) {
// turned into cwd.
$app_path = realpath($app_path);

$this->append($app_path, $style . '.css', $app_url);
$this->append($app_path, $subpath . '.css', $app_url);
}

/**
* @param string $style
*/
public function doFindTheme($style) {
public function doFindTheme(string $resource): void {
$theme_dir = 'themes/' . $this->theme . '/';
$this->appendIfExist($this->serverroot, $theme_dir . 'apps/' . $style . '.css')
|| $this->appendIfExist($this->serverroot, $theme_dir . $style . '.css')
|| $this->appendIfExist($this->serverroot, $theme_dir . 'core/' . $style . '.css');
$this->appendIfExist($this->serverroot, $theme_dir . 'apps/' . $resource . '.css')
|| $this->appendIfExist($this->serverroot, $theme_dir . $resource . '.css')
|| $this->appendIfExist($this->serverroot, $theme_dir . 'core/' . $resource . '.css');
}

public function append($root, $file, $webRoot = null, $throw = true, $scss = false) {
public function append(string $root, string $file, ?string $webRoot = null, bool $throw = true, bool $scss = false): void {
if (!$scss) {
parent::append($root, $file, $webRoot, $throw);
} else {
if (!$webRoot) {
if ($webRoot === null || $webRoot === '') {
$webRoot = $this->findWebRoot($root);

if ($webRoot === null) {
Expand Down
80 changes: 20 additions & 60 deletions lib/private/Template/JSCombiner.php
Original file line number Diff line number Diff line change
@@ -1,60 +1,39 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\Template;

use OC\SystemConfig;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IURLGenerator;
use Psr\Log\LoggerInterface;

class JSCombiner {
/** @var IAppData */
protected $appData;

/** @var IURLGenerator */
protected $urlGenerator;

/** @var ICache */
protected $depsCache;

/** @var SystemConfig */
protected $config;

protected LoggerInterface $logger;

/** @var ICacheFactory */
private $cacheFactory;

public function __construct(IAppData $appData,
IURLGenerator $urlGenerator,
ICacheFactory $cacheFactory,
SystemConfig $config,
LoggerInterface $logger) {
$this->appData = $appData;
$this->urlGenerator = $urlGenerator;
$this->cacheFactory = $cacheFactory;
protected ICache $depsCache;

public function __construct(
protected IAppData $appData,
protected IURLGenerator $urlGenerator,
protected ICacheFactory $cacheFactory,
protected IConfig $config,
protected LoggerInterface $logger,
) {
$this->depsCache = $this->cacheFactory->createDistributed('JS-' . md5($this->urlGenerator->getBaseUrl()));
$this->config = $config;
$this->logger = $logger;
}

/**
* @param string $root
* @param string $file
* @param string $app
* @return bool
*/
public function process($root, $file, $app) {
if ($this->config->getValue('debug') || !$this->config->getValue('installed')) {
public function process(string $root, string $file, string $app): bool {
if ($this->config->getSystemValueBool('debug') || !$this->config->getSystemValueBool('installed')) {
return false;
}

Expand All @@ -76,12 +55,7 @@ public function process($root, $file, $app) {
return $this->cache($path, $fileName, $folder);
}

/**
* @param string $fileName
* @param ISimpleFolder $folder
* @return bool
*/
protected function isCached($fileName, ISimpleFolder $folder) {
protected function isCached(string $fileName, ISimpleFolder $folder): bool {
$fileName = str_replace('.json', '.js', $fileName);

if (!$folder->fileExists($fileName)) {
Expand Down Expand Up @@ -126,13 +100,7 @@ protected function isCached($fileName, ISimpleFolder $folder) {
}
}

/**
* @param string $path
* @param string $fileName
* @param ISimpleFolder $folder
* @return bool
*/
protected function cache($path, $fileName, ISimpleFolder $folder) {
protected function cache(string $path, string $fileName, ISimpleFolder $folder): bool {
$deps = [];
$fullPath = $path . '/' . $fileName;
$data = json_decode(file_get_contents($fullPath));
Expand Down Expand Up @@ -183,12 +151,7 @@ protected function cache($path, $fileName, ISimpleFolder $folder) {
}
}

/**
* @param string $appName
* @param string $fileName
* @return string
*/
public function getCachedJS($appName, $fileName) {
public function getCachedJS(string $appName, string $fileName): string {
$tmpfileLoc = explode('/', $fileName);
$fileName = array_pop($tmpfileLoc);
$fileName = str_replace('.json', '.js', $fileName);
Expand All @@ -197,12 +160,9 @@ public function getCachedJS($appName, $fileName) {
}

/**
* @param string $root
* @param string $file
* @return string[]
*/
public function getContent($root, $file) {
/** @var array $data */
public function getContent(string $root, string $file): array {
$data = json_decode(file_get_contents($root . '/' . $file));
if (!is_array($data)) {
return [];
Expand All @@ -226,7 +186,7 @@ public function getContent($root, $file) {
*
* @throws NotFoundException
*/
public function resetCache() {
public function resetCache(): void {
$this->cacheFactory->createDistributed('JS-')->clear();
$appDirectory = $this->appData->getDirectoryListing();
foreach ($appDirectory as $folder) {
Expand Down
8 changes: 6 additions & 2 deletions lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ public function getConfig(): string {

$capabilities = $this->capabilitiesManager->getCapabilities(false, true);

$userFirstDay = $this->config->getUserValue($uid, 'core', AUserDataOCSController::USER_FIELD_FIRST_DAY_OF_WEEK, null);
$firstDay = (int)($userFirstDay ?? $this->l->l('firstday', null));
$firstDay = $this->config->getUserValue($uid, 'core', AUserDataOCSController::USER_FIELD_FIRST_DAY_OF_WEEK, '');
if ($firstDay === '') {
$firstDay = (int)$this->l->l('firstday', null);
} else {
$firstDay = (int)$firstDay;
}

$config = [
/** @deprecated 30.0.0 - use files capabilities instead */
Expand Down
Loading
Loading