]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Images.php
Friendica copyright changed from 2023 to 2034
[friendica.git] / src / Util / Images.php
index 7f6d8720ff0bb5f89942670da2546abbfd131671..b44b1fb8f558fe0a4dbc76078dc531e4dc8a8155 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2023, the Friendica project
+ * @copyright Copyright (C) 2010-2024, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -249,17 +249,19 @@ class Images
                        return [];
                }
 
-               if ($data) {
-                       $image = new Image($img_str);
+               if (!$data) {
+                       return [];
+               }
 
-                       if ($image->isValid()) {
-                               $data['blurhash'] = $image->getBlurHash();
-                       }
+               $image = new Image($img_str);
 
-                       $data['size'] = $filesize;
+               if ($image->isValid()) {
+                       $data['blurhash'] = $image->getBlurHash();
                }
 
-               return is_array($data) ? $data : [];
+               $data['size'] = $filesize;
+
+               return $data;
        }
 
        /**
@@ -327,7 +329,7 @@ class Images
         * @param string $description
         * @return string
         */
-       public static function getBBCodeByResource(string $resource_id, string $nickname, int $preview, string $ext, string $description = null): string
+       public static function getBBCodeByResource(string $resource_id, string $nickname, int $preview, string $ext, string $description = ''): string
        {
                return self::getBBCodeByUrl(
                        DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id,
@@ -344,20 +346,23 @@ class Images
         * @param string $description
         * @return string
         */
-       public static function getBBCodeByUrl(string $photo, string $preview = null, string $description = null): string
+       public static function getBBCodeByUrl(string $photo, string $preview = null, string $description = ''): string
        {
                if (!empty($preview)) {
-                       if (!is_null($description)) {
-                               return '[url=' . $photo . '][img=' . $preview . ']' . $description . '[/img][/url]';
-                       } else {
-                               return '[url=' . $photo . '][img]' . $preview . '[/img][/url]';
-                       }
+                       return '[url=' . $photo . '][img=' . $preview . ']' . $description . '[/img][/url]';
                }
 
-               if (!is_null($description)) {
-                       return '[img=' . $photo . ']' . $description . '[/img]';
-               } else {
-                       return '[img]' . $photo . '[/img]';
-               }
+               return '[img=' . $photo . ']' . $description . '[/img]';
+       }
+
+       /**
+        * Get the maximum possible upload size in bytes
+        *
+        * @return integer
+        */
+       public static function getMaxUploadBytes(): int
+       {
+               $upload_size = ini_get('upload_max_filesize') ?: DI::config()->get('system', 'maximagesize');
+               return Strings::getBytesFromShorthand($upload_size);
        }
 }