]> git.mxchange.org Git - friendica.git/commitdiff
Move size to pixels conversion in its own method in Util\Proxy
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 29 Sep 2023 04:10:28 +0000 (00:10 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 3 Oct 2023 23:58:51 +0000 (19:58 -0400)
src/Content/Post/Entity/PostMedia.php
src/Model/Post/Media.php
src/Util/Proxy.php

index ca064d4c7e84d42ead4fcc6b1718c2b3a86f7213..deb4ec1b36dc094019cd571c7beb9f8e6263ec56 100644 (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;
+
        }
 }
index 2d7df08096b22d498159e0deeb5cfba3dc0245ea..64f44c198d6bc2f20640c65bd1e6e82c2f9b328a 100644 (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;
        }
 }
index aa0f66bbffbc274fae80eef7e9ebb6564c14e54f..423e676ae60733338451a29008c091cfa2a4066e 100644 (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;
+               }
+       }
 }