improve code

This commit is contained in:
Daniel Seifert 2024-12-04 14:25:51 +01:00
parent db7f3bc29c
commit 5cb8888d59
5 changed files with 105 additions and 59 deletions

View File

@ -121,7 +121,7 @@ class Loader
} }
/** /**
* @return array * @return string[]
*/ */
public function getScripts(): array public function getScripts(): array
{ {
@ -129,8 +129,8 @@ class Loader
return []; return [];
} }
$sCopyLongDescFromTinyMCE = file_get_contents(__DIR__.'/../../../assets/out/scripts/copyLongDesc.js'); $sCopyLongDescFromTinyMCE = file_get_contents(__DIR__.'/../../../assets/out/scripts/copyLongDesc.js') ?: '';
$sUrlConverter = file_get_contents(__DIR__.'/../../../assets/out/scripts/urlConverter.js'); $sUrlConverter = file_get_contents(__DIR__.'/../../../assets/out/scripts/urlConverter.js') ?: '';
$sInit = str_replace( $sInit = str_replace(
"'CONFIG':'VALUES'", "'CONFIG':'VALUES'",
$this->configuration->getConfig(), $this->configuration->getConfig(),
@ -145,7 +145,7 @@ class Loader
} }
/** /**
* @return array * @return string[]
*/ */
public function getIncludes(): array public function getIncludes(): array
{ {

View File

@ -41,8 +41,9 @@ class FilemanagerUrl extends AbstractOption
public function get(): string public function get(): string
{ {
/** @var string $sFilemanagerKey */ $sFilemanagerKey = md5_file(
$sFilemanagerKey = md5_file(rtrim(Registry::getConfig()->getConfigParam("sShopDir"), '/')."/config.inc.php"); rtrim(Registry::getConfig()->getConfigParam("sShopDir"), '/')."/config.inc.php"
) ?: '';
Registry::get(UtilsServer::class)->setOxCookie("filemanagerkey", $sFilemanagerKey); Registry::get(UtilsServer::class)->setOxCookie("filemanagerkey", $sFilemanagerKey);
return str_replace( return str_replace(

View File

@ -40,6 +40,9 @@ class ViewConfig extends ViewConfig_parent
return $loader->getEditorCode(); return $loader->getEditorCode();
} }
/**
* @return string[]
*/
public function getTinyMceScripts(): array public function getTinyMceScripts(): array
{ {
$config = Registry::getConfig(); $config = Registry::getConfig();
@ -49,6 +52,9 @@ class ViewConfig extends ViewConfig_parent
return $loader->getScripts(); return $loader->getScripts();
} }
/**
* @return string[]
*/
public function getTinyMceIncludes(): array public function getTinyMceIncludes(): array
{ {
$config = Registry::getConfig(); $config = Registry::getConfig();

View File

@ -459,21 +459,35 @@ class RoxyFile
} }
class RoxyImage class RoxyImage
{ {
public static function GetImage(string $path) public static function GetImage(string $path): GdImage
{ {
$ext = RoxyFile::GetExtension(basename($path)); $ext = RoxyFile::GetExtension(basename($path));
switch ($ext) { switch ($ext) {
case 'png': case 'png':
return imagecreatefrompng($path); $img = imagecreatefrompng($path);
break;
case 'gif': case 'gif':
return imagecreatefromgif($path); $img = imagecreatefromgif($path);
break;
default: default:
return imagecreatefromjpeg($path); $img = imagecreatefromjpeg($path);
}
} }
public static function OutputImage($img, string $type, ?string $destination = '', int $quality = 90) if (!$img) {
throw new RuntimeException('Cannot open image');
}
return $img;
}
public static function OutputImage(
GdImage|string $img,
string $type,
?string $destination = '',
int $quality = 90
): void
{ {
try {
if ( is_string( $img ) ) { if ( is_string( $img ) ) {
$img = self::GetImage( $img ); $img = self::GetImage( $img );
} }
@ -488,9 +502,10 @@ class RoxyImage
default: default:
imagejpeg( $img, $destination, $quality ); imagejpeg( $img, $destination, $quality );
} }
} catch ( RuntimeException $e ) {}
} }
public static function SetAlpha($img, string $path) public static function SetAlpha(GdImage $img, string $path): GdImage
{ {
$ext = RoxyFile::GetExtension(basename($path)); $ext = RoxyFile::GetExtension(basename($path));
if ($ext == "gif" || $ext == "png") { if ($ext == "gif" || $ext == "png") {
@ -528,6 +543,7 @@ class RoxyImage
$newWidth = intval($newHeight * $r); $newWidth = intval($newHeight * $r);
} }
try {
$thumbImg = imagecreatetruecolor( (int) $newWidth, (int) $newHeight ); $thumbImg = imagecreatetruecolor( (int) $newWidth, (int) $newHeight );
$img = self::GetImage( $source ); $img = self::GetImage( $source );
@ -536,8 +552,18 @@ class RoxyImage
imagecopyresampled( $thumbImg, $img, 0, 0, 0, 0, (int) $newWidth, (int) $newHeight, $w, $h ); imagecopyresampled( $thumbImg, $img, 0, 0, 0, 0, (int) $newWidth, (int) $newHeight, $w, $h );
self::OutputImage( $thumbImg, RoxyFile::GetExtension( basename( $source ) ), $destination, $quality ); self::OutputImage( $thumbImg, RoxyFile::GetExtension( basename( $source ) ), $destination, $quality );
} catch ( RuntimeException $e ) {}
} }
/**
* @param string $source
* @param string|null $destination
* @param int<1, max> $width
* @param int<1, max> $height
* @param int $quality
*
* @return void
*/
public static function CropCenter( public static function CropCenter(
string $source, string $source,
?string $destination, ?string $destination,
@ -548,7 +574,11 @@ class RoxyImage
$tmp = (array) getimagesize($source); $tmp = (array) getimagesize($source);
$w = $tmp[0]; $w = $tmp[0];
$h = $tmp[1]; $h = $tmp[1];
if (($w <= $width) && (!$height || ($h <= $height))) {
try {
if ( ( $w <= $width ) &&
( $h <= $height)
) {
self::OutputImage( self::GetImage( $source ), RoxyFile::GetExtension( basename( $source ) ), $destination, $quality ); self::OutputImage( self::GetImage( $source ), RoxyFile::GetExtension( basename( $source ) ), $destination, $quality );
} }
$ratio = $width / $height; $ratio = $width / $height;
@ -573,8 +603,22 @@ class RoxyImage
} }
self::Crop( $source, $destination, (int) $left, (int) $top, $cropWidth, $cropHeight, $width, $height, $quality ); self::Crop( $source, $destination, (int) $left, (int) $top, $cropWidth, $cropHeight, $width, $height, $quality );
} catch (RuntimeException $e) {}
} }
/**
* @param string $source
* @param string|null $destination
* @param int $x
* @param int $y
* @param int $cropWidth
* @param int $cropHeight
* @param int<1, max> $width
* @param int<1, max> $height
* @param int $quality
*
* @return void
*/
public static function Crop( public static function Crop(
string $source, string $source,
?string $destination, ?string $destination,

View File

@ -7,7 +7,7 @@ parameters:
paths: paths:
- Application - Application
- assets/out/fileman - assets/out/fileman
level: 9 level: 6
phpVersion: 80000 phpVersion: 80000
ignoreErrors: ignoreErrors:
- '#Constant FILES_ROOT not found.#' - '#Constant FILES_ROOT not found.#'
@ -19,8 +19,3 @@ parameters:
- '#Constant FILEPERMISSIONS not found.#' - '#Constant FILEPERMISSIONS not found.#'
- '#Constant MAX_IMAGE_HEIGHT not found.#' - '#Constant MAX_IMAGE_HEIGHT not found.#'
- '#Constant MAX_IMAGE_WIDTH not found.#' - '#Constant MAX_IMAGE_WIDTH not found.#'
- '#Method RoxyImage\:\:OutputImage\(\) has no return type specified.#'
- '#Method RoxyImage\:\:OutputImage\(\) has parameter \$img with no type specified.#'
- '#Method RoxyImage\:\:SetAlpha\(\) has no return type specified.#'
- '#Method RoxyImage\:\:SetAlpha\(\) has parameter \$img with no type specified.#'
- '#Method RoxyImage\:\:GetImage\(\) has no return type specified.#'