Browse Source

Merge pull request #38611 from fsamapoor/replace_strpos_calls_in_theming_app

Refactors "strpos" calls in /apps/theming
tags/v28.0.0beta1
Côme Chilliet 1 year ago
parent
commit
2e111e862f
No account linked to committer's email address

+ 1
- 1
apps/theming/lib/Command/UpdateConfig.php View File

@@ -112,7 +112,7 @@ class UpdateConfig extends Command {
}

if (in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) {
if (strpos($value, '/') !== 0) {
if (!str_starts_with($value, '/')) {
$output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>');
return 1;
}

+ 2
- 2
apps/theming/lib/Controller/ThemingController.php View File

@@ -182,7 +182,7 @@ class ThemingController extends Controller {
* Check that a string is a valid http/https url
*/
private function isValidUrl(string $url): bool {
return ((strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0) &&
return ((str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) &&
filter_var($url, FILTER_VALIDATE_URL) !== false);
}

@@ -400,7 +400,7 @@ class ThemingController extends Controller {
$info = $this->appManager->getAppInfo($app, false, $this->l10n->getLanguageCode());
$name = $info['name'] . ' - ' . $this->themingDefaults->getName();
$shortName = $info['name'];
if (strpos($this->request->getRequestUri(), '/index.php/') !== false) {
if (str_contains($this->request->getRequestUri(), '/index.php/')) {
$startUrl = $this->urlGenerator->getBaseUrl() . '/index.php/apps/' . $app . '/';
} else {
$startUrl = $this->urlGenerator->getBaseUrl() . '/apps/' . $app . '/';

+ 4
- 4
apps/theming/lib/ImageManager.php View File

@@ -266,7 +266,7 @@ class ImageManager {
$newTmpFile = $this->tempManager->getTemporaryFile();
imageinterlace($outputImage, 1);
// Keep jpeg images encoded as jpeg
if (strpos($detectedMimeType, 'image/jpeg') !== false) {
if (str_contains($detectedMimeType, 'image/jpeg')) {
if (!imagejpeg($outputImage, $newTmpFile, 90)) {
throw new \Exception('Could not recompress background image as JPEG');
}
@@ -300,16 +300,16 @@ class ImageManager {
*/
private function shouldOptimizeBackgroundImage(string $mimeType, int $contentSize): bool {
// Do not touch SVGs
if (strpos($mimeType, 'image/svg') !== false) {
if (str_contains($mimeType, 'image/svg')) {
return false;
}
// GIF does not benefit from converting
if (strpos($mimeType, 'image/gif') !== false) {
if (str_contains($mimeType, 'image/gif')) {
return false;
}
// WebP also does not benefit from converting
// We could possibly try to convert to progressive image, but normally webP images are quite small
if (strpos($mimeType, 'image/webp') !== false) {
if (str_contains($mimeType, 'image/webp')) {
return false;
}
// As a rule of thumb background images should be max. 150-300 KiB, small images do not benefit from converting

+ 1
- 1
apps/theming/lib/ThemingDefaults.php View File

@@ -404,7 +404,7 @@ class ThemingDefaults extends \OC_Defaults {
}
$route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest', ['app' => $app ]);
}
if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) {
if (str_starts_with($image, 'filetypes/') && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) {
$route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]);
}


Loading…
Cancel
Save