Move size to pixels conversion in its own method in Util\Proxy

This commit is contained in:
Hypolite Petovan 2023-09-29 00:10:28 -04:00
parent 4462ad6bf0
commit 5004471770
3 changed files with 30 additions and 76 deletions

View File

@ -168,25 +168,9 @@ class PostMedia extends BaseEntity
*/
public function getPhotoPath(string $size = ''): string
{
$url = '/photo/media/';
switch ($size) {
case Proxy::SIZE_MICRO:
$url .= Proxy::PIXEL_MICRO . '/';
break;
case Proxy::SIZE_THUMB:
$url .= Proxy::PIXEL_THUMB . '/';
break;
case Proxy::SIZE_SMALL:
$url .= Proxy::PIXEL_SMALL . '/';
break;
case Proxy::SIZE_MEDIUM:
$url .= Proxy::PIXEL_MEDIUM . '/';
break;
case Proxy::SIZE_LARGE:
$url .= Proxy::PIXEL_LARGE . '/';
break;
}
return $url . $this->id;
return '/photo/media/' .
(Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
$this->id;
}
/**
@ -197,24 +181,9 @@ class PostMedia extends BaseEntity
*/
public function getPreviewPath(string $size = ''): string
{
$url = '/photo/preview/';
switch ($size) {
case Proxy::SIZE_MICRO:
$url .= Proxy::PIXEL_MICRO . '/';
break;
case Proxy::SIZE_THUMB:
$url .= Proxy::PIXEL_THUMB . '/';
break;
case Proxy::SIZE_SMALL:
$url .= Proxy::PIXEL_SMALL . '/';
break;
case Proxy::SIZE_MEDIUM:
$url .= Proxy::PIXEL_MEDIUM . '/';
break;
case Proxy::SIZE_LARGE:
$url .= Proxy::PIXEL_LARGE . '/';
break;
}
return $url . $this->id;
return '/photo/preview/' .
(Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
$this->id;
}
}

View File

@ -1012,25 +1012,9 @@ class Media
*/
public static function getPreviewUrlForId(int $id, string $size = ''): string
{
$url = DI::baseUrl() . '/photo/preview/';
switch ($size) {
case Proxy::SIZE_MICRO:
$url .= Proxy::PIXEL_MICRO . '/';
break;
case Proxy::SIZE_THUMB:
$url .= Proxy::PIXEL_THUMB . '/';
break;
case Proxy::SIZE_SMALL:
$url .= Proxy::PIXEL_SMALL . '/';
break;
case Proxy::SIZE_MEDIUM:
$url .= Proxy::PIXEL_MEDIUM . '/';
break;
case Proxy::SIZE_LARGE:
$url .= Proxy::PIXEL_LARGE . '/';
break;
}
return $url . $id;
return '/photo/preview/' .
(Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
$id;
}
/**
@ -1042,24 +1026,8 @@ class Media
*/
public static function getUrlForId(int $id, string $size = ''): string
{
$url = DI::baseUrl() . '/photo/media/';
switch ($size) {
case Proxy::SIZE_MICRO:
$url .= Proxy::PIXEL_MICRO . '/';
break;
case Proxy::SIZE_THUMB:
$url .= Proxy::PIXEL_THUMB . '/';
break;
case Proxy::SIZE_SMALL:
$url .= Proxy::PIXEL_SMALL . '/';
break;
case Proxy::SIZE_MEDIUM:
$url .= Proxy::PIXEL_MEDIUM . '/';
break;
case Proxy::SIZE_LARGE:
$url .= Proxy::PIXEL_LARGE . '/';
break;
}
return $url . $id;
return '/photo/media/' .
(Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
$id;
}
}

View File

@ -211,4 +211,21 @@ class Proxy
return $matches[1] . self::proxifyUrl(htmlspecialchars_decode($matches[2])) . $matches[3];
}
public static function getPixelsFromSize(string $size): int
{
switch ($size) {
case Proxy::SIZE_MICRO:
return Proxy::PIXEL_MICRO;
case Proxy::SIZE_THUMB:
return Proxy::PIXEL_THUMB;
case Proxy::SIZE_SMALL:
return Proxy::PIXEL_SMALL;
case Proxy::SIZE_MEDIUM:
return Proxy::PIXEL_MEDIUM;
case Proxy::SIZE_LARGE:
return Proxy::PIXEL_LARGE;
default:
return 0;
}
}
}