Refactors "strpos" calls in /apps/themingtags/v28.0.0beta1
} | } | ||||
if (in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) { | 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>'); | $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); | ||||
return 1; | return 1; | ||||
} | } |
* Check that a string is a valid http/https url | * Check that a string is a valid http/https url | ||||
*/ | */ | ||||
private function isValidUrl(string $url): bool { | 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); | filter_var($url, FILTER_VALIDATE_URL) !== false); | ||||
} | } | ||||
$info = $this->appManager->getAppInfo($app, false, $this->l10n->getLanguageCode()); | $info = $this->appManager->getAppInfo($app, false, $this->l10n->getLanguageCode()); | ||||
$name = $info['name'] . ' - ' . $this->themingDefaults->getName(); | $name = $info['name'] . ' - ' . $this->themingDefaults->getName(); | ||||
$shortName = $info['name']; | $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 . '/'; | $startUrl = $this->urlGenerator->getBaseUrl() . '/index.php/apps/' . $app . '/'; | ||||
} else { | } else { | ||||
$startUrl = $this->urlGenerator->getBaseUrl() . '/apps/' . $app . '/'; | $startUrl = $this->urlGenerator->getBaseUrl() . '/apps/' . $app . '/'; |
$newTmpFile = $this->tempManager->getTemporaryFile(); | $newTmpFile = $this->tempManager->getTemporaryFile(); | ||||
imageinterlace($outputImage, 1); | imageinterlace($outputImage, 1); | ||||
// Keep jpeg images encoded as jpeg | // Keep jpeg images encoded as jpeg | ||||
if (strpos($detectedMimeType, 'image/jpeg') !== false) { | |||||
if (str_contains($detectedMimeType, 'image/jpeg')) { | |||||
if (!imagejpeg($outputImage, $newTmpFile, 90)) { | if (!imagejpeg($outputImage, $newTmpFile, 90)) { | ||||
throw new \Exception('Could not recompress background image as JPEG'); | throw new \Exception('Could not recompress background image as JPEG'); | ||||
} | } | ||||
*/ | */ | ||||
private function shouldOptimizeBackgroundImage(string $mimeType, int $contentSize): bool { | private function shouldOptimizeBackgroundImage(string $mimeType, int $contentSize): bool { | ||||
// Do not touch SVGs | // Do not touch SVGs | ||||
if (strpos($mimeType, 'image/svg') !== false) { | |||||
if (str_contains($mimeType, 'image/svg')) { | |||||
return false; | return false; | ||||
} | } | ||||
// GIF does not benefit from converting | // GIF does not benefit from converting | ||||
if (strpos($mimeType, 'image/gif') !== false) { | |||||
if (str_contains($mimeType, 'image/gif')) { | |||||
return false; | return false; | ||||
} | } | ||||
// WebP also does not benefit from converting | // WebP also does not benefit from converting | ||||
// We could possibly try to convert to progressive image, but normally webP images are quite small | // 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; | return false; | ||||
} | } | ||||
// As a rule of thumb background images should be max. 150-300 KiB, small images do not benefit from converting | // As a rule of thumb background images should be max. 150-300 KiB, small images do not benefit from converting |
} | } | ||||
$route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest', ['app' => $app ]); | $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]); | $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); | ||||
} | } | ||||