From 021283fe7e73c97a2f3b03cecb002d8eda3ed9d4 Mon Sep 17 00:00:00 2001 From: Marvin Flock Date: Tue, 22 Apr 2025 17:39:15 +0200 Subject: [PATCH] fix: folder and file handling by using native php methods --- .../components/com_sportsmanager/admin.php | 42 +++++++++---------- .../com_sportsmanager/database/update.php | 4 +- .../com_sportsmanager/util/image.php | 4 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/structure/components/com_sportsmanager/admin.php b/src/structure/components/com_sportsmanager/admin.php index 2ca2ac5..a32a72d 100644 --- a/src/structure/components/com_sportsmanager/admin.php +++ b/src/structure/components/com_sportsmanager/admin.php @@ -2034,12 +2034,12 @@ function adminSpielerZusammenlegenForm(): void $bilder_pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'spieler'; $neues_bild_pfad = $bilder_pfad . DIRECTORY_SEPARATOR . $spieler_beizubehalten_id . '.'; - if (!File::exists($neues_bild_pfad . 'png') && !File::exists($neues_bild_pfad . 'jpg')) { + if (!(file_exists($neues_bild_pfad . 'png') && is_file($neues_bild_pfad . 'png')) && !(file_exists($neues_bild_pfad . 'jpg') && is_file($neues_bild_pfad . 'jpg'))) { $altes_bild_pfad = $bilder_pfad . DIRECTORY_SEPARATOR . $spieler_zu_entfernen_id . '.'; - if (File::exists($altes_bild_pfad . 'png')) + if (file_exists($altes_bild_pfad . 'png') && is_file($altes_bild_pfad . 'png')) File::copy($altes_bild_pfad . 'png', $neues_bild_pfad . 'png'); - else if (File::exists($altes_bild_pfad . 'jpg')) + else if (file_exists($altes_bild_pfad . 'jpg') && is_file($altes_bild_pfad . 'jpg')) File::copy($altes_bild_pfad . 'jpg', $neues_bild_pfad . 'jpg'); } @@ -7821,10 +7821,10 @@ function mannschaftsgruppe_verknuepfen($quelle_team_id, $ziel_team_id, $mannscha foreach ($quelle_mitglieder as $quelle_mitglied) { foreach ($ziel_mitglieder as $ziel_mitglied) { $pfad = $bilder_pfad . DIRECTORY_SEPARATOR . $quelle_mitglied->mitglied_von_team_id . '.'; - if (File::exists($pfad . 'png')) { + if (file_exists($pfad . 'png') && is_file($pfad . 'png')) { File::copy($pfad . 'png', $bilder_pfad . DIRECTORY_SEPARATOR . $ziel_mitglied->mitglied_von_team_id . '.png'); $bild_kopiert = true; - } else if (File::exists($pfad . 'jpg')) { + } else if (file_exists($pfad . 'jpg') && is_file($pfad . 'jpg')) { File::copy($pfad . 'jpg', $bilder_pfad . DIRECTORY_SEPARATOR . $ziel_mitglied->mitglied_von_team_id . '.jpg'); $bild_kopiert = true; } @@ -7841,9 +7841,9 @@ function mannschaftsgruppe_verknuepfen($quelle_team_id, $ziel_team_id, $mannscha $bilder_pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'mannschaften'; $quelle_pfad = $bilder_pfad . DIRECTORY_SEPARATOR . $quelle_team_id . '.'; $ziel_pfad = $bilder_pfad . DIRECTORY_SEPARATOR . $ziel_team_id . '.'; - if (File::exists($quelle_pfad . 'png')) + if (file_exists($quelle_pfad . 'png') && is_file($quelle_pfad . 'png')) $ext = "png"; - else if (File::exists($quelle_pfad . 'jpg')) + else if (file_exists($quelle_pfad . 'jpg') && is_file($quelle_pfad . 'jpg')) $ext = "jpg"; else $ext = ""; @@ -8222,9 +8222,9 @@ function adminKopierenMannschaftForm(): void $ziel_mitglied_von_team_id = $db->insertid(); $pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'mannschaftsmitglieder' . DIRECTORY_SEPARATOR . $row->mitglied_von_team_id . '.'; - if (File::exists($pfad . 'png')) + if (file_exists($pfad . 'png') && is_file($pfad . 'png')) File::copy($pfad . 'png', $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'mannschaftsmitglieder' . DIRECTORY_SEPARATOR . $ziel_mitglied_von_team_id . '.png'); - else if (File::exists($pfad . 'jpg')) + else if (file_exists($pfad . 'jpg') && is_file($pfad . 'jpg')) File::copy($pfad . 'jpg', $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'mannschaftsmitglieder' . DIRECTORY_SEPARATOR . $ziel_mitglied_von_team_id . '.jpg'); } } @@ -8264,9 +8264,9 @@ function adminKopierenMannschaftForm(): void } $pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'mannschaften' . DIRECTORY_SEPARATOR . $id . '.'; - if (File::exists($pfad . 'png')) + if (file_exists($pfad . 'png') && is_file($pfad . 'png')) File::copy($pfad . "png", $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'mannschaften' . DIRECTORY_SEPARATOR . $ziel_teamid . '.png'); - else if (File::exists($pfad . 'jpg')) + else if (file_exists($pfad . 'jpg') && is_file($pfad . 'jpg')) File::copy($pfad . "jpg", $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'mannschaften' . DIRECTORY_SEPARATOR . $ziel_teamid . '.jpg'); } } @@ -14342,7 +14342,7 @@ function adminSpielerExportBilderForm(): void } $ziel_bilder_pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'export'; - if (!Folder::exists($ziel_bilder_pfad) && !Folder::create($ziel_bilder_pfad, 0777)) { + if (!is_dir($ziel_bilder_pfad) && !Folder::create($ziel_bilder_pfad, 0777)) { redirectSportsManagerURL('&task=admin_spieler', "Der Ordner 'images/sportsmanager/export' konnte nicht neu erstellt werden."); } @@ -14368,9 +14368,9 @@ function adminSpielerExportBilderForm(): void foreach ($spieler as $s) { $pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'spieler' . DIRECTORY_SEPARATOR . $s->spieler_id . '.'; - if (File::exists($pfad . 'png')) + if (file_exists($pfad . 'png') && is_file($pfad . 'png')) $ext = "png"; - else if (File::exists($pfad . 'jpg')) + else if (file_exists($pfad . 'jpg') && is_file($pfad . 'jpg')) $ext = "jpg"; else continue; @@ -14454,7 +14454,7 @@ function adminVereineExportBilderForm(): void $veranstalter = null; $ziel_bilder_pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'export'; - if (!Folder::exists($ziel_bilder_pfad) && !Folder::create($ziel_bilder_pfad, 0777)) { + if (!is_dir($ziel_bilder_pfad) && !Folder::create($ziel_bilder_pfad, 0777)) { redirectSportsManagerURL('&task=admin_vereine', "Der Ordner 'images/sportsmanager/export' konnte nicht neu erstellt werden."); } @@ -14478,9 +14478,9 @@ function adminVereineExportBilderForm(): void foreach ($vereine as $v) { $pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'vereine' . DIRECTORY_SEPARATOR . $v->verein_id . '.'; - if (File::exists($pfad . 'png')) + if (file_exists($pfad . 'png') && is_file($pfad . 'png')) $ext = "png"; - else if (File::exists($pfad . 'jpg')) + else if (file_exists($pfad . 'jpg') && is_file($pfad . 'jpg')) $ext = "jpg"; else continue; @@ -14580,7 +14580,7 @@ function adminSpielerImportBilder(): void } $quelle_bilder_pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'import'; - if (!Folder::exists($quelle_bilder_pfad) && !Folder::create($quelle_bilder_pfad, 0777)) { + if (!is_dir($quelle_bilder_pfad) && !Folder::create($quelle_bilder_pfad, 0777)) { redirectSportsManagerURL('&task=admin_spieler', "Der Ordner 'images/sportsmanager/import' existiert nicht."); } @@ -14664,7 +14664,7 @@ function adminSpielerImportBilder(): void if ($bilder_beibehalten) { $ziel_pfad = $ziel_bilder_pfad . DIRECTORY_SEPARATOR . $spieler_id . '.'; - if (File::exists($ziel_pfad . 'jpg') || File::exists($ziel_pfad . 'png')) + if (file_exists($ziel_pfad . 'jpg') && is_file($ziel_pfad . 'jpg') || file_exists($ziel_pfad . 'png') && is_file($ziel_pfad . 'png')) continue; } @@ -14728,7 +14728,7 @@ function adminVereineImportBilder(): void $bilder_beibehalten = $jInput->get('bilder_beibehalten', 0, 'INT'); $quelle_bilder_pfad = $sportsmanager_joomla_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . 'import'; - if (!Folder::exists($quelle_bilder_pfad) && !Folder::create($quelle_bilder_pfad, 0777)) { + if (!is_dir($quelle_bilder_pfad) && !Folder::create($quelle_bilder_pfad, 0777)) { redirectSportsManagerURL('&task=admin_uebersicht', "Der Ordner 'images/sportsmanager/import' existiert nicht."); } @@ -14787,7 +14787,7 @@ function adminVereineImportBilder(): void if ($bilder_beibehalten) { $ziel_pfad = $ziel_bilder_pfad . DIRECTORY_SEPARATOR . $verein_id . '.'; - if (File::exists($ziel_pfad . 'jpg') || File::exists($ziel_pfad . 'png')) + if (file_exists($ziel_pfad . 'jpg') && is_file($ziel_pfad . 'jpg') || file_exists($ziel_pfad . 'png') && is_file($ziel_pfad . 'png')) continue; } diff --git a/src/structure/components/com_sportsmanager/database/update.php b/src/structure/components/com_sportsmanager/database/update.php index c776577..1e1cbde 100644 --- a/src/structure/components/com_sportsmanager/database/update.php +++ b/src/structure/components/com_sportsmanager/database/update.php @@ -959,7 +959,7 @@ function updateDatabase(): void } if ($datenbank_version < 23) { - if (!Folder::exists(JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tsleague' . DIRECTORY_SEPARATOR . 'spieler')) { + if (!is_dir(JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tsleague' . DIRECTORY_SEPARATOR . 'spieler')) { if (!Folder::move(JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tsleague' . DIRECTORY_SEPARATOR . 'players', JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tsleague' . DIRECTORY_SEPARATOR . 'spieler')) die(Text::_('COM_SPORTSMANAGER_RENAME_PLAYER_DIRECTORY_FAILED')); } @@ -1720,7 +1720,7 @@ function updateDatabase(): void if (!$db->execute()) { die($db->stderr(true)); } - if (!Folder::exists(JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager') && Folder::exists(JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tsleague')) { + if (!is_dir(JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager') && is_dir(JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tsleague')) { if (!Folder::move(JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tsleague', JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager')) die(Text::_('COM_SPORTSMANAGER_RENAME_PLAYER_FAILED')); } diff --git a/src/structure/components/com_sportsmanager/util/image.php b/src/structure/components/com_sportsmanager/util/image.php index e9fcedb..8c900e2 100644 --- a/src/structure/components/com_sportsmanager/util/image.php +++ b/src/structure/components/com_sportsmanager/util/image.php @@ -80,9 +80,9 @@ function bildKopierenAngepasst($quelle, $ziel, $ziel_breite, $ziel_hoehe, $zusch $no_cache = $jInput->get('nc', 0, 'INT'); $pfad = SPORTSMANAGER_JOOMLA_PATH . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'sportsmanager' . DIRECTORY_SEPARATOR . $typ . DIRECTORY_SEPARATOR . $id . '.'; - if (File::exists($pfad . 'png')) + if (file_exists($pfad . 'png') && is_file($pfad . 'png')) $ext = "png"; - else if (File::exists($pfad . 'jpg')) + else if (file_exists($pfad . 'png') && is_file($pfad . 'png')) $ext = "jpg"; else { ob_end_clean(); // Wegen UTF-8-Zeichen, die in der ausgabe vorhanden sind