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 public function getPhotoPath(string $size = ''): string
{ {
$url = '/photo/media/'; return '/photo/media/' .
switch ($size) { (Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
case Proxy::SIZE_MICRO: $this->id;
$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;
} }
/** /**
@ -197,24 +181,9 @@ class PostMedia extends BaseEntity
*/ */
public function getPreviewPath(string $size = ''): string public function getPreviewPath(string $size = ''): string
{ {
$url = '/photo/preview/'; return '/photo/preview/' .
switch ($size) { (Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
case Proxy::SIZE_MICRO: $this->id;
$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;
} }
} }

View file

@ -1012,25 +1012,9 @@ class Media
*/ */
public static function getPreviewUrlForId(int $id, string $size = ''): string public static function getPreviewUrlForId(int $id, string $size = ''): string
{ {
$url = DI::baseUrl() . '/photo/preview/'; return '/photo/preview/' .
switch ($size) { (Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
case Proxy::SIZE_MICRO: $id;
$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;
} }
/** /**
@ -1042,24 +1026,8 @@ class Media
*/ */
public static function getUrlForId(int $id, string $size = ''): string public static function getUrlForId(int $id, string $size = ''): string
{ {
$url = DI::baseUrl() . '/photo/media/'; return '/photo/media/' .
switch ($size) { (Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') .
case Proxy::SIZE_MICRO: $id;
$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;
} }
} }

View file

@ -211,4 +211,21 @@ class Proxy
return $matches[1] . self::proxifyUrl(htmlspecialchars_decode($matches[2])) . $matches[3]; 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;
}
}
} }