improve code
This commit is contained in:
parent
db7f3bc29c
commit
5cb8888d59
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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(
|
||||||
|
@ -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();
|
||||||
|
@ -459,38 +459,53 @@ 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
|
||||||
{
|
{
|
||||||
if (is_string($img)) {
|
try {
|
||||||
$img = self::GetImage($img);
|
if ( is_string( $img ) ) {
|
||||||
|
$img = self::GetImage( $img );
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (strtolower($type)) {
|
switch ( strtolower( $type ) ) {
|
||||||
case 'png':
|
case 'png':
|
||||||
imagepng($img, $destination);
|
imagepng( $img, $destination );
|
||||||
break;
|
break;
|
||||||
case 'gif':
|
case 'gif':
|
||||||
imagegif($img, $destination);
|
imagegif( $img, $destination );
|
||||||
break;
|
break;
|
||||||
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,16 +543,27 @@ class RoxyImage
|
|||||||
$newWidth = intval($newHeight * $r);
|
$newWidth = intval($newHeight * $r);
|
||||||
}
|
}
|
||||||
|
|
||||||
$thumbImg = imagecreatetruecolor((int) $newWidth, (int) $newHeight);
|
try {
|
||||||
$img = self::GetImage($source);
|
$thumbImg = imagecreatetruecolor( (int) $newWidth, (int) $newHeight );
|
||||||
|
$img = self::GetImage( $source );
|
||||||
|
|
||||||
$thumbImg = self::SetAlpha($thumbImg, $source);
|
$thumbImg = self::SetAlpha( $thumbImg, $source );
|
||||||
|
|
||||||
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,33 +574,51 @@ 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))) {
|
|
||||||
self::OutputImage(self::GetImage($source), RoxyFile::GetExtension(basename($source)), $destination, $quality);
|
try {
|
||||||
|
if ( ( $w <= $width ) &&
|
||||||
|
( $h <= $height)
|
||||||
|
) {
|
||||||
|
self::OutputImage( self::GetImage( $source ), RoxyFile::GetExtension( basename( $source ) ), $destination, $quality );
|
||||||
}
|
}
|
||||||
$ratio = $width / $height;
|
$ratio = $width / $height;
|
||||||
$top = $left = 0;
|
$top = $left = 0;
|
||||||
|
|
||||||
$cropWidth = floor($h * $ratio);
|
$cropWidth = floor( $h * $ratio );
|
||||||
$cropHeight = floor($cropWidth / $ratio);
|
$cropHeight = floor( $cropWidth / $ratio );
|
||||||
if ($cropWidth > $w) {
|
if ( $cropWidth > $w ) {
|
||||||
$cropWidth = $w;
|
$cropWidth = $w;
|
||||||
$cropHeight = $w / $ratio;
|
$cropHeight = $w / $ratio;
|
||||||
}
|
}
|
||||||
if ($cropHeight > $h) {
|
if ( $cropHeight > $h ) {
|
||||||
$cropHeight = $h;
|
$cropHeight = $h;
|
||||||
$cropWidth = $h * $ratio;
|
$cropWidth = $h * $ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cropWidth < $w) {
|
if ( $cropWidth < $w ) {
|
||||||
$left = floor(($w - $cropWidth) / 2);
|
$left = floor( ( $w - $cropWidth ) / 2 );
|
||||||
}
|
}
|
||||||
if ($cropHeight < $h) {
|
if ( $cropHeight < $h ) {
|
||||||
$top = floor(($h - $cropHeight) / 2);
|
$top = floor( ( $h - $cropHeight ) / 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
@ -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.#'
|
|
Loading…
Reference in New Issue
Block a user