зеркало из
https://github.com/nextcloud/server.git
synced 2024-07-21 20:09:54 +02:00
Refactors "strpos" calls in /apps/theming to improve code readability.
Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
Этот коммит содержится в:
родитель
09c5f997c6
Коммит
437631a334
@ -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;
|
||||
}
|
||||
|
@ -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 . '/';
|
||||
|
@ -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
|
||||
|
@ -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]);
|
||||
}
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user