From 9ab6ee93a870302a22496080009786ce0ad3837c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Mon, 11 May 2020 10:14:29 +0200 Subject: [PATCH] Fixed #8 bug with missing theme mapping --- .../de/rocksolid_theme_assistant.php | 1 + .../en/rocksolid_theme_assistant.php | 1 + src/ThemeAssistantDataContainer.php | 40 ++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Resources/contao/languages/de/rocksolid_theme_assistant.php b/src/Resources/contao/languages/de/rocksolid_theme_assistant.php index 95dd4b0..21bc83d 100644 --- a/src/Resources/contao/languages/de/rocksolid_theme_assistant.php +++ b/src/Resources/contao/languages/de/rocksolid_theme_assistant.php @@ -33,3 +33,4 @@ $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['editor_info'] = 'Falls der Editor nicht korrekt angezeigt wird, laden Sie die Seite bitte neu.'; $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['source'][0] = 'Quelltext'; $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['source'][1] = 'Hier können Sie den Quelltext direkt bearbeiten'; +$GLOBALS['TL_LANG']['rocksolid_theme_assistant']['unknown_theme'] = 'Keinem Theme zugeordnet'; diff --git a/src/Resources/contao/languages/en/rocksolid_theme_assistant.php b/src/Resources/contao/languages/en/rocksolid_theme_assistant.php index 81b42c5..6608c86 100644 --- a/src/Resources/contao/languages/en/rocksolid_theme_assistant.php +++ b/src/Resources/contao/languages/en/rocksolid_theme_assistant.php @@ -33,3 +33,4 @@ $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['editor_info'] = 'If the editor doesn\'t appear correctly, reload the page.'; $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['source'][0] = 'Source code'; $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['source'][1] = 'Here you can edit the source code directly.'; +$GLOBALS['TL_LANG']['rocksolid_theme_assistant']['unknown_theme'] = 'Not associated with a theme'; diff --git a/src/ThemeAssistantDataContainer.php b/src/ThemeAssistantDataContainer.php index 6e90a7c..2e0e399 100644 --- a/src/ThemeAssistantDataContainer.php +++ b/src/ThemeAssistantDataContainer.php @@ -86,7 +86,7 @@ public function showAll() $files[] = array( 'id' => $file, 'type' => $extension === 'html5' ? 'html' : $extension, - 'name' => substr($file, strlen($folder)+1, -5), + 'name' => substr($file, strlen($GLOBALS['TL_CONFIG']['uploadPath'])+1, -5), ); } } @@ -125,6 +125,44 @@ public function showAll() } + $files = array(); + $allCssFiles = array_merge( + glob(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/*.css.base') ?: array(), + glob(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/*/*.css.base') ?: array(), + glob(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/*/*/*.css.base') ?: array(), + glob(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/*/*/*/*.css.base') ?: array(), + glob(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/*/*/*/*/*.css.base') ?: array(), + glob(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/*/*/*/*/*/*.css.base') ?: array(), + glob(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/*/*/*/*/*/*/*.css.base') ?: array() + ); + + foreach ($allCssFiles as $baseFile) { + if(!file_exists(substr($baseFile, 0, -5))){ + continue; + } + $baseFileId = substr($baseFile, strlen(TL_ROOT)+1); + foreach ($themeList as $theme) { + foreach ($theme['files'] as $file) { + if ($file['id'] === $baseFileId) { + continue 3; + } + } + } + $files[] = array( + 'id' => $baseFileId, + 'type' => 'css', + 'name' => substr($baseFileId, strlen($GLOBALS['TL_CONFIG']['uploadPath'])+1, -5), + ); + } + + if (count($files)) { + $themeList[] = array( + 'name' => $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['unknown_theme'], + 'files' => $files, + 'screenshot' => null, + ); + } + if (!count($themeList)) { return '

' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '

'; }