From 05b42c3327a14351692330bdc299dd011cd03dc4 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Sun, 8 Nov 2020 17:07:31 +0100 Subject: Make imagetype file extension array a const of Image Yet another pointless global var gone :) --- ratatoeskr/sys/models.php | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'ratatoeskr/sys') diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php index 01ffeb3..74d4419 100644 --- a/ratatoeskr/sys/models.php +++ b/ratatoeskr/sys/models.php @@ -20,19 +20,6 @@ require_once(dirname(__FILE__) . "/utils.php"); require_once(dirname(__FILE__) . "/textprocessors.php"); require_once(dirname(__FILE__) . "/pluginpackage.php"); -/* - * Array: $imagetype_file_extensions - * Array of default file extensions for most IMAGETYPE_* constants - */ -$imagetype_file_extensions = [ - IMAGETYPE_GIF => "gif", - IMAGETYPE_JPEG => "jpg", - IMAGETYPE_PNG => "png", - IMAGETYPE_BMP => "bmp", - IMAGETYPE_TIFF_II => "tif", - IMAGETYPE_TIFF_MM => "tif", -]; - /* * Variable: $ratatoeskr_settings * The global object. Can be accessed like an array. @@ -2157,6 +2144,18 @@ class Image extends BySQLRowEnabled private const PRE_MAXW = 150; private const PRE_MAXH = 100; + /** + * Array of default file extensions for most IMAGETYPE_* constants + */ + private const IMAGETYPE_FILE_EXTENSIONS = [ + IMAGETYPE_GIF => "gif", + IMAGETYPE_JPEG => "jpg", + IMAGETYPE_PNG => "png", + IMAGETYPE_BMP => "bmp", + IMAGETYPE_TIFF_II => "tif", + IMAGETYPE_TIFF_MM => "tif", + ]; + /** @var int */ private $id; @@ -2267,8 +2266,6 @@ class Image extends BySQLRowEnabled */ public function exchange_image($file, ?Database $db = null): void { - global $imagetype_file_extensions; - $file = (string)$file; if (!is_file($file)) { @@ -2278,13 +2275,13 @@ class Image extends BySQLRowEnabled if ($imageinfo === false) { throw new UnknownFileFormat(); } - if (!isset($imagetype_file_extensions[$imageinfo[2]])) { + if (!isset(self::IMAGETYPE_FILE_EXTENSIONS[$imageinfo[2]])) { throw new UnknownFileFormat(); } if (is_file(SITE_BASE_PATH . "/images/" . $this->filename)) { unlink(SITE_BASE_PATH . "/images/" . $this->filename); } - $new_fn = $this->id . "." . $imagetype_file_extensions[$imageinfo[2]]; + $new_fn = $this->id . "." . self::IMAGETYPE_FILE_EXTENSIONS[$imageinfo[2]]; if (!move_uploaded_file($file, SITE_BASE_PATH . "/images/" . $new_fn)) { throw new IOError("Can not move file."); } -- cgit v1.2.3-70-g09d2